author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Tue, 21 Jul 2009 12:44:36 +0200 | |
changeset 2400 | 17b1f0b80fe8 |
parent 2385 | 8fa16dc4b8c8 |
child 3494 | ed9501fb1152 |
permissions | -rw-r--r-- |
0 | 1 |
CubicWeb.require('python.js'); |
2338
3f7c7fbae94e
call postAjaxLoad in reloadComponent; add corners only on reloaded elements
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2232
diff
changeset
|
2 |
CubicWeb.require('jquery.corner.js'); |
0 | 3 |
|
4 |
/* returns the document's baseURI. (baseuri() uses document.baseURI if |
|
5 |
* available and inspects the <base> tag manually otherwise.) |
|
6 |
*/ |
|
7 |
function baseuri() { |
|
8 |
var uri = document.baseURI; |
|
9 |
if (uri) { // some browsers don't define baseURI |
|
10 |
return uri; |
|
11 |
} |
|
12 |
var basetags = document.getElementsByTagName('base'); |
|
13 |
if (basetags.length) { |
|
14 |
return getNodeAttribute(basetags[0], 'href'); |
|
15 |
} |
|
16 |
return ''; |
|
17 |
} |
|
18 |
||
19 |
||
2357
e65e352cfde3
[htmlhelpers] notes about seemingly unused functions (remove for cw 3.4 ?), cleanup a bit
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2355
diff
changeset
|
20 |
/* set body's cursor to 'progress' */ |
0 | 21 |
function setProgressCursor() { |
22 |
var body = document.getElementsByTagName('body')[0]; |
|
23 |
body.style.cursor = 'progress'; |
|
24 |
} |
|
25 |
||
2357
e65e352cfde3
[htmlhelpers] notes about seemingly unused functions (remove for cw 3.4 ?), cleanup a bit
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2355
diff
changeset
|
26 |
/* reset body's cursor to default (mouse cursor). The main |
0 | 27 |
* purpose of this function is to be used as a callback in the |
2357
e65e352cfde3
[htmlhelpers] notes about seemingly unused functions (remove for cw 3.4 ?), cleanup a bit
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2355
diff
changeset
|
28 |
* deferreds' callbacks chain. */ |
0 | 29 |
function resetCursor(result) { |
30 |
var body = document.getElementsByTagName('body')[0]; |
|
31 |
body.style.cursor = 'default'; |
|
32 |
// pass result to next callback in the callback chain |
|
33 |
return result; |
|
34 |
} |
|
35 |
||
36 |
function updateMessage(msg) { |
|
37 |
var msgdiv = DIV({'class':'message'}); |
|
38 |
// don't pass msg to DIV() directly because DIV will html escape it |
|
39 |
// and msg should alreay be html escaped at this point. |
|
40 |
msgdiv.innerHTML = msg; |
|
41 |
jQuery('#appMsg').removeClass('hidden').empty().append(msgdiv); |
|
42 |
} |
|
43 |
||
44 |
/* builds an url from an object (used as a dictionnary) |
|
1419 | 45 |
* Notable difference with MochiKit's queryString: asURL does not |
0 | 46 |
* *url_quote* each value found in the dictionnary |
29
7d14f1eadded
fix focus problems on login inputs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
47 |
* |
1419 | 48 |
* >>> asURL({'rql' : "RQL", 'x': [1, 2], 'itemvid' : "oneline"}) |
0 | 49 |
* rql=RQL&vid=list&itemvid=oneline&x=1&x=2 |
50 |
*/ |
|
1419 | 51 |
function asURL(props) { |
0 | 52 |
var chunks = []; |
53 |
for(key in props) { |
|
54 |
var value = props[key]; |
|
55 |
// generate a list of couple key=value if key is multivalued |
|
56 |
if (isArrayLike(value)) { |
|
57 |
for (var i=0; i<value.length;i++) { |
|
58 |
chunks.push(key + '=' + value[i]); |
|
59 |
} |
|
60 |
} else { |
|
61 |
chunks.push(key + '=' + value); |
|
62 |
} |
|
63 |
} |
|
64 |
return chunks.join('&'); |
|
65 |
} |
|
66 |
||
29
7d14f1eadded
fix focus problems on login inputs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
67 |
/* return selected value of a combo box if any |
0 | 68 |
*/ |
69 |
function firstSelected(selectNode) { |
|
70 |
var selection = filter(attrgetter('selected'), selectNode.options); |
|
2357
e65e352cfde3
[htmlhelpers] notes about seemingly unused functions (remove for cw 3.4 ?), cleanup a bit
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2355
diff
changeset
|
71 |
return (selection.length > 0) ? getNodeAttribute(selection[0], 'value'):null; |
0 | 72 |
} |
73 |
||
74 |
/* toggle visibility of an element by its id |
|
75 |
*/ |
|
76 |
function toggleVisibility(elemId) { |
|
77 |
jqNode(elemId).toggleClass('hidden'); |
|
78 |
} |
|
79 |
||
29
7d14f1eadded
fix focus problems on login inputs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
80 |
|
7d14f1eadded
fix focus problems on login inputs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
81 |
/* toggles visibility of login popup div */ |
2385
8fa16dc4b8c8
[js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2378
diff
changeset
|
82 |
// XXX used exactly ONCE in basecomponents |
29
7d14f1eadded
fix focus problems on login inputs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
83 |
function popupLoginBox() { |
7d14f1eadded
fix focus problems on login inputs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
84 |
toggleVisibility('popupLoginBox'); |
7d14f1eadded
fix focus problems on login inputs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
85 |
jQuery('#__login:visible').focus(); |
7d14f1eadded
fix focus problems on login inputs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
86 |
} |
7d14f1eadded
fix focus problems on login inputs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
87 |
|
0 | 88 |
|
89 |
/* returns the list of elements in the document matching the tag name |
|
90 |
* and the properties provided |
|
29
7d14f1eadded
fix focus problems on login inputs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
91 |
* |
0 | 92 |
* @param tagName the tag's name |
93 |
* @param properties a js Object used as a dict |
|
94 |
* @return an iterator (if a *real* array is needed, you can use the |
|
95 |
* list() function) |
|
96 |
*/ |
|
97 |
function getElementsMatching(tagName, properties, /* optional */ parent) { |
|
98 |
parent = parent || document; |
|
2357
e65e352cfde3
[htmlhelpers] notes about seemingly unused functions (remove for cw 3.4 ?), cleanup a bit
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2355
diff
changeset
|
99 |
return filter(function elementMatches(element) { |
e65e352cfde3
[htmlhelpers] notes about seemingly unused functions (remove for cw 3.4 ?), cleanup a bit
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2355
diff
changeset
|
100 |
for (prop in properties) { |
e65e352cfde3
[htmlhelpers] notes about seemingly unused functions (remove for cw 3.4 ?), cleanup a bit
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2355
diff
changeset
|
101 |
if (getNodeAttribute(element, prop) != properties[prop]) { |
e65e352cfde3
[htmlhelpers] notes about seemingly unused functions (remove for cw 3.4 ?), cleanup a bit
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2355
diff
changeset
|
102 |
return false;}} |
e65e352cfde3
[htmlhelpers] notes about seemingly unused functions (remove for cw 3.4 ?), cleanup a bit
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2355
diff
changeset
|
103 |
return true;}, |
e65e352cfde3
[htmlhelpers] notes about seemingly unused functions (remove for cw 3.4 ?), cleanup a bit
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2355
diff
changeset
|
104 |
parent.getElementsByTagName(tagName)); |
0 | 105 |
} |
106 |
||
107 |
/* |
|
29
7d14f1eadded
fix focus problems on login inputs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
108 |
* sets checked/unchecked status of checkboxes |
0 | 109 |
*/ |
110 |
function setCheckboxesState(nameprefix, checked){ |
|
111 |
// XXX: this looks in *all* the document for inputs |
|
112 |
var elements = getElementsMatching('input', {'type': "checkbox"}); |
|
113 |
filterfunc = function(cb) { return nameprefix && cb.name.startsWith(nameprefix); }; |
|
114 |
forEach(filter(filterfunc, elements), function(cb) {cb.checked=checked;}); |
|
115 |
} |
|
116 |
||
117 |
function setCheckboxesState2(nameprefix, value, checked){ |
|
118 |
// XXX: this looks in *all* the document for inputs |
|
119 |
var elements = getElementsMatching('input', {'type': "checkbox"}); |
|
120 |
filterfunc = function(cb) { return nameprefix && cb.name.startsWith(nameprefix) && cb.value == value; }; |
|
121 |
forEach(filter(filterfunc, elements), function(cb) {cb.checked=checked;}); |
|
122 |
} |
|
123 |
||
124 |
||
125 |
/* this function is a hack to build a dom node from html source */ |
|
126 |
function html2dom(source) { |
|
127 |
var tmpNode = SPAN(); |
|
128 |
tmpNode.innerHTML = source; |
|
129 |
if (tmpNode.childNodes.length == 1) { |
|
130 |
return tmpNode.firstChild; |
|
131 |
} |
|
132 |
else { |
|
133 |
// we leave the span node when `source` has no root node |
|
134 |
// XXX This is cleary not the best solution, but css/html-wise, |
|
135 |
/// a span not should not be too much disturbing |
|
136 |
return tmpNode; |
|
137 |
} |
|
138 |
} |
|
139 |
||
140 |
||
141 |
// *** HELPERS **************************************************** // |
|
142 |
function rql_for_eid(eid) { return 'Any X WHERE X eid ' + eid; } |
|
143 |
function isTextNode(domNode) { return domNode.nodeType == 3; } |
|
144 |
function isElementNode(domNode) { return domNode.nodeType == 1; } |
|
145 |
||
146 |
function autogrow(area) { |
|
147 |
if (area.scrollHeight > area.clientHeight && !window.opera) { |
|
148 |
if (area.rows < 20) { |
|
149 |
area.rows += 2; |
|
150 |
} |
|
151 |
} |
|
152 |
} |
|
153 |
//============= page loading events ==========================================// |
|
2338
3f7c7fbae94e
call postAjaxLoad in reloadComponent; add corners only on reloaded elements
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2232
diff
changeset
|
154 |
|
3f7c7fbae94e
call postAjaxLoad in reloadComponent; add corners only on reloaded elements
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2232
diff
changeset
|
155 |
CubicWeb.rounded = [ |
3f7c7fbae94e
call postAjaxLoad in reloadComponent; add corners only on reloaded elements
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2232
diff
changeset
|
156 |
['div.sideBoxBody', 'bottom 6px'], |
2357
e65e352cfde3
[htmlhelpers] notes about seemingly unused functions (remove for cw 3.4 ?), cleanup a bit
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2355
diff
changeset
|
157 |
['div.boxTitle, div.boxPrefTitle, div.sideBoxTitle, th.month', 'top 6px'] |
2338
3f7c7fbae94e
call postAjaxLoad in reloadComponent; add corners only on reloaded elements
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2232
diff
changeset
|
158 |
]; |
3f7c7fbae94e
call postAjaxLoad in reloadComponent; add corners only on reloaded elements
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2232
diff
changeset
|
159 |
|
3f7c7fbae94e
call postAjaxLoad in reloadComponent; add corners only on reloaded elements
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2232
diff
changeset
|
160 |
function roundedCorners(node) { |
3f7c7fbae94e
call postAjaxLoad in reloadComponent; add corners only on reloaded elements
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2232
diff
changeset
|
161 |
node = jQuery(node); |
2355
359903ef980a
for some reason, use of an anonymous function makes things more readable
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2338
diff
changeset
|
162 |
for(var r=0; r < CubicWeb.rounded.length; r++) { |
2338
3f7c7fbae94e
call postAjaxLoad in reloadComponent; add corners only on reloaded elements
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2232
diff
changeset
|
163 |
node.find(CubicWeb.rounded[r][0]).corner(CubicWeb.rounded[r][1]); |
3f7c7fbae94e
call postAjaxLoad in reloadComponent; add corners only on reloaded elements
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2232
diff
changeset
|
164 |
} |
0 | 165 |
} |
166 |
||
2385
8fa16dc4b8c8
[js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2378
diff
changeset
|
167 |
jQuery(document).ready(function () {roundedCorners(this.body);}); |
8fa16dc4b8c8
[js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2378
diff
changeset
|
168 |
|
8fa16dc4b8c8
[js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2378
diff
changeset
|
169 |
CubicWeb.provide('corners.js'); |
0 | 170 |
|
171 |
CubicWeb.provide('htmlhelpers.js'); |