Ticket #4045: admin-js.diff

File admin-js.diff, 6.9 KB (added by arvin, 18 years ago)
  • core.js

     
    2525    }
    2626}
    2727
     28function cancelEventPropagation(e) {
     29    if (!e) e = window.event;
     30    e.cancelBubble = true;
     31    if (e.stopPropagation) e.stopPropagation();
     32}
     33
    2834// quickElement(tagType, parentReference, textInChildNode, [, attribute, attributeValue ...]);
    2935function quickElement() {
    3036    var obj = document.createElement(arguments[0]);
     
    4046    return obj;
    4147}
    4248
     49// "a" is reference to an object
     50function removeChildren(a) {
     51    while (a.hasChildNodes()) a.removeChild(a.lastChild);
     52}
     53
    4354// ----------------------------------------------------------------------------
    4455// Cross-browser xmlhttp object
    4556// from http://jibbering.com/2002/4/httprequest.html
  • calendar.js

     
    22calendar.js - Calendar functions by Adrian Holovaty
    33*/
    44
    5 function removeChildren(a) { // "a" is reference to an object
    6     while (a.hasChildNodes()) a.removeChild(a.lastChild);
    7 }
    8 
    9 // quickElement(tagType, parentReference, textInChildNode, [, attribute, attributeValue ...]);
    10 function quickElement() {
    11     var obj = document.createElement(arguments[0]);
    12     if (arguments[2] != '' && arguments[2] != null) {
    13         var textNode = document.createTextNode(arguments[2]);
    14         obj.appendChild(textNode);
    15     }
    16     var len = arguments.length;
    17     for (var i = 3; i < len; i += 2) {
    18         obj.setAttribute(arguments[i], arguments[i+1]);
    19     }
    20     arguments[1].appendChild(obj);
    21     return obj;
    22 }
    23 
    245// CalendarNamespace -- Provides a collection of HTML calendar-related helper functions
    256var CalendarNamespace = {
    267    monthsOfYear: gettext('January February March April May June July August September October November December').split(' '),
  • admin/ordering.js

     
    120120    draw();
    121121}
    122122
    123 function addEvent(elm, evType, fn, useCapture)
    124 // addEvent and removeEvent
    125 // cross-browser event handling for IE5+,  NS6 and Mozilla
    126 // By Scott Andrew
    127 {
    128   if (elm.addEventListener){
    129     elm.addEventListener(evType, fn, useCapture);
    130     return true;
    131   } else if (elm.attachEvent){
    132     var r = elm.attachEvent("on"+evType, fn);
    133     return r;
    134   } else {
    135     elm['on'+evType] = fn;
    136   }
    137 }
  • admin/DateTimeShortcuts.js

     
    66    calendars: [],
    77    calendarInputs: [],
    88    clockInputs: [],
     9    dismissCalendarFunc: [],
     10    dismissClockFunc: [],
    911    calendarDivName1: 'calendarbox', // name of calendar <div> that gets toggled
    1012    calendarDivName2: 'calendarin',  // name of <div> that contains calendar
    1113    calendarLinkName: 'calendarlink',// name of the link that is used to toggle
     
    3941    addClock: function(inp) {
    4042        var num = DateTimeShortcuts.clockInputs.length;
    4143        DateTimeShortcuts.clockInputs[num] = inp;
     44        DateTimeShortcuts.dismissClockFunc[num] = function() { DateTimeShortcuts.dismissClock(num); return true; };
    4245
    4346        // Shortcut links (clock icon and "Now" link)
    4447        var shortcuts_span = document.createElement('span');
     
    7578        clock_box.className = 'clockbox module';
    7679        clock_box.setAttribute('id', DateTimeShortcuts.clockDivName + num);
    7780        document.body.appendChild(clock_box);
    78         addEvent(clock_box, 'click', DateTimeShortcuts.cancelEventPropagation);
     81        addEvent(clock_box, 'click', cancelEventPropagation);
    7982
    8083        quickElement('h2', clock_box, gettext('Choose a time'));
    8184        time_list = quickElement('ul', clock_box, '');
     
    109112   
    110113        // Show the clock box
    111114        clock_box.style.display = 'block';
    112         addEvent(window, 'click', function() { DateTimeShortcuts.dismissClock(num); return true; });
     115        addEvent(document, 'click', DateTimeShortcuts.dismissClockFunc[num]);
    113116    },
    114117    dismissClock: function(num) {
    115118       document.getElementById(DateTimeShortcuts.clockDivName + num).style.display = 'none';
    116        window.onclick = null;
     119        removeEvent(document, 'click', DateTimeShortcuts.dismissClockFunc[num]);
    117120    },
    118121    handleClockQuicklink: function(num, val) {
    119122       DateTimeShortcuts.clockInputs[num].value = val;
     
    122125    // Add calendar widget to a given field.
    123126    addCalendar: function(inp) {
    124127        var num = DateTimeShortcuts.calendars.length;
    125 
    126128        DateTimeShortcuts.calendarInputs[num] = inp;
     129        DateTimeShortcuts.dismissCalendarFunc[num] = function() { DateTimeShortcuts.dismissCalendar(num); return true; };
    127130
    128131        // Shortcut links (calendar icon and "Today" link)
    129132        var shortcuts_span = document.createElement('span');
     
    163166        cal_box.className = 'calendarbox module';
    164167        cal_box.setAttribute('id', DateTimeShortcuts.calendarDivName1 + num);
    165168        document.body.appendChild(cal_box);
    166         addEvent(cal_box, 'click', DateTimeShortcuts.cancelEventPropagation);
     169        addEvent(cal_box, 'click', cancelEventPropagation);
    167170
    168171        // next-prev links
    169172        var cal_nav = quickElement('div', cal_box, '');
     
    211214        cal_box.style.top = findPosY(cal_link) - 75 + 'px';
    212215   
    213216        cal_box.style.display = 'block';
    214         addEvent(window, 'click', function() { DateTimeShortcuts.dismissCalendar(num); return true; });
     217        addEvent(document, 'click', DateTimeShortcuts.dismissCalendarFunc[num]);
    215218    },
    216219    dismissCalendar: function(num) {
    217220        document.getElementById(DateTimeShortcuts.calendarDivName1+num).style.display = 'none';
     221        removeEvent(document, 'click', DateTimeShortcuts.dismissCalendarFunc[num]);
    218222    },
    219223    drawPrev: function(num) {
    220224        DateTimeShortcuts.calendars[num].drawPreviousMonth();
     
    223227        DateTimeShortcuts.calendars[num].drawNextMonth();
    224228    },
    225229    handleCalendarCallback: function(num) {
    226         return "function(y, m, d) { DateTimeShortcuts.calendarInputs["+num+"].value = y+'-'+m+'-'+d; document.getElementById(DateTimeShortcuts.calendarDivName1+"+num+").style.display='none';}";
     230        return "function(y, m, d) { var d = new Date(y, m, d); DateTimeShortcuts.calendarInputs["+num+"].value = d.getISODate(); DateTimeShortcuts.dismissCalendar("+num+");}";
    227231    },
    228232    handleCalendarQuickLink: function(num, offset) {
    229233       var d = new Date();
    230234       d.setDate(d.getDate() + offset)
    231235       DateTimeShortcuts.calendarInputs[num].value = d.getISODate();
    232236       DateTimeShortcuts.dismissCalendar(num);
    233     },
    234     cancelEventPropagation: function(e) {
    235         if (!e) e = window.event;
    236         e.cancelBubble = true;
    237         if (e.stopPropagation) e.stopPropagation();
    238237    }
    239238}
    240239
Back to Top