~ubuntu-branches/ubuntu/edgy/sope/edgy

« back to all changes in this revision

Viewing changes to sope-appserver/samples/TestSite/plone/plone_javascripts.js

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Ley
  • Date: 2005-08-19 16:53:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050819165331-hs683wz1osm708pw
Tags: upstream-4.4rc.2
ImportĀ upstreamĀ versionĀ 4.4rc.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
 
 
3
 
 
4
 
 
5
// Fix for bug in IE6.0 float handling (don't ask, don't tell ;)
 
6
 
 
7
if (document.all && window.attachEvent) window.attachEvent("onload", fixWinIE);
 
8
function fixWinIE() {
 
9
    try {
 
10
        document.getElementById('content').style.display = 'block';
 
11
    } catch(er) {}
 
12
}
 
13
 
 
14
 
 
15
// The calendar popup show/hide:
 
16
 
 
17
    function showDay(date) {
 
18
        document.getElementById('day' + date).style.visibility = 'visible';
 
19
        return true;
 
20
    }
 
21
    
 
22
    function hideDay(date) {
 
23
        document.getElementById('day' + date).style.visibility = 'hidden';
 
24
        return true;
 
25
    }
 
26
 
 
27
// Focus on error or tabindex=1
 
28
if (window.addEventListener) window.addEventListener("load",setFocus,false);
 
29
else if (window.attachEvent) window.attachEvent("onload",setFocus);
 
30
function setFocus() {
 
31
    var xre = new RegExp(/\berror\b/);
 
32
    // Search only forms to avoid spending time on regular text
 
33
    for (var f = 0; (formnode = document.getElementsByTagName('form').item(f)); f++) {
 
34
        // Search for errors first, focus on first error if found
 
35
        for (var i = 0; (node = formnode.getElementsByTagName('div').item(i)); i++) {
 
36
            if (xre.exec(node.className)) {
 
37
                for (var j = 0; (inputnode = node.getElementsByTagName('input').item(j)); j++) {
 
38
                    inputnode.focus();
 
39
                    return;   
 
40
                }
 
41
            }
 
42
        }
 
43
        // If no error, focus on input element with tabindex 1
 
44
        for (var i = 0; (node = formnode.getElementsByTagName('input').item(i)); i++) {
 
45
            if (node.getAttribute('tabindex') == 1) {
 
46
                 node.focus();
 
47
                 return;   
 
48
            }
 
49
        }
 
50
    }
 
51
}
 
52
 
 
53
/********* Table sorter script *************/
 
54
// Table sorter script, thanks to Geir Bļæ½kholt for this.
 
55
// DOM table sorter originally made by Paul Sowden 
 
56
 
 
57
function compare(a,b)
 
58
{
 
59
    au = new String(a);
 
60
    bu = new String(b);
 
61
 
 
62
    if (au.charAt(4) != '-' && au.charAt(7) != '-')
 
63
    {
 
64
    var an = parseFloat(au)
 
65
    var bn = parseFloat(bu)
 
66
    }
 
67
    if (isNaN(an) || isNaN(bn))
 
68
        {as = au.toLowerCase()
 
69
         bs = bu.toLowerCase()
 
70
        if (as > bs)
 
71
            {return 1;}
 
72
        else
 
73
            {return -1;}
 
74
        }
 
75
    else {
 
76
    return an - bn;
 
77
    }
 
78
}
 
79
 
 
80
 
 
81
 
 
82
function getConcatenedTextContent(node) {
 
83
    var _result = "";
 
84
          if (node == null) {
 
85
                    return _result;
 
86
          }
 
87
    var childrens = node.childNodes;
 
88
    var i = 0;
 
89
    while (i < childrens.length) {
 
90
        var child = childrens.item(i);
 
91
        switch (child.nodeType) {
 
92
            case 1: // ELEMENT_NODE
 
93
            case 5: // ENTITY_REFERENCE_NODE
 
94
                _result += getConcatenedTextContent(child);
 
95
                break;
 
96
            case 3: // TEXT_NODE
 
97
            case 2: // ATTRIBUTE_NODE
 
98
            case 4: // CDATA_SECTION_NODE
 
99
                _result += child.nodeValue;
 
100
                break;
 
101
            case 6: // ENTITY_NODE
 
102
            case 7: // PROCESSING_INSTRUCTION_NODE
 
103
            case 8: // COMMENT_NODE
 
104
            case 9: // DOCUMENT_NODE
 
105
            case 10: // DOCUMENT_TYPE_NODE
 
106
            case 11: // DOCUMENT_FRAGMENT_NODE
 
107
            case 12: // NOTATION_NODE
 
108
                // skip
 
109
                break;
 
110
        }
 
111
        i ++;
 
112
    }
 
113
        return _result;
 
114
}
 
