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