1/*jslint unparam: true, browser: true, indent: 2 */ 2 3;(function ($, window, document, undefined) { 4 'use strict'; 5 6 Foundation.libs.dropdown = { 7 name : 'dropdown', 8 9 version : '4.3.0', 10 11 settings : { 12 activeClass: 'open', 13 is_hover: false, 14 opened: function(){}, 15 closed: function(){} 16 }, 17 18 init : function (scope, method, options) { 19 this.scope = scope || this.scope; 20 Foundation.inherit(this, 'throttle scrollLeft data_options'); 21 22 if (typeof method === 'object') { 23 $.extend(true, this.settings, method); 24 } 25 26 if (typeof method !== 'string') { 27 28 if (!this.settings.init) { 29 this.events(); 30 } 31 32 return this.settings.init; 33 } else { 34 return this[method].call(this, options); 35 } 36 }, 37 38 events : function () { 39 var self = this; 40 41 $(this.scope) 42 .on('click.fndtn.dropdown', '[data-dropdown]', function (e) { 43 var settings = $.extend({}, self.settings, self.data_options($(this))); 44 e.preventDefault(); 45 46 if (!settings.is_hover) self.toggle($(this)); 47 }) 48 .on('mouseenter', '[data-dropdown]', function (e) { 49 var settings = $.extend({}, self.settings, self.data_options($(this))); 50 if (settings.is_hover) self.toggle($(this)); 51 }) 52 .on('mouseleave', '[data-dropdown-content]', function (e) { 53 var target = $('[data-dropdown="' + $(this).attr('id') + '"]'), 54 settings = $.extend({}, self.settings, self.data_options(target)); 55 if (settings.is_hover) self.close.call(self, $(this)); 56 }) 57 .on('opened.fndtn.dropdown', '[data-dropdown-content]', this.settings.opened) 58 .on('closed.fndtn.dropdown', '[data-dropdown-content]', this.settings.closed); 59 60 $(document).on('click.fndtn.dropdown', function (e) { 61 var parent = $(e.target).closest('[data-dropdown-content]'); 62 63 if ($(e.target).data('dropdown')) { 64 return; 65 } 66 if (parent.length > 0 && ($(e.target).is('[data-dropdown-content]') || $.contains(parent.first()[0], e.target))) { 67 e.stopPropagation(); 68 return; 69 } 70 71 self.close.call(self, $('[data-dropdown-content]')); 72 }); 73 74 $(window).on('resize.fndtn.dropdown', self.throttle(function () { 75 self.resize.call(self); 76 }, 50)).trigger('resize'); 77 78 this.settings.init = true; 79 }, 80 81 close: function (dropdown) { 82 var self = this; 83 dropdown.each(function () { 84 if ($(this).hasClass(self.settings.activeClass)) { 85 $(this) 86 .css(Foundation.rtl ? 'right':'left', '-99999px') 87 .removeClass(self.settings.activeClass); 88 $(this).trigger('closed'); 89 } 90 }); 91 }, 92 93 open: function (dropdown, target) { 94 this 95 .css(dropdown 96 .addClass(this.settings.activeClass), target); 97 dropdown.trigger('opened'); 98 }, 99 100 toggle : function (target) { 101 var dropdown = $('#' + target.data('dropdown')); 102 103 this.close.call(this, $('[data-dropdown-content]').not(dropdown)); 104 105 if (dropdown.hasClass(this.settings.activeClass)) { 106 this.close.call(this, dropdown); 107 } else { 108 this.close.call(this, $('[data-dropdown-content]')) 109 this.open.call(this, dropdown, target); 110 } 111 }, 112 113 resize : function () { 114 var dropdown = $('[data-dropdown-content].open'), 115 target = $("[data-dropdown='" + dropdown.attr('id') + "']"); 116 117 if (dropdown.length && target.length) { 118 this.css(dropdown, target); 119 } 120 }, 121 122 css : function (dropdown, target) { 123 var offset_parent = dropdown.offsetParent(); 124 // if (offset_parent.length > 0 && /body/i.test(dropdown.offsetParent()[0].nodeName)) { 125 var position = target.offset(); 126 position.top -= offset_parent.offset().top; 127 position.left -= offset_parent.offset().left; 128 // } else { 129 // var position = target.position(); 130 // } 131 132 if (this.small()) { 133 dropdown.css({ 134 position : 'absolute', 135 width: '95%', 136 left: '2.5%', 137 'max-width': 'none', 138 top: position.top + this.outerHeight(target) 139 }); 140 } else { 141 if (!Foundation.rtl && $(window).width() > this.outerWidth(dropdown) + target.offset().left) { 142 var left = position.left; 143 if (dropdown.hasClass('right')) { 144 dropdown.removeClass('right'); 145 } 146 } else { 147 if (!dropdown.hasClass('right')) { 148 dropdown.addClass('right'); 149 } 150 var left = position.left - (this.outerWidth(dropdown) - this.outerWidth(target)); 151 } 152 153 dropdown.attr('style', '').css({ 154 position : 'absolute', 155 top: position.top + this.outerHeight(target), 156 left: left 157 }); 158 } 159 160 return dropdown; 161 }, 162 163 small : function () { 164 return $(window).width() < 768 || $('html').hasClass('lt-ie9'); 165 }, 166 167 off: function () { 168 $(this.scope).off('.fndtn.dropdown'); 169 $('html, body').off('.fndtn.dropdown'); 170 $(window).off('.fndtn.dropdown'); 171 $('[data-dropdown-content]').off('.fndtn.dropdown'); 172 this.settings.init = false;
173 }, 174 175 reflow : function () {} 176 }; 177}(Foundation.zj, this, this.document));
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.