Ticket #15580: hashes.diff

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