mirror of
https://github.com/WordPress/WordPress.git
synced 2024-09-07 13:18:14 +02:00
see #25858, #22862. Built from https://develop.svn.wordpress.org/trunk@26143 git-svn-id: http://core.svn.wordpress.org/trunk@26054 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 line
7.2 KiB
JavaScript
1 line
7.2 KiB
JavaScript
window.wp=window.wp||{},function(a){var b=wp.themes=wp.themes||{};b.data=_wpThemeSettings,_.extend(b,{model:{},view:{},routes:{},router:{},template:wp.template}),b.model=Backbone.Model.extend({}),b.view.Appearance=wp.Backbone.View.extend({el:b.data.settings.container,window:a(window),page:0,events:{"click .themes-bulk-edit":"editMode","click .theme .delete-theme":"deleteTheme"},initialize:function(){var a=this;this.window.bind("scroll.themes",function(){this.throttle=!0}),setInterval(function(){this.throttle&&(this.throttle=!1,a.scroller())},300)},render:function(){this.view=new b.view.Themes({collection:this.collection,parent:this}),this.view.render(),this.$el.append(this.view.el),this.search()},search:function(){var a,c=this;a=new b.view.Search({collection:c.collection}),a.render(),c.$el.find("> h2").after(a.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")},editMode:function(){a("body").toggleClass("edit-mode"),this.$el.find(".themes-bulk-edit").toggleClass("mp6-text-highlight")},deleteTheme:function(){return confirm(b.data.settings.confirmDelete)}}),b.Collection=Backbone.Collection.extend({model:b.model,terms:"",doSearch:function(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,f=this;f.reset(b.data.themes),a=a.replace(" ",")(?=.*"),c=new RegExp("^(?=.*"+a+").+","i"),d=f.filter(function(a){return e=_.union(a.get("name"),a.get("author"),a.get("tags")),c.test(a.get("author"))&&a.set("displayAuthor",!0),c.test(e)}),f.reset(d)},paginate:function(a){var b=this;return a=a||0,b=_(b.rest(15*a)),b=_(b.first(15))}}),b.view.Theme=wp.Backbone.View.extend({className:"theme",state:"grid",html:b.template("theme"),events:{click:"expand"},render:function(){var a=this.model.toJSON();this.$el.html(this.html(a)),this.activeTheme(),this.model.get("displayAuthor")&&this.$el.addClass("display-author")},activeTheme:function(){this.model.get("active")&&(this.$el.addClass("active"),this.$el.find(".theme-name").addClass("mp6-primary"),a("#theme-overlay").addClass("active"))},expand:function(b){var c=this;b=b||window.event,a(b.target).is(".theme-actions a, .delete-theme")||this.trigger("theme:expand",c.model.cid)}}),b.view.Details=wp.Backbone.View.extend({id:"theme-overlay",events:{click:"collapse","click .delete-theme":"deleteTheme","click .left":"previousTheme","click .right":"nextTheme"},html:b.template("theme-single"),render:function(){var a=this.model.toJSON();this.$el.html(this.html(a)),this.activeTheme(),this.navigation()},activeTheme:function(){this.model.get("active")?this.$el.addClass("active"):a("#theme-overlay").removeClass("active")},collapse:function(c){var d,e=this;c=c||window.event,(a(c.target).is(".theme-backdrop")||a(c.target).is("div.back")||27===c.keyCode)&&(a("body").addClass("closing-overlay"),this.$el.fadeOut(130,function(){a("body").removeClass("theme-overlay closing-overlay"),e.closeOverlay(),d=document.body.scrollTop,b.router.navigate(""),document.body.scrollTop=d}))},navigation:function(){var b=this;a("body").on("keyup",function(a){39===a.keyCode&&b.trigger("theme:next",b.model.cid),37===a.keyCode&&b.trigger("theme:previous",b.model.cid),27===a.keyCode&&b.collapse()})},closeOverlay:function(){this.remove(),this.unbind(),this.trigger("theme:collapse")},screenshotGallery:function(){var b,c,d=a("#theme-screenshots");d.find("div.first").next().addClass("selected"),d.on("click","div.thumb",function(){b=a(this),c=a(this).find("img").clone(),b.siblings(".first").html(c),b.siblings(".selected").removeClass("selected"),b.addClass("selected")})},deleteTheme:function(){return confirm(b.data.settings.confirmDelete)},nextTheme:function(){var a=this;a.trigger("theme:next",a.model.cid)},previousTheme:function(){var a=this;a.trigger("theme:previous",a.model.cid)}}),b.view.Themes=wp.Backbone.View.extend({id:"themes",index:0,count:a("#theme-count"),initialize:function(a){var b=this;this.parent=a.parent,this.setView("grid"),b.currentTheme(),this.listenTo(b.collection,"update",function(){b.parent.page=0,b.currentTheme(),b.render(this)}),this.listenTo(this.parent,"theme:scroll",function(){b.renderThemes(b.parent.page)})},render:function(){this.$el.html(""),this.renderThemes(this.parent.page),this.count.text(this.collection.length)},renderThemes:function(c){var d=this;d.instance=d.collection.paginate(c),0!==d.instance.length&&(c>=1&&a("#add-new").remove(),d.instance.each(function(a){d.theme=new b.view.Theme({model:a}),d.theme.render(),d.$el.append(d.theme.el),d.listenTo(d.theme,"theme:expand",d.expand,d)}),this.$el.append('<div id="add-new" class="theme add-new"><a href="'+b.data.settings.install_uri+'"><div class="theme-screenshot"><span></span></div><h3 class="theme-name">'+b.data.i18n.add_new+"</h3></a></div>"),this.parent.page++)},currentTheme:function(){var a,b=this;a=b.collection.findWhere({active:!0}),a&&(b.collection.remove(a),b.collection.add(a,{at:0}))},setView:function(a){return a},expand:function(c){var d=this;this.model=d.collection.get(c),b.router.navigate("theme/"+this.model.id),this.setView("detail"),a("body").addClass("theme-overlay"),this.overlay=new b.view.Details({model:d.model,className:"theme-"+d.model.id}),this.overlay.render(),this.$el.append(this.overlay.el),this.overlay.screenshotGallery(),this.index=0,this.listenTo(this.overlay,"theme:next",function(){d.index++,d.next([d.model.cid,d.index]),d.overlay.screenshotGallery()}).listenTo(this.overlay,"theme:previous",function(){d.index--,d.previous([d.model.cid,d.index]),d.overlay.screenshotGallery()})},next:function(a){var c,d,e=this;return c=e.collection.get(a[0]),d=e.collection.at(e.collection.indexOf(c)+a[1]),void 0!==d?(this.overlay.$el.html(""),this.nextTheme=new b.view.Details({model:d,className:"theme-"+d.id}),b.router.navigate("theme/"+d.id),this.nextTheme.render(),this.overlay.$el.html(this.nextTheme.el)):(e.index--,void 0)},previous:function(a){var c,d,e=this;return c=e.collection.get(a[0]),d=e.collection.at(e.collection.indexOf(c)+a[1]),void 0!==d?(this.overlay.$el.html(""),this.previousTheme=new b.view.Details({model:d,className:"theme-"+d.id}),b.router.navigate("theme/"+d.id),this.previousTheme.render(),this.overlay.$el.html(this.previousTheme.el)):(e.index++,void 0)}}),b.view.Search=wp.Backbone.View.extend({className:"search-form",events:{"keyup #theme-search":"search"},html:b.template("theme-search"),render:function(){var a=this;a.$el.html(a.html)},search:function(){this.collection.doSearch(a("#theme-search").val())}}),b.routes=Backbone.Router.extend({routes:{"search/:query":"search","theme/:slug":"theme"},search:function(b){a("#theme-search").val(b)}}),_.extend(b.routes,b.data.settings.extraRoutes),b.Run={init:function(){this.themes=new b.Collection(b.data.themes),this.view=new b.view.Appearance({collection:this.themes}),this.render()},render:function(){this.view.render(),this.routes(),Backbone.history.start({root:b.data.settings.root})},routes:function(){var a=this;b.router=new b.routes,b.router.on("route:theme",function(b){a.view.view.expand(b)}),b.router.on("route:search",function(b){a.themes.doSearch(b)})}},jQuery(document).ready(_.bind(b.Run.init,b.Run))}(jQuery); |