Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixes for Ticket 4120 - JS cleanup for admin #948

Closed
wants to merge 3 commits into from

2 participants

@andrewjesaitis

This was quite an old ticket, but most of the original patch still applies. Consider it spring cleaning?!

It is just js cleanup. No admin functionality. The most import change is that it removes a duplicative function from calendar.js, which is also found in core.js.

The other two commits shuffle a couple functions into core.js. This ticket seemed to be a prerequisite to addressing #4045 which I will pick up once a call is made on this ticket.

The only part of the original patch that didn't apply were the changes to js/admin/ordering.js, which appear to have been removed. This change looked to be removing a duplicative addEvent function.

Associated TIcket

andrewjesaitis added some commits
@andrewjesaitis andrewjesaitis Removes quickElement from calendar.js
The function quickElement in calendar.js is a duplicate of the
quickElement function in core.js.
e8c92ed
@andrewjesaitis andrewjesaitis Moves cancelEventPropagation into core.js
The cancelEventPropagation function is a general utility function that
can be reused by other widgets.
dfbd783
@andrewjesaitis andrewjesaitis Moves removeChildren to core.js
The function removeChildren is a general utility that other functions
might want to use.
64d2278
@claudep
Collaborator

Thanks, I have pushed your patches.

@claudep claudep closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 23, 2013
  1. @andrewjesaitis

    Removes quickElement from calendar.js

    andrewjesaitis authored
    The function quickElement in calendar.js is a duplicate of the
    quickElement function in core.js.
  2. @andrewjesaitis

    Moves cancelEventPropagation into core.js

    andrewjesaitis authored
    The cancelEventPropagation function is a general utility function that
    can be reused by other widgets.
  3. @andrewjesaitis

    Moves removeChildren to core.js

    andrewjesaitis authored
    The function removeChildren is a general utility that other functions
    might want to use.
This page is out of date. Refresh to see the latest.
View
9 django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js
@@ -76,7 +76,7 @@ var DateTimeShortcuts = {
clock_box.className = 'clockbox module';
clock_box.setAttribute('id', DateTimeShortcuts.clockDivName + num);
document.body.appendChild(clock_box);
- addEvent(clock_box, 'click', DateTimeShortcuts.cancelEventPropagation);
+ addEvent(clock_box, 'click', cancelEventPropagation);
quickElement('h2', clock_box, gettext('Choose a time'));
var time_list = quickElement('ul', clock_box, '');
@@ -174,7 +174,7 @@ var DateTimeShortcuts = {
cal_box.className = 'calendarbox module';
cal_box.setAttribute('id', DateTimeShortcuts.calendarDivName1 + num);
document.body.appendChild(cal_box);
- addEvent(cal_box, 'click', DateTimeShortcuts.cancelEventPropagation);
+ addEvent(cal_box, 'click', cancelEventPropagation);
// next-prev links
var cal_nav = quickElement('div', cal_box, '');
@@ -277,11 +277,6 @@ var DateTimeShortcuts = {
DateTimeShortcuts.calendarInputs[num].value = d.strftime(get_format('DATE_INPUT_FORMATS')[0]);
DateTimeShortcuts.calendarInputs[num].focus();
DateTimeShortcuts.dismissCalendar(num);
- },
- cancelEventPropagation: function(e) {
- if (!e) e = window.event;
- e.cancelBubble = true;
- if (e.stopPropagation) e.stopPropagation();
}
}
View
19 django/contrib/admin/static/admin/js/calendar.js
@@ -2,25 +2,6 @@
calendar.js - Calendar functions by Adrian Holovaty
*/
-function removeChildren(a) { // "a" is reference to an object
- while (a.hasChildNodes()) a.removeChild(a.lastChild);
-}
-
-// quickElement(tagType, parentReference, textInChildNode, [, attribute, attributeValue ...]);
-function quickElement() {
- var obj = document.createElement(arguments[0]);
- if (arguments[2] != '' && arguments[2] != null) {
- var textNode = document.createTextNode(arguments[2]);
- obj.appendChild(textNode);
- }
- var len = arguments.length;
- for (var i = 3; i < len; i += 2) {
- obj.setAttribute(arguments[i], arguments[i+1]);
- }
- arguments[1].appendChild(obj);
- return obj;
-}
-
// CalendarNamespace -- Provides a collection of HTML calendar-related helper functions
var CalendarNamespace = {
monthsOfYear: gettext('January February March April May June July August September October November December').split(' '),
View
11 django/contrib/admin/static/admin/js/core.js
@@ -29,6 +29,12 @@ function removeEvent(obj, evType, fn) {
}
}
+function cancelEventPropagation(e) {
+ if (!e) e = window.event;
+ e.cancelBubble = true;
+ if (e.stopPropagation) e.stopPropagation();
+}
+
// quickElement(tagType, parentReference, textInChildNode, [, attribute, attributeValue ...]);
function quickElement() {
var obj = document.createElement(arguments[0]);
@@ -44,6 +50,11 @@ function quickElement() {
return obj;
}
+// "a" is reference to an object
+function removeChildren(a) {
+ while (a.hasChildNodes()) a.removeChild(a.lastChild);
+}
+
// ----------------------------------------------------------------------------
// Cross-browser xmlhttp object
// from http://jibbering.com/2002/4/httprequest.html
Something went wrong with that request. Please try again.