balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

redux-welcome-admin.js (7820B)


      1 /* global window */
      2 
      3 ( function( $ ) {
      4 $.redux_welcome = $.redux_welcome || {};
      5 
      6 	$( document ).ready(
      7 		function() {
      8 			$.redux_welcome.initQtip();
      9 
     10 			if ( $( document.getElementById( 'support_div' ) ).is( ':visible' ) ) {
     11 				$.redux_welcome.initSupportPage();
     12 			}
     13 
     14 			$.redux_welcome.supportHash();
     15 		}
     16 	);
     17 
     18 	$.redux_welcome.supportHash = function() {
     19 		$( '#support_hash' ).on(
     20 			'focus',
     21 			function() {
     22 				var $this = $( this );
     23 				$this.trigger( 'select' );
     24 
     25 				// Work around Chrome's little problem.
     26 				$this.on(
     27 					'mouseup',
     28 					function() {
     29 
     30 						// Prevent further mouseup intervention.
     31 						$this.off( 'mouseup' );
     32 						return false;
     33 					}
     34 				);
     35 			}
     36 		);
     37 
     38 		$( '.redux_support_hash' ).on(
     39 			'click',
     40 			function( e ) {
     41 				var $nonce;
     42 
     43 				var $button = $( this );
     44 
     45 				if ( $button.hasClass( 'disabled' ) ) {
     46 					return;
     47 				}
     48 
     49 				$nonce = $( '#redux_support_nonce' ).val();
     50 
     51 				$button.addClass( 'disabled' );
     52 				$button.parent().append( '<span class="spinner" style="display:block;float: none;margin: 10px auto;"></span>' );
     53 
     54 				$button.closest( '.spinner' ).fadeIn();
     55 
     56 				if ( ! window.console ) {
     57 					window.console = {};
     58 				}
     59 
     60 				$.ajax(
     61 					{
     62 						type: 'post',
     63 						dataType: 'json',
     64 						url: window.ajaxurl,
     65 						data: {
     66 							action: 'redux_support_hash',
     67 							nonce: $nonce
     68 						},
     69 						error: function( response ) {
     70 							console.log( response );
     71 							$button.removeClass( 'disabled' );
     72 							$button.parent().find( '.spinner' ).remove();
     73 							alert( 'There was an error. Please try again later.' );
     74 						},
     75 						success: function( response ) {
     76 							if ( 'success' === response.status ) {
     77 								$( '#support_hash' ).val( 'https://support.redux.io/?id=' + response.identifier );
     78 								$button.parents( 'fieldset:first' ).find( '.next' ).prop( 'disabled', false ).trigger( 'click' );
     79 							} else {
     80 								window.console.log( response );
     81 								alert( 'There was an error. Please try again later.' );
     82 							}
     83 						}
     84 					}
     85 				);
     86 
     87 				e.preventDefault();
     88 			}
     89 		);
     90 	};
     91 
     92 	$.redux_welcome.initSupportPage = function() {
     93 		var current_fs, next_fs, previous_fs;   // Fieldsets.
     94 		var left, opacity, scale;               // Fieldset properties which we will animate.
     95 		var animating;                          // Flag to prevent quick multi-click glitches.
     96 
     97 		$.fn.actualHeight = function() {
     98 
     99 			// Find the closest visible parent and get it's hidden children.
    100 			var visibleParent = this.closest( ':visible' ).children(), thisHeight;
    101 
    102 			// Set a temporary class on the hidden parent of the element.
    103 			visibleParent.addClass( 'temp-show' );
    104 
    105 			// Get the height.
    106 			thisHeight = this.height();
    107 
    108 			// Remove the temporary class.
    109 			visibleParent.removeClass( 'temp-show' );
    110 
    111 			return thisHeight;
    112 		};
    113 
    114 		function setHeight() {
    115 			var $height = 0;
    116 
    117 			$( document ).find( '#support_div fieldset' ).each(
    118 				function() {
    119 					var $actual = $( this ).actualHeight();
    120 					if ( $height < $actual ) {
    121 						$height = $actual;
    122 					}
    123 				}
    124 			);
    125 
    126 			$( '#support_div' ).height( $height + 20 );
    127 		}
    128 
    129 		setHeight();
    130 
    131 		$( window ).on(
    132 			'resize',
    133 			function() {
    134 				setHeight();
    135 			}
    136 		);
    137 
    138 		$( '#is_user' ).on(
    139 			'click',
    140 			function() {
    141 				$( '#final_support .is_user' ).show();
    142 				$( '#final_support .is_developer' ).hide();
    143 				$( this ).parents( 'fieldset:first' ).find( '.next' ).trigger( 'click' );
    144 			}
    145 		);
    146 
    147 		$( '#is_developer' ).on(
    148 			'click',
    149 			function() {
    150 				$( '#final_support .is_user' ).hide();
    151 				$( '#final_support .is_developer' ).show();
    152 				$( this ).parents( 'fieldset:first' ).find( '.next' ).trigger( 'click' );
    153 			}
    154 		);
    155 
    156 		$( '#support_div .next' ).on(
    157 			'click',
    158 			function() {
    159 				if ( animating ) {
    160 					return false;
    161 				}
    162 
    163 				animating = true;
    164 
    165 				current_fs = $( this ).parent();
    166 				next_fs    = $( this ).parent().next();
    167 
    168 				// Activate next step on progressbar using the index of next_fs.
    169 				$( '#progressbar li' ).eq( $( 'fieldset' ).index( next_fs ) ).addClass( 'active' );
    170 
    171 				// Show the next fieldset.
    172 				next_fs.show();
    173 
    174 				// Hide the current fieldset with style.
    175 				current_fs.animate(
    176 					{ opacity: 0 },
    177 					{
    178 						step: function( now ) {
    179 
    180 							// As the opacity of current_fs reduces to 0 - stored in 'now'.
    181 							// 1. scale current_fs down to 80%.
    182 							scale = 1 - ( 1 - now ) * 0.2;
    183 
    184 							// 2. bring next_fs from the right(50%)
    185 							left = ( now * 50 ) + '%';
    186 
    187 							// 3. increase opacity of next_fs to 1 as it moves in
    188 							opacity = 1 - now;
    189 
    190 							current_fs.css( { 'transform': 'scale(' + scale + ')' } );
    191 							next_fs.css( { 'left': left, 'opacity': opacity } );
    192 						},
    193 						duration: 800, complete: function() {
    194 							current_fs.hide();
    195 							animating = false;
    196 						},
    197 						easing: 'easeInOutBack'
    198 					}
    199 				);
    200 			}
    201 		);
    202 
    203 		$( '#support_div .previous' ).on(
    204 			'click',
    205 			function() {
    206 				if ( animating ) {
    207 					return false;
    208 				}
    209 
    210 				animating = true;
    211 
    212 				current_fs  = $( this ).parent();
    213 				previous_fs = $( this ).parent().prev();
    214 
    215 				// De-activate current step on progressbar.
    216 				$( '#progressbar li' ).eq( $( 'fieldset' ).index( current_fs ) ).removeClass( 'active' );
    217 
    218 				// Show the previous fieldset.
    219 				previous_fs.show();
    220 
    221 				// Hide the current fieldset with style.
    222 				current_fs.animate(
    223 					{ opacity: 0 },
    224 					{
    225 						step: function( now ) {
    226 
    227 							// As the opacity of current_fs reduces to 0 - stored in 'now'.
    228 							// 1. scale previous_fs from 80% to 100%.
    229 							scale = 0.8 + ( 1 - now ) * 0.2;
    230 
    231 							// 2. take current_fs to the right(50%) - from 0%.
    232 							left = ( ( 1 - now ) * 50 ) + '%';
    233 
    234 							// 3. increase opacity of previous_fs to 1 as it moves in.
    235 							opacity = 1 - now;
    236 
    237 							current_fs.css( { 'left': left } );
    238 							previous_fs.css( { 'transform': 'scale(' + scale + ')', 'opacity': opacity } );
    239 						},
    240 						duration: 800, complete: function() {
    241 							current_fs.hide();
    242 							animating = false;
    243 						}, // This comes from the custom easing plugin
    244 						easing: 'easeInOutBack'
    245 					}
    246 				);
    247 			}
    248 		);
    249 	};
    250 
    251 	$.redux_welcome.initQtip = function() {
    252 		var shadow  = 'qtip-shadow';
    253 		var color   = 'qtip-dark';
    254 		var rounded = '';
    255 		var style   = ''; // Qtip-bootstrap'.
    256 		var classes = shadow + ',' + color + ',' + rounded + ',' + style;
    257 
    258 		// Get position data.
    259 		var myPos = 'top center';
    260 		var atPos = 'bottom center';
    261 
    262 		// Tooltip trigger action.
    263 		var showEvent = 'mouseenter';
    264 		var hideEvent = 'click mouseleave';
    265 
    266 		// Tip show effect.
    267 		var tipShowEffect   = 'slide';
    268 		var tipShowDuration = '300';
    269 
    270 		// Tip hide effect.
    271 		var tipHideEffect   = 'slide';
    272 		var tipHideDuration = '300';
    273 
    274 		if ( $().qtip ) {
    275 			classes = classes.replace( /,/g, ' ' );
    276 
    277 			$( '.redux-hint-qtip' ).each(
    278 				function() {
    279 					$( this ).qtip(
    280 						{
    281 							content: {
    282 								text: $( this ).attr( 'qtip-content' ), title: $( this ).attr( 'qtip-title' )
    283 							},
    284 							show: {
    285 								effect: function() {
    286 									switch ( tipShowEffect ) {
    287 										case 'slide':
    288 											$( this ).slideDown( tipShowDuration );
    289 											break;
    290 										case 'fade':
    291 											$( this ).fadeIn( tipShowDuration );
    292 											break;
    293 										default:
    294 											$( this ).show();
    295 											break;
    296 									}
    297 								},
    298 								event: showEvent
    299 							}, hide: {
    300 								effect: function() {
    301 									switch ( tipHideEffect ) {
    302 										case 'slide':
    303 											$( this ).slideUp( tipHideDuration );
    304 											break;
    305 										case 'fade':
    306 											$( this ).fadeOut( tipHideDuration );
    307 											break;
    308 										default:
    309 											$( this ).show( tipHideDuration );
    310 											break;
    311 									}
    312 								}, event: hideEvent
    313 							}, style: {
    314 								classes: classes
    315 							}, position: {
    316 								my: myPos,
    317 								at: atPos
    318 							}
    319 						}
    320 					);
    321 				}
    322 			);
    323 		}
    324 	};
    325 })( jQuery );