vendor: 5,139 bytes, lines 1-151
1(function ($, pluginName) { 2 var defaults = { 3 htmlClass: true 4 } 5 6 function Plugin (element, options) { 7 this.element = element 8 this.eventController = eventController 9 this.options = $.extend({}, defaults, options) 10 this.options.initialized = false 11 this.init() 12 } 13 Plugin.prototype.init = function () { 14 var zeynep = this.element 15 var options = this.options 16 var eventController = this.eventController.bind(this) 17 // exit if already initialized 18 if (options.initialized === true) return 19 20 eventController('loading') 21 // handle subMenu links/triggers click events 22 zeynep.find('[data-submenu]').on('click', function (event) { 23 event.preventDefault() 24 var self = $(this) 25 var subMenuId = self.attr('data-submenu') 26 var subMenuEl = $('#' + subMenuId) 27 // if subMenu not found, do nothing 28 if (!subMenuEl.length) return 29 30 var eventDetails = { 31 subMenu: true, 32 menuId: subMenuId 33 } 34 eventController('opening', eventDetails) 35 // open the subMenu 36 zeynep.find('.submenu.current').removeClass('current') 37 subMenuEl.addClass('opened current') 38 !zeynep.hasClass('submenu-opened') && zeynep.addClass('submenu-opened') 39 // scroll to top before submenu transition 40 zeynep[0].scrollTo({ top: 0 }) 41 42 eventController('opened', eventDetails) 43 }) 44 // handle subMenu closers click events 45 zeynep.find('[data-submenu-close]').on('click', function (event) { 46 event.preventDefault() 47 var self = $(this) 48 var subMenuId = self.attr('data-submenu-close') 49 var subMenuEl = $('#' + subMenuId) 50 // if subMenu not found, do nothing 51 if (!subMenuEl.length) return 52 53 var eventDetails = { 54 subMenu: true, 55 menuId: subMenuId 56 } 57 eventController('closing', eventDetails) 58 // close subMenu 59 subMenuEl.removeClass('opened current') 60 zeynep.find('.submenu.opened').last().addClass('current') 61 !zeynep.find('.submenu.opened').length && zeynep.removeClass('submenu-opened') 62 // scroll to top between submenu transitions 63 subMenuEl[0].scrollTo({ top: 0 }) 64 65 eventController('closed', eventDetails) 66 }) 67 eventController('load') 68 // zeynepjs successfully initialized 69 this.options.htmlClass && !$('html').hasClass('zeynep-initialized') && $('html').addClass('zeynep-initialized') 70 options.initialized = true 71 } 72 73 Plugin.prototype.open = function () { 74 this.eventController( 75 'opening', 76 { subMenu: false } 77 ) 78 // zeynepjs menu is opened 79 this.element.addClass('opened') 80 this.options.htmlClass && $('html').addClass('zeynep-opened') 81 this.eventController( 82 'opened', 83 { subMenu: false } 84 ) 85 } 86 Plugin.prototype.close = function (disableEvent) { 87 !disableEvent && this.eventController('closing', { subMenu: false }) 88 89 // zeynepjs menu is opened 90 this.element.removeClass('opened') 91 this.options.htmlClass && $('html').removeClass('zeynep-opened') 92 !disableEvent && this.eventController('closed', { subMenu: false }) 93 } 94 Plugin.prototype.destroy = function () { 95 this.eventController('destroying') 96 // close the menu without firing any event 97 this.close(true) 98 99 // close submenus 100 this.element.find('.submenu.opened').removeClass('opened') 101 // clear/remove the instance on the element 102 this.element.removeData(pluginName) 103 this.eventController('destroyed') 104 // reset options 105 this.options = defaults 106 107 this.options.htmlClass && $('html').removeClass('zeynep-initialized') 108 delete this.element 109 delete this.options 110 delete this.eventController 111 } 112 Plugin.prototype.on = function (name, handler) { 113 eventBinder.call(this, name, handler) 114 } 115 var eventController = function (type, details) { 116 if (!this.options[type]) return 117 if (typeof this.options[type] !== 'function') throw Error('event handler must be a function: ' + type) 118 119 // call the event 120 this.options[type].call(this, this.element, this.options, details) 121 } 122 var getInstance = function (element, options) { 123 var instance = null 124 if (!element.data(pluginName)) { 125 // zeynepjs is not initialized for the element 126 // crceate a new instance 127 instance = new Plugin(element, options || {}) 128 // put the instance on element 129 element.data(pluginName, instance) 130 } else { 131 // return the already initialized instance 132 instance = element.data(pluginName) 133 } 134 135 return instance 136 } 137 var eventBinder = function (name, handler) { 138 if (typeof name !== 'string') throw Error('event name is expected to be a string but got: ' + typeof name) 139 if (typeof handler !== 'function') throw Error('event handler is not a function for: ' + name) 140 // update options 141 this.options[name] = handler 142 } 143 // a really lightweight plugin wrapper around the constructor 144 // preventing against multiple instantiations 145 $.fn[pluginName] = function (options) { 146 // get a zeynepjs instance 147 var instance = getInstance($(this[0]), options) 148 149 return instance 150 } 151})(window.jQuery || window.cash, 'zeynep')
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.