// disable the plugin on old browsers (including IE7 and lower) if (document.querySelector) { // note : the content is null (empty) by default and can stay that way if the plugin remains initialized but not fed any content. The tooltip will just not appear. // let's save the initial value of the title attribute for later restoration if need be. var initialTitle = null; // it will already have been saved in case of multiple tooltips if (!self.element['tooltipster-initialTitle']) { initialTitle = self.element.getAttribute('title'); // we do not want initialTitle to have the value "undefined" because of how jQuery's .data() method works if (!initialTitle) initialTitle = null; self.element['tooltipster-initialTitle'] = initialTitle; } // if content is provided in the options, its has precedence over the title attribute. // Note : an empty string is considered content, only 'null' represents the absence of content. // Also, an existing title="" attribute will result in an empty string content if (self.options.content !== null) { self._content_set(self.options.content); } else { self._content_set(initialTitle); } var customFunction = self.options.functionInit.call(self.element, self.element, self.Content); if (typeof customFunction !== 'undefined') self._content_set(customFunction); // strip the title off of the element to prevent the default tooltips from popping up self.element.removeAttribute('title'); // to be able to find all instances on the page later (upon window events in particular) t_addClass(self.element, 'tooltipstered'); // a11y added aria-label in tooltip trigger for screen readers var tooltipText = ''; if (self.Content) { tooltipText = self.Content.replace(/(\<(\/?[^>]+)>)/g, ''); } self.element.setAttribute('aria-label', tooltipText); // detect if we're changing the tooltip origin to an icon // note about this condition : if the device has touch capability and self.options.iconTouch is false, you'll have no icons event though you may consider your device as a desktop if it also has a mouse. Not sure why someone would have this use case though. if ( (!deviceHasTouchCapability && self.options.iconDesktop) || (deviceHasTouchCapability && self.options.iconTouch) ) { // Until it's done, the icon feature does not really make sense since the user still has most of the work to do by himself // if the icon provided is in the form of a string if (typeof self.options.icon === 'string') { // wrap it in a span with the icon class self.elementProxy = document.createElement('span'); t_addClass(self.elementProxy, self.options.iconTheme); self.elementProxy.textContent = self.options.icon; } else { // if it is an object (sensible choice) // (deep) clone the object if iconCloning == true, to make sure every instance has its own proxy. We use the icon without wrapping, no need to. We do not give it a class either, as the user will undoubtedly style the object on his own and since our css properties may conflict with his own if (self.options.iconCloning) { self.elementProxy = self.options.icon.cloneNode(true); } else { self.elementProxy = self.options.icon; } } self.elementProxy.appendChild(self.element); } else { self.elementProxy = self.element; } // for 'click' and 'hover' triggers : bind on events to open the tooltip. Closing is now handled in _showNow() because of its bindings. // Notes about touch events : // - mouseenter, mouseleave and clicks happen even on pure touch devices because they are emulated. deviceIsPureTouch() is a simple attempt to detect them. // - on hybrid devices, we do not prevent touch gesture from opening tooltips. It would be too complex to differentiate real mouse events from emulated ones. // - we check deviceIsPureTouch() at each event rather than prior to binding because the situation may change during browsing if (self.options.trigger === 'hover') { // these binding are for mouse interaction only /** * Save call event mouseenter for later removal */ function elementProxyMouseEnter() { if (!deviceIsPureTouch() || self.options.touchDevices) { self.mouseIsOverProxy = true; self._show(); } } /** * Save call event mouseleave for later removal