/[drupal]/contributions/modules/menu_otf/menu_otf.js
ViewVC logotype

Contents of /contributions/modules/menu_otf/menu_otf.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Sat Mar 26 18:25:43 2005 UTC (4 years, 8 months ago) by mathias
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-4-6
Changes since 1.1: +81 -15 lines
File MIME type: text/javascript
Updated to 4.6 in lieu of #16204 not making it into core.
1 /* $Id: menu_otf.js,v 1.1 2004/12/23 21:56:17 mathias Exp $
2 Authored by Matt Westgate <drupal at asitis dot org>
3 */
4
5 function stopPropagation(e) {
6 if (!e) e=window.event;
7 if (typeof e.preventDefault!='undefined') e.preventDefault();
8 if (typeof e.stopPropagation!='undefined') e.stopPropagation();
9 return false;
10 }
11
12 function addEvent(o,e,f) {
13 if (o.addEventListener) { o.addEventListener(e,f,false); return true; }
14 else if (o.attachEvent) { return o.attachEvent('on'+e,f); }
15 return false;
16 }
17
18 String.prototype.trim = function() {
19 return this.replace('^\s+','').replace('\s+$','');
20 }
21
22 var REQUIRED = 'required';
23 var ERROR = 'error';
24 var COLLAPSED = 'fieldset-collapsed';
25 var EXPANDED = 'fieldset-expanded';
26 var IS_COLLAPSED = 'collapsed';
27
28 addEvent(window, 'load', initFieldsets);
29
30 function initFieldsets() {
31 if (document.getElementsByTagName) {
32 var f = document.getElementsByTagName('fieldset');
33 for (var i=0; i<f.length; i++) {
34 if (f[i].id == 'quick-menu') {
35 var l = f[i].getElementsByTagName('legend')[0];
36 addEvent(l, 'click', fieldsetClickHandler);
37 addEvent(l, 'mousedown', stopPropagation);
38 addEvent(l, 'mousemove', stopPropagation);
39 f[i].isCollapsible = fieldsetIsCollapsible;
40 var p = new RegExp('[^\w-]*'+IS_COLLAPSED+'[^\w-]*');
41 if (f[i].className.match(p) && f[i].isCollapsible()) {
42 f[i].className = f[i].className.replace(p, ' ' + COLLAPSED);
43 }
44 else {
45 f[i].className += ' ' + EXPANDED;
46 }
47 }
48 }
49 }
50 }
51
52 function fieldsetClickHandler(e) {
53 if (!e) e = window.event;
54 if (this.parentNode) {
55 var f = this.parentNode;
56 }
57 else if (e.srcElement && e.srcElement.parentNode) {
58 var f = e.srcElement.parentNode;
59 }
60 var pe = new RegExp('[^\w-]*'+EXPANDED+'[^\w-]*');
61 var pc = new RegExp('[^\w-]*'+COLLAPSED+'[^\w-]*');
62 if (f.className.match(pc)) {
63 f.className = f.className.replace(pc, ' '+EXPANDED+' ');
64 }
65 else if (f.className.match(pe) && f.isCollapsible()) {
66 f.className = f.className.replace(pe, ' '+COLLAPSED+' ');
67 }
68 return false;
69 }
70
71 function fieldsetIsCollapsible() {
72 var n = this.getElementsByTagName('*');
73 for (var i=0; i < n.length; i++) {
74 if (n[i].className && (n[i].className.match('[^\w-]*'+ERROR+'[^\w-]*') ||
75 (n[i].className.match('[^\w-]*'+REQUIRED+'[^\w-]*')))) {
76 if (n[i].tagName.toLowerCase() == 'input' && n[i].value.trim() == '') {
77 return false;
78 }
79 else if (n[i].tagName.toLowerCase() == 'select' && n[i].options[n[i].selectedIndex].value.trim() == '') {
80 return false;
81 }
82 }
83 }
84 return true;
85 }
86
87
88 function setTitle(form) {
89 // Prefill the menu item title to the current node title.
90 if (form['edit[menu][title]'].value == '') {
91 form['edit[menu][title]'].value = form['edit[title]'].value;
92 }
93 }

  ViewVC Help
Powered by ViewVC 1.1.2