var elements = []; for (var i = 0; i < self.length; i++) { elements.push(self[i]); } initTooltip(elements, arguments); }; } /** * Init plugin tooltip * * @param {Node} element - element init * @param {object} args - arguments options * @returns {array || Node || boolean} - return value init or not init */ function initTooltip(element, args) { // for using in closures // if we are not in the context of jQuery wrapped HTML element(s) : // this happens when calling element.tooltipster('methodName or options') where element matches one or more elements if (element.length > 0) { // method calls if (typeof args[0] === 'string') { var symbols = '#*$~&'; for (var i = 0; i < element.length; i++) { var currentElement = element[i]; var arrId; arrId = currentElement['tooltipster-ns']; var self = arrId && arrId[0] ? currentElement[arrId[0]] : null; if (self) { if (typeof self[args[0]] === 'function') { // note : args[1] and args[2] may not be defined var resp = self[args[0]](args[1], args[2]); } else { throw new Error('Unknown method .tooltipster("' + args[0] + '")'); } // if the function returned anything other than the instance itself (which implies chaining) if (resp !== self) { symbols = resp; // return false to stop .each iteration on the first element matched by the selector return false; } } else { throw new Error( 'You called Tooltipster\'s "' + args[0] + '" method on an uninitialized element' ); } } return symbols !== '#*$~&' ? symbols : element; } else { // first argument is undefined or an object : the tooltip is initializing var instances = []; // is there a defined value for the multiple option in the options object ? var multipleIsSet = args[0] && typeof args[0].multiple !== 'undefined'; // if the multiple option is set to true, or if it's not defined but set to true in the defaults var multiple = (multipleIsSet && args[0].multiple) || (!multipleIsSet && defaults.multiple); // same for debug var debugIsSet = args[0] && typeof args[0].debug !== 'undefined'; var debug = (debugIsSet && args[0].debug) || (!debugIsSet && defaults.debug); // initialize a tooltipster instance for each element if it doesn't already have one or if the multiple option is set, and attach the object to it for (var i = 0; i < element.length; i++) { var currentElement = element[i]; var isInitPlugin = false; var instance = null; var arrId = currentElement['tooltipster-ns']; if (!arrId) { isInitPlugin = true; } else if (multiple) { isInitPlugin = true; } else if (debug) { // Tooltipster: one or more tooltips are already attached to this element: ignoring. Use the "multiple" option to attach more tooltips. } if (isInitPlugin) { instance = new Plugin(currentElement, args[0]); // save the reference of the new instance if (!arrId) arrId = [];