WordPress/wp-admin/js/theme.min.js

1 line
20 KiB
JavaScript
Raw Normal View History

window.wp=window.wp||{},function(a){var b,c;b=wp.themes=wp.themes||{},b.data=_wpThemeSettings,c=b.data.l10n,b.isInstall=!!b.data.settings.isInstall,_.extend(b,{model:{},view:{},routes:{},router:{},template:wp.template}),b.Model=Backbone.Model.extend({initialize:function(){var c,d;c={action:"install-theme",theme:this.get("slug"),_wpnonce:b.data.settings._nonceInstall},c=b.data.settings.updateURI+"?"+a.param(c),-1!==_.indexOf(b.data.installedThemes,this.get("slug"))&&this.set({installed:!0}),this.set({installURI:this.get("slug")?c:!1,id:this.get("slug")||this.get("id")}),this.has("sections")&&(d=this.get("sections").description,this.set({description:d}))}}),b.view.Appearance=wp.Backbone.View.extend({el:"#wpbody-content .wrap .theme-browser",window:a(window),page:0,initialize:function(a){_.bindAll(this,"scroller"),this.SearchView=a.SearchView?a.SearchView:b.view.Search,this.window.bind("scroll",_.throttle(this.scroller,300))},render:function(){this.view=new b.view.Themes({collection:this.collection,parent:this}),this.search(),this.view.render(),this.$el.empty().append(this.view.el).addClass("rendered"),this.$el.append('<br class="clear"/>')},searchContainer:a("#wpbody h2:first"),search:function(){var d,e=this;1!==b.data.themes.length&&(d=new this.SearchView({collection:e.collection,parent:this}),d.render(),this.searchContainer.append(a.parseHTML('<label class="screen-reader-text" for="theme-search-input">'+c.search+"</label>")).append(d.el))},scroller:function(){var a,b,c=this;a=this.window.scrollTop()+c.window.height(),b=c.$el.offset().top+c.$el.outerHeight(!1)-c.window.height(),b=Math.round(.9*b),a>b&&this.trigger("theme:scroll")}}),b.Collection=Backbone.Collection.extend({model:b.Model,terms:"",doSearch:function(a){this.terms!==a&&(this.terms=a,this.terms.length>0&&this.search(this.terms),""===this.terms&&this.reset(b.data.themes),this.trigger("update"))},search:function(a){var c,d,e;this.reset(b.data.themes,{silent:!0}),a=a.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),a=a.replace(/ /g,")(?=.*"),c=new RegExp("^(?=.*"+a+").+","i"),d=this.filter(function(b){return e=_.union(b.get("name"),b.get("id"),b.get("description"),b.get("author"),b.get("tags")),c.test(b.get("author"))&&a.length>2&&b.set("displayAuthor",!0),c.test(e)}),this.reset(d)},paginate:function(a){var b=this;return a=a||0,b=_(b.rest(20*a)),b=_(b.first(20))},count:!1,query:function(b,c){var d,e,f,g=this.queries,h=this;if(this.currentQuery.request=b,d=_.find(g,function(a){return _.isEqual(a.request,b)}),e=_.has(b,"page"),e||(this.currentQuery.page=1),d||e){if(e)return this.apiCall(b,c,e).done(function(a){h.add(a.themes),h.trigger("query:success"),h.loadingThemes=!1}).fail(function(){h.trigger("query:fail")});0===d.themes.length?h.trigger("query:empty"):a("body").removeClass("no-results"),_.isNumber(d.total)&&(this.count=d.total),d.total||(this.count=this.length),this.reset(d.themes),this.trigger("update")}else d=this.apiCall(b,c).done(function(a){a.themes?(h.reset(a.themes),f=a.info.results,g.push({themes:a.themes,request:b,total:f})):c&&(h.reset(a),f=1,h.trigger("query:theme")),h.trigger("update"),h.trigger("query:success",f),a.themes&&0===a.themes.length&&h.trigger("query:empty")}).fail(function(){h.trigger("query:fail")})},queries:[],currentQuery:{page:1,request:{}},apiCall:function(b,c,d){return b.tag&&_.isArray(b.tag)&&(b.tag=b.tag.join(",")),c||(c="query_themes"),a.ajax({url:"https://api.wordpress.org/themes/info/1.1/?callback=?",dataType:"jsonp",timeout:15e3,data:{action:c,request:_.extend({per_page:72,fields:"description,tested,requires,rating,downloaded,downloadLink,last_updated,homepage,num_ratings"},b)},beforeSend:function(){d||a("body").addClass("loading-themes").removeClass("no-results")}})},loadingThemes:!1}),b.view.Theme=wp.Backbone.View.extend({className:"theme",state:"grid",html:b.template("theme"),events:{click:b.isInstall?"preview":"expand","click .preview":"preview",keydown:b.isInstall?"preview":"expand",touchend:b.isInstall?"preview":"expand",keyup:"addFocus",touchmove:"preventExpand"},touchDrag:!1,render:function(){var a=this.model.toJSON();thi