Make WordPress Core

Ticket #15580: hashes.diff

File hashes.diff, 11.9 KB (added by scribu, 14 years ago)
  • wp-includes/js/jquery/jquery.query.js

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

     
    1919                        .html(listTableL10n.loading)
    2020                        .hide()
    2121                        .prependTo($('body'));
     22
     23                this.update_rows( $.query.load( location.hash ).keys );
    2224        },
    2325
    2426        // paging
     
    116118
    117119                        $('th.column-cb :input').attr('checked', false);
    118120
     121                        location.hash = '#' + $.query.toString().substr(1);
     122
    119123                        if ( this._callback )
    120124                                this._callback();
    121125                }