115
 
 
116
 
 
117
 
 
118
function sort(e) {
 
119
    var el = window.event ? window.event.srcElement : e.currentTarget;
 
120
 
 
121
    // a pretty ugly sort function, but it works nonetheless
 
122
    var a = new Array();
 
123
    // check if the image or the th is clicked. Proceed to parent id it is the image
 
124
    // NOTE THAT nodeName IS UPPERCASE
 
125
    if (el.nodeName == 'IMG') el = el.parentNode;
 
126
    //var name = el.firstChild.nodeValue;
 
127
    // This is not very robust, it assumes there is an image as first node then text
 
128
    var name = el.childNodes.item(1).nodeValue;
 
129
    var dad = el.parentNode;
 
130
    var node;
 
131
    
 
132
    // kill all arrows
 
133
    for (var im = 0; (node = dad.getElementsByTagName("th").item(im)); im++) {
 
134
        // NOTE THAT nodeName IS IN UPPERCASE
 
135
        if (node.lastChild.nodeName == 'IMG')
 
136
        {
 
137
            lastindex = node.getElementsByTagName('img').length - 1;
 
138
            node.getElementsByTagName('img').item(lastindex).setAttribute('src','http://docs.opengroupware.org/arrowBlank.gif');
 
139
        }
 
140
    }
 
141
    
 
142
    for (var i = 0; (node = dad.getElementsByTagName("th").item(i)); i++) {
 
143
        var xre = new RegExp(/\bnosort\b/);
 
144
        // Make sure we are not messing with nosortable columns, then check second node.
 
145
        if (!xre.exec(node.className) && node.childNodes.item(1).nodeValue == name) 
 
146
        {
 
147
            //window.alert(node.childNodes.item(1).nodeValue;
 
148
            lastindex = node.getElementsByTagName('img').length -1;
 
149
            node.getElementsByTagName('img').item(lastindex).setAttribute('src','http://docs.opengroupware.org/arrowUp.gif');
 
150
            break;
 
151
        }
 
152
    }
 
153
 
 
154
    var tbody = dad.parentNode.parentNode.getElementsByTagName("tbody").item(0);
 
155
    for (var j = 0; (node = tbody.getElementsByTagName("tr").item(j)); j++) {
 
156
 
 
157
        // crude way to sort by surname and name after first choice
 
158
        a[j] = new Array();
 
159
        a[j][0] = getConcatenedTextContent(node.getElementsByTagName("td").item(i));
 
160
        a[j][1] = getConcatenedTextContent(node.getElementsByTagName("td").item(1));
 
161
        a[j][2] = getConcatenedTextContent(node.getElementsByTagName("td").item(0));            
 
162
        a[j][3] = node;
 
163
    }
 
164
 
 
165
    if (a.length > 1) {
 
166
        
 
167
        a.sort(compare);
 
168
 
 
169
        // not a perfect way to check, but hell, it suits me fine
 
170
        if (a[0][0] == getConcatenedTextContent(tbody.getElementsByTagName("tr").item(0).getElementsByTagName("td").item(i))
 
171
               && a[1][0] == getConcatenedTextContent(tbody.getElementsByTagName("tr").item(1).getElementsByTagName("td").item(i))) 
 
172
        {
 
173
            a.reverse();
 
174
            lastindex = el.getElementsByTagName('img').length - 1;
 
175
            el.getElementsByTagName('img').item(lastindex).setAttribute('src','http://docs.opengroupware.org/arrowDown.gif');
 
176
        }
 
177
 
 
178
    }
 
179
        
 
180
    for (var j = 0; j < a.length; j++) {
 
181
        tbody.appendChild(a[j][3]);
 
182
    }
 
183
}
 
