Fixed JavaScript "strict" violations.

This commit is contained in:
Tim Graham 2015-07-20 19:35:17 -04:00
parent 3c0770f23d
commit fbb4f0797c
13 changed files with 1118 additions and 1062 deletions

View File

@ -1,5 +1,7 @@
/*eslint no-cond-assign:1*/ /*eslint no-cond-assign:1*/
var SelectBox = { (function() {
'use strict';
var SelectBox = {
cache: {}, cache: {},
init: function(id) { init: function(id) {
var box = document.getElementById(id); var box = document.getElementById(id);
@ -114,4 +116,6 @@ var SelectBox = {
box.options[i].selected = 'selected'; box.options[i].selected = 'selected';
} }
} }
}; };
window.SelectBox = SelectBox;
})();

View File

@ -5,6 +5,7 @@ SelectFilter2 - Turns a multiple-select box into a filter interface.
Requires core.js, SelectBox.js and addevent.js. Requires core.js, SelectBox.js and addevent.js.
*/ */
(function($) { (function($) {
'use strict';
function findForm(node) { function findForm(node) {
// returns the node of the form containing the given node // returns the node of the form containing the given node
if (node.tagName.toLowerCase() !== 'form') { if (node.tagName.toLowerCase() !== 'form') {

View File

@ -1,5 +1,6 @@
/*global _actions_icnt, gettext, interpolate, ngettext*/ /*global _actions_icnt, gettext, interpolate, ngettext*/
(function($) { (function($) {
'use strict';
var lastChecked; var lastChecked;
$.fn.actions = function(opts) { $.fn.actions = function(opts) {

View File

@ -2,8 +2,9 @@
// 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">
(function() {
var DateTimeShortcuts = { 'use strict';
var DateTimeShortcuts = {
calendars: [], calendars: [],
calendarInputs: [], calendarInputs: [],
clockInputs: [], clockInputs: [],
@ -356,6 +357,8 @@ var DateTimeShortcuts = {
DateTimeShortcuts.calendarInputs[num].focus(); DateTimeShortcuts.calendarInputs[num].focus();
DateTimeShortcuts.dismissCalendar(num); DateTimeShortcuts.dismissCalendar(num);
} }
}; };
addEvent(window, 'load', DateTimeShortcuts.init); addEvent(window, 'load', DateTimeShortcuts.init);
window.DateTimeShortcuts = DateTimeShortcuts;
})();

View File

@ -2,7 +2,10 @@
// 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.
function html_unescape(text) { (function() {
'use strict';
function html_unescape(text) {
// Unescape a string that was escaped using django.utils.html.escape. // Unescape a string that was escaped using django.utils.html.escape.
text = text.replace(/&lt;/g, '<'); text = text.replace(/&lt;/g, '<');
text = text.replace(/&gt;/g, '>'); text = text.replace(/&gt;/g, '>');
@ -10,25 +13,25 @@ function html_unescape(text) {
text = text.replace(/&#39;/g, "'"); text = text.replace(/&#39;/g, "'");
text = text.replace(/&amp;/g, '&'); text = text.replace(/&amp;/g, '&');
return text; return text;
} }
// IE doesn't accept periods or dashes in the window name, but the element IDs // IE doesn't accept periods or dashes in the window name, but the element IDs
// we use to generate popup window names may contain them, therefore we map them // we use to generate popup window names may contain them, therefore we map them
// to allowed characters in a reversible way so that we can locate the correct // to allowed characters in a reversible way so that we can locate the correct
// element when the popup window is dismissed. // element when the popup window is dismissed.
function id_to_windowname(text) { function id_to_windowname(text) {
text = text.replace(/\./g, '__dot__'); text = text.replace(/\./g, '__dot__');
text = text.replace(/\-/g, '__dash__'); text = text.replace(/\-/g, '__dash__');
return text; return text;
} }
function windowname_to_id(text) { function windowname_to_id(text) {
text = text.replace(/__dot__/g, '.'); text = text.replace(/__dot__/g, '.');
text = text.replace(/__dash__/g, '-'); text = text.replace(/__dash__/g, '-');
return text; return text;
} }
function showAdminPopup(triggeringLink, name_regexp, add_popup) { function showAdminPopup(triggeringLink, name_regexp, add_popup) {
var name = triggeringLink.id.replace(name_regexp, ''); var name = triggeringLink.id.replace(name_regexp, '');
name = id_to_windowname(name); name = id_to_windowname(name);
var href = triggeringLink.href; var href = triggeringLink.href;
@ -42,13 +45,13 @@ function showAdminPopup(triggeringLink, name_regexp, add_popup) {
var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes'); var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes');
win.focus(); win.focus();
return false; return false;
} }
function showRelatedObjectLookupPopup(triggeringLink) { function showRelatedObjectLookupPopup(triggeringLink) {
return showAdminPopup(triggeringLink, /^lookup_/, true); return showAdminPopup(triggeringLink, /^lookup_/, true);
} }
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) {
@ -57,13 +60,13 @@ function dismissRelatedLookupPopup(win, chosenId) {
document.getElementById(name).value = chosenId; document.getElementById(name).value = chosenId;
} }
win.close(); win.close();
} }
function showRelatedObjectPopup(triggeringLink) { function showRelatedObjectPopup(triggeringLink) {
return showAdminPopup(triggeringLink, /^(change|add|delete)_/, false); return showAdminPopup(triggeringLink, /^(change|add|delete)_/, false);
} }
function updateRelatedObjectLinks(triggeringLink) { function updateRelatedObjectLinks(triggeringLink) {
var $this = django.jQuery(triggeringLink); var $this = django.jQuery(triggeringLink);
var siblings = $this.nextAll('.change-related, .delete-related'); var siblings = $this.nextAll('.change-related, .delete-related');
if (!siblings.length) { if (!siblings.length) {
@ -78,9 +81,9 @@ function updateRelatedObjectLinks(triggeringLink) {
} else { } else {
siblings.removeAttr('href'); siblings.removeAttr('href');
} }
} }
function dismissAddRelatedObjectPopup(win, newId, newRepr) { function dismissAddRelatedObjectPopup(win, newId, newRepr) {
// newId and newRepr are expected to have previously been escaped by // newId and newRepr are expected to have previously been escaped by
// django.utils.html.escape. // django.utils.html.escape.
newId = html_unescape(newId); newId = html_unescape(newId);
@ -107,9 +110,9 @@ function dismissAddRelatedObjectPopup(win, newId, newRepr) {
SelectBox.redisplay(toId); SelectBox.redisplay(toId);
} }
win.close(); win.close();
} }
function dismissChangeRelatedObjectPopup(win, objId, newRepr, newId) { function dismissChangeRelatedObjectPopup(win, objId, newRepr, newId) {
objId = html_unescape(objId); objId = html_unescape(objId);
newRepr = html_unescape(newRepr); newRepr = html_unescape(newRepr);
var id = windowname_to_id(win.name).replace(/^edit_/, ''); var id = windowname_to_id(win.name).replace(/^edit_/, '');
@ -122,9 +125,9 @@ function dismissChangeRelatedObjectPopup(win, objId, newRepr, newId) {
} }
}); });
win.close(); win.close();
} }
function dismissDeleteRelatedObjectPopup(win, objId) { function dismissDeleteRelatedObjectPopup(win, objId) {
objId = html_unescape(objId); objId = html_unescape(objId);
var id = windowname_to_id(win.name).replace(/^delete_/, ''); var id = windowname_to_id(win.name).replace(/^delete_/, '');
var selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]); var selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]);
@ -135,8 +138,23 @@ function dismissDeleteRelatedObjectPopup(win, objId) {
} }
}).trigger('change'); }).trigger('change');
win.close(); win.close();
} }
// Kept for backward compatibility // Global for testing purposes
var showAddAnotherPopup = showRelatedObjectPopup; window.html_unescape = html_unescape;
var dismissAddAnotherPopup = dismissAddRelatedObjectPopup; window.id_to_windowname = id_to_windowname;
window.windowname_to_id = windowname_to_id;
window.showRelatedObjectLookupPopup = showRelatedObjectLookupPopup;
window.dismissRelatedLookupPopup = dismissRelatedLookupPopup;
window.showRelatedObjectPopup = showRelatedObjectPopup;
window.updateRelatedObjectLinks = updateRelatedObjectLinks;
window.dismissAddRelatedObjectPopup = dismissAddRelatedObjectPopup;
window.dismissChangeRelatedObjectPopup = dismissChangeRelatedObjectPopup;
window.dismissDeleteRelatedObjectPopup = dismissDeleteRelatedObjectPopup;
// Kept for backward compatibility
window.showAddAnotherPopup = showRelatedObjectPopup;
window.dismissAddAnotherPopup = dismissAddRelatedObjectPopup;
})();

