rather use ''.slice than ''.substr
This commit is contained in:
parent
f990f3b857
commit
1608664bb6
20 changed files with 69 additions and 71 deletions
|
@ -355,7 +355,7 @@ Ox.load.Image = function(options, callback) {
|
||||||
while (str.length < cap) {
|
while (str.length < cap) {
|
||||||
str += str.substr(4, len);
|
str += str.substr(4, len);
|
||||||
}
|
}
|
||||||
str = str.substr(0, Math.ceil(cap));
|
str = str.slice(0, Math.ceil(cap));
|
||||||
// Create an array of bit values
|
// Create an array of bit values
|
||||||
bin = Ox.flatten(Ox.map(str.split(''), function(chr) {
|
bin = Ox.flatten(Ox.map(str.split(''), function(chr) {
|
||||||
return Ox.range(8).map(function(i) {
|
return Ox.range(8).map(function(i) {
|
||||||
|
|
|
@ -30,7 +30,7 @@ Ox.SourceViewer = function(options, self) {
|
||||||
return match ? match[0].length : 0;
|
return match ? match[0].length : 0;
|
||||||
}));
|
}));
|
||||||
return '<pre>' + lines.map(function(line) {
|
return '<pre>' + lines.map(function(line) {
|
||||||
return line.substr(indent);
|
return line.slice(indent);
|
||||||
}).join('\n') + '</pre>';
|
}).join('\n') + '</pre>';
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -336,10 +336,10 @@ Ox.URL = function(options) {
|
||||||
}
|
}
|
||||||
if (['=', '!='].indexOf(condition.operator) > -1) {
|
if (['=', '!='].indexOf(condition.operator) > -1) {
|
||||||
if (condition.value[0] == '*') {
|
if (condition.value[0] == '*') {
|
||||||
condition.value = condition.value.substr(1);
|
condition.value = condition.value.slice(1);
|
||||||
condition.operator = condition.operator.replace('=', '$')
|
condition.operator = condition.operator.replace('=', '$')
|
||||||
} else if (condition.value[condition.value.length - 1] == '*') {
|
} 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('=', '^')
|
condition.operator = condition.operator.replace('=', '^')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -417,7 +417,7 @@ Ox.URL = function(options) {
|
||||||
return str.split(',').map(function(str) {
|
return str.split(',').map(function(str) {
|
||||||
var hasOperator = /^[\+-]/.test(str);
|
var hasOperator = /^[\+-]/.test(str);
|
||||||
return {
|
return {
|
||||||
key: hasOperator ? str.substr(1) : str,
|
key: hasOperator ? str.slice(1) : str,
|
||||||
operator: hasOperator
|
operator: hasOperator
|
||||||
? str[0]
|
? str[0]
|
||||||
: Ox.getObjectById(self.options.sortKeys[state.type][
|
: Ox.getObjectById(self.options.sortKeys[state.type][
|
||||||
|
|
|
@ -113,7 +113,7 @@ Ox.Button = function(options, self) {
|
||||||
that.attr({
|
that.attr({
|
||||||
src: Ox.UI.getImageURL(
|
src: Ox.UI.getImageURL(
|
||||||
'symbol' + self.options.title[0].toUpperCase()
|
'symbol' + self.options.title[0].toUpperCase()
|
||||||
+ self.options.title.substr(1)
|
+ self.options.title.slice(1)
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -513,7 +513,7 @@ Ox.Input = function(options, self) {
|
||||||
} else if (/\./.test(value) && self.options.decimals) {
|
} else if (/\./.test(value) && self.options.decimals) {
|
||||||
length = value.split('.')[1].length;
|
length = value.split('.')[1].length;
|
||||||
if (length > self.options.decimals) {
|
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];
|
cursor = [oldCursor[0] + 1, oldCursor[1] + 1];
|
||||||
} else if (length < self.options.decimals) {
|
} else if (length < self.options.decimals) {
|
||||||
value += Ox.repeat('0', self.options.decimals - length);
|
value += Ox.repeat('0', self.options.decimals - length);
|
||||||
|
@ -527,7 +527,7 @@ Ox.Input = function(options, self) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (/^0\d/.test(value)) {
|
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) {
|
if (!regexp.test(value) || value < self.options.min || value > self.options.max) {
|
||||||
value = oldValue;
|
value = oldValue;
|
||||||
|
@ -725,7 +725,7 @@ Ox.Input = function(options, self) {
|
||||||
that.triggerEvent('insert', {
|
that.triggerEvent('insert', {
|
||||||
end: input.selectionEnd,
|
end: input.selectionEnd,
|
||||||
id: that.oxid,
|
id: that.oxid,
|
||||||
selection: input.value.substring(input.selectionStart, input.selectionEnd),
|
selection: input.value.slice(input.selectionStart, input.selectionEnd),
|
||||||
start: input.selectionStart,
|
start: input.selectionStart,
|
||||||
value: input.value
|
value: input.value
|
||||||
});
|
});
|
||||||
|
@ -734,7 +734,7 @@ Ox.Input = function(options, self) {
|
||||||
function keydown(event) {
|
function keydown(event) {
|
||||||
var oldCursor = cursor(),
|
var oldCursor = cursor(),
|
||||||
oldValue = self.options.value,
|
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) &&
|
hasDeletedSelectedEnd = (event.keyCode == 8 || event.keyCode == 46) &&
|
||||||
oldCursor[0] < oldCursor[1] && oldCursor[1] == oldValue.length;
|
oldCursor[0] < oldCursor[1] && oldCursor[1] == oldValue.length;
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -190,9 +190,9 @@ Ox.InsertHTMLDialog = function(options, self) {
|
||||||
);
|
);
|
||||||
self.options.callback({
|
self.options.callback({
|
||||||
position: self.options.start + value.length,
|
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
|
+ value
|
||||||
+ self.options.value.substr(self.options.end)
|
+ self.options.value.slice(self.options.end)
|
||||||
});
|
});
|
||||||
that.close();
|
that.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,7 @@ Ox.TimeInput = function(options, self) {
|
||||||
function getDate() {
|
function getDate() {
|
||||||
return new Date('1970/01/01 ' + (
|
return new Date('1970/01/01 ' + (
|
||||||
self.options.milliseconds
|
self.options.milliseconds
|
||||||
? self.options.value.substr(0, self.options.value.length - 4)
|
? self.options.value.slice(0, -4)
|
||||||
: self.options.value
|
: self.options.value
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ Ox.TimeInput = function(options, self) {
|
||||||
return {
|
return {
|
||||||
ampm: Ox.formatDate(date, '%p'),
|
ampm: Ox.formatDate(date, '%p'),
|
||||||
hours: Ox.formatDate(date, self.options.ampm ? '%I' : '%H'),
|
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'),
|
minutes: Ox.formatDate(date, '%M'),
|
||||||
seconds: Ox.formatDate(date, '%S')
|
seconds: Ox.formatDate(date, '%S')
|
||||||
};
|
};
|
||||||
|
|
|
@ -774,7 +774,7 @@ Ox.ListMap = function(options, self) {
|
||||||
country = Ox.getCountryByGeoname(place.geoname);
|
country = Ox.getCountryByGeoname(place.geoname);
|
||||||
place.countryCode = country ? country.code : '';
|
place.countryCode = country ? country.code : '';
|
||||||
if (!self.isAsync) {
|
if (!self.isAsync) {
|
||||||
place.id = self.selectedPlace.substr(1); // fixme: safe?
|
place.id = self.selectedPlace.slice(1); // fixme: safe?
|
||||||
self.selectedPlace = place.id;
|
self.selectedPlace = place.id;
|
||||||
self.options.places.push(place);
|
self.options.places.push(place);
|
||||||
self.$list.options({
|
self.$list.options({
|
||||||
|
|
|
@ -302,8 +302,9 @@ Ox.AnnotationPanel = function(options, self) {
|
||||||
insert({
|
insert({
|
||||||
end: element.selectionEnd,
|
end: element.selectionEnd,
|
||||||
id: id,
|
id: id,
|
||||||
selection: element.value
|
selection: element.value.slice(
|
||||||
.substr(element.selectionStart, element.selectionEnd),
|
element.selectionStart, element.selectionEnd
|
||||||
|
),
|
||||||
start: element.selectionStart,
|
start: element.selectionStart,
|
||||||
value: element.value
|
value: element.value
|
||||||
});
|
});
|
||||||
|
|
|
@ -89,7 +89,7 @@ Ox.VideoElement = function(options, self) {
|
||||||
item.$videos = src.map(function(src, i) {
|
item.$videos = src.map(function(src, i) {
|
||||||
// in all browsers except firefox,
|
// in all browsers except firefox,
|
||||||
// loadedmetadata fires only once per src
|
// 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();
|
src += '?' + Ox.uid();
|
||||||
}
|
}
|
||||||
return $('<video>')
|
return $('<video>')
|
||||||
|
@ -434,7 +434,7 @@ Ox.VideoElement = function(options, self) {
|
||||||
self.$video.each(function(video, i) {
|
self.$video.each(function(video, i) {
|
||||||
if (i != self.currentPart) {
|
if (i != self.currentPart) {
|
||||||
var src = self.options.src[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();
|
src += '?' + Ox.uid();
|
||||||
}
|
}
|
||||||
video.src = src;
|
video.src = src;
|
||||||
|
@ -443,7 +443,7 @@ Ox.VideoElement = function(options, self) {
|
||||||
} else {
|
} else {
|
||||||
self.items[0].$videos.forEach(function($video, i) {
|
self.items[0].$videos.forEach(function($video, i) {
|
||||||
var src = self.options.src[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();
|
src += '?' + Ox.uid();
|
||||||
}
|
}
|
||||||
$video[0].src = src;
|
$video[0].src = src;
|
||||||
|
|
|
@ -309,7 +309,7 @@ Ox.Dialog = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function resizestart(event) {
|
function resizestart(event) {
|
||||||
var edge = event.target.className.substr(17).toLowerCase(),
|
var edge = event.target.className.slice(17).toLowerCase(),
|
||||||
offset = that.offset();
|
offset = that.offset();
|
||||||
self.drag = {
|
self.drag = {
|
||||||
edge: edge,
|
edge: edge,
|
||||||
|
|
|
@ -462,8 +462,8 @@ Ox.range = function() {
|
||||||
var len;
|
var len;
|
||||||
if (new RegExp('^' + article + ' ').test(sort[val])) {
|
if (new RegExp('^' + article + ' ').test(sort[val])) {
|
||||||
len = article.length;
|
len = article.length;
|
||||||
sort[val] = sort[val].substr(len + 1) + ', '
|
sort[val] = sort[val].slice(len + 1) + ', '
|
||||||
+ sort[val].substr(0, len);
|
+ sort[val].slice(0, len);
|
||||||
Ox.break();
|
Ox.break();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -119,4 +119,3 @@ Ox.toRGB = function(hex) {
|
||||||
return parseInt(hex.substr(i * 2, 2), 16);
|
return parseInt(hex.substr(i * 2, 2), 16);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ Ox.MONTHS = [
|
||||||
];
|
];
|
||||||
//@ Ox.SHORT_MONTHS <[str]> Short names of months
|
//@ Ox.SHORT_MONTHS <[str]> Short names of months
|
||||||
Ox.SHORT_MONTHS = Ox.MONTHS.map(function(val) {
|
Ox.SHORT_MONTHS = Ox.MONTHS.map(function(val) {
|
||||||
return val.substr(0, 3);
|
return val.slice(0, 3);
|
||||||
});
|
});
|
||||||
//@ Ox.PATH <str> Path of Ox.js
|
//@ Ox.PATH <str> Path of Ox.js
|
||||||
Ox.PATH = Ox.toArray(
|
Ox.PATH = Ox.toArray(
|
||||||
|
@ -127,5 +127,5 @@ Ox.WEEKDAYS = [
|
||||||
];
|
];
|
||||||
//@ Ox.SHORT_WEEKDAYS <[str]> Short names of weekdays
|
//@ Ox.SHORT_WEEKDAYS <[str]> Short names of weekdays
|
||||||
Ox.SHORT_WEEKDAYS = Ox.WEEKDAYS.map(function(val) {
|
Ox.SHORT_WEEKDAYS = Ox.WEEKDAYS.map(function(val) {
|
||||||
return val.substr(0, 3);
|
return val.slice(0, 3);
|
||||||
});
|
});
|
||||||
|
|
|
@ -141,7 +141,7 @@ Ox.localStorage = function(namespace) {
|
||||||
ret = {};
|
ret = {};
|
||||||
Ox.forEach(localStorage, function(val, key) {
|
Ox.forEach(localStorage, function(val, key) {
|
||||||
if (Ox.startsWith(key, namespace + '.')) {
|
if (Ox.startsWith(key, namespace + '.')) {
|
||||||
ret[key.substr(namespace.length + 1)] = JSON.parse(val);
|
ret[key.slice(namespace.length + 1)] = JSON.parse(val);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (arguments.length == 1 && typeof key == 'string') {
|
} else if (arguments.length == 1 && typeof key == 'string') {
|
||||||
|
@ -214,7 +214,7 @@ Ox.Log = (function() {
|
||||||
if (!log.filterEnabled || log.filter.indexOf(args[0]) > -1) {
|
if (!log.filterEnabled || log.filter.indexOf(args[0]) > -1) {
|
||||||
date = new Date();
|
date = new Date();
|
||||||
args.unshift(
|
args.unshift(
|
||||||
Ox.formatDate(date, '%H:%M:%S.') + (+date).toString().substr(-3)
|
Ox.formatDate(date, '%H:%M:%S.') + (+date).toString().slice(-3)
|
||||||
);
|
);
|
||||||
window.console && window.console.log.apply(window.console, args);
|
window.console && window.console.log.apply(window.console, args);
|
||||||
ret = args.join(' ');
|
ret = args.join(' ');
|
||||||
|
@ -326,7 +326,7 @@ Ox.print = function() {
|
||||||
var args = Ox.toArray(arguments),
|
var args = Ox.toArray(arguments),
|
||||||
date = new Date();
|
date = new Date();
|
||||||
args.unshift(
|
args.unshift(
|
||||||
Ox.formatDate(date, '%H:%M:%S.') + (+date).toString().substr(-3)/*,
|
Ox.formatDate(date, '%H:%M:%S.') + (+date).toString().slice(-3)/*,
|
||||||
(arguments.callee.caller && arguments.callee.caller.name)
|
(arguments.callee.caller && arguments.callee.caller.name)
|
||||||
|| '(anonymous)'*/
|
|| '(anonymous)'*/
|
||||||
);
|
);
|
||||||
|
|
|
@ -26,7 +26,7 @@ Ox.getDateInWeek = function(date, weekday, utc) {
|
||||||
var sourceWeekday = Ox.getISODay(date, utc),
|
var sourceWeekday = Ox.getISODay(date, utc),
|
||||||
targetWeekday = Ox.isNumber(weekday) ? weekday
|
targetWeekday = Ox.isNumber(weekday) ? weekday
|
||||||
: Ox.indexOf(Ox.WEEKDAYS, function(v) {
|
: Ox.indexOf(Ox.WEEKDAYS, function(v) {
|
||||||
return v.substr(0, 3) == weekday.substr(0, 3);
|
return v.slice(0, 3) == weekday.slice(0, 3);
|
||||||
}) + 1;
|
}) + 1;
|
||||||
return Ox.setDate(date, Ox.getDate(date, utc) - sourceWeekday + targetWeekday, utc);
|
return Ox.setDate(date, Ox.getDate(date, utc) - sourceWeekday + targetWeekday, utc);
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ Ox.getDaysInMonth = function(year, month) {
|
||||||
year = Ox.makeYear(year);
|
year = Ox.makeYear(year);
|
||||||
month = Ox.isNumber(month) ? month
|
month = Ox.isNumber(month) ? month
|
||||||
: Ox.indexOf(Ox.MONTHS, function(v) {
|
: Ox.indexOf(Ox.MONTHS, function(v) {
|
||||||
return v.substr(0, 3) == month.substr(0, 3);
|
return v.slice(0, 3) == month.slice(0, 3);
|
||||||
}) + 1;
|
}) + 1;
|
||||||
return new Date(year, month, 0).getDate();
|
return new Date(year, month, 0).getDate();
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,14 +204,14 @@
|
||||||
// bytes IHDR name), keep bytes 16 to 19 (width), discard bytes 20 to 29
|
// bytes IHDR name), keep bytes 16 to 19 (width), discard bytes 20 to 29
|
||||||
// (4 bytes height, 5 bytes flags), keep bytes 29 to 32 (IHDR checksum),
|
// (4 bytes height, 5 bytes flags), keep bytes 29 to 32 (IHDR checksum),
|
||||||
// keep the rest (IDAT chunks), discard the last 12 bytes (IEND chunk).
|
// keep the rest (IDAT chunks), discard the last 12 bytes (IEND chunk).
|
||||||
data = str.substr(16, 4) + str.substr(29, 4);
|
data = str.slice(16, 20) + str.slice(29, 33);
|
||||||
idat = str.substr(33, str.length - 45);
|
idat = str.slice(33, -45);
|
||||||
while (idat) {
|
while (idat) {
|
||||||
// Each IDAT chunk is 4 bytes length, 4 bytes name, length bytes
|
// Each IDAT chunk is 4 bytes length, 4 bytes name, length bytes
|
||||||
// data and 4 bytes checksum. We can discard the name parts.
|
// data and 4 bytes checksum. We can discard the name parts.
|
||||||
len = idat.substr(0, 4);
|
len = idat.slice(0, 4);
|
||||||
data += len + idat.substr(8, 4 + (len = Ox.decodeBase256(len)));
|
data += len + idat.slice(8, 12 + (len = Ox.decodeBase256(len)));
|
||||||
idat = idat.substr(12 + len);
|
idat = idat.slice(12 + len);
|
||||||
}
|
}
|
||||||
callback && callback(data);
|
callback && callback(data);
|
||||||
return data;
|
return data;
|
||||||
|
@ -234,18 +234,18 @@
|
||||||
var image = new Image(),
|
var image = new Image(),
|
||||||
// PNG file signature and IHDR chunk
|
// PNG file signature and IHDR chunk
|
||||||
data = '\u0089PNG\r\n\u001A\n\u0000\u0000\u0000\u000DIHDR'
|
data = '\u0089PNG\r\n\u001A\n\u0000\u0000\u0000\u000DIHDR'
|
||||||
+ str.substr(0, 4) + '\u0000\u0000\u0000\u0001'
|
+ str.slice(0, 4) + '\u0000\u0000\u0000\u0001'
|
||||||
+ '\u0008\u0006\u0000\u0000\u0000' + str.substr(4, 4),
|
+ '\u0008\u0006\u0000\u0000\u0000' + str.slice(4, 8),
|
||||||
// IDAT chunks
|
// IDAT chunks
|
||||||
idat = str.substr(8), len;
|
idat = str.slice(8), len;
|
||||||
function error() {
|
function error() {
|
||||||
throw new RangeError('Deflate codec can\'t decode data.');
|
throw new RangeError('Deflate codec can\'t decode data.');
|
||||||
}
|
}
|
||||||
while (idat) {
|
while (idat) {
|
||||||
// Reinsert the IDAT chunk names
|
// Reinsert the IDAT chunk names
|
||||||
len = idat.substr(0, 4);
|
len = idat.slice(0, 4);
|
||||||
data += len + 'IDAT' + idat.substr(4, 4 + (len = Ox.decodeBase256(len)));
|
data += len + 'IDAT' + idat.slice(4, 8 + (len = Ox.decodeBase256(len)));
|
||||||
idat = idat.substr(8 + len);
|
idat = idat.slice(8 + len);
|
||||||
}
|
}
|
||||||
// IEND chunk
|
// IEND chunk
|
||||||
data += '\u0000\u0000\u0000\u0000IEND\u00AE\u0042\u0060\u0082';
|
data += '\u0000\u0000\u0000\u0000IEND\u00AE\u0042\u0060\u0082';
|
||||||
|
@ -259,7 +259,7 @@
|
||||||
try {
|
try {
|
||||||
// Parse the first byte as number of bytes to chop at the end,
|
// Parse the first byte as number of bytes to chop at the end,
|
||||||
// and the rest, without these bytes, as an UTF8-encoded string.
|
// and the rest, without these bytes, as an UTF8-encoded string.
|
||||||
str = Ox.decodeUTF8(str.substr(1, str.length - 1 - str.charCodeAt(0)))
|
str = Ox.decodeUTF8(str.slice(1, -str.CharCodeAt(0)));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error();
|
error();
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,7 +153,7 @@ Ox.formatDate = function(date, str, utc) {
|
||||||
['d', function(d) {return Ox.pad(Ox.getDate(d, utc), 2);}],
|
['d', function(d) {return Ox.pad(Ox.getDate(d, utc), 2);}],
|
||||||
['e', function(d) {return Ox.pad(Ox.getDate(d, utc), 2, ' ');}],
|
['e', function(d) {return Ox.pad(Ox.getDate(d, utc), 2, ' ');}],
|
||||||
['G', function(d) {return Ox.getISOYear(d, utc);}],
|
['G', function(d) {return Ox.getISOYear(d, utc);}],
|
||||||
['g', function(d) {return Ox.getISOYear(d, utc).toString().substr(-2);}],
|
['g', function(d) {return Ox.getISOYear(d, utc).toString().slice(-2);}],
|
||||||
['H', function(d) {return Ox.pad(Ox.getHours(d, utc), 2);}],
|
['H', function(d) {return Ox.pad(Ox.getHours(d, utc), 2);}],
|
||||||
['I', function(d) {return Ox.pad((Ox.getHours(d, utc) + 11) % 12 + 1, 2);}],
|
['I', function(d) {return Ox.pad((Ox.getHours(d, utc) + 11) % 12 + 1, 2);}],
|
||||||
['j', function(d) {return Ox.pad(Ox.getDayOfTheYear(d, utc), 3);}],
|
['j', function(d) {return Ox.pad(Ox.getDayOfTheYear(d, utc), 3);}],
|
||||||
|
@ -185,7 +185,7 @@ Ox.formatDate = function(date, str, utc) {
|
||||||
return Math.abs(y) + (y < 1000 ? ' ' + Ox.BCAD[y < 0 ? 0 : 1] : '');
|
return Math.abs(y) + (y < 1000 ? ' ' + Ox.BCAD[y < 0 ? 0 : 1] : '');
|
||||||
}],
|
}],
|
||||||
['Y', function(d) {return Ox.getFullYear(d, utc);}],
|
['Y', function(d) {return Ox.getFullYear(d, utc);}],
|
||||||
['y', function(d) {return Ox.getFullYear(d, utc).toString().substr(-2);}],
|
['y', function(d) {return Ox.getFullYear(d, utc).toString().slice(-2);}],
|
||||||
['Z', function(d) {return d.toString().split('(')[1].replace(')', '');}],
|
['Z', function(d) {return d.toString().split('(')[1].replace(')', '');}],
|
||||||
['z', function(d) {return Ox.getTimezoneOffsetString(d);}],
|
['z', function(d) {return Ox.getTimezoneOffsetString(d);}],
|
||||||
['n', function() {return '\n';}],
|
['n', function() {return '\n';}],
|
||||||
|
@ -496,8 +496,8 @@ Ox.formatNumber = function(num, dec) {
|
||||||
str = Ox.isUndefined(dec) ? abs.toString() : abs.toFixed(dec),
|
str = Ox.isUndefined(dec) ? abs.toString() : abs.toFixed(dec),
|
||||||
spl = str.split('.');
|
spl = str.split('.');
|
||||||
while (spl[0]) {
|
while (spl[0]) {
|
||||||
arr.unshift(spl[0].substr(-3));
|
arr.unshift(spl[0].slice(-3));
|
||||||
spl[0] = spl[0].substr(0, spl[0].length - 3);
|
spl[0] = spl[0].slice(0, -3);
|
||||||
}
|
}
|
||||||
spl[0] = arr.join(',');
|
spl[0] = arr.join(',');
|
||||||
return (num < 0 ? '-' : '') + spl.join('.');
|
return (num < 0 ? '-' : '') + spl.join('.');
|
||||||
|
|
|
@ -76,7 +76,7 @@ Ox.doc = (function() {
|
||||||
// or if the second last char is a single or double quote
|
// or if the second last char is a single or double quote
|
||||||
return matches && (
|
return matches && (
|
||||||
matches[2].indexOf('/') == -1 ||
|
matches[2].indexOf('/') == -1 ||
|
||||||
'\'"'.indexOf(matches[2].substr(-2, 1)) > -1
|
'\'"'.indexOf(matches[2].slice(-2, -1)) > -1
|
||||||
) ? Ox.extend({
|
) ? Ox.extend({
|
||||||
name: parseName(matches[1].trim()),
|
name: parseName(matches[1].trim()),
|
||||||
summary: matches[3].trim()
|
summary: matches[3].trim()
|
||||||
|
@ -163,7 +163,7 @@ Ox.doc = (function() {
|
||||||
// main item
|
// main item
|
||||||
// include leading whitespace
|
// include leading whitespace
|
||||||
item.source = parseTokens(tokens[i]);
|
item.source = parseTokens(tokens[i]);
|
||||||
item.line = source.substr(0, item.source[0].offset)
|
item.line = source.slice(0, item.source[0].offset)
|
||||||
.split('\n').length;
|
.split('\n').length;
|
||||||
items.push(item);
|
items.push(item);
|
||||||
} else {
|
} else {
|
||||||
|
@ -186,7 +186,7 @@ Ox.doc = (function() {
|
||||||
// fixme: we cannot properly handle tests where a string contains '\n '
|
// fixme: we cannot properly handle tests where a string contains '\n '
|
||||||
var lines = decodeLinebreaks(str).split('\n ');
|
var lines = decodeLinebreaks(str).split('\n ');
|
||||||
return {
|
return {
|
||||||
statement: lines[0].substr(2),
|
statement: lines[0].slice(2),
|
||||||
result: lines[1].trim()
|
result: lines[1].trim()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -258,7 +258,7 @@ Ox.doc = (function() {
|
||||||
split,
|
split,
|
||||||
type;
|
type;
|
||||||
// only split by ':' if there is no default string value
|
// only split by ':' if there is no default string value
|
||||||
if ('\'"'.indexOf(str.substr(-2, 1)) == -1) {
|
if ('\'"'.indexOf(str.slice(-2, -1)) == -1) {
|
||||||
split = str.split(':');
|
split = str.split(':');
|
||||||
str = split[0];
|
str = split[0];
|
||||||
if (split.length == 2) {
|
if (split.length == 2) {
|
||||||
|
@ -637,7 +637,7 @@ Ox.tokenize = (function() {
|
||||||
identifier: function() {
|
identifier: function() {
|
||||||
var str;
|
var str;
|
||||||
while ((identifier + number).indexOf(source[++cursor]) > -1) {}
|
while ((identifier + number).indexOf(source[++cursor]) > -1) {}
|
||||||
str = source.substring(start, cursor);
|
str = source.slice(start, cursor);
|
||||||
Ox.forEach(word, function(value, key) {
|
Ox.forEach(word, function(value, key) {
|
||||||
if (value.indexOf(str) > -1) {
|
if (value.indexOf(str) > -1) {
|
||||||
type = key;
|
type = key;
|
||||||
|
|
|
@ -48,7 +48,7 @@ Ox.ends = Ox.endsWith = function(str, sub) {
|
||||||
// fixme: rename to ends
|
// fixme: rename to ends
|
||||||
str = str.toString();
|
str = str.toString();
|
||||||
sub = sub.toString();
|
sub = sub.toString();
|
||||||
return str.substr(str.length - sub.length) == sub;
|
return str.slice(str.length - sub.length) == sub;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
|
@ -107,7 +107,7 @@ Ox.highlightHTML = function(html, str, classname, tags) {
|
||||||
isEntity = true;
|
isEntity = true;
|
||||||
} else if (!isTag && chr == '<') {
|
} else if (!isTag && chr == '<') {
|
||||||
Ox.forEach(tags, function(tag) {
|
Ox.forEach(tags, function(tag) {
|
||||||
if (html.substr(i + 1).match(new RegExp('^/?' + tag + '\\W'))) {
|
if (html.slice(i + 1).match(new RegExp('^/?' + tag + '\\W'))) {
|
||||||
isTag = true;
|
isTag = true;
|
||||||
Ox.break();
|
Ox.break();
|
||||||
}
|
}
|
||||||
|
@ -138,10 +138,10 @@ Ox.highlightHTML = function(html, str, classname, tags) {
|
||||||
});
|
});
|
||||||
positions.forEach(function(position) {
|
positions.forEach(function(position) {
|
||||||
var match = '<span class="' + classname + '">'
|
var match = '<span class="' + classname + '">'
|
||||||
+ html.substr(position[0], position[1] - position[0])
|
+ html.slice(position[0], position[1])
|
||||||
.replace(/(<.*?>)/g, '</span>$1<span class="' + classname + '">')
|
.replace(/(<.*?>)/g, '</span>$1<span class="' + classname + '">')
|
||||||
+ '</span>';
|
+ '</span>';
|
||||||
html = html.substr(0, position[0]) + match + html.substr(position[1]);
|
html = html.slice(0, position[0]) + match + html.slice(position[1]);
|
||||||
});
|
});
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
@ -180,13 +180,11 @@ Ox.pad = function(str, len, pad) {
|
||||||
// fixme: slighly obscure signature
|
// fixme: slighly obscure signature
|
||||||
// fixme: weird for negative numbers
|
// fixme: weird for negative numbers
|
||||||
var pos = len / (len = Math.abs(len));
|
var pos = len / (len = Math.abs(len));
|
||||||
str = str.toString().substr(0, len);
|
str = str.toString().slice(0, len);
|
||||||
pad = Ox.repeat(pad || '0', len - str.length);
|
pad = Ox.repeat(pad || '0', len - str.length);
|
||||||
str = pos == 1 ? pad + str : str + pad;
|
return pos == 1
|
||||||
str = pos == 1 ?
|
? (pad + str).slice(-len)
|
||||||
str.substr(str.length - len, str.length) :
|
: (str + pad).slice(0, len);
|
||||||
str.substr(0, len);
|
|
||||||
return str;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
|
@ -209,7 +207,7 @@ Ox.parsePath = function(str) {
|
||||||
return {
|
return {
|
||||||
pathname: matches[1] || '',
|
pathname: matches[1] || '',
|
||||||
filename: matches[2] || '',
|
filename: matches[2] || '',
|
||||||
extension: matches[3] ? matches[3].substr(1) : ''
|
extension: matches[3] ? matches[3].slice(1) : ''
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,7 +420,7 @@ Ox.starts = Ox.startsWith = function(str, sub) {
|
||||||
// fixme: rename to starts
|
// fixme: rename to starts
|
||||||
str = str.toString();
|
str = str.toString();
|
||||||
sub = sub.toString();
|
sub = sub.toString();
|
||||||
return str.substr(0, sub.length) == sub;
|
return str.slice(0, sub.length) == sub;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
|
@ -482,10 +480,10 @@ Ox.toTitleCase <f> Returns a string with capitalized words
|
||||||
@*/
|
@*/
|
||||||
Ox.toTitleCase = function(str) {
|
Ox.toTitleCase = function(str) {
|
||||||
return str.split(' ').map(function(val) {
|
return str.split(' ').map(function(val) {
|
||||||
var sub = val.substr(1),
|
var sub = val.slice(1),
|
||||||
low = sub.toLowerCase();
|
low = sub.toLowerCase();
|
||||||
if (sub == low) {
|
if (sub == low) {
|
||||||
val = val.substr(0, 1).toUpperCase() + low;
|
val = val.slice(0, 1).toUpperCase() + low;
|
||||||
}
|
}
|
||||||
return val;
|
return val;
|
||||||
}).join(' ');
|
}).join(' ');
|
||||||
|
@ -533,13 +531,13 @@ Ox.truncate = function(str, len, pad, pos) {
|
||||||
left, right;
|
left, right;
|
||||||
if (strlen > len) {
|
if (strlen > len) {
|
||||||
if (pos == 'left') {
|
if (pos == 'left') {
|
||||||
str = pad + str.substr(padlen + strlen - len);
|
str = pad + str.slice(padlen + strlen - len);
|
||||||
} else if (pos == 'center') {
|
} else if (pos == 'center') {
|
||||||
left = Math.ceil((len - padlen) / 2);
|
left = Math.ceil((len - padlen) / 2);
|
||||||
right = Math.floor((len - padlen) / 2);
|
right = Math.floor((len - padlen) / 2);
|
||||||
str = str.substr(0, left) + pad + str.substr(-right);
|
str = str.slice(0, left) + pad + str.slice(-right);
|
||||||
} else if (pos == 'right') {
|
} else if (pos == 'right') {
|
||||||
str = str.substr(0, len - padlen) + pad;
|
str = str.slice(0, len - padlen) + pad;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
|
@ -628,7 +626,7 @@ Ox.wordwrap = function(str, len, sep, bal, spa) {
|
||||||
} else {
|
} else {
|
||||||
// word is longer than line
|
// word is longer than line
|
||||||
chr = len - lines[lines.length - 1].length;
|
chr = len - lines[lines.length - 1].length;
|
||||||
lines[lines.length - 1] += word.substr(0, chr);
|
lines[lines.length - 1] += word.slice(0, chr);
|
||||||
Ox.loop(chr, word.length, len, function(pos) {
|
Ox.loop(chr, word.length, len, function(pos) {
|
||||||
lines.push(word.substr(pos, len));
|
lines.push(word.substr(pos, len));
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue