Add URI component
Great library for Url manipulation, see http://medialize.github.io/URI.js/ MIT and GPLv3 License refs #4611
This commit is contained in:
parent
e6b3a54e90
commit
f596f72169
|
@ -0,0 +1,185 @@
|
|||
/*!
|
||||
* URI.js - Mutating URLs
|
||||
* IPv6 Support
|
||||
*
|
||||
* Version: 1.11.2
|
||||
*
|
||||
* Author: Rodney Rehm
|
||||
* Web: http://medialize.github.com/URI.js/
|
||||
*
|
||||
* Licensed under
|
||||
* MIT License http://www.opensource.org/licenses/mit-license
|
||||
* GPL v3 http://opensource.org/licenses/GPL-3.0
|
||||
*
|
||||
*/
|
||||
(function (root, factory) {
|
||||
// https://github.com/umdjs/umd/blob/master/returnExports.js
|
||||
if (typeof exports === 'object') {
|
||||
// Node
|
||||
module.exports = factory();
|
||||
} else if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(factory);
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
root.IPv6 = factory(root);
|
||||
}
|
||||
}(this, function (root) {
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
var _in = "fe80:0000:0000:0000:0204:61ff:fe9d:f156";
|
||||
var _out = IPv6.best(_in);
|
||||
var _expected = "fe80::204:61ff:fe9d:f156";
|
||||
|
||||
console.log(_in, _out, _expected, _out === _expected);
|
||||
*/
|
||||
|
||||
// save current IPv6 variable, if any
|
||||
var _IPv6 = root && root.IPv6;
|
||||
|
||||
function best(address) {
|
||||
// based on:
|
||||
// Javascript to test an IPv6 address for proper format, and to
|
||||
// present the "best text representation" according to IETF Draft RFC at
|
||||
// http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-04
|
||||
// 8 Feb 2010 Rich Brown, Dartware, LLC
|
||||
// Please feel free to use this code as long as you provide a link to
|
||||
// http://www.intermapper.com
|
||||
// http://intermapper.com/support/tools/IPV6-Validator.aspx
|
||||
// http://download.dartware.com/thirdparty/ipv6validator.js
|
||||
|
||||
var _address = address.toLowerCase();
|
||||
var segments = _address.split(':');
|
||||
var length = segments.length;
|
||||
var total = 8;
|
||||
|
||||
// trim colons (:: or ::a:b:c… or …a:b:c::)
|
||||
if (segments[0] === '' && segments[1] === '' && segments[2] === '') {
|
||||
// must have been ::
|
||||
// remove first two items
|
||||
segments.shift();
|
||||
segments.shift();
|
||||
} else if (segments[0] === '' && segments[1] === '') {
|
||||
// must have been ::xxxx
|
||||
// remove the first item
|
||||
segments.shift();
|
||||
} else if (segments[length - 1] === '' && segments[length - 2] === '') {
|
||||
// must have been xxxx::
|
||||
segments.pop();
|
||||
}
|
||||
|
||||
length = segments.length;
|
||||
|
||||
// adjust total segments for IPv4 trailer
|
||||
if (segments[length - 1].indexOf('.') !== -1) {
|
||||
// found a "." which means IPv4
|
||||
total = 7;
|
||||
}
|
||||
|
||||
// fill empty segments them with "0000"
|
||||
var pos;
|
||||
for (pos = 0; pos < length; pos++) {
|
||||
if (segments[pos] === '') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pos < total) {
|
||||
segments.splice(pos, 1, '0000');
|
||||
while (segments.length < total) {
|
||||
segments.splice(pos, 0, '0000');
|
||||
}
|
||||
|
||||
length = segments.length;
|
||||
}
|
||||
|
||||
// strip leading zeros
|
||||
var _segments;
|
||||
for (var i = 0; i < total; i++) {
|
||||
_segments = segments[i].split("");
|
||||
for (var j = 0; j < 3 ; j++) {
|
||||
if (_segments[0] === '0' && _segments.length > 1) {
|
||||
_segments.splice(0,1);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
segments[i] = _segments.join("");
|
||||
}
|
||||
|
||||
// find longest sequence of zeroes and coalesce them into one segment
|
||||
var best = -1;
|
||||
var _best = 0;
|
||||
var _current = 0;
|
||||
var current = -1;
|
||||
var inzeroes = false;
|
||||
// i; already declared
|
||||
|
||||
for (i = 0; i < total; i++) {
|
||||
if (inzeroes) {
|
||||
if (segments[i] === '0') {
|
||||
_current += 1;
|
||||
} else {
|
||||
inzeroes = false;
|
||||
if (_current > _best) {
|
||||
best = current;
|
||||
_best = _current;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (segments[i] == '0') {
|
||||
inzeroes = true;
|
||||
current = i;
|
||||
_current = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_current > _best) {
|
||||
best = current;
|
||||
_best = _current;
|
||||
}
|
||||
|
||||
if (_best > 1) {
|
||||
segments.splice(best, _best, "");
|
||||
}
|
||||
|
||||
length = segments.length;
|
||||
|
||||
// assemble remaining segments
|
||||
var result = '';
|
||||
if (segments[0] === '') {
|
||||
beststr = ":";
|
||||
}
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
result += segments[i];
|
||||
if (i === length - 1) {
|
||||
break;
|
||||
}
|
||||
|
||||
result += ':';
|
||||
}
|
||||
|
||||
if (segments[length - 1] === '') {
|
||||
result += ":";
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
function noConflict(){
|
||||
if (root.IPv6 === this) {
|
||||
root.IPv6 = _IPv6;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
return {
|
||||
best: best,
|
||||
noConflict: noConflict
|
||||
};
|
||||
}));
|
|
@ -0,0 +1,220 @@
|
|||
/*!
|
||||
* URI.js - Mutating URLs
|
||||
* Second Level Domain (SLD) Support
|
||||
*
|
||||
* Version: 1.11.2
|
||||
*
|
||||
* Author: Rodney Rehm
|
||||
* Web: http://medialize.github.com/URI.js/
|
||||
*
|
||||
* Licensed under
|
||||
* MIT License http://www.opensource.org/licenses/mit-license
|
||||
* GPL v3 http://opensource.org/licenses/GPL-3.0
|
||||
*
|
||||
*/
|
||||
|
||||
(function (root, factory) {
|
||||
// https://github.com/umdjs/umd/blob/master/returnExports.js
|
||||
if (typeof exports === 'object') {
|
||||
// Node
|
||||
module.exports = factory();
|
||||
} else if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(factory);
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
root.SecondLevelDomains = factory(root);
|
||||
}
|
||||
}(this, function (root) {
|
||||
"use strict";
|
||||
|
||||
// save current SecondLevelDomains variable, if any
|
||||
var _SecondLevelDomains = root && root.SecondLevelDomains;
|
||||
|
||||
var hasOwn = Object.prototype.hasOwnProperty;
|
||||
var SLD = {
|
||||
// list of known Second Level Domains
|
||||
// converted list of SLDs from https://github.com/gavingmiller/second-level-domains
|
||||
// ----
|
||||
// publicsuffix.org is more current and actually used by a couple of browsers internally.
|
||||
// downside is it also contains domains like "dyndns.org" - which is fine for the security
|
||||
// issues browser have to deal with (SOP for cookies, etc) - but is way overboard for URI.js
|
||||
// ----
|
||||
list: {
|
||||
"ac":"com|gov|mil|net|org",
|
||||
"ae":"ac|co|gov|mil|name|net|org|pro|sch",
|
||||
"af":"com|edu|gov|net|org",
|
||||
"al":"com|edu|gov|mil|net|org",
|
||||
"ao":"co|ed|gv|it|og|pb",
|
||||
"ar":"com|edu|gob|gov|int|mil|net|org|tur",
|
||||
"at":"ac|co|gv|or",
|
||||
"au":"asn|com|csiro|edu|gov|id|net|org",
|
||||
"ba":"co|com|edu|gov|mil|net|org|rs|unbi|unmo|unsa|untz|unze",
|
||||
"bb":"biz|co|com|edu|gov|info|net|org|store|tv",
|
||||
"bh":"biz|cc|com|edu|gov|info|net|org",
|
||||
"bn":"com|edu|gov|net|org",
|
||||
"bo":"com|edu|gob|gov|int|mil|net|org|tv",
|
||||
"br":"adm|adv|agr|am|arq|art|ato|b|bio|blog|bmd|cim|cng|cnt|com|coop|ecn|edu|eng|esp|etc|eti|far|flog|fm|fnd|fot|fst|g12|ggf|gov|imb|ind|inf|jor|jus|lel|mat|med|mil|mus|net|nom|not|ntr|odo|org|ppg|pro|psc|psi|qsl|rec|slg|srv|tmp|trd|tur|tv|vet|vlog|wiki|zlg",
|
||||
"bs":"com|edu|gov|net|org",
|
||||
"bz":"du|et|om|ov|rg",
|
||||
"ca":"ab|bc|mb|nb|nf|nl|ns|nt|nu|on|pe|qc|sk|yk",
|
||||
"ck":"biz|co|edu|gen|gov|info|net|org",
|
||||
"cn":"ac|ah|bj|com|cq|edu|fj|gd|gov|gs|gx|gz|ha|hb|he|hi|hl|hn|jl|js|jx|ln|mil|net|nm|nx|org|qh|sc|sd|sh|sn|sx|tj|tw|xj|xz|yn|zj",
|
||||
"co":"com|edu|gov|mil|net|nom|org",
|
||||
"cr":"ac|c|co|ed|fi|go|or|sa",
|
||||
"cy":"ac|biz|com|ekloges|gov|ltd|name|net|org|parliament|press|pro|tm",
|
||||
"do":"art|com|edu|gob|gov|mil|net|org|sld|web",
|
||||
"dz":"art|asso|com|edu|gov|net|org|pol",
|
||||
"ec":"com|edu|fin|gov|info|med|mil|net|org|pro",
|
||||
"eg":"com|edu|eun|gov|mil|name|net|org|sci",
|
||||
"er":"com|edu|gov|ind|mil|net|org|rochest|w",
|
||||
"es":"com|edu|gob|nom|org",
|
||||
"et":"biz|com|edu|gov|info|name|net|org",
|
||||
"fj":"ac|biz|com|info|mil|name|net|org|pro",
|
||||
"fk":"ac|co|gov|net|nom|org",
|
||||
"fr":"asso|com|f|gouv|nom|prd|presse|tm",
|
||||
"gg":"co|net|org",
|
||||
"gh":"com|edu|gov|mil|org",
|
||||
"gn":"ac|com|gov|net|org",
|
||||
"gr":"com|edu|gov|mil|net|org",
|
||||
"gt":"com|edu|gob|ind|mil|net|org",
|
||||
"gu":"com|edu|gov|net|org",
|
||||
"hk":"com|edu|gov|idv|net|org",
|
||||
"id":"ac|co|go|mil|net|or|sch|web",
|
||||
"il":"ac|co|gov|idf|k12|muni|net|org",
|
||||
"in":"ac|co|edu|ernet|firm|gen|gov|i|ind|mil|net|nic|org|res",
|
||||
"iq":"com|edu|gov|i|mil|net|org",
|
||||
"ir":"ac|co|dnssec|gov|i|id|net|org|sch",
|
||||
"it":"edu|gov",
|
||||
"je":"co|net|org",
|
||||
"jo":"com|edu|gov|mil|name|net|org|sch",
|
||||
"jp":"ac|ad|co|ed|go|gr|lg|ne|or",
|
||||
"ke":"ac|co|go|info|me|mobi|ne|or|sc",
|
||||
"kh":"com|edu|gov|mil|net|org|per",
|
||||
"ki":"biz|com|de|edu|gov|info|mob|net|org|tel",
|
||||
"km":"asso|com|coop|edu|gouv|k|medecin|mil|nom|notaires|pharmaciens|presse|tm|veterinaire",
|
||||
"kn":"edu|gov|net|org",
|
||||
"kr":"ac|busan|chungbuk|chungnam|co|daegu|daejeon|es|gangwon|go|gwangju|gyeongbuk|gyeonggi|gyeongnam|hs|incheon|jeju|jeonbuk|jeonnam|k|kg|mil|ms|ne|or|pe|re|sc|seoul|ulsan",
|
||||
"kw":"com|edu|gov|net|org",
|
||||
"ky":"com|edu|gov|net|org",
|
||||
"kz":"com|edu|gov|mil|net|org",
|
||||
"lb":"com|edu|gov|net|org",
|
||||
"lk":"assn|com|edu|gov|grp|hotel|int|ltd|net|ngo|org|sch|soc|web",
|
||||
"lr":"com|edu|gov|net|org",
|
||||
"lv":"asn|com|conf|edu|gov|id|mil|net|org",
|
||||
"ly":"com|edu|gov|id|med|net|org|plc|sch",
|
||||
"ma":"ac|co|gov|m|net|org|press",
|
||||
"mc":"asso|tm",
|
||||
"me":"ac|co|edu|gov|its|net|org|priv",
|
||||
"mg":"com|edu|gov|mil|nom|org|prd|tm",
|
||||
"mk":"com|edu|gov|inf|name|net|org|pro",
|
||||
"ml":"com|edu|gov|net|org|presse",
|
||||
"mn":"edu|gov|org",
|
||||
"mo":"com|edu|gov|net|org",
|
||||
"mt":"com|edu|gov|net|org",
|
||||
"mv":"aero|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro",
|
||||
"mw":"ac|co|com|coop|edu|gov|int|museum|net|org",
|
||||
"mx":"com|edu|gob|net|org",
|
||||
"my":"com|edu|gov|mil|name|net|org|sch",
|
||||
"nf":"arts|com|firm|info|net|other|per|rec|store|web",
|
||||
"ng":"biz|com|edu|gov|mil|mobi|name|net|org|sch",
|
||||
"ni":"ac|co|com|edu|gob|mil|net|nom|org",
|
||||
"np":"com|edu|gov|mil|net|org",
|
||||
"nr":"biz|com|edu|gov|info|net|org",
|
||||
"om":"ac|biz|co|com|edu|gov|med|mil|museum|net|org|pro|sch",
|
||||
"pe":"com|edu|gob|mil|net|nom|org|sld",
|
||||
"ph":"com|edu|gov|i|mil|net|ngo|org",
|
||||
"pk":"biz|com|edu|fam|gob|gok|gon|gop|gos|gov|net|org|web",
|
||||
"pl":"art|bialystok|biz|com|edu|gda|gdansk|gorzow|gov|info|katowice|krakow|lodz|lublin|mil|net|ngo|olsztyn|org|poznan|pwr|radom|slupsk|szczecin|torun|warszawa|waw|wroc|wroclaw|zgora",
|
||||
"pr":"ac|biz|com|edu|est|gov|info|isla|name|net|org|pro|prof",
|
||||
"ps":"com|edu|gov|net|org|plo|sec",
|
||||
"pw":"belau|co|ed|go|ne|or",
|
||||
"ro":"arts|com|firm|info|nom|nt|org|rec|store|tm|www",
|
||||
"rs":"ac|co|edu|gov|in|org",
|
||||
"sb":"com|edu|gov|net|org",
|
||||
"sc":"com|edu|gov|net|org",
|
||||
"sh":"co|com|edu|gov|net|nom|org",
|
||||
"sl":"com|edu|gov|net|org",
|
||||
"st":"co|com|consulado|edu|embaixada|gov|mil|net|org|principe|saotome|store",
|
||||
"sv":"com|edu|gob|org|red",
|
||||
"sz":"ac|co|org",
|
||||
"tr":"av|bbs|bel|biz|com|dr|edu|gen|gov|info|k12|name|net|org|pol|tel|tsk|tv|web",
|
||||
"tt":"aero|biz|cat|co|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel",
|
||||
"tw":"club|com|ebiz|edu|game|gov|idv|mil|net|org",
|
||||
"mu":"ac|co|com|gov|net|or|org",
|
||||
"mz":"ac|co|edu|gov|org",
|
||||
"na":"co|com",
|
||||
"nz":"ac|co|cri|geek|gen|govt|health|iwi|maori|mil|net|org|parliament|school",
|
||||
"pa":"abo|ac|com|edu|gob|ing|med|net|nom|org|sld",
|
||||
"pt":"com|edu|gov|int|net|nome|org|publ",
|
||||
"py":"com|edu|gov|mil|net|org",
|
||||
"qa":"com|edu|gov|mil|net|org",
|
||||
"re":"asso|com|nom",
|
||||
"ru":"ac|adygeya|altai|amur|arkhangelsk|astrakhan|bashkiria|belgorod|bir|bryansk|buryatia|cbg|chel|chelyabinsk|chita|chukotka|chuvashia|com|dagestan|e-burg|edu|gov|grozny|int|irkutsk|ivanovo|izhevsk|jar|joshkar-ola|kalmykia|kaluga|kamchatka|karelia|kazan|kchr|kemerovo|khabarovsk|khakassia|khv|kirov|koenig|komi|kostroma|kranoyarsk|kuban|kurgan|kursk|lipetsk|magadan|mari|mari-el|marine|mil|mordovia|mosreg|msk|murmansk|nalchik|net|nnov|nov|novosibirsk|nsk|omsk|orenburg|org|oryol|penza|perm|pp|pskov|ptz|rnd|ryazan|sakhalin|samara|saratov|simbirsk|smolensk|spb|stavropol|stv|surgut|tambov|tatarstan|tom|tomsk|tsaritsyn|tsk|tula|tuva|tver|tyumen|udm|udmurtia|ulan-ude|vladikavkaz|vladimir|vladivostok|volgograd|vologda|voronezh|vrn|vyatka|yakutia|yamal|yekaterinburg|yuzhno-sakhalinsk",
|
||||
"rw":"ac|co|com|edu|gouv|gov|int|mil|net",
|
||||
"sa":"com|edu|gov|med|net|org|pub|sch",
|
||||
"sd":"com|edu|gov|info|med|net|org|tv",
|
||||
"se":"a|ac|b|bd|c|d|e|f|g|h|i|k|l|m|n|o|org|p|parti|pp|press|r|s|t|tm|u|w|x|y|z",
|
||||
"sg":"com|edu|gov|idn|net|org|per",
|
||||
"sn":"art|com|edu|gouv|org|perso|univ",
|
||||
"sy":"com|edu|gov|mil|net|news|org",
|
||||
"th":"ac|co|go|in|mi|net|or",
|
||||
"tj":"ac|biz|co|com|edu|go|gov|info|int|mil|name|net|nic|org|test|web",
|
||||
"tn":"agrinet|com|defense|edunet|ens|fin|gov|ind|info|intl|mincom|nat|net|org|perso|rnrt|rns|rnu|tourism",
|
||||
"tz":"ac|co|go|ne|or",
|
||||
"ua":"biz|cherkassy|chernigov|chernovtsy|ck|cn|co|com|crimea|cv|dn|dnepropetrovsk|donetsk|dp|edu|gov|if|in|ivano-frankivsk|kh|kharkov|kherson|khmelnitskiy|kiev|kirovograd|km|kr|ks|kv|lg|lugansk|lutsk|lviv|me|mk|net|nikolaev|od|odessa|org|pl|poltava|pp|rovno|rv|sebastopol|sumy|te|ternopil|uzhgorod|vinnica|vn|zaporizhzhe|zhitomir|zp|zt",
|
||||
"ug":"ac|co|go|ne|or|org|sc",
|
||||
"uk":"ac|bl|british-library|co|cym|gov|govt|icnet|jet|lea|ltd|me|mil|mod|national-library-scotland|nel|net|nhs|nic|nls|org|orgn|parliament|plc|police|sch|scot|soc",
|
||||
"us":"dni|fed|isa|kids|nsn",
|
||||
"uy":"com|edu|gub|mil|net|org",
|
||||
"ve":"co|com|edu|gob|info|mil|net|org|web",
|
||||
"vi":"co|com|k12|net|org",
|
||||
"vn":"ac|biz|com|edu|gov|health|info|int|name|net|org|pro",
|
||||
"ye":"co|com|gov|ltd|me|net|org|plc",
|
||||
"yu":"ac|co|edu|gov|org",
|
||||
"za":"ac|agric|alt|bourse|city|co|cybernet|db|edu|gov|grondar|iaccess|imt|inca|landesign|law|mil|net|ngo|nis|nom|olivetti|org|pix|school|tm|web",
|
||||
"zm":"ac|co|com|edu|gov|net|org|sch"
|
||||
},
|
||||
// SLD expression for each TLD
|
||||
//expressions: {},
|
||||
// SLD expression for all TLDs
|
||||
has_expression: null,
|
||||
is_expression: null,
|
||||
// validate domain is a known SLD
|
||||
has: function(domain) {
|
||||
return !!domain.match(SLD.has_expression);
|
||||
},
|
||||
is: function(domain) {
|
||||
return !!domain.match(SLD.is_expression);
|
||||
},
|
||||
get: function(domain) {
|
||||
var t = domain.match(SLD.has_expression);
|
||||
return t && t[1] || null;
|
||||
},
|
||||
noConflict: function(){
|
||||
if (root.SecondLevelDomains === this) {
|
||||
root.SecondLevelDomains = _SecondLevelDomains;
|
||||
}
|
||||
return this;
|
||||
},
|
||||
init: function() {
|
||||
var t = '';
|
||||
for (var tld in SLD.list) {
|
||||
if (!hasOwn.call(SLD.list, tld)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var expression = '(' + SLD.list[tld] + ')\.' + tld;
|
||||
//SLD.expressions[tld] = new RegExp('\.' + expression + '$', 'i');
|
||||
t += '|(' + expression + ')';
|
||||
}
|
||||
|
||||
SLD.has_expression = new RegExp('\\.(' + t.substr(1) + ')$', 'i');
|
||||
SLD.is_expression = new RegExp('^(' + t.substr(1) + ')$', 'i');
|
||||
}
|
||||
};
|
||||
|
||||
SLD.init();
|
||||
|
||||
return SLD;
|
||||
}));
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* Extending URI.js for fragment abuse
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------------
|
||||
// EXAMPLE: storing application/x-www-form-urlencoded data in the fragment
|
||||
// possibly helpful for Google's hashbangs
|
||||
// see http://code.google.com/web/ajaxcrawling/
|
||||
// --------------------------------------------------------------------------------
|
||||
|
||||
// Note: make sure this is the last file loaded!
|
||||
|
||||
// USAGE:
|
||||
// var uri = URI("http://example.org/#?foo=bar");
|
||||
// uri.fragment(true) === {foo: "bar"};
|
||||
// uri.fragment({bar: "foo"});
|
||||
// uri.toString() === "http://example.org/#?bar=foo";
|
||||
// uri.addFragment("name", "value");
|
||||
// uri.toString() === "http://example.org/#?bar=foo&name=value";
|
||||
// uri.removeFragment("name");
|
||||
// uri.toString() === "http://example.org/#?bar=foo";
|
||||
|
||||
(function (root, factory) {
|
||||
// https://github.com/umdjs/umd/blob/master/returnExports.js
|
||||
if (typeof exports === 'object') {
|
||||
// Node
|
||||
module.exports = factory(require('./URI'));
|
||||
} else if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['./URI'], factory);
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
factory(root.URI);
|
||||
}
|
||||
}(this, function (URI) {
|
||||
"use strict";
|
||||
|
||||
var p = URI.prototype;
|
||||
// old fragment handler we need to wrap
|
||||
var f = p.fragment;
|
||||
|
||||
// make fragmentPrefix configurable
|
||||
URI.fragmentPrefix = '?';
|
||||
var _parts = URI._parts;
|
||||
URI._parts = function() {
|
||||
var parts = _parts();
|
||||
parts.fragmentPrefix = URI.fragmentPrefix;
|
||||
return parts;
|
||||
};
|
||||
p.fragmentPrefix = function(v) {
|
||||
this._parts.fragmentPrefix = v;
|
||||
return this;
|
||||
};
|
||||
|
||||
// add fragment(true) and fragment({key: value}) signatures
|
||||
p.fragment = function(v, build) {
|
||||
var prefix = this._parts.fragmentPrefix;
|
||||
var fragment = this._parts.fragment || "";
|
||||
|
||||
if (v === true) {
|
||||
if (fragment.substring(0, prefix.length) !== prefix) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return URI.parseQuery(fragment.substring(prefix.length));
|
||||
} else if (v !== undefined && typeof v !== "string") {
|
||||
this._parts.fragment = prefix + URI.buildQuery(v);
|
||||
this.build(!build);
|
||||
return this;
|
||||
} else {
|
||||
return f.call(this, v, build);
|
||||
}
|
||||
};
|
||||
p.addFragment = function(name, value, build) {
|
||||
var prefix = this._parts.fragmentPrefix;
|
||||
var data = URI.parseQuery((this._parts.fragment || "").substring(prefix.length));
|
||||
URI.addQuery(data, name, value);
|
||||
this._parts.fragment = prefix + URI.buildQuery(data);
|
||||
if (typeof name !== "string") {
|
||||
build = value;
|
||||
}
|
||||
|
||||
this.build(!build);
|
||||
return this;
|
||||
};
|
||||
p.removeFragment = function(name, value, build) {
|
||||
var prefix = this._parts.fragmentPrefix;
|
||||
var data = URI.parseQuery((this._parts.fragment || "").substring(prefix.length));
|
||||
URI.removeQuery(data, name, value);
|
||||
this._parts.fragment = prefix + URI.buildQuery(data);
|
||||
if (typeof name !== "string") {
|
||||
build = value;
|
||||
}
|
||||
|
||||
this.build(!build);
|
||||
return this;
|
||||
};
|
||||
p.addHash = p.addFragment;
|
||||
p.removeHash = p.removeFragment;
|
||||
|
||||
// extending existing object rather than defining something new
|
||||
return {};
|
||||
}));
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Extending URI.js for fragment abuse
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------------
|
||||
// EXAMPLE: storing a relative URL in the fragment ("FragmentURI")
|
||||
// possibly helpful when working with backbone.js or sammy.js
|
||||
// inspired by https://github.com/medialize/URI.js/pull/2
|
||||
// --------------------------------------------------------------------------------
|
||||
|
||||
// Note: make sure this is the last file loaded!
|
||||
|
||||
// USAGE:
|
||||
// var uri = URI("http://example.org/#!/foo/bar/baz.html");
|
||||
// var furi = uri.fragment(true);
|
||||
// furi.pathname() === '/foo/bar/baz.html';
|
||||
// furi.pathname('/hello.html');
|
||||
// uri.toString() === "http://example.org/#!/hello.html"
|
||||
|
||||
(function (root, factory) {
|
||||
// https://github.com/umdjs/umd/blob/master/returnExports.js
|
||||
if (typeof exports === 'object') {
|
||||
// Node
|
||||
module.exports = factory(require('./URI'));
|
||||
} else if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['./URI'], factory);
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
factory(root.URI);
|
||||
}
|
||||
}(this, function (URI) {
|
||||
"use strict";
|
||||
|
||||
var p = URI.prototype;
|
||||
// old handlers we need to wrap
|
||||
var f = p.fragment;
|
||||
var b = p.build;
|
||||
|
||||
// make fragmentPrefix configurable
|
||||
URI.fragmentPrefix = '!';
|
||||
var _parts = URI._parts;
|
||||
URI._parts = function() {
|
||||
var parts = _parts();
|
||||
parts.fragmentPrefix = URI.fragmentPrefix;
|
||||
return parts;
|
||||
};
|
||||
p.fragmentPrefix = function(v) {
|
||||
this._parts.fragmentPrefix = v;
|
||||
return this;
|
||||
};
|
||||
|
||||
// add fragment(true) and fragment(URI) signatures
|
||||
p.fragment = function(v, build) {
|
||||
var prefix = this._parts.fragmentPrefix;
|
||||
var fragment = this._parts.fragment || "";
|
||||
var furi;
|
||||
|
||||
if (v === true) {
|
||||
if (fragment.substring(0, prefix.length) !== prefix) {
|
||||
furi = URI("");
|
||||
} else {
|
||||
furi = new URI(fragment.substring(prefix.length));
|
||||
}
|
||||
|
||||
this._fragmentURI = furi;
|
||||
furi._parentURI = this;
|
||||
return furi;
|
||||
} else if (v !== undefined && typeof v !== "string") {
|
||||
this._fragmentURI = v;
|
||||
v._parentURI = v;
|
||||
this._parts.fragment = prefix + v.toString();
|
||||
this.build(!build);
|
||||
return this;
|
||||
} else if (typeof v === "string") {
|
||||
this._fragmentURI = undefined;
|
||||
}
|
||||
|
||||
return f.call(this, v, build);
|
||||
};
|
||||
|
||||
// make .build() of the actual URI aware of the FragmentURI
|
||||
p.build = function(deferBuild) {
|
||||
var t = b.call(this, deferBuild);
|
||||
|
||||
if (deferBuild !== false && this._parentURI) {
|
||||
// update the parent
|
||||
this._parentURI.fragment(this);
|
||||
}
|
||||
|
||||
return t;
|
||||
};
|
||||
|
||||
// extending existing object rather than defining something new
|
||||
return {};
|
||||
}));
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,81 @@
|
|||
/*! URI.js v1.11.2 http://medialize.github.com/URI.js/ */
|
||||
/* build contains: IPv6.js, punycode.js, SecondLevelDomains.js, URI.js, URITemplate.js */
|
||||
(function(f,l){"object"===typeof exports?module.exports=l():"function"===typeof define&&define.amd?define(l):f.IPv6=l(f)})(this,function(f){var l=f&&f.IPv6;return{best:function(h){h=h.toLowerCase().split(":");var f=h.length,d=8;""===h[0]&&""===h[1]&&""===h[2]?(h.shift(),h.shift()):""===h[0]&&""===h[1]?h.shift():""===h[f-1]&&""===h[f-2]&&h.pop();f=h.length;-1!==h[f-1].indexOf(".")&&(d=7);var q;for(q=0;q<f&&""!==h[q];q++);if(q<d)for(h.splice(q,1,"0000");h.length<d;)h.splice(q,0,"0000");for(q=0;q<d;q++){for(var f=
|
||||
h[q].split(""),l=0;3>l;l++)if("0"===f[0]&&1<f.length)f.splice(0,1);else break;h[q]=f.join("")}var f=-1,n=l=0,e=-1,u=!1;for(q=0;q<d;q++)u?"0"===h[q]?n+=1:(u=!1,n>l&&(f=e,l=n)):"0"==h[q]&&(u=!0,e=q,n=1);n>l&&(f=e,l=n);1<l&&h.splice(f,l,"");f=h.length;d="";""===h[0]&&(beststr=":");for(q=0;q<f;q++){d+=h[q];if(q===f-1)break;d+=":"}""===h[f-1]&&(d+=":");return d},noConflict:function(){f.IPv6===this&&(f.IPv6=l);return this}}});
|
||||
(function(f){function l(a){throw RangeError(c[a]);}function h(a,b){for(var c=a.length;c--;)a[c]=b(a[c]);return a}function p(a){for(var b=[],c=0,d=a.length,k,g;c<d;)k=a.charCodeAt(c++),55296<=k&&56319>=k&&c<d?(g=a.charCodeAt(c++),56320==(g&64512)?b.push(((k&1023)<<10)+(g&1023)+65536):(b.push(k),c--)):b.push(k);return b}function d(a){return h(a,function(a){var b="";65535<a&&(a-=65536,b+=x(a>>>10&1023|55296),a=56320|a&1023);return b+=x(a)}).join("")}function q(a,b,c){var d=0;a=c?B(a/y):a>>1;for(a+=B(a/
|
||||
b);a>k*m>>1;d+=g)a=B(a/k);return B(d+(k+1)*a/(a+s))}function A(a){var b=[],c=a.length,k,e=0,f=D,h=w,x,u,v,t,s;x=a.lastIndexOf(E);0>x&&(x=0);for(u=0;u<x;++u)128<=a.charCodeAt(u)&&l("not-basic"),b.push(a.charCodeAt(u));for(x=0<x?x+1:0;x<c;){u=e;k=1;for(v=g;;v+=g){x>=c&&l("invalid-input");t=a.charCodeAt(x++);t=10>t-48?t-22:26>t-65?t-65:26>t-97?t-97:g;(t>=g||t>B((C-e)/k))&&l("overflow");e+=t*k;s=v<=h?r:v>=h+m?m:v-h;if(t<s)break;t=g-s;k>B(C/t)&&l("overflow");k*=t}k=b.length+1;h=q(e-u,k,0==u);B(e/k)>C-
|
||||
f&&l("overflow");f+=B(e/k);e%=k;b.splice(e++,0,f)}return d(b)}function n(a){var b,c,d,k,e,f,h,u,t,v=[],s,z,n;a=p(a);s=a.length;b=D;c=0;e=w;for(f=0;f<s;++f)t=a[f],128>t&&v.push(x(t));for((d=k=v.length)&&v.push(E);d<s;){h=C;for(f=0;f<s;++f)t=a[f],t>=b&&t<h&&(h=t);z=d+1;h-b>B((C-c)/z)&&l("overflow");c+=(h-b)*z;b=h;for(f=0;f<s;++f)if(t=a[f],t<b&&++c>C&&l("overflow"),t==b){u=c;for(h=g;;h+=g){t=h<=e?r:h>=e+m?m:h-e;if(u<t)break;n=u-t;u=g-t;v.push(x(t+n%u+22+75*(26>t+n%u)-0));u=B(n/u)}v.push(x(u+22+75*(26>
|
||||
u)-0));e=q(c,z,d==k);c=0;++d}++c;++b}return v.join("")}var e="object"==typeof exports&&exports,u="object"==typeof module&&module&&module.exports==e&&module,v="object"==typeof global&&global;if(v.global===v||v.window===v)f=v;var z,C=2147483647,g=36,r=1,m=26,s=38,y=700,w=72,D=128,E="-",F=/^xn--/,a=/[^ -~]/,b=/\x2E|\u3002|\uFF0E|\uFF61/g,c={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},k=g-r,B=
|
||||
Math.floor,x=String.fromCharCode,t;z={version:"1.2.3",ucs2:{decode:p,encode:d},decode:A,encode:n,toASCII:function(c){return h(c.split(b),function(b){return a.test(b)?"xn--"+n(b):b}).join(".")},toUnicode:function(a){return h(a.split(b),function(a){return F.test(a)?A(a.slice(4).toLowerCase()):a}).join(".")}};if("function"==typeof define&&"object"==typeof define.amd&&define.amd)define(function(){return z});else if(e&&!e.nodeType)if(u)u.exports=z;else for(t in z)z.hasOwnProperty(t)&&(e[t]=z[t]);else f.punycode=
|
||||
z})(this);
|
||||
(function(f,l){"object"===typeof exports?module.exports=l():"function"===typeof define&&define.amd?define(l):f.SecondLevelDomains=l(f)})(this,function(f){var l=f&&f.SecondLevelDomains,h=Object.prototype.hasOwnProperty,p={list:{ac:"com|gov|mil|net|org",ae:"ac|co|gov|mil|name|net|org|pro|sch",af:"com|edu|gov|net|org",al:"com|edu|gov|mil|net|org",ao:"co|ed|gv|it|og|pb",ar:"com|edu|gob|gov|int|mil|net|org|tur",at:"ac|co|gv|or",au:"asn|com|csiro|edu|gov|id|net|org",ba:"co|com|edu|gov|mil|net|org|rs|unbi|unmo|unsa|untz|unze",bb:"biz|co|com|edu|gov|info|net|org|store|tv",
|
||||
bh:"biz|cc|com|edu|gov|info|net|org",bn:"com|edu|gov|net|org",bo:"com|edu|gob|gov|int|mil|net|org|tv",br:"adm|adv|agr|am|arq|art|ato|b|bio|blog|bmd|cim|cng|cnt|com|coop|ecn|edu|eng|esp|etc|eti|far|flog|fm|fnd|fot|fst|g12|ggf|gov|imb|ind|inf|jor|jus|lel|mat|med|mil|mus|net|nom|not|ntr|odo|org|ppg|pro|psc|psi|qsl|rec|slg|srv|tmp|trd|tur|tv|vet|vlog|wiki|zlg",bs:"com|edu|gov|net|org",bz:"du|et|om|ov|rg",ca:"ab|bc|mb|nb|nf|nl|ns|nt|nu|on|pe|qc|sk|yk",ck:"biz|co|edu|gen|gov|info|net|org",cn:"ac|ah|bj|com|cq|edu|fj|gd|gov|gs|gx|gz|ha|hb|he|hi|hl|hn|jl|js|jx|ln|mil|net|nm|nx|org|qh|sc|sd|sh|sn|sx|tj|tw|xj|xz|yn|zj",
|
||||
co:"com|edu|gov|mil|net|nom|org",cr:"ac|c|co|ed|fi|go|or|sa",cy:"ac|biz|com|ekloges|gov|ltd|name|net|org|parliament|press|pro|tm","do":"art|com|edu|gob|gov|mil|net|org|sld|web",dz:"art|asso|com|edu|gov|net|org|pol",ec:"com|edu|fin|gov|info|med|mil|net|org|pro",eg:"com|edu|eun|gov|mil|name|net|org|sci",er:"com|edu|gov|ind|mil|net|org|rochest|w",es:"com|edu|gob|nom|org",et:"biz|com|edu|gov|info|name|net|org",fj:"ac|biz|com|info|mil|name|net|org|pro",fk:"ac|co|gov|net|nom|org",fr:"asso|com|f|gouv|nom|prd|presse|tm",
|
||||
gg:"co|net|org",gh:"com|edu|gov|mil|org",gn:"ac|com|gov|net|org",gr:"com|edu|gov|mil|net|org",gt:"com|edu|gob|ind|mil|net|org",gu:"com|edu|gov|net|org",hk:"com|edu|gov|idv|net|org",id:"ac|co|go|mil|net|or|sch|web",il:"ac|co|gov|idf|k12|muni|net|org","in":"ac|co|edu|ernet|firm|gen|gov|i|ind|mil|net|nic|org|res",iq:"com|edu|gov|i|mil|net|org",ir:"ac|co|dnssec|gov|i|id|net|org|sch",it:"edu|gov",je:"co|net|org",jo:"com|edu|gov|mil|name|net|org|sch",jp:"ac|ad|co|ed|go|gr|lg|ne|or",ke:"ac|co|go|info|me|mobi|ne|or|sc",
|
||||
kh:"com|edu|gov|mil|net|org|per",ki:"biz|com|de|edu|gov|info|mob|net|org|tel",km:"asso|com|coop|edu|gouv|k|medecin|mil|nom|notaires|pharmaciens|presse|tm|veterinaire",kn:"edu|gov|net|org",kr:"ac|busan|chungbuk|chungnam|co|daegu|daejeon|es|gangwon|go|gwangju|gyeongbuk|gyeonggi|gyeongnam|hs|incheon|jeju|jeonbuk|jeonnam|k|kg|mil|ms|ne|or|pe|re|sc|seoul|ulsan",kw:"com|edu|gov|net|org",ky:"com|edu|gov|net|org",kz:"com|edu|gov|mil|net|org",lb:"com|edu|gov|net|org",lk:"assn|com|edu|gov|grp|hotel|int|ltd|net|ngo|org|sch|soc|web",
|
||||
lr:"com|edu|gov|net|org",lv:"asn|com|conf|edu|gov|id|mil|net|org",ly:"com|edu|gov|id|med|net|org|plc|sch",ma:"ac|co|gov|m|net|org|press",mc:"asso|tm",me:"ac|co|edu|gov|its|net|org|priv",mg:"com|edu|gov|mil|nom|org|prd|tm",mk:"com|edu|gov|inf|name|net|org|pro",ml:"com|edu|gov|net|org|presse",mn:"edu|gov|org",mo:"com|edu|gov|net|org",mt:"com|edu|gov|net|org",mv:"aero|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro",mw:"ac|co|com|coop|edu|gov|int|museum|net|org",mx:"com|edu|gob|net|org",my:"com|edu|gov|mil|name|net|org|sch",
|
||||
nf:"arts|com|firm|info|net|other|per|rec|store|web",ng:"biz|com|edu|gov|mil|mobi|name|net|org|sch",ni:"ac|co|com|edu|gob|mil|net|nom|org",np:"com|edu|gov|mil|net|org",nr:"biz|com|edu|gov|info|net|org",om:"ac|biz|co|com|edu|gov|med|mil|museum|net|org|pro|sch",pe:"com|edu|gob|mil|net|nom|org|sld",ph:"com|edu|gov|i|mil|net|ngo|org",pk:"biz|com|edu|fam|gob|gok|gon|gop|gos|gov|net|org|web",pl:"art|bialystok|biz|com|edu|gda|gdansk|gorzow|gov|info|katowice|krakow|lodz|lublin|mil|net|ngo|olsztyn|org|poznan|pwr|radom|slupsk|szczecin|torun|warszawa|waw|wroc|wroclaw|zgora",
|
||||
pr:"ac|biz|com|edu|est|gov|info|isla|name|net|org|pro|prof",ps:"com|edu|gov|net|org|plo|sec",pw:"belau|co|ed|go|ne|or",ro:"arts|com|firm|info|nom|nt|org|rec|store|tm|www",rs:"ac|co|edu|gov|in|org",sb:"com|edu|gov|net|org",sc:"com|edu|gov|net|org",sh:"co|com|edu|gov|net|nom|org",sl:"com|edu|gov|net|org",st:"co|com|consulado|edu|embaixada|gov|mil|net|org|principe|saotome|store",sv:"com|edu|gob|org|red",sz:"ac|co|org",tr:"av|bbs|bel|biz|com|dr|edu|gen|gov|info|k12|name|net|org|pol|tel|tsk|tv|web",tt:"aero|biz|cat|co|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel",
|
||||
tw:"club|com|ebiz|edu|game|gov|idv|mil|net|org",mu:"ac|co|com|gov|net|or|org",mz:"ac|co|edu|gov|org",na:"co|com",nz:"ac|co|cri|geek|gen|govt|health|iwi|maori|mil|net|org|parliament|school",pa:"abo|ac|com|edu|gob|ing|med|net|nom|org|sld",pt:"com|edu|gov|int|net|nome|org|publ",py:"com|edu|gov|mil|net|org",qa:"com|edu|gov|mil|net|org",re:"asso|com|nom",ru:"ac|adygeya|altai|amur|arkhangelsk|astrakhan|bashkiria|belgorod|bir|bryansk|buryatia|cbg|chel|chelyabinsk|chita|chukotka|chuvashia|com|dagestan|e-burg|edu|gov|grozny|int|irkutsk|ivanovo|izhevsk|jar|joshkar-ola|kalmykia|kaluga|kamchatka|karelia|kazan|kchr|kemerovo|khabarovsk|khakassia|khv|kirov|koenig|komi|kostroma|kranoyarsk|kuban|kurgan|kursk|lipetsk|magadan|mari|mari-el|marine|mil|mordovia|mosreg|msk|murmansk|nalchik|net|nnov|nov|novosibirsk|nsk|omsk|orenburg|org|oryol|penza|perm|pp|pskov|ptz|rnd|ryazan|sakhalin|samara|saratov|simbirsk|smolensk|spb|stavropol|stv|surgut|tambov|tatarstan|tom|tomsk|tsaritsyn|tsk|tula|tuva|tver|tyumen|udm|udmurtia|ulan-ude|vladikavkaz|vladimir|vladivostok|volgograd|vologda|voronezh|vrn|vyatka|yakutia|yamal|yekaterinburg|yuzhno-sakhalinsk",
|
||||
rw:"ac|co|com|edu|gouv|gov|int|mil|net",sa:"com|edu|gov|med|net|org|pub|sch",sd:"com|edu|gov|info|med|net|org|tv",se:"a|ac|b|bd|c|d|e|f|g|h|i|k|l|m|n|o|org|p|parti|pp|press|r|s|t|tm|u|w|x|y|z",sg:"com|edu|gov|idn|net|org|per",sn:"art|com|edu|gouv|org|perso|univ",sy:"com|edu|gov|mil|net|news|org",th:"ac|co|go|in|mi|net|or",tj:"ac|biz|co|com|edu|go|gov|info|int|mil|name|net|nic|org|test|web",tn:"agrinet|com|defense|edunet|ens|fin|gov|ind|info|intl|mincom|nat|net|org|perso|rnrt|rns|rnu|tourism",tz:"ac|co|go|ne|or",
|
||||
ua:"biz|cherkassy|chernigov|chernovtsy|ck|cn|co|com|crimea|cv|dn|dnepropetrovsk|donetsk|dp|edu|gov|if|in|ivano-frankivsk|kh|kharkov|kherson|khmelnitskiy|kiev|kirovograd|km|kr|ks|kv|lg|lugansk|lutsk|lviv|me|mk|net|nikolaev|od|odessa|org|pl|poltava|pp|rovno|rv|sebastopol|sumy|te|ternopil|uzhgorod|vinnica|vn|zaporizhzhe|zhitomir|zp|zt",ug:"ac|co|go|ne|or|org|sc",uk:"ac|bl|british-library|co|cym|gov|govt|icnet|jet|lea|ltd|me|mil|mod|national-library-scotland|nel|net|nhs|nic|nls|org|orgn|parliament|plc|police|sch|scot|soc",
|
||||
us:"dni|fed|isa|kids|nsn",uy:"com|edu|gub|mil|net|org",ve:"co|com|edu|gob|info|mil|net|org|web",vi:"co|com|k12|net|org",vn:"ac|biz|com|edu|gov|health|info|int|name|net|org|pro",ye:"co|com|gov|ltd|me|net|org|plc",yu:"ac|co|edu|gov|org",za:"ac|agric|alt|bourse|city|co|cybernet|db|edu|gov|grondar|iaccess|imt|inca|landesign|law|mil|net|ngo|nis|nom|olivetti|org|pix|school|tm|web",zm:"ac|co|com|edu|gov|net|org|sch"},has_expression:null,is_expression:null,has:function(d){return!!d.match(p.has_expression)},
|
||||
is:function(d){return!!d.match(p.is_expression)},get:function(d){return(d=d.match(p.has_expression))&&d[1]||null},noConflict:function(){f.SecondLevelDomains===this&&(f.SecondLevelDomains=l);return this},init:function(){var d="",f;for(f in p.list)h.call(p.list,f)&&(d+="|("+("("+p.list[f]+")."+f)+")");p.has_expression=RegExp("\\.("+d.substr(1)+")$","i");p.is_expression=RegExp("^("+d.substr(1)+")$","i")}};p.init();return p});
|
||||
(function(f,l){"object"===typeof exports?module.exports=l(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],l):f.URI=l(f.punycode,f.IPv6,f.SecondLevelDomains,f)})(this,function(f,l,h,p){function d(a,b){if(!(this instanceof d))return new d(a,b);void 0===a&&(a="undefined"!==typeof location?location.href+"":"");this.href(a);return void 0!==b?this.absoluteTo(b):this}function q(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,
|
||||
"\\$1")}function A(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function n(a){return"Array"===A(a)}function e(a,b){var c,d;if(n(b)){c=0;for(d=b.length;c<d;c++)if(!e(a,b[c]))return!1;return!0}var g=A(b);c=0;for(d=a.length;c<d;c++)if("RegExp"===g){if("string"===typeof a[c]&&a[c].match(b))return!0}else if(a[c]===b)return!0;return!1}function u(a,b){if(!n(a)||!n(b)||a.length!==b.length)return!1;a.sort();b.sort();for(var c=0,d=a.length;c<d;c++)if(a[c]!==b[c])return!1;
|
||||
return!0}function v(a){return escape(a)}function z(a){return encodeURIComponent(a).replace(/[!'()*]/g,v).replace(/\*/g,"%2A")}var C=p&&p.URI,g=d.prototype,r=Object.prototype.hasOwnProperty;d._parts=function(){return{protocol:null,username:null,password:null,hostname:null,urn:null,port:null,path:null,query:null,fragment:null,duplicateQueryParameters:d.duplicateQueryParameters,escapeQuerySpace:d.escapeQuerySpace}};d.duplicateQueryParameters=!1;d.escapeQuerySpace=!0;d.protocol_expression=/^[a-z][a-z0-9-+-]*$/i;
|
||||
d.idn_expression=/[^a-z0-9\.-]/i;d.punycode_expression=/(xn--)/i;d.ip4_expression=/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;d.ip6_expression=/^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/;
|
||||
d.find_uri_expression=/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/ig;d.defaultPorts={http:"80",https:"443",ftp:"21",gopher:"70",ws:"80",wss:"443"};d.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/;d.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",
|
||||
iframe:"src",embed:"src",source:"src",track:"src",input:"src"};d.getDomAttribute=function(a){if(a&&a.nodeName){var b=a.nodeName.toLowerCase();return"input"===b&&"image"!==a.type?void 0:d.domAttributes[b]}};d.encode=z;d.decode=decodeURIComponent;d.iso8859=function(){d.encode=escape;d.decode=unescape};d.unicode=function(){d.encode=z;d.decode=decodeURIComponent};d.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/ig,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=",
|
||||
"%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/ig,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}}};d.encodeQuery=function(a,b){var c=d.encode(a+"");return b?c.replace(/%20/g,"+"):c};d.decodeQuery=function(a,b){a+="";try{return d.decode(b?
|
||||
a.replace(/\+/g,"%20"):a)}catch(c){return a}};d.recodePath=function(a){a=(a+"").split("/");for(var b=0,c=a.length;b<c;b++)a[b]=d.encodePathSegment(d.decode(a[b]));return a.join("/")};d.decodePath=function(a){a=(a+"").split("/");for(var b=0,c=a.length;b<c;b++)a[b]=d.decodePathSegment(a[b]);return a.join("/")};var m={encode:"encode",decode:"decode"},s,y=function(a,b){return function(c){return d[b](c+"").replace(d.characters[a][b].expression,function(c){return d.characters[a][b].map[c]})}};for(s in m)d[s+
|
||||
"PathSegment"]=y("pathname",m[s]);d.encodeReserved=y("reserved","encode");d.parse=function(a,b){var c;b||(b={});c=a.indexOf("#");-1<c&&(b.fragment=a.substring(c+1)||null,a=a.substring(0,c));c=a.indexOf("?");-1<c&&(b.query=a.substring(c+1)||null,a=a.substring(0,c));"//"===a.substring(0,2)?(b.protocol=null,a=a.substring(2),a=d.parseAuthority(a,b)):(c=a.indexOf(":"),-1<c&&(b.protocol=a.substring(0,c)||null,b.protocol&&!b.protocol.match(d.protocol_expression)?b.protocol=void 0:"file"===b.protocol?a=a.substring(c+
|
||||
3):"//"===a.substring(c+1,c+3)?(a=a.substring(c+3),a=d.parseAuthority(a,b)):(a=a.substring(c+1),b.urn=!0)));b.path=a;return b};d.parseHost=function(a,b){var c=a.indexOf("/"),d;-1===c&&(c=a.length);"["===a.charAt(0)?(d=a.indexOf("]"),b.hostname=a.substring(1,d)||null,b.port=a.substring(d+2,c)||null):a.indexOf(":")!==a.lastIndexOf(":")?(b.hostname=a.substring(0,c)||null,b.port=null):(d=a.substring(0,c).split(":"),b.hostname=d[0]||null,b.port=d[1]||null);b.hostname&&"/"!==a.substring(c).charAt(0)&&(c++,
|
||||
a="/"+a);return a.substring(c)||"/"};d.parseAuthority=function(a,b){a=d.parseUserinfo(a,b);return d.parseHost(a,b)};d.parseUserinfo=function(a,b){var c=a.indexOf("/"),k=-1<c?a.lastIndexOf("@",c):a.indexOf("@");-1<k&&(-1===c||k<c)?(c=a.substring(0,k).split(":"),b.username=c[0]?d.decode(c[0]):null,c.shift(),b.password=c[0]?d.decode(c.join(":")):null,a=a.substring(k+1)):(b.username=null,b.password=null);return a};d.parseQuery=function(a,b){if(!a)return{};a=a.replace(/&+/g,"&").replace(/^\?*&*|&+$/g,
|
||||
"");if(!a)return{};for(var c={},k=a.split("&"),g=k.length,e,f,h=0;h<g;h++)e=k[h].split("="),f=d.decodeQuery(e.shift(),b),e=e.length?d.decodeQuery(e.join("="),b):null,c[f]?("string"===typeof c[f]&&(c[f]=[c[f]]),c[f].push(e)):c[f]=e;return c};d.build=function(a){var b="";a.protocol&&(b+=a.protocol+":");a.urn||!b&&!a.hostname||(b+="//");b+=d.buildAuthority(a)||"";"string"===typeof a.path&&("/"!==a.path.charAt(0)&&"string"===typeof a.hostname&&(b+="/"),b+=a.path);"string"===typeof a.query&&a.query&&(b+=
|
||||
"?"+a.query);"string"===typeof a.fragment&&a.fragment&&(b+="#"+a.fragment);return b};d.buildHost=function(a){var b="";if(a.hostname)d.ip6_expression.test(a.hostname)?b=a.port?b+("["+a.hostname+"]:"+a.port):b+a.hostname:(b+=a.hostname,a.port&&(b+=":"+a.port));else return"";return b};d.buildAuthority=function(a){return d.buildUserinfo(a)+d.buildHost(a)};d.buildUserinfo=function(a){var b="";a.username&&(b+=d.encode(a.username),a.password&&(b+=":"+d.encode(a.password)),b+="@");return b};d.buildQuery=
|
||||
function(a,b,c){var k="",g,e,f,h;for(e in a)if(r.call(a,e)&&e)if(n(a[e]))for(g={},f=0,h=a[e].length;f<h;f++)void 0!==a[e][f]&&void 0===g[a[e][f]+""]&&(k+="&"+d.buildQueryParameter(e,a[e][f],c),!0!==b&&(g[a[e][f]+""]=!0));else void 0!==a[e]&&(k+="&"+d.buildQueryParameter(e,a[e],c));return k.substring(1)};d.buildQueryParameter=function(a,b,c){return d.encodeQuery(a,c)+(null!==b?"="+d.encodeQuery(b,c):"")};d.addQuery=function(a,b,c){if("object"===typeof b)for(var k in b)r.call(b,k)&&d.addQuery(a,k,b[k]);
|
||||
else if("string"===typeof b)void 0===a[b]?a[b]=c:("string"===typeof a[b]&&(a[b]=[a[b]]),n(c)||(c=[c]),a[b]=a[b].concat(c));else throw new TypeError("URI.addQuery() accepts an object, string as the name parameter");};d.removeQuery=function(a,b,c){var k;if(n(b))for(c=0,k=b.length;c<k;c++)a[b[c]]=void 0;else if("object"===typeof b)for(k in b)r.call(b,k)&&d.removeQuery(a,k,b[k]);else if("string"===typeof b)if(void 0!==c)if(a[b]===c)a[b]=void 0;else{if(n(a[b])){k=a[b];var g={},e,f;if(n(c))for(e=0,f=c.length;e<
|
||||
f;e++)g[c[e]]=!0;else g[c]=!0;e=0;for(f=k.length;e<f;e++)void 0!==g[k[e]]&&(k.splice(e,1),f--,e--);a[b]=k}}else a[b]=void 0;else throw new TypeError("URI.addQuery() accepts an object, string as the first parameter");};d.hasQuery=function(a,b,c,k){if("object"===typeof b){for(var g in b)if(r.call(b,g)&&!d.hasQuery(a,g,b[g]))return!1;return!0}if("string"!==typeof b)throw new TypeError("URI.hasQuery() accepts an object, string as the name parameter");switch(A(c)){case "Undefined":return b in a;case "Boolean":return a=
|
||||
Boolean(n(a[b])?a[b].length:a[b]),c===a;case "Function":return!!c(a[b],b,a);case "Array":return n(a[b])?(k?e:u)(a[b],c):!1;case "RegExp":return n(a[b])?k?e(a[b],c):!1:Boolean(a[b]&&a[b].match(c));case "Number":c=String(c);case "String":return n(a[b])?k?e(a[b],c):!1:a[b]===c;default:throw new TypeError("URI.hasQuery() accepts undefined, boolean, string, number, RegExp, Function as the value parameter");}};d.commonPath=function(a,b){var c=Math.min(a.length,b.length),d;for(d=0;d<c;d++)if(a.charAt(d)!==
|
||||
b.charAt(d)){d--;break}if(1>d)return a.charAt(0)===b.charAt(0)&&"/"===a.charAt(0)?"/":"";if("/"!==a.charAt(d)||"/"!==b.charAt(d))d=a.substring(0,d).lastIndexOf("/");return a.substring(0,d+1)};d.withinString=function(a,b){return a.replace(d.find_uri_expression,b)};d.ensureValidHostname=function(a){if(a.match(d.invalid_hostname_characters)){if(!f)throw new TypeError("Hostname '"+a+"' contains characters other than [A-Z0-9.-] and Punycode.js is not available");if(f.toASCII(a).match(d.invalid_hostname_characters))throw new TypeError("Hostname '"+
|
||||
a+"' contains characters other than [A-Z0-9.-]");}};d.noConflict=function(a){if(a)return a={URI:this.noConflict()},URITemplate&&"function"==typeof URITemplate.noConflict&&(a.URITemplate=URITemplate.noConflict()),l&&"function"==typeof l.noConflict&&(a.IPv6=l.noConflict()),SecondLevelDomains&&"function"==typeof SecondLevelDomains.noConflict&&(a.SecondLevelDomains=SecondLevelDomains.noConflict()),a;p.URI===this&&(p.URI=C);return this};g.build=function(a){if(!0===a)this._deferred_build=!0;else if(void 0===
|
||||
a||this._deferred_build)this._string=d.build(this._parts),this._deferred_build=!1;return this};g.clone=function(){return new d(this)};g.valueOf=g.toString=function(){return this.build(!1)._string};m={protocol:"protocol",username:"username",password:"password",hostname:"hostname",port:"port"};y=function(a){return function(b,c){if(void 0===b)return this._parts[a]||"";this._parts[a]=b||null;this.build(!c);return this}};for(s in m)g[s]=y(m[s]);m={query:"?",fragment:"#"};y=function(a,b){return function(c,
|
||||
d){if(void 0===c)return this._parts[a]||"";null!==c&&(c+="",c.charAt(0)===b&&(c=c.substring(1)));this._parts[a]=c;this.build(!d);return this}};for(s in m)g[s]=y(s,m[s]);m={search:["?","query"],hash:["#","fragment"]};y=function(a,b){return function(c,d){var e=this[a](c,d);return"string"===typeof e&&e.length?b+e:e}};for(s in m)g[s]=y(m[s][1],m[s][0]);g.pathname=function(a,b){if(void 0===a||!0===a){var c=this._parts.path||(this._parts.hostname?"/":"");return a?d.decodePath(c):c}this._parts.path=a?d.recodePath(a):
|
||||
"/";this.build(!b);return this};g.path=g.pathname;g.href=function(a,b){var c;if(void 0===a)return this.toString();this._string="";this._parts=d._parts();var k=a instanceof d,e="object"===typeof a&&(a.hostname||a.path||a.pathname);a.nodeName&&(e=d.getDomAttribute(a),a=a[e]||"",e=!1);!k&&(e&&void 0!==a.pathname)&&(a=a.toString());if("string"===typeof a)this._parts=d.parse(a,this._parts);else if(k||e)for(c in k=k?a._parts:a,k)r.call(this._parts,c)&&(this._parts[c]=k[c]);else throw new TypeError("invalid input");
|
||||
this.build(!b);return this};g.is=function(a){var b=!1,c=!1,k=!1,e=!1,g=!1,f=!1,u=!1,m=!this._parts.urn;this._parts.hostname&&(m=!1,c=d.ip4_expression.test(this._parts.hostname),k=d.ip6_expression.test(this._parts.hostname),b=c||k,g=(e=!b)&&h&&h.has(this._parts.hostname),f=e&&d.idn_expression.test(this._parts.hostname),u=e&&d.punycode_expression.test(this._parts.hostname));switch(a.toLowerCase()){case "relative":return m;case "absolute":return!m;case "domain":case "name":return e;case "sld":return g;
|
||||
case "ip":return b;case "ip4":case "ipv4":case "inet4":return c;case "ip6":case "ipv6":case "inet6":return k;case "idn":return f;case "url":return!this._parts.urn;case "urn":return!!this._parts.urn;case "punycode":return u}return null};var w=g.protocol,D=g.port,E=g.hostname;g.protocol=function(a,b){if(void 0!==a&&a&&(a=a.replace(/:(\/\/)?$/,""),a.match(/[^a-zA-z0-9\.+-]/)))throw new TypeError("Protocol '"+a+"' contains characters other than [A-Z0-9.+-]");return w.call(this,a,b)};g.scheme=g.protocol;
|
||||
g.port=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0!==a&&(0===a&&(a=null),a&&(a+="",":"===a.charAt(0)&&(a=a.substring(1)),a.match(/[^0-9]/))))throw new TypeError("Port '"+a+"' contains characters other than [0-9]");return D.call(this,a,b)};g.hostname=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0!==a){var c={};d.parseHost(a,c);a=c.hostname}return E.call(this,a,b)};g.host=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?
|
||||
d.buildHost(this._parts):"";d.parseHost(a,this._parts);this.build(!b);return this};g.authority=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?d.buildAuthority(this._parts):"";d.parseAuthority(a,this._parts);this.build(!b);return this};g.userinfo=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){if(!this._parts.username)return"";var c=d.buildUserinfo(this._parts);return c.substring(0,c.length-1)}"@"!==a[a.length-1]&&(a+=
|
||||
"@");d.parseUserinfo(a,this._parts);this.build(!b);return this};g.resource=function(a,b){var c;if(void 0===a)return this.path()+this.search()+this.hash();c=d.parse(a);this._parts.path=c.path;this._parts.query=c.query;this._parts.fragment=c.fragment;this.build(!b);return this};g.subdomain=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var c=this._parts.hostname.length-this.domain().length-1;return this._parts.hostname.substring(0,
|
||||
c)||""}c=this._parts.hostname.length-this.domain().length;c=this._parts.hostname.substring(0,c);c=RegExp("^"+q(c));a&&"."!==a.charAt(a.length-1)&&(a+=".");a&&d.ensureValidHostname(a);this._parts.hostname=this._parts.hostname.replace(c,a);this.build(!b);return this};g.domain=function(a,b){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(b=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var c=this._parts.hostname.match(/\./g);if(c&&2>c.length)return this._parts.hostname;
|
||||
c=this._parts.hostname.length-this.tld(b).length-1;c=this._parts.hostname.lastIndexOf(".",c-1)+1;return this._parts.hostname.substring(c)||""}if(!a)throw new TypeError("cannot set domain empty");d.ensureValidHostname(a);!this._parts.hostname||this.is("IP")?this._parts.hostname=a:(c=RegExp(q(this.domain())+"$"),this._parts.hostname=this._parts.hostname.replace(c,a));this.build(!b);return this};g.tld=function(a,b){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(b=a,a=void 0);if(void 0===
|
||||
a){if(!this._parts.hostname||this.is("IP"))return"";var c=this._parts.hostname.lastIndexOf("."),c=this._parts.hostname.substring(c+1);return!0!==b&&h&&h.list[c.toLowerCase()]?h.get(this._parts.hostname)||c:c}if(a)if(a.match(/[^a-zA-Z0-9-]/))if(h&&h.is(a))c=RegExp(q(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(c,a);else throw new TypeError("TLD '"+a+"' contains characters other than [A-Z0-9]");else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");
|
||||
c=RegExp(q(this.tld())+"$");this._parts.hostname=this._parts.hostname.replace(c,a)}else throw new TypeError("cannot set TLD empty");this.build(!b);return this};g.directory=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path&&!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var c=this._parts.path.length-this.filename().length-1,c=this._parts.path.substring(0,c)||(this._parts.hostname?"/":"");return a?d.decodePath(c):c}c=this._parts.path.length-
|
||||
this.filename().length;c=this._parts.path.substring(0,c);c=RegExp("^"+q(c));this.is("relative")||(a||(a="/"),"/"!==a.charAt(0)&&(a="/"+a));a&&"/"!==a.charAt(a.length-1)&&(a+="/");a=d.recodePath(a);this._parts.path=this._parts.path.replace(c,a);this.build(!b);return this};g.filename=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var c=this._parts.path.lastIndexOf("/"),c=this._parts.path.substring(c+1);return a?
|
||||
d.decodePathSegment(c):c}c=!1;"/"===a.charAt(0)&&(a=a.substring(1));a.match(/\.?\//)&&(c=!0);var k=RegExp(q(this.filename())+"$");a=d.recodePath(a);this._parts.path=this._parts.path.replace(k,a);c?this.normalizePath(b):this.build(!b);return this};g.suffix=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var c=this.filename(),k=c.lastIndexOf(".");if(-1===k)return"";c=c.substring(k+1);c=/^[a-z0-9%]+$/i.test(c)?c:
|
||||
"";return a?d.decodePathSegment(c):c}"."===a.charAt(0)&&(a=a.substring(1));if(c=this.suffix())k=a?RegExp(q(c)+"$"):RegExp(q("."+c)+"$");else{if(!a)return this;this._parts.path+="."+d.recodePath(a)}k&&(a=d.recodePath(a),this._parts.path=this._parts.path.replace(k,a));this.build(!b);return this};g.segment=function(a,b,c){var d=this._parts.urn?":":"/",e=this.path(),g="/"===e.substring(0,1),e=e.split(d);void 0!==a&&"number"!==typeof a&&(c=b,b=a,a=void 0);if(void 0!==a&&"number"!==typeof a)throw Error("Bad segment '"+
|
||||
a+"', must be 0-based integer");g&&e.shift();0>a&&(a=Math.max(e.length+a,0));if(void 0===b)return void 0===a?e:e[a];if(null===a||void 0===e[a])if(n(b)){e=[];a=0;for(var f=b.length;a<f;a++)if(b[a].length||e.length&&e[e.length-1].length)e.length&&!e[e.length-1].length&&e.pop(),e.push(b[a])}else{if(b||"string"===typeof b)""===e[e.length-1]?e[e.length-1]=b:e.push(b)}else b||"string"===typeof b&&b.length?e[a]=b:e.splice(a,1);g&&e.unshift("");return this.path(e.join(d),c)};g.segmentCoded=function(a,b,c){var e,
|
||||
g;"number"!==typeof a&&(c=b,b=a,a=void 0);if(void 0===b){a=this.segment(a,b,c);if(n(a))for(e=0,g=a.length;e<g;e++)a[e]=d.decode(a[e]);else a=void 0!==a?d.decode(a):void 0;return a}if(n(b))for(e=0,g=b.length;e<g;e++)b[e]=d.decode(b[e]);else b="string"===typeof b?d.encode(b):b;return this.segment(a,b,c)};var F=g.query;g.query=function(a,b){if(!0===a)return d.parseQuery(this._parts.query,this._parts.escapeQuerySpace);if("function"===typeof a){var c=d.parseQuery(this._parts.query,this._parts.escapeQuerySpace),
|
||||
e=a.call(this,c);this._parts.query=d.buildQuery(e||c,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace);this.build(!b);return this}return void 0!==a&&"string"!==typeof a?(this._parts.query=d.buildQuery(a,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),this.build(!b),this):F.call(this,a,b)};g.setQuery=function(a,b,c){var e=d.parseQuery(this._parts.query,this._parts.escapeQuerySpace);if("object"===typeof a)for(var g in a)r.call(a,g)&&(e[g]=a[g]);else if("string"===
|
||||
typeof a)e[a]=void 0!==b?b:null;else throw new TypeError("URI.addQuery() accepts an object, string as the name parameter");this._parts.query=d.buildQuery(e,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace);"string"!==typeof a&&(c=b);this.build(!c);return this};g.addQuery=function(a,b,c){var e=d.parseQuery(this._parts.query,this._parts.escapeQuerySpace);d.addQuery(e,a,void 0===b?null:b);this._parts.query=d.buildQuery(e,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace);
|
||||
"string"!==typeof a&&(c=b);this.build(!c);return this};g.removeQuery=function(a,b,c){var e=d.parseQuery(this._parts.query,this._parts.escapeQuerySpace);d.removeQuery(e,a,b);this._parts.query=d.buildQuery(e,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace);"string"!==typeof a&&(c=b);this.build(!c);return this};g.hasQuery=function(a,b,c){var e=d.parseQuery(this._parts.query,this._parts.escapeQuerySpace);return d.hasQuery(e,a,b,c)};g.setSearch=g.setQuery;g.addSearch=g.addQuery;g.removeSearch=
|
||||
g.removeQuery;g.hasSearch=g.hasQuery;g.normalize=function(){return this._parts.urn?this.normalizeProtocol(!1).normalizeQuery(!1).normalizeFragment(!1).build():this.normalizeProtocol(!1).normalizeHostname(!1).normalizePort(!1).normalizePath(!1).normalizeQuery(!1).normalizeFragment(!1).build()};g.normalizeProtocol=function(a){"string"===typeof this._parts.protocol&&(this._parts.protocol=this._parts.protocol.toLowerCase(),this.build(!a));return this};g.normalizeHostname=function(a){this._parts.hostname&&
|
||||
(this.is("IDN")&&f?this._parts.hostname=f.toASCII(this._parts.hostname):this.is("IPv6")&&l&&(this._parts.hostname=l.best(this._parts.hostname)),this._parts.hostname=this._parts.hostname.toLowerCase(),this.build(!a));return this};g.normalizePort=function(a){"string"===typeof this._parts.protocol&&this._parts.port===d.defaultPorts[this._parts.protocol]&&(this._parts.port=null,this.build(!a));return this};g.normalizePath=function(a){if(this._parts.urn||!this._parts.path||"/"===this._parts.path)return this;
|
||||
var b,c=this._parts.path,e,g;"/"!==c.charAt(0)&&(b=!0,c="/"+c);for(c=c.replace(/(\/(\.\/)+)|(\/\.$)/g,"/").replace(/\/{2,}/g,"/");;){e=c.indexOf("/../");if(-1===e)break;else if(0===e){c=c.substring(3);break}g=c.substring(0,e).lastIndexOf("/");-1===g&&(g=e);c=c.substring(0,g)+c.substring(e+3)}b&&this.is("relative")&&(c=c.substring(1));c=d.recodePath(c);this._parts.path=c;this.build(!a);return this};g.normalizePathname=g.normalizePath;g.normalizeQuery=function(a){"string"===typeof this._parts.query&&
|
||||
(this._parts.query.length?this.query(d.parseQuery(this._parts.query,this._parts.escapeQuerySpace)):this._parts.query=null,this.build(!a));return this};g.normalizeFragment=function(a){this._parts.fragment||(this._parts.fragment=null,this.build(!a));return this};g.normalizeSearch=g.normalizeQuery;g.normalizeHash=g.normalizeFragment;g.iso8859=function(){var a=d.encode,b=d.decode;d.encode=escape;d.decode=decodeURIComponent;this.normalize();d.encode=a;d.decode=b;return this};g.unicode=function(){var a=
|
||||
d.encode,b=d.decode;d.encode=z;d.decode=unescape;this.normalize();d.encode=a;d.decode=b;return this};g.readable=function(){var a=this.clone();a.username("").password("").normalize();var b="";a._parts.protocol&&(b+=a._parts.protocol+"://");a._parts.hostname&&(a.is("punycode")&&f?(b+=f.toUnicode(a._parts.hostname),a._parts.port&&(b+=":"+a._parts.port)):b+=a.host());a._parts.hostname&&(a._parts.path&&"/"!==a._parts.path.charAt(0))&&(b+="/");b+=a.path(!0);if(a._parts.query){for(var c="",e=0,g=a._parts.query.split("&"),
|
||||
h=g.length;e<h;e++){var u=(g[e]||"").split("="),c=c+("&"+d.decodeQuery(u[0],this._parts.escapeQuerySpace).replace(/&/g,"%26"));void 0!==u[1]&&(c+="="+d.decodeQuery(u[1],this._parts.escapeQuerySpace).replace(/&/g,"%26"))}b+="?"+c.substring(1)}return b+=d.decodeQuery(a.hash(),!0)};g.absoluteTo=function(a){var b=this.clone(),c=["protocol","username","password","hostname","port"],e,g;if(this._parts.urn)throw Error("URNs do not have any generally defined hierarchical components");a instanceof d||(a=new d(a));
|
||||
b._parts.protocol||(b._parts.protocol=a._parts.protocol);if(this._parts.hostname)return b;for(e=0;g=c[e];e++)b._parts[g]=a._parts[g];c=["query","path"];for(e=0;g=c[e];e++)!b._parts[g]&&a._parts[g]&&(b._parts[g]=a._parts[g]);"/"!==b.path().charAt(0)&&(a=a.directory(),b._parts.path=(a?a+"/":"")+b._parts.path,b.normalizePath());b.build();return b};g.relativeTo=function(a){var b=this.clone().normalize(),c,e,g,f;if(b._parts.urn)throw Error("URNs do not have any generally defined hierarchical components");
|
||||
a=(new d(a)).normalize();c=b._parts;e=a._parts;g=b.path();f=a.path();if("/"!==g.charAt(0))throw Error("URI is already relative");if("/"!==f.charAt(0))throw Error("Cannot calculate a URI relative to another relative URI");c.protocol===e.protocol&&(c.protocol=null);if(c.username===e.username&&c.password===e.password&&null===c.protocol&&null===c.username&&null===c.password&&c.hostname===e.hostname&&c.port===e.port)c.hostname=null,c.port=null;else return b.build();if(g===f)return c.path="",b.build();
|
||||
a=d.commonPath(b.path(),a.path());if(!a)return b.build();e=e.path.substring(a.length).replace(/[^\/]*$/,"").replace(/.*?\//g,"../");c.path=e+c.path.substring(a.length);return b.build()};g.equals=function(a){var b=this.clone();a=new d(a);var c={},e={},g={},f;b.normalize();a.normalize();if(b.toString()===a.toString())return!0;c=b.query();e=a.query();b.query("");a.query("");if(b.toString()!==a.toString()||c.length!==e.length)return!1;c=d.parseQuery(c,this._parts.escapeQuerySpace);e=d.parseQuery(e,this._parts.escapeQuerySpace);
|
||||
for(f in c)if(r.call(c,f)){if(!n(c[f])){if(c[f]!==e[f])return!1}else if(!u(c[f],e[f]))return!1;g[f]=!0}for(f in e)if(r.call(e,f)&&!g[f])return!1;return!0};g.duplicateQueryParameters=function(a){this._parts.duplicateQueryParameters=!!a;return this};g.escapeQuerySpace=function(a){this._parts.escapeQuerySpace=!!a;return this};return d});
|
||||
(function(f,l){"object"===typeof exports?module.exports=l(require("./URI")):"function"===typeof define&&define.amd?define(["./URI"],l):f.URITemplate=l(f.URI,f)})(this,function(f,l){function h(d){if(h._cache[d])return h._cache[d];if(!(this instanceof h))return new h(d);this.expression=d;h._cache[d]=this;return this}function p(d){this.data=d;this.cache={}}var d=l&&l.URITemplate,q=Object.prototype.hasOwnProperty,A=h.prototype,n={"":{prefix:"",separator:",",named:!1,empty_name_separator:!1,encode:"encode"},
|
||||
"+":{prefix:"",separator:",",named:!1,empty_name_separator:!1,encode:"encodeReserved"},"#":{prefix:"#",separator:",",named:!1,empty_name_separator:!1,encode:"encodeReserved"},".":{prefix:".",separator:".",named:!1,empty_name_separator:!1,encode:"encode"},"/":{prefix:"/",separator:"/",named:!1,empty_name_separator:!1,encode:"encode"},";":{prefix:";",separator:";",named:!0,empty_name_separator:!1,encode:"encode"},"?":{prefix:"?",separator:"&",named:!0,empty_name_separator:!0,encode:"encode"},"&":{prefix:"&",
|
||||
separator:"&",named:!0,empty_name_separator:!0,encode:"encode"}};h._cache={};h.EXPRESSION_PATTERN=/\{([^a-zA-Z0-9%_]?)([^\}]+)(\}|$)/g;h.VARIABLE_PATTERN=/^([^*:]+)((\*)|:(\d+))?$/;h.VARIABLE_NAME_PATTERN=/[^a-zA-Z0-9%_]/;h.expand=function(d,f){var v=n[d.operator],l=v.named?"Named":"Unnamed",q=d.variables,g=[],r,m,s;for(s=0;m=q[s];s++)r=f.get(m.name),r.val.length?g.push(h["expand"+l](r,v,m.explode,m.explode&&v.separator||",",m.maxlength,m.name)):r.type&&g.push("");return g.length?v.prefix+g.join(v.separator):
|
||||
""};h.expandNamed=function(d,h,v,l,q,g){var r="",m=h.encode;h=h.empty_name_separator;var s=!d[m].length,n=2===d.type?"":f[m](g),w,p,A;p=0;for(A=d.val.length;p<A;p++)q?(w=f[m](d.val[p][1].substring(0,q)),2===d.type&&(n=f[m](d.val[p][0].substring(0,q)))):s?(w=f[m](d.val[p][1]),2===d.type?(n=f[m](d.val[p][0]),d[m].push([n,w])):d[m].push([void 0,w])):(w=d[m][p][1],2===d.type&&(n=d[m][p][0])),r&&(r+=l),v?r+=n+(h||w?"=":"")+w:(p||(r+=f[m](g)+(h||w?"=":"")),2===d.type&&(r+=n+","),r+=w);return r};h.expandUnnamed=
|
||||
function(d,h,l,q,n,g){g="";var r=h.encode;h=h.empty_name_separator;var m=!d[r].length,s,p,w,A;w=0;for(A=d.val.length;w<A;w++)n?p=f[r](d.val[w][1].substring(0,n)):m?(p=f[r](d.val[w][1]),d[r].push([2===d.type?f[r](d.val[w][0]):void 0,p])):p=d[r][w][1],g&&(g+=q),2===d.type&&(s=n?f[r](d.val[w][0].substring(0,n)):d[r][w][0],g+=s,g=l?g+(h||p?"=":""):g+","),g+=p;return g};h.noConflict=function(){l.URITemplate===h&&(l.URITemplate=d);return h};A.expand=function(d){var f="";this.parts&&this.parts.length||this.parse();
|
||||
d instanceof p||(d=new p(d));for(var l=0,n=this.parts.length;l<n;l++)f+="string"===typeof this.parts[l]?this.parts[l]:h.expand(this.parts[l],d);return f};A.parse=function(){var d=this.expression,f=h.EXPRESSION_PATTERN,l=h.VARIABLE_PATTERN,q=h.VARIABLE_NAME_PATTERN,p=[],g=0,r,m,s;for(f.lastIndex=0;;){m=f.exec(d);if(null===m){p.push(d.substring(g));break}else p.push(d.substring(g,m.index)),g=m.index+m[0].length;if(!n[m[1]])throw Error('Unknown Operator "'+m[1]+'" in "'+m[0]+'"');if(!m[3])throw Error('Unclosed Expression "'+
|
||||
m[0]+'"');r=m[2].split(",");for(var y=0,w=r.length;y<w;y++){s=r[y].match(l);if(null===s)throw Error('Invalid Variable "'+r[y]+'" in "'+m[0]+'"');if(s[1].match(q))throw Error('Invalid Variable Name "'+s[1]+'" in "'+m[0]+'"');r[y]={name:s[1],explode:!!s[3],maxlength:s[4]&&parseInt(s[4],10)}}if(!r.length)throw Error('Expression Missing Variable(s) "'+m[0]+'"');p.push({expression:m[0],operator:m[1],variables:r})}p.length||p.push(d);this.parts=p;return this};p.prototype.get=function(d){var f=this.data,
|
||||
h={type:0,val:[],encode:[],encodeReserved:[]},l;if(void 0!==this.cache[d])return this.cache[d];this.cache[d]=h;f="[object Function]"===String(Object.prototype.toString.call(f))?f(d):"[object Function]"===String(Object.prototype.toString.call(f[d]))?f[d](d):f[d];if(void 0!==f&&null!==f)if("[object Array]"===String(Object.prototype.toString.call(f))){l=0;for(d=f.length;l<d;l++)void 0!==f[l]&&null!==f[l]&&h.val.push([void 0,String(f[l])]);h.val.length&&(h.type=3)}else if("[object Object]"===String(Object.prototype.toString.call(f))){for(l in f)q.call(f,
|
||||
l)&&(void 0!==f[l]&&null!==f[l])&&h.val.push([l,String(f[l])]);h.val.length&&(h.type=2)}else h.type=1,h.val.push([void 0,String(f)]);return h};f.expand=function(d,l){var n=(new h(d)).expand(l);return new f(n)};return h});
|
|
@ -0,0 +1,494 @@
|
|||
/*!
|
||||
* URI.js - Mutating URLs
|
||||
* URI Template Support - http://tools.ietf.org/html/rfc6570
|
||||
*
|
||||
* Version: 1.11.2
|
||||
*
|
||||
* Author: Rodney Rehm
|
||||
* Web: http://medialize.github.com/URI.js/
|
||||
*
|
||||
* Licensed under
|
||||
* MIT License http://www.opensource.org/licenses/mit-license
|
||||
* GPL v3 http://opensource.org/licenses/GPL-3.0
|
||||
*
|
||||
*/
|
||||
(function (root, factory) {
|
||||
// https://github.com/umdjs/umd/blob/master/returnExports.js
|
||||
if (typeof exports === 'object') {
|
||||
// Node
|
||||
module.exports = factory(require('./URI'));
|
||||
} else if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['./URI'], factory);
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
root.URITemplate = factory(root.URI, root);
|
||||
}
|
||||
}(this, function (URI, root) {
|
||||
"use strict";
|
||||
|
||||
// save current URITemplate variable, if any
|
||||
var _URITemplate = root && root.URITemplate;
|
||||
|
||||
var hasOwn = Object.prototype.hasOwnProperty;
|
||||
function URITemplate(expression) {
|
||||
// serve from cache where possible
|
||||
if (URITemplate._cache[expression]) {
|
||||
return URITemplate._cache[expression];
|
||||
}
|
||||
|
||||
// Allow instantiation without the 'new' keyword
|
||||
if (!(this instanceof URITemplate)) {
|
||||
return new URITemplate(expression);
|
||||
}
|
||||
|
||||
this.expression = expression;
|
||||
URITemplate._cache[expression] = this;
|
||||
return this;
|
||||
}
|
||||
|
||||
function Data(data) {
|
||||
this.data = data;
|
||||
this.cache = {};
|
||||
}
|
||||
|
||||
var p = URITemplate.prototype;
|
||||
// list of operators and their defined options
|
||||
var operators = {
|
||||
// Simple string expansion
|
||||
'' : {
|
||||
prefix: "",
|
||||
separator: ",",
|
||||
named: false,
|
||||
empty_name_separator: false,
|
||||
encode : "encode"
|
||||
},
|
||||
// Reserved character strings
|
||||
'+' : {
|
||||
prefix: "",
|
||||
separator: ",",
|
||||
named: false,
|
||||
empty_name_separator: false,
|
||||
encode : "encodeReserved"
|
||||
},
|
||||
// Fragment identifiers prefixed by "#"
|
||||
'#' : {
|
||||
prefix: "#",
|
||||
separator: ",",
|
||||
named: false,
|
||||
empty_name_separator: false,
|
||||
encode : "encodeReserved"
|
||||
},
|
||||
// Name labels or extensions prefixed by "."
|
||||
'.' : {
|
||||
prefix: ".",
|
||||
separator: ".",
|
||||
named: false,
|
||||
empty_name_separator: false,
|
||||
encode : "encode"
|
||||
},
|
||||
// Path segments prefixed by "/"
|
||||
'/' : {
|
||||
prefix: "/",
|
||||
separator: "/",
|
||||
named: false,
|
||||
empty_name_separator: false,
|
||||
encode : "encode"
|
||||
},
|
||||
// Path parameter name or name=value pairs prefixed by ";"
|
||||
';' : {
|
||||
prefix: ";",
|
||||
separator: ";",
|
||||
named: true,
|
||||
empty_name_separator: false,
|
||||
encode : "encode"
|
||||
},
|
||||
// Query component beginning with "?" and consisting
|
||||
// of name=value pairs separated by "&"; an
|
||||
'?' : {
|
||||
prefix: "?",
|
||||
separator: "&",
|
||||
named: true,
|
||||
empty_name_separator: true,
|
||||
encode : "encode"
|
||||
},
|
||||
// Continuation of query-style &name=value pairs
|
||||
// within a literal query component.
|
||||
'&' : {
|
||||
prefix: "&",
|
||||
separator: "&",
|
||||
named: true,
|
||||
empty_name_separator: true,
|
||||
encode : "encode"
|
||||
}
|
||||
|
||||
// The operator characters equals ("="), comma (","), exclamation ("!"),
|
||||
// at sign ("@"), and pipe ("|") are reserved for future extensions.
|
||||
};
|
||||
|
||||
// storage for already parsed templates
|
||||
URITemplate._cache = {};
|
||||
// pattern to identify expressions [operator, variable-list] in template
|
||||
URITemplate.EXPRESSION_PATTERN = /\{([^a-zA-Z0-9%_]?)([^\}]+)(\}|$)/g;
|
||||
// pattern to identify variables [name, explode, maxlength] in variable-list
|
||||
URITemplate.VARIABLE_PATTERN = /^([^*:]+)((\*)|:(\d+))?$/;
|
||||
// pattern to verify variable name integrity
|
||||
URITemplate.VARIABLE_NAME_PATTERN = /[^a-zA-Z0-9%_]/;
|
||||
|
||||
// expand parsed expression (expression, not template!)
|
||||
URITemplate.expand = function(expression, data) {
|
||||
// container for defined options for the given operator
|
||||
var options = operators[expression.operator];
|
||||
// expansion type (include keys or not)
|
||||
var type = options.named ? "Named" : "Unnamed";
|
||||
// list of variables within the expression
|
||||
var variables = expression.variables;
|
||||
// result buffer for evaluating the expression
|
||||
var buffer = [];
|
||||
var d, variable, i, l, value;
|
||||
|
||||
for (i = 0; variable = variables[i]; i++) {
|
||||
// fetch simplified data source
|
||||
d = data.get(variable.name);
|
||||
if (!d.val.length) {
|
||||
if (d.type) {
|
||||
// empty variables (empty string)
|
||||
// still lead to a separator being appended!
|
||||
buffer.push("");
|
||||
}
|
||||
// no data, no action
|
||||
continue;
|
||||
}
|
||||
|
||||
// expand the given variable
|
||||
buffer.push(URITemplate["expand" + type](
|
||||
d,
|
||||
options,
|
||||
variable.explode,
|
||||
variable.explode && options.separator || ",",
|
||||
variable.maxlength,
|
||||
variable.name
|
||||
));
|
||||
}
|
||||
|
||||
if (buffer.length) {
|
||||
return options.prefix + buffer.join(options.separator);
|
||||
} else {
|
||||
// prefix is not prepended for empty expressions
|
||||
return "";
|
||||
}
|
||||
};
|
||||
// expand a named variable
|
||||
URITemplate.expandNamed = function(d, options, explode, separator, length, name) {
|
||||
// variable result buffer
|
||||
var result = "";
|
||||
// peformance crap
|
||||
var encode = options.encode;
|
||||
var empty_name_separator = options.empty_name_separator;
|
||||
// flag noting if values are already encoded
|
||||
var _encode = !d[encode].length;
|
||||
// key for named expansion
|
||||
var _name = d.type === 2 ? '': URI[encode](name);
|
||||
var _value, i, l;
|
||||
|
||||
// for each found value
|
||||
for (i = 0, l = d.val.length; i < l; i++) {
|
||||
if (length) {
|
||||
// maxlength must be determined before encoding can happen
|
||||
_value = URI[encode](d.val[i][1].substring(0, length));
|
||||
if (d.type === 2) {
|
||||
// apply maxlength to keys of objects as well
|
||||
_name = URI[encode](d.val[i][0].substring(0, length));
|
||||
}
|
||||
} else if (_encode) {
|
||||
// encode value
|
||||
_value = URI[encode](d.val[i][1]);
|
||||
if (d.type === 2) {
|
||||
// encode name and cache encoded value
|
||||
_name = URI[encode](d.val[i][0]);
|
||||
d[encode].push([_name, _value]);
|
||||
} else {
|
||||
// cache encoded value
|
||||
d[encode].push([undefined, _value]);
|
||||
}
|
||||
} else {
|
||||
// values are already encoded and can be pulled from cache
|
||||
_value = d[encode][i][1];
|
||||
if (d.type === 2) {
|
||||
_name = d[encode][i][0];
|
||||
}
|
||||
}
|
||||
|
||||
if (result) {
|
||||
// unless we're the first value, prepend the separator
|
||||
result += separator;
|
||||
}
|
||||
|
||||
if (!explode) {
|
||||
if (!i) {
|
||||
// first element, so prepend variable name
|
||||
result += URI[encode](name) + (empty_name_separator || _value ? "=" : "");
|
||||
}
|
||||
|
||||
if (d.type === 2) {
|
||||
// without explode-modifier, keys of objects are returned comma-separated
|
||||
result += _name + ",";
|
||||
}
|
||||
|
||||
result += _value;
|
||||
} else {
|
||||
// only add the = if it is either default (?&) or there actually is a value (;)
|
||||
result += _name + (empty_name_separator || _value ? "=" : "") + _value;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
// expand an unnamed variable
|
||||
URITemplate.expandUnnamed = function(d, options, explode, separator, length, name) {
|
||||
// variable result buffer
|
||||
var result = "";
|
||||
// performance crap
|
||||
var encode = options.encode;
|
||||
var empty_name_separator = options.empty_name_separator;
|
||||
// flag noting if values are already encoded
|
||||
var _encode = !d[encode].length;
|
||||
var _name, _value, i, l;
|
||||
|
||||
// for each found value
|
||||
for (i = 0, l = d.val.length; i < l; i++) {
|
||||
if (length) {
|
||||
// maxlength must be determined before encoding can happen
|
||||
_value = URI[encode](d.val[i][1].substring(0, length));
|
||||
} else if (_encode) {
|
||||
// encode and cache value
|
||||
_value = URI[encode](d.val[i][1]);
|
||||
d[encode].push([
|
||||
d.type === 2 ? URI[encode](d.val[i][0]) : undefined,
|
||||
_value
|
||||
]);
|
||||
} else {
|
||||
// value already encoded, pull from cache
|
||||
_value = d[encode][i][1];
|
||||
}
|
||||
|
||||
if (result) {
|
||||
// unless we're the first value, prepend the separator
|
||||
result += separator;
|
||||
}
|
||||
|
||||
if (d.type === 2) {
|
||||
if (length) {
|
||||
// maxlength also applies to keys of objects
|
||||
_name = URI[encode](d.val[i][0].substring(0, length));
|
||||
} else {
|
||||
// at this point the name must already be encoded
|
||||
_name = d[encode][i][0];
|
||||
}
|
||||
|
||||
result += _name;
|
||||
if (explode) {
|
||||
// explode-modifier separates name and value by "="
|
||||
result += (empty_name_separator || _value ? "=" : "");
|
||||
} else {
|
||||
// no explode-modifier separates name and value by ","
|
||||
result += ",";
|
||||
}
|
||||
}
|
||||
|
||||
result += _value;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
URITemplate.noConflict = function() {
|
||||
if (root.URITemplate === URITemplate) {
|
||||
root.URITemplate = _URITemplate;
|
||||
}
|
||||
|
||||
return URITemplate;
|
||||
};
|
||||
|
||||
// expand template through given data map
|
||||
p.expand = function(data) {
|
||||
var result = "";
|
||||
|
||||
if (!this.parts || !this.parts.length) {
|
||||
// lazilyy parse the template
|
||||
this.parse();
|
||||
}
|
||||
|
||||
if (!(data instanceof Data)) {
|
||||
// make given data available through the
|
||||
// optimized data handling thingie
|
||||
data = new Data(data);
|
||||
}
|
||||
|
||||
for (var i = 0, l = this.parts.length; i < l; i++) {
|
||||
result += typeof this.parts[i] === "string"
|
||||
// literal string
|
||||
? this.parts[i]
|
||||
// expression
|
||||
: URITemplate.expand(this.parts[i], data);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
// parse template into action tokens
|
||||
p.parse = function() {
|
||||
// performance crap
|
||||
var expression = this.expression;
|
||||
var ePattern = URITemplate.EXPRESSION_PATTERN;
|
||||
var vPattern = URITemplate.VARIABLE_PATTERN;
|
||||
var nPattern = URITemplate.VARIABLE_NAME_PATTERN;
|
||||
// token result buffer
|
||||
var parts = [];
|
||||
// position within source template
|
||||
var pos = 0;
|
||||
var variables, eMatch, vMatch;
|
||||
|
||||
// RegExp is shared accross all templates,
|
||||
// which requires a manual reset
|
||||
ePattern.lastIndex = 0;
|
||||
// I don't like while(foo = bar()) loops,
|
||||
// to make things simpler I go while(true) and break when required
|
||||
while (true) {
|
||||
eMatch = ePattern.exec(expression);
|
||||
if (eMatch === null) {
|
||||
// push trailing literal
|
||||
parts.push(expression.substring(pos));
|
||||
break;
|
||||
} else {
|
||||
// push leading literal
|
||||
parts.push(expression.substring(pos, eMatch.index));
|
||||
pos = eMatch.index + eMatch[0].length;
|
||||
}
|
||||
|
||||
if (!operators[eMatch[1]]) {
|
||||
throw new Error('Unknown Operator "' + eMatch[1] + '" in "' + eMatch[0] + '"');
|
||||
} else if (!eMatch[3]) {
|
||||
throw new Error('Unclosed Expression "' + eMatch[0] + '"');
|
||||
}
|
||||
|
||||
// parse variable-list
|
||||
variables = eMatch[2].split(',');
|
||||
for (var i = 0, l = variables.length; i < l; i++) {
|
||||
vMatch = variables[i].match(vPattern);
|
||||
if (vMatch === null) {
|
||||
throw new Error('Invalid Variable "' + variables[i] + '" in "' + eMatch[0] + '"');
|
||||
} else if (vMatch[1].match(nPattern)) {
|
||||
throw new Error('Invalid Variable Name "' + vMatch[1] + '" in "' + eMatch[0] + '"');
|
||||
}
|
||||
|
||||
variables[i] = {
|
||||
name: vMatch[1],
|
||||
explode: !!vMatch[3],
|
||||
maxlength: vMatch[4] && parseInt(vMatch[4], 10)
|
||||
};
|
||||
}
|
||||
|
||||
if (!variables.length) {
|
||||
throw new Error('Expression Missing Variable(s) "' + eMatch[0] + '"');
|
||||
}
|
||||
|
||||
parts.push({
|
||||
expression: eMatch[0],
|
||||
operator: eMatch[1],
|
||||
variables: variables
|
||||
});
|
||||
}
|
||||
|
||||
if (!parts.length) {
|
||||
// template doesn't contain any expressions
|
||||
// so it is a simple literal string
|
||||
// this probably should fire a warning or something?
|
||||
parts.push(expression);
|
||||
}
|
||||
|
||||
this.parts = parts;
|
||||
return this;
|
||||
};
|
||||
|
||||
// simplify data structures
|
||||
Data.prototype.get = function(key) {
|
||||
// performance crap
|
||||
var data = this.data;
|
||||
// cache for processed data-point
|
||||
var d = {
|
||||
// type of data 0: undefined/null, 1: string, 2: object, 3: array
|
||||
type: 0,
|
||||
// original values (except undefined/null)
|
||||
val: [],
|
||||
// cache for encoded values (only for non-maxlength expansion)
|
||||
encode: [],
|
||||
encodeReserved: []
|
||||
};
|
||||
var i, l, value;
|
||||
|
||||
if (this.cache[key] !== undefined) {
|
||||
// we've already processed this key
|
||||
return this.cache[key];
|
||||
}
|
||||
|
||||
this.cache[key] = d;
|
||||
|
||||
if (String(Object.prototype.toString.call(data)) === "[object Function]") {
|
||||
// data itself is a callback (global callback)
|
||||
value = data(key);
|
||||
} else if (String(Object.prototype.toString.call(data[key])) === "[object Function]") {
|
||||
// data is a map of callbacks (local callback)
|
||||
value = data[key](key);
|
||||
} else {
|
||||
// data is a map of data
|
||||
value = data[key];
|
||||
}
|
||||
|
||||
// generalize input into [ [name1, value1], [name2, value2], … ]
|
||||
// so expansion has to deal with a single data structure only
|
||||
if (value === undefined || value === null) {
|
||||
// undefined and null values are to be ignored completely
|
||||
return d;
|
||||
} else if (String(Object.prototype.toString.call(value)) === "[object Array]") {
|
||||
for (i = 0, l = value.length; i < l; i++) {
|
||||
if (value[i] !== undefined && value[i] !== null) {
|
||||
// arrays don't have names
|
||||
d.val.push([undefined, String(value[i])]);
|
||||
}
|
||||
}
|
||||
|
||||
if (d.val.length) {
|
||||
// only treat non-empty arrays as arrays
|
||||
d.type = 3; // array
|
||||
}
|
||||
} else if (String(Object.prototype.toString.call(value)) === "[object Object]") {
|
||||
for (i in value) {
|
||||
if (hasOwn.call(value, i) && value[i] !== undefined && value[i] !== null) {
|
||||
// objects have keys, remember them for named expansion
|
||||
d.val.push([i, String(value[i])]);
|
||||
}
|
||||
}
|
||||
|
||||
if (d.val.length) {
|
||||
// only treat non-empty objects as objects
|
||||
d.type = 2; // object
|
||||
}
|
||||
} else {
|
||||
d.type = 1; // primitive string (could've been string, number, boolean and objects with a toString())
|
||||
// arrays don't have names
|
||||
d.val.push([undefined, String(value)]);
|
||||
}
|
||||
|
||||
return d;
|
||||
};
|
||||
|
||||
// hook into URI for fluid access
|
||||
URI.expand = function(expression, data) {
|
||||
var template = new URITemplate(expression);
|
||||
var expansion = template.expand(data);
|
||||
|
||||
return new URI(expansion);
|
||||
};
|
||||
|
||||
return URITemplate;
|
||||
}));
|
|
@ -0,0 +1,232 @@
|
|||
/*!
|
||||
* URI.js - Mutating URLs
|
||||
* jQuery Plugin
|
||||
*
|
||||
* Version: 1.11.2
|
||||
*
|
||||
* Author: Rodney Rehm
|
||||
* Web: http://medialize.github.com/URI.js/jquery-uri-plugin.html
|
||||
*
|
||||
* Licensed under
|
||||
* MIT License http://www.opensource.org/licenses/mit-license
|
||||
* GPL v3 http://opensource.org/licenses/GPL-3.0
|
||||
*
|
||||
*/
|
||||
|
||||
(function (root, factory) {
|
||||
// https://github.com/umdjs/umd/blob/master/returnExports.js
|
||||
if (typeof exports === 'object') {
|
||||
// Node
|
||||
module.exports = factory(require('jquery', './URI'));
|
||||
} else if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['jquery', './URI'], factory);
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
factory(root.jQuery, root.URI);
|
||||
}
|
||||
}(this, function ($, URI) {
|
||||
"use strict";
|
||||
|
||||
var comparable = {};
|
||||
var compare = {
|
||||
// equals
|
||||
'=': function(value, target) {
|
||||
return value === target;
|
||||
},
|
||||
// ~= translates to value.match((?:^|\s)target(?:\s|$)) which is useless for URIs
|
||||
// |= translates to value.match((?:\b)target(?:-|\s|$)) which is useless for URIs
|
||||
// begins with
|
||||
'^=': function(value, target, property) {
|
||||
return !!(value + "").match(new RegExp('^' + escapeRegEx(target), 'i'));
|
||||
},
|
||||
// ends with
|
||||
'$=': function(value, target, property) {
|
||||
return !!(value + "").match(new RegExp(escapeRegEx(target) + '$', 'i'));
|
||||
},
|
||||
// contains
|
||||
'*=': function(value, target, property) {
|
||||
if (property == 'directory') {
|
||||
// add trailing slash so /dir/ will match the deep-end as well
|
||||
value += '/';
|
||||
}
|
||||
|
||||
return !!(value + "").match(new RegExp(escapeRegEx(target), 'i'));
|
||||
},
|
||||
'equals:': function(uri, target) {
|
||||
return uri.equals(target);
|
||||
},
|
||||
'is:': function(uri, target) {
|
||||
return uri.is(target);
|
||||
}
|
||||
};
|
||||
|
||||
function escapeRegEx(string) {
|
||||
// https://github.com/medialize/URI.js/commit/85ac21783c11f8ccab06106dba9735a31a86924d#commitcomment-821963
|
||||
return string.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
|
||||
}
|
||||
|
||||
function getUriProperty(elem) {
|
||||
var nodeName = elem.nodeName.toLowerCase();
|
||||
var property = URI.domAttributes[nodeName];
|
||||
if (nodeName === 'input' && elem.type !== 'image') {
|
||||
// compensate ambiguous <input> that is not an image
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// NOTE: as we use a static mapping from element to attribute,
|
||||
// the HTML5 attribute issue should not come up again
|
||||
// https://github.com/medialize/URI.js/issues/69
|
||||
return property;
|
||||
}
|
||||
|
||||
function generateAccessor(property) {
|
||||
return {
|
||||
get: function(elem) {
|
||||
return $(elem).uri()[property]();
|
||||
},
|
||||
set: function(elem, value) {
|
||||
$(elem).uri()[property](value);
|
||||
return value;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// populate lookup table and register $.attr('uri:accessor') handlers
|
||||
$.each('authority directory domain filename fragment hash host hostname href password path pathname port protocol query resource scheme search subdomain suffix tld username'.split(" "), function(k, v) {
|
||||
comparable[v] = true;
|
||||
$.attrHooks['uri:' + v] = generateAccessor(v);
|
||||
});
|
||||
|
||||
// pipe $.attr('src') and $.attr('href') through URI.js
|
||||
var _attrHooks = {
|
||||
get: function(elem) {
|
||||
return $(elem).uri();
|
||||
},
|
||||
set: function(elem, value) {
|
||||
return $(elem).uri().href(value).toString();
|
||||
}
|
||||
};
|
||||
$.each(['src', 'href', 'action', 'uri', 'cite'], function(k, v) {
|
||||
$.attrHooks[v] = {
|
||||
set: _attrHooks.set
|
||||
};
|
||||
});
|
||||
$.attrHooks.uri.get = _attrHooks.get;
|
||||
|
||||
// general URI accessor
|
||||
$.fn.uri = function(uri) {
|
||||
var $this = this.first();
|
||||
var elem = $this.get(0);
|
||||
var property = getUriProperty(elem);
|
||||
|
||||
if (!property) {
|
||||
throw new Error('Element "' + elem.nodeName + '" does not have either property: href, src, action, cite');
|
||||
}
|
||||
|
||||
if (uri !== undefined) {
|
||||
var old = $this.data('uri');
|
||||
if (old) {
|
||||
return old.href(uri);
|
||||
}
|
||||
|
||||
if (!(uri instanceof URI)) {
|
||||
uri = URI(uri || '');
|
||||
}
|
||||
} else {
|
||||
uri = $this.data('uri');
|
||||
if (uri) {
|
||||
return uri;
|
||||
} else {
|
||||
uri = URI($this.attr(property) || '');
|
||||
}
|
||||
}
|
||||
|
||||
uri._dom_element = elem;
|
||||
uri._dom_attribute = property;
|
||||
uri.normalize();
|
||||
$this.data('uri', uri);
|
||||
return uri;
|
||||
};
|
||||
|
||||
// overwrite URI.build() to update associated DOM element if necessary
|
||||
URI.prototype.build = function(deferBuild) {
|
||||
if (this._dom_element) {
|
||||
// cannot defer building when hooked into a DOM element
|
||||
this._string = URI.build(this._parts);
|
||||
this._deferred_build = false;
|
||||
this._dom_element.setAttribute(this._dom_attribute, this._string);
|
||||
this._dom_element[this._dom_attribute] = this._string;
|
||||
} else if (deferBuild === true) {
|
||||
this._deferred_build = true;
|
||||
} else if (deferBuild === undefined || this._deferred_build) {
|
||||
this._string = URI.build(this._parts);
|
||||
this._deferred_build = false;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
// add :uri() pseudo class selector to sizzle
|
||||
var uriSizzle;
|
||||
var pseudoArgs = /^([a-zA-Z]+)\s*([\^\$*]?=|:)\s*(['"]?)(.+)\3|^\s*([a-zA-Z0-9]+)\s*$/;
|
||||
function uriPseudo (elem, text) {
|
||||
var match, property, uri;
|
||||
|
||||
// skip anything without src|href|action and bad :uri() syntax
|
||||
if (!getUriProperty(elem) || !text) {
|
||||
return false;
|
||||
}
|
||||
|
||||
match = text.match(pseudoArgs);
|
||||
|
||||
if (!match || (!match[5] && match[2] !== ':' && !compare[match[2]])) {
|
||||
// abort because the given selector cannot be executed
|
||||
// filers seem to fail silently
|
||||
return false;
|
||||
}
|
||||
|
||||
uri = $(elem).uri();
|
||||
|
||||
if (match[5]) {
|
||||
return uri.is(match[5]);
|
||||
} else if (match[2] === ':') {
|
||||
property = match[1].toLowerCase() + ':';
|
||||
if (!compare[property]) {
|
||||
// filers seem to fail silently
|
||||
return false;
|
||||
}
|
||||
|
||||
return compare[property](uri, match[4]);
|
||||
} else {
|
||||
property = match[1].toLowerCase();
|
||||
if (!comparable[property]) {
|
||||
// filers seem to fail silently
|
||||
return false;
|
||||
}
|
||||
|
||||
return compare[match[2]](uri[property](), match[4], property);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($.expr.createPseudo) {
|
||||
// jQuery >= 1.8
|
||||
uriSizzle = $.expr.createPseudo(function (text) {
|
||||
return function (elem) {
|
||||
return uriPseudo(elem, text);
|
||||
};
|
||||
});
|
||||
} else {
|
||||
// jQuery < 1.8
|
||||
uriSizzle = function (elem, i, match) {
|
||||
return uriPseudo(elem, match[3]);
|
||||
};
|
||||
}
|
||||
|
||||
$.expr[":"].uri = uriSizzle;
|
||||
|
||||
// extending existing object rather than defining something new
|
||||
return {};
|
||||
}));
|
|
@ -0,0 +1,7 @@
|
|||
/*! URI.js v1.11.2 http://medialize.github.com/URI.js/ */
|
||||
/* build contains: jquery.URI.js */
|
||||
(function(d,e){"object"===typeof exports?module.exports=e(require("jquery","./URI")):"function"===typeof define&&define.amd?define(["jquery","./URI"],e):e(d.jQuery,d.URI)})(this,function(d,e){function h(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function k(a){var b=a.nodeName.toLowerCase();return"input"===b&&"image"!==a.type?void 0:e.domAttributes[b]}function p(a){return{get:function(b){return d(b).uri()[a]()},set:function(b,c){d(b).uri()[a](c);return c}}}function l(a,b){var c,e,f;if(!k(a)||
|
||||
!b)return!1;c=b.match(q);if(!c||!c[5]&&":"!==c[2]&&!g[c[2]])return!1;f=d(a).uri();if(c[5])return f.is(c[5]);if(":"===c[2])return e=c[1].toLowerCase()+":",g[e]?g[e](f,c[4]):!1;e=c[1].toLowerCase();return m[e]?g[c[2]](f[e](),c[4],e):!1}var m={},g={"=":function(a,b){return a===b},"^=":function(a,b,c){return!!(a+"").match(RegExp("^"+h(b),"i"))},"$=":function(a,b,c){return!!(a+"").match(RegExp(h(b)+"$","i"))},"*=":function(a,b,c){"directory"==c&&(a+="/");return!!(a+"").match(RegExp(h(b),"i"))},"equals:":function(a,
|
||||
b){return a.equals(b)},"is:":function(a,b){return a.is(b)}};d.each("authority directory domain filename fragment hash host hostname href password path pathname port protocol query resource scheme search subdomain suffix tld username".split(" "),function(a,b){m[b]=!0;d.attrHooks["uri:"+b]=p(b)});var r=function(a,b){return d(a).uri().href(b).toString()};d.each(["src","href","action","uri","cite"],function(a,b){d.attrHooks[b]={set:r}});d.attrHooks.uri.get=function(a){return d(a).uri()};d.fn.uri=function(a){var b=
|
||||
this.first(),c=b.get(0),d=k(c);if(!d)throw Error('Element "'+c.nodeName+'" does not have either property: href, src, action, cite');if(void 0!==a){var f=b.data("uri");if(f)return f.href(a);a instanceof e||(a=e(a||""))}else{if(a=b.data("uri"))return a;a=e(b.attr(d)||"")}a._dom_element=c;a._dom_attribute=d;a.normalize();b.data("uri",a);return a};e.prototype.build=function(a){if(this._dom_element)this._string=e.build(this._parts),this._deferred_build=!1,this._dom_element.setAttribute(this._dom_attribute,
|
||||
this._string),this._dom_element[this._dom_attribute]=this._string;else if(!0===a)this._deferred_build=!0;else if(void 0===a||this._deferred_build)this._string=e.build(this._parts),this._deferred_build=!1;return this};var n,q=/^([a-zA-Z]+)\s*([\^\$*]?=|:)\s*(['"]?)(.+)\3|^\s*([a-zA-Z0-9]+)\s*$/;n=d.expr.createPseudo?d.expr.createPseudo(function(a){return function(b){return l(b,a)}}):function(a,b,c){return l(a,c[3])};d.expr[":"].uri=n;return{}});
|
|
@ -0,0 +1,508 @@
|
|||
/*! http://mths.be/punycode v1.2.3 by @mathias */
|
||||
;(function(root) {
|
||||
|
||||
/** Detect free variables */
|
||||
var freeExports = typeof exports == 'object' && exports;
|
||||
var freeModule = typeof module == 'object' && module &&
|
||||
module.exports == freeExports && module;
|
||||
var freeGlobal = typeof global == 'object' && global;
|
||||
if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
|
||||
root = freeGlobal;
|
||||
}
|
||||
|
||||
/**
|
||||
* The `punycode` object.
|
||||
* @name punycode
|
||||
* @type Object
|
||||
*/
|
||||
var punycode,
|
||||
|
||||
/** Highest positive signed 32-bit float value */
|
||||
maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1
|
||||
|
||||
/** Bootstring parameters */
|
||||
base = 36,
|
||||
tMin = 1,
|
||||
tMax = 26,
|
||||
skew = 38,
|
||||
damp = 700,
|
||||
initialBias = 72,
|
||||
initialN = 128, // 0x80
|
||||
delimiter = '-', // '\x2D'
|
||||
|
||||
/** Regular expressions */
|
||||
regexPunycode = /^xn--/,
|
||||
regexNonASCII = /[^ -~]/, // unprintable ASCII chars + non-ASCII chars
|
||||
regexSeparators = /\x2E|\u3002|\uFF0E|\uFF61/g, // RFC 3490 separators
|
||||
|
||||
/** Error messages */
|
||||
errors = {
|
||||
'overflow': 'Overflow: input needs wider integers to process',
|
||||
'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
|
||||
'invalid-input': 'Invalid input'
|
||||
},
|
||||
|
||||
/** Convenience shortcuts */
|
||||
baseMinusTMin = base - tMin,
|
||||
floor = Math.floor,
|
||||
stringFromCharCode = String.fromCharCode,
|
||||
|
||||
/** Temporary variable */
|
||||
key;
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* A generic error utility function.
|
||||
* @private
|
||||
* @param {String} type The error type.
|
||||
* @returns {Error} Throws a `RangeError` with the applicable error message.
|
||||
*/
|
||||
function error(type) {
|
||||
throw RangeError(errors[type]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A generic `Array#map` utility function.
|
||||
* @private
|
||||
* @param {Array} array The array to iterate over.
|
||||
* @param {Function} callback The function that gets called for every array
|
||||
* item.
|
||||
* @returns {Array} A new array of values returned by the callback function.
|
||||
*/
|
||||
function map(array, fn) {
|
||||
var length = array.length;
|
||||
while (length--) {
|
||||
array[length] = fn(array[length]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple `Array#map`-like wrapper to work with domain name strings.
|
||||
* @private
|
||||
* @param {String} domain The domain name.
|
||||
* @param {Function} callback The function that gets called for every
|
||||
* character.
|
||||
* @returns {Array} A new string of characters returned by the callback
|
||||
* function.
|
||||
*/
|
||||
function mapDomain(string, fn) {
|
||||
return map(string.split(regexSeparators), fn).join('.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an array containing the numeric code points of each Unicode
|
||||
* character in the string. While JavaScript uses UCS-2 internally,
|
||||
* this function will convert a pair of surrogate halves (each of which
|
||||
* UCS-2 exposes as separate characters) into a single code point,
|
||||
* matching UTF-16.
|
||||
* @see `punycode.ucs2.encode`
|
||||
* @see <http://mathiasbynens.be/notes/javascript-encoding>
|
||||
* @memberOf punycode.ucs2
|
||||
* @name decode
|
||||
* @param {String} string The Unicode input string (UCS-2).
|
||||
* @returns {Array} The new array of code points.
|
||||
*/
|
||||
function ucs2decode(string) {
|
||||
var output = [],
|
||||
counter = 0,
|
||||
length = string.length,
|
||||
value,
|
||||
extra;
|
||||
while (counter < length) {
|
||||
value = string.charCodeAt(counter++);
|
||||
if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
|
||||
// high surrogate, and there is a next character
|
||||
extra = string.charCodeAt(counter++);
|
||||
if ((extra & 0xFC00) == 0xDC00) { // low surrogate
|
||||
output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
|
||||
} else {
|
||||
// unmatched surrogate; only append this code unit, in case the next
|
||||
// code unit is the high surrogate of a surrogate pair
|
||||
output.push(value);
|
||||
counter--;
|
||||
}
|
||||
} else {
|
||||
output.push(value);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string based on an array of numeric code points.
|
||||
* @see `punycode.ucs2.decode`
|
||||
* @memberOf punycode.ucs2
|
||||
* @name encode
|
||||
* @param {Array} codePoints The array of numeric code points.
|
||||
* @returns {String} The new Unicode string (UCS-2).
|
||||
*/
|
||||
function ucs2encode(array) {
|
||||
return map(array, function(value) {
|
||||
var output = '';
|
||||
if (value > 0xFFFF) {
|
||||
value -= 0x10000;
|
||||
output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
|
||||
value = 0xDC00 | value & 0x3FF;
|
||||
}
|
||||
output += stringFromCharCode(value);
|
||||
return output;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a basic code point into a digit/integer.
|
||||
* @see `digitToBasic()`
|
||||
* @private
|
||||
* @param {Number} codePoint The basic numeric code point value.
|
||||
* @returns {Number} The numeric value of a basic code point (for use in
|
||||
* representing integers) in the range `0` to `base - 1`, or `base` if
|
||||
* the code point does not represent a value.
|
||||
*/
|
||||
function basicToDigit(codePoint) {
|
||||
if (codePoint - 48 < 10) {
|
||||
return codePoint - 22;
|
||||
}
|
||||
if (codePoint - 65 < 26) {
|
||||
return codePoint - 65;
|
||||
}
|
||||
if (codePoint - 97 < 26) {
|
||||
return codePoint - 97;
|
||||
}
|
||||
return base;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a digit/integer into a basic code point.
|
||||
* @see `basicToDigit()`
|
||||
* @private
|
||||
* @param {Number} digit The numeric value of a basic code point.
|
||||
* @returns {Number} The basic code point whose value (when used for
|
||||
* representing integers) is `digit`, which needs to be in the range
|
||||
* `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
|
||||
* used; else, the lowercase form is used. The behavior is undefined
|
||||
* if `flag` is non-zero and `digit` has no uppercase form.
|
||||
*/
|
||||
function digitToBasic(digit, flag) {
|
||||
// 0..25 map to ASCII a..z or A..Z
|
||||
// 26..35 map to ASCII 0..9
|
||||
return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bias adaptation function as per section 3.4 of RFC 3492.
|
||||
* http://tools.ietf.org/html/rfc3492#section-3.4
|
||||
* @private
|
||||
*/
|
||||
function adapt(delta, numPoints, firstTime) {
|
||||
var k = 0;
|
||||
delta = firstTime ? floor(delta / damp) : delta >> 1;
|
||||
delta += floor(delta / numPoints);
|
||||
for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
|
||||
delta = floor(delta / baseMinusTMin);
|
||||
}
|
||||
return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Punycode string of ASCII-only symbols to a string of Unicode
|
||||
* symbols.
|
||||
* @memberOf punycode
|
||||
* @param {String} input The Punycode string of ASCII-only symbols.
|
||||
* @returns {String} The resulting string of Unicode symbols.
|
||||
*/
|
||||
function decode(input) {
|
||||
// Don't use UCS-2
|
||||
var output = [],
|
||||
inputLength = input.length,
|
||||
out,
|
||||
i = 0,
|
||||
n = initialN,
|
||||
bias = initialBias,
|
||||
basic,
|
||||
j,
|
||||
index,
|
||||
oldi,
|
||||
w,
|
||||
k,
|
||||
digit,
|
||||
t,
|
||||
length,
|
||||
/** Cached calculation results */
|
||||
baseMinusT;
|
||||
|
||||
// Handle the basic code points: let `basic` be the number of input code
|
||||
// points before the last delimiter, or `0` if there is none, then copy
|
||||
// the first basic code points to the output.
|
||||
|
||||
basic = input.lastIndexOf(delimiter);
|
||||
if (basic < 0) {
|
||||
basic = 0;
|
||||
}
|
||||
|
||||
for (j = 0; j < basic; ++j) {
|
||||
// if it's not a basic code point
|
||||
if (input.charCodeAt(j) >= 0x80) {
|
||||
error('not-basic');
|
||||
}
|
||||
output.push(input.charCodeAt(j));
|
||||
}
|
||||
|
||||
// Main decoding loop: start just after the last delimiter if any basic code
|
||||
// points were copied; start at the beginning otherwise.
|
||||
|
||||
for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
|
||||
|
||||
// `index` is the index of the next character to be consumed.
|
||||
// Decode a generalized variable-length integer into `delta`,
|
||||
// which gets added to `i`. The overflow checking is easier
|
||||
// if we increase `i` as we go, then subtract off its starting
|
||||
// value at the end to obtain `delta`.
|
||||
for (oldi = i, w = 1, k = base; /* no condition */; k += base) {
|
||||
|
||||
if (index >= inputLength) {
|
||||
error('invalid-input');
|
||||
}
|
||||
|
||||
digit = basicToDigit(input.charCodeAt(index++));
|
||||
|
||||
if (digit >= base || digit > floor((maxInt - i) / w)) {
|
||||
error('overflow');
|
||||
}
|
||||
|
||||
i += digit * w;
|
||||
t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
|
||||
|
||||
if (digit < t) {
|
||||
break;
|
||||
}
|
||||
|
||||
baseMinusT = base - t;
|
||||
if (w > floor(maxInt / baseMinusT)) {
|
||||
error('overflow');
|
||||
}
|
||||
|
||||
w *= baseMinusT;
|
||||
|
||||
}
|
||||
|
||||
out = output.length + 1;
|
||||
bias = adapt(i - oldi, out, oldi == 0);
|
||||
|
||||
// `i` was supposed to wrap around from `out` to `0`,
|
||||
// incrementing `n` each time, so we'll fix that now:
|
||||
if (floor(i / out) > maxInt - n) {
|
||||
error('overflow');
|
||||
}
|
||||
|
||||
n += floor(i / out);
|
||||
i %= out;
|
||||
|
||||
// Insert `n` at position `i` of the output
|
||||
output.splice(i++, 0, n);
|
||||
|
||||
}
|
||||
|
||||
return ucs2encode(output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string of Unicode symbols to a Punycode string of ASCII-only
|
||||
* symbols.
|
||||
* @memberOf punycode
|
||||
* @param {String} input The string of Unicode symbols.
|
||||
* @returns {String} The resulting Punycode string of ASCII-only symbols.
|
||||
*/
|
||||
function encode(input) {
|
||||
var n,
|
||||
delta,
|
||||
handledCPCount,
|
||||
basicLength,
|
||||
bias,
|
||||
j,
|
||||
m,
|
||||
q,
|
||||
k,
|
||||
t,
|
||||
currentValue,
|
||||
output = [],
|
||||
/** `inputLength` will hold the number of code points in `input`. */
|
||||
inputLength,
|
||||
/** Cached calculation results */
|
||||
handledCPCountPlusOne,
|
||||
baseMinusT,
|
||||
qMinusT;
|
||||
|
||||
// Convert the input in UCS-2 to Unicode
|
||||
input = ucs2decode(input);
|
||||
|
||||
// Cache the length
|
||||
inputLength = input.length;
|
||||
|
||||
// Initialize the state
|
||||
n = initialN;
|
||||
delta = 0;
|
||||
bias = initialBias;
|
||||
|
||||
// Handle the basic code points
|
||||
for (j = 0; j < inputLength; ++j) {
|
||||
currentValue = input[j];
|
||||
if (currentValue < 0x80) {
|
||||
output.push(stringFromCharCode(currentValue));
|
||||
}
|
||||
}
|
||||
|
||||
handledCPCount = basicLength = output.length;
|
||||
|
||||
// `handledCPCount` is the number of code points that have been handled;
|
||||
// `basicLength` is the number of basic code points.
|
||||
|
||||
// Finish the basic string - if it is not empty - with a delimiter
|
||||
if (basicLength) {
|
||||
output.push(delimiter);
|
||||
}
|
||||
|
||||
// Main encoding loop:
|
||||
while (handledCPCount < inputLength) {
|
||||
|
||||
// All non-basic code points < n have been handled already. Find the next
|
||||
// larger one:
|
||||
for (m = maxInt, j = 0; j < inputLength; ++j) {
|
||||
currentValue = input[j];
|
||||
if (currentValue >= n && currentValue < m) {
|
||||
m = currentValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
|
||||
// but guard against overflow
|
||||
handledCPCountPlusOne = handledCPCount + 1;
|
||||
if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
|
||||
error('overflow');
|
||||
}
|
||||
|
||||
delta += (m - n) * handledCPCountPlusOne;
|
||||
n = m;
|
||||
|
||||
for (j = 0; j < inputLength; ++j) {
|
||||
currentValue = input[j];
|
||||
|
||||
if (currentValue < n && ++delta > maxInt) {
|
||||
error('overflow');
|
||||
}
|
||||
|
||||
if (currentValue == n) {
|
||||
// Represent delta as a generalized variable-length integer
|
||||
for (q = delta, k = base; /* no condition */; k += base) {
|
||||
t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
|
||||
if (q < t) {
|
||||
break;
|
||||
}
|
||||
qMinusT = q - t;
|
||||
baseMinusT = base - t;
|
||||
output.push(
|
||||
stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
|
||||
);
|
||||
q = floor(qMinusT / baseMinusT);
|
||||
}
|
||||
|
||||
output.push(stringFromCharCode(digitToBasic(q, 0)));
|
||||
bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
|
||||
delta = 0;
|
||||
++handledCPCount;
|
||||
}
|
||||
}
|
||||
|
||||
++delta;
|
||||
++n;
|
||||
|
||||
}
|
||||
return output.join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Punycode string representing a domain name to Unicode. Only the
|
||||
* Punycoded parts of the domain name will be converted, i.e. it doesn't
|
||||
* matter if you call it on a string that has already been converted to
|
||||
* Unicode.
|
||||
* @memberOf punycode
|
||||
* @param {String} domain The Punycode domain name to convert to Unicode.
|
||||
* @returns {String} The Unicode representation of the given Punycode
|
||||
* string.
|
||||
*/
|
||||
function toUnicode(domain) {
|
||||
return mapDomain(domain, function(string) {
|
||||
return regexPunycode.test(string)
|
||||
? decode(string.slice(4).toLowerCase())
|
||||
: string;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Unicode string representing a domain name to Punycode. Only the
|
||||
* non-ASCII parts of the domain name will be converted, i.e. it doesn't
|
||||
* matter if you call it with a domain that's already in ASCII.
|
||||
* @memberOf punycode
|
||||
* @param {String} domain The domain name to convert, as a Unicode string.
|
||||
* @returns {String} The Punycode representation of the given domain name.
|
||||
*/
|
||||
function toASCII(domain) {
|
||||
return mapDomain(domain, function(string) {
|
||||
return regexNonASCII.test(string)
|
||||
? 'xn--' + encode(string)
|
||||
: string;
|
||||
});
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/** Define the public API */
|
||||
punycode = {
|
||||
/**
|
||||
* A string representing the current Punycode.js version number.
|
||||
* @memberOf punycode
|
||||
* @type String
|
||||
*/
|
||||
'version': '1.2.3',
|
||||
/**
|
||||
* An object of methods to convert from JavaScript's internal character
|
||||
* representation (UCS-2) to Unicode code points, and back.
|
||||
* @see <http://mathiasbynens.be/notes/javascript-encoding>
|
||||
* @memberOf punycode
|
||||
* @type Object
|
||||
*/
|
||||
'ucs2': {
|
||||
'decode': ucs2decode,
|
||||
'encode': ucs2encode
|
||||
},
|
||||
'decode': decode,
|
||||
'encode': encode,
|
||||
'toASCII': toASCII,
|
||||
'toUnicode': toUnicode
|
||||
};
|
||||
|
||||
/** Expose `punycode` */
|
||||
// Some AMD build optimizers, like r.js, check for specific condition patterns
|
||||
// like the following:
|
||||
if (
|
||||
typeof define == 'function' &&
|
||||
typeof define.amd == 'object' &&
|
||||
define.amd
|
||||
) {
|
||||
define(function() {
|
||||
return punycode;
|
||||
});
|
||||
} else if (freeExports && !freeExports.nodeType) {
|
||||
if (freeModule) { // in Node.js or RingoJS v0.8.0+
|
||||
freeModule.exports = punycode;
|
||||
} else { // in Narwhal or RingoJS v0.7.0-
|
||||
for (key in punycode) {
|
||||
punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
|
||||
}
|
||||
}
|
||||
} else { // in Rhino or a web browser
|
||||
root.punycode = punycode;
|
||||
}
|
||||
|
||||
}(this));
|
Loading…
Reference in New Issue