1/** 2 * jquery.tctooltip.js 3 * 4 * @version: v1.1 5 * @author: themeComplete 6 * 7 * Created by themeComplete 8 * 9 * Copyright (c) 2021 themeComplete http://themecomplete.com 10 */ 11( function( window, $ ) { 12 'use strict'; 13 14 var ToolTip = function( dom, options ) { 15 this.targets = $( dom ); 16 17 this.settings = $.extend( {}, $.fn.tcToolTip.defaults, options ); 18 19 if ( this.targets.length > 0 ) { 20 this.init(); 21 return this; 22 } 23 24 return false; 25 }; 26 27 var TMEPOJS; 28 29 // document ready 30 $( function() { 31 TMEPOJS = window.TMEPOJS || { tm_epo_global_tooltip_max_width: '340px' }; 32 } ); 33 34 ToolTip.prototype = { 35 constructor: ToolTip, 36 37 removeTooltip: function( target, tooltip ) { 38 var settings = this.settings; 39 40 if ( target.data( 'is_moving' ) ) { 41 return; 42 } 43 44 tooltip.removeClass( settings.fadin ).addClass( settings.fadeout ); 45 46 tooltip.animate( 47 { 48 opacity: 0 49 }, 50 settings.speed, 51 function() { 52 $( this ).remove(); 53 } 54 ); 55 56 if ( target.data( 'tmtip-title' ) && target.data( 'tm-tip-html' ) === undefined && ! target.attr( 'data-tm-tooltip-html' ) ) { 57 target.attr( 'title', target.data( 'tmtip-title' ) ); 58 } 59 60 $( window ).off( 'scroll.tcToolTip resize.tcToolTip' ); 61 62 if ( settings.onetime ) { 63 this.destroy(); 64 } 65 }, 66 67 initTooltip: function( target, tooltip, nofx ) { 68 var settings = this.settings; 69 var tip; 70 var scroll; 71 var pos_left; 72 var pos_top; 73 var pos_from_top; 74 var original_pos_left; 75 76 if ( target && tooltip && target.length === 1 && tooltip.length === 1 && target.data( 'tm-has-tm-tip' ) === 1 ) { 77 if ( nofx === 1 ) { 78 if ( target.data( 'tm-tip-html' ) !== undefined ) { 79 tip = target.data( 'tm-tip-html' ); 80 } else if ( target.attr( 'data-tm-tooltip-html' ) ) { 81 tip = target.attr( 'data-tm-tooltip-html' ); 82 } else { 83 tip = target.attr( 'title' ); 84 } 85 86 tooltip.html( tip ); 87 target.data( 'is_moving', true ); 88 } 89 90 tooltip.find( 'aside' ).hide(); 91 92 if ( TMEPOJS.tm_epo_global_tooltip_max_width === '' ) { 93 // 50: average scrollbar width. Needed to avoid flickering width issues on mobile. 94 if ( $( window ).width() <= tooltip.outerWidth() * 1.2 ) { 95 tooltip.css( 'max-width', ( $( window ).width() / 1.2 ) + 'px' ); 96 } else { 97 tooltip.css( 'max-width', '340px' ); 98 } 99 } else { 100 if ( TMEPOJS.tm_epo_global_tooltip_max_width.isNumeric() ) { 101 TMEPOJS.tm_epo_global_tooltip_max_width = TMEPOJS.tm_epo_global_tooltip_max_width + 'px'; 102 } 103 tooltip.css( 'max-width', TMEPOJS.tm_epo_global_tooltip_max_width ); 104 } 105 106 tooltip.find( 'aside' ).show(); 107 108 tooltip.css( { 109 left: '', 110 right: '', 111 top: '' 112 } ); 113 114 scroll = $.epoAPI.dom.scroll(); 115 pos_left = target.offset().left + ( target.outerWidth() / 2 ) - ( tooltip.outerWidth() / 2 ); 116 original_pos_left = pos_left; 117 118 if ( pos_left < 0 ) { 119 pos_left = target.offset().left + ( target.outerWidth() / 2 ) - 20; 120 tooltip.addClass( 'left' ); 121 } else { 122 tooltip.removeClass( 'left' ); 123 } 124 if ( original_pos_left >= 0 && pos_left + tooltip.outerWidth() > $( window ).width() ) { 125 pos_left = target.offset().left - tooltip.outerWidth() + ( target.outerWidth() / 2 ) + 20; 126 if ( pos_left < 0 ) { 127 pos_left = pos_left - 10; 128 tooltip.css( 'max-width', 'calc(' + tooltip.css( 'max-width' ) + ' - ' + Math.abs( pos_left ) + 'px)' ); 129 pos_left = 10; 130 } 131 tooltip.addClass( 'right' ); 132 } else { 133 tooltip.removeClass( 'right' ); 134 } 135 136 tooltip.css( { 137 left: pos_left, 138 right: 'auto', 139 top: pos_top 140 } ); 141 pos_top = target.offset().top - tooltip.outerHeight() - 10; 142 pos_from_top = target.offset().top - scroll.top - tooltip.outerHeight() - 10; 143 144 if ( pos_top < 0 || pos_from_top < 0 ) { 145 pos_top = target.offset().top + target.outerHeight() + 10; 146 tooltip.addClass( 'top' ); 147 tooltip.removeClass( 'bottom' ); 148 } else { 149 tooltip.removeClass( 'top' ); 150 tooltip.addClass( 'bottom' ); 151 } 152 153 $( window ).trigger( 'tm_tooltip_show' ); 154 155 if ( nofx ) { 156 tooltip.css( { 157 left: pos_left, 158 top: pos_top 159 } ); 160 target.data( 'is_moving', false ); 161 } else { 162 tooltip 163 .css( { 164 left: pos_left, 165 top: pos_top 166 } ) 167 .removeClass( settings.fadeout ) 168 .addClass( settings.fadin ); 169 } 170 } 171 }, 172 173 show: function( target ) { 174 var tooltip; 175 var tip; 176 var img; 177 var settings = this.settings; 178 179 if ( target.data( 'is_moving' ) ) { 180 return; 181 } 182 183 if ( target.data( 'tm-has-tm-tip' ) === 1 ) { 184 if ( target.data( 'tm-tip-html' ) !== undefined ) { 185 tip = target.data( 'tm-tip-html' ); 186 if ( target.attr( 'title' ) ) { 187 target.data( 'tmtip-title', target.attr( 'title' ) ); 188 } 189 target.removeAttr( 'title' ); 190 } else if ( target.attr( 'data-tm-tooltip-html' ) ) { 191 tip = target.attr( 'data-tm-tooltip-html' ); 192 if ( target.attr( 'title' ) ) { 193 target.data( 'tmtip-title', target.attr( 'title' ) ); 194 } 195 target.removeAttr( 'title' ); 196 } else { 197 tip = target.attr( 'title' ); 198 } 199 200 if ( tip !== undefined ) { 201 $( '#tm-tooltip' ).remove(); 202 if ( ! settings.tipclass ) { 203 settings.tipclass = ''; 204 } else { 205 settings.tipclass = ' ' + settings.tipclass; 206 } 207 tooltip = $( '<div id="tm-tooltip" class="tm-tip tm-animated' + settings.tipclass + '"></div>' ); 208 tooltip.css( 'opacity', 0 ).html( tip ).appendTo( 'body' ); 209 210 img = tooltip.find( 'img' ); 211 if ( img.length > 0 ) { 212 img.on( 'load', this.initTooltip.bind( this, target, tooltip ) ); 213 } 214 215 this.initTooltip( target, tooltip ); 216 217 $( window ).on( 'scroll.tcToolTip resize.tcToolTip', this.initTooltip.bind( this, target, tooltip ) ); 218 219 target.data( 'is_moving', false ); 220 221 target.on( 'tmmovetooltip', this.initTooltip.bind( this, target, tooltip, 1 ) ); 222 target.on( 'mouseleave.tc tmhidetooltip', this.removeTooltip.bind( this, target, tooltip ) ); 223 224 target.closest( 'label' ).on( 'mouseleave.tc tmhidetooltip', this.removeTooltip.bind( this, target, tooltip ) ); 225 226 tooltip.on( 'click', this.removeTooltip.bind( this, target, tooltip ) ); 227 } 228 } 229 230 return false;
231 }, 232 233 destroy: function() { 234 if ( this.targets.length > 0 ) { 235 this.targets.toArray().forEach( function( element ) { 236 var target = $( element ); 237 target.closest( 'off' ).on( 'mouseleave.tc tmhidetooltip' ); 238 target.off( 'tc-tooltip-html-changed tmmovetooltip tmhidetooltip mouseenter.tc mouseleave.tc tmshowtooltip.tc' ); 239 target.removeData( 'tmtip-title' ); 240 target.removeData( 'tm-tip-html' ); 241 } ); 242 this.targets.removeData( 'tctooltip tm-has-tm-tip is_moving' ); 243 } 244 }, 245 246 init: function() { 247 var that = this; 248 var settings = this.settings; 249 250 if ( this.targets.length > 0 ) { 251 this.targets.toArray().forEach( function( element ) { 252 var target; 253 var is_swatch; 254 var is_swatch_desc; 255 var is_swatch_lbl_desc; 256 var is_swatch_img; 257 var is_swatch_img_lbl; 258 var is_swatch_img_desc; 259 var is_swatch_img_lbl_desc; 260 var tip; 261 var label; 262 var desc; 263 var descHTML; 264 var get_img_src; 265 var findlabel; 266 var is_hide_label; 267 268 target = $( element ); 269 tip = settings.tip || undefined; 270 271 if ( target.data( 'tm-has-tm-tip' ) === undefined ) { 272 is_swatch = target.attr( 'data-tm-tooltip-swatch' ); 273 is_swatch_desc = target.attr( 'data-tm-tooltip-swatch-desc' ); 274 is_swatch_lbl_desc = target.attr( 'data-tm-tooltip-swatch-lbl-desc' ); 275 is_swatch_img = target.attr( 'data-tm-tooltip-swatch-img' ); 276 is_swatch_img_lbl = target.attr( 'data-tm-tooltip-swatch-img-lbl' ); 277 is_swatch_img_desc = target.attr( 'data-tm-tooltip-swatch-img-desc' ); 278 is_swatch_img_lbl_desc = target.attr( 'data-tm-tooltip-swatch-img-lbl-desc' ); 279 280 target.data( 'tm-has-tm-tip', 1 ); 281 282 if ( target.attr( 'data-original' ) !== undefined ) { 283 get_img_src = target.attr( 'data-original' ); 284 } else if ( target.attr( 'src' ) !== undefined ) { 285 if ( target.attr( 'data-src' ) !== undefined ) { 286 get_img_src = target.attr( 'data-src' ); 287 } else { 288 get_img_src = target.attr( 'src' ); 289 } 290 } else { 291 get_img_src = target[ 0 ].src; 292 } 293 294 label = target.closest( '.tmcp-field-wrap' ); 295 if ( label.is( '.tc-epo-element-product-holder' ) ) { 296 label = target.closest( '.cpf-element' ); 297 } 298 if ( label.length === 0 ) { 299 label = target.closest( '.cpf-element' ); 300 } 301 if ( label.length === 0 ) { 302 label = target.closest( '.cpf-section' ).find( '.tc-section-inner-wrap .tm-section-description.tm-description' ); 303 } 304 findlabel = label.find( '.tm-tip-html' ); 305 if ( findlabel.length === 0 ) { 306 findlabel = label.find( '.checkbox-image-label,.checkbox-image-label-inline,.radio-image-label,.radio-image-label-inline' ); 307 } 308 309 if ( findlabel.length === 0 ) { 310 findlabel = label.next( '.checkbox-image-label,.checkbox-image-label-inline,.radio-image-label,.radio-image-label-inline,.tm-tip-html' ); 311 } 312 if ( findlabel.length === 0 && label.is( '.tm-description' ) ) { 313 findlabel = label; 314 } 315 label = findlabel; 316 317 findlabel = $( label ); 318 319 is_hide_label = target.attr( 'data-tm-hide-label' ) === 'yes' || target.attr( 'data-tm-hide-label' ) === undefined || findlabel.is( '.tm-tip-html' ); 320 321 descHTML = ''; 322 desc = target.closest( '.tmcp-field-wrap' ); 323 desc = desc.find( '[data-tm-tooltip-html]' ); 324 if ( desc.length === 0 ) { 325 desc = target.closest( '.tmcp-field-wrap' ).find( '.tc-inline-description' ); 326 if ( desc.length > 0 ) { 327 descHTML = desc.html(); 328 } 329 } else { 330 descHTML = desc.attr( 'data-tm-tooltip-html' ); 331 } 332 333 if ( tip === undefined ) { 334 if ( is_swatch ) { 335 tip = findlabel.html(); 336 } else if ( is_swatch_desc ) { 337 tip = '<aside>' + descHTML + '</aside>'; 338 } else if ( is_swatch_lbl_desc ) { 339 tip = '<aside>' + findlabel.html() + '</aside><aside>' + descHTML + '</aside>'; 340 } else if ( is_swatch_img ) { 341 tip = '<img src="' + get_img_src + '">'; 342 } else if ( is_swatch_img_lbl ) { 343 tip = '<img src="' + get_img_src + '"><aside>' + findlabel.html() + '</aside>'; 344 } else if ( is_swatch_img_desc ) { 345 tip = '<img src="' + get_img_src + '"><aside>' + descHTML + '</aside>'; 346 } else if ( is_swatch_img_lbl_desc ) { 347 tip = '<img src="' + get_img_src + '"><aside>' + findlabel.html() + '</aside><aside>' + descHTML + '</aside>'; 348 } 349 350 if ( tip !== undefined ) { 351 target.data( 'tm-tip-html', tip ); 352 if ( is_hide_label ) { 353 findlabel.hide(); 354 } 355 } 356 357 // The following two methods are here for dynamic tooltip support 358 if ( target.attr( 'data-tm-tooltip-html' ) ) { 359 tip = target.attr( 'data-tm-tooltip-html' ); 360 } else { 361 tip = target.attr( 'title' ); 362 } 363 } else { 364 target.data( 'tm-tip-html', tip ); 365 } 366 367 target.on( 'tc-tooltip-html-changed', function() { 368 if ( target.attr( 'data-tm-tooltip-html' ) ) { 369 target.show(); 370 } else { 371 target.hide(); 372 } 373 } ); 374 375 target.closest( 'label' ).on( 'mouseenter tmshowtooltip', that.show.bind( that, target ) ); 376 target.on( 'mouseenter.tc tmshowtooltip.tc', that.show.bind( that, target ) ); 377 378 if ( settings.trigger ) { 379 that.show( target ); 380 } 381 } 382 } ); 383 } 384 } 385 }; 386 387 $.fn.tcToolTip = function( option ) { 388 var methodReturn; 389 var targets = $( this ); 390 var data; 391 var options; 392 var ret; 393 var hasAtLeastOneNonToolTip = targets 394 .map( function() { 395 return $( this ).data( 'tctooltip' ) || ''; 396 } ) 397 .get() 398 .some( function( value ) { 399 return value === ''; 400 } ); 401 402 if ( typeof option === 'object' ) { 403 options = option; 404 } else { 405 options = {}; 406 } 407 408 if ( hasAtLeastOneNonToolTip ) { 409 data = new ToolTip( this, options ); 410 targets.data( 'tctooltip', data ); 411 } 412 413 if ( typeof option === 'string' ) { 414 data = targets.data( 'tctooltip' ); 415 methodReturn = data[ option ].apply( data, [] ); 416 } 417 418 if ( methodReturn === undefined ) { 419 ret = targets; 420 } else { 421 ret = methodReturn; 422 } 423 424 return ret; 425 }; 426 427 $.fn.tcToolTip.defaults = { 428 fadin: 'fadein', 429 fadeout: 'fadeout', 430 speed: 1500 431 }; 432 433 $.fn.tcToolTip.instances = []; 434 435 $.fn.tcToolTip.Constructor = ToolTip; 436 437 $.tcToolTip = function( targets, options ) { 438 var data = false;
439 var hasAtLeastOneNonToolTip; 440 441 targets = targets || $( '.tm-tooltip' ); 442 hasAtLeastOneNonToolTip = targets 443 .map( function() { 444 return $( this ).data( 'tctooltip' ) || ''; 445 } ) 446 .get() 447 .some( function( value ) { 448 return value === ''; 449 } ); 450 if ( hasAtLeastOneNonToolTip ) { 451 data = new ToolTip( targets, options ); 452 targets.data( 'tctooltip', data ); 453 } 454 455 return data; 456 }; 457}( window, window.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.