PluginProbe
Comments Extra Fields For Post,Pages and CPT / 4.4
Comments Extra Fields For Post,Pages and CPT v4.4
trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 2.2 2.3 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 5.0 5.1 5.2
wp-comment-fields / js / wpcomment-tooltip.js

wpcomment-tooltip.js in Comments Extra Fields For Post,Pages and CPT 4.4, at js/wpcomment-tooltip.js

90 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 });