PageSourceSearch

https://cityoffollybeach.com/revize/plugins/revize_calendar/jquery.query-object.js

js cityoffollybeach.com collected 2026-09-24 21:36:11 UTC 8,439 bytes, 245 lines download raw bytes

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        var value = !is(val) ? null : val;
133        var parsed = parse(key), base = parsed[0], tokens = parsed[1];
134        var target = this.keys[base];
135        this.keys[base] = set(target, tokens.slice(0), value);
136        return this;
137      },
138      set: function(key, val) {
139        return this.copy().SET(key, val);
140      },
141      REMOVE: function(key, val) {
142        if (val) {
143          var target = this.GET(key);
144          if (is(target, Array)) {
145            for (tval in target) {
146                target[tval] = target[tval].toString();
147            }
148            var index = $.inArray(val, target);
149            if (index >= 0) {
150              key = target.splice(index, 1);
151              key = key[index];
152            } else {
153              return;
154            }
155          } else if (val != target) {
156              return;
157          }
158        }
159        return this.SET(key, null).COMPACT();
160      },
161      remove: function(key, val) {
162        return this.copy().REMOVE(key, val);
163      },
164      EMPTY: function() {
165        var self = this;
166        jQuery.each(self.keys, function(key, value) {
167          delete self.keys[key];
168        });
169        return self;
170      },
171      load: function(url) {
172        var hash = url.replace(/^.*?[#](.+?)(?:\?.+)?$/, "$1");
173        var search = url.replace(/^.*?[?](.+?)(?:#.+)?$/, "$1");
174        return new queryObject(url.length == search.length ? '' : search, url.length == hash.length ? '' : hash);
175      },
176      empty: function() {
177        return this.copy().EMPTY();
178      },
179      copy: function() {
180        return new queryObject(this);
181      },
182      COMPACT: function() {
183        function build(orig) {
184          var obj = typeof orig == "object" ? is(orig, Array) ? [] : {} : orig;
185          if (typeof orig == 'object') {
186            function add(o, key, value) {
187              if (is(o, Array))
188                o.push(value);
189              else
190                o[key] = value;
191            }
192            jQuery.each(orig, function(key, value) {
193              if (!is(value)) return true;
194              add(obj, key, build(value));
195            });
196          }
197          return obj;
198        }
199        this.keys = build(this.keys);
200        return this;
201      },
202      compact: function() {
203        return this.copy().COMPACT();
204      },
205      toString: function() {
206        var i = 0, queryString = [], chunks = [], self = this;
207        var encode = function(str) {
208          str = str + "";
209          str = encodeURIComponent(str);
210          if ($spaces) str = str.replace(/%20/g, "+");
211          return str;
212        };
213        var addFields = function(arr, key, value) {
214          if (!is(value) || value === false) return;
215          var o = [encode(key)];
216          if (value !== true) {
217            o.push("=");
218            o.push(encode(value));
219          }
220          arr.push(o.join(""));
221        };
222        var build = function(obj, base) {
223          var newKey = function(key) {
224            return !base || base == "" ? [key].join("") : [base, "[", key, "]"].join("");
225          };
226          jQuery.each(obj, function(key, value) {
227            if (typeof value == 'object') 
228              build(value, newKey(key));
229            else
230              addFields(chunks, newKey(key), value);
231          });
232        };
233        
234        build(this.keys);
235        
236        if (chunks.length > 0) queryString.push($hash);
237        queryString.push(chunks.join($separator));
238        
239        return queryString.join("");
240      }
241    };
242    
243    return new queryObject(location.search, location.hash);
244  };
245}(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.