1
0
Fork 0
forked from 0x2620/oxjs

rather use ''.slice than ''.substr

This commit is contained in:
rolux 2012-05-24 11:47:33 +02:00
commit 1608664bb6
20 changed files with 69 additions and 71 deletions

View file

@ -30,7 +30,7 @@ Ox.SourceViewer = function(options, self) {
return match ? match[0].length : 0;
}));
return '<pre>' + lines.map(function(line) {
return line.substr(indent);
return line.slice(indent);
}).join('\n') + '</pre>';
}
]

View file

@ -336,10 +336,10 @@ Ox.URL = function(options) {
}
if (['=', '!='].indexOf(condition.operator) > -1) {
if (condition.value[0] == '*') {
condition.value = condition.value.substr(1);
condition.value = condition.value.slice(1);
condition.operator = condition.operator.replace('=', '$')
} else if (condition.value[condition.value.length - 1] == '*') {
condition.value = condition.value.substr(0, condition.value.length - 1);
condition.value = condition.value.slice(0, -1);
condition.operator = condition.operator.replace('=', '^')
}
}
@ -417,7 +417,7 @@ Ox.URL = function(options) {
return str.split(',').map(function(str) {
var hasOperator = /^[\+-]/.test(str);
return {
key: hasOperator ? str.substr(1) : str,
key: hasOperator ? str.slice(1) : str,
operator: hasOperator
? str[0]
: Ox.getObjectById(self.options.sortKeys[state.type][

View file

@ -113,7 +113,7 @@ Ox.Button = function(options, self) {
that.attr({
src: Ox.UI.getImageURL(
'symbol' + self.options.title[0].toUpperCase()
+ self.options.title.substr(1)
+ self.options.title.slice(1)
)
});
} else {

View file

@ -513,7 +513,7 @@ Ox.Input = function(options, self) {
} else if (/\./.test(value) && self.options.decimals) {
length = value.split('.')[1].length;
if (length > self.options.decimals) {
value = value.substr(0, value.indexOf('.') + 1 + self.options.decimals);
value = value.slice(0, value.indexOf('.') + 1 + self.options.decimals);
cursor = [oldCursor[0] + 1, oldCursor[1] + 1];
} else if (length < self.options.decimals) {
value += Ox.repeat('0', self.options.decimals - length);
@ -527,7 +527,7 @@ Ox.Input = function(options, self) {
}
}
while (/^0\d/.test(value)) {
value = value.substr(1, value.length);
value = value.slice(1);
}
if (!regexp.test(value) || value < self.options.min || value > self.options.max) {
value = oldValue;
@ -725,7 +725,7 @@ Ox.Input = function(options, self) {
that.triggerEvent('insert', {
end: input.selectionEnd,
id: that.oxid,
selection: input.value.substring(input.selectionStart, input.selectionEnd),
selection: input.value.slice(input.selectionStart, input.selectionEnd),
start: input.selectionStart,
value: input.value
});
@ -734,7 +734,7 @@ Ox.Input = function(options, self) {
function keydown(event) {
var oldCursor = cursor(),
oldValue = self.options.value,
newValue = oldValue.substr(0, oldCursor[0] - 1),
newValue = oldValue.slice(0, oldCursor[0] - 1),
hasDeletedSelectedEnd = (event.keyCode == 8 || event.keyCode == 46) &&
oldCursor[0] < oldCursor[1] && oldCursor[1] == oldValue.length;
if (

View file

@ -190,9 +190,9 @@ Ox.InsertHTMLDialog = function(options, self) {
);
self.options.callback({
position: self.options.start + value.length,
value: self.options.value.substr(0, self.options.start)
value: self.options.value.slice(0, self.options.start)
+ value
+ self.options.value.substr(self.options.end)
+ self.options.value.slice(self.options.end)
});
that.close();
}

View file

@ -119,7 +119,7 @@ Ox.TimeInput = function(options, self) {
function getDate() {
return new Date('1970/01/01 ' + (
self.options.milliseconds
? self.options.value.substr(0, self.options.value.length - 4)
? self.options.value.slice(0, -4)
: self.options.value
));
}
@ -129,7 +129,7 @@ Ox.TimeInput = function(options, self) {
return {
ampm: Ox.formatDate(date, '%p'),
hours: Ox.formatDate(date, self.options.ampm ? '%I' : '%H'),
milliseconds: self.options.milliseconds ? self.options.value.substr(-3) : '000',
milliseconds: self.options.milliseconds ? self.options.value.slice(-3) : '000',
minutes: Ox.formatDate(date, '%M'),
seconds: Ox.formatDate(date, '%S')
};

View file

@ -774,7 +774,7 @@ Ox.ListMap = function(options, self) {
country = Ox.getCountryByGeoname(place.geoname);
place.countryCode = country ? country.code : '';
if (!self.isAsync) {
place.id = self.selectedPlace.substr(1); // fixme: safe?
place.id = self.selectedPlace.slice(1); // fixme: safe?
self.selectedPlace = place.id;
self.options.places.push(place);
self.$list.options({

View file

@ -302,8 +302,9 @@ Ox.AnnotationPanel = function(options, self) {
insert({
end: element.selectionEnd,
id: id,
selection: element.value
.substr(element.selectionStart, element.selectionEnd),
selection: element.value.slice(
element.selectionStart, element.selectionEnd
),
start: element.selectionStart,
value: element.value
});

View file

@ -89,7 +89,7 @@ Ox.VideoElement = function(options, self) {
item.$videos = src.map(function(src, i) {
// in all browsers except firefox,
// loadedmetadata fires only once per src
if(Ox.parseURL(src).protocol.substr(0, 4) == 'http') {
if (Ox.startsWith(Ox.parseURL(src).protocol, 'http')) {
src += '?' + Ox.uid();
}
return $('<video>')
@ -434,7 +434,7 @@ Ox.VideoElement = function(options, self) {
self.$video.each(function(video, i) {
if (i != self.currentPart) {
var src = self.options.src[i];
if(Ox.parseURL(src).protocol.substr(0, 4) == 'http') {
if (Ox.startsWith(Ox.parseURL(src).protocol, 'http')) {
src += '?' + Ox.uid();
}
video.src = src;
@ -443,7 +443,7 @@ Ox.VideoElement = function(options, self) {
} else {
self.items[0].$videos.forEach(function($video, i) {
var src = self.options.src[i];
if (Ox.parseURL(src).protocol.substr(0, 4) == 'http') {
if (Ox.startsWith(Ox.parseURL(src).protocol, 'http')) {
src += '?' + Ox.uid();
}
$video[0].src = src;

View file

@ -309,7 +309,7 @@ Ox.Dialog = function(options, self) {
}
function resizestart(event) {
var edge = event.target.className.substr(17).toLowerCase(),
var edge = event.target.className.slice(17).toLowerCase(),
offset = that.offset();
self.drag = {
edge: edge,