View File

@ -4,8 +4,10 @@ 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
*/ */
// CalendarNamespace -- Provides a collection of HTML calendar-related helper functions (function() {
var CalendarNamespace = { 'use strict';
// 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(' '), monthsOfYear: gettext('January February March April May June July August September October November December').split(' '),
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')),
@ -111,10 +113,10 @@ var CalendarNamespace = {
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) {
// div_id (string) is the ID of the element in which the calendar will // div_id (string) is the ID of the element in which the calendar will
// be displayed // be displayed
// callback (string) is the name of a JavaScript function that will be // callback (string) is the name of a JavaScript function that will be
@ -128,8 +130,8 @@ function Calendar(div_id, callback, selected) {
if (typeof selected !== 'undefined') { if (typeof selected !== 'undefined') {
this.selected = selected; this.selected = selected;
} }
} }
Calendar.prototype = { Calendar.prototype = {
drawCurrent: function() { drawCurrent: function() {
CalendarNamespace.draw(this.currentMonth, this.currentYear, this.div_id, this.callback, this.selected); CalendarNamespace.draw(this.currentMonth, this.currentYear, this.div_id, this.callback, this.selected);
}, },
@ -171,4 +173,6 @@ Calendar.prototype = {
this.currentYear++; this.currentYear++;
this.drawCurrent(); this.drawCurrent();
} }
}; };
window.Calendar = Calendar;
})();

