
$(function(){'use strict';var SpecialVideos={init:function(){this.$wrapper=$('.special-videos-grid');this.initEllipses();this.initDropdown();this.initAddVideo();this.initRemoveVideo();},initEllipses:function(){var self=this;$(window).on('resize.specialvideos',function(){self.$wrapper.find('.title a').ellipses();}).trigger('resize.specialvideos');},initDropdown:function(){$('.WikiaDropdown').wikiaDropdown({onChange:function(e,$target){var sort=$target.data('sort'),category=$target.data('category'),qs=new Wikia.Querystring();qs.setVal('sort',sort);if(category){qs.setVal('category',category);}else{qs.removeVal('category');}
qs.goTo();}});},initAddVideo:function(){var addVideoButton=$('.addVideo'),videoEmbedMain;if($.isFunction($.fn.addVideoButton)){addVideoButton.addVideoButton({callbackAfterSelect:function(url,VET){require(['wikia.throbber'],function(throbber){videoEmbedMain=$('#VideoEmbedMain');throbber.show(videoEmbedMain);});$.nirvana.postJson('VideosController','addVideo',{token:mw.user.tokens.get('editToken'),url:url},function(formRes){SpecialVideos.bannerNotification.hide();require(['wikia.throbber'],function(throbber){throbber.remove(videoEmbedMain);});if(formRes.error){SpecialVideos.bannerNotification.setContent(formRes.error).show();}else{VET.close();(new Wikia.Querystring()).goTo();}},function(){require(['wikia.throbber'],function(throbber){throbber.remove(videoEmbedMain);});SpecialVideos.bannerNotification.setContent($.msg('vet-error-while-loading')).show();});return false;}});}else{addVideoButton.hide();}},initRemoveVideo:function(){this.$wrapper.on('click','.remove',function(){var $video=$(this).prevAll('.video-thumbnail'),videoName=$video.children('img').attr('data-video-name');if(videoName){$.confirm({title:$.msg('specialvideos-remove-modal-title'),content:$.msg('specialvideos-remove-modal-message'),width:600,onOk:function(){$.nirvana.sendRequest({controller:'VideoHandler',method:'removeVideo',format:'json',data:{title:videoName},callback:function(json){if(json.result==='ok'){(new Wikia.Querystring(window.location)).addCb().goTo();}else{SpecialVideos.bannerNotification.setContent(json.msg).show();}}});}});}else{SpecialVideos.bannerNotification.setContent($.msg('oasis-generic-error')).show();}});}};require(['BannerNotification'],function(BannerNotification){SpecialVideos.bannerNotification=new BannerNotification().setType('error');SpecialVideos.init();});});;(function(window,$){var Wikia=window.Wikia||{};Wikia.Dropdown=$.createClass(Observable,{settings:{closeOnEscape:true,closeOnOutsideClick:true,eventNamespace:'WikiaDropdown',onChange:null,onDocumentClick:null,onClick:null,onKeyDown:null},constructor:function(element,options){Wikia.Dropdown.superclass.constructor.apply(this,arguments);this.settings=$.extend(this.settings,options);this.$document=$(document);this.$wrapper=$(element).addClass('closed');this.$dropdown=this.$wrapper.find('.dropdown');this.$selectedItems=this.$wrapper.find('.selected-items');this.$selectedItemsList=this.$selectedItems.find('.selected-items-list');this.bindEvents();},bindEvents:function(){this.$wrapper.off('click.'+this.settings.eventNamespace).on('click.'+this.settings.eventNamespace,this.proxy(this.onClick));this.getItems().off('click.'+this.settings.eventNamespace).on('click.'+this.settings.eventNamespace,this.proxy(this.onChange));this.$document.off('click.'+this.settings.eventNamespace).off('keydown.'+this.settings.eventNamespace);if(this.settings.closeOnEscape||this.settings.onKeyDown){this.$document.on('keydown.'+this.settings.eventNamespace,this.proxy(this.onKeyDown));}
if(this.settings.closeOnOutsideClick||this.settings.onDocumentClick){this.$document.on('click.'+this.settings.eventNamespace,this.proxy(this.onDocumentClick));}
this.fire('bindEvents');},disable:function(){this.close();this.$wrapper.addClass('disable');},enable:function(){this.$wrapper.removeClass('disable');},close:function(){this.$wrapper.removeClass('open').addClass('closed');this.fire('close');},open:function(){if(this.$wrapper.hasClass('disable')){return true;}
this.$wrapper.toggleClass('open closed');this.fire('open');},getItems:function(){return this.$dropdown.find('.dropdown-item');},getSelectedItems:function(){return this.getItems().filter('.selected');},isOpen:function(){return this.$wrapper.hasClass('open');},onClick:function(event){var $target=$(event.target);if($target.is(this.getItems().find('label'))){return;}
if(!this.settings.onClick||this.settings.onClick()!==false){if(!this.isOpen()){this.open();}}
this.fire('click',event);},onChange:function(event){var $target=$(event.target);var value=$target.text();if($.isFunction(this.settings.onChange)){this.settings.onChange.call(this,event,$target);}
this.getSelectedItems().removeClass('selected');$target.parent().addClass('selected');this.$selectedItemsList.text(value);this.fire('change',event);this.close();},onKeyDown:function(event){if(!this.settings.onKeyDown||this.settings.onKeyDown()!==false){if(this.settings.closeOnEscape&&event.keyCode==27&&this.isOpen()){this.close();}}
this.fire('keyDown',event);},onDocumentClick:function(event){if(!this.settings.onDocumentClick||this.settings.onDocumentClick()!==false){if(this.settings.closeOnOutsideClick&&this.isOpen()&&!$.contains(this.$wrapper[0],event.target)){this.close();}}
this.fire('documentClick',event);}});$.fn.wikiaDropdown=function(options){return this.each(function(){$.data(this,'WikiaDropdown',new Wikia.Dropdown(this,options));});};window.Wikia=Wikia;})(this,jQuery);;