1/** 2 * Creates and initialises the drawers. 3 * 4 * @class 5 * @extends Responsiville.Debug 6 * @extends Responsiville.Events 7 * 8 * @author Nevma, [email protected] 9 * @license Nevma Copyright (c) http://www.nevma.gr 10 * 11 * @fires Responsiville.Drawers#init 12 * 13 * @classdesc A drawers element is an element that opens and closes like an 14 * an accordion, only it is self contained and has no header/title 15 * element like the accordion. Instead it automatically creates an 16 * open/close button. 17 * 18 * @param {Object} options The initialisation options of the module. 19 * 20 * @property {Object} options The options that define the object 21 * behaviour. 22 * @property {boolean} options.debug Whether to print debug messages in the 23 * browser console. 24 * @property {boolean} options.slug A special codename for the instance of 25 * the element, to be used as a class on 26 * its container and as a key in arrays 27 * where it is grouped with other elements 28 * of its kind. 29 * @property {boolean} options.exclusive Whether multiple drawers panels 30 * drawers can be simultaneously open or 31 * not. 32 * @property {boolean} options.container The container element of the drawers 33 * panels. 34 * @property {boolean} options.element The selector or element that is the 35 * actual panel which opens and closes. It 36 * has to be inside the container element. 37 * @property {boolean} options.effect The visual effect to use for opening 38 * and closing the elements. 39 * @property {boolean} options.duration The duration of the visual effect when 40 * opening and closing the elements. 41 * @property {string} options.enter Comma separated list of breakpoints in 42 * which the drawers enters, wihch means 43 * it is enabled. 44 * @property {string} options.leave Comma separated list of breakpoints in 45 * which the drawers leaves, which means 46 * it is disabled. 47 */ 48Responsiville.Drawers=function(options){if(!Responsiville.Main.getInstance()){throw new Error('Responsiville instantiation error: the framework has not been initialised, call new Responsiville::Main() and then Responsiville::init().')} 49this.options={};this.options=jQuery.extend(this.options,Responsiville.Drawers.defaults,options);this.codeName='responsiville.drawers';this.responsiville=Responsiville.Main.getInstance();this.$body=this.responsiville.$body;this.$document=this.responsiville.$document;this.$window=this.responsiville.$window;this.$container=jQuery(this.options.container);for(var key in this.options){var value=this.$container.data('responsiville-drawers-'+key.toLowerCase());if(typeof value!=='undefined'){this.options[key]=value}} 50if(this.options.slug==''){Responsiville.Drawers.elementsCounter=Responsiville.Drawers.elementsCounter!==undefined?++Responsiville.Drawers.elementsCounter:0;this.options.slug=this.codeName.replace('.','-')+'-'+Responsiville.Drawers.elementsCounter} 51var htmlBreakpoints=Responsiville.determineEnableDisableBreakpoints({enter:this.$container.data('responsiville-drawers-enter'),leave:this.$container.data('responsiville-drawers-leave')});if(htmlBreakpoints!==null){this.options.enter=htmlBreakpoints.enter;this.options.leave=htmlBreakpoints.leave} 52if(this.$container.length===0){this.log('Responsiville.Drawers instantiation error: no drawers found ('+this.options.container+').');return} 53if(typeof this.$container.data('responsiville-drawers-api')!=='undefined'){this.log('Responsiville.Drawers has already run for element: ('+this.options.container+').');return} 54this.$container.data('responsiville-api',this);this.$container.data('responsiville-drawers-api',this);this.$container.addClass(this.options.slug);this.$elements=this.$container.find(this.options.element);this.enabled=!1;this.setupEvents();this.log('drawers initialised');this.fireEvent('init')};Responsiville.extend(Responsiville.Drawers,Responsiville.Debug.Extensions);Responsiville.extend(Responsiville.Drawers,Responsiville.Events);Responsiville.Drawers.AUTO_RUN=typeof RESPONSIVILLE_AUTO_INIT!=='undefined'?RESPONSIVILLE_AUTO_INIT:!0;Responsiville.Drawers.defaults={debug:!1,exclusive:!1,slug:'',container:'.responsiville-drawers',element:'ul',effect:'slide',startAt:0,duration:300,enter:'small, mobile, tablet, laptop, desktop, large, xlarge',leave:''};Responsiville.Drawers.autoRun=function(){jQuery(Responsiville.Drawers.defaults.container).each(function(){new Responsiville.Drawers({debug:Responsiville.Main.getInstance().options.debug,container:this})})};Responsiville.Drawers.prototype.setupEvents=function(){var k,length;var breakpointsEnter=Responsiville.splitAndTrim(this.options.enter);for(k=0,length=breakpointsEnter.length;k<length;k++){this.responsiville.on('enter.'+breakpointsEnter[k],this.getBoundFunction(this.enable))} 55var breakpointsLeave=Responsiville.splitAndTrim(this.options.leave);for(k=0,length=breakpointsLeave.length;k<length;k++){this.responsiville.on('enter.'+breakpointsLeave[k],this.getBoundFunction(this.disable))} 56if(this.responsiville.is(this.options.enter)){this.enable()} 57if(this.options.startAt>0){this.openElement(this.$elements.eq(this.options.startAt-1))}};Responsiville.Drawers.prototype.enable=function(){if(this.enabled){return} 58this.log('enable drawers');this.enabled=!0;for(var k=0,length=this.$elements.length;k<length;k++){var $element=this.$elements.eq(k);if($element.parent().find('.responsiville-drawers-button').length==0){$element.parent().append('<button class="responsiville-drawers-button"></button>')}} 59for(var k=0,length=this.$elements.length;k<length;k++){var $element=this.$elements.eq(k);$element.parent().addClass('responsiville-drawers-parent');$element.addClass('responsiville-drawers-element').siblings('.responsiville-drawers-button').on('click',this.getBoundFunction(this.buttonClick))} 60this.fireEvent('enabled')};Responsiville.Drawers.prototype.disable=function(){if(!this.enabled){return} 61this.log('disable drawers');this.enabled=!1;for(var k=0,length=this.$elements.length;k<length;k++){var $element=this.$elements.eq(k);$element.parent().removeClass('responsiville-drawers-parent');$element.addClass('responsiville-drawers-element').siblings('.responsiville-drawers-button').off('click',this.getBoundFunction(this.buttonClick))} 62this.fireEvent('disabled')};Responsiville.Drawers.prototype.buttonClick=function(event){var $element=jQuery(event.target).siblings(this.options.element);if($element.is(':visible')){this.closeElement($element)}else{this.openElement($element)}};Responsiville.Drawers.prototype.openElement=function($element){this.log('opening drawers');this.fireEvent('opening');$element.addClass('responsiville-drawers-element-opening');$element.velocity('slideDown',{duration:this.options.duration,complete:(function(){$element.removeClass('responsiville-drawers-element-opening');$element.addClass('responsiville-drawers-element-open');$element.siblings('.responsiville-drawers-button').addClass('responsiville-drawers-button-open');this.fireEvent('opened')}).bind(this)})};Responsiville.Drawers.prototype.closeElement=function($element){this.log('closing drawers');this.fireEvent('closing');$element.addClass('responsiville-drawers-element-closing');$element.velocity('slideUp',{duration:this.options.duration,complete:(function(){$element.removeClass('responsiville-drawers-element-closing');$element.removeClass('responsiville-drawers-element-open');$element.siblings('.responsiville-drawers-button').removeClass('responsiville-drawers-button-open');this.fireEvent('closed')}).bind(this)})} 63;
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.