1/** 2 * jQuery Once Plugin 1.2.6 3 * http://github.com/robloach/jquery-once 4 * 5 * Dual licensed under the MIT and GPL licenses: 6 * http://www.opensource.org/licenses/mit-license.php 7 * http://www.gnu.org/licenses/gpl.html 8 * 9 * This library changed its function signature in its 2.x branch. This is a 10 * forked version that is jQuery 3.x compatible. 11 * 12 * See https://github.com/backdrop/backdrop-issues/issues/6195 13 */ 14 15(function (factory) { 16 "use strict"; 17 if (typeof exports === 'object') { 18 factory(require('jquery')); 19 } else if (typeof define === 'function' && define.amd) { 20 define(['jquery'], factory); 21 } else { 22 factory(jQuery); 23 } 24}(function ($) { 25 "use strict"; 26 var cache = {}, uuid = 0; 27 28 /** 29 * Filters elements by whether they have not yet been processed. 30 * 31 * @param id 32 * (Optional) If this is a string, then it will be used as the CSS class 33 * name that is applied to the elements for determining whether it has 34 * already been processed. The elements will get a class in the form of 35 * "id-processed". 36 * 37 * If the id parameter is a function, it will be passed off to the fn 38 * parameter and the id will become a unique identifier, represented as a 39 * number. 40 * 41 * When the id is neither a string or a function, it becomes a unique 42 * identifier, depicted as a number. The element's class will then be 43 * represented in the form of "jquery-once-#-processed". 44 * 45 * Take note that the id must be valid for usage as an element's class name. 46 * @param fn 47 * (Optional) If given, this function will be called for each element that 48 * has not yet been processed. The function's return value follows the same 49 * logic as $.each(). Returning true will continue to the next matched 50 * element in the set, while returning false will entirely break the 51 * iteration. 52 * 53 * @api public 54 */ 55 $.fn.once = function (id, fn) { 56 if (typeof id !== 'string') { 57 // Generate a numeric ID if the id passed can't be used as a CSS class. 58 if (!(id in cache)) { 59 cache[id] = ++uuid; 60 } 61 // When the fn parameter is not passed, we interpret it from the id. 62 if (!fn) { 63 fn = id; 64 } 65 id = 'jquery-once-' + cache[id]; 66 } 67 // Remove elements from the set that have already been processed. 68 var name = id + '-processed'; 69 var elements = this.not('.' + name).addClass(name); 70 71 return typeof fn == 'function' ? elements.each(fn) : elements; 72 }; 73 74 /** 75 * Filters elements that have been processed once already. 76 * 77 * @param id 78 * A required string representing the name of the class which should be used 79 * when filtering the elements. This only filters elements that have already 80 * been processed by the once function. The id should be the same id that 81 * was originally passed to the once() function. 82 * @param fn 83 * (Optional) If given, this function will be called for each element that 84 * has not yet been processed. The function's return value follows the same 85 * logic as $.each(). Returning true will continue to the next matched 86 * element in the set, while returning false will entirely break the 87 * iteration. 88 * 89 * @api public 90 */ 91 $.fn.removeOnce = function (id, fn) { 92 var name = id + '-processed'; 93 var elements = this.filter('.' + name).removeClass(name); 94 95 return typeof fn == 'function' ? elements.each(fn) : elements; 96 }; 97}));
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.