184
    
 
185
function init(e) {
 
186
    var tbls = document.getElementsByTagName('table');
 
187
    for (var t = 0; t < tbls.length; t++)
 
188
        {
 
189
        // elements of class="listing" can be sorted
 
190
        var re = new RegExp(/\blisting\b/)
 
191
        // elements of class="nosort" should not be sorted
 
192
        var xre = new RegExp(/\bnosort\b/)
 
193
        if (re.exec(tbls[t].className) && !xre.exec(tbls[t].className))
 
194
        {
 
195
            try {
 
196
                var tablename = tbls[t].getAttribute('id');
 
197
                var thead = document.getElementById(tablename).getElementsByTagName("thead").item(0);
 
198
                var node;
 
199
                // set up blank spaceholder gifs
 
200
                blankarrow = document.createElement('img');
 
201
                blankarrow.setAttribute('src','http://docs.opengroupware.org/arrowBlank.gif');
 
202
                blankarrow.setAttribute('height',6);
 
203
                blankarrow.setAttribute('width',9);
 
204
                // the first sortable column should get an arrow initially.
 
205
                initialsort = false;
 
206
                for (var i = 0; (node = thead.getElementsByTagName("th").item(i)); i++) {
 
207
                    // check that the columns does not have class="nosort"
 
208
                    if (!xre.exec(node.className)) {
 
209
                        node.insertBefore(blankarrow.cloneNode(1), node.firstChild);
 
210
                        if (!initialsort) {
 
211
                            initialsort = true;
 
212
                            uparrow = document.createElement('img');
 
213
                            uparrow.setAttribute('src','http://docs.opengroupware.org/arrowUp.gif');
 
214
                            uparrow.setAttribute('height',6);
 
215
                            uparrow.setAttribute('width',9);
 
216
                            node.appendChild(uparrow);
 
217
                        } else {
 
218
                            node.appendChild(blankarrow.cloneNode(1));
 
219
                        }
 
220
    
 
221
                        if (node.addEventListener) node.addEventListener("click",sort,false);
 
222
                        else if (node.attachEvent) node.attachEvent("onclick",sort);
 
223
                    }
 
224
                }
 
225
            } catch(er) {}
 
226
        }
 
227
    }
 
228
}
 
229
 
 
230
// initialize the sorter functions 
 
231
// add stuff to secure it from broken DOM-implanetations or missing objects.
 
232
   
 
233
    
 
234
        
 
235
//    p.appendChild(document.createTextNode("Change sorting by clicking on each individual heading."));
 
236
//    document.getElementById(tablename).parentNode.insertBefore(p,document.getElementById(tablename));
 
237
    
 
238
 
 
239
if (window.addEventListener) window.addEventListener("load",init,false);
 
240
else if (window.attachEvent) window.attachEvent("onload",init);
 
241
 
 
242
       
 
243
// **** End table sort script ***
 
244
 
 
245
 
 
246
 
 
247
// Actions used in the folder_contents view
 
248
 
 
249
function submitFolderAction(folderAction) {
 
250
    document.folderContentsForm.action = document.folderContentsForm.action+'/'+folderAction;
 
251
    document.folderContentsForm.submit();
 
252
}
 
253
 
 
254
function submitFilterAction() {
 
255
    document.folderContentsForm.action = document.folderContentsForm.action+'/folder_contents';
 
256
    filter_selection=document.getElementById('filter_selection');
 
257
    for (var i =0; i < filter_selection.length; i++){
 
258
        if (filter_selection.options[i].selected) {
 
259
            if (filter_selection.options[i].value=='#') {
 
260
                document.folderContentsForm.filter_state.value='clear_view_filter';
 
261
            }
 
262
            else {
 
263
                document.folderContentsForm.filter_state.value='set_view_filter'
 
264
            }
 
265
        }                                               
 
266
    }
 
267
    document.folderContentsForm.submit();
 
268
}
 
269
    
 
270
 
 
271
// Functions for selecting all checkboxes in folder_contents view
 
272
 
 
273
isSelected = false;
 
274
 
 
275
function selectAll() {
 
276
  checkboxes = document.getElementsByName('ids:list');
 
277
  for (i = 0; i < checkboxes.length; i++)
 
278
    checkboxes[i].checked = true ;
 
279
  isSelected = true;
 
280
  return isSelected;
 
281
}
 
282
 
 
283
function deselectAll() {
 
284
  checkboxes = document.getElementsByName('ids:list');
 
285
  for (i = 0; i < checkboxes.length; i++)
 
286
    checkboxes[i].checked = false ;
 
287
  isSelected = false;
 
288
  return isSelected;
 
289
}
 
290
 
 
291
function toggleSelect(selectbutton) {
 
292
  if (isSelected == false) {
 
293
    selectbutton.setAttribute('src','http://docs.opengroupware.org/select_none_icon.gif');
 
294
    return selectAll();
 
295
  }
 
296
  else {
 
297
    selectbutton.setAttribute('src','http://docs.opengroupware.org/select_all_icon.gif');
 
298
    return deselectAll();
 
299
  }
 
300
}