5
|
1 |
/** |
|
2 |
* BWS tooltip function |
|
3 |
*/ |
|
4 |
(function($) { |
19
|
5 |
"use strict"; |
|
6 |
$( document ).ready( |
|
7 |
function() { |
|
8 |
jQuery.bwsTooltip = function( pointer_options ) { |
|
9 |
var pointer_buttons = pointer_options['buttons']; |
|
10 |
/* extend pointer options - add close button */ |
|
11 |
pointer_options = $.extend( |
|
12 |
pointer_options, |
|
13 |
{ |
|
14 |
buttons: function(event, t) { |
|
15 |
var button = ''; |
|
16 |
/* check and add dismiss-type buttons */ |
|
17 |
for ( var but in pointer_buttons ) { |
|
18 |
if ( typeof pointer_buttons[ but ]['type'] != 'undefined' && pointer_buttons[ but ]['type'] == 'dismiss' && typeof pointer_buttons[ but ]['text'] != 'undefined' && pointer_buttons[ but ]['text'] != '' ) { |
|
19 |
button += '<a style="margin:0px 5px 2px;" class="button-secondary">' + pointer_buttons[ but ]['text'] + '</a>'; |
|
20 |
} |
|
21 |
} |
|
22 |
button = jQuery( button ); |
|
23 |
button.on( |
|
24 |
'click.pointer', |
|
25 |
function () { |
|
26 |
t.element.pointer( 'close' ); |
|
27 |
} |
|
28 |
); |
|
29 |
return button; |
|
30 |
}, |
|
31 |
/* add ajax dismiss functionality */ |
|
32 |
close : $.proxy( |
|
33 |
function () { |
|
34 |
if ( pointer_options['actions']['onload'] == true ) { |
|
35 |
$.post( ajaxurl, this ); |
|
36 |
} |
|
37 |
}, |
|
38 |
{ |
|
39 |
pointer: pointer_options['tooltip_id'], |
|
40 |
action: 'dismiss-wp-pointer' |
|
41 |
} |
|
42 |
) |
|
43 |
} |
|
44 |
); |
|
45 |
/* function to display pointer */ |
|
46 |
function displayPointer( cssSelector ) { |
|
47 |
cssSelector.pointer( pointer_options ).pointer( |
|
48 |
{ |
|
49 |
pointerClass: 'wp-pointer ' + pointer_options["tooltip_id"], |
|
50 |
content: pointer_options['content'], |
|
51 |
position: { |
|
52 |
edge: pointer_options['position']['edge'], |
|
53 |
align: pointer_options['position']['align'], |
|
54 |
}, |
|
55 |
} |
|
56 |
).pointer( 'open' ); |
|
57 |
/* display buttons that are not type of dismiss */ |
|
58 |
for ( var but in pointer_buttons ) { |
|
59 |
if ( typeof pointer_buttons[ but ]['type'] != 'undefined' && pointer_buttons[ but ]['type'] != 'dismiss' && typeof pointer_buttons[ but ]['text'] != 'undefined' && pointer_buttons[ but ]['text'] != '' ) { |
|
60 |
$( '.' + pointer_options['tooltip_id'] + ' .button-secondary' ).first().before( |
|
61 |
'<a class="button-primary" style="margin-right: 5px;" ' + |
|
62 |
( ( pointer_buttons[ but ]['type'] == 'link' && typeof pointer_buttons[ but ]['link'] != 'undefined' && pointer_buttons[ but ]['link'] != '') ? 'target="_blank" href="' + pointer_buttons[ but ]['link'] + '"' : '' ) |
|
63 |
+ '>' + pointer_buttons[ but ]['text'] + '</a>' |
|
64 |
); |
|
65 |
}; |
|
66 |
} |
|
67 |
/* adjust position of pointer */ |
|
68 |
var topPos, |
|
69 |
leftPos, |
|
70 |
pointerZindex; |
|
71 |
topPos = parseInt( $( "." + pointer_options["tooltip_id"] ).css( "top" ) ) + parseInt( pointer_options['position']['pos-top'] ); |
|
72 |
leftPos = parseInt( $( "." + pointer_options["tooltip_id"] ).css( "left" ) ) + parseInt( pointer_options['position']['pos-left'] ); |
|
73 |
if ( pointer_options['position']['align'] == 'left' ) { |
|
74 |
leftPos += cssSelector.outerWidth() / 2; |
|
75 |
}; |
|
76 |
$( "." + pointer_options["tooltip_id"] ).css( { "top": topPos + "px", "left": leftPos + "px" } ); |
|
77 |
/* adjust z-index if need */ |
|
78 |
pointerZindex = parseInt( $( "." + pointer_options["tooltip_id"] ).css( "z-index" ) ); |
|
79 |
if ( pointerZindex != pointer_options['position']['zindex'] ) { |
|
80 |
$( "." + pointer_options["tooltip_id"] ).css( { "z-index": pointer_options['position']['zindex'] } ); |
5
|
81 |
} |
|
82 |
} |
19
|
83 |
|
|
84 |
/* display pointer for the first time */ |
|
85 |
if ( pointer_options['actions']['onload'] ) { |
|
86 |
if ( pointer_options['set_timeout'] > 0 ) { |
|
87 |
var settime = parseInt( pointer_options['set_timeout'] ); |
|
88 |
setTimeout( |
|
89 |
function() { |
|
90 |
displayPointer( $( pointer_options['css_selector'] ) ); |
|
91 |
}, |
|
92 |
settime |
|
93 |
); |
|
94 |
} else { |
|
95 |
displayPointer( $( pointer_options['css_selector'] ) ); |
|
96 |
} |
5
|
97 |
} |
19
|
98 |
|
|
99 |
/* display pointer when clicked on selector */ |
|
100 |
if ( pointer_options['actions']['click'] ) { |
|
101 |
$( pointer_options['css_selector'] ).click( |
|
102 |
function () { |
|
103 |
displayPointer( $( this ) ); |
|
104 |
} |
|
105 |
); |
|
106 |
} |
5
|
107 |
}; |
19
|
108 |
} |
|
109 |
) |
|
110 |
})( jQuery ); |