author | ymh <ymh.work@gmail.com> |
Tue, 15 Dec 2020 13:49:49 +0100 | |
changeset 16 | a86126ab1dd4 |
parent 7 | cf61fcea0001 |
child 19 | 3d72ae0968f4 |
permissions | -rwxr-xr-x |
5 | 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 */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
10 |
pointer_options = $.extend( pointer_options, { |
5 | 11 |
buttons: function(event, t) { |
16 | 12 |
var button = ''; |
5 | 13 |
/* check and add dismiss-type buttons */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
for ( var but in pointer_buttons ) { |
5 | 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 ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
cssSelector.pointer( pointer_options ).pointer({ |
5 | 38 |
pointerClass: 'wp-pointer ' + pointer_options["tooltip_id"], |
39 |
content: pointer_options['content'], |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
position: { |
5 | 41 |
edge: pointer_options['position']['edge'], |
42 |
align: pointer_options['position']['align'], |
|
43 |
}, |
|
44 |
}).pointer('open'); |
|
45 |
/* display buttons that are not type of dismiss */ |
|
46 |
for ( var but in pointer_buttons ) { |
|
47 |
if ( typeof pointer_buttons[ but ]['type'] != 'undefined' && pointer_buttons[ but ]['type'] != 'dismiss' && typeof pointer_buttons[ but ]['text'] != 'undefined' && pointer_buttons[ but ]['text'] != '' ) { |
|
48 |
$( '.' + pointer_options['tooltip_id'] + ' .button-secondary').first().before( '<a class="button-primary" style="margin-right: 5px;" ' + |
|
49 |
( ( pointer_buttons[ but ]['type'] == 'link' && typeof pointer_buttons[ but ]['link'] != 'undefined' && pointer_buttons[ but ]['link'] != '') ? 'target="_blank" href="' + pointer_buttons[ but ]['link'] + '"' : '' ) |
|
50 |
+ '>' + pointer_buttons[ but ]['text'] + '</a>' ); |
|
51 |
}; |
|
52 |
} |
|
53 |
/* adjust position of pointer */ |
|
54 |
topPos = parseInt( $( "." + pointer_options["tooltip_id"] ).css("top") ) + parseInt( pointer_options['position']['pos-top'] ); |
|
55 |
leftPos = parseInt( $( "." + pointer_options["tooltip_id"] ).css("left") ) + parseInt( pointer_options['position']['pos-left'] ); |
|
56 |
if ( pointer_options['position']['align'] == 'left' ) { |
|
57 |
leftPos += cssSelector.outerWidth()/2; |
|
58 |
}; |
|
59 |
$( "." + pointer_options["tooltip_id"] ).css({ "top": topPos + "px", "left": leftPos + "px" }); |
|
60 |
/* adjust z-index if need */ |
|
61 |
pointerZindex = parseInt( $( "." + pointer_options["tooltip_id"] ).css("z-index") ); |
|
62 |
if ( pointerZindex != pointer_options['position']['zindex'] ) { |
|
63 |
$( "." + pointer_options["tooltip_id"] ).css({ "z-index": pointer_options['position']['zindex'] }); |
|
64 |
} |
|
65 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
66 |
|
5 | 67 |
/* display pointer for the first time */ |
68 |
if ( pointer_options['actions']['onload'] ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
if ( pointer_options['set_timeout'] > 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
var settime = parseInt( pointer_options['set_timeout'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
setTimeout( function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
displayPointer( $( pointer_options['css_selector'] ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
}, settime ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
displayPointer( $( pointer_options['css_selector'] ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
76 |
} |
5 | 77 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
78 |
|
5 | 79 |
/* display pointer when clicked on selector */ |
80 |
if ( pointer_options['actions']['click'] ) { |
|
81 |
$( pointer_options['css_selector'] ).click( function () { |
|
82 |
displayPointer( $( this ) ); |
|
83 |
}); |
|
84 |
} |
|
85 |
}; |
|
86 |
}) |
|
87 |
})(jQuery); |