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 ( label.length === 0 ) { 305 label = target.closest( '.cpf-section' ).find( '.tc-section-inner-wrap .tm-section-description.tm-description' ); 306 } 307 findlabel = label.find( '.tm-tip-html' ); 308 if ( findlabel.length === 0 ) { 309 findlabel = label.find( '.checkbox-image-label,.checkbox-image-label-inline,.radio-image-label,.radio-image-label-inline' ); 310 } 311 312 if ( findlabel.length === 0 ) { 313 findlabel = label.next( '.checkbox-image-label,.checkbox-image-label-inline,.radio-image-label,.radio-image-label-inline,.tm-tip-html' ); 314 } 315 if ( findlabel.length === 0 && label.is( '.tm-description' ) ) { 316 findlabel = label; 317 } 318 label = findlabel; 319 320 findlabel = $( label ); 321 findlabelText = findlabel.find( '.tc-label-text' ); 322 if ( ! findlabelText.length ) { 323 findlabelText = findlabel; 324 } 325 326 is_hide_label = target.attr( 'data-tm-hide-label' ) === 'yes' || target.attr( 'data-tm-hide-label' ) === undefined || findlabel.is( '.tm-tip-html' ); 327 328 descHTML = ''; 329 desc = target.closest( '.tmcp-field-wrap' ); 330 desc = desc.find( '[data-tm-tooltip-html]' ); 331 if ( desc.length === 0 ) { 332 desc = target.closest( '.tmcp-field-wrap' ).find( '.tc-inline-description' ); 333 if ( desc.length > 0 ) { 334 descHTML = desc.html(); 335 } 336 } else { 337 descHTML = desc.attr( 'data-tm-tooltip-html' ); 338 } 339 340 if ( tip === undefined ) { 341 if ( is_swatch ) { 342 tip = findlabelText.html(); 343 } else if ( is_swatch_desc && descHTML !== '' ) { 344 tip = '<aside>' + descHTML + '</aside>'; 345 } else if ( is_swatch_lbl_desc && ( findlabelText.html() !== '' || descHTML !== '' ) ) { 346 tip = '<aside>' + findlabelText.html() + '</aside><aside>' + descHTML + '</aside>'; 347 } else if ( is_swatch_img && get_img_src !== '' ) { 348 tip = '<img src="' + get_img_src + '">'; 349 } else if ( is_swatch_img_lbl && ( findlabelText.html() !== '' || get_img_src !== '' ) ) { 350 tip = '<img src="' + get_img_src + '"><aside>' + findlabelText.html() + '</aside>'; 351 } else if ( is_swatch_img_desc && ( get_img_src !== '' || descHTML !== '' ) ) { 352 tip = '<img src="' + get_img_src + '"><aside>' + descHTML + '</aside>'; 353 } else if ( is_swatch_img_lbl_desc && ( findlabelText.html() !== '' || get_img_src !== '' || descHTML !== '' ) ) { 354 tip = '<img src="' + get_img_src + '"><aside>' + findlabelText.html() + '</aside><aside>' + descHTML + '</aside>'; 355 } 356 357 if ( tip !== undefined ) { 358 target.data( 'tm-tip-html', tip ); 359 if ( is_hide_label ) { 360 findlabel.find( '.tm-tooltip' ).remove(); 361 findlabelText.hide(); 362 } 363 } 364 if ( tip === undefined ) { 365 // The following two methods are here for dynamic tooltip support 366 if ( target.attr( 'data-tm-tooltip-html' ) ) { 367 tip = target.attr( 'data-tm-tooltip-html' ); 368 } else { 369 tip = target.attr( 'title' ); 370 } 371 } 372 } else { 373 target.data( 'tm-tip-html', tip ); 374 } 375 376 target.on( 'tc-tooltip-html-changed', function() { 377 if ( target.attr( 'data-tm-tooltip-html' ) ) { 378 target.show(); 379 } else { 380 target.hide(); 381 } 382 } ); 383 384 if ( target.is( 'img' ) ) { 385 target.closest( 'label' ).on( 'mouseenter tmshowtooltip', that.show.bind( that, target ) ); 386 } 387 target.on( 'mouseenter.tc tmshowtooltip.tc', that.show.bind( that, target ) ); 388 389 if ( settings.trigger ) { 390 that.show( target ); 391 } 392 } 393 } ); 394 } 395 } 396 }; 397 398 $.fn.tcToolTip = function( option ) { 399 var methodReturn; 400 var targets = $( this ); 401 var data; 402 var options; 403 var ret; 404 var hasAtLeastOneNonToolTip = targets 405 .map( function() { 406 return $( this ).data( 'tctooltip' ) || ''; 407 } ) 408 .get() 409 .some( function( value ) { 410 return value === ''; 411 } ); 412 413 if ( typeof option === 'object' ) { 414 options = option; 415 } else { 416 options = {}; 417 } 418 419 if ( hasAtLeastOneNonToolTip ) { 420 data = new ToolTip( this, options ); 421 targets.data( 'tctooltip', data ); 422 } 423 424 if ( typeof option === 'string' ) { 425 data = targets.data( 'tctooltip' ); 426 methodReturn = data[ option ].apply( data, [] ); 427 } 428 429 if ( methodReturn === undefined ) { 430 ret = targets; 431 } else { 432 ret = methodReturn; 433 } 434 435 return ret; 436 }; 437 438 $.fn.tcToolTip.defaults = { 439 fadin: 'fadein', 440 fadeout: 'fadeout', 441 speed: 1500 442 }; 443 444 $.fn.tcToolTip.instances = []; 445 446 $.fn.tcToolTip.Constructor = ToolTip; 447 448 $.tcToolTip = function( targets, options ) { 449 var data = false;
450 var hasAtLeastOneNonToolTip; 451 452 targets = targets || $( '.tm-tooltip' ); 453 hasAtLeastOneNonToolTip = targets 454 .map( function() { 455 return $( this ).data( 'tctooltip' ) || ''; 456 } ) 457 .get() 458 .some( function( value ) { 459 return value === ''; 460 } ); 461 if ( hasAtLeastOneNonToolTip ) { 462 data = new ToolTip( targets, options ); 463 targets.data( 'tctooltip', data ); 464 } 465 466 return data; 467 }; 468}( 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.