1;(function ($, window, document, undefined) { 2 'use strict'; 3 4 Foundation.libs.dropdown = { 5 name : 'dropdown', 6 7 version : '5.3.3', 8 9 settings : { 10 active_class: 'open', 11 align: 'bottom', 12 is_hover: false, 13 opened: function(){}, 14 closed: function(){} 15 }, 16 17 init : function (scope, method, options) { 18 Foundation.inherit(this, 'throttle'); 19 20 this.bindings(method, options); 21 }, 22 23 events : function (scope) { 24 var self = this, 25 S = self.S; 26 27 S(this.scope) 28 .off('.dropdown') 29 .on('click.fndtn.dropdown', '[' + this.attr_name() + ']', function (e) { 30 var settings = S(this).data(self.attr_name(true) + '-init') || self.settings; 31 if (!settings.is_hover || Modernizr.touch) { 32 e.preventDefault(); 33 self.toggle($(this)); 34 } 35 }) 36 .on('mouseenter.fndtn.dropdown', '[' + this.attr_name() + '], [' + this.attr_name() + '-content]', function (e) { 37 var $this = S(this), 38 dropdown, 39 target; 40 41 clearTimeout(self.timeout); 42 43 if ($this.data(self.data_attr())) { 44 dropdown = S('#' + $this.data(self.data_attr())); 45 target = $this; 46 } else { 47 dropdown = $this; 48 target = S("[" + self.attr_name() + "='" + dropdown.attr('id') + "']"); 49 } 50 51 var settings = target.data(self.attr_name(true) + '-init') || self.settings; 52 53 if(S(e.target).data(self.data_attr()) && settings.is_hover) { 54 self.closeall.call(self); 55 } 56 57 if (settings.is_hover) self.open.apply(self, [dropdown, target]); 58 }) 59 .on('mouseleave.fndtn.dropdown', '[' + this.attr_name() + '], [' + this.attr_name() + '-content]', function (e) { 60 var $this = S(this); 61 self.timeout = setTimeout(function () { 62 if ($this.data(self.data_attr())) { 63 var settings = $this.data(self.data_attr(true) + '-init') || self.settings; 64 if (settings.is_hover) self.close.call(self, S('#' + $this.data(self.data_attr()))); 65 } else { 66 var target = S('[' + self.attr_name() + '="' + S(this).attr('id') + '"]'), 67 settings = target.data(self.attr_name(true) + '-init') || self.settings; 68 if (settings.is_hover) self.close.call(self, $this); 69 } 70 }.bind(this), 150); 71 }) 72 .on('click.fndtn.dropdown', function (e) { 73 var parent = S(e.target).closest('[' + self.attr_name() + '-content]'); 74 75 if (S(e.target).closest('[' + self.attr_name() + ']').length > 0) { 76 return; 77 } 78 if (!(S(e.target).data('revealId')) && 79 (parent.length > 0 && (S(e.target).is('[' + self.attr_name() + '-content]') || 80 $.contains(parent.first()[0], e.target)))) { 81 e.stopPropagation(); 82 return; 83 } 84 85 self.close.call(self, S('[' + self.attr_name() + '-content]')); 86 }) 87 .on('opened.fndtn.dropdown', '[' + self.attr_name() + '-content]', function () { 88 self.settings.opened.call(this); 89 }) 90 .on('closed.fndtn.dropdown', '[' + self.attr_name() + '-content]', function () { 91 self.settings.closed.call(this); 92 }); 93 94 S(window) 95 .off('.dropdown') 96 .on('resize.fndtn.dropdown', self.throttle(function () { 97 self.resize.call(self); 98 }, 50)); 99 100 this.resize(); 101 }, 102 103 close: function (dropdown) { 104 var self = this; 105 dropdown.each(function () { 106 if (self.S(this).hasClass(self.settings.active_class)) { 107 self.S(this) 108 .css(Foundation.rtl ? 'right':'left', '-99999px') 109 .removeClass(self.settings.active_class) 110 .prev('[' + self.attr_name() + ']') 111 .removeClass(self.settings.active_class) 112 .removeData('target'); 113 114 self.S(this).trigger('closed').trigger('closed.fndtn.dropdown', [dropdown]); 115 } 116 }); 117 }, 118 119 closeall: function() { 120 var self = this; 121 $.each(self.S('[' + this.attr_name() + '-content]'), function() { 122 self.close.call(self, self.S(this)) 123 }); 124 }, 125 126 open: function (dropdown, target) { 127 this 128 .css(dropdown 129 .addClass(this.settings.active_class), target); 130 dropdown.prev('[' + this.attr_name() + ']').addClass(this.settings.active_class); 131 dropdown.data('target', target.get(0)).trigger('opened').trigger('opened.fndtn.dropdown', [dropdown, target]); 132 }, 133 134 data_attr: function () { 135 if (this.namespace.length > 0) { 136 return this.namespace + '-' + this.name; 137 } 138 139 return this.name; 140 }, 141 142 toggle : function (target) { 143 var dropdown = this.S('#' + target.data(this.data_attr())); 144 if (dropdown.length === 0) {
145 // No dropdown found, not continuing 146 return; 147 } 148 149 this.close.call(this, this.S('[' + this.attr_name() + '-content]').not(dropdown)); 150 151 if (dropdown.hasClass(this.settings.active_class)) { 152 this.close.call(this, dropdown); 153 if (dropdown.data('target') !== target.get(0)) 154 this.open.call(this, dropdown, target); 155 } else { 156 this.open.call(this, dropdown, target); 157 } 158 }, 159 160 resize : function () { 161 var dropdown = this.S('[' + this.attr_name() + '-content].open'), 162 target = this.S("[" + this.attr_name() + "='" + dropdown.attr('id') + "']"); 163 164 if (dropdown.length && target.length) { 165 this.css(dropdown, target); 166 } 167 }, 168 169 css : function (dropdown, target) { 170 var left_offset = Math.max((target.width() - dropdown.width()) / 2, 8); 171 172 this.clear_idx(); 173 174 if (this.small()) { 175 var p = this.dirs.bottom.call(dropdown, target); 176 177 dropdown.attr('style', '').removeClass('drop-left drop-right drop-top').css({ 178 position : 'absolute', 179 width: '95%', 180 'max-width': 'none', 181 top: p.top 182 }); 183 184 dropdown.css(Foundation.rtl ? 'right':'left', left_offset); 185 } else { 186 var settings = target.data(this.attr_name(true) + '-init') || this.settings; 187 188 this.style(dropdown, target, settings); 189 } 190 191 return dropdown; 192 }, 193 194 style : function (dropdown, target, settings) { 195 var css = $.extend({position: 'absolute'}, 196 this.dirs[settings.align].call(dropdown, target, settings)); 197 198 dropdown.attr('style', '').css(css); 199 }, 200 201 // return CSS property object 202 // `this` is the dropdown 203 dirs : { 204 // Calculate target offset 205 _base : function (t) { 206 var o_p = this.offsetParent(), 207 o = o_p.offset(), 208 p = t.offset(); 209 210 p.top -= o.top; 211 p.left -= o.left; 212 213 return p; 214 }, 215 top: function (t, s) { 216 var self = Foundation.libs.dropdown, 217 p = self.dirs._base.call(this, t), 218 pip_offset_base = 8; 219 220 this.addClass('drop-top'); 221 222 if (t.outerWidth() < this.outerWidth() || self.small()) { 223 self.adjust_pip(pip_offset_base, p); 224 } 225 226 if (Foundation.rtl) { 227 return {left: p.left - this.outerWidth() + t.outerWidth(), 228 top: p.top - this.outerHeight()}; 229 } 230 231 return {left: p.left, top: p.top - this.outerHeight()}; 232 }, 233 bottom: function (t, s) { 234 var self = Foundation.libs.dropdown, 235 p = self.dirs._base.call(this, t), 236 pip_offset_base = 8; 237 238 if (t.outerWidth() < this.outerWidth() || self.small()) { 239 self.adjust_pip(pip_offset_base, p); 240 } 241 242 if (self.rtl) { 243 return {left: p.left - this.outerWidth() + t.outerWidth(), top: p.top + t.outerHeight()}; 244 } 245 246 return {left: p.left, top: p.top + t.outerHeight()}; 247 }, 248 left: function (t, s) { 249 var p = Foundation.libs.dropdown.dirs._base.call(this, t); 250 251 this.addClass('drop-left'); 252 253 return {left: p.left - this.outerWidth(), top: p.top}; 254 }, 255 right: function (t, s) { 256 var p = Foundation.libs.dropdown.dirs._base.call(this, t); 257 258 this.addClass('drop-right'); 259 260 return {left: p.left + t.outerWidth(), top: p.top}; 261 } 262 }, 263 264 // Insert rule to style psuedo elements 265 adjust_pip : function (pip_offset_base, p) { 266 var sheet = Foundation.stylesheet; 267 268 if (this.small()) { 269 pip_offset_base += p.left - 8; 270 } 271 272 this.rule_idx = sheet.cssRules.length; 273 274 var sel_before = '.f-dropdown.open:before', 275 sel_after = '.f-dropdown.open:after', 276 css_before = 'left: ' + pip_offset_base + 'px;', 277 css_after = 'left: ' + (pip_offset_base - 1) + 'px;'; 278 279 if (sheet.insertRule) { 280 sheet.insertRule([sel_before, '{', css_before, '}'].join(' '), this.rule_idx); 281 sheet.insertRule([sel_after, '{', css_after, '}'].join(' '), this.rule_idx + 1); 282 } else { 283 sheet.addRule(sel_before, css_before, this.rule_idx); 284 sheet.addRule(sel_after, css_after, this.rule_idx + 1); 285 } 286 }, 287 288 // Remove old dropdown rule index 289 clear_idx : function () { 290 var sheet = Foundation.stylesheet; 291 292 if (this.rule_idx) { 293 sheet.deleteRule(this.rule_idx); 294 sheet.deleteRule(this.rule_idx); 295 delete this.rule_idx; 296 } 297 }, 298 299 small : function () { 300 return true; 301 }, 302 303 off: function () { 304 this.S(this.scope).off('.fndtn.dropdown'); 305 this.S('html, body').off('.fndtn.dropdown'); 306 this.S(window).off('.fndtn.dropdown'); 307 this.S('[data-dropdown-content]').off('.fndtn.dropdown'); 308 }, 309 310 reflow : function () {} 311 }; 312}(jQuery, window, window.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.