Code

Ticket #4045: admin-js.diff

File admin-js.diff, 6.9 KB (added by arvin, 7 years ago)
Line 
1Index: core.js
2===================================================================
3--- core.js     (revision 5007)
4+++ core.js     (working copy)
5@@ -25,6 +25,12 @@
6     }
7 }
8 
9+function cancelEventPropagation(e) {
10+    if (!e) e = window.event;
11+    e.cancelBubble = true;
12+    if (e.stopPropagation) e.stopPropagation();
13+}
14+
15 // quickElement(tagType, parentReference, textInChildNode, [, attribute, attributeValue ...]);
16 function quickElement() {
17     var obj = document.createElement(arguments[0]);
18@@ -40,6 +46,11 @@
19     return obj;
20 }
21 
22+// "a" is reference to an object
23+function removeChildren(a) {
24+    while (a.hasChildNodes()) a.removeChild(a.lastChild);
25+}
26+
27 // ----------------------------------------------------------------------------
28 // Cross-browser xmlhttp object
29 // from http://jibbering.com/2002/4/httprequest.html
30Index: calendar.js
31===================================================================
32--- calendar.js (revision 5007)
33+++ calendar.js (working copy)
34@@ -2,25 +2,6 @@
35 calendar.js - Calendar functions by Adrian Holovaty
36 */
37 
38-function removeChildren(a) { // "a" is reference to an object
39-    while (a.hasChildNodes()) a.removeChild(a.lastChild);
40-}
41-
42-// quickElement(tagType, parentReference, textInChildNode, [, attribute, attributeValue ...]);
43-function quickElement() {
44-    var obj = document.createElement(arguments[0]);
45-    if (arguments[2] != '' && arguments[2] != null) {
46-        var textNode = document.createTextNode(arguments[2]);
47-        obj.appendChild(textNode);
48-    }
49-    var len = arguments.length;
50-    for (var i = 3; i < len; i += 2) {
51-        obj.setAttribute(arguments[i], arguments[i+1]);
52-    }
53-    arguments[1].appendChild(obj);
54-    return obj;
55-}
56-
57 // CalendarNamespace -- Provides a collection of HTML calendar-related helper functions
58 var CalendarNamespace = {
59     monthsOfYear: gettext('January February March April May June July August September October November December').split(' '),
60Index: admin/ordering.js
61===================================================================
62--- admin/ordering.js   (revision 5007)
63+++ admin/ordering.js   (working copy)
64@@ -120,18 +120,3 @@
65     draw();
66 }
67 
68-function addEvent(elm, evType, fn, useCapture)
69-// addEvent and removeEvent
70-// cross-browser event handling for IE5+,  NS6 and Mozilla
71-// By Scott Andrew
72-{
73-  if (elm.addEventListener){
74-    elm.addEventListener(evType, fn, useCapture);
75-    return true;
76-  } else if (elm.attachEvent){
77-    var r = elm.attachEvent("on"+evType, fn);
78-    return r;
79-  } else {
80-    elm['on'+evType] = fn;
81-  }
82-}
83Index: admin/DateTimeShortcuts.js
84===================================================================
85--- admin/DateTimeShortcuts.js  (revision 5007)
86+++ admin/DateTimeShortcuts.js  (working copy)
87@@ -6,6 +6,8 @@
88     calendars: [],
89     calendarInputs: [],
90     clockInputs: [],
91+    dismissCalendarFunc: [],
92+    dismissClockFunc: [],
93     calendarDivName1: 'calendarbox', // name of calendar <div> that gets toggled
94     calendarDivName2: 'calendarin',  // name of <div> that contains calendar
95     calendarLinkName: 'calendarlink',// name of the link that is used to toggle
96@@ -39,6 +41,7 @@
97     addClock: function(inp) {
98         var num = DateTimeShortcuts.clockInputs.length;
99         DateTimeShortcuts.clockInputs[num] = inp;
100+       DateTimeShortcuts.dismissClockFunc[num] = function() { DateTimeShortcuts.dismissClock(num); return true; };
101 
102         // Shortcut links (clock icon and "Now" link)
103         var shortcuts_span = document.createElement('span');
104@@ -75,7 +78,7 @@
105         clock_box.className = 'clockbox module';
106         clock_box.setAttribute('id', DateTimeShortcuts.clockDivName + num);
107         document.body.appendChild(clock_box);
108-        addEvent(clock_box, 'click', DateTimeShortcuts.cancelEventPropagation);
109+        addEvent(clock_box, 'click', cancelEventPropagation);
110 
111         quickElement('h2', clock_box, gettext('Choose a time'));
112         time_list = quickElement('ul', clock_box, '');
113@@ -109,11 +112,11 @@
114     
115         // Show the clock box
116         clock_box.style.display = 'block';
117-        addEvent(window, 'click', function() { DateTimeShortcuts.dismissClock(num); return true; });
118+        addEvent(document, 'click', DateTimeShortcuts.dismissClockFunc[num]);
119     },
120     dismissClock: function(num) {
121        document.getElementById(DateTimeShortcuts.clockDivName + num).style.display = 'none';
122-       window.onclick = null;
123+       removeEvent(document, 'click', DateTimeShortcuts.dismissClockFunc[num]);
124     },
125     handleClockQuicklink: function(num, val) {
126        DateTimeShortcuts.clockInputs[num].value = val;
127@@ -122,8 +125,8 @@
128     // Add calendar widget to a given field.
129     addCalendar: function(inp) {
130         var num = DateTimeShortcuts.calendars.length;
131-
132         DateTimeShortcuts.calendarInputs[num] = inp;
133+       DateTimeShortcuts.dismissCalendarFunc[num] = function() { DateTimeShortcuts.dismissCalendar(num); return true; };
134 
135         // Shortcut links (calendar icon and "Today" link)
136         var shortcuts_span = document.createElement('span');
137@@ -163,7 +166,7 @@
138         cal_box.className = 'calendarbox module';
139         cal_box.setAttribute('id', DateTimeShortcuts.calendarDivName1 + num);
140         document.body.appendChild(cal_box);
141-        addEvent(cal_box, 'click', DateTimeShortcuts.cancelEventPropagation);
142+        addEvent(cal_box, 'click', cancelEventPropagation);
143 
144         // next-prev links
145         var cal_nav = quickElement('div', cal_box, '');
146@@ -211,10 +214,11 @@
147         cal_box.style.top = findPosY(cal_link) - 75 + 'px';
148     
149         cal_box.style.display = 'block';
150-        addEvent(window, 'click', function() { DateTimeShortcuts.dismissCalendar(num); return true; });
151+        addEvent(document, 'click', DateTimeShortcuts.dismissCalendarFunc[num]);
152     },
153     dismissCalendar: function(num) {
154         document.getElementById(DateTimeShortcuts.calendarDivName1+num).style.display = 'none';
155+       removeEvent(document, 'click', DateTimeShortcuts.dismissCalendarFunc[num]);
156     },
157     drawPrev: function(num) {
158         DateTimeShortcuts.calendars[num].drawPreviousMonth();
159@@ -223,18 +227,13 @@
160         DateTimeShortcuts.calendars[num].drawNextMonth();
161     },
162     handleCalendarCallback: function(num) {
163-        return "function(y, m, d) { DateTimeShortcuts.calendarInputs["+num+"].value = y+'-'+m+'-'+d; document.getElementById(DateTimeShortcuts.calendarDivName1+"+num+").style.display='none';}";
164+       return "function(y, m, d) { var d = new Date(y, m, d); DateTimeShortcuts.calendarInputs["+num+"].value = d.getISODate(); DateTimeShortcuts.dismissCalendar("+num+");}";
165     },
166     handleCalendarQuickLink: function(num, offset) {
167        var d = new Date();
168        d.setDate(d.getDate() + offset)
169        DateTimeShortcuts.calendarInputs[num].value = d.getISODate();
170        DateTimeShortcuts.dismissCalendar(num);
171-    },
172-    cancelEventPropagation: function(e) {
173-        if (!e) e = window.event;
174-        e.cancelBubble = true;
175-        if (e.stopPropagation) e.stopPropagation();
176     }
177 }
178