bws_menu.js
4 years ago
bws_tooltip.js
4 years ago
c_o_o_k_i_e.js
4 years ago
codemirror.js
4 years ago
general_script.js
4 years ago
shortcode-button.js
4 years ago
bws_tooltip.js
91 lines
| 1 | /** |
| 2 | * BWS tooltip function |
| 3 | * |
| 4 | */ |
| 5 | (function($) { |
| 6 | "use strict"; |
| 7 | $(document).ready( 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( pointer_options, { |
| 12 | buttons: function(event, t) { |
| 13 | var button = ''; |
| 14 | /* check and add dismiss-type buttons */ |
| 15 | for ( var but in pointer_buttons ) { |
| 16 | if ( typeof pointer_buttons[ but ]['type'] != 'undefined' && pointer_buttons[ but ]['type'] == 'dismiss' && typeof pointer_buttons[ but ]['text'] != 'undefined' && pointer_buttons[ but ]['text'] != '' ) { |
| 17 | button += '<a style="margin:0px 5px 2px;" class="button-secondary">' + pointer_buttons[ but ]['text'] + '</a>'; |
| 18 | } |
| 19 | } |
| 20 | button = jQuery( button ); |
| 21 | button.on('click.pointer', function () { |
| 22 | t.element.pointer('close'); |
| 23 | }); |
| 24 | return button; |
| 25 | }, |
| 26 | /* add ajax dismiss functionality */ |
| 27 | close : $.proxy(function () { |
| 28 | if ( pointer_options['actions']['onload'] == true ) { |
| 29 | $.post( ajaxurl, this ); |
| 30 | } |
| 31 | }, { |
| 32 | pointer: pointer_options['tooltip_id'], |
| 33 | action: 'dismiss-wp-pointer' |
| 34 | }) |
| 35 | }); |
| 36 | /* function to display pointer */ |
| 37 | function displayPointer( cssSelector ) { |
| 38 | cssSelector.pointer( pointer_options ).pointer({ |
| 39 | pointerClass: 'wp-pointer ' + pointer_options["tooltip_id"], |
| 40 | content: pointer_options['content'], |
| 41 | position: { |
| 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 | var topPos, |
| 56 | leftPos, |
| 57 | pointerZindex; |
| 58 | topPos = parseInt( $( "." + pointer_options["tooltip_id"] ).css("top") ) + parseInt( pointer_options['position']['pos-top'] ); |
| 59 | leftPos = parseInt( $( "." + pointer_options["tooltip_id"] ).css("left") ) + parseInt( pointer_options['position']['pos-left'] ); |
| 60 | if ( pointer_options['position']['align'] == 'left' ) { |
| 61 | leftPos += cssSelector.outerWidth()/2; |
| 62 | }; |
| 63 | $( "." + pointer_options["tooltip_id"] ).css({ "top": topPos + "px", "left": leftPos + "px" }); |
| 64 | /* adjust z-index if need */ |
| 65 | pointerZindex = parseInt( $( "." + pointer_options["tooltip_id"] ).css("z-index") ); |
| 66 | if ( pointerZindex != pointer_options['position']['zindex'] ) { |
| 67 | $( "." + pointer_options["tooltip_id"] ).css({ "z-index": pointer_options['position']['zindex'] }); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | /* display pointer for the first time */ |
| 72 | if ( pointer_options['actions']['onload'] ) { |
| 73 | if ( pointer_options['set_timeout'] > 0 ) { |
| 74 | var settime = parseInt( pointer_options['set_timeout'] ); |
| 75 | setTimeout( function() { |
| 76 | displayPointer( $( pointer_options['css_selector'] ) ); |
| 77 | }, settime ); |
| 78 | } else { |
| 79 | displayPointer( $( pointer_options['css_selector'] ) ); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /* display pointer when clicked on selector */ |
| 84 | if ( pointer_options['actions']['click'] ) { |
| 85 | $( pointer_options['css_selector'] ).click( function () { |
| 86 | displayPointer( $( this ) ); |
| 87 | }); |
| 88 | } |
| 89 | }; |
| 90 | }) |
| 91 | })(jQuery); |