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