WordPress.org

Make WordPress Core

Changeset 15526


Ignore:
Timestamp:
08/23/2010 09:44:25 PM (9 years ago)
Author:
scribu
Message:

munge admin-table.js & minify jquery.query

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/js/admin-table.js

    r15509 r15526  
    1 var adminTable;jQuery(document).ready(function(a){adminTable={init:function(){this.loading=false;a("form").each(function(){this.reset()});if(""==a.query.GET("paged")){a.query.SET("paged",1)}this.set_total_pages();this.$tbody=a("#the-list, #the-comment-list");this.$overlay=a('<div id="loading-items>').html(adminTableL10n.loading).hide().prependTo(a("body"))},set_total_pages:function(){this.total_pages=parseInt(a(".total-pages").eq(0).text())},get_total_pages:function(){return this.total_pages},change_page:function(b){if(b<1||b>this.total_pages){return false}this.update_rows({paged:b})},change_search:function(b){this.update_rows({s:b},true,function(){a("h2 .subtitle").remove();if(b){a("h2").eq(0).append(a('<span class="subtitle">').html(adminTableL10n.search.replace("%s",this.htmlencode(b))))}})},htmlencode:function(b){return a("<div/>").text(b).html()},update_rows:function(c,b,f){if(this.loading){return false}var e=false;a.each(c,function(g,h){if(h!=a.query.GET(g)){a.query.SET(g,h);e=true}});if(!e){return false}this.show_overlay();if(b){a.query.SET("paged",1)}var d=a.query.get();this._callback=f;this.fetch_list(d,a.proxy(this,"handle_success"),a.proxy(this,"handle_error"));return true},fetch_list:function(c,d,b){c=a.extend(c,{action:"fetch-list",list_args:list_args,});a.ajax({url:ajaxurl,global:false,dataType:"json",data:c,success:d,error:b,})},handle_success:function(b){if("object"!=typeof b){this.handle_error()}else{this.hide_overlay();this.$tbody.html(b.rows);a(".displaying-num").html(b.total_items);a(".total-pages").html(b.total_pages);this.set_total_pages();a(".current-page").val(a.query.GET("paged"));if(this._callback){this._callback()}}},handle_error:function(){this.hide_overlay();a("h2").after('<div class="error ajax below-h2"><p>'+adminTableL10n.error+"</p></div>")},show_overlay:function(){this.loading=true;a(".error.ajax").remove();this.$overlay.css({width:this.$tbody.width()+"px",height:this.$tbody.height()-20+"px"}).css(this.$tbody.offset()).show()},hide_overlay:function(){this.loading=false;this.$overlay.hide()}};adminTable.init();a(".tablenav-pages a").click(function(){var b=a.query.GET("paged");switch(a(this).attr("class")){case"first-page":b=1;break;case"prev-page":b-=1;break;case"next-page":b+=1;break;case"last-page":b=adminTable.get_total_pages();break}adminTable.change_page(b);return false});a(".current-page").keypress(function(b){if(13!=b.keyCode){return}adminTable.change_page(parseInt(a(this).val()));return false});a("th a").click(function(){var d=a.query.GET("orderby"),b=a.query.GET("order"),c=a(this).parent("th");if(c.hasClass("sortable")){d=a.query.load(a(this).attr("href")).get("orderby");b="asc";a("th.sorted-desc, th.sorted-asc").removeClass("sorted-asc").removeClass("sorted-desc").addClass("sortable");c.removeClass("sortable").addClass("sorted-asc")}else{if(c.hasClass("sorted-asc")){b="desc";c.removeClass("sorted-asc").addClass("sorted-desc")}else{if(c.hasClass("sorted-desc")){b="asc";c.removeClass("sorted-desc").addClass("sorted-asc")}}}adminTable.update_rows({orderby:d,order:b},true);return false});a(".search-box :submit").click(function(){adminTable.change_search(a(this).parent(".search-box").find(":text").val());return false});a(".search-box :text").keypress(function(b){if(13!=b.keyCode){return}adminTable.change_search(a(this).val());return false});a("#post-query-submit").click(function(){var c,d,b={};a(this).parents(".actions").find('select[name!="action"]').each(function(){var e=a(this);b[e.attr("name")]=e.val()});adminTable.update_rows(b,true);return false});a(".view-switch a").click(function(){var b=a(this);adminTable.update_rows({mode:a.query.load(b.attr("href")).get("mode")},false,function(){a(".view-switch .current").removeClass("current");b.addClass("current")});return false})});
     1jQuery(document).ready(function(a){window.adminTable={init:function(){this.loading=false;a("form").each(function(){this.reset()});if(""==a.query.GET("paged")){a.query.SET("paged",1)}this.set_total_pages();this.$tbody=a("#the-list, #the-comment-list");this.$overlay=a('<div id="loading-items>').html(adminTableL10n.loading).hide().prependTo(a("body"))},set_total_pages:function(){this.total_pages=parseInt(a(".total-pages").eq(0).text())},get_total_pages:function(){return this.total_pages},change_page:function(b){if(b<1||b>this.total_pages){return false}this.update_rows({paged:b})},change_search:function(b){this.update_rows({s:b},true,function(){a("h2 .subtitle").remove();if(b){a("h2").eq(0).append(a('<span class="subtitle">').html(adminTableL10n.search.replace("%s",this.htmlencode(b))))}})},htmlencode:function(b){return a("<div/>").text(b).html()},update_rows:function(c,b,f){if(this.loading){return false}var e=false;a.each(c,function(g,h){if(h!=a.query.GET(g)){a.query.SET(g,h);e=true}});if(!e){return false}this.show_overlay();if(b){a.query.SET("paged",1)}var d=a.query.get();this._callback=f;this.fetch_list(d,a.proxy(this,"handle_success"),a.proxy(this,"handle_error"));return true},fetch_list:function(c,d,b){c=a.extend(c,{action:"fetch-list",list_args:list_args,});a.ajax({url:ajaxurl,global:false,dataType:"json",data:c,success:d,error:b,})},handle_success:function(b){if("object"!=typeof b){this.handle_error()}else{this.hide_overlay();this.$tbody.html(b.rows);a(".displaying-num").html(b.total_items);a(".total-pages").html(b.total_pages);this.set_total_pages();a(".current-page").val(a.query.GET("paged"));if(this._callback){this._callback()}}},handle_error:function(){this.hide_overlay();a("h2").after('<div class="error ajax below-h2"><p>'+adminTableL10n.error+"</p></div>")},show_overlay:function(){this.loading=true;a(".error.ajax").remove();this.$overlay.css({width:this.$tbody.width()+"px",height:this.$tbody.height()-20+"px"}).css(this.$tbody.offset()).show()},hide_overlay:function(){this.loading=false;this.$overlay.hide()}};adminTable.init();a(".tablenav-pages a").click(function(){var b=a.query.GET("paged");switch(a(this).attr("class")){case"first-page":b=1;break;case"prev-page":b-=1;break;case"next-page":b+=1;break;case"last-page":b=adminTable.get_total_pages();break}adminTable.change_page(b);return false});a(".current-page").keypress(function(b){if(13!=b.keyCode){return}adminTable.change_page(parseInt(a(this).val()));return false});a("th a").click(function(){var d=a.query.GET("orderby"),b=a.query.GET("order"),c=a(this).parent("th");if(c.hasClass("sortable")){d=a.query.load(a(this).attr("href")).get("orderby");b="asc";a("th.sorted-desc, th.sorted-asc").removeClass("sorted-asc").removeClass("sorted-desc").addClass("sortable");c.removeClass("sortable").addClass("sorted-asc")}else{if(c.hasClass("sorted-asc")){b="desc";c.removeClass("sorted-asc").addClass("sorted-desc")}else{if(c.hasClass("sorted-desc")){b="asc";c.removeClass("sorted-desc").addClass("sorted-asc")}}}adminTable.update_rows({orderby:d,order:b},true);return false});a(".search-box :submit").click(function(){adminTable.change_search(a(this).parent(".search-box").find(":text").val());return false});a(".search-box :text").keypress(function(b){if(13!=b.keyCode){return}adminTable.change_search(a(this).val());return false});a("#post-query-submit").click(function(){var c,d,b={};a(this).parents(".actions").find('select[name!="action"]').each(function(){var e=a(this);b[e.attr("name")]=e.val()});adminTable.update_rows(b,true);return false});a(".view-switch a").click(function(){var b=a(this);adminTable.update_rows({mode:a.query.load(b.attr("href")).get("mode")},false,function(){a(".view-switch .current").removeClass("current");b.addClass("current")});return false})});
  • trunk/wp-includes/js/jquery/jquery.query.js

    r15491 r15526  
    99 *
    1010 **/
    11 new 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         jQuery.each(arguments, function() {
    75           var q = "" + this;
    76           q = q.replace(/^[?#]/,''); // remove any leading ? || #
    77           q = q.replace(/[;&]$/,''); // remove any trailing & || ;
    78           if ($spaces) q = q.replace(/[+]/g,' '); // replace +'s with spaces
    79          
    80           jQuery.each(q.split(/[&;]/), function(){
    81             var key = decodeURIComponent(this.split('=')[0] || "");
    82             var val = decodeURIComponent(this.split('=')[1] || "");
    83            
    84             if (!key) return;
    85            
    86             if ($numbers) {
    87               if (/^[+-]?[0-9]+\.[0-9]*$/.test(val)) // simple float regex
    88                 val = parseFloat(val);
    89               else if (/^[+-]?[0-9]+$/.test(val)) // simple int regex
    90                 val = parseInt(val, 10);
    91             }
    92            
    93             val = (!val && val !== 0) ? true : val;
    94            
    95             if (val !== false && val !== true && typeof val != 'number')
    96               val = val;
    97            
    98             self.SET(key, val);
    99           });
    100         });
    101       }
    102       return self;
    103     };
    104    
    105     queryObject.prototype = {
    106       queryObject: true,
    107       has: function(key, type) {
    108         var value = this.get(key);
    109         return is(value, type);
    110       },
    111       GET: function(key) {
    112         if (!is(key)) return this.keys;
    113         var parsed = parse(key), base = parsed[0], tokens = parsed[1];
    114         var target = this.keys[base];
    115         while (target != null && tokens.length != 0) {
    116           target = target[tokens.shift()];
    117         }
    118         return typeof target == 'number' ? target : target || "";
    119       },
    120       get: function(key) {
    121         var target = this.GET(key);
    122         if (is(target, Object))
    123           return jQuery.extend(true, {}, target);
    124         else if (is(target, Array))
    125           return target.slice(0);
    126         return target;
    127       },
    128       SET: function(key, val) {
    129         var value = !is(val) ? null : val;
    130         var parsed = parse(key), base = parsed[0], tokens = parsed[1];
    131         var target = this.keys[base];
    132         this.keys[base] = set(target, tokens.slice(0), value);
    133         return this;
    134       },
    135       set: function(key, val) {
    136         return this.copy().SET(key, val);
    137       },
    138       REMOVE: function(key) {
    139         return this.SET(key, null).COMPACT();
    140       },
    141       remove: function(key) {
    142         return this.copy().REMOVE(key);
    143       },
    144       EMPTY: function() {
    145         var self = this;
    146         jQuery.each(self.keys, function(key, value) {
    147           delete self.keys[key];
    148         });
    149         return self;
    150       },
    151       load: function(url) {
    152         var hash = url.replace(/^.*?[#](.+?)(?:\?.+)?$/, "$1");
    153         var search = url.replace(/^.*?[?](.+?)(?:#.+)?$/, "$1");
    154         return new queryObject(url.length == search.length ? '' : search, url.length == hash.length ? '' : hash);
    155       },
    156       empty: function() {
    157         return this.copy().EMPTY();
    158       },
    159       copy: function() {
    160         return new queryObject(this);
    161       },
    162       COMPACT: function() {
    163         function build(orig) {
    164           var obj = typeof orig == "object" ? is(orig, Array) ? [] : {} : orig;
    165           if (typeof orig == 'object') {
    166             function add(o, key, value) {
    167               if (is(o, Array))
    168                 o.push(value);
    169               else
    170                 o[key] = value;
    171             }
    172             jQuery.each(orig, function(key, value) {
    173               if (!is(value)) return true;
    174               add(obj, key, build(value));
    175             });
    176           }
    177           return obj;
    178         }
    179         this.keys = build(this.keys);
    180         return this;
    181       },
    182       compact: function() {
    183         return this.copy().COMPACT();
    184       },
    185       toString: function() {
    186         var i = 0, queryString = [], chunks = [], self = this;
    187         var encode = function(str) {
    188           str = str + "";
    189           if ($spaces) str = str.replace(/ /g, "+");
    190           return encodeURIComponent(str);
    191         };
    192         var addFields = function(arr, key, value) {
    193           if (!is(value) || value === false) return;
    194           var o = [encode(key)];
    195           if (value !== true) {
    196             o.push("=");
    197             o.push(encode(value));
    198           }
    199           arr.push(o.join(""));
    200         };
    201         var build = function(obj, base) {
    202           var newKey = function(key) {
    203             return !base || base == "" ? [key].join("") : [base, "[", key, "]"].join("");
    204           };
    205           jQuery.each(obj, function(key, value) {
    206             if (typeof value == 'object')
    207               build(value, newKey(key));
    208             else
    209               addFields(chunks, newKey(key), value);
    210           });
    211         };
    212        
    213         build(this.keys);
    214        
    215         if (chunks.length > 0) queryString.push($hash);
    216         queryString.push(chunks.join($separator));
    217        
    218         return queryString.join("");
    219       }
    220     };
    221    
    222     return new queryObject(location.search, location.hash);
    223   };
    224 }(jQuery.query || {}); // Pass in jQuery.query as settings object
     11new 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||{});
Note: See TracChangeset for help on using the changeset viewer.