| 1 |
"use strict"; |
| 2 |
jQuery(function($){ |
| 3 |
|
| 4 |
/******************************************* |
| 5 |
* PPOM Fields Desciption Tooltip JS Code * |
| 6 |
********************************************/ |
| 7 |
|
| 8 |
var target, tooltip, title, tip; |
| 9 |
var targets = $( '[data-wpcomment-tooltip~=wpcomment_tooltip]' ), |
| 10 |
target = false, |
| 11 |
tooltip = false, |
| 12 |
title = false; |
| 13 |
|
| 14 |
$(document).on('mouseenter', '[data-wpcomment-tooltip~=wpcomment_tooltip]', function(){ |
| 15 |
|
| 16 |
// for iphone double click issue |
| 17 |
if(navigator.userAgent.match(/(iPod|iPhone|iPad)/)){ |
| 18 |
$(this).trigger('click'); |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
target = $( this ); |
| 23 |
tip = target.attr( 'title' ); |
| 24 |
tooltip = $( '<div id="wpcomment_tooltip"></div>' ); |
| 25 |
|
| 26 |
if( !tip || tip == '' ) |
| 27 |
return false; |
| 28 |
|
| 29 |
target.removeAttr( 'title' ); |
| 30 |
tooltip.css( 'opacity', 0 ) |
| 31 |
.html( tip ) |
| 32 |
.appendTo( 'body' ); |
| 33 |
|
| 34 |
var init_tooltip = function() |
| 35 |
{ |
| 36 |
if( $( window ).width() < tooltip.outerWidth() * 1.5 ) |
| 37 |
tooltip.css( 'max-width', $( window ).width() / 2 ); |
| 38 |
else |
| 39 |
tooltip.css( 'max-width', 340 ); |
| 40 |
|
| 41 |
var pos_left = target.offset().left + ( target.outerWidth() / 2 ) - ( tooltip.outerWidth() / 2 ), |
| 42 |
pos_top = target.offset().top - tooltip.outerHeight() - 20; |
| 43 |
|
| 44 |
if( pos_left < 0 ) |
| 45 |
{ |
| 46 |
pos_left = target.offset().left + target.outerWidth() / 2 - 20; |
| 47 |
tooltip.addClass( 'left' ); |
| 48 |
} |
| 49 |
else |
| 50 |
tooltip.removeClass( 'left' ); |
| 51 |
|
| 52 |
if( pos_left + tooltip.outerWidth() > $( window ).width() ) |
| 53 |
{ |
| 54 |
pos_left = target.offset().left - tooltip.outerWidth() + target.outerWidth() / 2 + 20; |
| 55 |
tooltip.addClass( 'right' ); |
| 56 |
} |
| 57 |
else |
| 58 |
tooltip.removeClass( 'right' ); |
| 59 |
|
| 60 |
if( pos_top < 0 ) |
| 61 |
{ |
| 62 |
var pos_top = target.offset().top + target.outerHeight(); |
| 63 |
tooltip.addClass( 'top' ); |
| 64 |
} |
| 65 |
else |
| 66 |
tooltip.removeClass( 'top' ); |
| 67 |
|
| 68 |
tooltip.css( { left: pos_left, top: pos_top } ) |
| 69 |
.animate( { top: '+=10', opacity: 1 }, 50 ); |
| 70 |
}; |
| 71 |
|
| 72 |
init_tooltip(); |
| 73 |
$( window ).resize( init_tooltip ); |
| 74 |
|
| 75 |
var remove_tooltip = function() |
| 76 |
{ |
| 77 |
tooltip.animate( { top: '-=10', opacity: 0 }, 50, function() |
| 78 |
{ |
| 79 |
$( this ).remove(); |
| 80 |
}); |
| 81 |
|
| 82 |
target.attr( 'title', tip ); |
| 83 |
}; |
| 84 |
|
| 85 |
target.bind( 'mouseleave', remove_tooltip ); |
| 86 |
tooltip.bind( 'click touchmove', remove_tooltip ); |
| 87 |
$('body').bind( 'touchmove', remove_tooltip ); |
| 88 |
}); |
| 89 |
|
| 90 |
}); |