View File

@ -1,5 +1,6 @@
/*global gettext*/ /*global gettext*/
(function($) { (function($) {
'use strict';
$(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) {

View File

@ -6,6 +6,7 @@ var isIE = ((document.all) && (!isOpera)) && parseFloat(navigator.appVersion.spl
// Cross-browser event handlers. // Cross-browser event handlers.
function addEvent(obj, evType, fn) { function addEvent(obj, evType, fn) {
'use strict';
if (obj.addEventListener) { if (obj.addEventListener) {
obj.addEventListener(evType, fn, false); obj.addEventListener(evType, fn, false);
return true; return true;
@ -18,6 +19,7 @@ function addEvent(obj, evType, fn) {
} }
function removeEvent(obj, evType, fn) { function removeEvent(obj, evType, fn) {
'use strict';
if (obj.removeEventListener) { if (obj.removeEventListener) {
obj.removeEventListener(evType, fn, false); obj.removeEventListener(evType, fn, false);
return true; return true;
@ -30,6 +32,7 @@ function removeEvent(obj, evType, fn) {
} }
function cancelEventPropagation(e) { function cancelEventPropagation(e) {
'use strict';
if (!e) { if (!e) {
e = window.event; e = window.event;
} }
@ -41,6 +44,7 @@ function cancelEventPropagation(e) {
// quickElement(tagType, parentReference [, textInChildNode, attribute, attributeValue ...]); // quickElement(tagType, parentReference [, textInChildNode, attribute, attributeValue ...]);
function quickElement() { function quickElement() {
'use strict';
var obj = document.createElement(arguments[0]); var obj = document.createElement(arguments[0]);
if (arguments[2]) { if (arguments[2]) {
var textNode = document.createTextNode(arguments[2]); var textNode = document.createTextNode(arguments[2]);
@ -56,6 +60,7 @@ function quickElement() {
// "a" is reference to an object // "a" is reference to an object
function removeChildren(a) { function removeChildren(a) {
'use strict';
while (a.hasChildNodes()) { while (a.hasChildNodes()) {
a.removeChild(a.lastChild); a.removeChild(a.lastChild);
} }
@ -89,6 +94,7 @@ if (!xmlhttp && typeof XMLHttpRequest !== 'undefined') {
// See http://www.quirksmode.org/js/findpos.html // See http://www.quirksmode.org/js/findpos.html
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
function findPosX(obj) { function findPosX(obj) {
'use strict';
var curleft = 0; var curleft = 0;
if (obj.offsetParent) { if (obj.offsetParent) {
while (obj.offsetParent) { while (obj.offsetParent) {
@ -106,6 +112,7 @@ function findPosX(obj) {
} }
function findPosY(obj) { function findPosY(obj) {
'use strict';
var curtop = 0; var curtop = 0;
if (obj.offsetParent) { if (obj.offsetParent) {
while (obj.offsetParent) { while (obj.offsetParent) {
@ -125,8 +132,9 @@ function findPosY(obj) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Date object extensions // Date object extensions
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
(function() {
Date.prototype.getTwelveHours = function() { 'use strict';
Date.prototype.getTwelveHours = function() {
var hours = this.getHours(); var hours = this.getHours();
if (hours === 0) { if (hours === 0) {
return 12; return 12;
@ -134,41 +142,41 @@ Date.prototype.getTwelveHours = function() {
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 = {
c: this.toString(), c: this.toString(),
d: this.getTwoDigitDate(), d: this.getTwoDigitDate(),
@ -197,20 +205,20 @@ Date.prototype.strftime = function(format) {
++i; ++i;
} }
return result; return result;
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// String object extensions // String object extensions
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
String.prototype.pad_left = function(pad_length, pad_string) { String.prototype.pad_left = function(pad_length, pad_string) {
var new_string = this; var new_string = this;
for (var i = 0; new_string.length < pad_length; i++) { for (var i = 0; new_string.length < pad_length; i++) {
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;
@ -233,12 +241,14 @@ String.prototype.strptime = function(format) {
++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) {
'use strict';
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);

View File

@ -16,6 +16,7 @@
* See: http://www.opensource.org/licenses/bsd-license.php * See: http://www.opensource.org/licenses/bsd-license.php
*/ */
(function($) { (function($) {
'use strict';
$.fn.formset = function(opts) { $.fn.formset = function(opts) {
var options = $.extend({}, $.fn.formset.defaults, opts); var options = $.extend({}, $.fn.formset.defaults, opts);
var $this = $(this); var $this = $(this);

View File

@ -1,5 +1,6 @@
/*global URLify*/ /*global URLify*/
(function($) { (function($) {
'use strict';
$.fn.prepopulate = function(dependencies, maxLength, allowUnicode) { $.fn.prepopulate = function(dependencies, maxLength, allowUnicode) {
/* /*
Depends on urlify.js Depends on urlify.js

View File

@ -1,4 +1,6 @@
var timeParsePatterns = [ (function() {
'use strict';
var timeParsePatterns = [
// 9 // 9
{ {
re: /^\d{1,2}$/i, re: /^\d{1,2}$/i,
@ -86,9 +88,9 @@ var timeParsePatterns = [
return '00:00'; return '00:00';
} }
} }
]; ];
function parseTimeString(s) { function parseTimeString(s) {
for (var i = 0; i < timeParsePatterns.length; i++) { for (var i = 0; i < timeParsePatterns.length; i++) {
var re = timeParsePatterns[i].re; var re = timeParsePatterns[i].re;
var handler = timeParsePatterns[i].handler; var handler = timeParsePatterns[i].handler;
@ -98,4 +100,7 @@ function parseTimeString(s) {
} }
} }
return s; return s;
} }
window.parseTimeString = parseTimeString;
})();

View File

@ -1,5 +1,8 @@
/*global XRegExp*/ /*global XRegExp*/
var LATIN_MAP = { (function() {
'use strict';
var LATIN_MAP = {
'À': 'A', 'Á': 'A', 'Â': 'A', 'Ã': 'A', 'Ä': 'A', 'Å': 'A', 'Æ': 'AE', 'À': 'A', 'Á': 'A', 'Â': 'A', 'Ã': 'A', 'Ä': 'A', 'Å': 'A', 'Æ': 'AE',
'Ç': 'C', 'È': 'E', 'É': 'E', 'Ê': 'E', 'Ë': 'E', 'Ì': 'I', 'Í': 'I', 'Ç': 'C', 'È': 'E', 'É': 'E', 'Ê': 'E', 'Ë': 'E', 'Ì': 'I', 'Í': 'I',
'Î': 'I', 'Ï': 'I', 'Ð': 'D', 'Ñ': 'N', 'Ò': 'O', 'Ó': 'O', 'Ô': 'O', 'Î': 'I', 'Ï': 'I', 'Ð': 'D', 'Ñ': 'N', 'Ò': 'O', 'Ó': 'O', 'Ô': 'O',
@ -10,11 +13,11 @@ var LATIN_MAP = {
'ï': 'i', 'ð': 'd', 'ñ': 'n', 'ò': 'o', 'ó': 'o', 'ô': 'o', 'õ': 'o', 'ï': 'i', 'ð': 'd', 'ñ': 'n', 'ò': 'o', 'ó': 'o', 'ô': 'o', 'õ': 'o',
'ö': 'o', 'ő': 'o', 'ø': 'o', 'ù': 'u', 'ú': 'u', 'û': 'u', 'ü': 'u', 'ö': 'o', 'ő': 'o', 'ø': 'o', 'ù': 'u', 'ú': 'u', 'û': 'u', 'ü': 'u',
'ű': 'u', 'ý': 'y', 'þ': 'th', 'ÿ': 'y' 'ű': 'u', 'ý': 'y', 'þ': 'th', 'ÿ': 'y'
}; };
var LATIN_SYMBOLS_MAP = { var LATIN_SYMBOLS_MAP = {
'©': '(c)' '©': '(c)'
}; };
var GREEK_MAP = { var GREEK_MAP = {
'α': 'a', 'β': 'b', 'γ': 'g', 'δ': 'd', 'ε': 'e', 'ζ': 'z', 'η': 'h', 'α': 'a', 'β': 'b', 'γ': 'g', 'δ': 'd', 'ε': 'e', 'ζ': 'z', 'η': 'h',
'θ': '8', 'ι': 'i', 'κ': 'k', 'λ': 'l', 'μ': 'm', 'ν': 'n', 'ξ': '3', 'θ': '8', 'ι': 'i', 'κ': 'k', 'λ': 'l', 'μ': 'm', 'ν': 'n', 'ξ': '3',
'ο': 'o', 'π': 'p', 'ρ': 'r', 'σ': 's', 'τ': 't', 'υ': 'y', 'φ': 'f', 'ο': 'o', 'π': 'p', 'ρ': 'r', 'σ': 's', 'τ': 't', 'υ': 'y', 'φ': 'f',
@ -25,16 +28,16 @@ var GREEK_MAP = {
'Ξ': '3', 'Ο': 'O', 'Π': 'P', 'Ρ': 'R', 'Σ': 'S', 'Τ': 'T', 'Υ': 'Y', 'Ξ': '3', 'Ο': 'O', 'Π': 'P', 'Ρ': 'R', 'Σ': 'S', 'Τ': 'T', 'Υ': 'Y',
'Φ': 'F', 'Χ': 'X', 'Ψ': 'PS', 'Ω': 'W', 'Ά': 'A', 'Έ': 'E', 'Ί': 'I', 'Φ': 'F', 'Χ': 'X', 'Ψ': 'PS', 'Ω': 'W', 'Ά': 'A', 'Έ': 'E', 'Ί': 'I',
'Ό': 'O', 'Ύ': 'Y', 'Ή': 'H', 'Ώ': 'W', 'Ϊ': 'I', 'Ϋ': 'Y' 'Ό': 'O', 'Ύ': 'Y', 'Ή': 'H', 'Ώ': 'W', 'Ϊ': 'I', 'Ϋ': 'Y'
}; };
var TURKISH_MAP = { var TURKISH_MAP = {
'ş': 's', 'Ş': 'S', 'ı': 'i', 'İ': 'I', 'ç': 'c', 'Ç': 'C', 'ü': 'u', 'ş': 's', 'Ş': 'S', 'ı': 'i', 'İ': 'I', 'ç': 'c', 'Ç': 'C', 'ü': 'u',
'Ü': 'U', 'ö': 'o', 'Ö': 'O', 'ğ': 'g', 'Ğ': 'G' 'Ü': 'U', 'ö': 'o', 'Ö': 'O', 'ğ': 'g', 'Ğ': 'G'
}; };
var ROMANIAN_MAP = { var ROMANIAN_MAP = {
'ă': 'a', 'î': 'i', 'ș': 's', 'ț': 't', 'â': 'a', 'ă': 'a', 'î': 'i', 'ș': 's', 'ț': 't', 'â': 'a',
'Ă': 'A', 'Î': 'I', 'Ș': 'S', 'Ț': 'T', 'Â': 'A' 'Ă': 'A', 'Î': 'I', 'Ș': 'S', 'Ț': 'T', 'Â': 'A'
}; };
var RUSSIAN_MAP = { var RUSSIAN_MAP = {
'а': 'a', 'б': 'b', 'в': 'v', 'г': 'g', 'д': 'd', 'е': 'e', 'ё': 'yo', 'а': 'a', 'б': 'b', 'в': 'v', 'г': 'g', 'д': 'd', 'е': 'e', 'ё': 'yo',
'ж': 'zh', 'з': 'z', 'и': 'i', 'й': 'j', 'к': 'k', 'л': 'l', 'м': 'm', 'ж': 'zh', 'з': 'z', 'и': 'i', 'й': 'j', 'к': 'k', 'л': 'l', 'м': 'm',
'н': 'n', 'о': 'o', 'п': 'p', 'р': 'r', 'с': 's', 'т': 't', 'у': 'u', 'н': 'n', 'о': 'o', 'п': 'p', 'р': 'r', 'с': 's', 'т': 't', 'у': 'u',
@ -45,50 +48,51 @@ var RUSSIAN_MAP = {
'Н': 'N', 'О': 'O', 'П': 'P', 'Р': 'R', 'С': 'S', 'Т': 'T', 'У': 'U', 'Н': 'N', 'О': 'O', 'П': 'P', 'Р': 'R', 'С': 'S', 'Т': 'T', 'У': 'U',
'Ф': 'F', 'Х': 'H', 'Ц': 'C', 'Ч': 'Ch', 'Ш': 'Sh', 'Щ': 'Sh', 'Ъ': '', 'Ф': 'F', 'Х': 'H', 'Ц': 'C', 'Ч': 'Ch', 'Ш': 'Sh', 'Щ': 'Sh', 'Ъ': '',
'Ы': 'Y', 'Ь': '', 'Э': 'E', 'Ю': 'Yu', 'Я': 'Ya' 'Ы': 'Y', 'Ь': '', 'Э': 'E', 'Ю': 'Yu', 'Я': 'Ya'
}; };
var UKRAINIAN_MAP = { var UKRAINIAN_MAP = {
'Є': 'Ye', 'І': 'I', 'Ї': 'Yi', 'Ґ': 'G', 'є': 'ye', 'і': 'i', 'ї': 'yi', 'Є': 'Ye', 'І': 'I', 'Ї': 'Yi', 'Ґ': 'G', 'є': 'ye', 'і': 'i',
'ґ': 'g' 'ї': 'yi', 'ґ': 'g'
}; };
var CZECH_MAP = { var CZECH_MAP = {
'č': 'c', 'ď': 'd', 'ě': 'e', 'ň': 'n', 'ř': 'r', 'š': 's', 'ť': 't', 'č': 'c', 'ď': 'd', 'ě': 'e', 'ň': 'n', 'ř': 'r', 'š': 's', 'ť': 't',
'ů': 'u', 'ž': 'z', 'Č': 'C', 'Ď': 'D', 'Ě': 'E', 'Ň': 'N', 'Ř': 'R', 'ů': 'u', 'ž': 'z', 'Č': 'C', 'Ď': 'D', 'Ě': 'E', 'Ň': 'N', 'Ř': 'R',
'Š': 'S', 'Ť': 'T', 'Ů': 'U', 'Ž': 'Z' 'Š': 'S', 'Ť': 'T', 'Ů': 'U', 'Ž': 'Z'
}; };
var POLISH_MAP = { var POLISH_MAP = {
'ą': 'a', 'ć': 'c', 'ę': 'e', 'ł': 'l', 'ń': 'n', 'ó': 'o', 'ś': 's', 'ą': 'a', 'ć': 'c', 'ę': 'e', 'ł': 'l', 'ń': 'n', 'ó': 'o', 'ś': 's',
'ź': 'z', 'ż': 'z', 'ź': 'z', 'ż': 'z',
'Ą': 'A', 'Ć': 'C', 'Ę': 'E', 'Ł': 'L', 'Ń': 'N', 'Ó': 'O', 'Ś': 'S', 'Ą': 'A', 'Ć': 'C', 'Ę': 'E', 'Ł': 'L', 'Ń': 'N', 'Ó': 'O', 'Ś': 'S',
'Ź': 'Z', 'Ż': 'Z' 'Ź': 'Z', 'Ż': 'Z'
}; };
var LATVIAN_MAP = { var LATVIAN_MAP = {
'ā': 'a', 'č': 'c', 'ē': 'e', 'ģ': 'g', 'ī': 'i', 'ķ': 'k', 'ļ': 'l', 'ā': 'a', 'č': 'c', 'ē': 'e', 'ģ': 'g', 'ī': 'i', 'ķ': 'k', 'ļ': 'l',
'ņ': 'n', 'š': 's', 'ū': 'u', 'ž': 'z', 'ņ': 'n', 'š': 's', 'ū': 'u', 'ž': 'z',
'Ā': 'A', 'Č': 'C', 'Ē': 'E', 'Ģ': 'G', 'Ī': 'I', 'Ķ': 'K', 'Ļ': 'L', 'Ā': 'A', 'Č': 'C', 'Ē': 'E', 'Ģ': 'G', 'Ī': 'I', 'Ķ': 'K', 'Ļ': 'L',
'Ņ': 'N', 'Š': 'S', 'Ū': 'U', 'Ž': 'Z' 'Ņ': 'N', 'Š': 'S', 'Ū': 'U', 'Ž': 'Z'
}; };
var ARABIC_MAP = { var ARABIC_MAP = {
'أ': 'a', 'ب': 'b', 'ت': 't', 'ث': 'th', 'ج': 'g', 'ح': 'h', 'خ': 'kh', 'د': 'd', 'أ': 'a', 'ب': 'b', 'ت': 't', 'ث': 'th', 'ج': 'g', 'ح': 'h', 'خ': 'kh', 'د': 'd',
'ذ': 'th', 'ر': 'r', 'ز': 'z', 'س': 's', 'ش': 'sh', 'ص': 's', 'ض': 'd', 'ط': 't', 'ذ': 'th', 'ر': 'r', 'ز': 'z', 'س': 's', 'ش': 'sh', 'ص': 's', 'ض': 'd', 'ط': 't',
'ظ': 'th', 'ع': 'aa', 'غ': 'gh', 'ف': 'f', 'ق': 'k', 'ك': 'k', 'ل': 'l', 'م': 'm', 'ظ': 'th', 'ع': 'aa', 'غ': 'gh', 'ف': 'f', 'ق': 'k', 'ك': 'k', 'ل': 'l', 'م': 'm',
'ن': 'n', 'ه': 'h', 'و': 'o', 'ي': 'y' 'ن': 'n', 'ه': 'h', 'و': 'o', 'ي': 'y'
}; };
var LITHUANIAN_MAP = { var LITHUANIAN_MAP = {
'ą': 'a', 'č': 'c', 'ę': 'e', 'ė': 'e', 'į': 'i', 'š': 's', 'ų': 'u', 'ą': 'a', 'č': 'c', 'ę': 'e', 'ė': 'e', 'į': 'i', 'š': 's', 'ų': 'u',
'ū': 'u', 'ž': 'z', 'ū': 'u', 'ž': 'z',
'Ą': 'A', 'Č': 'C', 'Ę': 'E', 'Ė': 'E', 'Į': 'I', 'Š': 'S', 'Ų': 'U', 'Ą': 'A', 'Č': 'C', 'Ę': 'E', 'Ė': 'E', 'Į': 'I', 'Š': 'S', 'Ų': 'U',
'Ū': 'U', 'Ž': 'Z' 'Ū': 'U', 'Ž': 'Z'
}; };
var SERBIAN_MAP = { var SERBIAN_MAP = {
'ђ': 'dj', 'ј': 'j', 'љ': 'lj', 'њ': 'nj', 'ћ': 'c', 'џ': 'dz', 'đ': 'dj', 'ђ': 'dj', 'ј': 'j', 'љ': 'lj', 'њ': 'nj', 'ћ': 'c', 'џ': 'dz',
'Ђ': 'Dj', 'Ј': 'j', 'Љ': 'Lj', 'Њ': 'Nj', 'Ћ': 'C', 'Џ': 'Dz', 'Đ': 'Dj' 'đ': 'dj', 'Ђ': 'Dj', 'Ј': 'j', 'Љ': 'Lj', 'Њ': 'Nj', 'Ћ': 'C',
}; 'Џ': 'Dz', 'Đ': 'Dj'
var AZERBAIJANI_MAP = { };
var AZERBAIJANI_MAP = {
'ç': 'c', 'ə': 'e', 'ğ': 'g', 'ı': 'i', 'ö': 'o', 'ş': 's', 'ü': 'u', 'ç': 'c', 'ə': 'e', 'ğ': 'g', 'ı': 'i', 'ö': 'o', 'ş': 's', 'ü': 'u',
'Ç': 'C', 'Ə': 'E', 'Ğ': 'G', 'İ': 'I', 'Ö': 'O', 'Ş': 'S', 'Ü': 'U' 'Ç': 'C', 'Ə': 'E', 'Ğ': 'G', 'İ': 'I', 'Ö': 'O', 'Ş': 'S', 'Ü': 'U'
}; };
var ALL_DOWNCODE_MAPS = [ var ALL_DOWNCODE_MAPS = [
LATIN_MAP, LATIN_MAP,
LATIN_SYMBOLS_MAP, LATIN_SYMBOLS_MAP,
GREEK_MAP, GREEK_MAP,
@ -103,9 +107,9 @@ var ALL_DOWNCODE_MAPS = [
LITHUANIAN_MAP, LITHUANIAN_MAP,
SERBIAN_MAP, SERBIAN_MAP,
AZERBAIJANI_MAP AZERBAIJANI_MAP
]; ];
var Downcoder = { var Downcoder = {
'Initialize': function() { 'Initialize': function() {
if (Downcoder.map) { // already made if (Downcoder.map) { // already made
return; return;
@ -127,17 +131,17 @@ var Downcoder = {
} }
Downcoder.regex = new RegExp(Downcoder.chars.join('|'), 'g'); Downcoder.regex = new RegExp(Downcoder.chars.join('|'), 'g');
} }
}; };
function downcode(slug) { function downcode(slug) {
Downcoder.Initialize(); Downcoder.Initialize();
return slug.replace(Downcoder.regex, function(m) { return slug.replace(Downcoder.regex, function(m) {
return Downcoder.map[m]; return Downcoder.map[m];
}); });
} }
function URLify(s, num_chars, allowUnicode) { function URLify(s, num_chars, allowUnicode) {
// changes, e.g., "Petty theft" to "petty_theft" // changes, e.g., "Petty theft" to "petty_theft"
// remove all these words from the string before urlifying // remove all these words from the string before urlifying
if (!allowUnicode) { if (!allowUnicode) {
@ -162,4 +166,6 @@ function URLify(s, num_chars, allowUnicode) {
s = s.replace(/[-\s]+/g, '-'); // convert spaces to hyphens s = s.replace(/[-\s]+/g, '-'); // convert spaces to hyphens
s = s.toLowerCase(); // convert to lowercase s = s.toLowerCase(); // convert to lowercase
return s.substring(0, num_chars);// trim to first num_chars chars return s.substring(0, num_chars);// trim to first num_chars chars
} }
window.URLify = URLify;
})();

View File

@ -1,5 +1,6 @@
/*global OpenLayers*/ /*global OpenLayers*/
(function() { (function() {
'use strict';
/** /**
* 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