1/** 2 * jQuery.query - Query String Modification and Creation for jQuery 3 * Written by Blair Mitchelmore (blair DOT mitchelmore AT gmail DOT com) 4 * Licensed under the WTFPL (http://sam.zoy.org/wtfpl/). 5 * Date: 2009/8/13 6 * 7 * @author Blair Mitchelmore 8 * @version 2.2.3 9 * 10 **/ 11new function(settings) { 12 // Various Settings 13 var $separator = settings.separator || '&'; 14 var $spaces = settings.spaces === false ? false : true; 15 var $suffix = settings.suffix === false ? '' : '[]'; 16 var $prefix = settings.prefix === false ? false : true; 17 var $hash = $prefix ? settings.hash === true ? "#" : "?" : ""; 18 var $numbers = settings.numbers === false ? false : true; 19 20 jQuery.query = new function() { 21 var is = function(o, t) { 22 return o != undefined && o !== null && (!!t ? o.constructor == t : true); 23 }; 24 var parse = function(path) { 25 var m, rx = /\[([^[]*)\]/g, match = /^([^[]+)(\[.*\])?$/.exec(path), base = match[1], tokens = []; 26 while (m = rx.exec(match[2])) tokens.push(m[1]); 27 return [base, tokens]; 28 }; 29 var set = function(target, tokens, value) { 30 var o, token = tokens.shift(); 31 if (typeof target != 'object') target = null; 32 if (token === "") { 33 if (!target) target = []; 34 if (is(target, Array)) { 35 target.push(tokens.length == 0 ? value : set(null, tokens.slice(0), value)); 36 } else if (is(target, Object)) { 37 var i = 0; 38 while (target[i++] != null); 39 target[--i] = tokens.length == 0 ? value : set(target[i], tokens.slice(0), value); 40 } else { 41 target = []; 42 target.push(tokens.length == 0 ? value : set(null, tokens.slice(0), value)); 43 } 44 } else if (token && token.match(/^\s*[0-9]+\s*$/)) { 45 var index = parseInt(token, 10); 46 if (!target) target = []; 47 target[index] = tokens.length == 0 ? value : set(target[index], tokens.slice(0), value); 48 } else if (token) { 49 var index = token.replace(/^\s*|\s*$/g, ""); 50 if (!target) target = {}; 51 if (is(target, Array)) { 52 var temp = {}; 53 for (var i = 0; i < target.length; ++i) { 54 temp[i] = target[i]; 55 } 56 target = temp; 57 } 58 target[index] = tokens.length == 0 ? value : set(target[index], tokens.slice(0), value); 59 } else { 60 return value; 61 } 62 return target; 63 }; 64 65 var queryObject = function(a) { 66 var self = this; 67 self.keys = {}; 68 69 if (a.queryObject) { 70 jQuery.each(a.get(), function(key, val) { 71 self.SET(key, val); 72 }); 73 } else { 74 self.parseNew.apply(self, arguments); 75 } 76 return self; 77 }; 78 79 queryObject.prototype = { 80 queryObject: true, 81 parseNew: function(){ 82 var self = this; 83 self.keys = {}; 84 jQuery.each(arguments, function() { 85 var q = "" + this; 86 q = q.replace(/^[?#]/,''); // remove any leading ? || # 87 q = q.replace(/[;&]$/,''); // remove any trailing & || ; 88 if ($spaces) q = q.replace(/[+]/g,' '); // replace +'s with spaces 89 90 jQuery.each(q.split(/[&;]/), function(){ 91 var key = decodeURIComponent(this.split('=')[0] || ""); 92 var val = decodeURIComponent(this.split('=')[1] || ""); 93 94 if (!key) return; 95 96 if ($numbers) { 97 if (/^[+-]?[0-9]+\.[0-9]*$/.test(val)) // simple float regex 98 val = parseFloat(val); 99 else if (/^[+-]?[1-9][0-9]*$/.test(val)) // simple int regex 100 val = parseInt(val, 10); 101 } 102 103 val = (!val && val !== 0) ? true : val; 104 105 self.SET(key, val); 106 }); 107 }); 108 return self; 109 }, 110 has: function(key, type) { 111 var value = this.get(key); 112 return is(value, type); 113 }, 114 GET: function(key) { 115 if (!is(key)) return this.keys; 116 var parsed = parse(key), base = parsed[0], tokens = parsed[1]; 117 var target = this.keys[base]; 118 while (target != null && tokens.length != 0) { 119 target = target[tokens.shift()]; 120 } 121 return typeof target == 'number' ? target : target || ""; 122 }, 123 get: function(key) { 124 var target = this.GET(key); 125 if (is(target, Object)) 126 return jQuery.extend(true, {}, target); 127 else if (is(target, Array)) 128 return target.slice(0); 129 return target; 130 }, 131 SET: function(key, val) { 132 if(!key.includes("__proto__")){ 133 var value = !is(val) ? null : val; 134 var parsed = parse(key), base = parsed[0], tokens = parsed[1]; 135 var target = this.keys[base]; 136 this.keys[base] = set(target, tokens.slice(0), value); 137 } 138 return this; 139 }, 140 set: function(key, val) { 141 return this.copy().SET(key, val); 142 }, 143 REMOVE: function(key, val) { 144 if (val) { 145 var target = this.GET(key); 146 if (is(target, Array)) { 147 for (tval in target) { 148 target[tval] = target[tval].toString(); 149 } 150 var index = $.inArray(val, target); 151 if (index >= 0) { 152 key = target.splice(index, 1); 153 key = key[index]; 154 } else { 155 return; 156 } 157 } else if (val != target) { 158 return; 159 } 160 } 161 return this.SET(key, null).COMPACT(); 162 }, 163 remove: function(key, val) { 164 return this.copy().REMOVE(key, val); 165 }, 166 EMPTY: function() { 167 var self = this; 168 jQuery.each(self.keys, function(key, value) { 169 delete self.keys[key]; 170 }); 171 return self; 172 }, 173 load: function(url) { 174 var hash = url.replace(/^.*?[#](.+?)(?:\?.+)?$/, "$1"); 175 var search = url.replace(/^.*?[?](.+?)(?:#.+)?$/, "$1"); 176 return new queryObject(url.length == search.length ? '' : search, url.length == hash.length ? '' : hash); 177 }, 178 empty: function() { 179 return this.copy().EMPTY(); 180 }, 181 copy: function() { 182 return new queryObject(this); 183 }, 184 COMPACT: function() { 185 function build(orig) { 186 var obj = typeof orig == "object" ? is(orig, Array) ? [] : {} : orig; 187 if (typeof orig == 'object') { 188 function add(o, key, value) { 189 if (is(o, Array)) 190 o.push(value); 191 else 192 o[key] = value; 193 } 194 jQuery.each(orig, function(key, value) { 195 if (!is(value)) return true; 196 add(obj, key, build(value)); 197 }); 198 } 199 return obj;
200 } 201 this.keys = build(this.keys); 202 return this; 203 }, 204 compact: function() { 205 return this.copy().COMPACT(); 206 }, 207 toString: function() { 208 var i = 0, queryString = [], chunks = [], self = this; 209 var encode = function(str) { 210 str = str + ""; 211 str = encodeURIComponent(str); 212 if ($spaces) str = str.replace(/%20/g, "+"); 213 return str; 214 }; 215 var addFields = function(arr, key, value) { 216 if (!is(value) || value === false) return; 217 var o = [encode(key)]; 218 if (value !== true) { 219 o.push("="); 220 o.push(encode(value)); 221 } 222 arr.push(o.join("")); 223 }; 224 var build = function(obj, base) { 225 var newKey = function(key) { 226 return !base || base == "" ? [key].join("") : [base, "[", key, "]"].join(""); 227 }; 228 jQuery.each(obj, function(key, value) { 229 if (typeof value == 'object') 230 build(value, newKey(key)); 231 else 232 addFields(chunks, newKey(key), value); 233 }); 234 }; 235 236 build(this.keys); 237 238 if (chunks.length > 0) queryString.push($hash); 239 queryString.push(chunks.join($separator)); 240 241 return queryString.join(""); 242 } 243 }; 244 245 return new queryObject(location.search, location.hash); 246 }; 247}(jQuery.query || {}); // Pass in jQuery.query as settings object
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.