jellyfin-web/dashboard-ui/scripts/extensions.js

101 lines
2.8 KiB
JavaScript
Raw Normal View History

2015-12-14 08:43:03 -07:00
function getWindowLocationSearch(win) {
2014-04-08 19:12:17 -07:00
var search = (win || window).location.search;
if (!search) {
var index = window.location.href.indexOf('?');
if (index != -1) {
search = window.location.href.substring(index);
}
}
2014-04-08 19:27:30 -07:00
2014-04-08 19:12:17 -07:00
return search || '';
}
2013-05-25 21:52:14 -07:00
function getParameterByName(name, url) {
2013-02-20 18:33:05 -07:00
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
2013-05-31 18:48:41 -07:00
var regex = new RegExp(regexS, "i");
2014-04-08 19:12:17 -07:00
var results = regex.exec(url || getWindowLocationSearch());
2013-02-20 18:33:05 -07:00
if (results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
2014-05-01 19:54:33 -07:00
function replaceQueryString(url, param, value) {
var re = new RegExp("([?|&])" + param + "=.*?(&|$)", "i");
if (url.match(re))
return url.replace(re, '$1' + param + "=" + value + '$2');
2015-06-29 11:45:42 -07:00
else if (value) {
2014-07-02 11:34:08 -07:00
2014-05-01 19:54:33 -07:00
if (url.indexOf('?') == -1) {
return url + '?' + param + "=" + value;
}
return url + '&' + param + "=" + value;
}
2015-06-29 11:45:42 -07:00
return url;
2014-05-01 19:54:33 -07:00
}
2013-04-12 11:22:40 -07:00
function parseISO8601Date(s, options) {
options = options || {};
2013-02-20 18:33:05 -07:00
// parenthese matches:
// year month day hours minutes seconds
// dotmilliseconds
// tzstring plusminus hours minutes
var re = /(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d+)?(Z|([+-])(\d{2}):(\d{2}))?/;
2013-02-20 18:33:05 -07:00
2013-04-12 11:22:40 -07:00
var d = s.match(re);
2013-02-20 18:33:05 -07:00
// "2010-12-07T11:00:00.000-09:00" parses to:
// ["2010-12-07T11:00:00.000-09:00", "2010", "12", "07", "11",
// "00", "00", ".000", "-09:00", "-", "09", "00"]
// "2010-12-07T11:00:00.000Z" parses to:
// ["2010-12-07T11:00:00.000Z", "2010", "12", "07", "11",
// "00", "00", ".000", "Z", undefined, undefined, undefined]
if (!d) {
2013-04-12 11:22:40 -07:00
2013-02-20 18:33:05 -07:00
throw "Couldn't parse ISO 8601 date string '" + s + "'";
}
// parse strings, leading zeros into proper ints
var a = [1, 2, 3, 4, 5, 6, 10, 11];
for (var i in a) {
d[a[i]] = parseInt(d[a[i]], 10);
}
d[7] = parseFloat(d[7]);
// Date.UTC(year, month[, date[, hrs[, min[, sec[, ms]]]]])
// note that month is 0-11, not 1-12
// see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/UTC
var ms = Date.UTC(d[1], d[2] - 1, d[3], d[4], d[5], d[6]);
// if there are milliseconds, add them
if (d[7] > 0) {
ms += Math.round(d[7] * 1000);
}
// if there's a timezone, calculate it
if (d[8] != "Z" && d[10]) {
var offset = d[10] * 60 * 60 * 1000;
if (d[11]) {
offset += d[11] * 60 * 1000;
}
if (d[9] == "-") {
ms -= offset;
} else {
ms += offset;
}
2013-04-12 11:22:40 -07:00
} else if (!options.toLocal) {
2013-02-20 18:33:05 -07:00
ms += new Date().getTimezoneOffset() * 60000;
}
return new Date(ms);
2015-12-14 08:43:03 -07:00
}