1'use strict'; 2 3var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; 4 5!function ($) { 6 7 "use strict"; 8 9 var FOUNDATION_VERSION = '6.3.0'; 10 11 // Global Foundation object 12 // This is attached to the window, or used as a module for AMD/Browserify 13 var Foundation = { 14 version: FOUNDATION_VERSION, 15 16 /** 17 * Stores initialized plugins. 18 */ 19 _plugins: {}, 20 21 /** 22 * Stores generated unique ids for plugin instances 23 */ 24 _uuids: [], 25 26 /** 27 * Returns a boolean for RTL support 28 */ 29 rtl: function rtl() { 30 return $('html').attr('dir') === 'rtl'; 31 }, 32 /** 33 * Defines a Foundation plugin, adding it to the `Foundation` namespace and the list of plugins to initialize when reflowing. 34 * @param {Object} plugin - The constructor of the plugin. 35 */ 36 plugin: function plugin(_plugin, name) { 37 // Object key to use when adding to global Foundation object 38 // Examples: Foundation.Reveal, Foundation.OffCanvas 39 var className = name || functionName(_plugin); 40 // Object key to use when storing the plugin, also used to create the identifying data attribute for the plugin 41 // Examples: data-reveal, data-off-canvas 42 var attrName = hyphenate(className); 43 44 // Add to the Foundation object and the plugins list (for reflowing) 45 this._plugins[attrName] = this[className] = _plugin; 46 }, 47 /** 48 * @function 49 * Populates the _uuids array with pointers to each individual plugin instance. 50 * Adds the `zfPlugin` data-attribute to programmatically created plugins to allow use of $(selector).foundation(method) calls. 51 * Also fires the initialization event for each plugin, consolidating repetitive code. 52 * @param {Object} plugin - an instance of a plugin, usually `this` in context. 53 * @param {String} name - the name of the plugin, passed as a camelCased string. 54 * @fires Plugin#init 55 */ 56 registerPlugin: function registerPlugin(plugin, name) { 57 var pluginName = name ? hyphenate(name) : functionName(plugin.constructor).toLowerCase(); 58 plugin.uuid = this.GetYoDigits(6, pluginName); 59 60 if (!plugin.$element.attr('data-' + pluginName)) { 61 plugin.$element.attr('data-' + pluginName, plugin.uuid); 62 } 63 if (!plugin.$element.data('zfPlugin')) { 64 plugin.$element.data('zfPlugin', plugin); 65 } 66 /** 67 * Fires when the plugin has initialized. 68 * @event Plugin#init 69 */ 70 plugin.$element.trigger('init.zf.' + pluginName); 71 72 this._uuids.push(plugin.uuid); 73 74 return; 75 }, 76 /** 77 * @function 78 * Removes the plugins uuid from the _uuids array. 79 * Removes the zfPlugin data attribute, as well as the data-plugin-name attribute. 80 * Also fires the destroyed event for the plugin, consolidating repetitive code. 81 * @param {Object} plugin - an instance of a plugin, usually `this` in context. 82 * @fires Plugin#destroyed 83 */ 84 unregisterPlugin: function unregisterPlugin(plugin) { 85 var pluginName = hyphenate(functionName(plugin.$element.data('zfPlugin').constructor)); 86 87 this._uuids.splice(this._uuids.indexOf(plugin.uuid), 1); 88 plugin.$element.removeAttr('data-' + pluginName).removeData('zfPlugin') 89 /** 90 * Fires when the plugin has been destroyed. 91 * @event Plugin#destroyed 92 */ 93 .trigger('destroyed.zf.' + pluginName); 94 for (var prop in plugin) { 95 plugin[prop] = null; //clean up script to prep for garbage collection. 96 } 97 return; 98 }, 99 100 /** 101 * @function 102 * Causes one or more active plugins to re-initialize, resetting event listeners, recalculating positions, etc. 103 * @param {String} plugins - optional string of an individual plugin key, attained by calling `$(element).data('pluginName')`, or string of a plugin class i.e. `'dropdown'` 104 * @default If no argument is passed, reflow all currently active plugins. 105 */ 106 reInit: function reInit(plugins) { 107 var isJQ = plugins instanceof $;
108 try { 109 if (isJQ) { 110 plugins.each(function () { 111 $(this).data('zfPlugin')._init(); 112 }); 113 } else { 114 var type = typeof plugins === 'undefined' ? 'undefined' : _typeof(plugins), 115 _this = this, 116 fns = { 117 'object': function object(plgs) { 118 plgs.forEach(function (p) { 119 p = hyphenate(p); 120 $('[data-' + p + ']').foundation('_init'); 121 }); 122 }, 123 'string': function string() { 124 plugins = hyphenate(plugins); 125 $('[data-' + plugins + ']').foundation('_init'); 126 }, 127 'undefined': function undefined() { 128 this['object'](Object.keys(_this._plugins)); 129 } 130 }; 131 fns[type](plugins); 132 } 133 } catch (err) { 134 console.error(err); 135 } finally { 136 return plugins; 137 } 138 }, 139 140 /** 141 * returns a random base-36 uid with namespacing 142 * @function 143 * @param {Number} length - number of random base-36 digits desired. Increase for more random strings. 144 * @param {String} namespace - name of plugin to be incorporated in uid, optional. 145 * @default {String} '' - if no plugin name is provided, nothing is appended to the uid. 146 * @returns {String} - unique id 147 */ 148 GetYoDigits: function GetYoDigits(length, namespace) { 149 length = length || 6; 150 return Math.round(Math.pow(36, length + 1) - Math.random() * Math.pow(36, length)).toString(36).slice(1) + (namespace ? '-' + namespace : ''); 151 }, 152 /** 153 * Initialize plugins on any elements within `elem` (and `elem` itself) that aren't already initialized. 154 * @param {Object} elem - jQuery object containing the element to check inside. Also checks the element itself, unless it's the `document` object. 155 * @param {String|Array} plugins - A list of plugins to initialize. Leave this out to initialize everything. 156 */ 157 reflow: function reflow(elem, plugins) { 158 159 // If plugins is undefined, just grab everything 160 if (typeof plugins === 'undefined') { 161 plugins = Object.keys(this._plugins); 162 } 163 // If plugins is a string, convert it to an array with one item 164 else if (typeof plugins === 'string') { 165 plugins = [plugins]; 166 } 167 168 var _this = this; 169 170 // Iterate through each plugin 171 $.each(plugins, function (i, name) { 172 // Get the current plugin 173 var plugin = _this._plugins[name]; 174 175 // Localize the search to all elements inside elem, as well as elem itself, unless elem === document 176 var $elem = $(elem).find('[data-' + name + ']').addBack('[data-' + name + ']'); 177 178 // For each plugin found, initialize it 179 $elem.each(function () { 180 var $el = $(this), 181 opts = {}; 182 // Don't double-dip on plugins 183 if ($el.data('zfPlugin')) { 184 console.warn("Tried to initialize " + name + " on an element that already has a Foundation plugin."); 185 return; 186 } 187 188 if ($el.attr('data-options')) { 189 var thing = $el.attr('data-options').split(';').forEach(function (e, i) { 190 var opt = e.split(':').map(function (el) { 191 return el.trim(); 192 }); 193 if (opt[0]) opts[opt[0]] = parseValue(opt[1]); 194 }); 195 } 196 try { 197 $el.data('zfPlugin', new plugin($(this), opts)); 198 } catch (er) { 199 console.error(er); 200 } finally { 201 return; 202 } 203 }); 204 }); 205 }, 206 getFnName: functionName, 207 transitionend: function transitionend($elem) { 208 var transitions = { 209 'transition': 'transitionend', 210 'WebkitTransition': 'webkitTransitionEnd', 211 'MozTransition': 'transitionend', 212 'OTransition': 'otransitionend' 213 }; 214 var elem = document.createElement('div'), 215 end; 216 217 for (var t in transitions) { 218 if (typeof elem.style[t] !== 'undefined') { 219 end = transitions[t]; 220 } 221 } 222 if (end) { 223 return end; 224 } else { 225 end = setTimeout(function () { 226 $elem.triggerHandler('transitionend', [$elem]); 227 }, 1); 228 return 'transitionend'; 229 } 230 } 231 }; 232 233 Foundation.util = { 234 /** 235 * Function for applying a debounce effect to a function call. 236 * @function 237 * @param {Function} func - Function to be called at end of timeout. 238 * @param {Number} delay - Time in ms to delay the call of `func`. 239 * @returns function 240 */ 241 throttle: function throttle(func, delay) { 242 var timer = null; 243 244 return function () { 245 var context = this, 246 args = arguments; 247 248 if (timer === null) { 249 timer = setTimeout(function () {
vendor: 5,129 bytes, lines 250-390
250 func.apply(context, args); 251 timer = null; 252 }, delay); 253 } 254 }; 255 } 256 }; 257 258 // TODO: consider not making this a jQuery function 259 // TODO: need way to reflow vs. re-initialize 260 /** 261 * The Foundation jQuery method. 262 * @param {String|Array} method - An action to perform on the current jQuery object. 263 */ 264 var foundation = function foundation(method) { 265 var type = typeof method === 'undefined' ? 'undefined' : _typeof(method), 266 $meta = $('meta.foundation-mq'), 267 $noJS = $('.no-js'); 268 269 if (!$meta.length) { 270 $('<meta class="foundation-mq">').appendTo(document.head); 271 } 272 if ($noJS.length) { 273 $noJS.removeClass('no-js'); 274 } 275 276 if (type === 'undefined') { 277 //needs to initialize the Foundation object, or an individual plugin. 278 Foundation.MediaQuery._init(); 279 Foundation.reflow(this); 280 } else if (type === 'string') { 281 //an individual method to invoke on a plugin or group of plugins 282 var args = Array.prototype.slice.call(arguments, 1); //collect all the arguments, if necessary 283 var plugClass = this.data('zfPlugin'); //determine the class of plugin 284 285 if (plugClass !== undefined && plugClass[method] !== undefined) { 286 //make sure both the class and method exist 287 if (this.length === 1) { 288 //if there's only one, call it directly. 289 plugClass[method].apply(plugClass, args); 290 } else { 291 this.each(function (i, el) { 292 //otherwise loop through the jQuery collection and invoke the method on each 293 plugClass[method].apply($(el).data('zfPlugin'), args); 294 }); 295 } 296 } else { 297 //error for no class or no method 298 throw new ReferenceError("We're sorry, '" + method + "' is not an available method for " + (plugClass ? functionName(plugClass) : 'this element') + '.'); 299 } 300 } else { 301 //error for invalid argument type 302 throw new TypeError('We\'re sorry, ' + type + ' is not a valid parameter. You must use a string representing the method you wish to invoke.'); 303 } 304 return this; 305 }; 306 307 window.Foundation = Foundation; 308 $.fn.foundation = foundation; 309 310 // Polyfill for requestAnimationFrame 311 (function () { 312 if (!Date.now || !window.Date.now) window.Date.now = Date.now = function () { 313 return new Date().getTime(); 314 }; 315 316 var vendors = ['webkit', 'moz']; 317 for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) { 318 var vp = vendors[i]; 319 window.requestAnimationFrame = window[vp + 'RequestAnimationFrame']; 320 window.cancelAnimationFrame = window[vp + 'CancelAnimationFrame'] || window[vp + 'CancelRequestAnimationFrame']; 321 } 322 if (/iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent) || !window.requestAnimationFrame || !window.cancelAnimationFrame) { 323 var lastTime = 0; 324 window.requestAnimationFrame = function (callback) { 325 var now = Date.now(); 326 var nextTime = Math.max(lastTime + 16, now); 327 return setTimeout(function () { 328 callback(lastTime = nextTime); 329 }, nextTime - now); 330 }; 331 window.cancelAnimationFrame = clearTimeout; 332 } 333 /** 334 * Polyfill for performance.now, required by rAF 335 */ 336 if (!window.performance || !window.performance.now) { 337 window.performance = { 338 start: Date.now(), 339 now: function now() { 340 return Date.now() - this.start; 341 } 342 }; 343 } 344 })(); 345 if (!Function.prototype.bind) { 346 Function.prototype.bind = function (oThis) { 347 if (typeof this !== 'function') { 348 // closest thing possible to the ECMAScript 5 349 // internal IsCallable function 350 throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); 351 } 352 353 var aArgs = Array.prototype.slice.call(arguments, 1), 354 fToBind = this, 355 fNOP = function fNOP() {}, 356 fBound = function fBound() { 357 return fToBind.apply(this instanceof fNOP ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments))); 358 }; 359 360 if (this.prototype) { 361 // native functions don't have a prototype 362 fNOP.prototype = this.prototype; 363 } 364 fBound.prototype = new fNOP(); 365 366 return fBound; 367 }; 368 } 369 // Polyfill to get the name of a function in IE9 370 function functionName(fn) { 371 if (Function.prototype.name === undefined) { 372 var funcNameRegex = /function\s([^(]{1,})\(/; 373 var results = funcNameRegex.exec(fn.toString()); 374 return results && results.length > 1 ? results[1].trim() : ""; 375 } else if (fn.prototype === undefined) { 376 return fn.constructor.name; 377 } else { 378 return fn.prototype.constructor.name; 379 } 380 } 381 function parseValue(str) { 382 if ('true' === str) return true;else if ('false' === str) return false;else if (!isNaN(str * 1)) return parseFloat(str); 383 return str; 384 } 385 // Convert PascalCase to kebab-case 386 // Thank you: http://stackoverflow.com/a/8955580 387 function hyphenate(str) { 388 return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); 389 } 390}(jQuery);
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.