From 5110267971cb846b44ae08282cc94f074f6152cb Mon Sep 17 00:00:00 2001 From: rolux Date: Thu, 24 May 2012 11:56:52 +0200 Subject: [PATCH] rather use ''.slice than ''.substr --- static/js/api/pandora.js | 2 +- static/js/embed/pandora.js | 6 +++--- static/js/pandora.js | 2 +- static/js/pandora/URL.js | 8 ++++---- static/js/pandora/autovalidate.js | 10 +++++----- static/js/pandora/editor.js | 2 +- static/js/pandora/infoView.0xdb.js | 2 +- static/js/pandora/menu.js | 4 ++-- static/js/pandora/statisticsDialog.js | 8 ++++---- static/js/pandora/toolbar.js | 2 +- static/js/pandora/tv.js | 2 +- static/js/pandora/usersDialog.js | 4 ++-- static/js/pandora/utils.js | 6 +++--- 13 files changed, 29 insertions(+), 29 deletions(-) diff --git a/static/js/api/pandora.js b/static/js/api/pandora.js index 408ad39c..dd457ebf 100755 --- a/static/js/api/pandora.js +++ b/static/js/api/pandora.js @@ -157,7 +157,7 @@ function constructList() { else info.html(app.site.default_info); - document.location.hash = hash.substring(0, hash.length-1); + document.location.hash = hash.slice(0, -1); app.$ui.actionInfo.html(info); } }); diff --git a/static/js/embed/pandora.js b/static/js/embed/pandora.js index b1a19d11..5feb8994 100755 --- a/static/js/embed/pandora.js +++ b/static/js/embed/pandora.js @@ -145,10 +145,10 @@ Ox.load('UI', { function parseQuery() { var vars = window.location.search.length - ? window.location.search.substring(1).split('&') + ? window.location.search.slice(1).split('&') : [], query = { - item: window.location.pathname.substring(1).split('/')[0] + item: window.location.pathname.slice(1).split('/')[0] }, defaults = { view: 'video', @@ -158,7 +158,7 @@ Ox.load('UI', { item: '' }; vars.forEach(function(v) { - v= v.split('='); + v = v.split('='); query[v[0]] = decodeURIComponent(v[1]); }); diff --git a/static/js/pandora.js b/static/js/pandora.js index c84ebb91..32a775a9 100644 --- a/static/js/pandora.js +++ b/static/js/pandora.js @@ -270,7 +270,7 @@ appPanel pandora.site.listSettings = {}; Ox.forEach(pandora.site.user.ui, function(val, key) { if (/^list[A-Z]/.test(key)) { - pandora.site.listSettings[key] = key[4].toLowerCase() + key.substr(5); + pandora.site.listSettings[key] = key[4].toLowerCase() + key.slice(5); } }); diff --git a/static/js/pandora/URL.js b/static/js/pandora/URL.js index 3ec606b2..34fe356c 100644 --- a/static/js/pandora/URL.js +++ b/static/js/pandora/URL.js @@ -110,8 +110,8 @@ pandora.URL = (function() { set['mapSelection'] = state.span; set['mapFind'] = ''; } else { - //pandora.user.ui.mapFind = state.span.substr(1); - set['mapFind'] = state.span.substr(1); + //pandora.user.ui.mapFind = state.span.slice(1); + set['mapFind'] = state.span.slice(1); set['mapSelection'] = ''; } } else if (state.view == 'calendar') { @@ -301,8 +301,8 @@ pandora.URL = (function() { // on page load, this sets the state from the URL that.parse = function(callback) { - if (document.location.pathname.substr(0, 4) == 'url=') { - document.location.href = decodeURI(document.location.pathname.substr(4)); + if (document.location.pathname.slice(0, 4) == 'url=') { + document.location.href = decodeURI(document.location.pathname.slice(4)); } else { self.URL.parse(function(state) { setState(state, callback); // setState -> UI.set -> URL.update diff --git a/static/js/pandora/autovalidate.js b/static/js/pandora/autovalidate.js index ed91e80b..8ea1668b 100644 --- a/static/js/pandora/autovalidate.js +++ b/static/js/pandora/autovalidate.js @@ -5,14 +5,14 @@ pandora.autovalidateCode = function(value, blur, callback) { value = value.toUpperCase().split('').map(function(v) { return /[A-Z]/.test(v) ? v : null; - }).join('').substr(0, 16); + }).join('').slice(0, 16); callback({valid: value.length == 16, value: value}); }; pandora.autovalidateEmail = function(value, blur, callback) { value = value.toLowerCase().split('').map(function(v, i) { return /[0-9a-z\.\+\-_@]/.test(v) ? v : null; - }).join('').substr(0, 255); + }).join('').slice(0, 255); callback({valid: Ox.isValidEmail(value), value: value}); }; @@ -23,7 +23,7 @@ pandora.autovalidateListname = function(value, blur, callback) { value = value.toLowerCase().split('').map(function(v, i) { return /\s/.test(v) && (i == 0 || (i == length - 1 && blur)) ? null : v; }).join(''); - value = value.replace(/\s+/g, ' ').substr(0, 255); + value = value.replace(/\s+/g, ' ').slice(0, 255); callback({valid: !!value.length, value: value}); }; @@ -34,7 +34,7 @@ pandora.autovalidateUsername = function(value, blur, callback) { value = value.toLowerCase().split('').map(function(v, i) { return /\s/.test(v) && (i == 0 || (i == length - 1 && blur)) ? null : v; }).join(''); - value = value.replace(/\s+/g, ' ').substr(0, 255); + value = value.replace(/\s+/g, ' ').slice(0, 255); callback({valid: !!value.length, value: value}); }; @@ -96,7 +96,7 @@ pandora.validateUser = function(key, existing) { callback({ message: existing ? 'Unknown ' + string : - string[0].toUpperCase() + string.substr(1) + ' already exists', + string[0].toUpperCase() + string.slice(1) + ' already exists', valid: valid }); }) : callback({ diff --git a/static/js/pandora/editor.js b/static/js/pandora/editor.js index a65457de..8796bae5 100644 --- a/static/js/pandora/editor.js +++ b/static/js/pandora/editor.js @@ -127,7 +127,7 @@ pandora.ui.editor = function(data) { function callback(result) { Ox.Log('', 'editAnnotation result', result); result.data.date = Ox.formatDate( - result.data.modified.substr(0, 10), '%B %e, %Y' + result.data.modified.slice(0, 10), '%B %e, %Y' ); pandora.$ui.editor.updateAnnotation(data.id, result.data); }; diff --git a/static/js/pandora/infoView.0xdb.js b/static/js/pandora/infoView.0xdb.js index a0d2abad..427abb0e 100644 --- a/static/js/pandora/infoView.0xdb.js +++ b/static/js/pandora/infoView.0xdb.js @@ -20,7 +20,7 @@ pandora.ui.infoView = function(data) { iconHeight = iconRatio < 1 ? iconSize : Math.round(iconSize / iconRatio), iconLeft = iconSize == 256 ? Math.floor((iconSize - iconWidth) / 2) : 0, borderRadius = ui.icons == 'posters' ? 0 : iconSize / 8, - isEditable = canEdit && data.id.substr(0, 2) == '0x', + isEditable = canEdit && data.id.slice(0, 2) == '0x', listWidth = 144 + Ox.UI.SCROLLBAR_SIZE, margin = 16, statisticsWidth = 128, diff --git a/static/js/pandora/menu.js b/static/js/pandora/menu.js index c4cd3a27..714cfaec 100644 --- a/static/js/pandora/menu.js +++ b/static/js/pandora/menu.js @@ -241,11 +241,11 @@ pandora.ui.mainMenu = function() { pandora.UI.set(set); } else if (data.id == 'viewicons') { pandora.UI.set({icons: value}); - } else if (data.id.substr(0, 8) == 'viewlist') { + } else if (data.id.slice(0, 8) == 'viewlist') { pandora.UI.set({ find: { conditions: data.checked ? [ - {key: 'list', value: data.id.substr(8), operator: '=='} + {key: 'list', value: data.id.slice(8), operator: '=='} ] : [], operator: '&' } diff --git a/static/js/pandora/statisticsDialog.js b/static/js/pandora/statisticsDialog.js index aefecf53..2a35855a 100644 --- a/static/js/pandora/statisticsDialog.js +++ b/static/js/pandora/statisticsDialog.js @@ -128,10 +128,10 @@ pandora.ui.statisticsDialog = function() { var city, continent, country, countryData, name = {}, region, split; if (mode == 'all' || item.level != 'guest') { ['firstseen', 'lastseen'].forEach(function(key, i) { - var year = item[key].substr(0, 4) + '-' + key, - month = item[key].substr(0, 7) + '-' + key, + var year = item[key].slice(0, 4) + '-' + key, + month = item[key].slice(0, 7) + '-' + key, day = Ox.formatDate(item[key], '%u'), - hour = item[key].substr(11, 2); + hour = item[key].slice(11, 13); data[mode].year[year] = data[mode].year[year] || {}; data[mode].year[year][month] = (data[mode].year[year][month] || 0) + 1; data[mode].month[month] = (data[mode].month[month] || 0) + 1; @@ -181,7 +181,7 @@ pandora.ui.statisticsDialog = function() { var keys, firstKey, lastKey; keys = Object.keys(data[mode].month).map(function(key) { - return key.substr(0, 7) + return key.slice(0, 7); }).sort(); firstKey = keys[0].split('-').map(function(str) { return parseInt(str, 10); diff --git a/static/js/pandora/toolbar.js b/static/js/pandora/toolbar.js index 0e88ba29..c59e4a5c 100644 --- a/static/js/pandora/toolbar.js +++ b/static/js/pandora/toolbar.js @@ -77,7 +77,7 @@ pandora.ui.toolbar = function() { return '' + ( listId == '' ? 'All ' + pandora.site.itemName.plural - : Ox.encodeHTMLEntities(listId.substr(listId.indexOf(':') + 1)) + : Ox.encodeHTMLEntities(listId.slice(listId.indexOf(':') + 1)) ) + ''; } function getListTitleLeft() { diff --git a/static/js/pandora/tv.js b/static/js/pandora/tv.js index deae99be..7ae390db 100644 --- a/static/js/pandora/tv.js +++ b/static/js/pandora/tv.js @@ -33,7 +33,7 @@ pandora.ui.tv = function() { lists = ['']; Ox.loop(3, function(f) { menu.items[f + 1].items.forEach(function(l) { - lists.push(l.id.substr(8)); + lists.push(l.id.slice(8)); }); }); } diff --git a/static/js/pandora/usersDialog.js b/static/js/pandora/usersDialog.js index 96380448..5f002fa0 100644 --- a/static/js/pandora/usersDialog.js +++ b/static/js/pandora/usersDialog.js @@ -804,9 +804,9 @@ pandora.ui.usersDialog = function() { textarea = $input.find('textarea')[0], value = $input.value(); $input.value( - value.substr(0, textarea.selectionStart) + value.slice(0, textarea.selectionStart) + '{' + data.id + '}' - + value.substr(textarea.selectionEnd) + + value.slice(textarea.selectionEnd) ) .focusInput(textarea.selectionStart + data.id.length + 2); } diff --git a/static/js/pandora/utils.js b/static/js/pandora/utils.js index 0110c16f..4174b8bf 100644 --- a/static/js/pandora/utils.js +++ b/static/js/pandora/utils.js @@ -675,7 +675,7 @@ pandora.getMetadataByIdOrName = function(item, view, str, callback) { ) && item && !isName, canBeEvent = !view || view == 'calendar', canBePlace = !view || view == 'map'; - str = isName ? str.substr(1) : str; + str = isName ? str.slice(1) : str; getId(canBeAnnotation ? 'annotation' : '', function(id) { if (id) { Ox.Log('URL', 'id?', id) @@ -764,7 +764,7 @@ pandora.getPageTitle = function(stateOrURL) { ].concat(pandora.site.sitePages), page = Ox.getObjectById( pages, - Ox.isObject(stateOrURL) ? stateOrURL.page : stateOrURL.substr(1) + Ox.isObject(stateOrURL) ? stateOrURL.page : stateOrURL.slice(1) ); return page ? pandora.site.site.name @@ -840,7 +840,7 @@ pandora.getVideoOptions = function(data) { pandora.site.layers.forEach(function(layer, i) { options.annotations[i] = Ox.extend({}, layer, { items: data.layers[layer.id].map(function(annotation) { - annotation.date = Ox.formatDate(annotation.modified.substr(0, 10), '%B %e, %Y'); + annotation.date = Ox.formatDate(annotation.modified.slice(0, 10), '%B %e, %Y'); annotation.duration = Math.abs(annotation.out - annotation['in']); annotation.editable = annotation.editable || annotation.user == pandora.user.username