trAvis - MANAGER
Edit File: gallery-select-min.js
if("undefined"==typeof EnviraGalleryModalWindow)var EnviraGalleryModalWindow=new wp.media.view.Modal({controller:{trigger:function(){}}});wp.media.view.EnviraGalleryError=wp.Backbone.View.extend({tagName:"div",className:"notice error envira-gallery-error",render:function(){return this.template=wp.media.template("envira-gallery-error"),this.$el.html(this.template(this.model)),this}});var EnviraGallerySelectionItemView=wp.Backbone.View.extend({tagName:"li",className:"attachment",template:wp.template("envira-selection-item"),initialize:function(e){this.model=e.model},render:function(){return this.$el.html(this.template(this.model.attributes)),this}}),EnviraGallerySelectionSidebarView=wp.Backbone.View.extend({tagName:"div",className:"sidebar",initialize:function(e){this.view="undefined"==typeof e?"envira-selection-sidebar":e},render:function(){return this.$el.html(wp.template(this.view)),this}}),EnviraGallerySelectionView=wp.Backbone.View.extend({tagName:"div",className:"media-frame mode-select wp-core-ui hide-router hide-menu",template:wp.template("envira-selection"),events:{"click .attachment":"click",keyup:"search",search:"search","change select":"updateInsertOption","click button.media-button-insert":"insert"},initialize:function(e){this.action=e.action,this.multiple=e.multiple,this.sidebar_view="undefined"==typeof e.sidebar_view?"envira-selection-sidebar":e.sidebar_view,this.onInsert=e.onInsert,this.prepend_ids="undefined"==typeof e.prepend_ids?!1:e.prepend_ids,this.select_ids="undefined"==typeof e.select_ids?!1:e.select_ids,this.selection=new Backbone.Collection,this.collection=new Backbone.Collection,this.insert_options=new Backbone.Model({modal_title:"undefined"==typeof e.modal_title?envira_gallery_select.modal_title:e.modal_title,title:0,insert_button_label:"undefined"==typeof e.modal_title?envira_gallery_select.insert_button_label:e.insert_button_label}),this.is_loading=!1,this.search_timeout=!1,this.on("loading",this.loading,this),this.on("loaded",this.loaded,this),this.getItems(!1,"")},click:function(e){var t=jQuery(e.currentTarget),i=jQuery("div.attachment-preview",t).attr("data-id");t.hasClass("selected")?this.removeFromSelection(t,i):(this.multiple||this.clearSelection(),this.addToSelection(t,i))},search:function(e){if(!this.is_loading){clearTimeout(this.search_timeout);var t=e.target.value;if(0==t.length)return void this.getItems(!1,"");if(!(t.length<3)){var i=this;this.search_timeout=setTimeout(function(){i.getItems(!0,t)},1e3)}}},getItems:function(e,t){if(!this.is_loading){this.clearSelection(),this.$el.find("ul.attachments").empty(),this.$el.find("div.envira-gallery-error").remove(),this.trigger("loading");var i="";switch(this.action){case"gallery":i="envira_gallery_editor_get_galleries";break;case"album":i="envira_albums_editor_get_albums"}wp.media.ajax(i,{context:this,data:{nonce:envira_gallery_select.get_galleries_nonce,search:e,search_terms:t,prepend_ids:this.prepend_ids},success:function(e){var t=new Backbone.Collection(e);this.collection.reset(),this.collection.add(t.models),this.collection.each(function(e){var t=new EnviraGallerySelectionItemView({model:e});if(this.$el.find("ul.attachments").append(t.render().el),this.select_ids!==!1){var i=jQuery.inArray(parseInt(e.get("id")),this.select_ids);i>-1&&this.addToSelection(jQuery(t.render().el),e.get("id"))}},this),this.trigger("loaded")},error:function(e){this.trigger("loaded",e)}})}},updateInsertOption:function(e){""!=e.target.name&&("checkbox"==e.target.type?value=e.target.checked?1:0:value=e.target.value,this.insert_options.set(e.target.name,value))},render:function(){this.$el.html(this.template(this.insert_options.attributes));var e=new EnviraGallerySelectionSidebarView(this.sidebar_view);return this.$el.find("div.media-sidebar").append(e.render().el),this},renderError:function(e){var t={};t.error=e;var i=new wp.media.view.EnviraGalleryError({model:t});return i.render().el},loading:function(){this.is_loading=!0,this.$el.find(".spinner").css("visibility","visible")},loaded:function(e){this.is_loading=!1,this.$el.find(".spinner").css("visibility","hidden"),"undefined"!=typeof e&&this.$el.find("ul.attachments").before(this.renderError(e))},addToSelection:function(e,t){this.trigger("loading"),this.collection.each(function(e){e.get("id")==t&&this.selection.add(e)},this),e.addClass("selected details"),this.selection.length>0&&this.$el.find("button.media-button-insert").attr("disabled",!1),this.trigger("loaded")},removeFromSelection:function(e,t){this.trigger("loading"),this.selection.each(function(e){this.selection.remove([{cid:e.cid}])},this),e.removeClass("selected details"),0==this.selection.length&&this.$el.find("button.media-button-insert").attr("disabled","disabled"),this.trigger("loaded")},clearSelection:function(){this.selection.each(function(e){this.$el.find('div[data-id="'+e.get("id")+'"]').parent().removeClass("selected details")},this),this.$el.find("button.media-button-insert").attr("disabled","disabled"),this.selection.reset()},insert:function(){if(this.trigger("loading"),"undefined"==typeof this.onInsert){var e=[];this.selection.forEach(function(t){e.push(t.attributes);var i="";0!=this.insert_options.get("title")&&(i="<"+this.insert_options.get("title")+">"+t.get("title")+"</"+this.insert_options.get("title")+">"),i+="[envira-"+this.action+' id="'+t.id+'"]',wp.media.editor.insert(i)},this),jQuery(document).trigger({type:"enviraGalleryModalData",items:e,insert_options:this.insert_options,action:this.action});var t=!0}else var t=this.onInsert();this.trigger("loaded"),t&&EnviraGalleryModalWindow.close()}});