munge admin-table.js & minify jquery.query
git-svn-id: http://svn.automattic.com/wordpress/trunk@15526 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
db4e0ce056
commit
593bd95cea
|
@ -1 +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})});
|
jQuery(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})});
|
|
@ -8,217 +8,4 @@
|
||||||
* @version 2.1.7
|
* @version 2.1.7
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
new function(settings) {
|
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||{});
|
||||||
// Various Settings
|
|
||||||
var $separator = settings.separator || '&';
|
|
||||||
var $spaces = settings.spaces === false ? false : true;
|
|
||||||
var $suffix = settings.suffix === false ? '' : '[]';
|
|
||||||
var $prefix = settings.prefix === false ? false : true;
|
|
||||||
var $hash = $prefix ? settings.hash === true ? "#" : "?" : "";
|
|
||||||
var $numbers = settings.numbers === false ? false : true;
|
|
||||||
|
|
||||||
jQuery.query = new function() {
|
|
||||||
var is = function(o, t) {
|
|
||||||
return o != undefined && o !== null && (!!t ? o.constructor == t : true);
|
|
||||||
};
|
|
||||||
var parse = function(path) {
|
|
||||||
var m, rx = /\[([^[]*)\]/g, match = /^([^[]+)(\[.*\])?$/.exec(path), base = match[1], tokens = [];
|
|
||||||
while (m = rx.exec(match[2])) tokens.push(m[1]);
|
|
||||||
return [base, tokens];
|
|
||||||
};
|
|
||||||
var set = function(target, tokens, value) {
|
|
||||||
var o, token = tokens.shift();
|
|
||||||
if (typeof target != 'object') target = null;
|
|
||||||
if (token === "") {
|
|
||||||
if (!target) target = [];
|
|
||||||
if (is(target, Array)) {
|
|
||||||
target.push(tokens.length == 0 ? value : set(null, tokens.slice(0), value));
|
|
||||||
} else if (is(target, Object)) {
|
|
||||||
var i = 0;
|
|
||||||
while (target[i++] != null);
|
|
||||||
target[--i] = tokens.length == 0 ? value : set(target[i], tokens.slice(0), value);
|
|
||||||
} else {
|
|
||||||
target = [];
|
|
||||||
target.push(tokens.length == 0 ? value : set(null, tokens.slice(0), value));
|
|
||||||
}
|
|
||||||
} else if (token && token.match(/^\s*[0-9]+\s*$/)) {
|
|
||||||
var index = parseInt(token, 10);
|
|
||||||
if (!target) target = [];
|
|
||||||
target[index] = tokens.length == 0 ? value : set(target[index], tokens.slice(0), value);
|
|
||||||
} else if (token) {
|
|
||||||
var index = token.replace(/^\s*|\s*$/g, "");
|
|
||||||
if (!target) target = {};
|
|
||||||
if (is(target, Array)) {
|
|
||||||
var temp = {};
|
|
||||||
for (var i = 0; i < target.length; ++i) {
|
|
||||||
temp[i] = target[i];
|
|
||||||
}
|
|
||||||
target = temp;
|
|
||||||
}
|
|
||||||
target[index] = tokens.length == 0 ? value : set(target[index], tokens.slice(0), value);
|
|
||||||
} else {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
return target;
|
|
||||||
};
|
|
||||||
|
|
||||||
var queryObject = function(a) {
|
|
||||||
var self = this;
|
|
||||||
self.keys = {};
|
|
||||||
|
|
||||||
if (a.queryObject) {
|
|
||||||
jQuery.each(a.get(), function(key, val) {
|
|
||||||
self.SET(key, val);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
jQuery.each(arguments, function() {
|
|
||||||
var q = "" + this;
|
|
||||||
q = q.replace(/^[?#]/,''); // remove any leading ? || #
|
|
||||||
q = q.replace(/[;&]$/,''); // remove any trailing & || ;
|
|
||||||
if ($spaces) q = q.replace(/[+]/g,' '); // replace +'s with spaces
|
|
||||||
|
|
||||||
jQuery.each(q.split(/[&;]/), function(){
|
|
||||||
var key = decodeURIComponent(this.split('=')[0] || "");
|
|
||||||
var val = decodeURIComponent(this.split('=')[1] || "");
|
|
||||||
|
|
||||||
if (!key) return;
|
|
||||||
|
|
||||||
if ($numbers) {
|
|
||||||
if (/^[+-]?[0-9]+\.[0-9]*$/.test(val)) // simple float regex
|
|
||||||
val = parseFloat(val);
|
|
||||||
else if (/^[+-]?[0-9]+$/.test(val)) // simple int regex
|
|
||||||
val = parseInt(val, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
val = (!val && val !== 0) ? true : val;
|
|
||||||
|
|
||||||
if (val !== false && val !== true && typeof val != 'number')
|
|
||||||
val = val;
|
|
||||||
|
|
||||||
self.SET(key, val);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return self;
|
|
||||||
};
|
|
||||||
|
|
||||||
queryObject.prototype = {
|
|
||||||
queryObject: true,
|
|
||||||
has: function(key, type) {
|
|
||||||
var value = this.get(key);
|
|
||||||
return is(value, type);
|
|
||||||
},
|
|
||||||
GET: function(key) {
|
|
||||||
if (!is(key)) return this.keys;
|
|
||||||
var parsed = parse(key), base = parsed[0], tokens = parsed[1];
|
|
||||||
var target = this.keys[base];
|
|
||||||
while (target != null && tokens.length != 0) {
|
|
||||||
target = target[tokens.shift()];
|
|
||||||
}
|
|
||||||
return typeof target == 'number' ? target : target || "";
|
|
||||||
},
|
|
||||||
get: function(key) {
|
|
||||||
var target = this.GET(key);
|
|
||||||
if (is(target, Object))
|
|
||||||
return jQuery.extend(true, {}, target);
|
|
||||||
else if (is(target, Array))
|
|
||||||
return target.slice(0);
|
|
||||||
return target;
|
|
||||||
},
|
|
||||||
SET: function(key, val) {
|
|
||||||
var value = !is(val) ? null : val;
|
|
||||||
var parsed = parse(key), base = parsed[0], tokens = parsed[1];
|
|
||||||
var target = this.keys[base];
|
|
||||||
this.keys[base] = set(target, tokens.slice(0), value);
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
set: function(key, val) {
|
|
||||||
return this.copy().SET(key, val);
|
|
||||||
},
|
|
||||||
REMOVE: function(key) {
|
|
||||||
return this.SET(key, null).COMPACT();
|
|
||||||
},
|
|
||||||
remove: function(key) {
|
|
||||||
return this.copy().REMOVE(key);
|
|
||||||
},
|
|
||||||
EMPTY: function() {
|
|
||||||
var self = this;
|
|
||||||
jQuery.each(self.keys, function(key, value) {
|
|
||||||
delete self.keys[key];
|
|
||||||
});
|
|
||||||
return self;
|
|
||||||
},
|
|
||||||
load: function(url) {
|
|
||||||
var hash = url.replace(/^.*?[#](.+?)(?:\?.+)?$/, "$1");
|
|
||||||
var search = url.replace(/^.*?[?](.+?)(?:#.+)?$/, "$1");
|
|
||||||
return new queryObject(url.length == search.length ? '' : search, url.length == hash.length ? '' : hash);
|
|
||||||
},
|
|
||||||
empty: function() {
|
|
||||||
return this.copy().EMPTY();
|
|
||||||
},
|
|
||||||
copy: function() {
|
|
||||||
return new queryObject(this);
|
|
||||||
},
|
|
||||||
COMPACT: function() {
|
|
||||||
function build(orig) {
|
|
||||||
var obj = typeof orig == "object" ? is(orig, Array) ? [] : {} : orig;
|
|
||||||
if (typeof orig == 'object') {
|
|
||||||
function add(o, key, value) {
|
|
||||||
if (is(o, Array))
|
|
||||||
o.push(value);
|
|
||||||
else
|
|
||||||
o[key] = value;
|
|
||||||
}
|
|
||||||
jQuery.each(orig, function(key, value) {
|
|
||||||
if (!is(value)) return true;
|
|
||||||
add(obj, key, build(value));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
this.keys = build(this.keys);
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
compact: function() {
|
|
||||||
return this.copy().COMPACT();
|
|
||||||
},
|
|
||||||
toString: function() {
|
|
||||||
var i = 0, queryString = [], chunks = [], self = this;
|
|
||||||
var encode = function(str) {
|
|
||||||
str = str + "";
|
|
||||||
if ($spaces) str = str.replace(/ /g, "+");
|
|
||||||
return encodeURIComponent(str);
|
|
||||||
};
|
|
||||||
var addFields = function(arr, key, value) {
|
|
||||||
if (!is(value) || value === false) return;
|
|
||||||
var o = [encode(key)];
|
|
||||||
if (value !== true) {
|
|
||||||
o.push("=");
|
|
||||||
o.push(encode(value));
|
|
||||||
}
|
|
||||||
arr.push(o.join(""));
|
|
||||||
};
|
|
||||||
var build = function(obj, base) {
|
|
||||||
var newKey = function(key) {
|
|
||||||
return !base || base == "" ? [key].join("") : [base, "[", key, "]"].join("");
|
|
||||||
};
|
|
||||||
jQuery.each(obj, function(key, value) {
|
|
||||||
if (typeof value == 'object')
|
|
||||||
build(value, newKey(key));
|
|
||||||
else
|
|
||||||
addFields(chunks, newKey(key), value);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
build(this.keys);
|
|
||||||
|
|
||||||
if (chunks.length > 0) queryString.push($hash);
|
|
||||||
queryString.push(chunks.join($separator));
|
|
||||||
|
|
||||||
return queryString.join("");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return new queryObject(location.search, location.hash);
|
|
||||||
};
|
|
||||||
}(jQuery.query || {}); // Pass in jQuery.query as settings object
|
|
||||||
|
|
Loading…
Reference in New Issue