Kaydet (Commit) ec4f219e authored tarafından Trey Hunner's avatar Trey Hunner Kaydeden (comit) Tim Graham

Fixed #22463 -- Added code style guide and JavaScript linting (EditorConfig and ESLint)

üst 1e63652e
# http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
charset = utf-8
# Use 2 spaces for the HTML files
[*.html]
indent_size = 2
# The JSON files contain newlines inconsistently
[*.json]
indent_size = 2
insert_final_newline = ignore
[**/admin/js/vendor/**]
indent_style = ignore
indent_size = ignore
# Minified JavaScript files shouldn't be changed
[**.min.js]
indent_style = ignore
insert_final_newline = ignore
# Makefiles always use tabs for indentation
[Makefile]
indent_style = tab
# Batch files use tabs for indentation
[*.bat]
indent_style = tab
**/{*.min,jquery}.js
django/contrib/gis/templates/**/*.js
node_modules/**.js
{
"rules": {
"camelcase": [1, {"properties": "always"}],
"comma-spacing": [1, {"before": false, "after": true}],
"dot-notation": [1, {"allowKeywords": true}],
"curly": [1, "all"],
"indent": [
2,
4
],
"key-spacing": [1, {
"beforeColon": false,
"afterColon": true
}],
"new-cap": [1, {"newIsCap": true, "capIsNew": true}],
"no-alert": [0],
"no-eval": [1],
"no-extend-native": [2, {"exceptions": ["Date", "String"]}],
"no-multi-spaces": [1],
"no-octal-escape": [1],
"no-underscore-dangle": [1],
"no-unused-vars": [2, {"vars": "local", "args": "none"}],
"no-script-url": [1],
"no-shadow": [1, {"hoist": "functions"}],
"quotes": [
1,
"single"
],
"linebreak-style": [
2,
"unix"
],
"semi": [
2,
"always"
],
"space-before-blocks": [2, "always"],
"space-before-function-paren": [1, {"anonymous": "always", "named": "never"}],
"space-infix-ops": [
1,
{"int32Hint": false}
],
"strict": [1, "function"]
},
"env": {
"browser": true
},
"globals": {
"django": false
}
}
\ No newline at end of file
...@@ -6,6 +6,7 @@ MANIFEST ...@@ -6,6 +6,7 @@ MANIFEST
dist/ dist/
docs/_build/ docs/_build/
docs/locale/ docs/locale/
node_modules/
tests/coverage_html/ tests/coverage_html/
tests/.coverage tests/.coverage
build/ build/
/*eslint no-cond-assign:1*/
var SelectBox = { var SelectBox = {
cache: new Object(), cache: {},
init: function(id) { init: function(id) {
var box = document.getElementById(id); var box = document.getElementById(id);
var node; var node;
SelectBox.cache[id] = new Array(); SelectBox.cache[id] = [];
var cache = SelectBox.cache[id]; var cache = SelectBox.cache[id];
for (var i = 0; (node = box.options[i]); i++) { for (var i = 0; (node = box.options[i]); i++) {
cache.push({value: node.value, text: node.text, displayed: 1}); cache.push({value: node.value, text: node.text, displayed: 1});
...@@ -31,7 +32,7 @@ var SelectBox = { ...@@ -31,7 +32,7 @@ var SelectBox = {
for (var i = 0; (node = SelectBox.cache[id][i]); i++) { for (var i = 0; (node = SelectBox.cache[id][i]); i++) {
node.displayed = 1; node.displayed = 1;
for (var j = 0; (token = tokens[j]); j++) { for (var j = 0; (token = tokens[j]); j++) {
if (node.text.toLowerCase().indexOf(token) == -1) { if (node.text.toLowerCase().indexOf(token) === -1) {
node.displayed = 0; node.displayed = 0;
} }
} }
...@@ -41,13 +42,13 @@ var SelectBox = { ...@@ -41,13 +42,13 @@ var SelectBox = {
delete_from_cache: function(id, value) { delete_from_cache: function(id, value) {
var node, delete_index = null; var node, delete_index = null;
for (var i = 0; (node = SelectBox.cache[id][i]); i++) { for (var i = 0; (node = SelectBox.cache[id][i]); i++) {
if (node.value == value) { if (node.value === value) {
delete_index = i; delete_index = i;
break; break;
} }
} }
var j = SelectBox.cache[id].length - 1; var j = SelectBox.cache[id].length - 1;
for (var i = delete_index; i < j; i++) { for (i = delete_index; i < j; i++) {
SelectBox.cache[id][i] = SelectBox.cache[id][i+1]; SelectBox.cache[id][i] = SelectBox.cache[id][i+1];
} }
SelectBox.cache[id].length--; SelectBox.cache[id].length--;
...@@ -59,7 +60,7 @@ var SelectBox = { ...@@ -59,7 +60,7 @@ var SelectBox = {
// Check if an item is contained in the cache // Check if an item is contained in the cache
var node; var node;
for (var i = 0; (node = SelectBox.cache[id][i]); i++) { for (var i = 0; (node = SelectBox.cache[id][i]); i++) {
if (node.value == value) { if (node.value === value) {
return true; return true;
} }
} }
...@@ -67,7 +68,6 @@ var SelectBox = { ...@@ -67,7 +68,6 @@ var SelectBox = {
}, },
move: function(from, to) { move: function(from, to) {
var from_box = document.getElementById(from); var from_box = document.getElementById(from);
var to_box = document.getElementById(to);
var option; var option;
for (var i = 0; (option = from_box.options[i]); i++) { for (var i = 0; (option = from_box.options[i]); i++) {
if (option.selected && SelectBox.cache_contains(from, option.value)) { if (option.selected && SelectBox.cache_contains(from, option.value)) {
...@@ -80,7 +80,6 @@ var SelectBox = { ...@@ -80,7 +80,6 @@ var SelectBox = {
}, },
move_all: function(from, to) { move_all: function(from, to) {
var from_box = document.getElementById(from); var from_box = document.getElementById(from);
var to_box = document.getElementById(to);
var option; var option;
for (var i = 0; (option = from_box.options[i]); i++) { for (var i = 0; (option = from_box.options[i]); i++) {
if (SelectBox.cache_contains(from, option.value)) { if (SelectBox.cache_contains(from, option.value)) {
...@@ -111,4 +110,4 @@ var SelectBox = { ...@@ -111,4 +110,4 @@ var SelectBox = {
box.options[i].selected = 'selected'; box.options[i].selected = 'selected';
} }
} }
} };
/*global addEvent, Calendar, cancelEventPropagation, findPosX, findPosY, getStyle, get_format, gettext, interpolate, ngettext, quickElement, removeEvent*/
// Inserts shortcut buttons after all of the following: // Inserts shortcut buttons after all of the following:
// <input type="text" class="vDateField"> // <input type="text" class="vDateField">
// <input type="text" class="vTimeField"> // <input type="text" class="vTimeField">
...@@ -17,20 +18,20 @@ var DateTimeShortcuts = { ...@@ -17,20 +18,20 @@ var DateTimeShortcuts = {
timezoneWarningClass: 'timezonewarning', // class of the warning for timezone mismatch timezoneWarningClass: 'timezonewarning', // class of the warning for timezone mismatch
timezoneOffset: 0, timezoneOffset: 0,
init: function() { init: function() {
if (window.__admin_utc_offset__ != undefined) { if (window.__admin_utc_offset__ !== undefined) {
var serverOffset = window.__admin_utc_offset__; var serverOffset = window.__admin_utc_offset__;
var localOffset = new Date().getTimezoneOffset() * -60; var localOffset = new Date().getTimezoneOffset() * -60;
DateTimeShortcuts.timezoneOffset = localOffset - serverOffset; DateTimeShortcuts.timezoneOffset = localOffset - serverOffset;
} }
var inputs = document.getElementsByTagName('input'); var inputs = document.getElementsByTagName('input');
for (i=0; i<inputs.length; i++) { for (var i=0; i<inputs.length; i++) {
var inp = inputs[i]; var inp = inputs[i];
if (inp.getAttribute('type') == 'text' && inp.className.match(/vTimeField/)) { if (inp.getAttribute('type') === 'text' && inp.className.match(/vTimeField/)) {
DateTimeShortcuts.addClock(inp); DateTimeShortcuts.addClock(inp);
DateTimeShortcuts.addTimezoneWarning(inp); DateTimeShortcuts.addTimezoneWarning(inp);
} }
else if (inp.getAttribute('type') == 'text' && inp.className.match(/vDateField/)) { else if (inp.getAttribute('type') === 'text' && inp.className.match(/vDateField/)) {
DateTimeShortcuts.addCalendar(inp); DateTimeShortcuts.addCalendar(inp);
DateTimeShortcuts.addTimezoneWarning(inp); DateTimeShortcuts.addTimezoneWarning(inp);
} }
...@@ -38,7 +39,7 @@ var DateTimeShortcuts = { ...@@ -38,7 +39,7 @@ var DateTimeShortcuts = {
}, },
// Return the current time while accounting for the server timezone. // Return the current time while accounting for the server timezone.
now: function() { now: function() {
if (window.__admin_utc_offset__ != undefined) { if (window.__admin_utc_offset__ !== undefined) {
var serverOffset = window.__admin_utc_offset__; var serverOffset = window.__admin_utc_offset__;
var localNow = new Date(); var localNow = new Date();
var localOffset = localNow.getTimezoneOffset() * -60; var localOffset = localNow.getTimezoneOffset() * -60;
...@@ -71,7 +72,7 @@ var DateTimeShortcuts = { ...@@ -71,7 +72,7 @@ var DateTimeShortcuts = {
); );
} }
else { else {
timezoneOffset *= -1 timezoneOffset *= -1;
message = ngettext( message = ngettext(
'Note: You are %s hour behind server time.', 'Note: You are %s hour behind server time.',
'Note: You are %s hours behind server time.', 'Note: You are %s hours behind server time.',
...@@ -86,7 +87,7 @@ var DateTimeShortcuts = { ...@@ -86,7 +87,7 @@ var DateTimeShortcuts = {
$(inp).parent() $(inp).parent()
.append($('<br>')) .append($('<br>'))
.append($warning) .append($warning);
}, },
// Add clock widget to a given field // Add clock widget to a given field
addClock: function(inp) { addClock: function(inp) {
...@@ -150,7 +151,7 @@ var DateTimeShortcuts = { ...@@ -150,7 +151,7 @@ var DateTimeShortcuts = {
cancel_p.className = 'calendar-cancel'; cancel_p.className = 'calendar-cancel';
quickElement('a', cancel_p, gettext('Cancel'), 'href', 'javascript:DateTimeShortcuts.dismissClock(' + num + ');'); quickElement('a', cancel_p, gettext('Cancel'), 'href', 'javascript:DateTimeShortcuts.dismissClock(' + num + ');');
django.jQuery(document).bind('keyup', function(event) { django.jQuery(document).bind('keyup', function(event) {
if (event.which == 27) { if (event.which === 27) {
// ESC key closes popup // ESC key closes popup
DateTimeShortcuts.dismissClock(num); DateTimeShortcuts.dismissClock(num);
event.preventDefault(); event.preventDefault();
...@@ -158,12 +159,12 @@ var DateTimeShortcuts = { ...@@ -158,12 +159,12 @@ var DateTimeShortcuts = {
}); });
}, },
openClock: function(num) { openClock: function(num) {
var clock_box = document.getElementById(DateTimeShortcuts.clockDivName+num) var clock_box = document.getElementById(DateTimeShortcuts.clockDivName+num);
var clock_link = document.getElementById(DateTimeShortcuts.clockLinkName+num) var clock_link = document.getElementById(DateTimeShortcuts.clockLinkName+num);
// Recalculate the clockbox position // Recalculate the clockbox position
// is it left-to-right or right-to-left layout ? // is it left-to-right or right-to-left layout ?
if (getStyle(document.body,'direction')!='rtl') { if (getStyle(document.body,'direction')!=='rtl') {
clock_box.style.left = findPosX(clock_link) + 17 + 'px'; clock_box.style.left = findPosX(clock_link) + 17 + 'px';
} }
else { else {
...@@ -180,20 +181,20 @@ var DateTimeShortcuts = { ...@@ -180,20 +181,20 @@ var DateTimeShortcuts = {
addEvent(document, 'click', DateTimeShortcuts.dismissClockFunc[num]); addEvent(document, 'click', DateTimeShortcuts.dismissClockFunc[num]);
}, },
dismissClock: function(num) { dismissClock: function(num) {
document.getElementById(DateTimeShortcuts.clockDivName + num).style.display = 'none'; document.getElementById(DateTimeShortcuts.clockDivName + num).style.display = 'none';
removeEvent(document, 'click', DateTimeShortcuts.dismissClockFunc[num]); removeEvent(document, 'click', DateTimeShortcuts.dismissClockFunc[num]);
}, },
handleClockQuicklink: function(num, val) { handleClockQuicklink: function(num, val) {
var d; var d;
if (val == -1) { if (val === -1) {
d = DateTimeShortcuts.now(); d = DateTimeShortcuts.now();
} }
else { else {
d = new Date(1970, 1, 1, val, 0, 0, 0) d = new Date(1970, 1, 1, val, 0, 0, 0);
} }
DateTimeShortcuts.clockInputs[num].value = d.strftime(get_format('TIME_INPUT_FORMATS')[0]); DateTimeShortcuts.clockInputs[num].value = d.strftime(get_format('TIME_INPUT_FORMATS')[0]);
DateTimeShortcuts.clockInputs[num].focus(); DateTimeShortcuts.clockInputs[num].focus();
DateTimeShortcuts.dismissClock(num); DateTimeShortcuts.dismissClock(num);
}, },
// Add calendar widget to a given field. // Add calendar widget to a given field.
addCalendar: function(inp) { addCalendar: function(inp) {
...@@ -274,7 +275,7 @@ var DateTimeShortcuts = { ...@@ -274,7 +275,7 @@ var DateTimeShortcuts = {
cancel_p.className = 'calendar-cancel'; cancel_p.className = 'calendar-cancel';
quickElement('a', cancel_p, gettext('Cancel'), 'href', 'javascript:DateTimeShortcuts.dismissCalendar(' + num + ');'); quickElement('a', cancel_p, gettext('Cancel'), 'href', 'javascript:DateTimeShortcuts.dismissCalendar(' + num + ');');
django.jQuery(document).bind('keyup', function(event) { django.jQuery(document).bind('keyup', function(event) {
if (event.which == 27) { if (event.which === 27) {
// ESC key closes popup // ESC key closes popup
DateTimeShortcuts.dismissCalendar(num); DateTimeShortcuts.dismissCalendar(num);
event.preventDefault(); event.preventDefault();
...@@ -282,8 +283,8 @@ var DateTimeShortcuts = { ...@@ -282,8 +283,8 @@ var DateTimeShortcuts = {
}); });
}, },
openCalendar: function(num) { openCalendar: function(num) {
var cal_box = document.getElementById(DateTimeShortcuts.calendarDivName1+num) var cal_box = document.getElementById(DateTimeShortcuts.calendarDivName1+num);
var cal_link = document.getElementById(DateTimeShortcuts.calendarLinkName+num) var cal_link = document.getElementById(DateTimeShortcuts.calendarLinkName+num);
var inp = DateTimeShortcuts.calendarInputs[num]; var inp = DateTimeShortcuts.calendarInputs[num];
// Determine if the current value in the input has a valid date. // Determine if the current value in the input has a valid date.
...@@ -293,7 +294,7 @@ var DateTimeShortcuts = { ...@@ -293,7 +294,7 @@ var DateTimeShortcuts = {
var selected = inp.value.strptime(format); var selected = inp.value.strptime(format);
var year = selected.getFullYear(); var year = selected.getFullYear();
var month = selected.getMonth() + 1; var month = selected.getMonth() + 1;
var re = /\d{4}/ var re = /\d{4}/;
if (re.test(year.toString()) && month >= 1 && month <= 12) { if (re.test(year.toString()) && month >= 1 && month <= 12) {
DateTimeShortcuts.calendars[num].drawDate(month, year, selected); DateTimeShortcuts.calendars[num].drawDate(month, year, selected);
} }
...@@ -301,7 +302,7 @@ var DateTimeShortcuts = { ...@@ -301,7 +302,7 @@ var DateTimeShortcuts = {
// Recalculate the clockbox position // Recalculate the clockbox position
// is it left-to-right or right-to-left layout ? // is it left-to-right or right-to-left layout ?
if (getStyle(document.body,'direction')!='rtl') { if (getStyle(document.body,'direction')!=='rtl') {
cal_box.style.left = findPosX(cal_link) + 17 + 'px'; cal_box.style.left = findPosX(cal_link) + 17 + 'px';
} }
else { else {
...@@ -345,12 +346,12 @@ var DateTimeShortcuts = { ...@@ -345,12 +346,12 @@ var DateTimeShortcuts = {
").style.display='none';}"].join(''); ").style.display='none';}"].join('');
}, },
handleCalendarQuickLink: function(num, offset) { handleCalendarQuickLink: function(num, offset) {
var d = DateTimeShortcuts.now(); var d = DateTimeShortcuts.now();
d.setDate(d.getDate() + offset) d.setDate(d.getDate() + offset);
DateTimeShortcuts.calendarInputs[num].value = d.strftime(get_format('DATE_INPUT_FORMATS')[0]); DateTimeShortcuts.calendarInputs[num].value = d.strftime(get_format('DATE_INPUT_FORMATS')[0]);
DateTimeShortcuts.calendarInputs[num].focus(); DateTimeShortcuts.calendarInputs[num].focus();
DateTimeShortcuts.dismissCalendar(num); DateTimeShortcuts.dismissCalendar(num);
} }
} };
addEvent(window, 'load', DateTimeShortcuts.init); addEvent(window, 'load', DateTimeShortcuts.init);
/*global SelectBox, interpolate*/
// Handles related-objects functionality: lookup link for raw_id_fields // Handles related-objects functionality: lookup link for raw_id_fields
// and Add Another links. // and Add Another links.
...@@ -32,7 +33,7 @@ function showAdminPopup(triggeringLink, name_regexp, add_popup) { ...@@ -32,7 +33,7 @@ function showAdminPopup(triggeringLink, name_regexp, add_popup) {
name = id_to_windowname(name); name = id_to_windowname(name);
var href = triggeringLink.href; var href = triggeringLink.href;
if (add_popup) { if (add_popup) {
if (href.indexOf('?') == -1) { if (href.indexOf('?') === -1) {
href += '?_popup=1'; href += '?_popup=1';
} else { } else {
href += '&_popup=1'; href += '&_popup=1';
...@@ -50,7 +51,7 @@ function showRelatedObjectLookupPopup(triggeringLink) { ...@@ -50,7 +51,7 @@ function showRelatedObjectLookupPopup(triggeringLink) {
function dismissRelatedLookupPopup(win, chosenId) { function dismissRelatedLookupPopup(win, chosenId) {
var name = windowname_to_id(win.name); var name = windowname_to_id(win.name);
var elem = document.getElementById(name); var elem = document.getElementById(name);
if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) { if (elem.className.indexOf('vManyToManyRawIdAdminField') !== -1 && elem.value) {
elem.value += ',' + chosenId; elem.value += ',' + chosenId;
} else { } else {
document.getElementById(name).value = chosenId; document.getElementById(name).value = chosenId;
...@@ -86,10 +87,10 @@ function dismissAddRelatedObjectPopup(win, newId, newRepr) { ...@@ -86,10 +87,10 @@ function dismissAddRelatedObjectPopup(win, newId, newRepr) {
var elem = document.getElementById(name); var elem = document.getElementById(name);
if (elem) { if (elem) {
var elemName = elem.nodeName.toUpperCase(); var elemName = elem.nodeName.toUpperCase();
if (elemName == 'SELECT') { if (elemName === 'SELECT') {
elem.options[elem.options.length] = new Option(newRepr, newId, true, true); elem.options[elem.options.length] = new Option(newRepr, newId, true, true);
} else if (elemName == 'INPUT') { } else if (elemName === 'INPUT') {
if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) { if (elem.className.indexOf('vManyToManyRawIdAdminField') !== -1 && elem.value) {
elem.value += ',' + newId; elem.value += ',' + newId;
} else { } else {
elem.value = newId; elem.value = newId;
...@@ -113,13 +114,13 @@ function dismissChangeRelatedObjectPopup(win, objId, newRepr, newId) { ...@@ -113,13 +114,13 @@ function dismissChangeRelatedObjectPopup(win, objId, newRepr, newId) {
var selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]); var selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]);
var selects = django.jQuery(selectsSelector); var selects = django.jQuery(selectsSelector);
selects.find('option').each(function() { selects.find('option').each(function() {
if (this.value == objId) { if (this.value === objId) {
this.innerHTML = newRepr; this.innerHTML = newRepr;
this.value = newId; this.value = newId;
} }
}); });
win.close(); win.close();
}; }
function dismissDeleteRelatedObjectPopup(win, objId) { function dismissDeleteRelatedObjectPopup(win, objId) {
objId = html_unescape(objId); objId = html_unescape(objId);
...@@ -127,13 +128,13 @@ function dismissDeleteRelatedObjectPopup(win, objId) { ...@@ -127,13 +128,13 @@ function dismissDeleteRelatedObjectPopup(win, objId) {
var selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]); var selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]);
var selects = django.jQuery(selectsSelector); var selects = django.jQuery(selectsSelector);
selects.find('option').each(function() { selects.find('option').each(function() {
if (this.value == objId) { if (this.value === objId) {
django.jQuery(this).remove(); django.jQuery(this).remove();
} }
}).trigger('change'); }).trigger('change');
win.close(); win.close();
}; }
// Kept for backward compatibility // Kept for backward compatibility
showAddAnotherPopup = showRelatedObjectPopup; var showAddAnotherPopup = showRelatedObjectPopup;
dismissAddAnotherPopup = dismissAddRelatedObjectPopup; var dismissAddAnotherPopup = dismissAddRelatedObjectPopup;
/*global gettext, get_format, quickElement, removeChildren*/
/* /*
calendar.js - Calendar functions by Adrian Holovaty calendar.js - Calendar functions by Adrian Holovaty
depends on core.js for utility functions like removeChildren or quickElement depends on core.js for utility functions like removeChildren or quickElement
...@@ -9,17 +10,17 @@ var CalendarNamespace = { ...@@ -9,17 +10,17 @@ var CalendarNamespace = {
daysOfWeek: gettext('S M T W T F S').split(' '), daysOfWeek: gettext('S M T W T F S').split(' '),
firstDayOfWeek: parseInt(get_format('FIRST_DAY_OF_WEEK')), firstDayOfWeek: parseInt(get_format('FIRST_DAY_OF_WEEK')),
isLeapYear: function(year) { isLeapYear: function(year) {
return (((year % 4)==0) && ((year % 100)!=0) || ((year % 400)==0)); return (((year % 4)===0) && ((year % 100)!==0) || ((year % 400)===0));
}, },
getDaysInMonth: function(month,year) { getDaysInMonth: function(month,year) {
var days; var days;
if (month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12) { if (month===1 || month===3 || month===5 || month===7 || month===8 || month===10 || month===12) {
days = 31; days = 31;
} }
else if (month==4 || month==6 || month==9 || month==11) { else if (month===4 || month===6 || month===9 || month===11) {
days = 30; days = 30;
} }
else if (month==2 && CalendarNamespace.isLeapYear(year)) { else if (month===2 && CalendarNamespace.isLeapYear(year)) {
days = 29; days = 29;
} }
else { else {
...@@ -46,8 +47,8 @@ var CalendarNamespace = { ...@@ -46,8 +47,8 @@ var CalendarNamespace = {
// The day variable above will be 1 instead of 2 in, say, US Pacific time // The day variable above will be 1 instead of 2 in, say, US Pacific time
// zone. // zone.
var isSelectedMonth = false; var isSelectedMonth = false;
if (typeof selected != 'undefined') { if (typeof selected !== 'undefined') {
isSelectedMonth = (selected.getUTCFullYear() == year && (selected.getUTCMonth()+1) == month); isSelectedMonth = (selected.getUTCFullYear() === year && (selected.getUTCMonth()+1) === month);
} }
month = parseInt(month); month = parseInt(month);
...@@ -67,28 +68,30 @@ var CalendarNamespace = { ...@@ -67,28 +68,30 @@ var CalendarNamespace = {
var startingPos = new Date(year, month-1, 1 - CalendarNamespace.firstDayOfWeek).getDay(); var startingPos = new Date(year, month-1, 1 - CalendarNamespace.firstDayOfWeek).getDay();
var days = CalendarNamespace.getDaysInMonth(month, year); var days = CalendarNamespace.getDaysInMonth(month, year);
var _cell;
// Draw blanks before first of month // Draw blanks before first of month
tableRow = quickElement('tr', tableBody); tableRow = quickElement('tr', tableBody);
for (var i = 0; i < startingPos; i++) { for (i = 0; i < startingPos; i++) {
var _cell = quickElement('td', tableRow, ' '); _cell = quickElement('td', tableRow, ' ');
_cell.className = "nonday"; _cell.className = "nonday";
} }
// Draw days of month // Draw days of month
var currentDay = 1; var currentDay = 1;
for (var i = startingPos; currentDay <= days; i++) { for (i = startingPos; currentDay <= days; i++) {
if (i%7 == 0 && currentDay != 1) { if (i%7 === 0 && currentDay !== 1) {
tableRow = quickElement('tr', tableBody); tableRow = quickElement('tr', tableBody);
} }
if ((currentDay==todayDay) && (month==todayMonth) && (year==todayYear)) { if ((currentDay===todayDay) && (month===todayMonth) && (year===todayYear)) {
todayClass='today'; todayClass='today';
} else { } else {
todayClass=''; todayClass='';
} }
// use UTC function; see above for explanation. // use UTC function; see above for explanation.
if (isSelectedMonth && currentDay == selected.getUTCDate()) { if (isSelectedMonth && currentDay === selected.getUTCDate()) {
if (todayClass != '') todayClass += " "; if (todayClass !== '') todayClass += " ";
todayClass += "selected"; todayClass += "selected";
} }
...@@ -100,13 +103,13 @@ var CalendarNamespace = { ...@@ -100,13 +103,13 @@ var CalendarNamespace = {
// Draw blanks after end of month (optional, but makes for valid code) // Draw blanks after end of month (optional, but makes for valid code)
while (tableRow.childNodes.length < 7) { while (tableRow.childNodes.length < 7) {
var _cell = quickElement('td', tableRow, ' '); _cell = quickElement('td', tableRow, ' ');
_cell.className = "nonday"; _cell.className = "nonday";
} }
calDiv.appendChild(calTable); calDiv.appendChild(calTable);
} }
} };
// Calendar -- A calendar instance // Calendar -- A calendar instance
function Calendar(div_id, callback, selected) { function Calendar(div_id, callback, selected) {
...@@ -120,7 +123,7 @@ function Calendar(div_id, callback, selected) { ...@@ -120,7 +123,7 @@ function Calendar(div_id, callback, selected) {
this.today = new Date(); this.today = new Date();
this.currentMonth = this.today.getMonth() + 1; this.currentMonth = this.today.getMonth() + 1;
this.currentYear = this.today.getFullYear(); this.currentYear = this.today.getFullYear();
if (typeof selected != 'undefined') { if (typeof selected !== 'undefined') {
this.selected = selected; this.selected = selected;
} }
} }
...@@ -139,7 +142,7 @@ Calendar.prototype = { ...@@ -139,7 +142,7 @@ Calendar.prototype = {
this.drawCurrent(); this.drawCurrent();
}, },
drawPreviousMonth: function() { drawPreviousMonth: function() {
if (this.currentMonth == 1) { if (this.currentMonth === 1) {
this.currentMonth = 12; this.currentMonth = 12;
this.currentYear--; this.currentYear--;
} }
...@@ -149,7 +152,7 @@ Calendar.prototype = { ...@@ -149,7 +152,7 @@ Calendar.prototype = {
this.drawCurrent(); this.drawCurrent();
}, },
drawNextMonth: function() { drawNextMonth: function() {
if (this.currentMonth == 12) { if (this.currentMonth === 12) {
this.currentMonth = 1; this.currentMonth = 1;
this.currentYear++; this.currentYear++;
} }
...@@ -166,4 +169,4 @@ Calendar.prototype = { ...@@ -166,4 +169,4 @@ Calendar.prototype = {
this.currentYear++; this.currentYear++;
this.drawCurrent(); this.drawCurrent();
} }
} };
/*global gettext*/
(function($) { (function($) {
$(document).ready(function() { $(document).ready(function() {
// Add anchor tag for Show/Hide link // Add anchor tag for Show/Hide link
$("fieldset.collapse").each(function(i, elem) { $("fieldset.collapse").each(function(i, elem) {
// Don't hide if fields in this fieldset have errors // Don't hide if fields in this fieldset have errors
if ($(elem).find("div.errors").length == 0) { if ($(elem).find("div.errors").length === 0) {
$(elem).addClass("collapsed").find("h2").first().append(' (<a id="fieldsetcollapser' + $(elem).addClass("collapsed").find("h2").first().append(' (<a id="fieldsetcollapser' +
i +'" class="collapse-toggle" href="#">' + gettext("Show") + i +'" class="collapse-toggle" href="#">' + gettext("Show") +
'</a>)'); '</a>)');
} }
}); });
// Add toggle to anchor tag // Add toggle to anchor tag
$("fieldset.collapse a.collapse-toggle").click(function(ev) { $("fieldset.collapse a.collapse-toggle").click(function(ev) {
if ($(this).closest("fieldset").hasClass("collapsed")) { if ($(this).closest("fieldset").hasClass("collapsed")) {
// Show // Show
$(this).text(gettext("Hide")).closest("fieldset").removeClass("collapsed").trigger("show.fieldset", [$(this).attr("id")]); $(this).text(gettext("Hide")).closest("fieldset").removeClass("collapsed").trigger("show.fieldset", [$(this).attr("id")]);
} else { } else {
// Hide // Hide
$(this).text(gettext("Show")).closest("fieldset").addClass("collapsed").trigger("hide.fieldset", [$(this).attr("id")]); $(this).text(gettext("Show")).closest("fieldset").addClass("collapsed").trigger("hide.fieldset", [$(this).attr("id")]);
} }
return false; return false;
}); });
}); });
})(django.jQuery); })(django.jQuery);
(function(a){a(document).ready(function(){a("fieldset.collapse").each(function(c,b){a(b).find("div.errors").length==0&&a(b).addClass("collapsed").find("h2").first().append(' (<a id="fieldsetcollapser'+c+'" class="collapse-toggle" href="#">'+gettext("Show")+"</a>)")});a("fieldset.collapse a.collapse-toggle").click(function(){a(this).closest("fieldset").hasClass("collapsed")?a(this).text(gettext("Hide")).closest("fieldset").removeClass("collapsed").trigger("show.fieldset",[a(this).attr("id")]):a(this).text(gettext("Show")).closest("fieldset").addClass("collapsed").trigger("hide.fieldset", (function(a){a(document).ready(function(){a("fieldset.collapse").each(function(b,c){0===a(c).find("div.errors").length&&a(c).addClass("collapsed").find("h2").first().append(' (<a id="fieldsetcollapser'+b+'" class="collapse-toggle" href="#">'+gettext("Show")+"</a>)")});a("fieldset.collapse a.collapse-toggle").click(function(b){a(this).closest("fieldset").hasClass("collapsed")?a(this).text(gettext("Hide")).closest("fieldset").removeClass("collapsed").trigger("show.fieldset",[a(this).attr("id")]):a(this).text(gettext("Show")).closest("fieldset").addClass("collapsed").trigger("hide.fieldset",
[a(this).attr("id")]);return false})})})(django.jQuery); [a(this).attr("id")]);return!1})})})(django.jQuery);
...@@ -74,8 +74,8 @@ var xmlhttp; ...@@ -74,8 +74,8 @@ var xmlhttp;
@else @else
xmlhttp = false; xmlhttp = false;
@end @*/ @end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { if (!xmlhttp && typeof XMLHttpRequest !== 'undefined') {
xmlhttp = new XMLHttpRequest(); xmlhttp = new XMLHttpRequest();
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
...@@ -90,7 +90,7 @@ function findPosX(obj) { ...@@ -90,7 +90,7 @@ function findPosX(obj) {
obj = obj.offsetParent; obj = obj.offsetParent;
} }
// IE offsetParent does not include the top-level // IE offsetParent does not include the top-level
if (isIE && obj.parentElement){ if (isIE && obj.parentElement) {
curleft += obj.offsetLeft - obj.scrollLeft; curleft += obj.offsetLeft - obj.scrollLeft;
} }
} else if (obj.x) { } else if (obj.x) {
...@@ -107,7 +107,7 @@ function findPosY(obj) { ...@@ -107,7 +107,7 @@ function findPosY(obj) {
obj = obj.offsetParent; obj = obj.offsetParent;
} }
// IE offsetParent does not include the top-level // IE offsetParent does not include the top-level
if (isIE && obj.parentElement){ if (isIE && obj.parentElement) {
curtop += obj.offsetTop - obj.scrollTop; curtop += obj.offsetTop - obj.scrollTop;
} }
} else if (obj.y) { } else if (obj.y) {
...@@ -121,46 +121,46 @@ function findPosY(obj) { ...@@ -121,46 +121,46 @@ function findPosY(obj) {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
Date.prototype.getTwelveHours = function() { Date.prototype.getTwelveHours = function() {
hours = this.getHours(); var hours = this.getHours();
if (hours == 0) { if (hours === 0) {
return 12; return 12;
} }
else { else {
return hours <= 12 ? hours : hours-12 return hours <= 12 ? hours : hours-12;
} }
} };
Date.prototype.getTwoDigitMonth = function() { Date.prototype.getTwoDigitMonth = function() {
return (this.getMonth() < 9) ? '0' + (this.getMonth()+1) : (this.getMonth()+1); return (this.getMonth() < 9) ? '0' + (this.getMonth()+1) : (this.getMonth()+1);
} };
Date.prototype.getTwoDigitDate = function() { Date.prototype.getTwoDigitDate = function() {
return (this.getDate() < 10) ? '0' + this.getDate() : this.getDate(); return (this.getDate() < 10) ? '0' + this.getDate() : this.getDate();
} };
Date.prototype.getTwoDigitTwelveHour = function() { Date.prototype.getTwoDigitTwelveHour = function() {
return (this.getTwelveHours() < 10) ? '0' + this.getTwelveHours() : this.getTwelveHours(); return (this.getTwelveHours() < 10) ? '0' + this.getTwelveHours() : this.getTwelveHours();
} };
Date.prototype.getTwoDigitHour = function() { Date.prototype.getTwoDigitHour = function() {
return (this.getHours() < 10) ? '0' + this.getHours() : this.getHours(); return (this.getHours() < 10) ? '0' + this.getHours() : this.getHours();
} };
Date.prototype.getTwoDigitMinute = function() { Date.prototype.getTwoDigitMinute = function() {
return (this.getMinutes() < 10) ? '0' + this.getMinutes() : this.getMinutes(); return (this.getMinutes() < 10) ? '0' + this.getMinutes() : this.getMinutes();
} };
Date.prototype.getTwoDigitSecond = function() { Date.prototype.getTwoDigitSecond = function() {
return (this.getSeconds() < 10) ? '0' + this.getSeconds() : this.getSeconds(); return (this.getSeconds() < 10) ? '0' + this.getSeconds() : this.getSeconds();
} };
Date.prototype.getHourMinute = function() { Date.prototype.getHourMinute = function() {
return this.getTwoDigitHour() + ':' + this.getTwoDigitMinute(); return this.getTwoDigitHour() + ':' + this.getTwoDigitMinute();
} };
Date.prototype.getHourMinuteSecond = function() { Date.prototype.getHourMinuteSecond = function() {
return this.getTwoDigitHour() + ':' + this.getTwoDigitMinute() + ':' + this.getTwoDigitSecond(); return this.getTwoDigitHour() + ':' + this.getTwoDigitMinute() + ':' + this.getTwoDigitSecond();
} };
Date.prototype.strftime = function(format) { Date.prototype.strftime = function(format) {
var fields = { var fields = {
...@@ -191,7 +191,7 @@ Date.prototype.strftime = function(format) { ...@@ -191,7 +191,7 @@ Date.prototype.strftime = function(format) {
++i; ++i;
} }
return result; return result;
} };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// String object extensions // String object extensions
...@@ -202,42 +202,43 @@ String.prototype.pad_left = function(pad_length, pad_string) { ...@@ -202,42 +202,43 @@ String.prototype.pad_left = function(pad_length, pad_string) {
new_string = pad_string + new_string; new_string = pad_string + new_string;
} }
return new_string; return new_string;
} };
String.prototype.strptime = function(format) { String.prototype.strptime = function(format) {
var split_format = format.split(/[.\-/]/); var split_format = format.split(/[.\-/]/);
var date = this.split(/[.\-/]/); var date = this.split(/[.\-/]/);
var i = 0; var i = 0;
var day, month, year;
while (i < split_format.length) { while (i < split_format.length) {
switch (split_format[i]) { switch (split_format[i]) {
case "%d": case "%d":
var day = date[i]; day = date[i];
break; break;
case "%m": case "%m":
var month = date[i] - 1; month = date[i] - 1;
break; break;
case "%Y": case "%Y":
var year = date[i]; year = date[i];
break; break;
case "%y": case "%y":
var year = date[i]; year = date[i];
break; break;
} }
++i; ++i;
}; }
return new Date(year, month, day); return new Date(year, month, day);
} };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Get the computed style for and element // Get the computed style for and element
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
function getStyle(oElm, strCssRule){ function getStyle(oElm, strCssRule) {
var strValue = ""; var strValue = "";
if(document.defaultView && document.defaultView.getComputedStyle){ if(document.defaultView && document.defaultView.getComputedStyle) {
strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule); strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
} }
else if(oElm.currentStyle){ else if(oElm.currentStyle) {
strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){ strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1) {
return p1.toUpperCase(); return p1.toUpperCase();
}); });
strValue = oElm.currentStyle[strCssRule]; strValue = oElm.currentStyle[strCssRule];
......
(function(c){c.fn.formset=function(b){var a=c.extend({},c.fn.formset.defaults,b),d=c(this);b=d.parent();var k=function(a,f,l){var h=new RegExp("("+f+"-(\\d+|__prefix__))");f=f+"-"+l;c(a).prop("for")&&c(a).prop("for",c(a).prop("for").replace(h,f));a.id&&(a.id=a.id.replace(h,f));a.name&&(a.name=a.name.replace(h,f))},e=c("#id_"+a.prefix+"-TOTAL_FORMS").prop("autocomplete","off"),l=parseInt(e.val(),10),f=c("#id_"+a.prefix+"-MAX_NUM_FORMS").prop("autocomplete","off"),e=""===f.val()||0<f.val()-e.val(); (function(c){c.fn.formset=function(b){var a=c.extend({},c.fn.formset.defaults,b),d=c(this);b=d.parent();var k=function(a,g,l){var h=new RegExp("("+g+"-(\\d+|__prefix__))");g=g+"-"+l;c(a).prop("for")&&c(a).prop("for",c(a).prop("for").replace(h,g));a.id&&(a.id=a.id.replace(h,g));a.name&&(a.name=a.name.replace(h,g))},f=c("#id_"+a.prefix+"-TOTAL_FORMS").prop("autocomplete","off"),l=parseInt(f.val(),10),g=c("#id_"+a.prefix+"-MAX_NUM_FORMS").prop("autocomplete","off"),f=""===g.val()||0<g.val()-f.val();
d.each(function(f){c(this).not("."+a.emptyCssClass).addClass(a.formCssClass)});if(d.length&&e){var h;"TR"==d.prop("tagName")?(d=this.eq(-1).children().length,b.append('<tr class="'+a.addCssClass+'"><td colspan="'+d+'"><a href="javascript:void(0)">'+a.addText+"</a></tr>"),h=b.find("tr:last a")):(d.filter(":last").after('<div class="'+a.addCssClass+'"><a href="javascript:void(0)">'+a.addText+"</a></div>"),h=d.filter(":last").next().find("a"));h.click(function(b){b.preventDefault();var d=c("#id_"+a.prefix+ d.each(function(g){c(this).not("."+a.emptyCssClass).addClass(a.formCssClass)});if(d.length&&f){var h;"TR"==d.prop("tagName")?(d=this.eq(-1).children().length,b.append('<tr class="'+a.addCssClass+'"><td colspan="'+d+'"><a href="javascript:void(0)">'+a.addText+"</a></tr>"),h=b.find("tr:last a")):(d.filter(":last").after('<div class="'+a.addCssClass+'"><a href="javascript:void(0)">'+a.addText+"</a></div>"),h=d.filter(":last").next().find("a"));h.click(function(b){b.preventDefault();var d=c("#id_"+a.prefix+
"-TOTAL_FORMS");b=c("#"+a.prefix+"-empty");var g=b.clone(!0);g.removeClass(a.emptyCssClass).addClass(a.formCssClass).attr("id",a.prefix+"-"+l);g.is("tr")?g.children(":last").append('<div><a class="'+a.deleteCssClass+'" href="javascript:void(0)">'+a.deleteText+"</a></div>"):g.is("ul")||g.is("ol")?g.append('<li><a class="'+a.deleteCssClass+'" href="javascript:void(0)">'+a.deleteText+"</a></li>"):g.children(":first").append('<span><a class="'+a.deleteCssClass+'" href="javascript:void(0)">'+a.deleteText+ "-TOTAL_FORMS");b=c("#"+a.prefix+"-empty");var e=b.clone(!0);e.removeClass(a.emptyCssClass).addClass(a.formCssClass).attr("id",a.prefix+"-"+l);e.is("tr")?e.children(":last").append('<div><a class="'+a.deleteCssClass+'" href="javascript:void(0)">'+a.deleteText+"</a></div>"):e.is("ul")||e.is("ol")?e.append('<li><a class="'+a.deleteCssClass+'" href="javascript:void(0)">'+a.deleteText+"</a></li>"):e.children(":first").append('<span><a class="'+a.deleteCssClass+'" href="javascript:void(0)">'+a.deleteText+
"</a></span>");g.find("*").each(function(){k(this,a.prefix,d.val())});g.insertBefore(c(b));c(d).val(parseInt(d.val(),10)+1);l+=1;""!==f.val()&&0>=f.val()-d.val()&&h.parent().hide();g.find("a."+a.deleteCssClass).click(function(b){b.preventDefault();b=c(this).parents("."+a.formCssClass);b.remove();--l;a.removed&&a.removed(b);b=c("."+a.formCssClass);c("#id_"+a.prefix+"-TOTAL_FORMS").val(b.length);(""===f.val()||0<f.val()-b.length)&&h.parent().show();for(var d=0,g=b.length;d<g;d++)k(c(b).get(d),a.prefix, "</a></span>");e.find("*").each(function(){k(this,a.prefix,d.val())});e.insertBefore(c(b));c(d).val(parseInt(d.val(),10)+1);l+=1;""!==g.val()&&0>=g.val()-d.val()&&h.parent().hide();e.find("a."+a.deleteCssClass).click(function(b){b.preventDefault();b=c(this).parents("."+a.formCssClass);b.remove();--l;a.removed&&a.removed(b);b=c("."+a.formCssClass);c("#id_"+a.prefix+"-TOTAL_FORMS").val(b.length);(""===g.val()||0<g.val()-b.length)&&h.parent().show();for(var d=function(){k(this,a.prefix,e)},e=0,f=b.length;e<
d),c(b.get(d)).find("*").each(function(){k(this,a.prefix,d)})});a.added&&a.added(g)})}return this};c.fn.formset.defaults={prefix:"form",addText:"add another",deleteText:"remove",addCssClass:"add-row",deleteCssClass:"delete-row",emptyCssClass:"empty-row",formCssClass:"dynamic-form",added:null,removed:null};c.fn.tabularFormset=function(b){var a=c(this),d=function(b){c(a.selector).not(".add-row").removeClass("row1 row2").filter(":even").addClass("row1").end().filter(":odd").addClass("row2")},k=function(){"undefined"!= f;e++)k(c(b).get(e),a.prefix,e),c(b.get(e)).find("*").each(d)});a.added&&a.added(e)})}return this};c.fn.formset.defaults={prefix:"form",addText:"add another",deleteText:"remove",addCssClass:"add-row",deleteCssClass:"delete-row",emptyCssClass:"empty-row",formCssClass:"dynamic-form",added:null,removed:null};c.fn.tabularFormset=function(b){var a=c(this),d=function(b){c(a.selector).not(".add-row").removeClass("row1 row2").filter(":even").addClass("row1").end().filter(":odd").addClass("row2")},k=function(){"undefined"!=
typeof SelectFilter&&(c(".selectfilter").each(function(a,c){var b=c.name.split("-");SelectFilter.init(c.id,b[b.length-1],!1)}),c(".selectfilterstacked").each(function(a,c){var b=c.name.split("-");SelectFilter.init(c.id,b[b.length-1],!0)}))},e=function(a){a.find(".prepopulated_field").each(function(){var b=c(this).find("input, select, textarea"),d=b.data("dependency_list")||[],e=[];c.each(d,function(c,b){e.push("#"+a.find(".field-"+b).find("input, select, textarea").attr("id"))});e.length&&b.prepopulate(e, typeof SelectFilter&&(c(".selectfilter").each(function(a,c){var b=c.name.split("-");SelectFilter.init(c.id,b[b.length-1],!1)}),c(".selectfilterstacked").each(function(a,c){var b=c.name.split("-");SelectFilter.init(c.id,b[b.length-1],!0)}))},f=function(a){a.find(".prepopulated_field").each(function(){var b=c(this).find("input, select, textarea"),d=b.data("dependency_list")||[],f=[];c.each(d,function(c,b){f.push("#"+a.find(".field-"+b).find("input, select, textarea").attr("id"))});f.length&&b.prepopulate(f,
b.attr("maxlength"))})};a.formset({prefix:b.prefix,addText:b.addText,formCssClass:"dynamic-"+b.prefix,deleteCssClass:"inline-deletelink",deleteText:b.deleteText,emptyCssClass:"empty-form",removed:d,added:function(a){e(a);"undefined"!=typeof DateTimeShortcuts&&(c(".datetimeshortcuts").remove(),DateTimeShortcuts.init());k();d(a)}});return a};c.fn.stackedFormset=function(b){var a=c(this),d=function(b){c(a.selector).find(".inline_label").each(function(a){a+=1;c(this).html(c(this).html().replace(/(#\d+)/g, b.attr("maxlength"))})};a.formset({prefix:b.prefix,addText:b.addText,formCssClass:"dynamic-"+b.prefix,deleteCssClass:"inline-deletelink",deleteText:b.deleteText,emptyCssClass:"empty-form",removed:d,added:function(a){f(a);"undefined"!=typeof DateTimeShortcuts&&(c(".datetimeshortcuts").remove(),DateTimeShortcuts.init());k();d(a)}});return a};c.fn.stackedFormset=function(b){var a=c(this),d=function(b){c(a.selector).find(".inline_label").each(function(a){a+=1;c(this).html(c(this).html().replace(/(#\d+)/g,
"#"+a))})},k=function(){"undefined"!=typeof SelectFilter&&(c(".selectfilter").each(function(a,c){var b=c.name.split("-");SelectFilter.init(c.id,b[b.length-1],!1)}),c(".selectfilterstacked").each(function(a,c){var b=c.name.split("-");SelectFilter.init(c.id,b[b.length-1],!0)}))},e=function(a){a.find(".prepopulated_field").each(function(){var b=c(this).find("input, select, textarea"),d=b.data("dependency_list")||[],e=[];c.each(d,function(b,c){e.push("#"+a.find(".form-row .field-"+c).find("input, select, textarea").attr("id"))}); "#"+a))})},k=function(){"undefined"!=typeof SelectFilter&&(c(".selectfilter").each(function(a,c){var b=c.name.split("-");SelectFilter.init(c.id,b[b.length-1],!1)}),c(".selectfilterstacked").each(function(a,c){var b=c.name.split("-");SelectFilter.init(c.id,b[b.length-1],!0)}))},f=function(a){a.find(".prepopulated_field").each(function(){var b=c(this).find("input, select, textarea"),d=b.data("dependency_list")||[],f=[];c.each(d,function(b,c){f.push("#"+a.find(".form-row .field-"+c).find("input, select, textarea").attr("id"))});
e.length&&b.prepopulate(e,b.attr("maxlength"))})};a.formset({prefix:b.prefix,addText:b.addText,formCssClass:"dynamic-"+b.prefix,deleteCssClass:"inline-deletelink",deleteText:b.deleteText,emptyCssClass:"empty-form",removed:d,added:function(a){e(a);"undefined"!=typeof DateTimeShortcuts&&(c(".datetimeshortcuts").remove(),DateTimeShortcuts.init());k();d(a)}});return a}})(django.jQuery); f.length&&b.prepopulate(f,b.attr("maxlength"))})};a.formset({prefix:b.prefix,addText:b.addText,formCssClass:"dynamic-"+b.prefix,deleteCssClass:"inline-deletelink",deleteText:b.deleteText,emptyCssClass:"empty-form",removed:d,added:function(a){f(a);"undefined"!=typeof DateTimeShortcuts&&(c(".datetimeshortcuts").remove(),DateTimeShortcuts.init());k();d(a)}});return a}})(django.jQuery);
/*global django:true, jQuery:false*/
/* Puts the included jQuery into our own namespace using noConflict and passing /* Puts the included jQuery into our own namespace using noConflict and passing
* it 'true'. This ensures that the included jQuery doesn't pollute the global * it 'true'. This ensures that the included jQuery doesn't pollute the global
* namespace (i.e. this preserves pre-existing values for both window.$ and * namespace (i.e. this preserves pre-existing values for both window.$ and
......
/*global URLify*/
(function($) { (function($) {
$.fn.prepopulate = function(dependencies, maxLength) { $.fn.prepopulate = function(dependencies, maxLength) {
/* /*
......
(function(b){b.fn.prepopulate=function(e,g){return this.each(function(){var a=b(this),d=function(){if(!a.data("_changed")){var f=[];b.each(e,function(h,c){c=b(c);c.val().length>0&&f.push(c.val())});a.val(URLify(f.join(" "),g))}};a.data("_changed",false);a.change(function(){a.data("_changed",true)});a.val()||b(e.join(",")).keyup(d).change(d).focus(d)})}})(django.jQuery); (function(c){c.fn.prepopulate=function(e,f){return this.each(function(){var a=c(this),b=function(){if(!a.data("_changed")){var b=[];c.each(e,function(a,d){d=c(d);0<d.val().length&&b.push(d.val())});a.val(URLify(b.join(" "),f))}};a.data("_changed",!1);a.change(function(){a.data("_changed",!0)});a.val()||c(e.join(",")).keyup(b).change(b).focus(b)})}})(django.jQuery);
...@@ -2,7 +2,7 @@ var timeParsePatterns = [ ...@@ -2,7 +2,7 @@ var timeParsePatterns = [
// 9 // 9
{ re: /^\d{1,2}$/i, { re: /^\d{1,2}$/i,
handler: function(bits) { handler: function(bits) {
if (bits[0].length == 1) { if (bits[0].length === 1) {
return '0' + bits[0] + ':00'; return '0' + bits[0] + ':00';
} else { } else {
return bits[0] + ':00'; return bits[0] + ':00';
...@@ -25,11 +25,11 @@ var timeParsePatterns = [ ...@@ -25,11 +25,11 @@ var timeParsePatterns = [
{ re: /^(\d+)\s*([ap])(?:.?m.?)?$/i, { re: /^(\d+)\s*([ap])(?:.?m.?)?$/i,
handler: function(bits) { handler: function(bits) {
var hour = parseInt(bits[1]); var hour = parseInt(bits[1]);
if (hour == 12) { if (hour === 12) {
hour = 0; hour = 0;
} }
if (bits[2].toLowerCase() == 'p') { if (bits[2].toLowerCase() === 'p') {
if (hour == 12) { if (hour === 12) {
hour = 0; hour = 0;
} }
return (hour + 12) + ':00'; return (hour + 12) + ':00';
...@@ -50,11 +50,11 @@ var timeParsePatterns = [ ...@@ -50,11 +50,11 @@ var timeParsePatterns = [
if (mins < 10) { if (mins < 10) {
mins = '0' + mins; mins = '0' + mins;
} }
if (hour == 12) { if (hour === 12) {
hour = 0; hour = 0;
} }
if (bits[3].toLowerCase() == 'p') { if (bits[3].toLowerCase() === 'p') {
if (hour == 12) { if (hour === 12) {
hour = 0; hour = 0;
} }
return (hour + 12) + ':' + mins; return (hour + 12) + ':' + mins;
......
/*global OpenLayers*/
/*eslint indent:1*/
(function() { (function() {
/** /**
* Transforms an array of features to a single feature with the merged * Transforms an array of features to a single feature with the merged
* geometry of geom_type * geometry of geom_type
*/ */
OpenLayers.Util.properFeatures = function(features, geom_type) { OpenLayers.Util.properFeatures = function(features, geom_type) {
if (features.constructor == Array) { if (features.constructor === Array) {
var geoms = []; var geoms = [];
for (var i=0; i<features.length; i++) { for (var i=0; i<features.length; i++) {
geoms.push(features[i].geometry); geoms.push(features[i].geometry);
...@@ -13,7 +15,7 @@ OpenLayers.Util.properFeatures = function(features, geom_type) { ...@@ -13,7 +15,7 @@ OpenLayers.Util.properFeatures = function(features, geom_type) {
features = new OpenLayers.Feature.Vector(geom); features = new OpenLayers.Feature.Vector(geom);
} }
return features; return features;
} };
/** /**
* @requires OpenLayers/Format/WKT.js * @requires OpenLayers/Format/WKT.js
...@@ -128,7 +130,7 @@ OpenLayers.Format.DjangoWKT = OpenLayers.Class(OpenLayers.Format.WKT, { ...@@ -128,7 +130,7 @@ OpenLayers.Format.DjangoWKT = OpenLayers.Class(OpenLayers.Format.WKT, {
geometry = geometry.clone(); geometry = geometry.clone();
geometry.transform(this.internalProjection, this.externalProjection); geometry.transform(this.internalProjection, this.externalProjection);
} }
var wktType = type == 'collection' ? 'GEOMETRYCOLLECTION' : type.toUpperCase(); var wktType = type === 'collection' ? 'GEOMETRYCOLLECTION' : type.toUpperCase();
var data = wktType + '(' + this.extract[type].apply(this, [geometry]) + ')'; var data = wktType + '(' + this.extract[type].apply(this, [geometry]) + ')';
return data; return data;
}, },
...@@ -138,8 +140,8 @@ OpenLayers.Format.DjangoWKT = OpenLayers.Class(OpenLayers.Format.WKT, { ...@@ -138,8 +140,8 @@ OpenLayers.Format.DjangoWKT = OpenLayers.Class(OpenLayers.Format.WKT, {
* geometrycollections. * geometrycollections.
*/ */
write: function(features) { write: function(features) {
var collection, geometry, type, data, isCollection; var collection, isCollection;
isCollection = features.geometry.CLASS_NAME == "OpenLayers.Geometry.Collection"; isCollection = features.geometry.CLASS_NAME === "OpenLayers.Geometry.Collection";
var pieces = []; var pieces = [];
if (isCollection) { if (isCollection) {
collection = features.geometry.components; collection = features.geometry.components;
...@@ -168,8 +170,8 @@ function MapWidget(options) { ...@@ -168,8 +170,8 @@ function MapWidget(options) {
this.wkt_f = new OpenLayers.Format.DjangoWKT(); this.wkt_f = new OpenLayers.Format.DjangoWKT();
// Mapping from OGRGeomType name to OpenLayers.Geometry name // Mapping from OGRGeomType name to OpenLayers.Geometry name
if (options['geom_name'] == 'Unknown') options['geom_type'] = OpenLayers.Geometry; if (options['geom_name'] === 'Unknown') options['geom_type'] = OpenLayers.Geometry;
else if (options['geom_name'] == 'GeometryCollection') options['geom_type'] = OpenLayers.Geometry.Collection; else if (options['geom_name'] === 'GeometryCollection') options['geom_type'] = OpenLayers.Geometry.Collection;
else options['geom_type'] = eval('OpenLayers.Geometry.' + options['geom_name']); else options['geom_type'] = eval('OpenLayers.Geometry.' + options['geom_name']);
// Default options // Default options
...@@ -204,7 +206,7 @@ function MapWidget(options) { ...@@ -204,7 +206,7 @@ function MapWidget(options) {
'fillOpacity': this.options.opacity, 'fillOpacity': this.options.opacity,
'strokeColor': '#' + this.options.color 'strokeColor': '#' + this.options.color
}; };
if (this.options.geom_name == 'LineString') { if (this.options.geom_name === 'LineString') {
defaults_style['strokeWidth'] = 3; defaults_style['strokeWidth'] = 3;
} }
var styleMap = new OpenLayers.StyleMap({'default': OpenLayers.Util.applyDefaults(defaults_style, OpenLayers.Feature.Vector.style['default'])}); var styleMap = new OpenLayers.StyleMap({'default': OpenLayers.Util.applyDefaults(defaults_style, OpenLayers.Feature.Vector.style['default'])});
...@@ -222,7 +224,7 @@ function MapWidget(options) { ...@@ -222,7 +224,7 @@ function MapWidget(options) {
this.layers.vector.addFeatures([feat]); this.layers.vector.addFeatures([feat]);
} }
this.map.zoomToExtent(feat.geometry.getBounds()); this.map.zoomToExtent(feat.geometry.getBounds());
if (this.options.geom_name == 'Point') { if (this.options.geom_name === 'Point') {
this.map.zoomTo(this.options.point_zoom); this.map.zoomTo(this.options.point_zoom);
} }
} else { } else {
...@@ -262,7 +264,7 @@ MapWidget.prototype.create_map = function() { ...@@ -262,7 +264,7 @@ MapWidget.prototype.create_map = function() {
if (this.options.base_layer) this.layers.base = this.options.base_layer; if (this.options.base_layer) this.layers.base = this.options.base_layer;
else this.layers.base = new OpenLayers.Layer.WMS('OpenLayers WMS', 'http://vmap0.tiles.osgeo.org/wms/vmap0', {layers: 'basic'}); else this.layers.base = new OpenLayers.Layer.WMS('OpenLayers WMS', 'http://vmap0.tiles.osgeo.org/wms/vmap0', {layers: 'basic'});
map.addLayer(this.layers.base); map.addLayer(this.layers.base);
return map return map;
}; };
MapWidget.prototype.get_ewkt = function(feat) { MapWidget.prototype.get_ewkt = function(feat) {
...@@ -270,7 +272,7 @@ MapWidget.prototype.get_ewkt = function(feat) { ...@@ -270,7 +272,7 @@ MapWidget.prototype.get_ewkt = function(feat) {
}; };
MapWidget.prototype.read_wkt = function(wkt) { MapWidget.prototype.read_wkt = function(wkt) {
var prefix = 'SRID=' + this.options.map_srid + ';' var prefix = 'SRID=' + this.options.map_srid + ';';
if (wkt.indexOf(prefix) === 0) { if (wkt.indexOf(prefix) === 0) {
wkt = wkt.slice(prefix.length); wkt = wkt.slice(prefix.length);
} }
...@@ -296,7 +298,7 @@ MapWidget.prototype.add_wkt = function(event) { ...@@ -296,7 +298,7 @@ MapWidget.prototype.add_wkt = function(event) {
this.write_wkt(feat); this.write_wkt(feat);
} else { } else {
if (this.layers.vector.features.length > 1) { if (this.layers.vector.features.length > 1) {
old_feats = [this.layers.vector.features[0]]; var old_feats = [this.layers.vector.features[0]];
this.layers.vector.removeFeatures(old_feats); this.layers.vector.removeFeatures(old_feats);
this.layers.vector.destroyFeatures(old_feats); this.layers.vector.destroyFeatures(old_feats);
} }
...@@ -306,7 +308,7 @@ MapWidget.prototype.add_wkt = function(event) { ...@@ -306,7 +308,7 @@ MapWidget.prototype.add_wkt = function(event) {
MapWidget.prototype.modify_wkt = function(event) { MapWidget.prototype.modify_wkt = function(event) {
if (this.options.is_collection) { if (this.options.is_collection) {
if (this.options.geom_name == 'MultiPoint') { if (this.options.geom_name === 'MultiPoint') {
this.add_wkt(event); this.add_wkt(event);
return; return;
} else { } else {
...@@ -359,13 +361,13 @@ MapWidget.prototype.getControls = function(layer) { ...@@ -359,13 +361,13 @@ MapWidget.prototype.getControls = function(layer) {
this.controls = [new OpenLayers.Control.Navigation()]; this.controls = [new OpenLayers.Control.Navigation()];
if (!this.options.modifiable && layer.features.length) if (!this.options.modifiable && layer.features.length)
return; return;
if (this.options.geom_name.indexOf('LineString') >= 0 || this.options.geom_name == 'GeometryCollection' || this.options.geom_name == 'Unknown') { if (this.options.geom_name.indexOf('LineString') >= 0 || this.options.geom_name === 'GeometryCollection' || this.options.geom_name === 'Unknown') {
this.controls.push(new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'})); this.controls.push(new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'}));
} }
if (this.options.geom_name.indexOf('Polygon') >= 0 || this.options.geom_name == 'GeometryCollection' || this.options.geom_name == 'Unknown') { if (this.options.geom_name.indexOf('Polygon') >= 0 || this.options.geom_name === 'GeometryCollection' || this.options.geom_name === 'Unknown') {
this.controls.push(new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'})); this.controls.push(new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'}));
} }
if (this.options.geom_name.indexOf('Point') >= 0 || this.options.geom_name == 'GeometryCollection' || this.options.geom_name == 'Unknown') { if (this.options.geom_name.indexOf('Point') >= 0 || this.options.geom_name === 'GeometryCollection' || this.options.geom_name === 'Unknown') {
this.controls.push(new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'})); this.controls.push(new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'}));
} }
if (this.options.modifiable) { if (this.options.modifiable) {
......
...@@ -7,6 +7,11 @@ Please follow these coding standards when writing code for inclusion in Django. ...@@ -7,6 +7,11 @@ Please follow these coding standards when writing code for inclusion in Django.
Python style Python style
------------ ------------
* Please conform to the indentation style dictated in the ``.editorconfig``
file. We recommend using a text editor with `EditorConfig`_ support to avoid
indentation and whitespace issues. The Python files use 4 spaces for
indentation and the HTML files use 2 spaces.
* Unless otherwise specified, follow :pep:`8`. * Unless otherwise specified, follow :pep:`8`.
Use `flake8`_ to check for problems in this area. Note that our ``setup.cfg`` Use `flake8`_ to check for problems in this area. Note that our ``setup.cfg``
...@@ -286,4 +291,11 @@ Miscellaneous ...@@ -286,4 +291,11 @@ Miscellaneous
change to the ``AUTHORS`` file in your patch if you make more than a change to the ``AUTHORS`` file in your patch if you make more than a
single trivial change. single trivial change.
JavaScript style
----------------
For details about the JavaScript code style used by Django, see
:doc:`javascript`.
.. _editorconfig: http://editorconfig.org/
.. _flake8: https://pypi.python.org/pypi/flake8 .. _flake8: https://pypi.python.org/pypi/flake8
...@@ -13,3 +13,4 @@ chances to be included in Django core: ...@@ -13,3 +13,4 @@ chances to be included in Django core:
unit-tests unit-tests
submitting-patches submitting-patches
working-with-git working-with-git
javascript
==========
JavaScript
==========
While most of Django core is Python, the ``admin`` and ``gis`` contrib apps
contain JavaScript code.
Please follow these coding standards when writing JavaScript code for inclusion
in Django.
Code style
----------
* Please conform to the indentation style dictated in the ``.editorconfig``
file. We recommend using a text editor with `EditorConfig`_ support to avoid
indentation and whitespace issues. Most of the JavaScript files use 4 spaces
for indentation, but there are some exceptions.
* When naming variables, use ``camelCase`` instead of ``underscore_case``.
Different JavaScript files sometimes use a different code style. Please try to
conform to the code style of each file.
* Use the `JSHint`_ code linter to check your code for bugs and style errors.
JSHint will be run when you run the JavaScript tests. We also recommended
installing a JSHint plugin in your text editor.
.. _javascript-patches:
JavaScript patches
------------------
Django's admin system leverages the jQuery framework to increase the
capabilities of the admin interface. In conjunction, there is an emphasis on
admin JavaScript performance and minimizing overall admin media file size.
Serving compressed or "minified" versions of JavaScript files is considered
best practice in this regard.
To that end, patches for JavaScript files should include both the original
code for future development (e.g. ``foo.js``), and a compressed version for
production use (e.g. ``foo.min.js``). Any links to the file in the codebase
should point to the compressed version.
Compressing JavaScript
~~~~~~~~~~~~~~~~~~~~~~
To simplify the process of providing optimized JavaScript code, Django
includes a handy Python script which should be used to create a "minified"
version. To run it::
python django/contrib/admin/bin/compress.py
Behind the scenes, ``compress.py`` is a front-end for Google's
`Closure Compiler`_ which is written in Java. However, the Closure Compiler
library is not bundled with Django directly, so those wishing to contribute
complete JavaScript patches will need to download and install the library
independently. The Closure Compiler library requires `Java`_ 7 or higher.
Please don't forget to run ``compress.py`` and include the ``diff`` of the
minified scripts when submitting patches for Django's JavaScript.
.. _Closure Compiler: https://developers.google.com/closure/compiler/
.. _EditorConfig: http://editorconfig.org/
.. _Java: https://www.java.com
.. _jshint: http://jshint.com/
...@@ -145,6 +145,8 @@ Regardless of the way you submit your work, follow these steps. ...@@ -145,6 +145,8 @@ Regardless of the way you submit your work, follow these steps.
obvious that the ticket includes a patch, and it will add the ticket to obvious that the ticket includes a patch, and it will add the ticket to
the `list of tickets with patches`_. the `list of tickets with patches`_.
.. _list of tickets with patches: https://code.djangoproject.com/query?status=new&status=assigned&status=reopened&has_patch=1&order=priority
.. _ticket tracker: https://code.djangoproject.com/newticket
Non-trivial patches Non-trivial patches
------------------- -------------------
...@@ -245,39 +247,8 @@ the new version are removed. ...@@ -245,39 +247,8 @@ the new version are removed.
JavaScript patches JavaScript patches
------------------ ------------------
Django's admin system leverages the jQuery framework to increase the For information on JavaScript patches, see the :ref:`javascript-patches`
capabilities of the admin interface. In conjunction, there is an emphasis on documentation.
admin JavaScript performance and minimizing overall admin media file size.
Serving compressed or "minified" versions of JavaScript files is considered
best practice in this regard.
To that end, patches for JavaScript files should include both the original
code for future development (e.g. ``foo.js``), and a compressed version for
production use (e.g. ``foo.min.js``). Any links to the file in the codebase
should point to the compressed version.
Compressing JavaScript
~~~~~~~~~~~~~~~~~~~~~~
To simplify the process of providing optimized JavaScript code, Django
includes a handy Python script which should be used to create a "minified"
version. To run it::
python django/contrib/admin/bin/compress.py
Behind the scenes, ``compress.py`` is a front-end for Google's
`Closure Compiler`_ which is written in Java. However, the Closure Compiler
library is not bundled with Django directly, so those wishing to contribute
complete JavaScript patches will need to download and install the library
independently. The Closure Compiler library requires `Java`_ 7 or higher.
Please don't forget to run ``compress.py`` and include the ``diff`` of the
minified scripts when submitting patches for Django's JavaScript.
.. _Closure Compiler: https://developers.google.com/closure/compiler/
.. _list of tickets with patches: https://code.djangoproject.com/query?status=new&status=assigned&status=reopened&has_patch=1&order=priority
.. _ticket tracker: https://code.djangoproject.com/newticket
.. _Java: https://www.java.com
.. _patch-review-checklist: .. _patch-review-checklist:
......
{
"name": "Django",
"private": true,
"scripts": {
"pretest": "eslint django/"
},
"devDependencies": {
"eslint": "^0.22.1"
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment