wp/wp-content/plugins/portfolio/bws_menu/js/bws_tooltip.js
changeset 19 3d72ae0968f4
parent 16 a86126ab1dd4
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
     1 /**
     1 /**
     2  * BWS tooltip function
     2  * BWS tooltip function
     3  *
       
     4  */
     3  */
     5 (function($) {
     4 (function($) {
     6 	$(document).ready( function() {
     5 	"use strict";
     7 		jQuery.bwsTooltip = function( pointer_options ) {
     6 	$( document ).ready(
     8 			var pointer_buttons = pointer_options['buttons'];
     7 		function() {
     9 			/* extend pointer options - add close button */
     8 				jQuery.bwsTooltip = function( pointer_options ) {
    10 			pointer_options = $.extend( pointer_options, {
     9 					  var pointer_buttons = pointer_options['buttons'];
    11 				buttons: function(event, t) {
    10 					  /* extend pointer options - add close button */
    12 					var button = '';
    11 					pointer_options = $.extend(
    13 					/* check and add dismiss-type buttons */
    12 						pointer_options,
    14 					for ( var but in pointer_buttons ) {
    13 						{
    15 						if ( typeof pointer_buttons[ but ]['type'] != 'undefined' && pointer_buttons[ but ]['type'] == 'dismiss' && typeof pointer_buttons[ but ]['text'] != 'undefined' && pointer_buttons[ but ]['text'] != '' ) {
    14 							buttons: function(event, t) {
    16 							button += '<a style="margin:0px 5px 2px;" class="button-secondary">' + pointer_buttons[ but ]['text'] + '</a>';
    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'] } );
    17 						}
    81 						}
    18 					}
    82 					}
    19 					button = jQuery( button );
    83 
    20 					button.bind('click.pointer', function () {
    84 					/* display pointer for the first time */
    21 						t.element.pointer('close');
    85 					if ( pointer_options['actions']['onload'] ) {
    22 					});
    86 						if ( pointer_options['set_timeout'] > 0 ) {
    23 					return button;
    87 							var settime = parseInt( pointer_options['set_timeout'] );
    24 				},
    88 							setTimeout(
    25 				/* add ajax dismiss functionality */
    89 								function() {
    26 				close : $.proxy(function () {
    90 									displayPointer( $( pointer_options['css_selector'] ) );
    27 					if ( pointer_options['actions']['onload'] == true ) {
    91 								},
    28 						$.post( ajaxurl, this );
    92 								settime
       
    93 							);
       
    94 						} else {
       
    95 							displayPointer( $( pointer_options['css_selector'] ) );
       
    96 						}
    29 					}
    97 					}
    30 				}, {
    98 
    31 					pointer: pointer_options['tooltip_id'],
    99 					/* display pointer when clicked on selector */
    32 					action: 'dismiss-wp-pointer'
   100 					if ( pointer_options['actions']['click'] ) {
    33 				})
   101 						$( pointer_options['css_selector'] ).click(
    34 			});
   102 							function () {
    35 			/* function to display pointer */
   103 									displayPointer( $( this ) );
    36 			function displayPointer( cssSelector ) {
   104 							}
    37 				cssSelector.pointer( pointer_options ).pointer({
   105 						);
    38 					pointerClass: 'wp-pointer ' + pointer_options["tooltip_id"],
   106 					}
    39 					content: pointer_options['content'],
       
    40 					position: {
       
    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 				};
   107 				};
    59 				$( "." + pointer_options["tooltip_id"] ).css({ "top": topPos + "px", "left": leftPos + "px" });
   108 		}
    60 				/* adjust z-index if need */
   109 	)
    61 				pointerZindex = parseInt( $( "." + pointer_options["tooltip_id"] ).css("z-index") );
   110 })( jQuery );
    62 				if ( pointerZindex != pointer_options['position']['zindex'] ) {
       
    63 					$( "." + pointer_options["tooltip_id"] ).css({ "z-index": pointer_options['position']['zindex'] });
       
    64 				}
       
    65 			}
       
    66 
       
    67 			/* display pointer for the first time */
       
    68 			if ( pointer_options['actions']['onload'] ) {
       
    69 				if ( pointer_options['set_timeout'] > 0 ) {
       
    70 					var settime = parseInt( pointer_options['set_timeout'] );					
       
    71 					setTimeout( function() {
       
    72 						displayPointer( $( pointer_options['css_selector'] ) );
       
    73 					}, settime );	
       
    74 				} else {
       
    75 					displayPointer( $( pointer_options['css_selector'] ) );
       
    76 				}
       
    77 			}
       
    78 						
       
    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);