Wordpress/wp-admin/js/theme.js
2012-02-09 22:00:49 +00:00

1 line
3.1 KiB
JavaScript

var ThemeViewer;(function(a){ThemeViewer=function(b){function d(){a("#filter-click, #mini-filter-click").unbind("click").click(function(){a("#filter-click").toggleClass("current");a("#filter-box").slideToggle();a("#current-theme").slideToggle(300);return false});a("#filter-box :checkbox").unbind("click").click(function(){var e=a("#filter-box :checked").length,f=a("#filter-click").text();if(f.indexOf("(")!=-1){f=f.substr(0,f.indexOf("("))}if(e==0){a("#filter-click").text(f)}else{a("#filter-click").text(f+" ("+e+")")}})}var c={init:d};return c}})(jQuery);jQuery(document).ready(function(a){theme_viewer=new ThemeViewer();theme_viewer.init()});var wpThemes;(function(c){var a={},b;wpThemes={timeToTriggerQuery:150,minQueryAJAXDuration:200,outListBottomThreshold:200,noMoreResults:false,init:function(){c(".pagination-links").hide();a.nonce=c("#_ajax_fetch_list_nonce").val();a.queryString=window.location.search;a.queryArray=wpThemes.parseQuery(a.queryString.substring(1));a.search=a.queryArray.s;a.features=a.queryArray.features;a.startPage=parseInt(a.queryArray.paged);a.tab=a.queryArray.tab;a.type=a.queryArray.type;if(isNaN(a.startPage)){a.startPage=2}else{a.startPage++}a.outList=c("#availablethemes");a.waiting=c("div.tablenav.bottom").children("img.ajax-loading");a.window=c(window);wpThemes.query=new b();a.window.scroll(function(){wpThemes.maybeLoad()})},delayedCallback:function(f,d){var i,h,g,e;if(!d){return f}setTimeout(function(){if(h){return f.apply(e,g)}i=true},d);return function(){if(i){return f.apply(this,arguments)}g=arguments;e=this;h=true}},ajax:function(f){var e=this,d=wpThemes.delayedCallback(function(g,h){e.process(g,h);if(f){f(g,h)}},wpThemes.minQueryAJAXDuration);this.query.ajax(d)},process:function(d,e){if((d===undefined)||(d.rows.indexOf("no-items")!=-1)){this.noMoreResults=true}else{a.outList.append(d.rows)}},maybeLoad:function(){var e=this,f=c(document),d=f.scrollTop()+a.window.innerHeight();if(this.noMoreResults||!this.query.ready()||(d<a.outList.height()-wpThemes.outListBottomThreshold)){return}setTimeout(function(){var g=f.scrollTop(),h=g+a.window.innerHeight();if(!e.query.ready()||(h<a.outList.height()-wpThemes.outListBottomThreshold)){return}a.waiting.css("visibility","visible");e.ajax(function(){a.waiting.css("visibility","hidden")})},wpThemes.timeToTriggerQuery)},parseQuery:function(h){var j={};if(!h){return j}var e=h.split(/[;&]/);for(var g=0;g<e.length;g++){var l=e[g].split("=");if(!l||l.length!=2){continue}var f=unescape(l[0]);var k=unescape(l[1]);k=k.replace(/\+/g," ");f=f.replace(/\[.*\]$/g,"");if(j[f]===undefined){j[f]=k}else{var d=j[f];if(!jQuery.isArray(j[f])){j[f]=new Array(d,k)}else{j[f].push(k)}}}return j}};b=function(){this.failedRequest=false;this.querying=false;this.page=a.startPage};c.extend(b.prototype,{ready:function(){return !(this.querying||this.failedRequest)},ajax:function(f){var d=this,e={action:"fetch-list",tab:a.tab,paged:this.page,s:a.search,type:a.type,_ajax_fetch_list_nonce:a.nonce,"features[]":a.features,list_args:list_args};this.querying=true;c.get(ajaxurl,e,function(g){d.page++;d.querying=false;d.failedRequest=!g;f(g,e)},"json")}});c(document).ready(wpThemes.init)})(jQuery);