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