| @@ -1,2695 +1,2695 @@ | ||
| 1 | 1 | /* assets/wpuf/js/frontend-form.js */ |
| 2 | -;(function($, window) { | |
| 3 | - | |
| 4 | - $.fn.listautowidth = function() { | |
| 5 | - return this.each(function() { | |
| 6 | - var w = $(this).width(); | |
| 7 | - var liw = w / $(this).children('li').length; | |
| 8 | - $(this).children('li').each(function(){ | |
| 9 | - var s = $(this).outerWidth(true)-$(this).width(); | |
| 10 | - $(this).width(liw-s); | |
| 11 | - }); | |
| 12 | - }); | |
| 13 | - }; | |
| 14 | - | |
| 15 | - window.WP_User_Frontend = { | |
| 16 | - | |
| 17 | - init: function() { | |
| 18 | - | |
| 19 | - //enable multistep | |
| 20 | - this.enableMultistep(this); | |
| 21 | - | |
| 22 | - // clone and remove repeated field | |
| 23 | - $('.wpuf-form').on('click', 'img.wpuf-clone-field', this.cloneField); | |
| 24 | - $('.wpuf-form').on('click', 'img.wpuf-remove-field', this.removeField); | |
| 25 | - $('.wpuf-form').on('click', 'a.wpuf-delete-avatar', this.deleteAvatar); | |
| 26 | - $('.wpuf-form').on('click', 'a#wpuf-post-draft', this.draftPost); | |
| 27 | - $('.wpuf-form').on('click', 'button#wpuf-account-update-profile', this.account_update_profile); | |
| 28 | - | |
| 29 | - $('.wpuf-form-add').on('submit', this.formSubmit); | |
| 30 | - $('form#post').on('submit', this.adminPostSubmit); | |
| 31 | - // $( '.wpuf-form').on('keyup', '#pass1', this.check_pass_strength ); | |
| 32 | - | |
| 33 | - // refresh pluploads on each step change (multistep form) | |
| 34 | - $('.wpuf-form').on('step-change-fieldset', function(event, number, step) { | |
| 35 | - if ( wpuf_plupload_items.length ) { | |
| 36 | - for (var i = wpuf_plupload_items.length - 1; i >= 0; i--) { | |
| 37 | - wpuf_plupload_items[i].refresh(); | |
| 38 | - } | |
| 39 | - } | |
| 40 | - if ( wpuf_map_items.length ) { | |
| 41 | - for (var i = wpuf_map_items.length - 1; i >= 0; i--) { | |
| 42 | - google.maps.event.trigger(wpuf_map_items[i].map, 'resize'); | |
| 43 | - wpuf_map_items[i].map.setCenter(wpuf_map_items[i].center); | |
| 44 | - } | |
| 45 | - } | |
| 46 | - }); | |
| 47 | - | |
| 48 | - this.ajaxCategory(); | |
| 49 | - // image insert | |
| 50 | - // this.insertImage(); | |
| 51 | - | |
| 52 | - //comfirmation alert for canceling subscription | |
| 53 | - $( ':submit[name="wpuf_user_subscription_cancel"]').click(function(e){ | |
| 54 | - e.preventDefault(); | |
| 55 | - | |
| 56 | - swal({ | |
| 57 | - text: wpuf_frontend.cancelSubMsg, | |
| 58 | - type: 'warning', | |
| 59 | - showCancelButton: true, | |
| 60 | - confirmButtonColor: '#d54e21', | |
| 61 | - confirmButtonText: wpuf_frontend.delete_it, | |
| 62 | - cancelButtonText: wpuf_frontend.cancel_it, | |
| 63 | - confirmButtonClass: 'btn btn-success', | |
| 64 | - cancelButtonClass: 'btn btn-danger', | |
| 65 | - }).then(function ( isConfirmed ) { | |
| 66 | - if ( !isConfirmed ) { | |
| 67 | - return false; | |
| 68 | - } | |
| 69 | - $('#wpuf_cancel_subscription').submit(); | |
| 70 | - }); | |
| 71 | - }); | |
| 72 | - }, | |
| 73 | - | |
| 74 | - check_pass_strength : function() { | |
| 75 | - var pass1 = $('#pass1').val(), strength; | |
| 76 | - | |
| 77 | - $('#pass-strength-result').show(); | |
| 78 | - | |
| 79 | - $('#pass-strength-result').removeClass('short bad good strong'); | |
| 80 | - if ( ! pass1 ) { | |
| 81 | - $('#pass-strength-result').html( ' ' ); | |
| 82 | - $('#pass-strength-result').hide(); | |
| 83 | - return; | |
| 84 | - } | |
| 85 | - | |
| 86 | - if ( typeof wp.passwordStrength != 'undefined' ) { | |
| 87 | - | |
| 88 | - strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputBlacklist(), pass1 ); | |
| 89 | - | |
| 90 | - switch ( strength ) { | |
| 91 | - case 2: | |
| 92 | - $('#pass-strength-result').addClass('bad').html( pwsL10n.bad ); | |
| 93 | - break; | |
| 94 | - case 3: | |
| 95 | - $('#pass-strength-result').addClass('good').html( pwsL10n.good ); | |
| 96 | - break; | |
| 97 | - case 4: | |
| 98 | - $('#pass-strength-result').addClass('strong').html( pwsL10n.strong ); | |
| 99 | - break; | |
| 100 | - case 5: | |
| 101 | - $('#pass-strength-result').addClass('short').html( pwsL10n.mismatch ); | |
| 102 | - break; | |
| 103 | - default: | |
| 104 | - $('#pass-strength-result').addClass('short').html( pwsL10n['short'] ); | |
| 105 | - } | |
| 106 | - | |
| 107 | - } | |
| 108 | - }, | |
| 109 | - | |
| 110 | - enableMultistep: function(o) { | |
| 111 | - | |
| 112 | - var js_obj = this; | |
| 113 | - var step_number = 0; | |
| 114 | - var progressbar_type = $(':hidden[name="wpuf_multistep_type"]').val(); | |
| 115 | - | |
| 116 | - if ( progressbar_type == null ) { | |
| 117 | - return; | |
| 118 | - } | |
| 119 | - | |
| 120 | - // first fieldset doesn't have prev button, | |
| 121 | - // last fieldset doesn't have next button | |
| 122 | - $('fieldset.wpuf-multistep-fieldset').find('.wpuf-multistep-prev-btn').first().remove(); | |
| 123 | - $('fieldset.wpuf-multistep-fieldset').find('.wpuf-multistep-next-btn').last().remove(); | |
| 124 | - | |
| 125 | - // at first first fieldset will be shown, and others will be hidden | |
| 126 | - $('.wpuf-form fieldset').removeClass('field-active').first().addClass('field-active'); | |
| 127 | - | |
| 128 | - if ( progressbar_type == 'progressive' && $('.wpuf-form .wpuf-multistep-fieldset').length != 0 ) { | |
| 129 | - | |
| 130 | - var firstLegend = $('fieldset.wpuf-multistep-fieldset legend').first(); | |
| 131 | - $('.wpuf-multistep-progressbar').html('<div class="wpuf-progress-percentage"></div>' ); | |
| 132 | - | |
| 133 | - var progressbar = $( ".wpuf-multistep-progressbar" ), | |
| 134 | - progressLabel = $( ".wpuf-progress-percentage" ); | |
| 135 | - | |
| 136 | - $( ".wpuf-multistep-progressbar" ).progressbar({ | |
| 137 | - change: function() { | |
| 138 | - progressLabel.text( progressbar.progressbar( "value" ) + "%" ); | |
| 139 | - } | |
| 140 | - }); | |
| 141 | - | |
| 142 | - $('.wpuf-multistep-fieldset legend').hide(); | |
| 143 | - | |
| 144 | - } else { | |
| 145 | - $('.wpuf-form').each(function() { | |
| 146 | - var this_obj = $(this); | |
| 147 | - var progressbar = $('.wpuf-multistep-progressbar', this_obj); | |
| 148 | - var nav = ''; | |
| 149 | - | |
| 150 | - progressbar.addClass('wizard-steps'); | |
| 151 | - nav += '<ul class="wpuf-step-wizard">'; | |
| 152 | - | |
| 153 | - $('.wpuf-multistep-fieldset', this).each(function(){ | |
| 154 | - nav += '<li>' + $.trim( $('legend', this).text() ) + '</li>'; | |
| 155 | - $('legend', this).hide(); | |
| 156 | - }); | |
| 157 | - | |
| 158 | - nav += '</ul>'; | |
| 159 | - progressbar.append( nav ); | |
| 160 | - | |
| 161 | - $('.wpuf-step-wizard li', progressbar).first().addClass('active-step'); | |
| 162 | - $('.wpuf-step-wizard', progressbar).listautowidth(); | |
| 163 | - }); | |
| 164 | - } | |
| 165 | - | |
| 166 | - this.change_fieldset(step_number, progressbar_type); | |
| 167 | - | |
| 168 | - $('fieldset .wpuf-multistep-prev-btn, fieldset .wpuf-multistep-next-btn').click(function(e) { | |
| 169 | - // js_obj.formSubmit(); | |
| 170 | - if ( $(this).hasClass('wpuf-multistep-next-btn') ) { | |
| 171 | - var result = js_obj.formStepCheck( '', $(this).closest('fieldset') ); | |
| 172 | - | |
| 173 | - if ( result != false ) { | |
| 174 | - o.change_fieldset(++step_number,progressbar_type); | |
| 175 | - } | |
| 176 | - | |
| 177 | - } else if ( $(this).hasClass('wpuf-multistep-prev-btn') ) { | |
| 178 | - o.change_fieldset( --step_number,progressbar_type ); | |
| 179 | - } | |
| 180 | - | |
| 181 | - var formDiv = $( "form.wpuf-form-add" ); | |
| 182 | - var position = formDiv.offset().top; | |
| 183 | - | |
| 184 | - // this changes the scrolling behavior to "smooth" | |
| 185 | - window.scrollTo({ | |
| 186 | - top: position - 32, | |
| 187 | - behavior: "smooth" | |
| 188 | - }); | |
| 189 | - | |
| 190 | - return false; | |
| 191 | - }); | |
| 192 | - }, | |
| 193 | - | |
| 194 | - change_fieldset: function(step_number, progressbar_type) { | |
| 195 | - var current_step = $('fieldset.wpuf-multistep-fieldset').eq(step_number); | |
| 196 | - | |
| 197 | - $('fieldset.wpuf-multistep-fieldset').removeClass('field-active').eq(step_number).addClass('field-active'); | |
| 198 | - | |
| 199 | - $('.wpuf-step-wizard li').each(function(){ | |
| 200 | - if ( $(this).index() <= step_number ){ | |
| 201 | - progressbar_type == 'step_by_step'? $(this).addClass('passed-wpuf-ms-bar') : $('.wpuf-ps-bar',this).addClass('passed-wpuf-ms-bar'); | |
| 202 | - } else { | |
| 203 | - progressbar_type == 'step_by_step'? $(this).removeClass('passed-wpuf-ms-bar') : $('.wpuf-ps-bar',this).removeClass('passed-wpuf-ms-bar'); | |
| 204 | - } | |
| 205 | - }); | |
| 206 | - | |
| 207 | - $('.wpuf-step-wizard li').removeClass('wpuf-ms-bar-active active-step completed-step'); | |
| 208 | - $('.passed-wpuf-ms-bar').addClass('completed-step').last().addClass('wpuf-ms-bar-active'); | |
| 209 | - $('.wpuf-ms-bar-active').addClass('active-step'); | |
| 210 | - | |
| 211 | - var legend = $('fieldset.wpuf-multistep-fieldset').eq(step_number).find('legend').text(); | |
| 212 | - legend = $.trim( legend ); | |
| 213 | - | |
| 214 | - if ( progressbar_type == 'progressive' && $('.wpuf-form .wpuf-multistep-fieldset').length != 0 ) { | |
| 215 | - var progress_percent = ( step_number + 1 ) * 100 / $('fieldset.wpuf-multistep-fieldset').length ; | |
| 216 | - var progress_percent = Number( progress_percent.toFixed(2) ); | |
| 217 | - $( ".wpuf-multistep-progressbar" ).progressbar({value: progress_percent }); | |
| 218 | - $( '.wpuf-progress-percentage' ).text( legend + ' (' + progress_percent + '%)'); | |
| 219 | - } | |
| 220 | - | |
| 221 | - // trigger a change event | |
| 222 | - $('.wpuf-form').trigger('step-change-fieldset', [ step_number, current_step ]); | |
| 223 | - }, | |
| 224 | - | |
| 225 | - ajaxCategory: function () { | |
| 226 | - | |
| 227 | - var el = '.cat-ajax', | |
| 228 | - wrap = '.category-wrap'; | |
| 229 | - | |
| 230 | - $(wrap).on('change', el, function(){ | |
| 231 | - currentLevel = parseInt( $(this).parent().attr('level') ); | |
| 232 | - WP_User_Frontend.getChildCats( $(this), 'lvl', currentLevel+1, wrap, 'category'); | |
| 233 | - }); | |
| 234 | - }, | |
| 235 | - | |
| 236 | - getChildCats: function (dropdown, result_div, level, wrap_div, taxonomy) { | |
| 237 | - | |
| 238 | - cat = $(dropdown).val(); | |
| 239 | - results_div = result_div + level; | |
| 240 | - taxonomy = typeof taxonomy !== 'undefined' ? taxonomy : 'category'; | |
| 241 | - field_attr = $(dropdown).siblings('span').data('taxonomy'); | |
| 242 | - | |
| 243 | - $.ajax({ | |
| 244 | - type: 'post', | |
| 245 | - url: wpuf_frontend.ajaxurl, | |
| 246 | - data: { | |
| 247 | - action: 'wpuf_get_child_cat', | |
| 248 | - catID: cat, | |
| 249 | - nonce: wpuf_frontend.nonce, | |
| 250 | - field_attr: field_attr | |
| 251 | - }, | |
| 252 | - beforeSend: function() { | |
| 253 | - $(dropdown).parent().parent().next('.loading').addClass('wpuf-loading'); | |
| 254 | - }, | |
| 255 | - complete: function() { | |
| 256 | - $(dropdown).parent().parent().next('.loading').removeClass('wpuf-loading'); | |
| 257 | - }, | |
| 258 | - success: function(html) { | |
| 259 | - //console.log( html ); return; | |
| 260 | - $(dropdown).parent().nextAll().each(function(){ | |
| 261 | - $(this).remove(); | |
| 262 | - }); | |
| 263 | - | |
| 264 | - if(html != "") { | |
| 265 | - $(dropdown).parent().addClass('hasChild').parent().append('<div id="'+result_div+level+'" level="'+level+'"></div>'); | |
| 266 | - dropdown.parent().parent().find('#'+results_div).html(html).slideDown('fast'); | |
| 267 | - } | |
| 268 | - } | |
| 269 | - }); | |
| 270 | - }, | |
| 271 | - | |
| 272 | - cloneField: function(e) { | |
| 273 | - e.preventDefault(); | |
| 274 | - | |
| 275 | - var $div = $(this).closest('tr'); | |
| 276 | - var $clone = $div.clone(); | |
| 277 | - // console.log($clone); | |
| 278 | - | |
| 279 | - //clear the inputs | |
| 280 | - $clone.find('input').val(''); | |
| 281 | - $clone.find(':checked').attr('checked', ''); | |
| 282 | - $div.after($clone); | |
| 283 | - }, | |
| 284 | - | |
| 285 | - removeField: function() { | |
| 286 | - //check if it's the only item | |
| 287 | - var $parent = $(this).closest('tr'); | |
| 288 | - var items = $parent.siblings().andSelf().length; | |
| 289 | - | |
| 290 | - if( items > 1 ) { | |
| 291 | - $parent.remove(); | |
| 292 | - } | |
| 293 | - }, | |
| 294 | - | |
| 295 | - adminPostSubmit: function(e) { | |
| 296 | - e.preventDefault(); | |
| 297 | - | |
| 298 | - var form = $(this), | |
| 299 | - form_data = WP_User_Frontend.validateForm(form); | |
| 300 | - | |
| 301 | - if (form_data) { | |
| 302 | - return true; | |
| 303 | - } | |
| 304 | - }, | |
| 305 | - | |
| 306 | - draftPost: function (e) { | |
| 307 | - e.preventDefault(); | |
| 308 | - | |
| 309 | - var self = $(this), | |
| 310 | - form = $(this).closest('form'), | |
| 311 | - form_data = form.serialize() + '&action=wpuf_draft_post', | |
| 312 | - post_id = form.find('input[type="hidden"][name="post_id"]').val(); | |
| 313 | - | |
| 314 | - var rich_texts = [], | |
| 315 | - val; | |
| 316 | - | |
| 317 | - // grab rich texts from tinyMCE | |
| 318 | - $('.wpuf-rich-validation').each(function (index, item) { | |
| 319 | - var item = $(item); | |
| 320 | - var editor_id = item.data('id'); | |
| 321 | - var item_name = item.data('name'); | |
| 322 | - var val = $.trim( tinyMCE.get(editor_id).getContent() ); | |
| 323 | - | |
| 324 | - rich_texts.push(item_name + '=' + encodeURIComponent( val ) ); | |
| 325 | - }); | |
| 326 | - | |
| 327 | - // append them to the form var | |
| 328 | - form_data = form_data + '&' + rich_texts.join('&'); | |
| 329 | - | |
| 330 | - | |
| 331 | - self.after(' <span class="wpuf-loading"></span>'); | |
| 332 | - $.post(wpuf_frontend.ajaxurl, form_data, function(res) { | |
| 333 | - // console.log(res, post_id); | |
| 334 | - if ( typeof post_id === 'undefined') { | |
| 335 | - var html = '<input type="hidden" name="post_id" value="' + res.post_id +'">'; | |
| 336 | - html += '<input type="hidden" name="post_date" value="' + res.date +'">'; | |
| 337 | - html += '<input type="hidden" name="post_author" value="' + res.post_author +'">'; | |
| 338 | - html += '<input type="hidden" name="comment_status" value="' + res.comment_status +'">'; | |
| 339 | - | |
| 340 | - form.append( html ); | |
| 341 | - } | |
| 342 | - | |
| 343 | - self.next('span.wpuf-loading').remove(); | |
| 344 | - | |
| 345 | - self.after('<span class="wpuf-draft-saved"> Post Saved</span>'); | |
| 346 | - $('.wpuf-draft-saved').delay(2500).fadeOut('fast', function(){ | |
| 347 | - $(this).remove(); | |
| 348 | - }); | |
| 349 | - }) | |
| 350 | - }, | |
| 351 | - | |
| 352 | - // Frontend account dashboard update profile | |
| 353 | - account_update_profile: function (e) { | |
| 354 | - e.preventDefault(); | |
| 355 | - var form = $(this).closest('form'); | |
| 356 | - | |
| 357 | - $.post(wpuf_frontend.ajaxurl, form.serialize(), function (res) { | |
| 358 | - if (res.success) { | |
| 359 | - form.find('.wpuf-error').hide(); | |
| 360 | - form.find('.wpuf-success').show(); | |
| 361 | - } else { | |
| 362 | - form.find('.wpuf-success').hide(); | |
| 363 | - form.find('.wpuf-error').show(); | |
| 364 | - form.find('.wpuf-error').text(res.data); | |
| 365 | - } | |
| 366 | - }); | |
| 367 | - }, | |
| 368 | - | |
| 369 | - formStepCheck : function(e,fieldset) { | |
| 370 | - var form = fieldset, | |
| 371 | - submitButton = form.find('input[type=submit]'); | |
| 372 | - form_data = WP_User_Frontend.validateForm(form); | |
| 373 | - | |
| 374 | - if ( form_data == false ) { | |
| 375 | - WP_User_Frontend.addErrorNotice( self, 'bottom' ); | |
| 376 | - } | |
| 377 | - return form_data; | |
| 378 | - }, | |
| 379 | - | |
| 380 | - formSubmit: function(e) { | |
| 381 | - e.preventDefault(); | |
| 382 | - | |
| 383 | - var form = $(this), | |
| 384 | - submitButton = form.find('input[type=submit]') | |
| 385 | - form_data = WP_User_Frontend.validateForm(form); | |
| 386 | - | |
| 387 | - if (form_data) { | |
| 388 | - | |
| 389 | - // send the request | |
| 390 | - form.find('li.wpuf-submit').append('<span class="wpuf-loading"></span>'); | |
| 391 | - submitButton.attr('disabled', 'disabled').addClass('button-primary-disabled'); | |
| 392 | - | |
| 393 | - $.post(wpuf_frontend.ajaxurl, form_data, function(res) { | |
| 394 | - // var res = $.parseJSON(res); | |
| 395 | - | |
| 396 | - if ( res.success) { | |
| 397 | - | |
| 398 | - // enable external plugins to use events | |
| 399 | - $('body').trigger('wpuf:postform:success', res); | |
| 400 | - | |
| 401 | - if ( res.show_message == true) { | |
| 402 | - form.before( '<div class="wpuf-success">' + res.message + '</div>'); | |
| 403 | - form.slideUp( 'fast', function() { | |
| 404 | - form.remove(); | |
| 405 | - }); | |
| 406 | - | |
| 407 | - //focus | |
| 408 | - $('html, body').animate({ | |
| 409 | - scrollTop: $('.wpuf-success').offset().top - 100 | |
| 410 | - }, 'fast'); | |
| 411 | - | |
| 412 | - } else { | |
| 413 | - window.location = res.redirect_to; | |
| 414 | - } | |
| 415 | - | |
| 416 | - } else { | |
| 417 | - | |
| 418 | - if ( typeof res.type !== 'undefined' && res.type === 'login' ) { | |
| 419 | - | |
| 420 | - if ( confirm(res.error) ) { | |
| 421 | - window.location = res.redirect_to; | |
| 422 | - } else { | |
| 423 | - submitButton.removeAttr('disabled'); | |
| 424 | - submitButton.removeClass('button-primary-disabled'); | |
| 425 | - form.find('span.wpuf-loading').remove(); | |
| 426 | - } | |
| 427 | - | |
| 428 | - return; | |
| 429 | - } else { | |
| 430 | - if ( form.find('.g-recaptcha').length > 0 ) { | |
| 431 | - grecaptcha.reset(); | |
| 432 | - } | |
| 433 | - | |
| 434 | - swal({ | |
| 435 | - html: res.error, | |
| 436 | - type: 'warning', | |
| 437 | - showCancelButton: false, | |
| 438 | - confirmButtonColor: '#d54e21', | |
| 439 | - confirmButtonText: 'OK', | |
| 440 | - cancelButtonClass: 'btn btn-danger', | |
| 441 | - }); | |
| 442 | - | |
| 443 | - } | |
| 444 | - | |
| 445 | - submitButton.removeAttr('disabled'); | |
| 446 | - } | |
| 447 | - | |
| 448 | - submitButton.removeClass('button-primary-disabled'); | |
| 449 | - form.find('span.wpuf-loading').remove(); | |
| 450 | - }); | |
| 451 | - } | |
| 452 | - }, | |
| 453 | - | |
| 454 | - validateForm: function( self ) { | |
| 455 | - | |
| 456 | - var temp, | |
| 457 | - temp_val = '', | |
| 458 | - error = false, | |
| 459 | - error_items = []; | |
| 460 | - error_type = ''; | |
| 461 | - | |
| 462 | - // remove all initial errors if any | |
| 463 | - WP_User_Frontend.removeErrors(self); | |
| 464 | - WP_User_Frontend.removeErrorNotice(self); | |
| 465 | - | |
| 466 | - // ===== Validate: Text and Textarea ======== | |
| 467 | - var required = self.find('[data-required="yes"]:visible'); | |
| 468 | - | |
| 469 | - required.each(function(i, item) { | |
| 470 | - // temp_val = $.trim($(item).val()); | |
| 471 | - | |
| 472 | - // console.log( $(item).data('type') ); | |
| 473 | - var data_type = $(item).data('type') | |
| 474 | - val = ''; | |
| 475 | - | |
| 476 | - switch(data_type) { | |
| 477 | - case 'rich': | |
| 478 | - var name = $(item).data('id') | |
| 479 | - val = $.trim( tinyMCE.get(name).getContent() ); | |
| 480 | - | |
| 481 | - if ( val === '') { | |
| 482 | - error = true; | |
| 483 | - | |
| 484 | - // make it warn collor | |
| 485 | - WP_User_Frontend.markError(item); | |
| 486 | - } | |
| 487 | - break; | |
| 488 | - | |
| 489 | - case 'textarea': | |
| 490 | - case 'text': | |
| 491 | - | |
| 492 | - val = $.trim( $(item).val() ); | |
| 493 | - | |
| 494 | - if ( val === '') { | |
| 495 | - error = true; | |
| 496 | - error_type = 'required'; | |
| 497 | - | |
| 498 | - // make it warn collor | |
| 499 | - WP_User_Frontend.markError( item, error_type ); | |
| 500 | - } | |
| 501 | - break; | |
| 502 | - | |
| 503 | - case 'password': | |
| 504 | - case 'confirm_password': | |
| 505 | - var hasRepeat = $(item).data('repeat'); | |
| 506 | - | |
| 507 | - val = $.trim( $(item).val() ); | |
| 508 | - | |
| 509 | - if ( val === '') { | |
| 510 | - error = true; | |
| 511 | - error_type = 'required'; | |
| 512 | - | |
| 513 | - // make it warn collor | |
| 514 | - WP_User_Frontend.markError( item, error_type ); | |
| 515 | - } | |
| 516 | - | |
| 517 | - if ( hasRepeat ) { | |
| 518 | - var repeatItem = $('[data-type="confirm_password"]').eq(0);; | |
| 519 | - | |
| 520 | - if ( repeatItem.val() != val ) { | |
| 521 | - error = true; | |
| 522 | - error_type = 'mismatch'; | |
| 523 | - | |
| 524 | - WP_User_Frontend.markError( repeatItem, error_type ); | |
| 525 | - } | |
| 526 | - } | |
| 527 | - | |
| 528 | - break; | |
| 529 | - | |
| 530 | - case 'select': | |
| 531 | - val = $(item).val(); | |
| 532 | - | |
| 533 | - // console.log(val); | |
| 534 | - if ( !val || val === '-1' ) { | |
| 535 | - error = true; | |
| 536 | - error_type = 'required'; | |
| 537 | - | |
| 538 | - // make it warn collor | |
| 539 | - WP_User_Frontend.markError( item, error_type ); | |
| 540 | - } | |
| 541 | - break; | |
| 542 | - | |
| 543 | - case 'multiselect': | |
| 544 | - val = $(item).val(); | |
| 545 | - | |
| 546 | - if ( val === null || val.length === 0 ) { | |
| 547 | - error = true; | |
| 548 | - error_type = 'required'; | |
| 549 | - | |
| 550 | - // make it warn collor | |
| 551 | - WP_User_Frontend.markError( item, error_type ); | |
| 552 | - } | |
| 553 | - break; | |
| 554 | - | |
| 555 | - case 'tax-checkbox': | |
| 556 | - var length = $(item).children().find('input:checked').length; | |
| 557 | - | |
| 558 | - if ( !length ) { | |
| 559 | - error = true; | |
| 560 | - error_type = 'required'; | |
| 561 | - | |
| 562 | - // make it warn collor | |
| 563 | - WP_User_Frontend.markError( item, error_type ); | |
| 564 | - } | |
| 565 | - break; | |
| 566 | - | |
| 567 | - case 'radio': | |
| 568 | - var length = $(item).find('input:checked').length; | |
| 569 | - | |
| 570 | - if ( !length ) { | |
| 571 | - error = true; | |
| 572 | - error_type = 'required'; | |
| 573 | - | |
| 574 | - // make it warn collor | |
| 575 | - WP_User_Frontend.markError( item, error_type ); | |
| 576 | - } | |
| 577 | - break; | |
| 578 | - | |
| 579 | - case 'file': | |
| 580 | - var length = $(item).find('ul').children().length; | |
| 581 | - | |
| 582 | - if ( !length ) { | |
| 583 | - error = true; | |
| 584 | - error_type = 'required'; | |
| 585 | - | |
| 586 | - // make it warn collor | |
| 587 | - WP_User_Frontend.markError( item, error_type ); | |
| 588 | - } | |
| 589 | - break; | |
| 590 | - | |
| 591 | - case 'email': | |
| 592 | - var val = $(item).val(); | |
| 593 | - | |
| 594 | - if ( val !== '' ) { | |
| 595 | - //run the validation | |
| 596 | - if( !WP_User_Frontend.isValidEmail( val ) ) { | |
| 597 | - error = true; | |
| 598 | - error_type = 'validation'; | |
| 599 | - | |
| 600 | - WP_User_Frontend.markError( item, error_type ); | |
| 601 | - } | |
| 602 | - } else if( val === '' ) { | |
| 603 | - error = true; | |
| 604 | - error_type = 'required'; | |
| 605 | - | |
| 606 | - WP_User_Frontend.markError( item, error_type ); | |
| 607 | - } | |
| 608 | - break; | |
| 609 | - | |
| 610 | - | |
| 611 | - case 'url': | |
| 612 | - var val = $(item).val(); | |
| 613 | - | |
| 614 | - if ( val !== '' ) { | |
| 615 | - //run the validation | |
| 616 | - if( !WP_User_Frontend.isValidURL( val ) ) { | |
| 617 | - error = true; | |
| 618 | - error_type = 'validation'; | |
| 619 | - | |
| 620 | - WP_User_Frontend.markError( item, error_type ); | |
| 621 | - } | |
| 622 | - } | |
| 623 | - break; | |
| 624 | - | |
| 625 | - }; | |
| 626 | - | |
| 627 | - }); | |
| 628 | - | |
| 629 | - //check Google Map is required | |
| 630 | - var map_required = self.find('[data-required="yes"][name="google_map"]'); | |
| 631 | - if ( map_required ) { | |
| 632 | - var val = $(map_required).val(); | |
| 633 | - if ( val == ',' ) { | |
| 634 | - error = true; | |
| 635 | - error_type = 'required'; | |
| 636 | - | |
| 637 | - WP_User_Frontend.markError( map_required, error_type ); | |
| 638 | - } | |
| 639 | - } | |
| 640 | - | |
| 641 | - // if already some error found, bail out | |
| 642 | - if (error) { | |
| 643 | - // add error notice | |
| 644 | - WP_User_Frontend.addErrorNotice(self,'end'); | |
| 645 | - | |
| 646 | - return false; | |
| 647 | - } | |
| 648 | - | |
| 649 | - var form_data = self.serialize(), | |
| 650 | - rich_texts = []; | |
| 651 | - | |
| 652 | - // grab rich texts from tinyMCE | |
| 653 | - $('.wpuf-rich-validation', self).each(function (index, item) { | |
| 654 | - var item = $(item); | |
| 655 | - var editor_id = item.data('id'); | |
| 656 | - var item_name = item.data('name'); | |
| 657 | - var val = $.trim( tinyMCE.get(editor_id).getContent() ); | |
| 658 | - | |
| 659 | - rich_texts.push(item_name + '=' + encodeURIComponent( val ) ); | |
| 660 | - }); | |
| 661 | - | |
| 662 | - // append them to the form var | |
| 663 | - form_data = form_data + '&' + rich_texts.join('&'); | |
| 664 | - return form_data; | |
| 665 | - }, | |
| 666 | - | |
| 667 | - /** | |
| 668 | - * | |
| 669 | - * @param form | |
| 670 | - * @param position (value = bottom or end) end if form is onepare, bottom, if form is multistep | |
| 671 | - */ | |
| 672 | - addErrorNotice: function( form, position ) { | |
| 673 | - if( position == 'bottom' ) { | |
| 674 | - $('.wpuf-multistep-fieldset:visible').append('<div class="wpuf-errors">' + wpuf_frontend.error_message + '</div>'); | |
| 675 | - } else { | |
| 676 | - $(form).find('li.wpuf-submit').append('<div class="wpuf-errors">' + wpuf_frontend.error_message + '</div>'); | |
| 677 | - } | |
| 678 | - | |
| 679 | - }, | |
| 680 | - | |
| 681 | - removeErrorNotice: function(form) { | |
| 682 | - $(form).find('.wpuf-errors').remove(); | |
| 683 | - }, | |
| 684 | - | |
| 685 | - markError: function(item, error_type) { | |
| 686 | - | |
| 687 | - var error_string = ''; | |
| 688 | - $(item).closest('li').addClass('has-error'); | |
| 689 | - | |
| 690 | - if ( error_type ) { | |
| 691 | - error_string = $(item).closest('li').data('label'); | |
| 692 | - switch ( error_type ) { | |
| 693 | - case 'required' : | |
| 694 | - error_string = error_string + ' ' + error_str_obj[error_type]; | |
| 695 | - break; | |
| 696 | - case 'mismatch' : | |
| 697 | - error_string = error_string + ' ' +error_str_obj[error_type]; | |
| 698 | - break; | |
| 699 | - case 'validation' : | |
| 700 | - error_string = error_string + ' ' + error_str_obj[error_type]; | |
| 701 | - break | |
| 702 | - } | |
| 703 | - $(item).siblings('.wpuf-error-msg').remove(); | |
| 704 | - $(item).after('<div class="wpuf-error-msg">'+ error_string +'</div>') | |
| 705 | - } | |
| 706 | - | |
| 707 | - $(item).focus(); | |
| 708 | - }, | |
| 709 | - | |
| 710 | - removeErrors: function(item) { | |
| 711 | - $(item).find('.has-error').removeClass('has-error'); | |
| 712 | - $('.wpuf-error-msg').remove(); | |
| 713 | - }, | |
| 714 | - | |
| 715 | - isValidEmail: function( email ) { | |
| 716 | - var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i); | |
| 717 | - return pattern.test(email); | |
| 718 | - }, | |
| 719 | - | |
| 720 | - isValidURL: function(url) { | |
| 721 | - var urlregex = new RegExp("^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.|http:\/\/|https:\/\/){1}([0-9A-Za-z]+\.)"); | |
| 722 | - return urlregex.test(url); | |
| 723 | - }, | |
| 724 | - | |
| 725 | - insertImage: function(button, form_id) { | |
| 726 | - | |
| 727 | - var container = 'wpuf-insert-image-container'; | |
| 728 | - | |
| 729 | - if ( ! $( '#' + button ).length ) { | |
| 730 | - return; | |
| 731 | - }; | |
| 732 | - | |
| 733 | - var imageUploader = new plupload.Uploader({ | |
| 734 | - runtimes: 'html5,html4', | |
| 735 | - browse_button: button, | |
| 736 | - container: container, | |
| 737 | - multipart: true, | |
| 738 | - multipart_params: { | |
| 739 | - action: 'wpuf_insert_image', | |
| 740 | - form_id: $( '#' + button ).data('form_id') | |
| 741 | - }, | |
| 742 | - multiple_queues: false, | |
| 743 | - multi_selection: false, | |
| 744 | - urlstream_upload: true, | |
| 745 | - file_data_name: 'wpuf_file', | |
| 746 | - max_file_size: '2mb', | |
| 747 | - url: wpuf_frontend_upload.plupload.url, | |
| 748 | - flash_swf_url: wpuf_frontend_upload.flash_swf_url, | |
| 749 | - filters: [{ | |
| 750 | - title: 'Allowed Files', | |
| 751 | - extensions: 'jpg,jpeg,gif,png,bmp' | |
| 752 | - }] | |
| 753 | - }); | |
| 754 | - | |
| 755 | - imageUploader.bind('Init', function(up, params) { | |
| 756 | - // console.log("Current runtime environment: " + params.runtime); | |
| 757 | - }); | |
| 758 | - | |
| 759 | - imageUploader.bind('FilesAdded', function(up, files) { | |
| 760 | - var $container = $('#' + container); | |
| 761 | - | |
| 762 | - $.each(files, function(i, file) { | |
| 763 | - $container.append( | |
| 764 | - '<div class="upload-item" id="' + file.id + '"><div class="progress progress-striped active"><div class="bar"></div></div></div>'); | |
| 765 | - }); | |
| 766 | - | |
| 767 | - up.refresh(); | |
| 768 | - up.start(); | |
| 769 | - }); | |
| 770 | - | |
| 771 | - imageUploader.bind('QueueChanged', function (uploader) { | |
| 772 | - imageUploader.start(); | |
| 773 | - }); | |
| 774 | - | |
| 775 | - imageUploader.bind('UploadProgress', function(up, file) { | |
| 776 | - var item = $('#' + file.id); | |
| 777 | - | |
| 778 | - $('.bar', item).css({ width: file.percent + '%' }); | |
| 779 | - $('.percent', item).html( file.percent + '%' ); | |
| 780 | - }); | |
| 781 | - | |
| 782 | - imageUploader.bind('Error', function(up, error) { | |
| 783 | - alert('Error #' + error.code + ': ' + error.message); | |
| 784 | - }); | |
| 785 | - | |
| 786 | - imageUploader.bind('FileUploaded', function(up, file, response) { | |
| 787 | - | |
| 788 | - $('#' + file.id).remove(); | |
| 789 | - | |
| 790 | - if ( response.response !== 'error' ) { | |
| 791 | - var success = false; | |
| 792 | - | |
| 793 | - if ( typeof tinyMCE !== 'undefined' ) { | |
| 794 | - | |
| 795 | - if ( typeof tinyMCE.execInstanceCommand !== 'function' ) { | |
| 796 | - // tinyMCE 4.x | |
| 797 | - var mce = tinyMCE.get( 'post_content_' + form_id ); | |
| 798 | - | |
| 799 | - if ( mce !== null ) { | |
| 800 | - mce.insertContent(response.response); | |
| 801 | - } | |
| 802 | - } else { | |
| 803 | - // tinyMCE 3.x | |
| 804 | - tinyMCE.execInstanceCommand( 'post_content_' + form_id, 'mceInsertContent', false, response.response); | |
| 805 | - } | |
| 806 | - } | |
| 807 | - | |
| 808 | - // insert failed to the edit, perhaps insert into textarea | |
| 809 | - var post_content = $('#post_content_' + form_id); | |
| 810 | - post_content.val( post_content.val() + response.response ); | |
| 811 | - | |
| 812 | - } else { | |
| 813 | - alert('Something went wrong'); | |
| 814 | - } | |
| 815 | - }); | |
| 816 | - | |
| 817 | - imageUploader.init(); | |
| 818 | - }, | |
| 819 | - | |
| 820 | - deleteAvatar: function(e) { | |
| 821 | - e.preventDefault(); | |
| 822 | - | |
| 823 | - if ( confirm( $(this).data('confirm') ) ) { | |
| 824 | - $.post(wpuf_frontend.ajaxurl, {action: 'wpuf_delete_avatar', _wpnonce: wpuf_frontend.nonce}, function() { | |
| 825 | - $(e.target).parent().remove(); | |
| 826 | - $('[id^=wpuf-avatar]').css("display", ""); | |
| 827 | - }); | |
| 828 | - } | |
| 829 | - }, | |
| 830 | - | |
| 831 | - editorLimit: { | |
| 832 | - | |
| 833 | - bind: function(limit, field, type) { | |
| 834 | - if ( type === 'no' ) { | |
| 835 | - // it's a textarea | |
| 836 | - $('textarea#' + field).keydown( function(event) { | |
| 837 | - WP_User_Frontend.editorLimit.textLimit.call(this, event, limit); | |
| 838 | - }); | |
| 839 | - | |
| 840 | - $('input#' + field).keydown( function(event) { | |
| 841 | - WP_User_Frontend.editorLimit.textLimit.call(this, event, limit); | |
| 842 | - }); | |
| 843 | - | |
| 844 | - $('textarea#' + field).on('paste', function(event) { | |
| 845 | - var self = $(this); | |
| 846 | - | |
| 847 | - setTimeout(function() { | |
| 848 | - WP_User_Frontend.editorLimit.textLimit.call(self, event, limit); | |
| 849 | - }, 100); | |
| 850 | - }); | |
| 851 | - | |
| 852 | - $('input#' + field).on('paste', function(event) { | |
| 853 | - var self = $(this); | |
| 854 | - | |
| 855 | - setTimeout(function() { | |
| 856 | - WP_User_Frontend.editorLimit.textLimit.call(self, event, limit); | |
| 857 | - }, 100); | |
| 858 | - }); | |
| 859 | - | |
| 860 | - } else { | |
| 861 | - // it's a rich textarea | |
| 862 | - setTimeout(function () { | |
| 863 | - tinyMCE.get(field).onKeyDown.add(function(ed, event) { | |
| 864 | - WP_User_Frontend.editorLimit.tinymce.onKeyDown(ed, event, limit); | |
| 865 | - } ); | |
| 866 | - | |
| 867 | - tinyMCE.get(field).onPaste.add(function(ed, event) { | |
| 868 | - setTimeout(function() { | |
| 869 | - WP_User_Frontend.editorLimit.tinymce.onPaste(ed, event, limit); | |
| 870 | - }, 100); | |
| 871 | - }); | |
| 872 | - | |
| 873 | - }, 1000); | |
| 874 | - } | |
| 875 | - }, | |
| 876 | - | |
| 877 | - tinymce: { | |
| 878 | - | |
| 879 | - getStats: function(ed) { | |
| 880 | - var body = ed.getBody(), text = tinymce.trim(body.innerText || body.textContent); | |
| 881 | - | |
| 882 | - return { | |
| 883 | - chars: text.length, | |
| 884 | - words: text.split(/[\w\u2019\'-]+/).length | |
| 885 | - }; | |
| 886 | - }, | |
| 887 | - | |
| 888 | - onKeyDown: function(ed, event, limit) { | |
| 889 | - var numWords = WP_User_Frontend.editorLimit.tinymce.getStats(ed).words - 1; | |
| 890 | - | |
| 891 | - limit ? $('.mce-path-item.mce-last', ed.container).html('Word Limit : '+ numWords +'/'+limit):''; | |
| 892 | - | |
| 893 | - if ( limit && numWords > limit ) { | |
| 894 | - WP_User_Frontend.editorLimit.blockTyping(event); | |
| 895 | - jQuery('.mce-path-item.mce-last', ed.container).html( wpuf_frontend.word_limit ); | |
| 896 | - } | |
| 897 | - }, | |
| 898 | - | |
| 899 | - onPaste: function(ed, event, limit) { | |
| 900 | - var editorContent = ed.getContent().split(' ').slice(0, limit).join(' '); | |
| 901 | - | |
| 902 | - // Let TinyMCE do the heavy lifting for inserting that content into the editor. | |
| 903 | - // ed.insertContent(content); //ed.execCommand('mceInsertContent', false, content); | |
| 904 | - ed.setContent(editorContent); | |
| 905 | - | |
| 906 | - WP_User_Frontend.editorLimit.make_media_embed_code(editorContent, ed); | |
| 907 | - } | |
| 908 | - }, | |
| 909 | - | |
| 910 | - textLimit: function(event, limit) { | |
| 911 | - var self = $(this), | |
| 912 | - content = self.val().split(' '); | |
| 913 | - | |
| 914 | - if ( limit && content.length > limit ) { | |
| 915 | - self.closest('.wpuf-fields').find('span.wpuf-wordlimit-message').html( wpuf_frontend.word_limit ); | |
| 916 | - WP_User_Frontend.editorLimit.blockTyping(event); | |
| 917 | - } else { | |
| 918 | - self.closest('.wpuf-fields').find('span.wpuf-wordlimit-message').html(''); | |
| 919 | - } | |
| 920 | - | |
| 921 | - // handle the paste event | |
| 922 | - if ( event.type === 'paste' ) { | |
| 923 | - self.val( content.slice(0, limit).join( ' ' ) ); | |
| 924 | - } | |
| 925 | - }, | |
| 926 | - | |
| 927 | - blockTyping: function(event) { | |
| 928 | - // Allow: backspace, delete, tab, escape, minus enter and . backspace = 8,delete=46,tab=9,enter=13,.=190,escape=27, minus = 189 | |
| 929 | - if ($.inArray(event.keyCode, [46, 8, 9, 27, 13, 110, 190, 189]) !== -1 || | |
| 930 | - // Allow: Ctrl+A | |
| 931 | - (event.keyCode == 65 && event.ctrlKey === true) || | |
| 932 | - // Allow: home, end, left, right, down, up | |
| 933 | - (event.keyCode >= 35 && event.keyCode <= 40)) { | |
| 934 | - // let it happen, don't do anything | |
| 935 | - return; | |
| 936 | - } | |
| 937 | - | |
| 938 | - event.preventDefault(); | |
| 939 | - event.stopPropagation(); | |
| 940 | - }, | |
| 941 | - | |
| 942 | - make_media_embed_code: function(content, editor){ | |
| 943 | - $.post( ajaxurl, { | |
| 944 | - action:'make_media_embed_code', | |
| 945 | - content: content | |
| 946 | - }, | |
| 947 | - function(data){ | |
| 948 | - // console.log(data); | |
| 949 | - editor.setContent(editor.getContent() + editor.setContent(data)); | |
| 950 | - } | |
| 951 | - ) | |
| 952 | - } | |
| 953 | - } | |
| 954 | - }; | |
| 955 | - | |
| 956 | - $(function() { | |
| 957 | - WP_User_Frontend.init(); | |
| 958 | - | |
| 959 | - // payment gateway selection | |
| 960 | - $('ul.wpuf-payment-gateways').on('click', 'input[type=radio]', function(e) { | |
| 961 | - $('.wpuf-payment-instruction').slideUp(250); | |
| 962 | - | |
| 963 | - $(this).parents('li').find('.wpuf-payment-instruction').slideDown(250); | |
| 964 | - }); | |
| 965 | - | |
| 966 | - if( !$('ul.wpuf-payment-gateways li').find('input[type=radio]').is(':checked') ) { | |
| 967 | - $('ul.wpuf-payment-gateways li').first().find('input[type=radio]').click() | |
| 968 | - } else { | |
| 969 | - var el = $('ul.wpuf-payment-gateways li').find('input[type=radio]:checked'); | |
| 970 | - el.parents('li').find('.wpuf-payment-instruction').slideDown(250); | |
| 971 | - } | |
| 972 | - }); | |
| 973 | - | |
| 974 | - $(function() { | |
| 975 | - $('input[name="first_name"], input[name="last_name"]').on('change keyup', function() { | |
| 976 | - var myVal, newVal = $.makeArray($('input[name="first_name"], input[name="last_name"]').map(function(){ | |
| 977 | - if (myVal = $(this).val()) { | |
| 978 | - return(myVal); | |
| 979 | - } | |
| 980 | - })).join(' '); | |
| 981 | - $('input[name="display_name"]').val(newVal); | |
| 982 | - }); | |
| 983 | - }); | |
| 984 | - | |
| 985 | - // script for Dokan vendor registration template | |
| 986 | - $(function($) { | |
| 987 | - | |
| 988 | - $('.wpuf-form-add input[name="dokan_store_name"]').on('focusout', function() { | |
| 989 | - var value = $(this).val().toLowerCase().replace(/-+/g, '').replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, ''); | |
| 990 | - $('input[name="shopurl"]').val(value); | |
| 991 | - $('#url-alart').text( value ); | |
| 992 | - $('input[name="shopurl"]').focus(); | |
| 993 | - }); | |
| 994 | - | |
| 995 | - $('.wpuf-form-add input[name="shopurl"]').keydown(function(e) { | |
| 996 | - var text = $(this).val(); | |
| 997 | - | |
| 998 | - // Allow: backspace, delete, tab, escape, enter and . | |
| 999 | - if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 91, 109, 110, 173, 189, 190]) !== -1 || | |
| 1000 | - // Allow: Ctrl+A | |
| 1001 | - (e.keyCode == 65 && e.ctrlKey === true) || | |
| 1002 | - // Allow: home, end, left, right | |
| 1003 | - (e.keyCode >= 35 && e.keyCode <= 39)) { | |
| 1004 | - // let it happen, don't do anything | |
| 1005 | - return; | |
| 1006 | - } | |
| 1007 | - | |
| 1008 | - if ((e.shiftKey || (e.keyCode < 65 || e.keyCode > 90) && (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105) ) { | |
| 1009 | - e.preventDefault(); | |
| 1010 | - } | |
| 1011 | - }); | |
| 1012 | - | |
| 1013 | - $('.wpuf-form-add input[name="shopurl"]').keyup(function(e) { | |
| 1014 | - $('#url-alart').text( $(this).val() ); | |
| 1015 | - }); | |
| 1016 | - | |
| 1017 | - $('.wpuf-form-add input[name="shopurl"]').on('focusout', function() { | |
| 1018 | - var self = $(this), | |
| 1019 | - data = { | |
| 1020 | - action : 'shop_url', | |
| 1021 | - url_slug : self.val(), | |
| 1022 | - _nonce : dokan.nonce, | |
| 1023 | - }; | |
| 1024 | - | |
| 1025 | - if ( self.val() === '' ) { | |
| 1026 | - return; | |
| 1027 | - } | |
| 1028 | - | |
| 1029 | - $.post( dokan.ajaxurl, data, function(resp) { | |
| 1030 | - | |
| 1031 | - if ( resp == 0){ | |
| 1032 | - $('#url-alart').removeClass('text-success').addClass('text-danger'); | |
| 1033 | - $('#url-alart-mgs').removeClass('text-success').addClass('text-danger').text(dokan.seller.notAvailable); | |
| 1034 | - } else { | |
| 1035 | - $('#url-alart').removeClass('text-danger').addClass('text-success'); | |
| 1036 | - $('#url-alart-mgs').removeClass('text-danger').addClass('text-success').text(dokan.seller.available); | |
| 1037 | - } | |
| 1038 | - | |
| 1039 | - } ); | |
| 1040 | - | |
| 1041 | - }); | |
| 1042 | - | |
| 1043 | - // Set name attribute for google map search field | |
| 1044 | - $(".wpuf-form-add #wpuf-map-add-location").attr("name", "find_address"); | |
| 1045 | - }); | |
| 1046 | - | |
| 1047 | -})(jQuery, window); | |
| 2 | +;(function($, window) { | |
| 1048 | 3 | |
| 4 | + $.fn.listautowidth = function() { | |
| 5 | + return this.each(function() { | |
| 6 | + var w = $(this).width(); | |
| 7 | + var liw = w / $(this).children('li').length; | |
| 8 | + $(this).children('li').each(function(){ | |
| 9 | + var s = $(this).outerWidth(true)-$(this).width(); | |
| 10 | + $(this).width(liw-s); | |
| 11 | + }); | |
| 12 | + }); | |
| 13 | + }; | |
| 14 | + | |
| 15 | + window.WP_User_Frontend = { | |
| 16 | + | |
| 17 | + init: function() { | |
| 18 | + | |
| 19 | + //enable multistep | |
| 20 | + this.enableMultistep(this); | |
| 21 | + | |
| 22 | + // clone and remove repeated field | |
| 23 | + $('.wpuf-form').on('click', 'img.wpuf-clone-field', this.cloneField); | |
| 24 | + $('.wpuf-form').on('click', 'img.wpuf-remove-field', this.removeField); | |
| 25 | + $('.wpuf-form').on('click', 'a.wpuf-delete-avatar', this.deleteAvatar); | |
| 26 | + $('.wpuf-form').on('click', 'a#wpuf-post-draft', this.draftPost); | |
| 27 | + $('.wpuf-form').on('click', 'button#wpuf-account-update-profile', this.account_update_profile); | |
| 28 | + | |
| 29 | + $('.wpuf-form-add').on('submit', this.formSubmit); | |
| 30 | + $('form#post').on('submit', this.adminPostSubmit); | |
| 31 | + // $( '.wpuf-form').on('keyup', '#pass1', this.check_pass_strength ); | |
| 32 | + | |
| 33 | + // refresh pluploads on each step change (multistep form) | |
| 34 | + $('.wpuf-form').on('step-change-fieldset', function(event, number, step) { | |
| 35 | + if ( wpuf_plupload_items.length ) { | |
| 36 | + for (var i = wpuf_plupload_items.length - 1; i >= 0; i--) { | |
| 37 | + wpuf_plupload_items[i].refresh(); | |
| 38 | + } | |
| 39 | + } | |
| 40 | + if ( wpuf_map_items.length ) { | |
| 41 | + for (var i = wpuf_map_items.length - 1; i >= 0; i--) { | |
| 42 | + google.maps.event.trigger(wpuf_map_items[i].map, 'resize'); | |
| 43 | + wpuf_map_items[i].map.setCenter(wpuf_map_items[i].center); | |
| 44 | + } | |
| 45 | + } | |
| 46 | + }); | |
| 47 | + | |
| 48 | + this.ajaxCategory(); | |
| 49 | + // image insert | |
| 50 | + // this.insertImage(); | |
| 51 | + | |
| 52 | + //comfirmation alert for canceling subscription | |
| 53 | + $( ':submit[name="wpuf_user_subscription_cancel"]').click(function(e){ | |
| 54 | + e.preventDefault(); | |
| 55 | + | |
| 56 | + swal({ | |
| 57 | + text: wpuf_frontend.cancelSubMsg, | |
| 58 | + type: 'warning', | |
| 59 | + showCancelButton: true, | |
| 60 | + confirmButtonColor: '#d54e21', | |
| 61 | + confirmButtonText: wpuf_frontend.delete_it, | |
| 62 | + cancelButtonText: wpuf_frontend.cancel_it, | |
| 63 | + confirmButtonClass: 'btn btn-success', | |
| 64 | + cancelButtonClass: 'btn btn-danger', | |
| 65 | + }).then(function ( isConfirmed ) { | |
| 66 | + if ( !isConfirmed ) { | |
| 67 | + return false; | |
| 68 | + } | |
| 69 | + $('#wpuf_cancel_subscription').submit(); | |
| 70 | + }); | |
| 71 | + }); | |
| 72 | + }, | |
| 73 | + | |
| 74 | + check_pass_strength : function() { | |
| 75 | + var pass1 = $('#pass1').val(), strength; | |
| 76 | + | |
| 77 | + $('#pass-strength-result').show(); | |
| 78 | + | |
| 79 | + $('#pass-strength-result').removeClass('short bad good strong'); | |
| 80 | + if ( ! pass1 ) { | |
| 81 | + $('#pass-strength-result').html( ' ' ); | |
| 82 | + $('#pass-strength-result').hide(); | |
| 83 | + return; | |
| 84 | + } | |
| 85 | + | |
| 86 | + if ( typeof wp.passwordStrength != 'undefined' ) { | |
| 87 | + | |
| 88 | + strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputBlacklist(), pass1 ); | |
| 89 | + | |
| 90 | + switch ( strength ) { | |
| 91 | + case 2: | |
| 92 | + $('#pass-strength-result').addClass('bad').html( pwsL10n.bad ); | |
| 93 | + break; | |
| 94 | + case 3: | |
| 95 | + $('#pass-strength-result').addClass('good').html( pwsL10n.good ); | |
| 96 | + break; | |
| 97 | + case 4: | |
| 98 | + $('#pass-strength-result').addClass('strong').html( pwsL10n.strong ); | |
| 99 | + break; | |
| 100 | + case 5: | |
| 101 | + $('#pass-strength-result').addClass('short').html( pwsL10n.mismatch ); | |
| 102 | + break; | |
| 103 | + default: | |
| 104 | + $('#pass-strength-result').addClass('short').html( pwsL10n['short'] ); | |
| 105 | + } | |
| 106 | + | |
| 107 | + } | |
| 108 | + }, | |
| 109 | + | |
| 110 | + enableMultistep: function(o) { | |
| 111 | + | |
| 112 | + var js_obj = this; | |
| 113 | + var step_number = 0; | |
| 114 | + var progressbar_type = $(':hidden[name="wpuf_multistep_type"]').val(); | |
| 115 | + | |
| 116 | + if ( progressbar_type == null ) { | |
| 117 | + return; | |
| 118 | + } | |
| 119 | + | |
| 120 | + // first fieldset doesn't have prev button, | |
| 121 | + // last fieldset doesn't have next button | |
| 122 | + $('fieldset.wpuf-multistep-fieldset').find('.wpuf-multistep-prev-btn').first().remove(); | |
| 123 | + $('fieldset.wpuf-multistep-fieldset').find('.wpuf-multistep-next-btn').last().remove(); | |
| 124 | + | |
| 125 | + // at first first fieldset will be shown, and others will be hidden | |
| 126 | + $('.wpuf-form fieldset').removeClass('field-active').first().addClass('field-active'); | |
| 127 | + | |
| 128 | + if ( progressbar_type == 'progressive' && $('.wpuf-form .wpuf-multistep-fieldset').length != 0 ) { | |
| 129 | + | |
| 130 | + var firstLegend = $('fieldset.wpuf-multistep-fieldset legend').first(); | |
| 131 | + $('.wpuf-multistep-progressbar').html('<div class="wpuf-progress-percentage"></div>' ); | |
| 132 | + | |
| 133 | + var progressbar = $( ".wpuf-multistep-progressbar" ), | |
| 134 | + progressLabel = $( ".wpuf-progress-percentage" ); | |
| 135 | + | |
| 136 | + $( ".wpuf-multistep-progressbar" ).progressbar({ | |
| 137 | + change: function() { | |
| 138 | + progressLabel.text( progressbar.progressbar( "value" ) + "%" ); | |
| 139 | + } | |
| 140 | + }); | |
| 141 | + | |
| 142 | + $('.wpuf-multistep-fieldset legend').hide(); | |
| 143 | + | |
| 144 | + } else { | |
| 145 | + $('.wpuf-form').each(function() { | |
| 146 | + var this_obj = $(this); | |
| 147 | + var progressbar = $('.wpuf-multistep-progressbar', this_obj); | |
| 148 | + var nav = ''; | |
| 149 | + | |
| 150 | + progressbar.addClass('wizard-steps'); | |
| 151 | + nav += '<ul class="wpuf-step-wizard">'; | |
| 152 | + | |
| 153 | + $('.wpuf-multistep-fieldset', this).each(function(){ | |
| 154 | + nav += '<li>' + $.trim( $('legend', this).text() ) + '</li>'; | |
| 155 | + $('legend', this).hide(); | |
| 156 | + }); | |
| 157 | + | |
| 158 | + nav += '</ul>'; | |
| 159 | + progressbar.append( nav ); | |
| 160 | + | |
| 161 | + $('.wpuf-step-wizard li', progressbar).first().addClass('active-step'); | |
| 162 | + $('.wpuf-step-wizard', progressbar).listautowidth(); | |
| 163 | + }); | |
| 164 | + } | |
| 165 | + | |
| 166 | + this.change_fieldset(step_number, progressbar_type); | |
| 167 | + | |
| 168 | + $('fieldset .wpuf-multistep-prev-btn, fieldset .wpuf-multistep-next-btn').click(function(e) { | |
| 169 | + // js_obj.formSubmit(); | |
| 170 | + if ( $(this).hasClass('wpuf-multistep-next-btn') ) { | |
| 171 | + var result = js_obj.formStepCheck( '', $(this).closest('fieldset') ); | |
| 172 | + | |
| 173 | + if ( result != false ) { | |
| 174 | + o.change_fieldset(++step_number,progressbar_type); | |
| 175 | + } | |
| 176 | + | |
| 177 | + } else if ( $(this).hasClass('wpuf-multistep-prev-btn') ) { | |
| 178 | + o.change_fieldset( --step_number,progressbar_type ); | |
| 179 | + } | |
| 180 | + | |
| 181 | + var formDiv = $( "form.wpuf-form-add" ); | |
| 182 | + var position = formDiv.offset().top; | |
| 183 | + | |
| 184 | + // this changes the scrolling behavior to "smooth" | |
| 185 | + window.scrollTo({ | |
| 186 | + top: position - 32, | |
| 187 | + behavior: "smooth" | |
| 188 | + }); | |
| 189 | + | |
| 190 | + return false; | |
| 191 | + }); | |
| 192 | + }, | |
| 193 | + | |
| 194 | + change_fieldset: function(step_number, progressbar_type) { | |
| 195 | + var current_step = $('fieldset.wpuf-multistep-fieldset').eq(step_number); | |
| 196 | + | |
| 197 | + $('fieldset.wpuf-multistep-fieldset').removeClass('field-active').eq(step_number).addClass('field-active'); | |
| 198 | + | |
| 199 | + $('.wpuf-step-wizard li').each(function(){ | |
| 200 | + if ( $(this).index() <= step_number ){ | |
| 201 | + progressbar_type == 'step_by_step'? $(this).addClass('passed-wpuf-ms-bar') : $('.wpuf-ps-bar',this).addClass('passed-wpuf-ms-bar'); | |
| 202 | + } else { | |
| 203 | + progressbar_type == 'step_by_step'? $(this).removeClass('passed-wpuf-ms-bar') : $('.wpuf-ps-bar',this).removeClass('passed-wpuf-ms-bar'); | |
| 204 | + } | |
| 205 | + }); | |
| 206 | + | |
| 207 | + $('.wpuf-step-wizard li').removeClass('wpuf-ms-bar-active active-step completed-step'); | |
| 208 | + $('.passed-wpuf-ms-bar').addClass('completed-step').last().addClass('wpuf-ms-bar-active'); | |
| 209 | + $('.wpuf-ms-bar-active').addClass('active-step'); | |
| 210 | + | |
| 211 | + var legend = $('fieldset.wpuf-multistep-fieldset').eq(step_number).find('legend').text(); | |
| 212 | + legend = $.trim( legend ); | |
| 213 | + | |
| 214 | + if ( progressbar_type == 'progressive' && $('.wpuf-form .wpuf-multistep-fieldset').length != 0 ) { | |
| 215 | + var progress_percent = ( step_number + 1 ) * 100 / $('fieldset.wpuf-multistep-fieldset').length ; | |
| 216 | + var progress_percent = Number( progress_percent.toFixed(2) ); | |
| 217 | + $( ".wpuf-multistep-progressbar" ).progressbar({value: progress_percent }); | |
| 218 | + $( '.wpuf-progress-percentage' ).text( legend + ' (' + progress_percent + '%)'); | |
| 219 | + } | |
| 220 | + | |
| 221 | + // trigger a change event | |
| 222 | + $('.wpuf-form').trigger('step-change-fieldset', [ step_number, current_step ]); | |
| 223 | + }, | |
| 224 | + | |
| 225 | + ajaxCategory: function () { | |
| 226 | + | |
| 227 | + var el = '.cat-ajax', | |
| 228 | + wrap = '.category-wrap'; | |
| 229 | + | |
| 230 | + $(wrap).on('change', el, function(){ | |
| 231 | + currentLevel = parseInt( $(this).parent().attr('level') ); | |
| 232 | + WP_User_Frontend.getChildCats( $(this), 'lvl', currentLevel+1, wrap, 'category'); | |
| 233 | + }); | |
| 234 | + }, | |
| 235 | + | |
| 236 | + getChildCats: function (dropdown, result_div, level, wrap_div, taxonomy) { | |
| 237 | + | |
| 238 | + cat = $(dropdown).val(); | |
| 239 | + results_div = result_div + level; | |
| 240 | + taxonomy = typeof taxonomy !== 'undefined' ? taxonomy : 'category'; | |
| 241 | + field_attr = $(dropdown).siblings('span').data('taxonomy'); | |
| 242 | + | |
| 243 | + $.ajax({ | |
| 244 | + type: 'post', | |
| 245 | + url: wpuf_frontend.ajaxurl, | |
| 246 | + data: { | |
| 247 | + action: 'wpuf_get_child_cat', | |
| 248 | + catID: cat, | |
| 249 | + nonce: wpuf_frontend.nonce, | |
| 250 | + field_attr: field_attr | |
| 251 | + }, | |
| 252 | + beforeSend: function() { | |
| 253 | + $(dropdown).parent().parent().next('.loading').addClass('wpuf-loading'); | |
| 254 | + }, | |
| 255 | + complete: function() { | |
| 256 | + $(dropdown).parent().parent().next('.loading').removeClass('wpuf-loading'); | |
| 257 | + }, | |
| 258 | + success: function(html) { | |
| 259 | + //console.log( html ); return; | |
| 260 | + $(dropdown).parent().nextAll().each(function(){ | |
| 261 | + $(this).remove(); | |
| 262 | + }); | |
| 263 | + | |
| 264 | + if(html != "") { | |
| 265 | + $(dropdown).parent().addClass('hasChild').parent().append('<div id="'+result_div+level+'" level="'+level+'"></div>'); | |
| 266 | + dropdown.parent().parent().find('#'+results_div).html(html).slideDown('fast'); | |
| 267 | + } | |
| 268 | + } | |
| 269 | + }); | |
| 270 | + }, | |
| 271 | + | |
| 272 | + cloneField: function(e) { | |
| 273 | + e.preventDefault(); | |
| 274 | + | |
| 275 | + var $div = $(this).closest('tr'); | |
| 276 | + var $clone = $div.clone(); | |
| 277 | + // console.log($clone); | |
| 278 | + | |
| 279 | + //clear the inputs | |
| 280 | + $clone.find('input').val(''); | |
| 281 | + $clone.find(':checked').attr('checked', ''); | |
| 282 | + $div.after($clone); | |
| 283 | + }, | |
| 284 | + | |
| 285 | + removeField: function() { | |
| 286 | + //check if it's the only item | |
| 287 | + var $parent = $(this).closest('tr'); | |
| 288 | + var items = $parent.siblings().andSelf().length; | |
| 289 | + | |
| 290 | + if( items > 1 ) { | |
| 291 | + $parent.remove(); | |
| 292 | + } | |
| 293 | + }, | |
| 294 | + | |
| 295 | + adminPostSubmit: function(e) { | |
| 296 | + e.preventDefault(); | |
| 297 | + | |
| 298 | + var form = $(this), | |
| 299 | + form_data = WP_User_Frontend.validateForm(form); | |
| 300 | + | |
| 301 | + if (form_data) { | |
| 302 | + return true; | |
| 303 | + } | |
| 304 | + }, | |
| 305 | + | |
| 306 | + draftPost: function (e) { | |
| 307 | + e.preventDefault(); | |
| 308 | + | |
| 309 | + var self = $(this), | |
| 310 | + form = $(this).closest('form'), | |
| 311 | + form_data = form.serialize() + '&action=wpuf_draft_post', | |
| 312 | + post_id = form.find('input[type="hidden"][name="post_id"]').val(); | |
| 313 | + | |
| 314 | + var rich_texts = [], | |
| 315 | + val; | |
| 316 | + | |
| 317 | + // grab rich texts from tinyMCE | |
| 318 | + $('.wpuf-rich-validation').each(function (index, item) { | |
| 319 | + var item = $(item); | |
| 320 | + var editor_id = item.data('id'); | |
| 321 | + var item_name = item.data('name'); | |
| 322 | + var val = $.trim( tinyMCE.get(editor_id).getContent() ); | |
| 323 | + | |
| 324 | + rich_texts.push(item_name + '=' + encodeURIComponent( val ) ); | |
| 325 | + }); | |
| 326 | + | |
| 327 | + // append them to the form var | |
| 328 | + form_data = form_data + '&' + rich_texts.join('&'); | |
| 329 | + | |
| 330 | + | |
| 331 | + self.after(' <span class="wpuf-loading"></span>'); | |
| 332 | + $.post(wpuf_frontend.ajaxurl, form_data, function(res) { | |
| 333 | + // console.log(res, post_id); | |
| 334 | + if ( typeof post_id === 'undefined') { | |
| 335 | + var html = '<input type="hidden" name="post_id" value="' + res.post_id +'">'; | |
| 336 | + html += '<input type="hidden" name="post_date" value="' + res.date +'">'; | |
| 337 | + html += '<input type="hidden" name="post_author" value="' + res.post_author +'">'; | |
| 338 | + html += '<input type="hidden" name="comment_status" value="' + res.comment_status +'">'; | |
| 339 | + | |
| 340 | + form.append( html ); | |
| 341 | + } | |
| 342 | + | |
| 343 | + self.next('span.wpuf-loading').remove(); | |
| 344 | + | |
| 345 | + self.after('<span class="wpuf-draft-saved"> Post Saved</span>'); | |
| 346 | + $('.wpuf-draft-saved').delay(2500).fadeOut('fast', function(){ | |
| 347 | + $(this).remove(); | |
| 348 | + }); | |
| 349 | + }) | |
| 350 | + }, | |
| 351 | + | |
| 352 | + // Frontend account dashboard update profile | |
| 353 | + account_update_profile: function (e) { | |
| 354 | + e.preventDefault(); | |
| 355 | + var form = $(this).closest('form'); | |
| 356 | + | |
| 357 | + $.post(wpuf_frontend.ajaxurl, form.serialize(), function (res) { | |
| 358 | + if (res.success) { | |
| 359 | + form.find('.wpuf-error').hide(); | |
| 360 | + form.find('.wpuf-success').show(); | |
| 361 | + } else { | |
| 362 | + form.find('.wpuf-success').hide(); | |
| 363 | + form.find('.wpuf-error').show(); | |
| 364 | + form.find('.wpuf-error').text(res.data); | |
| 365 | + } | |
| 366 | + }); | |
| 367 | + }, | |
| 368 | + | |
| 369 | + formStepCheck : function(e,fieldset) { | |
| 370 | + var form = fieldset, | |
| 371 | + submitButton = form.find('input[type=submit]'); | |
| 372 | + form_data = WP_User_Frontend.validateForm(form); | |
| 373 | + | |
| 374 | + if ( form_data == false ) { | |
| 375 | + WP_User_Frontend.addErrorNotice( self, 'bottom' ); | |
| 376 | + } | |
| 377 | + return form_data; | |
| 378 | + }, | |
| 379 | + | |
| 380 | + formSubmit: function(e) { | |
| 381 | + e.preventDefault(); | |
| 382 | + | |
| 383 | + var form = $(this), | |
| 384 | + submitButton = form.find('input[type=submit]') | |
| 385 | + form_data = WP_User_Frontend.validateForm(form); | |
| 386 | + | |
| 387 | + if (form_data) { | |
| 388 | + | |
| 389 | + // send the request | |
| 390 | + form.find('li.wpuf-submit').append('<span class="wpuf-loading"></span>'); | |
| 391 | + submitButton.attr('disabled', 'disabled').addClass('button-primary-disabled'); | |
| 392 | + | |
| 393 | + $.post(wpuf_frontend.ajaxurl, form_data, function(res) { | |
| 394 | + // var res = $.parseJSON(res); | |
| 395 | + | |
| 396 | + if ( res.success) { | |
| 397 | + | |
| 398 | + // enable external plugins to use events | |
| 399 | + $('body').trigger('wpuf:postform:success', res); | |
| 400 | + | |
| 401 | + if ( res.show_message == true) { | |
| 402 | + form.before( '<div class="wpuf-success">' + res.message + '</div>'); | |
| 403 | + form.slideUp( 'fast', function() { | |
| 404 | + form.remove(); | |
| 405 | + }); | |
| 406 | + | |
| 407 | + //focus | |
| 408 | + $('html, body').animate({ | |
| 409 | + scrollTop: $('.wpuf-success').offset().top - 100 | |
| 410 | + }, 'fast'); | |
| 411 | + | |
| 412 | + } else { | |
| 413 | + window.location = res.redirect_to; | |
| 414 | + } | |
| 415 | + | |
| 416 | + } else { | |
| 417 | + | |
| 418 | + if ( typeof res.type !== 'undefined' && res.type === 'login' ) { | |
| 419 | + | |
| 420 | + if ( confirm(res.error) ) { | |
| 421 | + window.location = res.redirect_to; | |
| 422 | + } else { | |
| 423 | + submitButton.removeAttr('disabled'); | |
| 424 | + submitButton.removeClass('button-primary-disabled'); | |
| 425 | + form.find('span.wpuf-loading').remove(); | |
| 426 | + } | |
| 427 | + | |
| 428 | + return; | |
| 429 | + } else { | |
| 430 | + if ( form.find('.g-recaptcha').length > 0 ) { | |
| 431 | + grecaptcha.reset(); | |
| 432 | + } | |
| 433 | + | |
| 434 | + swal({ | |
| 435 | + html: res.error, | |
| 436 | + type: 'warning', | |
| 437 | + showCancelButton: false, | |
| 438 | + confirmButtonColor: '#d54e21', | |
| 439 | + confirmButtonText: 'OK', | |
| 440 | + cancelButtonClass: 'btn btn-danger', | |
| 441 | + }); | |
| 442 | + | |
| 443 | + } | |
| 444 | + | |
| 445 | + submitButton.removeAttr('disabled'); | |
| 446 | + } | |
| 447 | + | |
| 448 | + submitButton.removeClass('button-primary-disabled'); | |
| 449 | + form.find('span.wpuf-loading').remove(); | |
| 450 | + }); | |
| 451 | + } | |
| 452 | + }, | |
| 453 | + | |
| 454 | + validateForm: function( self ) { | |
| 455 | + | |
| 456 | + var temp, | |
| 457 | + temp_val = '', | |
| 458 | + error = false, | |
| 459 | + error_items = []; | |
| 460 | + error_type = ''; | |
| 461 | + | |
| 462 | + // remove all initial errors if any | |
| 463 | + WP_User_Frontend.removeErrors(self); | |
| 464 | + WP_User_Frontend.removeErrorNotice(self); | |
| 465 | + | |
| 466 | + // ===== Validate: Text and Textarea ======== | |
| 467 | + var required = self.find('[data-required="yes"]:visible'); | |
| 468 | + | |
| 469 | + required.each(function(i, item) { | |
| 470 | + // temp_val = $.trim($(item).val()); | |
| 471 | + | |
| 472 | + // console.log( $(item).data('type') ); | |
| 473 | + var data_type = $(item).data('type') | |
| 474 | + val = ''; | |
| 475 | + | |
| 476 | + switch(data_type) { | |
| 477 | + case 'rich': | |
| 478 | + var name = $(item).data('id') | |
| 479 | + val = $.trim( tinyMCE.get(name).getContent() ); | |
| 480 | + | |
| 481 | + if ( val === '') { | |
| 482 | + error = true; | |
| 483 | + | |
| 484 | + // make it warn collor | |
| 485 | + WP_User_Frontend.markError(item); | |
| 486 | + } | |
| 487 | + break; | |
| 488 | + | |
| 489 | + case 'textarea': | |
| 490 | + case 'text': | |
| 491 | + | |
| 492 | + val = $.trim( $(item).val() ); | |
| 493 | + | |
| 494 | + if ( val === '') { | |
| 495 | + error = true; | |
| 496 | + error_type = 'required'; | |
| 497 | + | |
| 498 | + // make it warn collor | |
| 499 | + WP_User_Frontend.markError( item, error_type ); | |
| 500 | + } | |
| 501 | + break; | |
| 502 | + | |
| 503 | + case 'password': | |
| 504 | + case 'confirm_password': | |
| 505 | + var hasRepeat = $(item).data('repeat'); | |
| 506 | + | |
| 507 | + val = $.trim( $(item).val() ); | |
| 508 | + | |
| 509 | + if ( val === '') { | |
| 510 | + error = true; | |
| 511 | + error_type = 'required'; | |
| 512 | + | |
| 513 | + // make it warn collor | |
| 514 | + WP_User_Frontend.markError( item, error_type ); | |
| 515 | + } | |
| 516 | + | |
| 517 | + if ( hasRepeat ) { | |
| 518 | + var repeatItem = $('[data-type="confirm_password"]').eq(0);; | |
| 519 | + | |
| 520 | + if ( repeatItem.val() != val ) { | |
| 521 | + error = true; | |
| 522 | + error_type = 'mismatch'; | |
| 523 | + | |
| 524 | + WP_User_Frontend.markError( repeatItem, error_type ); | |
| 525 | + } | |
| 526 | + } | |
| 527 | + | |
| 528 | + break; | |
| 529 | + | |
| 530 | + case 'select': | |
| 531 | + val = $(item).val(); | |
| 532 | + | |
| 533 | + // console.log(val); | |
| 534 | + if ( !val || val === '-1' ) { | |
| 535 | + error = true; | |
| 536 | + error_type = 'required'; | |
| 537 | + | |
| 538 | + // make it warn collor | |
| 539 | + WP_User_Frontend.markError( item, error_type ); | |
| 540 | + } | |
| 541 | + break; | |
| 542 | + | |
| 543 | + case 'multiselect': | |
| 544 | + val = $(item).val(); | |
| 545 | + | |
| 546 | + if ( val === null || val.length === 0 ) { | |
| 547 | + error = true; | |
| 548 | + error_type = 'required'; | |
| 549 | + | |
| 550 | + // make it warn collor | |
| 551 | + WP_User_Frontend.markError( item, error_type ); | |
| 552 | + } | |
| 553 | + break; | |
| 554 | + | |
| 555 | + case 'tax-checkbox': | |
| 556 | + var length = $(item).children().find('input:checked').length; | |
| 557 | + | |
| 558 | + if ( !length ) { | |
| 559 | + error = true; | |
| 560 | + error_type = 'required'; | |
| 561 | + | |
| 562 | + // make it warn collor | |
| 563 | + WP_User_Frontend.markError( item, error_type ); | |
| 564 | + } | |
| 565 | + break; | |
| 566 | + | |
| 567 | + case 'radio': | |
| 568 | + var length = $(item).find('input:checked').length; | |
| 569 | + | |
| 570 | + if ( !length ) { | |
| 571 | + error = true; | |
| 572 | + error_type = 'required'; | |
| 573 | + | |
| 574 | + // make it warn collor | |
| 575 | + WP_User_Frontend.markError( item, error_type ); | |
| 576 | + } | |
| 577 | + break; | |
| 578 | + | |
| 579 | + case 'file': | |
| 580 | + var length = $(item).find('ul').children().length; | |
| 581 | + | |
| 582 | + if ( !length ) { | |
| 583 | + error = true; | |
| 584 | + error_type = 'required'; | |
| 585 | + | |
| 586 | + // make it warn collor | |
| 587 | + WP_User_Frontend.markError( item, error_type ); | |
| 588 | + } | |
| 589 | + break; | |
| 590 | + | |
| 591 | + case 'email': | |
| 592 | + var val = $(item).val(); | |
| 593 | + | |
| 594 | + if ( val !== '' ) { | |
| 595 | + //run the validation | |
| 596 | + if( !WP_User_Frontend.isValidEmail( val ) ) { | |
| 597 | + error = true; | |
| 598 | + error_type = 'validation'; | |
| 599 | + | |
| 600 | + WP_User_Frontend.markError( item, error_type ); | |
| 601 | + } | |
| 602 | + } else if( val === '' ) { | |
| 603 | + error = true; | |
| 604 | + error_type = 'required'; | |
| 605 | + | |
| 606 | + WP_User_Frontend.markError( item, error_type ); | |
| 607 | + } | |
| 608 | + break; | |
| 609 | + | |
| 610 | + | |
| 611 | + case 'url': | |
| 612 | + var val = $(item).val(); | |
| 613 | + | |
| 614 | + if ( val !== '' ) { | |
| 615 | + //run the validation | |
| 616 | + if( !WP_User_Frontend.isValidURL( val ) ) { | |
| 617 | + error = true; | |
| 618 | + error_type = 'validation'; | |
| 619 | + | |
| 620 | + WP_User_Frontend.markError( item, error_type ); | |
| 621 | + } | |
| 622 | + } | |
| 623 | + break; | |
| 624 | + | |
| 625 | + }; | |
| 626 | + | |
| 627 | + }); | |
| 628 | + | |
| 629 | + //check Google Map is required | |
| 630 | + var map_required = self.find('[data-required="yes"][name="google_map"]'); | |
| 631 | + if ( map_required ) { | |
| 632 | + var val = $(map_required).val(); | |
| 633 | + if ( val == ',' ) { | |
| 634 | + error = true; | |
| 635 | + error_type = 'required'; | |
| 636 | + | |
| 637 | + WP_User_Frontend.markError( map_required, error_type ); | |
| 638 | + } | |
| 639 | + } | |
| 640 | + | |
| 641 | + // if already some error found, bail out | |
| 642 | + if (error) { | |
| 643 | + // add error notice | |
| 644 | + WP_User_Frontend.addErrorNotice(self,'end'); | |
| 645 | + | |
| 646 | + return false; | |
| 647 | + } | |
| 648 | + | |
| 649 | + var form_data = self.serialize(), | |
| 650 | + rich_texts = []; | |
| 651 | + | |
| 652 | + // grab rich texts from tinyMCE | |
| 653 | + $('.wpuf-rich-validation', self).each(function (index, item) { | |
| 654 | + var item = $(item); | |
| 655 | + var editor_id = item.data('id'); | |
| 656 | + var item_name = item.data('name'); | |
| 657 | + var val = $.trim( tinyMCE.get(editor_id).getContent() ); | |
| 658 | + | |
| 659 | + rich_texts.push(item_name + '=' + encodeURIComponent( val ) ); | |
| 660 | + }); | |
| 661 | + | |
| 662 | + // append them to the form var | |
| 663 | + form_data = form_data + '&' + rich_texts.join('&'); | |
| 664 | + return form_data; | |
| 665 | + }, | |
| 666 | + | |
| 667 | + /** | |
| 668 | + * | |
| 669 | + * @param form | |
| 670 | + * @param position (value = bottom or end) end if form is onepare, bottom, if form is multistep | |
| 671 | + */ | |
| 672 | + addErrorNotice: function( form, position ) { | |
| 673 | + if( position == 'bottom' ) { | |
| 674 | + $('.wpuf-multistep-fieldset:visible').append('<div class="wpuf-errors">' + wpuf_frontend.error_message + '</div>'); | |
| 675 | + } else { | |
| 676 | + $(form).find('li.wpuf-submit').append('<div class="wpuf-errors">' + wpuf_frontend.error_message + '</div>'); | |
| 677 | + } | |
| 678 | + | |
| 679 | + }, | |
| 680 | + | |
| 681 | + removeErrorNotice: function(form) { | |
| 682 | + $(form).find('.wpuf-errors').remove(); | |
| 683 | + }, | |
| 684 | + | |
| 685 | + markError: function(item, error_type) { | |
| 686 | + | |
| 687 | + var error_string = ''; | |
| 688 | + $(item).closest('li').addClass('has-error'); | |
| 689 | + | |
| 690 | + if ( error_type ) { | |
| 691 | + error_string = $(item).closest('li').data('label'); | |
| 692 | + switch ( error_type ) { | |
| 693 | + case 'required' : | |
| 694 | + error_string = error_string + ' ' + error_str_obj[error_type]; | |
| 695 | + break; | |
| 696 | + case 'mismatch' : | |
| 697 | + error_string = error_string + ' ' +error_str_obj[error_type]; | |
| 698 | + break; | |
| 699 | + case 'validation' : | |
| 700 | + error_string = error_string + ' ' + error_str_obj[error_type]; | |
| 701 | + break | |
| 702 | + } | |
| 703 | + $(item).siblings('.wpuf-error-msg').remove(); | |
| 704 | + $(item).after('<div class="wpuf-error-msg">'+ error_string +'</div>') | |
| 705 | + } | |
| 706 | + | |
| 707 | + $(item).focus(); | |
| 708 | + }, | |
| 709 | + | |
| 710 | + removeErrors: function(item) { | |
| 711 | + $(item).find('.has-error').removeClass('has-error'); | |
| 712 | + $('.wpuf-error-msg').remove(); | |
| 713 | + }, | |
| 714 | + | |
| 715 | + isValidEmail: function( email ) { | |
| 716 | + var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i); | |
| 717 | + return pattern.test(email); | |
| 718 | + }, | |
| 719 | + | |
| 720 | + isValidURL: function(url) { | |
| 721 | + var urlregex = new RegExp("^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.|http:\/\/|https:\/\/){1}([0-9A-Za-z]+\.)"); | |
| 722 | + return urlregex.test(url); | |
| 723 | + }, | |
| 724 | + | |
| 725 | + insertImage: function(button, form_id) { | |
| 726 | + | |
| 727 | + var container = 'wpuf-insert-image-container'; | |
| 728 | + | |
| 729 | + if ( ! $( '#' + button ).length ) { | |
| 730 | + return; | |
| 731 | + }; | |
| 732 | + | |
| 733 | + var imageUploader = new plupload.Uploader({ | |
| 734 | + runtimes: 'html5,html4', | |
| 735 | + browse_button: button, | |
| 736 | + container: container, | |
| 737 | + multipart: true, | |
| 738 | + multipart_params: { | |
| 739 | + action: 'wpuf_insert_image', | |
| 740 | + form_id: $( '#' + button ).data('form_id') | |
| 741 | + }, | |
| 742 | + multiple_queues: false, | |
| 743 | + multi_selection: false, | |
| 744 | + urlstream_upload: true, | |
| 745 | + file_data_name: 'wpuf_file', | |
| 746 | + max_file_size: '2mb', | |
| 747 | + url: wpuf_frontend_upload.plupload.url, | |
| 748 | + flash_swf_url: wpuf_frontend_upload.flash_swf_url, | |
| 749 | + filters: [{ | |
| 750 | + title: 'Allowed Files', | |
| 751 | + extensions: 'jpg,jpeg,gif,png,bmp' | |
| 752 | + }] | |
| 753 | + }); | |
| 754 | + | |
| 755 | + imageUploader.bind('Init', function(up, params) { | |
| 756 | + // console.log("Current runtime environment: " + params.runtime); | |
| 757 | + }); | |
| 758 | + | |
| 759 | + imageUploader.bind('FilesAdded', function(up, files) { | |
| 760 | + var $container = $('#' + container); | |
| 761 | + | |
| 762 | + $.each(files, function(i, file) { | |
| 763 | + $container.append( | |
| 764 | + '<div class="upload-item" id="' + file.id + '"><div class="progress progress-striped active"><div class="bar"></div></div></div>'); | |
| 765 | + }); | |
| 766 | + | |
| 767 | + up.refresh(); | |
| 768 | + up.start(); | |
| 769 | + }); | |
| 770 | + | |
| 771 | + imageUploader.bind('QueueChanged', function (uploader) { | |
| 772 | + imageUploader.start(); | |
| 773 | + }); | |
| 774 | + | |
| 775 | + imageUploader.bind('UploadProgress', function(up, file) { | |
| 776 | + var item = $('#' + file.id); | |
| 777 | + | |
| 778 | + $('.bar', item).css({ width: file.percent + '%' }); | |
| 779 | + $('.percent', item).html( file.percent + '%' ); | |
| 780 | + }); | |
| 781 | + | |
| 782 | + imageUploader.bind('Error', function(up, error) { | |
| 783 | + alert('Error #' + error.code + ': ' + error.message); | |
| 784 | + }); | |
| 785 | + | |
| 786 | + imageUploader.bind('FileUploaded', function(up, file, response) { | |
| 787 | + | |
| 788 | + $('#' + file.id).remove(); | |
| 789 | + | |
| 790 | + if ( response.response !== 'error' ) { | |
| 791 | + var success = false; | |
| 792 | + | |
| 793 | + if ( typeof tinyMCE !== 'undefined' ) { | |
| 794 | + | |
| 795 | + if ( typeof tinyMCE.execInstanceCommand !== 'function' ) { | |
| 796 | + // tinyMCE 4.x | |
| 797 | + var mce = tinyMCE.get( 'post_content_' + form_id ); | |
| 798 | + | |
| 799 | + if ( mce !== null ) { | |
| 800 | + mce.insertContent(response.response); | |
| 801 | + } | |
| 802 | + } else { | |
| 803 | + // tinyMCE 3.x | |
| 804 | + tinyMCE.execInstanceCommand( 'post_content_' + form_id, 'mceInsertContent', false, response.response); | |
| 805 | + } | |
| 806 | + } | |
| 807 | + | |
| 808 | + // insert failed to the edit, perhaps insert into textarea | |
| 809 | + var post_content = $('#post_content_' + form_id); | |
| 810 | + post_content.val( post_content.val() + response.response ); | |
| 811 | + | |
| 812 | + } else { | |
| 813 | + alert('Something went wrong'); | |
| 814 | + } | |
| 815 | + }); | |
| 816 | + | |
| 817 | + imageUploader.init(); | |
| 818 | + }, | |
| 819 | + | |
| 820 | + deleteAvatar: function(e) { | |
| 821 | + e.preventDefault(); | |
| 822 | + | |
| 823 | + if ( confirm( $(this).data('confirm') ) ) { | |
| 824 | + $.post(wpuf_frontend.ajaxurl, {action: 'wpuf_delete_avatar', _wpnonce: wpuf_frontend.nonce}, function() { | |
| 825 | + $(e.target).parent().remove(); | |
| 826 | + $('[id^=wpuf-avatar]').css("display", ""); | |
| 827 | + }); | |
| 828 | + } | |
| 829 | + }, | |
| 830 | + | |
| 831 | + editorLimit: { | |
| 832 | + | |
| 833 | + bind: function(limit, field, type) { | |
| 834 | + if ( type === 'no' ) { | |
| 835 | + // it's a textarea | |
| 836 | + $('textarea#' + field).keydown( function(event) { | |
| 837 | + WP_User_Frontend.editorLimit.textLimit.call(this, event, limit); | |
| 838 | + }); | |
| 839 | + | |
| 840 | + $('input#' + field).keydown( function(event) { | |
| 841 | + WP_User_Frontend.editorLimit.textLimit.call(this, event, limit); | |
| 842 | + }); | |
| 843 | + | |
| 844 | + $('textarea#' + field).on('paste', function(event) { | |
| 845 | + var self = $(this); | |
| 846 | + | |
| 847 | + setTimeout(function() { | |
| 848 | + WP_User_Frontend.editorLimit.textLimit.call(self, event, limit); | |
| 849 | + }, 100); | |
| 850 | + }); | |
| 851 | + | |
| 852 | + $('input#' + field).on('paste', function(event) { | |
| 853 | + var self = $(this); | |
| 854 | + | |
| 855 | + setTimeout(function() { | |
| 856 | + WP_User_Frontend.editorLimit.textLimit.call(self, event, limit); | |
| 857 | + }, 100); | |
| 858 | + }); | |
| 859 | + | |
| 860 | + } else { | |
| 861 | + // it's a rich textarea | |
| 862 | + setTimeout(function () { | |
| 863 | + tinyMCE.get(field).onKeyDown.add(function(ed, event) { | |
| 864 | + WP_User_Frontend.editorLimit.tinymce.onKeyDown(ed, event, limit); | |
| 865 | + } ); | |
| 866 | + | |
| 867 | + tinyMCE.get(field).onPaste.add(function(ed, event) { | |
| 868 | + setTimeout(function() { | |
| 869 | + WP_User_Frontend.editorLimit.tinymce.onPaste(ed, event, limit); | |
| 870 | + }, 100); | |
| 871 | + }); | |
| 872 | + | |
| 873 | + }, 1000); | |
| 874 | + } | |
| 875 | + }, | |
| 876 | + | |
| 877 | + tinymce: { | |
| 878 | + | |
| 879 | + getStats: function(ed) { | |
| 880 | + var body = ed.getBody(), text = tinymce.trim(body.innerText || body.textContent); | |
| 881 | + | |
| 882 | + return { | |
| 883 | + chars: text.length, | |
| 884 | + words: text.split(/[\w\u2019\'-]+/).length | |
| 885 | + }; | |
| 886 | + }, | |
| 887 | + | |
| 888 | + onKeyDown: function(ed, event, limit) { | |
| 889 | + var numWords = WP_User_Frontend.editorLimit.tinymce.getStats(ed).words - 1; | |
| 890 | + | |
| 891 | + limit ? $('.mce-path-item.mce-last', ed.container).html('Word Limit : '+ numWords +'/'+limit):''; | |
| 892 | + | |
| 893 | + if ( limit && numWords > limit ) { | |
| 894 | + WP_User_Frontend.editorLimit.blockTyping(event); | |
| 895 | + jQuery('.mce-path-item.mce-last', ed.container).html( wpuf_frontend.word_limit ); | |
| 896 | + } | |
| 897 | + }, | |
| 898 | + | |
| 899 | + onPaste: function(ed, event, limit) { | |
| 900 | + var editorContent = ed.getContent().split(' ').slice(0, limit).join(' '); | |
| 901 | + | |
| 902 | + // Let TinyMCE do the heavy lifting for inserting that content into the editor. | |
| 903 | + // ed.insertContent(content); //ed.execCommand('mceInsertContent', false, content); | |
| 904 | + ed.setContent(editorContent); | |
| 905 | + | |
| 906 | + WP_User_Frontend.editorLimit.make_media_embed_code(editorContent, ed); | |
| 907 | + } | |
| 908 | + }, | |
| 909 | + | |
| 910 | + textLimit: function(event, limit) { | |
| 911 | + var self = $(this), | |
| 912 | + content = self.val().split(' '); | |
| 913 | + | |
| 914 | + if ( limit && content.length > limit ) { | |
| 915 | + self.closest('.wpuf-fields').find('span.wpuf-wordlimit-message').html( wpuf_frontend.word_limit ); | |
| 916 | + WP_User_Frontend.editorLimit.blockTyping(event); | |
| 917 | + } else { | |
| 918 | + self.closest('.wpuf-fields').find('span.wpuf-wordlimit-message').html(''); | |
| 919 | + } | |
| 920 | + | |
| 921 | + // handle the paste event | |
| 922 | + if ( event.type === 'paste' ) { | |
| 923 | + self.val( content.slice(0, limit).join( ' ' ) ); | |
| 924 | + } | |
| 925 | + }, | |
| 926 | + | |
| 927 | + blockTyping: function(event) { | |
| 928 | + // Allow: backspace, delete, tab, escape, minus enter and . backspace = 8,delete=46,tab=9,enter=13,.=190,escape=27, minus = 189 | |
| 929 | + if ($.inArray(event.keyCode, [46, 8, 9, 27, 13, 110, 190, 189]) !== -1 || | |
| 930 | + // Allow: Ctrl+A | |
| 931 | + (event.keyCode == 65 && event.ctrlKey === true) || | |
| 932 | + // Allow: home, end, left, right, down, up | |
| 933 | + (event.keyCode >= 35 && event.keyCode <= 40)) { | |
| 934 | + // let it happen, don't do anything | |
| 935 | + return; | |
| 936 | + } | |
| 937 | + | |
| 938 | + event.preventDefault(); | |
| 939 | + event.stopPropagation(); | |
| 940 | + }, | |
| 941 | + | |
| 942 | + make_media_embed_code: function(content, editor){ | |
| 943 | + $.post( ajaxurl, { | |
| 944 | + action:'make_media_embed_code', | |
| 945 | + content: content | |
| 946 | + }, | |
| 947 | + function(data){ | |
| 948 | + // console.log(data); | |
| 949 | + editor.setContent(editor.getContent() + editor.setContent(data)); | |
| 950 | + } | |
| 951 | + ) | |
| 952 | + } | |
| 953 | + } | |
| 954 | + }; | |
| 955 | + | |
| 956 | + $(function() { | |
| 957 | + WP_User_Frontend.init(); | |
| 958 | + | |
| 959 | + // payment gateway selection | |
| 960 | + $('ul.wpuf-payment-gateways').on('click', 'input[type=radio]', function(e) { | |
| 961 | + $('.wpuf-payment-instruction').slideUp(250); | |
| 962 | + | |
| 963 | + $(this).parents('li').find('.wpuf-payment-instruction').slideDown(250); | |
| 964 | + }); | |
| 965 | + | |
| 966 | + if( !$('ul.wpuf-payment-gateways li').find('input[type=radio]').is(':checked') ) { | |
| 967 | + $('ul.wpuf-payment-gateways li').first().find('input[type=radio]').click() | |
| 968 | + } else { | |
| 969 | + var el = $('ul.wpuf-payment-gateways li').find('input[type=radio]:checked'); | |
| 970 | + el.parents('li').find('.wpuf-payment-instruction').slideDown(250); | |
| 971 | + } | |
| 972 | + }); | |
| 973 | + | |
| 974 | + $(function() { | |
| 975 | + $('input[name="first_name"], input[name="last_name"]').on('change keyup', function() { | |
| 976 | + var myVal, newVal = $.makeArray($('input[name="first_name"], input[name="last_name"]').map(function(){ | |
| 977 | + if (myVal = $(this).val()) { | |
| 978 | + return(myVal); | |
| 979 | + } | |
| 980 | + })).join(' '); | |
| 981 | + $('input[name="display_name"]').val(newVal); | |
| 982 | + }); | |
| 983 | + }); | |
| 984 | + | |
| 985 | + // script for Dokan vendor registration template | |
| 986 | + $(function($) { | |
| 987 | + | |
| 988 | + $('.wpuf-form-add input[name="dokan_store_name"]').on('focusout', function() { | |
| 989 | + var value = $(this).val().toLowerCase().replace(/-+/g, '').replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, ''); | |
| 990 | + $('input[name="shopurl"]').val(value); | |
| 991 | + $('#url-alart').text( value ); | |
| 992 | + $('input[name="shopurl"]').focus(); | |
| 993 | + }); | |
| 994 | + | |
| 995 | + $('.wpuf-form-add input[name="shopurl"]').keydown(function(e) { | |
| 996 | + var text = $(this).val(); | |
| 997 | + | |
| 998 | + // Allow: backspace, delete, tab, escape, enter and . | |
| 999 | + if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 91, 109, 110, 173, 189, 190]) !== -1 || | |
| 1000 | + // Allow: Ctrl+A | |
| 1001 | + (e.keyCode == 65 && e.ctrlKey === true) || | |
| 1002 | + // Allow: home, end, left, right | |
| 1003 | + (e.keyCode >= 35 && e.keyCode <= 39)) { | |
| 1004 | + // let it happen, don't do anything | |
| 1005 | + return; | |
| 1006 | + } | |
| 1007 | + | |
| 1008 | + if ((e.shiftKey || (e.keyCode < 65 || e.keyCode > 90) && (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105) ) { | |
| 1009 | + e.preventDefault(); | |
| 1010 | + } | |
| 1011 | + }); | |
| 1012 | + | |
| 1013 | + $('.wpuf-form-add input[name="shopurl"]').keyup(function(e) { | |
| 1014 | + $('#url-alart').text( $(this).val() ); | |
| 1015 | + }); | |
| 1016 | + | |
| 1017 | + $('.wpuf-form-add input[name="shopurl"]').on('focusout', function() { | |
| 1018 | + var self = $(this), | |
| 1019 | + data = { | |
| 1020 | + action : 'shop_url', | |
| 1021 | + url_slug : self.val(), | |
| 1022 | + _nonce : dokan.nonce, | |
| 1023 | + }; | |
| 1024 | + | |
| 1025 | + if ( self.val() === '' ) { | |
| 1026 | + return; | |
| 1027 | + } | |
| 1028 | + | |
| 1029 | + $.post( dokan.ajaxurl, data, function(resp) { | |
| 1030 | + | |
| 1031 | + if ( resp == 0){ | |
| 1032 | + $('#url-alart').removeClass('text-success').addClass('text-danger'); | |
| 1033 | + $('#url-alart-mgs').removeClass('text-success').addClass('text-danger').text(dokan.seller.notAvailable); | |
| 1034 | + } else { | |
| 1035 | + $('#url-alart').removeClass('text-danger').addClass('text-success'); | |
| 1036 | + $('#url-alart-mgs').removeClass('text-danger').addClass('text-success').text(dokan.seller.available); | |
| 1037 | + } | |
| 1038 | + | |
| 1039 | + } ); | |
| 1040 | + | |
| 1041 | + }); | |
| 1042 | + | |
| 1043 | + // Set name attribute for google map search field | |
| 1044 | + $(".wpuf-form-add #wpuf-map-add-location").attr("name", "find_address"); | |
| 1045 | + }); | |
| 1046 | + | |
| 1047 | +})(jQuery, window); | |
| 1048 | + | |
| 1049 | 1049 | /* assets/wpuf/vendor/sweetalert2/dist/sweetalert2.js */ |
| 1050 | -/*! | |
| 1051 | - * sweetalert2 v6.6.4 | |
| 1052 | - * Released under the MIT License. | |
| 1053 | - */ | |
| 1054 | -(function (global, factory) { | |
| 1055 | - typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | |
| 1056 | - typeof define === 'function' && define.amd ? define(factory) : | |
| 1057 | - (global.Sweetalert2 = factory()); | |
| 1058 | -}(this, (function () { 'use strict'; | |
| 1059 | - | |
| 1060 | -var defaultParams = { | |
| 1061 | - title: '', | |
| 1062 | - titleText: '', | |
| 1063 | - text: '', | |
| 1064 | - html: '', | |
| 1065 | - type: null, | |
| 1066 | - customClass: '', | |
| 1067 | - target: 'body', | |
| 1068 | - animation: true, | |
| 1069 | - allowOutsideClick: true, | |
| 1070 | - allowEscapeKey: true, | |
| 1071 | - allowEnterKey: true, | |
| 1072 | - showConfirmButton: true, | |
| 1073 | - showCancelButton: false, | |
| 1074 | - preConfirm: null, | |
| 1075 | - confirmButtonText: 'OK', | |
| 1076 | - confirmButtonColor: '#3085d6', | |
| 1077 | - confirmButtonClass: null, | |
| 1078 | - cancelButtonText: 'Cancel', | |
| 1079 | - cancelButtonColor: '#aaa', | |
| 1080 | - cancelButtonClass: null, | |
| 1081 | - buttonsStyling: true, | |
| 1082 | - reverseButtons: false, | |
| 1083 | - focusCancel: false, | |
| 1084 | - showCloseButton: false, | |
| 1085 | - showLoaderOnConfirm: false, | |
| 1086 | - imageUrl: null, | |
| 1087 | - imageWidth: null, | |
| 1088 | - imageHeight: null, | |
| 1089 | - imageClass: null, | |
| 1090 | - timer: null, | |
| 1091 | - width: 500, | |
| 1092 | - padding: 20, | |
| 1093 | - background: '#fff', | |
| 1094 | - input: null, | |
| 1095 | - inputPlaceholder: '', | |
| 1096 | - inputValue: '', | |
| 1097 | - inputOptions: {}, | |
| 1098 | - inputAutoTrim: true, | |
| 1099 | - inputClass: null, | |
| 1100 | - inputAttributes: {}, | |
| 1101 | - inputValidator: null, | |
| 1102 | - progressSteps: [], | |
| 1103 | - currentProgressStep: null, | |
| 1104 | - progressStepsDistance: '40px', | |
| 1105 | - onOpen: null, | |
| 1106 | - onClose: null, | |
| 1107 | - useRejections: true | |
| 1108 | -}; | |
| 1109 | - | |
| 1110 | -var swalPrefix = 'swal2-'; | |
| 1111 | - | |
| 1112 | -var prefix = function prefix(items) { | |
| 1113 | - var result = {}; | |
| 1114 | - for (var i in items) { | |
| 1115 | - result[items[i]] = swalPrefix + items[i]; | |
| 1116 | - } | |
| 1117 | - return result; | |
| 1118 | -}; | |
| 1119 | - | |
| 1120 | -var swalClasses = prefix(['container', 'shown', 'iosfix', 'modal', 'overlay', 'fade', 'show', 'hide', 'noanimation', 'close', 'title', 'content', 'buttonswrapper', 'confirm', 'cancel', 'icon', 'image', 'input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea', 'inputerror', 'validationerror', 'progresssteps', 'activeprogressstep', 'progresscircle', 'progressline', 'loading', 'styled']); | |
| 1121 | - | |
| 1122 | -var iconTypes = prefix(['success', 'warning', 'info', 'question', 'error']); | |
| 1123 | - | |
| 1124 | -/* | |
| 1125 | - * Set hover, active and focus-states for buttons (source: http://www.sitepoint.com/javascript-generate-lighter-darker-color) | |
| 1126 | - */ | |
| 1127 | -var colorLuminance = function colorLuminance(hex, lum) { | |
| 1128 | - // Validate hex string | |
| 1129 | - hex = String(hex).replace(/[^0-9a-f]/gi, ''); | |
| 1130 | - if (hex.length < 6) { | |
| 1131 | - hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; | |
| 1132 | - } | |
| 1133 | - lum = lum || 0; | |
| 1134 | - | |
| 1135 | - // Convert to decimal and change luminosity | |
| 1136 | - var rgb = '#'; | |
| 1137 | - for (var i = 0; i < 3; i++) { | |
| 1138 | - var c = parseInt(hex.substr(i * 2, 2), 16); | |
| 1139 | - c = Math.round(Math.min(Math.max(0, c + c * lum), 255)).toString(16); | |
| 1140 | - rgb += ('00' + c).substr(c.length); | |
| 1141 | - } | |
| 1142 | - | |
| 1143 | - return rgb; | |
| 1144 | -}; | |
| 1145 | - | |
| 1146 | -var uniqueArray = function uniqueArray(arr) { | |
| 1147 | - var result = []; | |
| 1148 | - for (var i in arr) { | |
| 1149 | - if (result.indexOf(arr[i]) === -1) { | |
| 1150 | - result.push(arr[i]); | |
| 1151 | - } | |
| 1152 | - } | |
| 1153 | - return result; | |
| 1154 | -}; | |
| 1155 | - | |
| 1156 | -/* global MouseEvent */ | |
| 1157 | - | |
| 1158 | -// Remember state in cases where opening and handling a modal will fiddle with it. | |
| 1159 | -var states = { | |
| 1160 | - previousWindowKeyDown: null, | |
| 1161 | - previousActiveElement: null, | |
| 1162 | - previousBodyPadding: null | |
| 1163 | -}; | |
| 1164 | - | |
| 1165 | -/* | |
| 1166 | - * Add modal + overlay to DOM | |
| 1167 | - */ | |
| 1168 | -var init = function init(params) { | |
| 1169 | - if (typeof document === 'undefined') { | |
| 1170 | - console.error('SweetAlert2 requires document to initialize'); | |
| 1171 | - return; | |
| 1172 | - } | |
| 1173 | - | |
| 1174 | - var container = document.createElement('div'); | |
| 1175 | - container.className = swalClasses.container; | |
| 1176 | - container.innerHTML = sweetHTML; | |
| 1177 | - | |
| 1178 | - var targetElement = document.querySelector(params.target); | |
| 1179 | - if (!targetElement) { | |
| 1180 | - console.warn('SweetAlert2: Can\'t find the target "' + params.target + '"'); | |
| 1181 | - targetElement = document.body; | |
| 1182 | - } | |
| 1183 | - targetElement.appendChild(container); | |
| 1184 | - | |
| 1185 | - var modal = getModal(); | |
| 1186 | - var input = getChildByClass(modal, swalClasses.input); | |
| 1187 | - var file = getChildByClass(modal, swalClasses.file); | |
| 1188 | - var range = modal.querySelector('.' + swalClasses.range + ' input'); | |
| 1189 | - var rangeOutput = modal.querySelector('.' + swalClasses.range + ' output'); | |
| 1190 | - var select = getChildByClass(modal, swalClasses.select); | |
| 1191 | - var checkbox = modal.querySelector('.' + swalClasses.checkbox + ' input'); | |
| 1192 | - var textarea = getChildByClass(modal, swalClasses.textarea); | |
| 1193 | - | |
| 1194 | - input.oninput = function () { | |
| 1195 | - sweetAlert.resetValidationError(); | |
| 1196 | - }; | |
| 1197 | - | |
| 1198 | - input.onkeydown = function (event) { | |
| 1199 | - setTimeout(function () { | |
| 1200 | - if (event.keyCode === 13 && params.allowEnterKey) { | |
| 1201 | - event.stopPropagation(); | |
| 1202 | - sweetAlert.clickConfirm(); | |
| 1203 | - } | |
| 1204 | - }, 0); | |
| 1205 | - }; | |
| 1206 | - | |
| 1207 | - file.onchange = function () { | |
| 1208 | - sweetAlert.resetValidationError(); | |
| 1209 | - }; | |
| 1210 | - | |
| 1211 | - range.oninput = function () { | |
| 1212 | - sweetAlert.resetValidationError(); | |
| 1213 | - rangeOutput.value = range.value; | |
| 1214 | - }; | |
| 1215 | - | |
| 1216 | - range.onchange = function () { | |
| 1217 | - sweetAlert.resetValidationError(); | |
| 1218 | - range.previousSibling.value = range.value; | |
| 1219 | - }; | |
| 1220 | - | |
| 1221 | - select.onchange = function () { | |
| 1222 | - sweetAlert.resetValidationError(); | |
| 1223 | - }; | |
| 1224 | - | |
| 1225 | - checkbox.onchange = function () { | |
| 1226 | - sweetAlert.resetValidationError(); | |
| 1227 | - }; | |
| 1228 | - | |
| 1229 | - textarea.oninput = function () { | |
| 1230 | - sweetAlert.resetValidationError(); | |
| 1231 | - }; | |
| 1232 | - | |
| 1233 | - return modal; | |
| 1234 | -}; | |
| 1235 | - | |
| 1236 | -/* | |
| 1237 | - * Manipulate DOM | |
| 1238 | - */ | |
| 1239 | - | |
| 1240 | -var sweetHTML = ('\n <div role="dialog" aria-labelledby="' + swalClasses.title + '" aria-describedby="' + swalClasses.content + '" class="' + swalClasses.modal + '" tabindex="-1">\n <ul class="' + swalClasses.progresssteps + '"></ul>\n <div class="' + swalClasses.icon + ' ' + iconTypes.error + '">\n <span class="swal2-x-mark"><span class="swal2-x-mark-line-left"></span><span class="swal2-x-mark-line-right"></span></span>\n </div>\n <div class="' + swalClasses.icon + ' ' + iconTypes.question + '">?</div>\n <div class="' + swalClasses.icon + ' ' + iconTypes.warning + '">!</div>\n <div class="' + swalClasses.icon + ' ' + iconTypes.info + '">i</div>\n <div class="' + swalClasses.icon + ' ' + iconTypes.success + '">\n <div class="swal2-success-circular-line-left"></div>\n <span class="swal2-success-line-tip"></span> <span class="swal2-success-line-long"></span>\n <div class="swal2-success-ring"></div> <div class="swal2-success-fix"></div>\n <div class="swal2-success-circular-line-right"></div>\n </div>\n <img class="' + swalClasses.image + '">\n <h2 class="' + swalClasses.title + '" id="' + swalClasses.title + '"></h2>\n <div id="' + swalClasses.content + '" class="' + swalClasses.content + '"></div>\n <input class="' + swalClasses.input + '">\n <input type="file" class="' + swalClasses.file + '">\n <div class="' + swalClasses.range + '">\n <output></output>\n <input type="range">\n </div>\n <select class="' + swalClasses.select + '"></select>\n <div class="' + swalClasses.radio + '"></div>\n <label for="' + swalClasses.checkbox + '" class="' + swalClasses.checkbox + '">\n <input type="checkbox">\n </label>\n <textarea class="' + swalClasses.textarea + '"></textarea>\n <div class="' + swalClasses.validationerror + '"></div>\n <div class="' + swalClasses.buttonswrapper + '">\n <button type="button" class="' + swalClasses.confirm + '">OK</button>\n <button type="button" class="' + swalClasses.cancel + '">Cancel</button>\n </div>\n <button type="button" class="' + swalClasses.close + '" aria-label="Close this dialog">×</button>\n </div>\n').replace(/(^|\n)\s*/g, ''); | |
| 1241 | - | |
| 1242 | -var getContainer = function getContainer() { | |
| 1243 | - return document.body.querySelector('.' + swalClasses.container); | |
| 1244 | -}; | |
| 1245 | - | |
| 1246 | -var getModal = function getModal() { | |
| 1247 | - return getContainer() ? getContainer().querySelector('.' + swalClasses.modal) : null; | |
| 1248 | -}; | |
| 1249 | - | |
| 1250 | -var getIcons = function getIcons() { | |
| 1251 | - var modal = getModal(); | |
| 1252 | - return modal.querySelectorAll('.' + swalClasses.icon); | |
| 1253 | -}; | |
| 1254 | - | |
| 1255 | -var elementByClass = function elementByClass(className) { | |
| 1256 | - return getContainer() ? getContainer().querySelector('.' + className) : null; | |
| 1257 | -}; | |
| 1258 | - | |
| 1259 | -var getTitle = function getTitle() { | |
| 1260 | - return elementByClass(swalClasses.title); | |
| 1261 | -}; | |
| 1262 | - | |
| 1263 | -var getContent = function getContent() { | |
| 1264 | - return elementByClass(swalClasses.content); | |
| 1265 | -}; | |
| 1266 | - | |
| 1267 | -var getImage = function getImage() { | |
| 1268 | - return elementByClass(swalClasses.image); | |
| 1269 | -}; | |
| 1270 | - | |
| 1271 | -var getButtonsWrapper = function getButtonsWrapper() { | |
| 1272 | - return elementByClass(swalClasses.buttonswrapper); | |
| 1273 | -}; | |
| 1274 | - | |
| 1275 | -var getProgressSteps = function getProgressSteps() { | |
| 1276 | - return elementByClass(swalClasses.progresssteps); | |
| 1277 | -}; | |
| 1278 | - | |
| 1279 | -var getValidationError = function getValidationError() { | |
| 1280 | - return elementByClass(swalClasses.validationerror); | |
| 1281 | -}; | |
| 1282 | - | |
| 1283 | -var getConfirmButton = function getConfirmButton() { | |
| 1284 | - return elementByClass(swalClasses.confirm); | |
| 1285 | -}; | |
| 1286 | - | |
| 1287 | -var getCancelButton = function getCancelButton() { | |
| 1288 | - return elementByClass(swalClasses.cancel); | |
| 1289 | -}; | |
| 1290 | - | |
| 1291 | -var getCloseButton = function getCloseButton() { | |
| 1292 | - return elementByClass(swalClasses.close); | |
| 1293 | -}; | |
| 1294 | - | |
| 1295 | -var getFocusableElements = function getFocusableElements(focusCancel) { | |
| 1296 | - var buttons = [getConfirmButton(), getCancelButton()]; | |
| 1297 | - if (focusCancel) { | |
| 1298 | - buttons.reverse(); | |
| 1299 | - } | |
| 1300 | - var focusableElements = buttons.concat(Array.prototype.slice.call(getModal().querySelectorAll('button, input:not([type=hidden]), textarea, select, a, *[tabindex]:not([tabindex="-1"])'))); | |
| 1301 | - return uniqueArray(focusableElements); | |
| 1302 | -}; | |
| 1303 | - | |
| 1304 | -var hasClass = function hasClass(elem, className) { | |
| 1305 | - if (elem.classList) { | |
| 1306 | - return elem.classList.contains(className); | |
| 1307 | - } | |
| 1308 | - return false; | |
| 1309 | -}; | |
| 1310 | - | |
| 1311 | -var focusInput = function focusInput(input) { | |
| 1312 | - input.focus(); | |
| 1313 | - | |
| 1314 | - // place cursor at end of text in text input | |
| 1315 | - if (input.type !== 'file') { | |
| 1316 | - // http://stackoverflow.com/a/2345915/1331425 | |
| 1317 | - var val = input.value; | |
| 1318 | - input.value = ''; | |
| 1319 | - input.value = val; | |
| 1320 | - } | |
| 1321 | -}; | |
| 1322 | - | |
| 1323 | -var addClass = function addClass(elem, className) { | |
| 1324 | - if (!elem || !className) { | |
| 1325 | - return; | |
| 1326 | - } | |
| 1327 | - var classes = className.split(/\s+/).filter(Boolean); | |
| 1328 | - classes.forEach(function (className) { | |
| 1329 | - elem.classList.add(className); | |
| 1330 | - }); | |
| 1331 | -}; | |
| 1332 | - | |
| 1333 | -var removeClass = function removeClass(elem, className) { | |
| 1334 | - if (!elem || !className) { | |
| 1335 | - return; | |
| 1336 | - } | |
| 1337 | - var classes = className.split(/\s+/).filter(Boolean); | |
| 1338 | - classes.forEach(function (className) { | |
| 1339 | - elem.classList.remove(className); | |
| 1340 | - }); | |
| 1341 | -}; | |
| 1342 | - | |
| 1343 | -var getChildByClass = function getChildByClass(elem, className) { | |
| 1344 | - for (var i = 0; i < elem.childNodes.length; i++) { | |
| 1345 | - if (hasClass(elem.childNodes[i], className)) { | |
| 1346 | - return elem.childNodes[i]; | |
| 1347 | - } | |
| 1348 | - } | |
| 1349 | -}; | |
| 1350 | - | |
| 1351 | -var show = function show(elem, display) { | |
| 1352 | - if (!display) { | |
| 1353 | - display = 'block'; | |
| 1354 | - } | |
| 1355 | - elem.style.opacity = ''; | |
| 1356 | - elem.style.display = display; | |
| 1357 | -}; | |
| 1358 | - | |
| 1359 | -var hide = function hide(elem) { | |
| 1360 | - elem.style.opacity = ''; | |
| 1361 | - elem.style.display = 'none'; | |
| 1362 | -}; | |
| 1363 | - | |
| 1364 | -var empty = function empty(elem) { | |
| 1365 | - while (elem.firstChild) { | |
| 1366 | - elem.removeChild(elem.firstChild); | |
| 1367 | - } | |
| 1368 | -}; | |
| 1369 | - | |
| 1370 | -// borrowed from jqeury $(elem).is(':visible') implementation | |
| 1371 | -var isVisible = function isVisible(elem) { | |
| 1372 | - return elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length; | |
| 1373 | -}; | |
| 1374 | - | |
| 1375 | -var removeStyleProperty = function removeStyleProperty(elem, property) { | |
| 1376 | - if (elem.style.removeProperty) { | |
| 1377 | - elem.style.removeProperty(property); | |
| 1378 | - } else { | |
| 1379 | - elem.style.removeAttribute(property); | |
| 1380 | - } | |
| 1381 | -}; | |
| 1382 | - | |
| 1383 | -var fireClick = function fireClick(node) { | |
| 1384 | - if (!isVisible(node)) { | |
| 1385 | - return false; | |
| 1386 | - } | |
| 1387 | - | |
| 1388 | - // Taken from http://www.nonobtrusive.com/2011/11/29/programatically-fire-crossbrowser-click-event-with-javascript/ | |
| 1389 | - // Then fixed for today's Chrome browser. | |
| 1390 | - if (typeof MouseEvent === 'function') { | |
| 1391 | - // Up-to-date approach | |
| 1392 | - var mevt = new MouseEvent('click', { | |
| 1393 | - view: window, | |
| 1394 | - bubbles: false, | |
| 1395 | - cancelable: true | |
| 1396 | - }); | |
| 1397 | - node.dispatchEvent(mevt); | |
| 1398 | - } else if (document.createEvent) { | |
| 1399 | - // Fallback | |
| 1400 | - var evt = document.createEvent('MouseEvents'); | |
| 1401 | - evt.initEvent('click', false, false); | |
| 1402 | - node.dispatchEvent(evt); | |
| 1403 | - } else if (document.createEventObject) { | |
| 1404 | - node.fireEvent('onclick'); | |
| 1405 | - } else if (typeof node.onclick === 'function') { | |
| 1406 | - node.onclick(); | |
| 1407 | - } | |
| 1408 | -}; | |
| 1409 | - | |
| 1410 | -var animationEndEvent = function () { | |
| 1411 | - var testEl = document.createElement('div'); | |
| 1412 | - var transEndEventNames = { | |
| 1413 | - 'WebkitAnimation': 'webkitAnimationEnd', | |
| 1414 | - 'OAnimation': 'oAnimationEnd oanimationend', | |
| 1415 | - 'msAnimation': 'MSAnimationEnd', | |
| 1416 | - 'animation': 'animationend' | |
| 1417 | - }; | |
| 1418 | - for (var i in transEndEventNames) { | |
| 1419 | - if (transEndEventNames.hasOwnProperty(i) && testEl.style[i] !== undefined) { | |
| 1420 | - return transEndEventNames[i]; | |
| 1421 | - } | |
| 1422 | - } | |
| 1423 | - | |
| 1424 | - return false; | |
| 1425 | -}(); | |
| 1426 | - | |
| 1427 | -// Reset previous window keydown handler and focued element | |
| 1428 | -var resetPrevState = function resetPrevState() { | |
| 1429 | - window.onkeydown = states.previousWindowKeyDown; | |
| 1430 | - if (states.previousActiveElement && states.previousActiveElement.focus) { | |
| 1431 | - var x = window.scrollX; | |
| 1432 | - var y = window.scrollY; | |
| 1433 | - states.previousActiveElement.focus(); | |
| 1434 | - if (x && y) { | |
| 1435 | - // IE has no scrollX/scrollY support | |
| 1436 | - window.scrollTo(x, y); | |
| 1437 | - } | |
| 1438 | - } | |
| 1439 | -}; | |
| 1440 | - | |
| 1441 | -// Measure width of scrollbar | |
| 1442 | -// https://github.com/twbs/bootstrap/blob/master/js/modal.js#L279-L286 | |
| 1443 | -var measureScrollbar = function measureScrollbar() { | |
| 1444 | - var supportsTouch = 'ontouchstart' in window || navigator.msMaxTouchPoints; | |
| 1445 | - if (supportsTouch) { | |
| 1446 | - return 0; | |
| 1447 | - } | |
| 1448 | - var scrollDiv = document.createElement('div'); | |
| 1449 | - scrollDiv.style.width = '50px'; | |
| 1450 | - scrollDiv.style.height = '50px'; | |
| 1451 | - scrollDiv.style.overflow = 'scroll'; | |
| 1452 | - document.body.appendChild(scrollDiv); | |
| 1453 | - var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; | |
| 1454 | - document.body.removeChild(scrollDiv); | |
| 1455 | - return scrollbarWidth; | |
| 1456 | -}; | |
| 1457 | - | |
| 1458 | -// JavaScript Debounce Function | |
| 1459 | -// Simplivied version of https://davidwalsh.name/javascript-debounce-function | |
| 1460 | -var debounce = function debounce(func, wait) { | |
| 1461 | - var timeout = void 0; | |
| 1462 | - return function () { | |
| 1463 | - var later = function later() { | |
| 1464 | - timeout = null; | |
| 1465 | - func(); | |
| 1466 | - }; | |
| 1467 | - clearTimeout(timeout); | |
| 1468 | - timeout = setTimeout(later, wait); | |
| 1469 | - }; | |
| 1470 | -}; | |
| 1471 | - | |
| 1472 | -var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | |
| 1473 | - return typeof obj; | |
| 1474 | -} : function (obj) { | |
| 1475 | - return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | |
| 1476 | -}; | |
| 1477 | - | |
| 1478 | - | |
| 1479 | - | |
| 1480 | - | |
| 1481 | - | |
| 1482 | - | |
| 1483 | - | |
| 1484 | - | |
| 1485 | - | |
| 1486 | - | |
| 1487 | - | |
| 1488 | - | |
| 1489 | - | |
| 1490 | - | |
| 1491 | - | |
| 1492 | - | |
| 1493 | - | |
| 1494 | - | |
| 1495 | - | |
| 1496 | - | |
| 1497 | - | |
| 1498 | -var _extends = Object.assign || function (target) { | |
| 1499 | - for (var i = 1; i < arguments.length; i++) { | |
| 1500 | - var source = arguments[i]; | |
| 1501 | - | |
| 1502 | - for (var key in source) { | |
| 1503 | - if (Object.prototype.hasOwnProperty.call(source, key)) { | |
| 1504 | - target[key] = source[key]; | |
| 1505 | - } | |
| 1506 | - } | |
| 1507 | - } | |
| 1508 | - | |
| 1509 | - return target; | |
| 1510 | -}; | |
| 1511 | - | |
| 1512 | -var modalParams = _extends({}, defaultParams); | |
| 1513 | -var queue = []; | |
| 1514 | -var swal2Observer = void 0; | |
| 1515 | - | |
| 1516 | -/* | |
| 1517 | - * Set type, text and actions on modal | |
| 1518 | - */ | |
| 1519 | -var setParameters = function setParameters(params) { | |
| 1520 | - var modal = getModal() || init(params); | |
| 1521 | - | |
| 1522 | - for (var param in params) { | |
| 1523 | - if (!defaultParams.hasOwnProperty(param) && param !== 'extraParams') { | |
| 1524 | - console.warn('SweetAlert2: Unknown parameter "' + param + '"'); | |
| 1525 | - } | |
| 1526 | - } | |
| 1527 | - | |
| 1528 | - // Set modal width | |
| 1529 | - modal.style.width = typeof params.width === 'number' ? params.width + 'px' : params.width; | |
| 1530 | - | |
| 1531 | - modal.style.padding = params.padding + 'px'; | |
| 1532 | - modal.style.background = params.background; | |
| 1533 | - var successIconParts = modal.querySelectorAll('[class^=swal2-success-circular-line], .swal2-success-fix'); | |
| 1534 | - for (var i = 0; i < successIconParts.length; i++) { | |
| 1535 | - successIconParts[i].style.background = params.background; | |
| 1536 | - } | |
| 1537 | - | |
| 1538 | - var title = getTitle(); | |
| 1539 | - var content = getContent(); | |
| 1540 | - var buttonsWrapper = getButtonsWrapper(); | |
| 1541 | - var confirmButton = getConfirmButton(); | |
| 1542 | - var cancelButton = getCancelButton(); | |
| 1543 | - var closeButton = getCloseButton(); | |
| 1544 | - | |
| 1545 | - // Title | |
| 1546 | - if (params.titleText) { | |
| 1547 | - title.innerText = params.titleText; | |
| 1548 | - } else { | |
| 1549 | - title.innerHTML = params.title.split('\n').join('<br>'); | |
| 1550 | - } | |
| 1551 | - | |
| 1552 | - // Content | |
| 1553 | - if (params.text || params.html) { | |
| 1554 | - if (_typeof(params.html) === 'object') { | |
| 1555 | - content.innerHTML = ''; | |
| 1556 | - if (0 in params.html) { | |
| 1557 | - for (var _i = 0; _i in params.html; _i++) { | |
| 1558 | - content.appendChild(params.html[_i].cloneNode(true)); | |
| 1559 | - } | |
| 1560 | - } else { | |
| 1561 | - content.appendChild(params.html.cloneNode(true)); | |
| 1562 | - } | |
| 1563 | - } else if (params.html) { | |
| 1564 | - content.innerHTML = params.html; | |
| 1565 | - } else if (params.text) { | |
| 1566 | - content.textContent = params.text; | |
| 1567 | - } | |
| 1568 | - show(content); | |
| 1569 | - } else { | |
| 1570 | - hide(content); | |
| 1571 | - } | |
| 1572 | - | |
| 1573 | - // Close button | |
| 1574 | - if (params.showCloseButton) { | |
| 1575 | - show(closeButton); | |
| 1576 | - } else { | |
| 1577 | - hide(closeButton); | |
| 1578 | - } | |
| 1579 | - | |
| 1580 | - // Custom Class | |
| 1581 | - modal.className = swalClasses.modal; | |
| 1582 | - if (params.customClass) { | |
| 1583 | - addClass(modal, params.customClass); | |
| 1584 | - } | |
| 1585 | - | |
| 1586 | - // Progress steps | |
| 1587 | - var progressStepsContainer = getProgressSteps(); | |
| 1588 | - var currentProgressStep = parseInt(params.currentProgressStep === null ? sweetAlert.getQueueStep() : params.currentProgressStep, 10); | |
| 1589 | - if (params.progressSteps.length) { | |
| 1590 | - show(progressStepsContainer); | |
| 1591 | - empty(progressStepsContainer); | |
| 1592 | - if (currentProgressStep >= params.progressSteps.length) { | |
| 1593 | - console.warn('SweetAlert2: Invalid currentProgressStep parameter, it should be less than progressSteps.length ' + '(currentProgressStep like JS arrays starts from 0)'); | |
| 1594 | - } | |
| 1595 | - params.progressSteps.forEach(function (step, index) { | |
| 1596 | - var circle = document.createElement('li'); | |
| 1597 | - addClass(circle, swalClasses.progresscircle); | |
| 1598 | - circle.innerHTML = step; | |
| 1599 | - if (index === currentProgressStep) { | |
| 1600 | - addClass(circle, swalClasses.activeprogressstep); | |
| 1601 | - } | |
| 1602 | - progressStepsContainer.appendChild(circle); | |
| 1603 | - if (index !== params.progressSteps.length - 1) { | |
| 1604 | - var line = document.createElement('li'); | |
| 1605 | - addClass(line, swalClasses.progressline); | |
| 1606 | - line.style.width = params.progressStepsDistance; | |
| 1607 | - progressStepsContainer.appendChild(line); | |
| 1608 | - } | |
| 1609 | - }); | |
| 1610 | - } else { | |
| 1611 | - hide(progressStepsContainer); | |
| 1612 | - } | |
| 1613 | - | |
| 1614 | - // Icon | |
| 1615 | - var icons = getIcons(); | |
| 1616 | - for (var _i2 = 0; _i2 < icons.length; _i2++) { | |
| 1617 | - hide(icons[_i2]); | |
| 1618 | - } | |
| 1619 | - if (params.type) { | |
| 1620 | - var validType = false; | |
| 1621 | - for (var iconType in iconTypes) { | |
| 1622 | - if (params.type === iconType) { | |
| 1623 | - validType = true; | |
| 1624 | - break; | |
| 1625 | - } | |
| 1626 | - } | |
| 1627 | - if (!validType) { | |
| 1628 | - console.error('SweetAlert2: Unknown alert type: ' + params.type); | |
| 1629 | - return false; | |
| 1630 | - } | |
| 1631 | - var icon = modal.querySelector('.' + swalClasses.icon + '.' + iconTypes[params.type]); | |
| 1632 | - show(icon); | |
| 1633 | - | |
| 1634 | - // Animate icon | |
| 1635 | - if (params.animation) { | |
| 1636 | - switch (params.type) { | |
| 1637 | - case 'success': | |
| 1638 | - addClass(icon, 'swal2-animate-success-icon'); | |
| 1639 | - addClass(icon.querySelector('.swal2-success-line-tip'), 'swal2-animate-success-line-tip'); | |
| 1640 | - addClass(icon.querySelector('.swal2-success-line-long'), 'swal2-animate-success-line-long'); | |
| 1641 | - break; | |
| 1642 | - case 'error': | |
| 1643 | - addClass(icon, 'swal2-animate-error-icon'); | |
| 1644 | - addClass(icon.querySelector('.swal2-x-mark'), 'swal2-animate-x-mark'); | |
| 1645 | - break; | |
| 1646 | - default: | |
| 1647 | - break; | |
| 1648 | - } | |
| 1649 | - } | |
| 1650 | - } | |
| 1651 | - | |
| 1652 | - // Custom image | |
| 1653 | - var image = getImage(); | |
| 1654 | - if (params.imageUrl) { | |
| 1655 | - image.setAttribute('src', params.imageUrl); | |
| 1656 | - show(image); | |
| 1657 | - | |
| 1658 | - if (params.imageWidth) { | |
| 1659 | - image.setAttribute('width', params.imageWidth); | |
| 1660 | - } else { | |
| 1661 | - image.removeAttribute('width'); | |
| 1662 | - } | |
| 1663 | - | |
| 1664 | - if (params.imageHeight) { | |
| 1665 | - image.setAttribute('height', params.imageHeight); | |
| 1666 | - } else { | |
| 1667 | - image.removeAttribute('height'); | |
| 1668 | - } | |
| 1669 | - | |
| 1670 | - image.className = swalClasses.image; | |
| 1671 | - if (params.imageClass) { | |
| 1672 | - addClass(image, params.imageClass); | |
| 1673 | - } | |
| 1674 | - } else { | |
| 1675 | - hide(image); | |
| 1676 | - } | |
| 1677 | - | |
| 1678 | - // Cancel button | |
| 1679 | - if (params.showCancelButton) { | |
| 1680 | - cancelButton.style.display = 'inline-block'; | |
| 1681 | - } else { | |
| 1682 | - hide(cancelButton); | |
| 1683 | - } | |
| 1684 | - | |
| 1685 | - // Confirm button | |
| 1686 | - if (params.showConfirmButton) { | |
| 1687 | - removeStyleProperty(confirmButton, 'display'); | |
| 1688 | - } else { | |
| 1689 | - hide(confirmButton); | |
| 1690 | - } | |
| 1691 | - | |
| 1692 | - // Buttons wrapper | |
| 1693 | - if (!params.showConfirmButton && !params.showCancelButton) { | |
| 1694 | - hide(buttonsWrapper); | |
| 1695 | - } else { | |
| 1696 | - show(buttonsWrapper); | |
| 1697 | - } | |
| 1698 | - | |
| 1699 | - // Edit text on cancel and confirm buttons | |
| 1700 | - confirmButton.innerHTML = params.confirmButtonText; | |
| 1701 | - cancelButton.innerHTML = params.cancelButtonText; | |
| 1702 | - | |
| 1703 | - // Set buttons to selected background colors | |
| 1704 | - if (params.buttonsStyling) { | |
| 1705 | - confirmButton.style.backgroundColor = params.confirmButtonColor; | |
| 1706 | - cancelButton.style.backgroundColor = params.cancelButtonColor; | |
| 1707 | - } | |
| 1708 | - | |
| 1709 | - // Add buttons custom classes | |
| 1710 | - confirmButton.className = swalClasses.confirm; | |
| 1711 | - addClass(confirmButton, params.confirmButtonClass); | |
| 1712 | - cancelButton.className = swalClasses.cancel; | |
| 1713 | - addClass(cancelButton, params.cancelButtonClass); | |
| 1714 | - | |
| 1715 | - // Buttons styling | |
| 1716 | - if (params.buttonsStyling) { | |
| 1717 | - addClass(confirmButton, swalClasses.styled); | |
| 1718 | - addClass(cancelButton, swalClasses.styled); | |
| 1719 | - } else { | |
| 1720 | - removeClass(confirmButton, swalClasses.styled); | |
| 1721 | - removeClass(cancelButton, swalClasses.styled); | |
| 1722 | - | |
| 1723 | - confirmButton.style.backgroundColor = confirmButton.style.borderLeftColor = confirmButton.style.borderRightColor = ''; | |
| 1724 | - cancelButton.style.backgroundColor = cancelButton.style.borderLeftColor = cancelButton.style.borderRightColor = ''; | |
| 1725 | - } | |
| 1726 | - | |
| 1727 | - // CSS animation | |
| 1728 | - if (params.animation === true) { | |
| 1729 | - removeClass(modal, swalClasses.noanimation); | |
| 1730 | - } else { | |
| 1731 | - addClass(modal, swalClasses.noanimation); | |
| 1732 | - } | |
| 1733 | -}; | |
| 1734 | - | |
| 1735 | -/* | |
| 1736 | - * Animations | |
| 1737 | - */ | |
| 1738 | -var openModal = function openModal(animation, onComplete) { | |
| 1739 | - var container = getContainer(); | |
| 1740 | - var modal = getModal(); | |
| 1741 | - | |
| 1742 | - if (animation) { | |
| 1743 | - addClass(modal, swalClasses.show); | |
| 1744 | - addClass(container, swalClasses.fade); | |
| 1745 | - removeClass(modal, swalClasses.hide); | |
| 1746 | - } else { | |
| 1747 | - removeClass(modal, swalClasses.fade); | |
| 1748 | - } | |
| 1749 | - show(modal); | |
| 1750 | - | |
| 1751 | - // scrolling is 'hidden' until animation is done, after that 'auto' | |
| 1752 | - container.style.overflowY = 'hidden'; | |
| 1753 | - if (animationEndEvent && !hasClass(modal, swalClasses.noanimation)) { | |
| 1754 | - modal.addEventListener(animationEndEvent, function swalCloseEventFinished() { | |
| 1755 | - modal.removeEventListener(animationEndEvent, swalCloseEventFinished); | |
| 1756 | - container.style.overflowY = 'auto'; | |
| 1757 | - }); | |
| 1758 | - } else { | |
| 1759 | - container.style.overflowY = 'auto'; | |
| 1760 | - } | |
| 1761 | - | |
| 1762 | - addClass(document.documentElement, swalClasses.shown); | |
| 1763 | - addClass(document.body, swalClasses.shown); | |
| 1764 | - addClass(container, swalClasses.shown); | |
| 1765 | - fixScrollbar(); | |
| 1766 | - iOSfix(); | |
| 1767 | - states.previousActiveElement = document.activeElement; | |
| 1768 | - if (onComplete !== null && typeof onComplete === 'function') { | |
| 1769 | - setTimeout(function () { | |
| 1770 | - onComplete(modal); | |
| 1771 | - }); | |
| 1772 | - } | |
| 1773 | -}; | |
| 1774 | - | |
| 1775 | -var fixScrollbar = function fixScrollbar() { | |
| 1776 | - // for queues, do not do this more than once | |
| 1777 | - if (states.previousBodyPadding !== null) { | |
| 1778 | - return; | |
| 1779 | - } | |
| 1780 | - // if the body has overflow | |
| 1781 | - if (document.body.scrollHeight > window.innerHeight) { | |
| 1782 | - // add padding so the content doesn't shift after removal of scrollbar | |
| 1783 | - states.previousBodyPadding = document.body.style.paddingRight; | |
| 1784 | - document.body.style.paddingRight = measureScrollbar() + 'px'; | |
| 1785 | - } | |
| 1786 | -}; | |
| 1787 | - | |
| 1788 | -var undoScrollbar = function undoScrollbar() { | |
| 1789 | - if (states.previousBodyPadding !== null) { | |
| 1790 | - document.body.style.paddingRight = states.previousBodyPadding; | |
| 1791 | - states.previousBodyPadding = null; | |
| 1792 | - } | |
| 1793 | -}; | |
| 1794 | - | |
| 1795 | -// Fix iOS scrolling http://stackoverflow.com/q/39626302/1331425 | |
| 1796 | -var iOSfix = function iOSfix() { | |
| 1797 | - var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; | |
| 1798 | - if (iOS && !hasClass(document.body, swalClasses.iosfix)) { | |
| 1799 | - var offset = document.body.scrollTop; | |
| 1800 | - document.body.style.top = offset * -1 + 'px'; | |
| 1801 | - addClass(document.body, swalClasses.iosfix); | |
| 1802 | - } | |
| 1803 | -}; | |
| 1804 | - | |
| 1805 | -var undoIOSfix = function undoIOSfix() { | |
| 1806 | - if (hasClass(document.body, swalClasses.iosfix)) { | |
| 1807 | - var offset = parseInt(document.body.style.top, 10); | |
| 1808 | - removeClass(document.body, swalClasses.iosfix); | |
| 1809 | - document.body.style.top = ''; | |
| 1810 | - document.body.scrollTop = offset * -1; | |
| 1811 | - } | |
| 1812 | -}; | |
| 1813 | - | |
| 1814 | -// SweetAlert entry point | |
| 1815 | -var sweetAlert = function sweetAlert() { | |
| 1816 | - for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | |
| 1817 | - args[_key] = arguments[_key]; | |
| 1818 | - } | |
| 1819 | - | |
| 1820 | - if (args[0] === undefined) { | |
| 1821 | - console.error('SweetAlert2 expects at least 1 attribute!'); | |
| 1822 | - return false; | |
| 1823 | - } | |
| 1824 | - | |
| 1825 | - var params = _extends({}, modalParams); | |
| 1826 | - | |
| 1827 | - switch (_typeof(args[0])) { | |
| 1828 | - case 'string': | |
| 1829 | - params.title = args[0]; | |
| 1830 | - params.html = args[1]; | |
| 1831 | - params.type = args[2]; | |
| 1832 | - | |
| 1833 | - break; | |
| 1834 | - | |
| 1835 | - case 'object': | |
| 1836 | - _extends(params, args[0]); | |
| 1837 | - params.extraParams = args[0].extraParams; | |
| 1838 | - | |
| 1839 | - if (params.input === 'email' && params.inputValidator === null) { | |
| 1840 | - params.inputValidator = function (email) { | |
| 1841 | - return new Promise(function (resolve, reject) { | |
| 1842 | - var emailRegex = /^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/; | |
| 1843 | - if (emailRegex.test(email)) { | |
| 1844 | - resolve(); | |
| 1845 | - } else { | |
| 1846 | - reject('Invalid email address'); | |
| 1847 | - } | |
| 1848 | - }); | |
| 1849 | - }; | |
| 1850 | - } | |
| 1851 | - | |
| 1852 | - if (params.input === 'url' && params.inputValidator === null) { | |
| 1853 | - params.inputValidator = function (url) { | |
| 1854 | - return new Promise(function (resolve, reject) { | |
| 1855 | - var urlRegex = /^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?$/; | |
| 1856 | - if (urlRegex.test(url)) { | |
| 1857 | - resolve(); | |
| 1858 | - } else { | |
| 1859 | - reject('Invalid URL'); | |
| 1860 | - } | |
| 1861 | - }); | |
| 1862 | - }; | |
| 1863 | - } | |
| 1864 | - break; | |
| 1865 | - | |
| 1866 | - default: | |
| 1867 | - console.error('SweetAlert2: Unexpected type of argument! Expected "string" or "object", got ' + _typeof(args[0])); | |
| 1868 | - return false; | |
| 1869 | - } | |
| 1870 | - | |
| 1871 | - setParameters(params); | |
| 1872 | - | |
| 1873 | - var container = getContainer(); | |
| 1874 | - var modal = getModal(); | |
| 1875 | - | |
| 1876 | - return new Promise(function (resolve, reject) { | |
| 1877 | - // Close on timer | |
| 1878 | - if (params.timer) { | |
| 1879 | - modal.timeout = setTimeout(function () { | |
| 1880 | - sweetAlert.closeModal(params.onClose); | |
| 1881 | - if (params.useRejections) { | |
| 1882 | - reject('timer'); | |
| 1883 | - } else { | |
| 1884 | - resolve({ dismiss: 'timer' }); | |
| 1885 | - } | |
| 1886 | - }, params.timer); | |
| 1887 | - } | |
| 1888 | - | |
| 1889 | - // Get input element by specified type or, if type isn't specified, by params.input | |
| 1890 | - var getInput = function getInput(inputType) { | |
| 1891 | - inputType = inputType || params.input; | |
| 1892 | - if (!inputType) { | |
| 1893 | - return null; | |
| 1894 | - } | |
| 1895 | - switch (inputType) { | |
| 1896 | - case 'select': | |
| 1897 | - case 'textarea': | |
| 1898 | - case 'file': | |
| 1899 | - return getChildByClass(modal, swalClasses[inputType]); | |
| 1900 | - case 'checkbox': | |
| 1901 | - return modal.querySelector('.' + swalClasses.checkbox + ' input'); | |
| 1902 | - case 'radio': | |
| 1903 | - return modal.querySelector('.' + swalClasses.radio + ' input:checked') || modal.querySelector('.' + swalClasses.radio + ' input:first-child'); | |
| 1904 | - case 'range': | |
| 1905 | - return modal.querySelector('.' + swalClasses.range + ' input'); | |
| 1906 | - default: | |
| 1907 | - return getChildByClass(modal, swalClasses.input); | |
| 1908 | - } | |
| 1909 | - }; | |
| 1910 | - | |
| 1911 | - // Get the value of the modal input | |
| 1912 | - var getInputValue = function getInputValue() { | |
| 1913 | - var input = getInput(); | |
| 1914 | - if (!input) { | |
| 1915 | - return null; | |
| 1916 | - } | |
| 1917 | - switch (params.input) { | |
| 1918 | - case 'checkbox': | |
| 1919 | - return input.checked ? 1 : 0; | |
| 1920 | - case 'radio': | |
| 1921 | - return input.checked ? input.value : null; | |
| 1922 | - case 'file': | |
| 1923 | - return input.files.length ? input.files[0] : null; | |
| 1924 | - default: | |
| 1925 | - return params.inputAutoTrim ? input.value.trim() : input.value; | |
| 1926 | - } | |
| 1927 | - }; | |
| 1928 | - | |
| 1929 | - // input autofocus | |
| 1930 | - if (params.input) { | |
| 1931 | - setTimeout(function () { | |
| 1932 | - var input = getInput(); | |
| 1933 | - if (input) { | |
| 1934 | - focusInput(input); | |
| 1935 | - } | |
| 1936 | - }, 0); | |
| 1937 | - } | |
| 1938 | - | |
| 1939 | - var confirm = function confirm(value) { | |
| 1940 | - if (params.showLoaderOnConfirm) { | |
| 1941 | - sweetAlert.showLoading(); | |
| 1942 | - } | |
| 1943 | - | |
| 1944 | - if (params.preConfirm) { | |
| 1945 | - params.preConfirm(value, params.extraParams).then(function (preConfirmValue) { | |
| 1946 | - sweetAlert.closeModal(params.onClose); | |
| 1947 | - resolve(preConfirmValue || value); | |
| 1948 | - }, function (error) { | |
| 1949 | - sweetAlert.hideLoading(); | |
| 1950 | - if (error) { | |
| 1951 | - sweetAlert.showValidationError(error); | |
| 1952 | - } | |
| 1953 | - }); | |
| 1954 | - } else { | |
| 1955 | - sweetAlert.closeModal(params.onClose); | |
| 1956 | - if (params.useRejections) { | |
| 1957 | - resolve(value); | |
| 1958 | - } else { | |
| 1959 | - resolve({ value: value }); | |
| 1960 | - } | |
| 1961 | - } | |
| 1962 | - }; | |
| 1963 | - | |
| 1964 | - // Mouse interactions | |
| 1965 | - var onButtonEvent = function onButtonEvent(event) { | |
| 1966 | - var e = event || window.event; | |
| 1967 | - var target = e.target || e.srcElement; | |
| 1968 | - var confirmButton = getConfirmButton(); | |
| 1969 | - var cancelButton = getCancelButton(); | |
| 1970 | - var targetedConfirm = confirmButton && (confirmButton === target || confirmButton.contains(target)); | |
| 1971 | - var targetedCancel = cancelButton && (cancelButton === target || cancelButton.contains(target)); | |
| 1972 | - | |
| 1973 | - switch (e.type) { | |
| 1974 | - case 'mouseover': | |
| 1975 | - case 'mouseup': | |
| 1976 | - if (params.buttonsStyling) { | |
| 1977 | - if (targetedConfirm) { | |
| 1978 | - confirmButton.style.backgroundColor = colorLuminance(params.confirmButtonColor, -0.1); | |
| 1979 | - } else if (targetedCancel) { | |
| 1980 | - cancelButton.style.backgroundColor = colorLuminance(params.cancelButtonColor, -0.1); | |
| 1981 | - } | |
| 1982 | - } | |
| 1983 | - break; | |
| 1984 | - case 'mouseout': | |
| 1985 | - if (params.buttonsStyling) { | |
| 1986 | - if (targetedConfirm) { | |
| 1987 | - confirmButton.style.backgroundColor = params.confirmButtonColor; | |
| 1988 | - } else if (targetedCancel) { | |
| 1989 | - cancelButton.style.backgroundColor = params.cancelButtonColor; | |
| 1990 | - } | |
| 1991 | - } | |
| 1992 | - break; | |
| 1993 | - case 'mousedown': | |
| 1994 | - if (params.buttonsStyling) { | |
| 1995 | - if (targetedConfirm) { | |
| 1996 | - confirmButton.style.backgroundColor = colorLuminance(params.confirmButtonColor, -0.2); | |
| 1997 | - } else if (targetedCancel) { | |
| 1998 | - cancelButton.style.backgroundColor = colorLuminance(params.cancelButtonColor, -0.2); | |
| 1999 | - } | |
| 2000 | - } | |
| 2001 | - break; | |
| 2002 | - case 'click': | |
| 2003 | - // Clicked 'confirm' | |
| 2004 | - if (targetedConfirm && sweetAlert.isVisible()) { | |
| 2005 | - sweetAlert.disableButtons(); | |
| 2006 | - if (params.input) { | |
| 2007 | - var inputValue = getInputValue(); | |
| 2008 | - | |
| 2009 | - if (params.inputValidator) { | |
| 2010 | - sweetAlert.disableInput(); | |
| 2011 | - params.inputValidator(inputValue, params.extraParams).then(function () { | |
| 2012 | - sweetAlert.enableButtons(); | |
| 2013 | - sweetAlert.enableInput(); | |
| 2014 | - confirm(inputValue); | |
| 2015 | - }, function (error) { | |
| 2016 | - sweetAlert.enableButtons(); | |
| 2017 | - sweetAlert.enableInput(); | |
| 2018 | - if (error) { | |
| 2019 | - sweetAlert.showValidationError(error); | |
| 2020 | - } | |
| 2021 | - }); | |
| 2022 | - } else { | |
| 2023 | - confirm(inputValue); | |
| 2024 | - } | |
| 2025 | - } else { | |
| 2026 | - confirm(true); | |
| 2027 | - } | |
| 2028 | - | |
| 2029 | - // Clicked 'cancel' | |
| 2030 | - } else if (targetedCancel && sweetAlert.isVisible()) { | |
| 2031 | - sweetAlert.disableButtons(); | |
| 2032 | - sweetAlert.closeModal(params.onClose); | |
| 2033 | - if (params.useRejections) { | |
| 2034 | - reject('cancel'); | |
| 2035 | - } else { | |
| 2036 | - resolve({ dismiss: 'cancel' }); | |
| 2037 | - } | |
| 2038 | - } | |
| 2039 | - break; | |
| 2040 | - default: | |
| 2041 | - } | |
| 2042 | - }; | |
| 2043 | - | |
| 2044 | - var buttons = modal.querySelectorAll('button'); | |
| 2045 | - for (var i = 0; i < buttons.length; i++) { | |
| 2046 | - buttons[i].onclick = onButtonEvent; | |
| 2047 | - buttons[i].onmouseover = onButtonEvent; | |
| 2048 | - buttons[i].onmouseout = onButtonEvent; | |
| 2049 | - buttons[i].onmousedown = onButtonEvent; | |
| 2050 | - } | |
| 2051 | - | |
| 2052 | - // Closing modal by close button | |
| 2053 | - getCloseButton().onclick = function () { | |
| 2054 | - sweetAlert.closeModal(params.onClose); | |
| 2055 | - if (params.useRejections) { | |
| 2056 | - reject('close'); | |
| 2057 | - } else { | |
| 2058 | - resolve({ dismiss: 'close' }); | |
| 2059 | - } | |
| 2060 | - }; | |
| 2061 | - | |
| 2062 | - // Closing modal by overlay click | |
| 2063 | - container.onclick = function (e) { | |
| 2064 | - if (e.target !== container) { | |
| 2065 | - return; | |
| 2066 | - } | |
| 2067 | - if (params.allowOutsideClick) { | |
| 2068 | - sweetAlert.closeModal(params.onClose); | |
| 2069 | - if (params.useRejections) { | |
| 2070 | - reject('overlay'); | |
| 2071 | - } else { | |
| 2072 | - resolve({ dismiss: 'overlay' }); | |
| 2073 | - } | |
| 2074 | - } | |
| 2075 | - }; | |
| 2076 | - | |
| 2077 | - var buttonsWrapper = getButtonsWrapper(); | |
| 2078 | - var confirmButton = getConfirmButton(); | |
| 2079 | - var cancelButton = getCancelButton(); | |
| 2080 | - | |
| 2081 | - // Reverse buttons (Confirm on the right side) | |
| 2082 | - if (params.reverseButtons) { | |
| 2083 | - confirmButton.parentNode.insertBefore(cancelButton, confirmButton); | |
| 2084 | - } else { | |
| 2085 | - confirmButton.parentNode.insertBefore(confirmButton, cancelButton); | |
| 2086 | - } | |
| 2087 | - | |
| 2088 | - // Focus handling | |
| 2089 | - var setFocus = function setFocus(index, increment) { | |
| 2090 | - var focusableElements = getFocusableElements(params.focusCancel); | |
| 2091 | - // search for visible elements and select the next possible match | |
| 2092 | - for (var _i3 = 0; _i3 < focusableElements.length; _i3++) { | |
| 2093 | - index = index + increment; | |
| 2094 | - | |
| 2095 | - // rollover to first item | |
| 2096 | - if (index === focusableElements.length) { | |
| 2097 | - index = 0; | |
| 2098 | - | |
| 2099 | - // go to last item | |
| 2100 | - } else if (index === -1) { | |
| 2101 | - index = focusableElements.length - 1; | |
| 2102 | - } | |
| 2103 | - | |
| 2104 | - // determine if element is visible | |
| 2105 | - var el = focusableElements[index]; | |
| 2106 | - if (isVisible(el)) { | |
| 2107 | - return el.focus(); | |
| 2108 | - } | |
| 2109 | - } | |
| 2110 | - }; | |
| 2111 | - | |
| 2112 | - var handleKeyDown = function handleKeyDown(event) { | |
| 2113 | - var e = event || window.event; | |
| 2114 | - var keyCode = e.keyCode || e.which; | |
| 2115 | - | |
| 2116 | - if ([9, 13, 32, 27, 37, 38, 39, 40].indexOf(keyCode) === -1) { | |
| 2117 | - // Don't do work on keys we don't care about. | |
| 2118 | - return; | |
| 2119 | - } | |
| 2120 | - | |
| 2121 | - var targetElement = e.target || e.srcElement; | |
| 2122 | - | |
| 2123 | - var focusableElements = getFocusableElements(params.focusCancel); | |
| 2124 | - var btnIndex = -1; // Find the button - note, this is a nodelist, not an array. | |
| 2125 | - for (var _i4 = 0; _i4 < focusableElements.length; _i4++) { | |
| 2126 | - if (targetElement === focusableElements[_i4]) { | |
| 2127 | - btnIndex = _i4; | |
| 2128 | - break; | |
| 2129 | - } | |
| 2130 | - } | |
| 2131 | - | |
| 2132 | - // TAB | |
| 2133 | - if (keyCode === 9) { | |
| 2134 | - if (!e.shiftKey) { | |
| 2135 | - // Cycle to the next button | |
| 2136 | - setFocus(btnIndex, 1); | |
| 2137 | - } else { | |
| 2138 | - // Cycle to the prev button | |
| 2139 | - setFocus(btnIndex, -1); | |
| 2140 | - } | |
| 2141 | - e.stopPropagation(); | |
| 2142 | - e.preventDefault(); | |
| 2143 | - | |
| 2144 | - // ARROWS - switch focus between buttons | |
| 2145 | - } else if (keyCode === 37 || keyCode === 38 || keyCode === 39 || keyCode === 40) { | |
| 2146 | - // focus Cancel button if Confirm button is currently focused | |
| 2147 | - if (document.activeElement === confirmButton && isVisible(cancelButton)) { | |
| 2148 | - cancelButton.focus(); | |
| 2149 | - // and vice versa | |
| 2150 | - } else if (document.activeElement === cancelButton && isVisible(confirmButton)) { | |
| 2151 | - confirmButton.focus(); | |
| 2152 | - } | |
| 2153 | - | |
| 2154 | - // ENTER/SPACE | |
| 2155 | - } else if (keyCode === 13 || keyCode === 32) { | |
| 2156 | - if (btnIndex === -1 && params.allowEnterKey) { | |
| 2157 | - // ENTER/SPACE clicked outside of a button. | |
| 2158 | - if (params.focusCancel) { | |
| 2159 | - fireClick(cancelButton, e); | |
| 2160 | - } else { | |
| 2161 | - fireClick(confirmButton, e); | |
| 2162 | - } | |
| 2163 | - e.stopPropagation(); | |
| 2164 | - e.preventDefault(); | |
| 2165 | - } | |
| 2166 | - | |
| 2167 | - // ESC | |
| 2168 | - } else if (keyCode === 27 && params.allowEscapeKey === true) { | |
| 2169 | - sweetAlert.closeModal(params.onClose); | |
| 2170 | - if (params.useRejections) { | |
| 2171 | - reject('esc'); | |
| 2172 | - } else { | |
| 2173 | - resolve({ dismiss: 'esc' }); | |
| 2174 | - } | |
| 2175 | - } | |
| 2176 | - }; | |
| 2177 | - | |
| 2178 | - if (!window.onkeydown || window.onkeydown.toString() !== handleKeyDown.toString()) { | |
| 2179 | - states.previousWindowKeyDown = window.onkeydown; | |
| 2180 | - window.onkeydown = handleKeyDown; | |
| 2181 | - } | |
| 2182 | - | |
| 2183 | - // Loading state | |
| 2184 | - if (params.buttonsStyling) { | |
| 2185 | - confirmButton.style.borderLeftColor = params.confirmButtonColor; | |
| 2186 | - confirmButton.style.borderRightColor = params.confirmButtonColor; | |
| 2187 | - } | |
| 2188 | - | |
| 2189 | - /** | |
| 2190 | - * Show spinner instead of Confirm button and disable Cancel button | |
| 2191 | - */ | |
| 2192 | - sweetAlert.hideLoading = sweetAlert.disableLoading = function () { | |
| 2193 | - if (!params.showConfirmButton) { | |
| 2194 | - hide(confirmButton); | |
| 2195 | - if (!params.showCancelButton) { | |
| 2196 | - hide(getButtonsWrapper()); | |
| 2197 | - } | |
| 2198 | - } | |
| 2199 | - removeClass(buttonsWrapper, swalClasses.loading); | |
| 2200 | - removeClass(modal, swalClasses.loading); | |
| 2201 | - confirmButton.disabled = false; | |
| 2202 | - cancelButton.disabled = false; | |
| 2203 | - }; | |
| 2204 | - | |
| 2205 | - sweetAlert.getTitle = function () { | |
| 2206 | - return getTitle(); | |
| 2207 | - }; | |
| 2208 | - sweetAlert.getContent = function () { | |
| 2209 | - return getContent(); | |
| 2210 | - }; | |
| 2211 | - sweetAlert.getInput = function () { | |
| 2212 | - return getInput(); | |
| 2213 | - }; | |
| 2214 | - sweetAlert.getImage = function () { | |
| 2215 | - return getImage(); | |
| 2216 | - }; | |
| 2217 | - sweetAlert.getButtonsWrapper = function () { | |
| 2218 | - return getButtonsWrapper(); | |
| 2219 | - }; | |
| 2220 | - sweetAlert.getConfirmButton = function () { | |
| 2221 | - return getConfirmButton(); | |
| 2222 | - }; | |
| 2223 | - sweetAlert.getCancelButton = function () { | |
| 2224 | - return getCancelButton(); | |
| 2225 | - }; | |
| 2226 | - | |
| 2227 | - sweetAlert.enableButtons = function () { | |
| 2228 | - confirmButton.disabled = false; | |
| 2229 | - cancelButton.disabled = false; | |
| 2230 | - }; | |
| 2231 | - | |
| 2232 | - sweetAlert.disableButtons = function () { | |
| 2233 | - confirmButton.disabled = true; | |
| 2234 | - cancelButton.disabled = true; | |
| 2235 | - }; | |
| 2236 | - | |
| 2237 | - sweetAlert.enableConfirmButton = function () { | |
| 2238 | - confirmButton.disabled = false; | |
| 2239 | - }; | |
| 2240 | - | |
| 2241 | - sweetAlert.disableConfirmButton = function () { | |
| 2242 | - confirmButton.disabled = true; | |
| 2243 | - }; | |
| 2244 | - | |
| 2245 | - sweetAlert.enableInput = function () { | |
| 2246 | - var input = getInput(); | |
| 2247 | - if (!input) { | |
| 2248 | - return false; | |
| 2249 | - } | |
| 2250 | - if (input.type === 'radio') { | |
| 2251 | - var radiosContainer = input.parentNode.parentNode; | |
| 2252 | - var radios = radiosContainer.querySelectorAll('input'); | |
| 2253 | - for (var _i5 = 0; _i5 < radios.length; _i5++) { | |
| 2254 | - radios[_i5].disabled = false; | |
| 2255 | - } | |
| 2256 | - } else { | |
| 2257 | - input.disabled = false; | |
| 2258 | - } | |
| 2259 | - }; | |
| 2260 | - | |
| 2261 | - sweetAlert.disableInput = function () { | |
| 2262 | - var input = getInput(); | |
| 2263 | - if (!input) { | |
| 2264 | - return false; | |
| 2265 | - } | |
| 2266 | - if (input && input.type === 'radio') { | |
| 2267 | - var radiosContainer = input.parentNode.parentNode; | |
| 2268 | - var radios = radiosContainer.querySelectorAll('input'); | |
| 2269 | - for (var _i6 = 0; _i6 < radios.length; _i6++) { | |
| 2270 | - radios[_i6].disabled = true; | |
| 2271 | - } | |
| 2272 | - } else { | |
| 2273 | - input.disabled = true; | |
| 2274 | - } | |
| 2275 | - }; | |
| 2276 | - | |
| 2277 | - // Set modal min-height to disable scrolling inside the modal | |
| 2278 | - sweetAlert.recalculateHeight = debounce(function () { | |
| 2279 | - var modal = getModal(); | |
| 2280 | - if (!modal) { | |
| 2281 | - return; | |
| 2282 | - } | |
| 2283 | - var prevState = modal.style.display; | |
| 2284 | - modal.style.minHeight = ''; | |
| 2285 | - show(modal); | |
| 2286 | - modal.style.minHeight = modal.scrollHeight + 1 + 'px'; | |
| 2287 | - modal.style.display = prevState; | |
| 2288 | - }, 50); | |
| 2289 | - | |
| 2290 | - // Show block with validation error | |
| 2291 | - sweetAlert.showValidationError = function (error) { | |
| 2292 | - var validationError = getValidationError(); | |
| 2293 | - validationError.innerHTML = error; | |
| 2294 | - show(validationError); | |
| 2295 | - | |
| 2296 | - var input = getInput(); | |
| 2297 | - if (input) { | |
| 2298 | - focusInput(input); | |
| 2299 | - addClass(input, swalClasses.inputerror); | |
| 2300 | - } | |
| 2301 | - }; | |
| 2302 | - | |
| 2303 | - // Hide block with validation error | |
| 2304 | - sweetAlert.resetValidationError = function () { | |
| 2305 | - var validationError = getValidationError(); | |
| 2306 | - hide(validationError); | |
| 2307 | - sweetAlert.recalculateHeight(); | |
| 2308 | - | |
| 2309 | - var input = getInput(); | |
| 2310 | - if (input) { | |
| 2311 | - removeClass(input, swalClasses.inputerror); | |
| 2312 | - } | |
| 2313 | - }; | |
| 2314 | - | |
| 2315 | - sweetAlert.getProgressSteps = function () { | |
| 2316 | - return params.progressSteps; | |
| 2317 | - }; | |
| 2318 | - | |
| 2319 | - sweetAlert.setProgressSteps = function (progressSteps) { | |
| 2320 | - params.progressSteps = progressSteps; | |
| 2321 | - setParameters(params); | |
| 2322 | - }; | |
| 2323 | - | |
| 2324 | - sweetAlert.showProgressSteps = function () { | |
| 2325 | - show(getProgressSteps()); | |
| 2326 | - }; | |
| 2327 | - | |
| 2328 | - sweetAlert.hideProgressSteps = function () { | |
| 2329 | - hide(getProgressSteps()); | |
| 2330 | - }; | |
| 2331 | - | |
| 2332 | - sweetAlert.enableButtons(); | |
| 2333 | - sweetAlert.hideLoading(); | |
| 2334 | - sweetAlert.resetValidationError(); | |
| 2335 | - | |
| 2336 | - // inputs | |
| 2337 | - var inputTypes = ['input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea']; | |
| 2338 | - var input = void 0; | |
| 2339 | - for (var _i7 = 0; _i7 < inputTypes.length; _i7++) { | |
| 2340 | - var inputClass = swalClasses[inputTypes[_i7]]; | |
| 2341 | - var inputContainer = getChildByClass(modal, inputClass); | |
| 2342 | - input = getInput(inputTypes[_i7]); | |
| 2343 | - | |
| 2344 | - // set attributes | |
| 2345 | - if (input) { | |
| 2346 | - for (var j in input.attributes) { | |
| 2347 | - if (input.attributes.hasOwnProperty(j)) { | |
| 2348 | - var attrName = input.attributes[j].name; | |
| 2349 | - if (attrName !== 'type' && attrName !== 'value') { | |
| 2350 | - input.removeAttribute(attrName); | |
| 2351 | - } | |
| 2352 | - } | |
| 2353 | - } | |
| 2354 | - for (var attr in params.inputAttributes) { | |
| 2355 | - input.setAttribute(attr, params.inputAttributes[attr]); | |
| 2356 | - } | |
| 2357 | - } | |
| 2358 | - | |
| 2359 | - // set class | |
| 2360 | - inputContainer.className = inputClass; | |
| 2361 | - if (params.inputClass) { | |
| 2362 | - addClass(inputContainer, params.inputClass); | |
| 2363 | - } | |
| 2364 | - | |
| 2365 | - hide(inputContainer); | |
| 2366 | - } | |
| 2367 | - | |
| 2368 | - var populateInputOptions = void 0; | |
| 2369 | - switch (params.input) { | |
| 2370 | - case 'text': | |
| 2371 | - case 'email': | |
| 2372 | - case 'password': | |
| 2373 | - case 'number': | |
| 2374 | - case 'tel': | |
| 2375 | - case 'url': | |
| 2376 | - input = getChildByClass(modal, swalClasses.input); | |
| 2377 | - input.value = params.inputValue; | |
| 2378 | - input.placeholder = params.inputPlaceholder; | |
| 2379 | - input.type = params.input; | |
| 2380 | - show(input); | |
| 2381 | - break; | |
| 2382 | - case 'file': | |
| 2383 | - input = getChildByClass(modal, swalClasses.file); | |
| 2384 | - input.placeholder = params.inputPlaceholder; | |
| 2385 | - input.type = params.input; | |
| 2386 | - show(input); | |
| 2387 | - break; | |
| 2388 | - case 'range': | |
| 2389 | - var range = getChildByClass(modal, swalClasses.range); | |
| 2390 | - var rangeInput = range.querySelector('input'); | |
| 2391 | - var rangeOutput = range.querySelector('output'); | |
| 2392 | - rangeInput.value = params.inputValue; | |
| 2393 | - rangeInput.type = params.input; | |
| 2394 | - rangeOutput.value = params.inputValue; | |
| 2395 | - show(range); | |
| 2396 | - break; | |
| 2397 | - case 'select': | |
| 2398 | - var select = getChildByClass(modal, swalClasses.select); | |
| 2399 | - select.innerHTML = ''; | |
| 2400 | - if (params.inputPlaceholder) { | |
| 2401 | - var placeholder = document.createElement('option'); | |
| 2402 | - placeholder.innerHTML = params.inputPlaceholder; | |
| 2403 | - placeholder.value = ''; | |
| 2404 | - placeholder.disabled = true; | |
| 2405 | - placeholder.selected = true; | |
| 2406 | - select.appendChild(placeholder); | |
| 2407 | - } | |
| 2408 | - populateInputOptions = function populateInputOptions(inputOptions) { | |
| 2409 | - for (var optionValue in inputOptions) { | |
| 2410 | - var option = document.createElement('option'); | |
| 2411 | - option.value = optionValue; | |
| 2412 | - option.innerHTML = inputOptions[optionValue]; | |
| 2413 | - if (params.inputValue === optionValue) { | |
| 2414 | - option.selected = true; | |
| 2415 | - } | |
| 2416 | - select.appendChild(option); | |
| 2417 | - } | |
| 2418 | - show(select); | |
| 2419 | - select.focus(); | |
| 2420 | - }; | |
| 2421 | - break; | |
| 2422 | - case 'radio': | |
| 2423 | - var radio = getChildByClass(modal, swalClasses.radio); | |
| 2424 | - radio.innerHTML = ''; | |
| 2425 | - populateInputOptions = function populateInputOptions(inputOptions) { | |
| 2426 | - for (var radioValue in inputOptions) { | |
| 2427 | - var radioInput = document.createElement('input'); | |
| 2428 | - var radioLabel = document.createElement('label'); | |
| 2429 | - var radioLabelSpan = document.createElement('span'); | |
| 2430 | - radioInput.type = 'radio'; | |
| 2431 | - radioInput.name = swalClasses.radio; | |
| 2432 | - radioInput.value = radioValue; | |
| 2433 | - if (params.inputValue === radioValue) { | |
| 2434 | - radioInput.checked = true; | |
| 2435 | - } | |
| 2436 | - radioLabelSpan.innerHTML = inputOptions[radioValue]; | |
| 2437 | - radioLabel.appendChild(radioInput); | |
| 2438 | - radioLabel.appendChild(radioLabelSpan); | |
| 2439 | - radioLabel.for = radioInput.id; | |
| 2440 | - radio.appendChild(radioLabel); | |
| 2441 | - } | |
| 2442 | - show(radio); | |
| 2443 | - var radios = radio.querySelectorAll('input'); | |
| 2444 | - if (radios.length) { | |
| 2445 | - radios[0].focus(); | |
| 2446 | - } | |
| 2447 | - }; | |
| 2448 | - break; | |
| 2449 | - case 'checkbox': | |
| 2450 | - var checkbox = getChildByClass(modal, swalClasses.checkbox); | |
| 2451 | - var checkboxInput = getInput('checkbox'); | |
| 2452 | - checkboxInput.type = 'checkbox'; | |
| 2453 | - checkboxInput.value = 1; | |
| 2454 | - checkboxInput.id = swalClasses.checkbox; | |
| 2455 | - checkboxInput.checked = Boolean(params.inputValue); | |
| 2456 | - var label = checkbox.getElementsByTagName('span'); | |
| 2457 | - if (label.length) { | |
| 2458 | - checkbox.removeChild(label[0]); | |
| 2459 | - } | |
| 2460 | - label = document.createElement('span'); | |
| 2461 | - label.innerHTML = params.inputPlaceholder; | |
| 2462 | - checkbox.appendChild(label); | |
| 2463 | - show(checkbox); | |
| 2464 | - break; | |
| 2465 | - case 'textarea': | |
| 2466 | - var textarea = getChildByClass(modal, swalClasses.textarea); | |
| 2467 | - textarea.value = params.inputValue; | |
| 2468 | - textarea.placeholder = params.inputPlaceholder; | |
| 2469 | - show(textarea); | |
| 2470 | - break; | |
| 2471 | - case null: | |
| 2472 | - break; | |
| 2473 | - default: | |
| 2474 | - console.error('SweetAlert2: Unexpected type of input! Expected "text", "email", "password", "number", "tel", "select", "radio", "checkbox", "textarea", "file" or "url", got "' + params.input + '"'); | |
| 2475 | - break; | |
| 2476 | - } | |
| 2477 | - | |
| 2478 | - if (params.input === 'select' || params.input === 'radio') { | |
| 2479 | - if (params.inputOptions instanceof Promise) { | |
| 2480 | - sweetAlert.showLoading(); | |
| 2481 | - params.inputOptions.then(function (inputOptions) { | |
| 2482 | - sweetAlert.hideLoading(); | |
| 2483 | - populateInputOptions(inputOptions); | |
| 2484 | - }); | |
| 2485 | - } else if (_typeof(params.inputOptions) === 'object') { | |
| 2486 | - populateInputOptions(params.inputOptions); | |
| 2487 | - } else { | |
| 2488 | - console.error('SweetAlert2: Unexpected type of inputOptions! Expected object or Promise, got ' + _typeof(params.inputOptions)); | |
| 2489 | - } | |
| 2490 | - } | |
| 2491 | - | |
| 2492 | - openModal(params.animation, params.onOpen); | |
| 2493 | - | |
| 2494 | - // Focus the first element (input or button) | |
| 2495 | - if (params.allowEnterKey) { | |
| 2496 | - setFocus(-1, 1); | |
| 2497 | - } else { | |
| 2498 | - if (document.activeElement) { | |
| 2499 | - document.activeElement.blur(); | |
| 2500 | - } | |
| 2501 | - } | |
| 2502 | - | |
| 2503 | - // fix scroll | |
| 2504 | - getContainer().scrollTop = 0; | |
| 2505 | - | |
| 2506 | - // Observe changes inside the modal and adjust height | |
| 2507 | - if (typeof MutationObserver !== 'undefined' && !swal2Observer) { | |
| 2508 | - swal2Observer = new MutationObserver(sweetAlert.recalculateHeight); | |
| 2509 | - swal2Observer.observe(modal, { childList: true, characterData: true, subtree: true }); | |
| 2510 | - } | |
| 2511 | - }); | |
| 2512 | -}; | |
| 2513 | - | |
| 2514 | -/* | |
| 2515 | - * Global function to determine if swal2 modal is shown | |
| 2516 | - */ | |
| 2517 | -sweetAlert.isVisible = function () { | |
| 2518 | - return !!getModal(); | |
| 2519 | -}; | |
| 2520 | - | |
| 2521 | -/* | |
| 2522 | - * Global function for chaining sweetAlert modals | |
| 2523 | - */ | |
| 2524 | -sweetAlert.queue = function (steps) { | |
| 2525 | - queue = steps; | |
| 2526 | - var resetQueue = function resetQueue() { | |
| 2527 | - queue = []; | |
| 2528 | - document.body.removeAttribute('data-swal2-queue-step'); | |
| 2529 | - }; | |
| 2530 | - var queueResult = []; | |
| 2531 | - return new Promise(function (resolve, reject) { | |
| 2532 | - (function step(i, callback) { | |
| 2533 | - if (i < queue.length) { | |
| 2534 | - document.body.setAttribute('data-swal2-queue-step', i); | |
| 2535 | - | |
| 2536 | - sweetAlert(queue[i]).then(function (result) { | |
| 2537 | - queueResult.push(result); | |
| 2538 | - step(i + 1, callback); | |
| 2539 | - }, function (dismiss) { | |
| 2540 | - resetQueue(); | |
| 2541 | - reject(dismiss); | |
| 2542 | - }); | |
| 2543 | - } else { | |
| 2544 | - resetQueue(); | |
| 2545 | - resolve(queueResult); | |
| 2546 | - } | |
| 2547 | - })(0); | |
| 2548 | - }); | |
| 2549 | -}; | |
| 2550 | - | |
| 2551 | -/* | |
| 2552 | - * Global function for getting the index of current modal in queue | |
| 2553 | - */ | |
| 2554 | -sweetAlert.getQueueStep = function () { | |
| 2555 | - return document.body.getAttribute('data-swal2-queue-step'); | |
| 2556 | -}; | |
| 2557 | - | |
| 2558 | -/* | |
| 2559 | - * Global function for inserting a modal to the queue | |
| 2560 | - */ | |
| 2561 | -sweetAlert.insertQueueStep = function (step, index) { | |
| 2562 | - if (index && index < queue.length) { | |
| 2563 | - return queue.splice(index, 0, step); | |
| 2564 | - } | |
| 2565 | - return queue.push(step); | |
| 2566 | -}; | |
| 2567 | - | |
| 2568 | -/* | |
| 2569 | - * Global function for deleting a modal from the queue | |
| 2570 | - */ | |
| 2571 | -sweetAlert.deleteQueueStep = function (index) { | |
| 2572 | - if (typeof queue[index] !== 'undefined') { | |
| 2573 | - queue.splice(index, 1); | |
| 2574 | - } | |
| 2575 | -}; | |
| 2576 | - | |
| 2577 | -/* | |
| 2578 | - * Global function to close sweetAlert | |
| 2579 | - */ | |
| 2580 | -sweetAlert.close = sweetAlert.closeModal = function (onComplete) { | |
| 2581 | - var container = getContainer(); | |
| 2582 | - var modal = getModal(); | |
| 2583 | - if (!modal) { | |
| 2584 | - return; | |
| 2585 | - } | |
| 2586 | - removeClass(modal, swalClasses.show); | |
| 2587 | - addClass(modal, swalClasses.hide); | |
| 2588 | - clearTimeout(modal.timeout); | |
| 2589 | - | |
| 2590 | - resetPrevState(); | |
| 2591 | - | |
| 2592 | - var removeModalAndResetState = function removeModalAndResetState() { | |
| 2593 | - if (container.parentNode) { | |
| 2594 | - container.parentNode.removeChild(container); | |
| 2595 | - } | |
| 2596 | - removeClass(document.documentElement, swalClasses.shown); | |
| 2597 | - removeClass(document.body, swalClasses.shown); | |
| 2598 | - undoScrollbar(); | |
| 2599 | - undoIOSfix(); | |
| 2600 | - }; | |
| 2601 | - | |
| 2602 | - // If animation is supported, animate | |
| 2603 | - if (animationEndEvent && !hasClass(modal, swalClasses.noanimation)) { | |
| 2604 | - modal.addEventListener(animationEndEvent, function swalCloseEventFinished() { | |
| 2605 | - modal.removeEventListener(animationEndEvent, swalCloseEventFinished); | |
| 2606 | - if (hasClass(modal, swalClasses.hide)) { | |
| 2607 | - removeModalAndResetState(); | |
| 2608 | - } | |
| 2609 | - }); | |
| 2610 | - } else { | |
| 2611 | - // Otherwise, remove immediately | |
| 2612 | - removeModalAndResetState(); | |
| 2613 | - } | |
| 2614 | - if (onComplete !== null && typeof onComplete === 'function') { | |
| 2615 | - setTimeout(function () { | |
| 2616 | - onComplete(modal); | |
| 2617 | - }); | |
| 2618 | - } | |
| 2619 | -}; | |
| 2620 | - | |
| 2621 | -/* | |
| 2622 | - * Global function to click 'Confirm' button | |
| 2623 | - */ | |
| 2624 | -sweetAlert.clickConfirm = function () { | |
| 2625 | - return getConfirmButton().click(); | |
| 2626 | -}; | |
| 2627 | - | |
| 2628 | -/* | |
| 2629 | - * Global function to click 'Cancel' button | |
| 2630 | - */ | |
| 2631 | -sweetAlert.clickCancel = function () { | |
| 2632 | - return getCancelButton().click(); | |
| 2633 | -}; | |
| 2634 | - | |
| 2635 | -/** | |
| 2636 | - * Show spinner instead of Confirm button and disable Cancel button | |
| 2637 | - */ | |
| 2638 | -sweetAlert.showLoading = sweetAlert.enableLoading = function () { | |
| 2639 | - var modal = getModal(); | |
| 2640 | - if (!modal) { | |
| 2641 | - sweetAlert(''); | |
| 2642 | - } | |
| 2643 | - var buttonsWrapper = getButtonsWrapper(); | |
| 2644 | - var confirmButton = getConfirmButton(); | |
| 2645 | - var cancelButton = getCancelButton(); | |
| 2646 | - | |
| 2647 | - show(buttonsWrapper); | |
| 2648 | - show(confirmButton, 'inline-block'); | |
| 2649 | - addClass(buttonsWrapper, swalClasses.loading); | |
| 2650 | - addClass(modal, swalClasses.loading); | |
| 2651 | - confirmButton.disabled = true; | |
| 2652 | - cancelButton.disabled = true; | |
| 2653 | -}; | |
| 2654 | - | |
| 2655 | -/** | |
| 2656 | - * Set default params for each popup | |
| 2657 | - * @param {Object} userParams | |
| 2658 | - */ | |
| 2659 | -sweetAlert.setDefaults = function (userParams) { | |
| 2660 | - if (!userParams || (typeof userParams === 'undefined' ? 'undefined' : _typeof(userParams)) !== 'object') { | |
| 2661 | - return console.error('SweetAlert2: the argument for setDefaults() is required and has to be a object'); | |
| 2662 | - } | |
| 2663 | - | |
| 2664 | - for (var param in userParams) { | |
| 2665 | - if (!defaultParams.hasOwnProperty(param) && param !== 'extraParams') { | |
| 2666 | - console.warn('SweetAlert2: Unknown parameter "' + param + '"'); | |
| 2667 | - delete userParams[param]; | |
| 2668 | - } | |
| 2669 | - } | |
| 2670 | - | |
| 2671 | - _extends(modalParams, userParams); | |
| 2672 | -}; | |
| 2673 | - | |
| 2674 | -/** | |
| 2675 | - * Reset default params for each popup | |
| 2676 | - */ | |
| 2677 | -sweetAlert.resetDefaults = function () { | |
| 2678 | - modalParams = _extends({}, defaultParams); | |
| 2679 | -}; | |
| 2680 | - | |
| 2681 | -sweetAlert.noop = function () {}; | |
| 2682 | - | |
| 2683 | -sweetAlert.version = '6.6.4'; | |
| 2684 | - | |
| 2685 | -sweetAlert.default = sweetAlert; | |
| 2686 | - | |
| 2687 | -return sweetAlert; | |
| 2688 | - | |
| 2689 | -}))); | |
| 2690 | -if (window.Sweetalert2) window.sweetAlert = window.swal = window.Sweetalert2; | |
| 1050 | +/*! | |
| 1051 | + * sweetalert2 v6.6.4 | |
| 1052 | + * Released under the MIT License. | |
| 1053 | + */ | |
| 1054 | +(function (global, factory) { | |
| 1055 | + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | |
| 1056 | + typeof define === 'function' && define.amd ? define(factory) : | |
| 1057 | + (global.Sweetalert2 = factory()); | |
| 1058 | +}(this, (function () { 'use strict'; | |
| 2691 | 1059 | |
| 1060 | +var defaultParams = { | |
| 1061 | + title: '', | |
| 1062 | + titleText: '', | |
| 1063 | + text: '', | |
| 1064 | + html: '', | |
| 1065 | + type: null, | |
| 1066 | + customClass: '', | |
| 1067 | + target: 'body', | |
| 1068 | + animation: true, | |
| 1069 | + allowOutsideClick: true, | |
| 1070 | + allowEscapeKey: true, | |
| 1071 | + allowEnterKey: true, | |
| 1072 | + showConfirmButton: true, | |
| 1073 | + showCancelButton: false, | |
| 1074 | + preConfirm: null, | |
| 1075 | + confirmButtonText: 'OK', | |
| 1076 | + confirmButtonColor: '#3085d6', | |
| 1077 | + confirmButtonClass: null, | |
| 1078 | + cancelButtonText: 'Cancel', | |
| 1079 | + cancelButtonColor: '#aaa', | |
| 1080 | + cancelButtonClass: null, | |
| 1081 | + buttonsStyling: true, | |
| 1082 | + reverseButtons: false, | |
| 1083 | + focusCancel: false, | |
| 1084 | + showCloseButton: false, | |
| 1085 | + showLoaderOnConfirm: false, | |
| 1086 | + imageUrl: null, | |
| 1087 | + imageWidth: null, | |
| 1088 | + imageHeight: null, | |
| 1089 | + imageClass: null, | |
| 1090 | + timer: null, | |
| 1091 | + width: 500, | |
| 1092 | + padding: 20, | |
| 1093 | + background: '#fff', | |
| 1094 | + input: null, | |
| 1095 | + inputPlaceholder: '', | |
| 1096 | + inputValue: '', | |
| 1097 | + inputOptions: {}, | |
| 1098 | + inputAutoTrim: true, | |
| 1099 | + inputClass: null, | |
| 1100 | + inputAttributes: {}, | |
| 1101 | + inputValidator: null, | |
| 1102 | + progressSteps: [], | |
| 1103 | + currentProgressStep: null, | |
| 1104 | + progressStepsDistance: '40px', | |
| 1105 | + onOpen: null, | |
| 1106 | + onClose: null, | |
| 1107 | + useRejections: true | |
| 1108 | +}; | |
| 1109 | + | |
| 1110 | +var swalPrefix = 'swal2-'; | |
| 1111 | + | |
| 1112 | +var prefix = function prefix(items) { | |
| 1113 | + var result = {}; | |
| 1114 | + for (var i in items) { | |
| 1115 | + result[items[i]] = swalPrefix + items[i]; | |
| 1116 | + } | |
| 1117 | + return result; | |
| 1118 | +}; | |
| 1119 | + | |
| 1120 | +var swalClasses = prefix(['container', 'shown', 'iosfix', 'modal', 'overlay', 'fade', 'show', 'hide', 'noanimation', 'close', 'title', 'content', 'buttonswrapper', 'confirm', 'cancel', 'icon', 'image', 'input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea', 'inputerror', 'validationerror', 'progresssteps', 'activeprogressstep', 'progresscircle', 'progressline', 'loading', 'styled']); | |
| 1121 | + | |
| 1122 | +var iconTypes = prefix(['success', 'warning', 'info', 'question', 'error']); | |
| 1123 | + | |
| 1124 | +/* | |
| 1125 | + * Set hover, active and focus-states for buttons (source: http://www.sitepoint.com/javascript-generate-lighter-darker-color) | |
| 1126 | + */ | |
| 1127 | +var colorLuminance = function colorLuminance(hex, lum) { | |
| 1128 | + // Validate hex string | |
| 1129 | + hex = String(hex).replace(/[^0-9a-f]/gi, ''); | |
| 1130 | + if (hex.length < 6) { | |
| 1131 | + hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; | |
| 1132 | + } | |
| 1133 | + lum = lum || 0; | |
| 1134 | + | |
| 1135 | + // Convert to decimal and change luminosity | |
| 1136 | + var rgb = '#'; | |
| 1137 | + for (var i = 0; i < 3; i++) { | |
| 1138 | + var c = parseInt(hex.substr(i * 2, 2), 16); | |
| 1139 | + c = Math.round(Math.min(Math.max(0, c + c * lum), 255)).toString(16); | |
| 1140 | + rgb += ('00' + c).substr(c.length); | |
| 1141 | + } | |
| 1142 | + | |
| 1143 | + return rgb; | |
| 1144 | +}; | |
| 1145 | + | |
| 1146 | +var uniqueArray = function uniqueArray(arr) { | |
| 1147 | + var result = []; | |
| 1148 | + for (var i in arr) { | |
| 1149 | + if (result.indexOf(arr[i]) === -1) { | |
| 1150 | + result.push(arr[i]); | |
| 1151 | + } | |
| 1152 | + } | |
| 1153 | + return result; | |
| 1154 | +}; | |
| 1155 | + | |
| 1156 | +/* global MouseEvent */ | |
| 1157 | + | |
| 1158 | +// Remember state in cases where opening and handling a modal will fiddle with it. | |
| 1159 | +var states = { | |
| 1160 | + previousWindowKeyDown: null, | |
| 1161 | + previousActiveElement: null, | |
| 1162 | + previousBodyPadding: null | |
| 1163 | +}; | |
| 1164 | + | |
| 1165 | +/* | |
| 1166 | + * Add modal + overlay to DOM | |
| 1167 | + */ | |
| 1168 | +var init = function init(params) { | |
| 1169 | + if (typeof document === 'undefined') { | |
| 1170 | + console.error('SweetAlert2 requires document to initialize'); | |
| 1171 | + return; | |
| 1172 | + } | |
| 1173 | + | |
| 1174 | + var container = document.createElement('div'); | |
| 1175 | + container.className = swalClasses.container; | |
| 1176 | + container.innerHTML = sweetHTML; | |
| 1177 | + | |
| 1178 | + var targetElement = document.querySelector(params.target); | |
| 1179 | + if (!targetElement) { | |
| 1180 | + console.warn('SweetAlert2: Can\'t find the target "' + params.target + '"'); | |
| 1181 | + targetElement = document.body; | |
| 1182 | + } | |
| 1183 | + targetElement.appendChild(container); | |
| 1184 | + | |
| 1185 | + var modal = getModal(); | |
| 1186 | + var input = getChildByClass(modal, swalClasses.input); | |
| 1187 | + var file = getChildByClass(modal, swalClasses.file); | |
| 1188 | + var range = modal.querySelector('.' + swalClasses.range + ' input'); | |
| 1189 | + var rangeOutput = modal.querySelector('.' + swalClasses.range + ' output'); | |
| 1190 | + var select = getChildByClass(modal, swalClasses.select); | |
| 1191 | + var checkbox = modal.querySelector('.' + swalClasses.checkbox + ' input'); | |
| 1192 | + var textarea = getChildByClass(modal, swalClasses.textarea); | |
| 1193 | + | |
| 1194 | + input.oninput = function () { | |
| 1195 | + sweetAlert.resetValidationError(); | |
| 1196 | + }; | |
| 1197 | + | |
| 1198 | + input.onkeydown = function (event) { | |
| 1199 | + setTimeout(function () { | |
| 1200 | + if (event.keyCode === 13 && params.allowEnterKey) { | |
| 1201 | + event.stopPropagation(); | |
| 1202 | + sweetAlert.clickConfirm(); | |
| 1203 | + } | |
| 1204 | + }, 0); | |
| 1205 | + }; | |
| 1206 | + | |
| 1207 | + file.onchange = function () { | |
| 1208 | + sweetAlert.resetValidationError(); | |
| 1209 | + }; | |
| 1210 | + | |
| 1211 | + range.oninput = function () { | |
| 1212 | + sweetAlert.resetValidationError(); | |
| 1213 | + rangeOutput.value = range.value; | |
| 1214 | + }; | |
| 1215 | + | |
| 1216 | + range.onchange = function () { | |
| 1217 | + sweetAlert.resetValidationError(); | |
| 1218 | + range.previousSibling.value = range.value; | |
| 1219 | + }; | |
| 1220 | + | |
| 1221 | + select.onchange = function () { | |
| 1222 | + sweetAlert.resetValidationError(); | |
| 1223 | + }; | |
| 1224 | + | |
| 1225 | + checkbox.onchange = function () { | |
| 1226 | + sweetAlert.resetValidationError(); | |
| 1227 | + }; | |
| 1228 | + | |
| 1229 | + textarea.oninput = function () { | |
| 1230 | + sweetAlert.resetValidationError(); | |
| 1231 | + }; | |
| 1232 | + | |
| 1233 | + return modal; | |
| 1234 | +}; | |
| 1235 | + | |
| 1236 | +/* | |
| 1237 | + * Manipulate DOM | |
| 1238 | + */ | |
| 1239 | + | |
| 1240 | +var sweetHTML = ('\n <div role="dialog" aria-labelledby="' + swalClasses.title + '" aria-describedby="' + swalClasses.content + '" class="' + swalClasses.modal + '" tabindex="-1">\n <ul class="' + swalClasses.progresssteps + '"></ul>\n <div class="' + swalClasses.icon + ' ' + iconTypes.error + '">\n <span class="swal2-x-mark"><span class="swal2-x-mark-line-left"></span><span class="swal2-x-mark-line-right"></span></span>\n </div>\n <div class="' + swalClasses.icon + ' ' + iconTypes.question + '">?</div>\n <div class="' + swalClasses.icon + ' ' + iconTypes.warning + '">!</div>\n <div class="' + swalClasses.icon + ' ' + iconTypes.info + '">i</div>\n <div class="' + swalClasses.icon + ' ' + iconTypes.success + '">\n <div class="swal2-success-circular-line-left"></div>\n <span class="swal2-success-line-tip"></span> <span class="swal2-success-line-long"></span>\n <div class="swal2-success-ring"></div> <div class="swal2-success-fix"></div>\n <div class="swal2-success-circular-line-right"></div>\n </div>\n <img class="' + swalClasses.image + '">\n <h2 class="' + swalClasses.title + '" id="' + swalClasses.title + '"></h2>\n <div id="' + swalClasses.content + '" class="' + swalClasses.content + '"></div>\n <input class="' + swalClasses.input + '">\n <input type="file" class="' + swalClasses.file + '">\n <div class="' + swalClasses.range + '">\n <output></output>\n <input type="range">\n </div>\n <select class="' + swalClasses.select + '"></select>\n <div class="' + swalClasses.radio + '"></div>\n <label for="' + swalClasses.checkbox + '" class="' + swalClasses.checkbox + '">\n <input type="checkbox">\n </label>\n <textarea class="' + swalClasses.textarea + '"></textarea>\n <div class="' + swalClasses.validationerror + '"></div>\n <div class="' + swalClasses.buttonswrapper + '">\n <button type="button" class="' + swalClasses.confirm + '">OK</button>\n <button type="button" class="' + swalClasses.cancel + '">Cancel</button>\n </div>\n <button type="button" class="' + swalClasses.close + '" aria-label="Close this dialog">×</button>\n </div>\n').replace(/(^|\n)\s*/g, ''); | |
| 1241 | + | |
| 1242 | +var getContainer = function getContainer() { | |
| 1243 | + return document.body.querySelector('.' + swalClasses.container); | |
| 1244 | +}; | |
| 1245 | + | |
| 1246 | +var getModal = function getModal() { | |
| 1247 | + return getContainer() ? getContainer().querySelector('.' + swalClasses.modal) : null; | |
| 1248 | +}; | |
| 1249 | + | |
| 1250 | +var getIcons = function getIcons() { | |
| 1251 | + var modal = getModal(); | |
| 1252 | + return modal.querySelectorAll('.' + swalClasses.icon); | |
| 1253 | +}; | |
| 1254 | + | |
| 1255 | +var elementByClass = function elementByClass(className) { | |
| 1256 | + return getContainer() ? getContainer().querySelector('.' + className) : null; | |
| 1257 | +}; | |
| 1258 | + | |
| 1259 | +var getTitle = function getTitle() { | |
| 1260 | + return elementByClass(swalClasses.title); | |
| 1261 | +}; | |
| 1262 | + | |
| 1263 | +var getContent = function getContent() { | |
| 1264 | + return elementByClass(swalClasses.content); | |
| 1265 | +}; | |
| 1266 | + | |
| 1267 | +var getImage = function getImage() { | |
| 1268 | + return elementByClass(swalClasses.image); | |
| 1269 | +}; | |
| 1270 | + | |
| 1271 | +var getButtonsWrapper = function getButtonsWrapper() { | |
| 1272 | + return elementByClass(swalClasses.buttonswrapper); | |
| 1273 | +}; | |
| 1274 | + | |
| 1275 | +var getProgressSteps = function getProgressSteps() { | |
| 1276 | + return elementByClass(swalClasses.progresssteps); | |
| 1277 | +}; | |
| 1278 | + | |
| 1279 | +var getValidationError = function getValidationError() { | |
| 1280 | + return elementByClass(swalClasses.validationerror); | |
| 1281 | +}; | |
| 1282 | + | |
| 1283 | +var getConfirmButton = function getConfirmButton() { | |
| 1284 | + return elementByClass(swalClasses.confirm); | |
| 1285 | +}; | |
| 1286 | + | |
| 1287 | +var getCancelButton = function getCancelButton() { | |
| 1288 | + return elementByClass(swalClasses.cancel); | |
| 1289 | +}; | |
| 1290 | + | |
| 1291 | +var getCloseButton = function getCloseButton() { | |
| 1292 | + return elementByClass(swalClasses.close); | |
| 1293 | +}; | |
| 1294 | + | |
| 1295 | +var getFocusableElements = function getFocusableElements(focusCancel) { | |
| 1296 | + var buttons = [getConfirmButton(), getCancelButton()]; | |
| 1297 | + if (focusCancel) { | |
| 1298 | + buttons.reverse(); | |
| 1299 | + } | |
| 1300 | + var focusableElements = buttons.concat(Array.prototype.slice.call(getModal().querySelectorAll('button, input:not([type=hidden]), textarea, select, a, *[tabindex]:not([tabindex="-1"])'))); | |
| 1301 | + return uniqueArray(focusableElements); | |
| 1302 | +}; | |
| 1303 | + | |
| 1304 | +var hasClass = function hasClass(elem, className) { | |
| 1305 | + if (elem.classList) { | |
| 1306 | + return elem.classList.contains(className); | |
| 1307 | + } | |
| 1308 | + return false; | |
| 1309 | +}; | |
| 1310 | + | |
| 1311 | +var focusInput = function focusInput(input) { | |
| 1312 | + input.focus(); | |
| 1313 | + | |
| 1314 | + // place cursor at end of text in text input | |
| 1315 | + if (input.type !== 'file') { | |
| 1316 | + // http://stackoverflow.com/a/2345915/1331425 | |
| 1317 | + var val = input.value; | |
| 1318 | + input.value = ''; | |
| 1319 | + input.value = val; | |
| 1320 | + } | |
| 1321 | +}; | |
| 1322 | + | |
| 1323 | +var addClass = function addClass(elem, className) { | |
| 1324 | + if (!elem || !className) { | |
| 1325 | + return; | |
| 1326 | + } | |
| 1327 | + var classes = className.split(/\s+/).filter(Boolean); | |
| 1328 | + classes.forEach(function (className) { | |
| 1329 | + elem.classList.add(className); | |
| 1330 | + }); | |
| 1331 | +}; | |
| 1332 | + | |
| 1333 | +var removeClass = function removeClass(elem, className) { | |
| 1334 | + if (!elem || !className) { | |
| 1335 | + return; | |
| 1336 | + } | |
| 1337 | + var classes = className.split(/\s+/).filter(Boolean); | |
| 1338 | + classes.forEach(function (className) { | |
| 1339 | + elem.classList.remove(className); | |
| 1340 | + }); | |
| 1341 | +}; | |
| 1342 | + | |
| 1343 | +var getChildByClass = function getChildByClass(elem, className) { | |
| 1344 | + for (var i = 0; i < elem.childNodes.length; i++) { | |
| 1345 | + if (hasClass(elem.childNodes[i], className)) { | |
| 1346 | + return elem.childNodes[i]; | |
| 1347 | + } | |
| 1348 | + } | |
| 1349 | +}; | |
| 1350 | + | |
| 1351 | +var show = function show(elem, display) { | |
| 1352 | + if (!display) { | |
| 1353 | + display = 'block'; | |
| 1354 | + } | |
| 1355 | + elem.style.opacity = ''; | |
| 1356 | + elem.style.display = display; | |
| 1357 | +}; | |
| 1358 | + | |
| 1359 | +var hide = function hide(elem) { | |
| 1360 | + elem.style.opacity = ''; | |
| 1361 | + elem.style.display = 'none'; | |
| 1362 | +}; | |
| 1363 | + | |
| 1364 | +var empty = function empty(elem) { | |
| 1365 | + while (elem.firstChild) { | |
| 1366 | + elem.removeChild(elem.firstChild); | |
| 1367 | + } | |
| 1368 | +}; | |
| 1369 | + | |
| 1370 | +// borrowed from jqeury $(elem).is(':visible') implementation | |
| 1371 | +var isVisible = function isVisible(elem) { | |
| 1372 | + return elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length; | |
| 1373 | +}; | |
| 1374 | + | |
| 1375 | +var removeStyleProperty = function removeStyleProperty(elem, property) { | |
| 1376 | + if (elem.style.removeProperty) { | |
| 1377 | + elem.style.removeProperty(property); | |
| 1378 | + } else { | |
| 1379 | + elem.style.removeAttribute(property); | |
| 1380 | + } | |
| 1381 | +}; | |
| 1382 | + | |
| 1383 | +var fireClick = function fireClick(node) { | |
| 1384 | + if (!isVisible(node)) { | |
| 1385 | + return false; | |
| 1386 | + } | |
| 1387 | + | |
| 1388 | + // Taken from http://www.nonobtrusive.com/2011/11/29/programatically-fire-crossbrowser-click-event-with-javascript/ | |
| 1389 | + // Then fixed for today's Chrome browser. | |
| 1390 | + if (typeof MouseEvent === 'function') { | |
| 1391 | + // Up-to-date approach | |
| 1392 | + var mevt = new MouseEvent('click', { | |
| 1393 | + view: window, | |
| 1394 | + bubbles: false, | |
| 1395 | + cancelable: true | |
| 1396 | + }); | |
| 1397 | + node.dispatchEvent(mevt); | |
| 1398 | + } else if (document.createEvent) { | |
| 1399 | + // Fallback | |
| 1400 | + var evt = document.createEvent('MouseEvents'); | |
| 1401 | + evt.initEvent('click', false, false); | |
| 1402 | + node.dispatchEvent(evt); | |
| 1403 | + } else if (document.createEventObject) { | |
| 1404 | + node.fireEvent('onclick'); | |
| 1405 | + } else if (typeof node.onclick === 'function') { | |
| 1406 | + node.onclick(); | |
| 1407 | + } | |
| 1408 | +}; | |
| 1409 | + | |
| 1410 | +var animationEndEvent = function () { | |
| 1411 | + var testEl = document.createElement('div'); | |
| 1412 | + var transEndEventNames = { | |
| 1413 | + 'WebkitAnimation': 'webkitAnimationEnd', | |
| 1414 | + 'OAnimation': 'oAnimationEnd oanimationend', | |
| 1415 | + 'msAnimation': 'MSAnimationEnd', | |
| 1416 | + 'animation': 'animationend' | |
| 1417 | + }; | |
| 1418 | + for (var i in transEndEventNames) { | |
| 1419 | + if (transEndEventNames.hasOwnProperty(i) && testEl.style[i] !== undefined) { | |
| 1420 | + return transEndEventNames[i]; | |
| 1421 | + } | |
| 1422 | + } | |
| 1423 | + | |
| 1424 | + return false; | |
| 1425 | +}(); | |
| 1426 | + | |
| 1427 | +// Reset previous window keydown handler and focued element | |
| 1428 | +var resetPrevState = function resetPrevState() { | |
| 1429 | + window.onkeydown = states.previousWindowKeyDown; | |
| 1430 | + if (states.previousActiveElement && states.previousActiveElement.focus) { | |
| 1431 | + var x = window.scrollX; | |
| 1432 | + var y = window.scrollY; | |
| 1433 | + states.previousActiveElement.focus(); | |
| 1434 | + if (x && y) { | |
| 1435 | + // IE has no scrollX/scrollY support | |
| 1436 | + window.scrollTo(x, y); | |
| 1437 | + } | |
| 1438 | + } | |
| 1439 | +}; | |
| 1440 | + | |
| 1441 | +// Measure width of scrollbar | |
| 1442 | +// https://github.com/twbs/bootstrap/blob/master/js/modal.js#L279-L286 | |
| 1443 | +var measureScrollbar = function measureScrollbar() { | |
| 1444 | + var supportsTouch = 'ontouchstart' in window || navigator.msMaxTouchPoints; | |
| 1445 | + if (supportsTouch) { | |
| 1446 | + return 0; | |
| 1447 | + } | |
| 1448 | + var scrollDiv = document.createElement('div'); | |
| 1449 | + scrollDiv.style.width = '50px'; | |
| 1450 | + scrollDiv.style.height = '50px'; | |
| 1451 | + scrollDiv.style.overflow = 'scroll'; | |
| 1452 | + document.body.appendChild(scrollDiv); | |
| 1453 | + var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; | |
| 1454 | + document.body.removeChild(scrollDiv); | |
| 1455 | + return scrollbarWidth; | |
| 1456 | +}; | |
| 1457 | + | |
| 1458 | +// JavaScript Debounce Function | |
| 1459 | +// Simplivied version of https://davidwalsh.name/javascript-debounce-function | |
| 1460 | +var debounce = function debounce(func, wait) { | |
| 1461 | + var timeout = void 0; | |
| 1462 | + return function () { | |
| 1463 | + var later = function later() { | |
| 1464 | + timeout = null; | |
| 1465 | + func(); | |
| 1466 | + }; | |
| 1467 | + clearTimeout(timeout); | |
| 1468 | + timeout = setTimeout(later, wait); | |
| 1469 | + }; | |
| 1470 | +}; | |
| 1471 | + | |
| 1472 | +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | |
| 1473 | + return typeof obj; | |
| 1474 | +} : function (obj) { | |
| 1475 | + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | |
| 1476 | +}; | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | +var _extends = Object.assign || function (target) { | |
| 1499 | + for (var i = 1; i < arguments.length; i++) { | |
| 1500 | + var source = arguments[i]; | |
| 1501 | + | |
| 1502 | + for (var key in source) { | |
| 1503 | + if (Object.prototype.hasOwnProperty.call(source, key)) { | |
| 1504 | + target[key] = source[key]; | |
| 1505 | + } | |
| 1506 | + } | |
| 1507 | + } | |
| 1508 | + | |
| 1509 | + return target; | |
| 1510 | +}; | |
| 1511 | + | |
| 1512 | +var modalParams = _extends({}, defaultParams); | |
| 1513 | +var queue = []; | |
| 1514 | +var swal2Observer = void 0; | |
| 1515 | + | |
| 1516 | +/* | |
| 1517 | + * Set type, text and actions on modal | |
| 1518 | + */ | |
| 1519 | +var setParameters = function setParameters(params) { | |
| 1520 | + var modal = getModal() || init(params); | |
| 1521 | + | |
| 1522 | + for (var param in params) { | |
| 1523 | + if (!defaultParams.hasOwnProperty(param) && param !== 'extraParams') { | |
| 1524 | + console.warn('SweetAlert2: Unknown parameter "' + param + '"'); | |
| 1525 | + } | |
| 1526 | + } | |
| 1527 | + | |
| 1528 | + // Set modal width | |
| 1529 | + modal.style.width = typeof params.width === 'number' ? params.width + 'px' : params.width; | |
| 1530 | + | |
| 1531 | + modal.style.padding = params.padding + 'px'; | |
| 1532 | + modal.style.background = params.background; | |
| 1533 | + var successIconParts = modal.querySelectorAll('[class^=swal2-success-circular-line], .swal2-success-fix'); | |
| 1534 | + for (var i = 0; i < successIconParts.length; i++) { | |
| 1535 | + successIconParts[i].style.background = params.background; | |
| 1536 | + } | |
| 1537 | + | |
| 1538 | + var title = getTitle(); | |
| 1539 | + var content = getContent(); | |
| 1540 | + var buttonsWrapper = getButtonsWrapper(); | |
| 1541 | + var confirmButton = getConfirmButton(); | |
| 1542 | + var cancelButton = getCancelButton(); | |
| 1543 | + var closeButton = getCloseButton(); | |
| 1544 | + | |
| 1545 | + // Title | |
| 1546 | + if (params.titleText) { | |
| 1547 | + title.innerText = params.titleText; | |
| 1548 | + } else { | |
| 1549 | + title.innerHTML = params.title.split('\n').join('<br>'); | |
| 1550 | + } | |
| 1551 | + | |
| 1552 | + // Content | |
| 1553 | + if (params.text || params.html) { | |
| 1554 | + if (_typeof(params.html) === 'object') { | |
| 1555 | + content.innerHTML = ''; | |
| 1556 | + if (0 in params.html) { | |
| 1557 | + for (var _i = 0; _i in params.html; _i++) { | |
| 1558 | + content.appendChild(params.html[_i].cloneNode(true)); | |
| 1559 | + } | |
| 1560 | + } else { | |
| 1561 | + content.appendChild(params.html.cloneNode(true)); | |
| 1562 | + } | |
| 1563 | + } else if (params.html) { | |
| 1564 | + content.innerHTML = params.html; | |
| 1565 | + } else if (params.text) { | |
| 1566 | + content.textContent = params.text; | |
| 1567 | + } | |
| 1568 | + show(content); | |
| 1569 | + } else { | |
| 1570 | + hide(content); | |
| 1571 | + } | |
| 1572 | + | |
| 1573 | + // Close button | |
| 1574 | + if (params.showCloseButton) { | |
| 1575 | + show(closeButton); | |
| 1576 | + } else { | |
| 1577 | + hide(closeButton); | |
| 1578 | + } | |
| 1579 | + | |
| 1580 | + // Custom Class | |
| 1581 | + modal.className = swalClasses.modal; | |
| 1582 | + if (params.customClass) { | |
| 1583 | + addClass(modal, params.customClass); | |
| 1584 | + } | |
| 1585 | + | |
| 1586 | + // Progress steps | |
| 1587 | + var progressStepsContainer = getProgressSteps(); | |
| 1588 | + var currentProgressStep = parseInt(params.currentProgressStep === null ? sweetAlert.getQueueStep() : params.currentProgressStep, 10); | |
| 1589 | + if (params.progressSteps.length) { | |
| 1590 | + show(progressStepsContainer); | |
| 1591 | + empty(progressStepsContainer); | |
| 1592 | + if (currentProgressStep >= params.progressSteps.length) { | |
| 1593 | + console.warn('SweetAlert2: Invalid currentProgressStep parameter, it should be less than progressSteps.length ' + '(currentProgressStep like JS arrays starts from 0)'); | |
| 1594 | + } | |
| 1595 | + params.progressSteps.forEach(function (step, index) { | |
| 1596 | + var circle = document.createElement('li'); | |
| 1597 | + addClass(circle, swalClasses.progresscircle); | |
| 1598 | + circle.innerHTML = step; | |
| 1599 | + if (index === currentProgressStep) { | |
| 1600 | + addClass(circle, swalClasses.activeprogressstep); | |
| 1601 | + } | |
| 1602 | + progressStepsContainer.appendChild(circle); | |
| 1603 | + if (index !== params.progressSteps.length - 1) { | |
| 1604 | + var line = document.createElement('li'); | |
| 1605 | + addClass(line, swalClasses.progressline); | |
| 1606 | + line.style.width = params.progressStepsDistance; | |
| 1607 | + progressStepsContainer.appendChild(line); | |
| 1608 | + } | |
| 1609 | + }); | |
| 1610 | + } else { | |
| 1611 | + hide(progressStepsContainer); | |
| 1612 | + } | |
| 1613 | + | |
| 1614 | + // Icon | |
| 1615 | + var icons = getIcons(); | |
| 1616 | + for (var _i2 = 0; _i2 < icons.length; _i2++) { | |
| 1617 | + hide(icons[_i2]); | |
| 1618 | + } | |
| 1619 | + if (params.type) { | |
| 1620 | + var validType = false; | |
| 1621 | + for (var iconType in iconTypes) { | |
| 1622 | + if (params.type === iconType) { | |
| 1623 | + validType = true; | |
| 1624 | + break; | |
| 1625 | + } | |
| 1626 | + } | |
| 1627 | + if (!validType) { | |
| 1628 | + console.error('SweetAlert2: Unknown alert type: ' + params.type); | |
| 1629 | + return false; | |
| 1630 | + } | |
| 1631 | + var icon = modal.querySelector('.' + swalClasses.icon + '.' + iconTypes[params.type]); | |
| 1632 | + show(icon); | |
| 1633 | + | |
| 1634 | + // Animate icon | |
| 1635 | + if (params.animation) { | |
| 1636 | + switch (params.type) { | |
| 1637 | + case 'success': | |
| 1638 | + addClass(icon, 'swal2-animate-success-icon'); | |
| 1639 | + addClass(icon.querySelector('.swal2-success-line-tip'), 'swal2-animate-success-line-tip'); | |
| 1640 | + addClass(icon.querySelector('.swal2-success-line-long'), 'swal2-animate-success-line-long'); | |
| 1641 | + break; | |
| 1642 | + case 'error': | |
| 1643 | + addClass(icon, 'swal2-animate-error-icon'); | |
| 1644 | + addClass(icon.querySelector('.swal2-x-mark'), 'swal2-animate-x-mark'); | |
| 1645 | + break; | |
| 1646 | + default: | |
| 1647 | + break; | |
| 1648 | + } | |
| 1649 | + } | |
| 1650 | + } | |
| 1651 | + | |
| 1652 | + // Custom image | |
| 1653 | + var image = getImage(); | |
| 1654 | + if (params.imageUrl) { | |
| 1655 | + image.setAttribute('src', params.imageUrl); | |
| 1656 | + show(image); | |
| 1657 | + | |
| 1658 | + if (params.imageWidth) { | |
| 1659 | + image.setAttribute('width', params.imageWidth); | |
| 1660 | + } else { | |
| 1661 | + image.removeAttribute('width'); | |
| 1662 | + } | |
| 1663 | + | |
| 1664 | + if (params.imageHeight) { | |
| 1665 | + image.setAttribute('height', params.imageHeight); | |
| 1666 | + } else { | |
| 1667 | + image.removeAttribute('height'); | |
| 1668 | + } | |
| 1669 | + | |
| 1670 | + image.className = swalClasses.image; | |
| 1671 | + if (params.imageClass) { | |
| 1672 | + addClass(image, params.imageClass); | |
| 1673 | + } | |
| 1674 | + } else { | |
| 1675 | + hide(image); | |
| 1676 | + } | |
| 1677 | + | |
| 1678 | + // Cancel button | |
| 1679 | + if (params.showCancelButton) { | |
| 1680 | + cancelButton.style.display = 'inline-block'; | |
| 1681 | + } else { | |
| 1682 | + hide(cancelButton); | |
| 1683 | + } | |
| 1684 | + | |
| 1685 | + // Confirm button | |
| 1686 | + if (params.showConfirmButton) { | |
| 1687 | + removeStyleProperty(confirmButton, 'display'); | |
| 1688 | + } else { | |
| 1689 | + hide(confirmButton); | |
| 1690 | + } | |
| 1691 | + | |
| 1692 | + // Buttons wrapper | |
| 1693 | + if (!params.showConfirmButton && !params.showCancelButton) { | |
| 1694 | + hide(buttonsWrapper); | |
| 1695 | + } else { | |
| 1696 | + show(buttonsWrapper); | |
| 1697 | + } | |
| 1698 | + | |
| 1699 | + // Edit text on cancel and confirm buttons | |
| 1700 | + confirmButton.innerHTML = params.confirmButtonText; | |
| 1701 | + cancelButton.innerHTML = params.cancelButtonText; | |
| 1702 | + | |
| 1703 | + // Set buttons to selected background colors | |
| 1704 | + if (params.buttonsStyling) { | |
| 1705 | + confirmButton.style.backgroundColor = params.confirmButtonColor; | |
| 1706 | + cancelButton.style.backgroundColor = params.cancelButtonColor; | |
| 1707 | + } | |
| 1708 | + | |
| 1709 | + // Add buttons custom classes | |
| 1710 | + confirmButton.className = swalClasses.confirm; | |
| 1711 | + addClass(confirmButton, params.confirmButtonClass); | |
| 1712 | + cancelButton.className = swalClasses.cancel; | |
| 1713 | + addClass(cancelButton, params.cancelButtonClass); | |
| 1714 | + | |
| 1715 | + // Buttons styling | |
| 1716 | + if (params.buttonsStyling) { | |
| 1717 | + addClass(confirmButton, swalClasses.styled); | |
| 1718 | + addClass(cancelButton, swalClasses.styled); | |
| 1719 | + } else { | |
| 1720 | + removeClass(confirmButton, swalClasses.styled); | |
| 1721 | + removeClass(cancelButton, swalClasses.styled); | |
| 1722 | + | |
| 1723 | + confirmButton.style.backgroundColor = confirmButton.style.borderLeftColor = confirmButton.style.borderRightColor = ''; | |
| 1724 | + cancelButton.style.backgroundColor = cancelButton.style.borderLeftColor = cancelButton.style.borderRightColor = ''; | |
| 1725 | + } | |
| 1726 | + | |
| 1727 | + // CSS animation | |
| 1728 | + if (params.animation === true) { | |
| 1729 | + removeClass(modal, swalClasses.noanimation); | |
| 1730 | + } else { | |
| 1731 | + addClass(modal, swalClasses.noanimation); | |
| 1732 | + } | |
| 1733 | +}; | |
| 1734 | + | |
| 1735 | +/* | |
| 1736 | + * Animations | |
| 1737 | + */ | |
| 1738 | +var openModal = function openModal(animation, onComplete) { | |
| 1739 | + var container = getContainer(); | |
| 1740 | + var modal = getModal(); | |
| 1741 | + | |
| 1742 | + if (animation) { | |
| 1743 | + addClass(modal, swalClasses.show); | |
| 1744 | + addClass(container, swalClasses.fade); | |
| 1745 | + removeClass(modal, swalClasses.hide); | |
| 1746 | + } else { | |
| 1747 | + removeClass(modal, swalClasses.fade); | |
| 1748 | + } | |
| 1749 | + show(modal); | |
| 1750 | + | |
| 1751 | + // scrolling is 'hidden' until animation is done, after that 'auto' | |
| 1752 | + container.style.overflowY = 'hidden'; | |
| 1753 | + if (animationEndEvent && !hasClass(modal, swalClasses.noanimation)) { | |
| 1754 | + modal.addEventListener(animationEndEvent, function swalCloseEventFinished() { | |
| 1755 | + modal.removeEventListener(animationEndEvent, swalCloseEventFinished); | |
| 1756 | + container.style.overflowY = 'auto'; | |
| 1757 | + }); | |
| 1758 | + } else { | |
| 1759 | + container.style.overflowY = 'auto'; | |
| 1760 | + } | |
| 1761 | + | |
| 1762 | + addClass(document.documentElement, swalClasses.shown); | |
| 1763 | + addClass(document.body, swalClasses.shown); | |
| 1764 | + addClass(container, swalClasses.shown); | |
| 1765 | + fixScrollbar(); | |
| 1766 | + iOSfix(); | |
| 1767 | + states.previousActiveElement = document.activeElement; | |
| 1768 | + if (onComplete !== null && typeof onComplete === 'function') { | |
| 1769 | + setTimeout(function () { | |
| 1770 | + onComplete(modal); | |
| 1771 | + }); | |
| 1772 | + } | |
| 1773 | +}; | |
| 1774 | + | |
| 1775 | +var fixScrollbar = function fixScrollbar() { | |
| 1776 | + // for queues, do not do this more than once | |
| 1777 | + if (states.previousBodyPadding !== null) { | |
| 1778 | + return; | |
| 1779 | + } | |
| 1780 | + // if the body has overflow | |
| 1781 | + if (document.body.scrollHeight > window.innerHeight) { | |
| 1782 | + // add padding so the content doesn't shift after removal of scrollbar | |
| 1783 | + states.previousBodyPadding = document.body.style.paddingRight; | |
| 1784 | + document.body.style.paddingRight = measureScrollbar() + 'px'; | |
| 1785 | + } | |
| 1786 | +}; | |
| 1787 | + | |
| 1788 | +var undoScrollbar = function undoScrollbar() { | |
| 1789 | + if (states.previousBodyPadding !== null) { | |
| 1790 | + document.body.style.paddingRight = states.previousBodyPadding; | |
| 1791 | + states.previousBodyPadding = null; | |
| 1792 | + } | |
| 1793 | +}; | |
| 1794 | + | |
| 1795 | +// Fix iOS scrolling http://stackoverflow.com/q/39626302/1331425 | |
| 1796 | +var iOSfix = function iOSfix() { | |
| 1797 | + var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; | |
| 1798 | + if (iOS && !hasClass(document.body, swalClasses.iosfix)) { | |
| 1799 | + var offset = document.body.scrollTop; | |
| 1800 | + document.body.style.top = offset * -1 + 'px'; | |
| 1801 | + addClass(document.body, swalClasses.iosfix); | |
| 1802 | + } | |
| 1803 | +}; | |
| 1804 | + | |
| 1805 | +var undoIOSfix = function undoIOSfix() { | |
| 1806 | + if (hasClass(document.body, swalClasses.iosfix)) { | |
| 1807 | + var offset = parseInt(document.body.style.top, 10); | |
| 1808 | + removeClass(document.body, swalClasses.iosfix); | |
| 1809 | + document.body.style.top = ''; | |
| 1810 | + document.body.scrollTop = offset * -1; | |
| 1811 | + } | |
| 1812 | +}; | |
| 1813 | + | |
| 1814 | +// SweetAlert entry point | |
| 1815 | +var sweetAlert = function sweetAlert() { | |
| 1816 | + for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | |
| 1817 | + args[_key] = arguments[_key]; | |
| 1818 | + } | |
| 1819 | + | |
| 1820 | + if (args[0] === undefined) { | |
| 1821 | + console.error('SweetAlert2 expects at least 1 attribute!'); | |
| 1822 | + return false; | |
| 1823 | + } | |
| 1824 | + | |
| 1825 | + var params = _extends({}, modalParams); | |
| 1826 | + | |
| 1827 | + switch (_typeof(args[0])) { | |
| 1828 | + case 'string': | |
| 1829 | + params.title = args[0]; | |
| 1830 | + params.html = args[1]; | |
| 1831 | + params.type = args[2]; | |
| 1832 | + | |
| 1833 | + break; | |
| 1834 | + | |
| 1835 | + case 'object': | |
| 1836 | + _extends(params, args[0]); | |
| 1837 | + params.extraParams = args[0].extraParams; | |
| 1838 | + | |
| 1839 | + if (params.input === 'email' && params.inputValidator === null) { | |
| 1840 | + params.inputValidator = function (email) { | |
| 1841 | + return new Promise(function (resolve, reject) { | |
| 1842 | + var emailRegex = /^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/; | |
| 1843 | + if (emailRegex.test(email)) { | |
| 1844 | + resolve(); | |
| 1845 | + } else { | |
| 1846 | + reject('Invalid email address'); | |
| 1847 | + } | |
| 1848 | + }); | |
| 1849 | + }; | |
| 1850 | + } | |
| 1851 | + | |
| 1852 | + if (params.input === 'url' && params.inputValidator === null) { | |
| 1853 | + params.inputValidator = function (url) { | |
| 1854 | + return new Promise(function (resolve, reject) { | |
| 1855 | + var urlRegex = /^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?$/; | |
| 1856 | + if (urlRegex.test(url)) { | |
| 1857 | + resolve(); | |
| 1858 | + } else { | |
| 1859 | + reject('Invalid URL'); | |
| 1860 | + } | |
| 1861 | + }); | |
| 1862 | + }; | |
| 1863 | + } | |
| 1864 | + break; | |
| 1865 | + | |
| 1866 | + default: | |
| 1867 | + console.error('SweetAlert2: Unexpected type of argument! Expected "string" or "object", got ' + _typeof(args[0])); | |
| 1868 | + return false; | |
| 1869 | + } | |
| 1870 | + | |
| 1871 | + setParameters(params); | |
| 1872 | + | |
| 1873 | + var container = getContainer(); | |
| 1874 | + var modal = getModal(); | |
| 1875 | + | |
| 1876 | + return new Promise(function (resolve, reject) { | |
| 1877 | + // Close on timer | |
| 1878 | + if (params.timer) { | |
| 1879 | + modal.timeout = setTimeout(function () { | |
| 1880 | + sweetAlert.closeModal(params.onClose); | |
| 1881 | + if (params.useRejections) { | |
| 1882 | + reject('timer'); | |
| 1883 | + } else { | |
| 1884 | + resolve({ dismiss: 'timer' }); | |
| 1885 | + } | |
| 1886 | + }, params.timer); | |
| 1887 | + } | |
| 1888 | + | |
| 1889 | + // Get input element by specified type or, if type isn't specified, by params.input | |
| 1890 | + var getInput = function getInput(inputType) { | |
| 1891 | + inputType = inputType || params.input; | |
| 1892 | + if (!inputType) { | |
| 1893 | + return null; | |
| 1894 | + } | |
| 1895 | + switch (inputType) { | |
| 1896 | + case 'select': | |
| 1897 | + case 'textarea': | |
| 1898 | + case 'file': | |
| 1899 | + return getChildByClass(modal, swalClasses[inputType]); | |
| 1900 | + case 'checkbox': | |
| 1901 | + return modal.querySelector('.' + swalClasses.checkbox + ' input'); | |
| 1902 | + case 'radio': | |
| 1903 | + return modal.querySelector('.' + swalClasses.radio + ' input:checked') || modal.querySelector('.' + swalClasses.radio + ' input:first-child'); | |
| 1904 | + case 'range': | |
| 1905 | + return modal.querySelector('.' + swalClasses.range + ' input'); | |
| 1906 | + default: | |
| 1907 | + return getChildByClass(modal, swalClasses.input); | |
| 1908 | + } | |
| 1909 | + }; | |
| 1910 | + | |
| 1911 | + // Get the value of the modal input | |
| 1912 | + var getInputValue = function getInputValue() { | |
| 1913 | + var input = getInput(); | |
| 1914 | + if (!input) { | |
| 1915 | + return null; | |
| 1916 | + } | |
| 1917 | + switch (params.input) { | |
| 1918 | + case 'checkbox': | |
| 1919 | + return input.checked ? 1 : 0; | |
| 1920 | + case 'radio': | |
| 1921 | + return input.checked ? input.value : null; | |
| 1922 | + case 'file': | |
| 1923 | + return input.files.length ? input.files[0] : null; | |
| 1924 | + default: | |
| 1925 | + return params.inputAutoTrim ? input.value.trim() : input.value; | |
| 1926 | + } | |
| 1927 | + }; | |
| 1928 | + | |
| 1929 | + // input autofocus | |
| 1930 | + if (params.input) { | |
| 1931 | + setTimeout(function () { | |
| 1932 | + var input = getInput(); | |
| 1933 | + if (input) { | |
| 1934 | + focusInput(input); | |
| 1935 | + } | |
| 1936 | + }, 0); | |
| 1937 | + } | |
| 1938 | + | |
| 1939 | + var confirm = function confirm(value) { | |
| 1940 | + if (params.showLoaderOnConfirm) { | |
| 1941 | + sweetAlert.showLoading(); | |
| 1942 | + } | |
| 1943 | + | |
| 1944 | + if (params.preConfirm) { | |
| 1945 | + params.preConfirm(value, params.extraParams).then(function (preConfirmValue) { | |
| 1946 | + sweetAlert.closeModal(params.onClose); | |
| 1947 | + resolve(preConfirmValue || value); | |
| 1948 | + }, function (error) { | |
| 1949 | + sweetAlert.hideLoading(); | |
| 1950 | + if (error) { | |
| 1951 | + sweetAlert.showValidationError(error); | |
| 1952 | + } | |
| 1953 | + }); | |
| 1954 | + } else { | |
| 1955 | + sweetAlert.closeModal(params.onClose); | |
| 1956 | + if (params.useRejections) { | |
| 1957 | + resolve(value); | |
| 1958 | + } else { | |
| 1959 | + resolve({ value: value }); | |
| 1960 | + } | |
| 1961 | + } | |
| 1962 | + }; | |
| 1963 | + | |
| 1964 | + // Mouse interactions | |
| 1965 | + var onButtonEvent = function onButtonEvent(event) { | |
| 1966 | + var e = event || window.event; | |
| 1967 | + var target = e.target || e.srcElement; | |
| 1968 | + var confirmButton = getConfirmButton(); | |
| 1969 | + var cancelButton = getCancelButton(); | |
| 1970 | + var targetedConfirm = confirmButton && (confirmButton === target || confirmButton.contains(target)); | |
| 1971 | + var targetedCancel = cancelButton && (cancelButton === target || cancelButton.contains(target)); | |
| 1972 | + | |
| 1973 | + switch (e.type) { | |
| 1974 | + case 'mouseover': | |
| 1975 | + case 'mouseup': | |
| 1976 | + if (params.buttonsStyling) { | |
| 1977 | + if (targetedConfirm) { | |
| 1978 | + confirmButton.style.backgroundColor = colorLuminance(params.confirmButtonColor, -0.1); | |
| 1979 | + } else if (targetedCancel) { | |
| 1980 | + cancelButton.style.backgroundColor = colorLuminance(params.cancelButtonColor, -0.1); | |
| 1981 | + } | |
| 1982 | + } | |
| 1983 | + break; | |
| 1984 | + case 'mouseout': | |
| 1985 | + if (params.buttonsStyling) { | |
| 1986 | + if (targetedConfirm) { | |
| 1987 | + confirmButton.style.backgroundColor = params.confirmButtonColor; | |
| 1988 | + } else if (targetedCancel) { | |
| 1989 | + cancelButton.style.backgroundColor = params.cancelButtonColor; | |
| 1990 | + } | |
| 1991 | + } | |
| 1992 | + break; | |
| 1993 | + case 'mousedown': | |
| 1994 | + if (params.buttonsStyling) { | |
| 1995 | + if (targetedConfirm) { | |
| 1996 | + confirmButton.style.backgroundColor = colorLuminance(params.confirmButtonColor, -0.2); | |
| 1997 | + } else if (targetedCancel) { | |
| 1998 | + cancelButton.style.backgroundColor = colorLuminance(params.cancelButtonColor, -0.2); | |
| 1999 | + } | |
| 2000 | + } | |
| 2001 | + break; | |
| 2002 | + case 'click': | |
| 2003 | + // Clicked 'confirm' | |
| 2004 | + if (targetedConfirm && sweetAlert.isVisible()) { | |
| 2005 | + sweetAlert.disableButtons(); | |
| 2006 | + if (params.input) { | |
| 2007 | + var inputValue = getInputValue(); | |
| 2008 | + | |
| 2009 | + if (params.inputValidator) { | |
| 2010 | + sweetAlert.disableInput(); | |
| 2011 | + params.inputValidator(inputValue, params.extraParams).then(function () { | |
| 2012 | + sweetAlert.enableButtons(); | |
| 2013 | + sweetAlert.enableInput(); | |
| 2014 | + confirm(inputValue); | |
| 2015 | + }, function (error) { | |
| 2016 | + sweetAlert.enableButtons(); | |
| 2017 | + sweetAlert.enableInput(); | |
| 2018 | + if (error) { | |
| 2019 | + sweetAlert.showValidationError(error); | |
| 2020 | + } | |
| 2021 | + }); | |
| 2022 | + } else { | |
| 2023 | + confirm(inputValue); | |
| 2024 | + } | |
| 2025 | + } else { | |
| 2026 | + confirm(true); | |
| 2027 | + } | |
| 2028 | + | |
| 2029 | + // Clicked 'cancel' | |
| 2030 | + } else if (targetedCancel && sweetAlert.isVisible()) { | |
| 2031 | + sweetAlert.disableButtons(); | |
| 2032 | + sweetAlert.closeModal(params.onClose); | |
| 2033 | + if (params.useRejections) { | |
| 2034 | + reject('cancel'); | |
| 2035 | + } else { | |
| 2036 | + resolve({ dismiss: 'cancel' }); | |
| 2037 | + } | |
| 2038 | + } | |
| 2039 | + break; | |
| 2040 | + default: | |
| 2041 | + } | |
| 2042 | + }; | |
| 2043 | + | |
| 2044 | + var buttons = modal.querySelectorAll('button'); | |
| 2045 | + for (var i = 0; i < buttons.length; i++) { | |
| 2046 | + buttons[i].onclick = onButtonEvent; | |
| 2047 | + buttons[i].onmouseover = onButtonEvent; | |
| 2048 | + buttons[i].onmouseout = onButtonEvent; | |
| 2049 | + buttons[i].onmousedown = onButtonEvent; | |
| 2050 | + } | |
| 2051 | + | |
| 2052 | + // Closing modal by close button | |
| 2053 | + getCloseButton().onclick = function () { | |
| 2054 | + sweetAlert.closeModal(params.onClose); | |
| 2055 | + if (params.useRejections) { | |
| 2056 | + reject('close'); | |
| 2057 | + } else { | |
| 2058 | + resolve({ dismiss: 'close' }); | |
| 2059 | + } | |
| 2060 | + }; | |
| 2061 | + | |
| 2062 | + // Closing modal by overlay click | |
| 2063 | + container.onclick = function (e) { | |
| 2064 | + if (e.target !== container) { | |
| 2065 | + return; | |
| 2066 | + } | |
| 2067 | + if (params.allowOutsideClick) { | |
| 2068 | + sweetAlert.closeModal(params.onClose); | |
| 2069 | + if (params.useRejections) { | |
| 2070 | + reject('overlay'); | |
| 2071 | + } else { | |
| 2072 | + resolve({ dismiss: 'overlay' }); | |
| 2073 | + } | |
| 2074 | + } | |
| 2075 | + }; | |
| 2076 | + | |
| 2077 | + var buttonsWrapper = getButtonsWrapper(); | |
| 2078 | + var confirmButton = getConfirmButton(); | |
| 2079 | + var cancelButton = getCancelButton(); | |
| 2080 | + | |
| 2081 | + // Reverse buttons (Confirm on the right side) | |
| 2082 | + if (params.reverseButtons) { | |
| 2083 | + confirmButton.parentNode.insertBefore(cancelButton, confirmButton); | |
| 2084 | + } else { | |
| 2085 | + confirmButton.parentNode.insertBefore(confirmButton, cancelButton); | |
| 2086 | + } | |
| 2087 | + | |
| 2088 | + // Focus handling | |
| 2089 | + var setFocus = function setFocus(index, increment) { | |
| 2090 | + var focusableElements = getFocusableElements(params.focusCancel); | |
| 2091 | + // search for visible elements and select the next possible match | |
| 2092 | + for (var _i3 = 0; _i3 < focusableElements.length; _i3++) { | |
| 2093 | + index = index + increment; | |
| 2094 | + | |
| 2095 | + // rollover to first item | |
| 2096 | + if (index === focusableElements.length) { | |
| 2097 | + index = 0; | |
| 2098 | + | |
| 2099 | + // go to last item | |
| 2100 | + } else if (index === -1) { | |
| 2101 | + index = focusableElements.length - 1; | |
| 2102 | + } | |
| 2103 | + | |
| 2104 | + // determine if element is visible | |
| 2105 | + var el = focusableElements[index]; | |
| 2106 | + if (isVisible(el)) { | |
| 2107 | + return el.focus(); | |
| 2108 | + } | |
| 2109 | + } | |
| 2110 | + }; | |
| 2111 | + | |
| 2112 | + var handleKeyDown = function handleKeyDown(event) { | |
| 2113 | + var e = event || window.event; | |
| 2114 | + var keyCode = e.keyCode || e.which; | |
| 2115 | + | |
| 2116 | + if ([9, 13, 32, 27, 37, 38, 39, 40].indexOf(keyCode) === -1) { | |
| 2117 | + // Don't do work on keys we don't care about. | |
| 2118 | + return; | |
| 2119 | + } | |
| 2120 | + | |
| 2121 | + var targetElement = e.target || e.srcElement; | |
| 2122 | + | |
| 2123 | + var focusableElements = getFocusableElements(params.focusCancel); | |
| 2124 | + var btnIndex = -1; // Find the button - note, this is a nodelist, not an array. | |
| 2125 | + for (var _i4 = 0; _i4 < focusableElements.length; _i4++) { | |
| 2126 | + if (targetElement === focusableElements[_i4]) { | |
| 2127 | + btnIndex = _i4; | |
| 2128 | + break; | |
| 2129 | + } | |
| 2130 | + } | |
| 2131 | + | |
| 2132 | + // TAB | |
| 2133 | + if (keyCode === 9) { | |
| 2134 | + if (!e.shiftKey) { | |
| 2135 | + // Cycle to the next button | |
| 2136 | + setFocus(btnIndex, 1); | |
| 2137 | + } else { | |
| 2138 | + // Cycle to the prev button | |
| 2139 | + setFocus(btnIndex, -1); | |
| 2140 | + } | |
| 2141 | + e.stopPropagation(); | |
| 2142 | + e.preventDefault(); | |
| 2143 | + | |
| 2144 | + // ARROWS - switch focus between buttons | |
| 2145 | + } else if (keyCode === 37 || keyCode === 38 || keyCode === 39 || keyCode === 40) { | |
| 2146 | + // focus Cancel button if Confirm button is currently focused | |
| 2147 | + if (document.activeElement === confirmButton && isVisible(cancelButton)) { | |
| 2148 | + cancelButton.focus(); | |
| 2149 | + // and vice versa | |
| 2150 | + } else if (document.activeElement === cancelButton && isVisible(confirmButton)) { | |
| 2151 | + confirmButton.focus(); | |
| 2152 | + } | |
| 2153 | + | |
| 2154 | + // ENTER/SPACE | |
| 2155 | + } else if (keyCode === 13 || keyCode === 32) { | |
| 2156 | + if (btnIndex === -1 && params.allowEnterKey) { | |
| 2157 | + // ENTER/SPACE clicked outside of a button. | |
| 2158 | + if (params.focusCancel) { | |
| 2159 | + fireClick(cancelButton, e); | |
| 2160 | + } else { | |
| 2161 | + fireClick(confirmButton, e); | |
| 2162 | + } | |
| 2163 | + e.stopPropagation(); | |
| 2164 | + e.preventDefault(); | |
| 2165 | + } | |
| 2166 | + | |
| 2167 | + // ESC | |
| 2168 | + } else if (keyCode === 27 && params.allowEscapeKey === true) { | |
| 2169 | + sweetAlert.closeModal(params.onClose); | |
| 2170 | + if (params.useRejections) { | |
| 2171 | + reject('esc'); | |
| 2172 | + } else { | |
| 2173 | + resolve({ dismiss: 'esc' }); | |
| 2174 | + } | |
| 2175 | + } | |
| 2176 | + }; | |
| 2177 | + | |
| 2178 | + if (!window.onkeydown || window.onkeydown.toString() !== handleKeyDown.toString()) { | |
| 2179 | + states.previousWindowKeyDown = window.onkeydown; | |
| 2180 | + window.onkeydown = handleKeyDown; | |
| 2181 | + } | |
| 2182 | + | |
| 2183 | + // Loading state | |
| 2184 | + if (params.buttonsStyling) { | |
| 2185 | + confirmButton.style.borderLeftColor = params.confirmButtonColor; | |
| 2186 | + confirmButton.style.borderRightColor = params.confirmButtonColor; | |
| 2187 | + } | |
| 2188 | + | |
| 2189 | + /** | |
| 2190 | + * Show spinner instead of Confirm button and disable Cancel button | |
| 2191 | + */ | |
| 2192 | + sweetAlert.hideLoading = sweetAlert.disableLoading = function () { | |
| 2193 | + if (!params.showConfirmButton) { | |
| 2194 | + hide(confirmButton); | |
| 2195 | + if (!params.showCancelButton) { | |
| 2196 | + hide(getButtonsWrapper()); | |
| 2197 | + } | |
| 2198 | + } | |
| 2199 | + removeClass(buttonsWrapper, swalClasses.loading); | |
| 2200 | + removeClass(modal, swalClasses.loading); | |
| 2201 | + confirmButton.disabled = false; | |
| 2202 | + cancelButton.disabled = false; | |
| 2203 | + }; | |
| 2204 | + | |
| 2205 | + sweetAlert.getTitle = function () { | |
| 2206 | + return getTitle(); | |
| 2207 | + }; | |
| 2208 | + sweetAlert.getContent = function () { | |
| 2209 | + return getContent(); | |
| 2210 | + }; | |
| 2211 | + sweetAlert.getInput = function () { | |
| 2212 | + return getInput(); | |
| 2213 | + }; | |
| 2214 | + sweetAlert.getImage = function () { | |
| 2215 | + return getImage(); | |
| 2216 | + }; | |
| 2217 | + sweetAlert.getButtonsWrapper = function () { | |
| 2218 | + return getButtonsWrapper(); | |
| 2219 | + }; | |
| 2220 | + sweetAlert.getConfirmButton = function () { | |
| 2221 | + return getConfirmButton(); | |
| 2222 | + }; | |
| 2223 | + sweetAlert.getCancelButton = function () { | |
| 2224 | + return getCancelButton(); | |
| 2225 | + }; | |
| 2226 | + | |
| 2227 | + sweetAlert.enableButtons = function () { | |
| 2228 | + confirmButton.disabled = false; | |
| 2229 | + cancelButton.disabled = false; | |
| 2230 | + }; | |
| 2231 | + | |
| 2232 | + sweetAlert.disableButtons = function () { | |
| 2233 | + confirmButton.disabled = true; | |
| 2234 | + cancelButton.disabled = true; | |
| 2235 | + }; | |
| 2236 | + | |
| 2237 | + sweetAlert.enableConfirmButton = function () { | |
| 2238 | + confirmButton.disabled = false; | |
| 2239 | + }; | |
| 2240 | + | |
| 2241 | + sweetAlert.disableConfirmButton = function () { | |
| 2242 | + confirmButton.disabled = true; | |
| 2243 | + }; | |
| 2244 | + | |
| 2245 | + sweetAlert.enableInput = function () { | |
| 2246 | + var input = getInput(); | |
| 2247 | + if (!input) { | |
| 2248 | + return false; | |
| 2249 | + } | |
| 2250 | + if (input.type === 'radio') { | |
| 2251 | + var radiosContainer = input.parentNode.parentNode; | |
| 2252 | + var radios = radiosContainer.querySelectorAll('input'); | |
| 2253 | + for (var _i5 = 0; _i5 < radios.length; _i5++) { | |
| 2254 | + radios[_i5].disabled = false; | |
| 2255 | + } | |
| 2256 | + } else { | |
| 2257 | + input.disabled = false; | |
| 2258 | + } | |
| 2259 | + }; | |
| 2260 | + | |
| 2261 | + sweetAlert.disableInput = function () { | |
| 2262 | + var input = getInput(); | |
| 2263 | + if (!input) { | |
| 2264 | + return false; | |
| 2265 | + } | |
| 2266 | + if (input && input.type === 'radio') { | |
| 2267 | + var radiosContainer = input.parentNode.parentNode; | |
| 2268 | + var radios = radiosContainer.querySelectorAll('input'); | |
| 2269 | + for (var _i6 = 0; _i6 < radios.length; _i6++) { | |
| 2270 | + radios[_i6].disabled = true; | |
| 2271 | + } | |
| 2272 | + } else { | |
| 2273 | + input.disabled = true; | |
| 2274 | + } | |
| 2275 | + }; | |
| 2276 | + | |
| 2277 | + // Set modal min-height to disable scrolling inside the modal | |
| 2278 | + sweetAlert.recalculateHeight = debounce(function () { | |
| 2279 | + var modal = getModal(); | |
| 2280 | + if (!modal) { | |
| 2281 | + return; | |
| 2282 | + } | |
| 2283 | + var prevState = modal.style.display; | |
| 2284 | + modal.style.minHeight = ''; | |
| 2285 | + show(modal); | |
| 2286 | + modal.style.minHeight = modal.scrollHeight + 1 + 'px'; | |
| 2287 | + modal.style.display = prevState; | |
| 2288 | + }, 50); | |
| 2289 | + | |
| 2290 | + // Show block with validation error | |
| 2291 | + sweetAlert.showValidationError = function (error) { | |
| 2292 | + var validationError = getValidationError(); | |
| 2293 | + validationError.innerHTML = error; | |
| 2294 | + show(validationError); | |
| 2295 | + | |
| 2296 | + var input = getInput(); | |
| 2297 | + if (input) { | |
| 2298 | + focusInput(input); | |
| 2299 | + addClass(input, swalClasses.inputerror); | |
| 2300 | + } | |
| 2301 | + }; | |
| 2302 | + | |
| 2303 | + // Hide block with validation error | |
| 2304 | + sweetAlert.resetValidationError = function () { | |
| 2305 | + var validationError = getValidationError(); | |
| 2306 | + hide(validationError); | |
| 2307 | + sweetAlert.recalculateHeight(); | |
| 2308 | + | |
| 2309 | + var input = getInput(); | |
| 2310 | + if (input) { | |
| 2311 | + removeClass(input, swalClasses.inputerror); | |
| 2312 | + } | |
| 2313 | + }; | |
| 2314 | + | |
| 2315 | + sweetAlert.getProgressSteps = function () { | |
| 2316 | + return params.progressSteps; | |
| 2317 | + }; | |
| 2318 | + | |
| 2319 | + sweetAlert.setProgressSteps = function (progressSteps) { | |
| 2320 | + params.progressSteps = progressSteps; | |
| 2321 | + setParameters(params); | |
| 2322 | + }; | |
| 2323 | + | |
| 2324 | + sweetAlert.showProgressSteps = function () { | |
| 2325 | + show(getProgressSteps()); | |
| 2326 | + }; | |
| 2327 | + | |
| 2328 | + sweetAlert.hideProgressSteps = function () { | |
| 2329 | + hide(getProgressSteps()); | |
| 2330 | + }; | |
| 2331 | + | |
| 2332 | + sweetAlert.enableButtons(); | |
| 2333 | + sweetAlert.hideLoading(); | |
| 2334 | + sweetAlert.resetValidationError(); | |
| 2335 | + | |
| 2336 | + // inputs | |
| 2337 | + var inputTypes = ['input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea']; | |
| 2338 | + var input = void 0; | |
| 2339 | + for (var _i7 = 0; _i7 < inputTypes.length; _i7++) { | |
| 2340 | + var inputClass = swalClasses[inputTypes[_i7]]; | |
| 2341 | + var inputContainer = getChildByClass(modal, inputClass); | |
| 2342 | + input = getInput(inputTypes[_i7]); | |
| 2343 | + | |
| 2344 | + // set attributes | |
| 2345 | + if (input) { | |
| 2346 | + for (var j in input.attributes) { | |
| 2347 | + if (input.attributes.hasOwnProperty(j)) { | |
| 2348 | + var attrName = input.attributes[j].name; | |
| 2349 | + if (attrName !== 'type' && attrName !== 'value') { | |
| 2350 | + input.removeAttribute(attrName); | |
| 2351 | + } | |
| 2352 | + } | |
| 2353 | + } | |
| 2354 | + for (var attr in params.inputAttributes) { | |
| 2355 | + input.setAttribute(attr, params.inputAttributes[attr]); | |
| 2356 | + } | |
| 2357 | + } | |
| 2358 | + | |
| 2359 | + // set class | |
| 2360 | + inputContainer.className = inputClass; | |
| 2361 | + if (params.inputClass) { | |
| 2362 | + addClass(inputContainer, params.inputClass); | |
| 2363 | + } | |
| 2364 | + | |
| 2365 | + hide(inputContainer); | |
| 2366 | + } | |
| 2367 | + | |
| 2368 | + var populateInputOptions = void 0; | |
| 2369 | + switch (params.input) { | |
| 2370 | + case 'text': | |
| 2371 | + case 'email': | |
| 2372 | + case 'password': | |
| 2373 | + case 'number': | |
| 2374 | + case 'tel': | |
| 2375 | + case 'url': | |
| 2376 | + input = getChildByClass(modal, swalClasses.input); | |
| 2377 | + input.value = params.inputValue; | |
| 2378 | + input.placeholder = params.inputPlaceholder; | |
| 2379 | + input.type = params.input; | |
| 2380 | + show(input); | |
| 2381 | + break; | |
| 2382 | + case 'file': | |
| 2383 | + input = getChildByClass(modal, swalClasses.file); | |
| 2384 | + input.placeholder = params.inputPlaceholder; | |
| 2385 | + input.type = params.input; | |
| 2386 | + show(input); | |
| 2387 | + break; | |
| 2388 | + case 'range': | |
| 2389 | + var range = getChildByClass(modal, swalClasses.range); | |
| 2390 | + var rangeInput = range.querySelector('input'); | |
| 2391 | + var rangeOutput = range.querySelector('output'); | |
| 2392 | + rangeInput.value = params.inputValue; | |
| 2393 | + rangeInput.type = params.input; | |
| 2394 | + rangeOutput.value = params.inputValue; | |
| 2395 | + show(range); | |
| 2396 | + break; | |
| 2397 | + case 'select': | |
| 2398 | + var select = getChildByClass(modal, swalClasses.select); | |
| 2399 | + select.innerHTML = ''; | |
| 2400 | + if (params.inputPlaceholder) { | |
| 2401 | + var placeholder = document.createElement('option'); | |
| 2402 | + placeholder.innerHTML = params.inputPlaceholder; | |
| 2403 | + placeholder.value = ''; | |
| 2404 | + placeholder.disabled = true; | |
| 2405 | + placeholder.selected = true; | |
| 2406 | + select.appendChild(placeholder); | |
| 2407 | + } | |
| 2408 | + populateInputOptions = function populateInputOptions(inputOptions) { | |
| 2409 | + for (var optionValue in inputOptions) { | |
| 2410 | + var option = document.createElement('option'); | |
| 2411 | + option.value = optionValue; | |
| 2412 | + option.innerHTML = inputOptions[optionValue]; | |
| 2413 | + if (params.inputValue === optionValue) { | |
| 2414 | + option.selected = true; | |
| 2415 | + } | |
| 2416 | + select.appendChild(option); | |
| 2417 | + } | |
| 2418 | + show(select); | |
| 2419 | + select.focus(); | |
| 2420 | + }; | |
| 2421 | + break; | |
| 2422 | + case 'radio': | |
| 2423 | + var radio = getChildByClass(modal, swalClasses.radio); | |
| 2424 | + radio.innerHTML = ''; | |
| 2425 | + populateInputOptions = function populateInputOptions(inputOptions) { | |
| 2426 | + for (var radioValue in inputOptions) { | |
| 2427 | + var radioInput = document.createElement('input'); | |
| 2428 | + var radioLabel = document.createElement('label'); | |
| 2429 | + var radioLabelSpan = document.createElement('span'); | |
| 2430 | + radioInput.type = 'radio'; | |
| 2431 | + radioInput.name = swalClasses.radio; | |
| 2432 | + radioInput.value = radioValue; | |
| 2433 | + if (params.inputValue === radioValue) { | |
| 2434 | + radioInput.checked = true; | |
| 2435 | + } | |
| 2436 | + radioLabelSpan.innerHTML = inputOptions[radioValue]; | |
| 2437 | + radioLabel.appendChild(radioInput); | |
| 2438 | + radioLabel.appendChild(radioLabelSpan); | |
| 2439 | + radioLabel.for = radioInput.id; | |
| 2440 | + radio.appendChild(radioLabel); | |
| 2441 | + } | |
| 2442 | + show(radio); | |
| 2443 | + var radios = radio.querySelectorAll('input'); | |
| 2444 | + if (radios.length) { | |
| 2445 | + radios[0].focus(); | |
| 2446 | + } | |
| 2447 | + }; | |
| 2448 | + break; | |
| 2449 | + case 'checkbox': | |
| 2450 | + var checkbox = getChildByClass(modal, swalClasses.checkbox); | |
| 2451 | + var checkboxInput = getInput('checkbox'); | |
| 2452 | + checkboxInput.type = 'checkbox'; | |
| 2453 | + checkboxInput.value = 1; | |
| 2454 | + checkboxInput.id = swalClasses.checkbox; | |
| 2455 | + checkboxInput.checked = Boolean(params.inputValue); | |
| 2456 | + var label = checkbox.getElementsByTagName('span'); | |
| 2457 | + if (label.length) { | |
| 2458 | + checkbox.removeChild(label[0]); | |
| 2459 | + } | |
| 2460 | + label = document.createElement('span'); | |
| 2461 | + label.innerHTML = params.inputPlaceholder; | |
| 2462 | + checkbox.appendChild(label); | |
| 2463 | + show(checkbox); | |
| 2464 | + break; | |
| 2465 | + case 'textarea': | |
| 2466 | + var textarea = getChildByClass(modal, swalClasses.textarea); | |
| 2467 | + textarea.value = params.inputValue; | |
| 2468 | + textarea.placeholder = params.inputPlaceholder; | |
| 2469 | + show(textarea); | |
| 2470 | + break; | |
| 2471 | + case null: | |
| 2472 | + break; | |
| 2473 | + default: | |
| 2474 | + console.error('SweetAlert2: Unexpected type of input! Expected "text", "email", "password", "number", "tel", "select", "radio", "checkbox", "textarea", "file" or "url", got "' + params.input + '"'); | |
| 2475 | + break; | |
| 2476 | + } | |
| 2477 | + | |
| 2478 | + if (params.input === 'select' || params.input === 'radio') { | |
| 2479 | + if (params.inputOptions instanceof Promise) { | |
| 2480 | + sweetAlert.showLoading(); | |
| 2481 | + params.inputOptions.then(function (inputOptions) { | |
| 2482 | + sweetAlert.hideLoading(); | |
| 2483 | + populateInputOptions(inputOptions); | |
| 2484 | + }); | |
| 2485 | + } else if (_typeof(params.inputOptions) === 'object') { | |
| 2486 | + populateInputOptions(params.inputOptions); | |
| 2487 | + } else { | |
| 2488 | + console.error('SweetAlert2: Unexpected type of inputOptions! Expected object or Promise, got ' + _typeof(params.inputOptions)); | |
| 2489 | + } | |
| 2490 | + } | |
| 2491 | + | |
| 2492 | + openModal(params.animation, params.onOpen); | |
| 2493 | + | |
| 2494 | + // Focus the first element (input or button) | |
| 2495 | + if (params.allowEnterKey) { | |
| 2496 | + setFocus(-1, 1); | |
| 2497 | + } else { | |
| 2498 | + if (document.activeElement) { | |
| 2499 | + document.activeElement.blur(); | |
| 2500 | + } | |
| 2501 | + } | |
| 2502 | + | |
| 2503 | + // fix scroll | |
| 2504 | + getContainer().scrollTop = 0; | |
| 2505 | + | |
| 2506 | + // Observe changes inside the modal and adjust height | |
| 2507 | + if (typeof MutationObserver !== 'undefined' && !swal2Observer) { | |
| 2508 | + swal2Observer = new MutationObserver(sweetAlert.recalculateHeight); | |
| 2509 | + swal2Observer.observe(modal, { childList: true, characterData: true, subtree: true }); | |
| 2510 | + } | |
| 2511 | + }); | |
| 2512 | +}; | |
| 2513 | + | |
| 2514 | +/* | |
| 2515 | + * Global function to determine if swal2 modal is shown | |
| 2516 | + */ | |
| 2517 | +sweetAlert.isVisible = function () { | |
| 2518 | + return !!getModal(); | |
| 2519 | +}; | |
| 2520 | + | |
| 2521 | +/* | |
| 2522 | + * Global function for chaining sweetAlert modals | |
| 2523 | + */ | |
| 2524 | +sweetAlert.queue = function (steps) { | |
| 2525 | + queue = steps; | |
| 2526 | + var resetQueue = function resetQueue() { | |
| 2527 | + queue = []; | |
| 2528 | + document.body.removeAttribute('data-swal2-queue-step'); | |
| 2529 | + }; | |
| 2530 | + var queueResult = []; | |
| 2531 | + return new Promise(function (resolve, reject) { | |
| 2532 | + (function step(i, callback) { | |
| 2533 | + if (i < queue.length) { | |
| 2534 | + document.body.setAttribute('data-swal2-queue-step', i); | |
| 2535 | + | |
| 2536 | + sweetAlert(queue[i]).then(function (result) { | |
| 2537 | + queueResult.push(result); | |
| 2538 | + step(i + 1, callback); | |
| 2539 | + }, function (dismiss) { | |
| 2540 | + resetQueue(); | |
| 2541 | + reject(dismiss); | |
| 2542 | + }); | |
| 2543 | + } else { | |
| 2544 | + resetQueue(); | |
| 2545 | + resolve(queueResult); | |
| 2546 | + } | |
| 2547 | + })(0); | |
| 2548 | + }); | |
| 2549 | +}; | |
| 2550 | + | |
| 2551 | +/* | |
| 2552 | + * Global function for getting the index of current modal in queue | |
| 2553 | + */ | |
| 2554 | +sweetAlert.getQueueStep = function () { | |
| 2555 | + return document.body.getAttribute('data-swal2-queue-step'); | |
| 2556 | +}; | |
| 2557 | + | |
| 2558 | +/* | |
| 2559 | + * Global function for inserting a modal to the queue | |
| 2560 | + */ | |
| 2561 | +sweetAlert.insertQueueStep = function (step, index) { | |
| 2562 | + if (index && index < queue.length) { | |
| 2563 | + return queue.splice(index, 0, step); | |
| 2564 | + } | |
| 2565 | + return queue.push(step); | |
| 2566 | +}; | |
| 2567 | + | |
| 2568 | +/* | |
| 2569 | + * Global function for deleting a modal from the queue | |
| 2570 | + */ | |
| 2571 | +sweetAlert.deleteQueueStep = function (index) { | |
| 2572 | + if (typeof queue[index] !== 'undefined') { | |
| 2573 | + queue.splice(index, 1); | |
| 2574 | + } | |
| 2575 | +}; | |
| 2576 | + | |
| 2577 | +/* | |
| 2578 | + * Global function to close sweetAlert | |
| 2579 | + */ | |
| 2580 | +sweetAlert.close = sweetAlert.closeModal = function (onComplete) { | |
| 2581 | + var container = getContainer(); | |
| 2582 | + var modal = getModal(); | |
| 2583 | + if (!modal) { | |
| 2584 | + return; | |
| 2585 | + } | |
| 2586 | + removeClass(modal, swalClasses.show); | |
| 2587 | + addClass(modal, swalClasses.hide); | |
| 2588 | + clearTimeout(modal.timeout); | |
| 2589 | + | |
| 2590 | + resetPrevState(); | |
| 2591 | + | |
| 2592 | + var removeModalAndResetState = function removeModalAndResetState() { | |
| 2593 | + if (container.parentNode) { | |
| 2594 | + container.parentNode.removeChild(container); | |
| 2595 | + } | |
| 2596 | + removeClass(document.documentElement, swalClasses.shown); | |
| 2597 | + removeClass(document.body, swalClasses.shown); | |
| 2598 | + undoScrollbar(); | |
| 2599 | + undoIOSfix(); | |
| 2600 | + }; | |
| 2601 | + | |
| 2602 | + // If animation is supported, animate | |
| 2603 | + if (animationEndEvent && !hasClass(modal, swalClasses.noanimation)) { | |
| 2604 | + modal.addEventListener(animationEndEvent, function swalCloseEventFinished() { | |
| 2605 | + modal.removeEventListener(animationEndEvent, swalCloseEventFinished); | |
| 2606 | + if (hasClass(modal, swalClasses.hide)) { | |
| 2607 | + removeModalAndResetState(); | |
| 2608 | + } | |
| 2609 | + }); | |
| 2610 | + } else { | |
| 2611 | + // Otherwise, remove immediately | |
| 2612 | + removeModalAndResetState(); | |
| 2613 | + } | |
| 2614 | + if (onComplete !== null && typeof onComplete === 'function') { | |
| 2615 | + setTimeout(function () { | |
| 2616 | + onComplete(modal); | |
| 2617 | + }); | |
| 2618 | + } | |
| 2619 | +}; | |
| 2620 | + | |
| 2621 | +/* | |
| 2622 | + * Global function to click 'Confirm' button | |
| 2623 | + */ | |
| 2624 | +sweetAlert.clickConfirm = function () { | |
| 2625 | + return getConfirmButton().click(); | |
| 2626 | +}; | |
| 2627 | + | |
| 2628 | +/* | |
| 2629 | + * Global function to click 'Cancel' button | |
| 2630 | + */ | |
| 2631 | +sweetAlert.clickCancel = function () { | |
| 2632 | + return getCancelButton().click(); | |
| 2633 | +}; | |
| 2634 | + | |
| 2635 | +/** | |
| 2636 | + * Show spinner instead of Confirm button and disable Cancel button | |
| 2637 | + */ | |
| 2638 | +sweetAlert.showLoading = sweetAlert.enableLoading = function () { | |
| 2639 | + var modal = getModal(); | |
| 2640 | + if (!modal) { | |
| 2641 | + sweetAlert(''); | |
| 2642 | + } | |
| 2643 | + var buttonsWrapper = getButtonsWrapper(); | |
| 2644 | + var confirmButton = getConfirmButton(); | |
| 2645 | + var cancelButton = getCancelButton(); | |
| 2646 | + | |
| 2647 | + show(buttonsWrapper); | |
| 2648 | + show(confirmButton, 'inline-block'); | |
| 2649 | + addClass(buttonsWrapper, swalClasses.loading); | |
| 2650 | + addClass(modal, swalClasses.loading); | |
| 2651 | + confirmButton.disabled = true; | |
| 2652 | + cancelButton.disabled = true; | |
| 2653 | +}; | |
| 2654 | + | |
| 2655 | +/** | |
| 2656 | + * Set default params for each popup | |
| 2657 | + * @param {Object} userParams | |
| 2658 | + */ | |
| 2659 | +sweetAlert.setDefaults = function (userParams) { | |
| 2660 | + if (!userParams || (typeof userParams === 'undefined' ? 'undefined' : _typeof(userParams)) !== 'object') { | |
| 2661 | + return console.error('SweetAlert2: the argument for setDefaults() is required and has to be a object'); | |
| 2662 | + } | |
| 2663 | + | |
| 2664 | + for (var param in userParams) { | |
| 2665 | + if (!defaultParams.hasOwnProperty(param) && param !== 'extraParams') { | |
| 2666 | + console.warn('SweetAlert2: Unknown parameter "' + param + '"'); | |
| 2667 | + delete userParams[param]; | |
| 2668 | + } | |
| 2669 | + } | |
| 2670 | + | |
| 2671 | + _extends(modalParams, userParams); | |
| 2672 | +}; | |
| 2673 | + | |
| 2674 | +/** | |
| 2675 | + * Reset default params for each popup | |
| 2676 | + */ | |
| 2677 | +sweetAlert.resetDefaults = function () { | |
| 2678 | + modalParams = _extends({}, defaultParams); | |
| 2679 | +}; | |
| 2680 | + | |
| 2681 | +sweetAlert.noop = function () {}; | |
| 2682 | + | |
| 2683 | +sweetAlert.version = '6.6.4'; | |
| 2684 | + | |
| 2685 | +sweetAlert.default = sweetAlert; | |
| 2686 | + | |
| 2687 | +return sweetAlert; | |
| 2688 | + | |
| 2689 | +}))); | |
| 2690 | +if (window.Sweetalert2) window.sweetAlert = window.swal = window.Sweetalert2; | |
| 2691 | + | |
| 2692 | 2692 | /* assets/wpuf/js/jquery-ui-timepicker-addon.js */ |
| 2693 | 2693 | /* |
| 2694 | 2694 | * jQuery timepicker addon |
| 2695 | 2695 | * By: Trent Richardson [http://trentrichardson.com] |
| @@ -4610,251 +4610,251 @@ | ||
| 4610 | 4610 | |
| 4611 | 4611 | })(jQuery); |
| 4612 | 4612 | |
| 4613 | 4613 | /* assets/wpuf/js/upload.js */ |
| 4614 | -;(function($) { | |
| 4615 | - | |
| 4616 | - /** | |
| 4617 | - * Upload handler helper | |
| 4618 | - * | |
| 4619 | - * @param string {browse_button} browse_button ID of the pickfile | |
| 4620 | - * @param string {container} container ID of the wrapper | |
| 4621 | - * @param int {max} maximum number of file uplaods | |
| 4622 | - * @param string {type} | |
| 4623 | - */ | |
| 4624 | - window.WPUF_Uploader = function (browse_button, container, max, type, allowed_type, max_file_size) { | |
| 4625 | - this.removed_files = []; | |
| 4626 | - this.container = container; | |
| 4627 | - this.browse_button = browse_button; | |
| 4628 | - this.max = max || 1; | |
| 4629 | - this.count = $('#' + container).find('.wpuf-attachment-list > li').length; //count how many items are there | |
| 4630 | - this.perFileCount = 0; //file count on each upload | |
| 4631 | - this.UploadedFiles = 0; //file count on each upload | |
| 4632 | - | |
| 4633 | - //if no element found on the page, bail out | |
| 4634 | - if( !$('#'+browse_button).length ) { | |
| 4635 | - return; | |
| 4636 | - } | |
| 4637 | - | |
| 4638 | - // enable drag option for ordering | |
| 4639 | - $( "ul.wpuf-attachment-list" ).sortable({ | |
| 4640 | - placeholder: "highlight" | |
| 4641 | - }); | |
| 4642 | - $( "ul.wpuf-attachment-list" ).disableSelection(); | |
| 4643 | - | |
| 4644 | - //instantiate the uploader | |
| 4645 | - this.uploader = new plupload.Uploader({ | |
| 4646 | - runtimes: 'html5,html4', | |
| 4647 | - browse_button: browse_button, | |
| 4648 | - container: container, | |
| 4649 | - multipart: true, | |
| 4650 | - multipart_params: { | |
| 4651 | - action: 'wpuf_upload_file', | |
| 4652 | - form_id: $( '#' + browse_button ).data('form_id') | |
| 4653 | - }, | |
| 4654 | - max_file_count : 2, | |
| 4655 | - multiple_queues: false, | |
| 4656 | - multi_selection: ( ( browse_button == 'wpuf-avatar-pickfiles' || browse_button == 'wpuf-featured_image-pickfiles' ) ? false : true ), | |
| 4657 | - urlstream_upload: true, | |
| 4658 | - file_data_name: 'wpuf_file', | |
| 4659 | - max_file_size: max_file_size + 'kb', | |
| 4660 | - url: wpuf_frontend_upload.plupload.url + '&type=' + type, | |
| 4661 | - flash_swf_url: wpuf_frontend_upload.flash_swf_url, | |
| 4662 | - filters: [{ | |
| 4663 | - title: 'Allowed Files', | |
| 4664 | - extensions: allowed_type | |
| 4665 | - }] | |
| 4666 | - }); | |
| 4667 | - | |
| 4668 | - //attach event handlers | |
| 4669 | - this.uploader.bind('Init', $.proxy(this, 'init')); | |
| 4670 | - this.uploader.bind('FilesAdded', $.proxy(this, 'added')); | |
| 4671 | - this.uploader.bind('QueueChanged', $.proxy(this, 'upload')); | |
| 4672 | - this.uploader.bind('UploadProgress', $.proxy(this, 'progress')); | |
| 4673 | - this.uploader.bind('Error', $.proxy(this, 'error')); | |
| 4674 | - this.uploader.bind('FileUploaded', $.proxy(this, 'uploaded')); | |
| 4675 | - | |
| 4676 | - this.uploader.init(); | |
| 4677 | - | |
| 4678 | - $('#' + container).on('click', 'a.attachment-delete', $.proxy(this.removeAttachment, this)); | |
| 4679 | - | |
| 4680 | - return this.uploader; | |
| 4681 | - }; | |
| 4682 | - | |
| 4683 | - WPUF_Uploader.prototype = { | |
| 4684 | - | |
| 4685 | - init: function (up, params) { | |
| 4686 | - this.showHide(); | |
| 4687 | - $('#' + this.container).prepend('<div class="wpuf-file-warning"></div>'); | |
| 4688 | - }, | |
| 4689 | - | |
| 4690 | - showHide: function () { | |
| 4691 | - | |
| 4692 | - if ( this.count >= this.max) { | |
| 4693 | - | |
| 4694 | - if ( this.count > this.max ) { | |
| 4695 | - $('#' + this.container + ' .wpuf-file-warning').html( wpuf_frontend_upload.warning ); | |
| 4696 | - } else { | |
| 4697 | - $('#' + this.container + ' .wpuf-file-warning').html( wpuf_frontend_upload.warning ); | |
| 4698 | - } | |
| 4699 | - | |
| 4700 | - $('#' + this.container).find('.file-selector').hide(); | |
| 4701 | - | |
| 4702 | - return; | |
| 4703 | - }; | |
| 4704 | - $('#' + this.container + ' .wpuf-file-warning').html( '' ); | |
| 4705 | - $('#' + this.container).find('.file-selector').show(); | |
| 4706 | - }, | |
| 4707 | - | |
| 4708 | - added: function (up, files) { | |
| 4709 | - var $container = $('#' + this.container).find('.wpuf-attachment-upload-filelist'); | |
| 4710 | - | |
| 4711 | - this.showHide(); | |
| 4712 | - | |
| 4713 | - $.each(files, function(i, file) { | |
| 4714 | - $(".wpuf-submit-button").attr("disabled", "disabled"); | |
| 4715 | - | |
| 4716 | - $container.append( | |
| 4717 | - '<div class="upload-item" id="' + file.id + '"><div class="progress progress-striped active"><div class="bar"></div></div><div class="filename original">' + | |
| 4718 | - file.name + ' (' + plupload.formatSize(file.size) + ') <b></b>' + | |
| 4719 | - '</div></div>'); | |
| 4720 | - }); | |
| 4721 | - | |
| 4722 | - up.refresh(); // Reposition Flash/Silverlight | |
| 4723 | - up.start(); | |
| 4724 | - }, | |
| 4725 | - | |
| 4726 | - upload: function (uploader) { | |
| 4727 | - this.count = uploader.files.length - this.removed_files.length ; | |
| 4728 | - this.showHide(); | |
| 4729 | - }, | |
| 4730 | - | |
| 4731 | - progress: function (up, file) { | |
| 4732 | - var item = $('#' + file.id); | |
| 4733 | - | |
| 4734 | - $('.bar', item).css({ width: file.percent + '%' }); | |
| 4735 | - $('.percent', item).html( file.percent + '%' ); | |
| 4736 | - }, | |
| 4737 | - | |
| 4738 | - error: function (up, error) { | |
| 4739 | - $('#' + this.container).find('#' + error.file.id).remove(); | |
| 4740 | - | |
| 4741 | - var msg = ''; | |
| 4742 | - switch (error.code) { | |
| 4743 | - case -600: | |
| 4744 | - msg = wpuf_frontend_upload.plupload.size_error; | |
| 4745 | - break; | |
| 4746 | - | |
| 4747 | - case -601: | |
| 4748 | - msg = wpuf_frontend_upload.plupload.type_error; | |
| 4749 | - break; | |
| 4750 | - | |
| 4751 | - default: | |
| 4752 | - msg = 'Error #' + error.code + ': ' + error.message; | |
| 4753 | - break; | |
| 4754 | - } | |
| 4755 | - | |
| 4756 | - alert(msg); | |
| 4757 | - | |
| 4758 | - this.count -= 1; | |
| 4759 | - this.showHide(); | |
| 4760 | - this.uploader.refresh(); | |
| 4761 | - }, | |
| 4762 | - | |
| 4763 | - uploaded: function (up, file, response) { | |
| 4764 | - // var res = $.parseJSON(response.response); | |
| 4765 | - var self = this; | |
| 4766 | - | |
| 4767 | - $('#' + file.id + " b").html("100%"); | |
| 4768 | - $('#' + file.id).remove(); | |
| 4769 | - | |
| 4770 | - if(response.response !== 'error') { | |
| 4771 | - | |
| 4772 | - this.perFileCount++; | |
| 4773 | - this.UploadedFiles++; | |
| 4774 | - var $container = $('#' + this.container).find('.wpuf-attachment-list'); | |
| 4775 | - $container.append(response.response); | |
| 4776 | - | |
| 4777 | - if ( this.perFileCount > this.max ) { | |
| 4778 | - var attach_id = $('.wpuf-image-wrap:last a.attachment-delete',$container).data('attach_id'); | |
| 4779 | - self.removeExtraAttachment(attach_id); | |
| 4780 | - $('.wpuf-image-wrap',$container).last().remove(); | |
| 4781 | - this.perFileCount--; | |
| 4782 | - } | |
| 4783 | - | |
| 4784 | - } else { | |
| 4785 | - alert(response.error); | |
| 4786 | - | |
| 4787 | - this.count -= 1; | |
| 4788 | - this.showHide(); | |
| 4789 | - } | |
| 4790 | - | |
| 4791 | - var uploaded = this.UploadedFiles, | |
| 4792 | - FileProgress = up.files.length, | |
| 4793 | - imageCount = $('ul.wpuf-attachment-list > li').length; | |
| 4794 | - | |
| 4795 | - if ( imageCount >= this.max ) { | |
| 4796 | - $('#' + this.container).find('.file-selector').hide(); | |
| 4797 | - } | |
| 4798 | - | |
| 4799 | - if ( FileProgress === uploaded ) { | |
| 4800 | - if ( typeof grecaptcha !== 'undefined' && !grecaptcha.getResponse().length ) { | |
| 4801 | - return; | |
| 4802 | - } | |
| 4803 | - $(".wpuf-submit-button").removeAttr("disabled"); | |
| 4804 | - } | |
| 4805 | - }, | |
| 4806 | - | |
| 4807 | - removeAttachment: function(e) { | |
| 4808 | - e.preventDefault(); | |
| 4809 | - | |
| 4810 | - var self = this, | |
| 4811 | - el = $(e.currentTarget); | |
| 4812 | - | |
| 4813 | - swal({ | |
| 4814 | - text: wpuf_frontend_upload.confirmMsg, | |
| 4815 | - type: 'warning', | |
| 4816 | - showCancelButton: true, | |
| 4817 | - confirmButtonColor: '#d54e21', | |
| 4818 | - confirmButtonText: wpuf_frontend_upload.delete_it, | |
| 4819 | - cancelButtonText: wpuf_frontend_upload.cancel_it, | |
| 4820 | - confirmButtonClass: 'btn btn-success', | |
| 4821 | - cancelButtonClass: 'btn btn-danger', | |
| 4822 | - }).then(function () { | |
| 4823 | - var data = { | |
| 4824 | - 'attach_id' : el.data('attach_id'), | |
| 4825 | - 'nonce' : wpuf_frontend_upload.nonce, | |
| 4826 | - 'action' : 'wpuf_file_del' | |
| 4827 | - }; | |
| 4828 | - self.removed_files.push(data); | |
| 4829 | - jQuery('#del_attach').val(el.data('attach_id')); | |
| 4830 | - jQuery.post(wpuf_frontend_upload.ajaxurl, data, function() { | |
| 4831 | - self.perFileCount--; | |
| 4832 | - el.parent().parent().remove(); | |
| 4833 | - | |
| 4834 | - self.count -= 1; | |
| 4835 | - self.showHide(); | |
| 4836 | - self.uploader.refresh(); | |
| 4837 | - }); | |
| 4838 | - }); | |
| 4839 | - }, | |
| 4840 | - | |
| 4841 | - removeExtraAttachment : function( attach_id ) { | |
| 4842 | - | |
| 4843 | - | |
| 4844 | - var self = this; | |
| 4845 | - | |
| 4846 | - var data = { | |
| 4847 | - 'attach_id' : attach_id, | |
| 4848 | - 'nonce' : wpuf_frontend_upload.nonce, | |
| 4849 | - 'action' : 'wpuf_file_del' | |
| 4850 | - }; | |
| 4851 | - this.removed_files.push(data); | |
| 4852 | - jQuery.post(wpuf_frontend_upload.ajaxurl, data, function() { | |
| 4853 | - self.count -= 1; | |
| 4854 | - self.showHide(); | |
| 4855 | - self.uploader.refresh(); | |
| 4856 | - }); | |
| 4857 | - } | |
| 4858 | - | |
| 4859 | - }; | |
| 4860 | -})(jQuery); | |
| 4614 | +;(function($) { | |
| 4615 | + | |
| 4616 | + /** | |
| 4617 | + * Upload handler helper | |
| 4618 | + * | |
| 4619 | + * @param string {browse_button} browse_button ID of the pickfile | |
| 4620 | + * @param string {container} container ID of the wrapper | |
| 4621 | + * @param int {max} maximum number of file uplaods | |
| 4622 | + * @param string {type} | |
| 4623 | + */ | |
| 4624 | + window.WPUF_Uploader = function (browse_button, container, max, type, allowed_type, max_file_size) { | |
| 4625 | + this.removed_files = []; | |
| 4626 | + this.container = container; | |
| 4627 | + this.browse_button = browse_button; | |
| 4628 | + this.max = max || 1; | |
| 4629 | + this.count = $('#' + container).find('.wpuf-attachment-list > li').length; //count how many items are there | |
| 4630 | + this.perFileCount = 0; //file count on each upload | |
| 4631 | + this.UploadedFiles = 0; //file count on each upload | |
| 4632 | + | |
| 4633 | + //if no element found on the page, bail out | |
| 4634 | + if( !$('#'+browse_button).length ) { | |
| 4635 | + return; | |
| 4636 | + } | |
| 4637 | + | |
| 4638 | + // enable drag option for ordering | |
| 4639 | + $( "ul.wpuf-attachment-list" ).sortable({ | |
| 4640 | + placeholder: "highlight" | |
| 4641 | + }); | |
| 4642 | + $( "ul.wpuf-attachment-list" ).disableSelection(); | |
| 4643 | + | |
| 4644 | + //instantiate the uploader | |
| 4645 | + this.uploader = new plupload.Uploader({ | |
| 4646 | + runtimes: 'html5,html4', | |
| 4647 | + browse_button: browse_button, | |
| 4648 | + container: container, | |
| 4649 | + multipart: true, | |
| 4650 | + multipart_params: { | |
| 4651 | + action: 'wpuf_upload_file', | |
| 4652 | + form_id: $( '#' + browse_button ).data('form_id') | |
| 4653 | + }, | |
| 4654 | + max_file_count : 2, | |
| 4655 | + multiple_queues: false, | |
| 4656 | + multi_selection: ( ( browse_button == 'wpuf-avatar-pickfiles' || browse_button == 'wpuf-featured_image-pickfiles' ) ? false : true ), | |
| 4657 | + urlstream_upload: true, | |
| 4658 | + file_data_name: 'wpuf_file', | |
| 4659 | + max_file_size: max_file_size + 'kb', | |
| 4660 | + url: wpuf_frontend_upload.plupload.url + '&type=' + type, | |
| 4661 | + flash_swf_url: wpuf_frontend_upload.flash_swf_url, | |
| 4662 | + filters: [{ | |
| 4663 | + title: 'Allowed Files', | |
| 4664 | + extensions: allowed_type | |
| 4665 | + }] | |
| 4666 | + }); | |
| 4667 | + | |
| 4668 | + //attach event handlers | |
| 4669 | + this.uploader.bind('Init', $.proxy(this, 'init')); | |
| 4670 | + this.uploader.bind('FilesAdded', $.proxy(this, 'added')); | |
| 4671 | + this.uploader.bind('QueueChanged', $.proxy(this, 'upload')); | |
| 4672 | + this.uploader.bind('UploadProgress', $.proxy(this, 'progress')); | |
| 4673 | + this.uploader.bind('Error', $.proxy(this, 'error')); | |
| 4674 | + this.uploader.bind('FileUploaded', $.proxy(this, 'uploaded')); | |
| 4675 | + | |
| 4676 | + this.uploader.init(); | |
| 4677 | + | |
| 4678 | + $('#' + container).on('click', 'a.attachment-delete', $.proxy(this.removeAttachment, this)); | |
| 4679 | + | |
| 4680 | + return this.uploader; | |
| 4681 | + }; | |
| 4682 | + | |
| 4683 | + WPUF_Uploader.prototype = { | |
| 4684 | + | |
| 4685 | + init: function (up, params) { | |
| 4686 | + this.showHide(); | |
| 4687 | + $('#' + this.container).prepend('<div class="wpuf-file-warning"></div>'); | |
| 4688 | + }, | |
| 4689 | + | |
| 4690 | + showHide: function () { | |
| 4691 | + | |
| 4692 | + if ( this.count >= this.max) { | |
| 4693 | + | |
| 4694 | + if ( this.count > this.max ) { | |
| 4695 | + $('#' + this.container + ' .wpuf-file-warning').html( wpuf_frontend_upload.warning ); | |
| 4696 | + } else { | |
| 4697 | + $('#' + this.container + ' .wpuf-file-warning').html( wpuf_frontend_upload.warning ); | |
| 4698 | + } | |
| 4699 | + | |
| 4700 | + $('#' + this.container).find('.file-selector').hide(); | |
| 4701 | + | |
| 4702 | + return; | |
| 4703 | + }; | |
| 4704 | + $('#' + this.container + ' .wpuf-file-warning').html( '' ); | |
| 4705 | + $('#' + this.container).find('.file-selector').show(); | |
| 4706 | + }, | |
| 4707 | + | |
| 4708 | + added: function (up, files) { | |
| 4709 | + var $container = $('#' + this.container).find('.wpuf-attachment-upload-filelist'); | |
| 4710 | + | |
| 4711 | + this.showHide(); | |
| 4712 | + | |
| 4713 | + $.each(files, function(i, file) { | |
| 4714 | + $(".wpuf-submit-button").attr("disabled", "disabled"); | |
| 4715 | + | |
| 4716 | + $container.append( | |
| 4717 | + '<div class="upload-item" id="' + file.id + '"><div class="progress progress-striped active"><div class="bar"></div></div><div class="filename original">' + | |
| 4718 | + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b>' + | |
| 4719 | + '</div></div>'); | |
| 4720 | + }); | |
| 4721 | + | |
| 4722 | + up.refresh(); // Reposition Flash/Silverlight | |
| 4723 | + up.start(); | |
| 4724 | + }, | |
| 4725 | + | |
| 4726 | + upload: function (uploader) { | |
| 4727 | + this.count = uploader.files.length - this.removed_files.length ; | |
| 4728 | + this.showHide(); | |
| 4729 | + }, | |
| 4730 | + | |
| 4731 | + progress: function (up, file) { | |
| 4732 | + var item = $('#' + file.id); | |
| 4733 | + | |
| 4734 | + $('.bar', item).css({ width: file.percent + '%' }); | |
| 4735 | + $('.percent', item).html( file.percent + '%' ); | |
| 4736 | + }, | |
| 4737 | + | |
| 4738 | + error: function (up, error) { | |
| 4739 | + $('#' + this.container).find('#' + error.file.id).remove(); | |
| 4740 | + | |
| 4741 | + var msg = ''; | |
| 4742 | + switch (error.code) { | |
| 4743 | + case -600: | |
| 4744 | + msg = wpuf_frontend_upload.plupload.size_error; | |
| 4745 | + break; | |
| 4746 | + | |
| 4747 | + case -601: | |
| 4748 | + msg = wpuf_frontend_upload.plupload.type_error; | |
| 4749 | + break; | |
| 4750 | + | |
| 4751 | + default: | |
| 4752 | + msg = 'Error #' + error.code + ': ' + error.message; | |
| 4753 | + break; | |
| 4754 | + } | |
| 4755 | + | |
| 4756 | + alert(msg); | |
| 4757 | + | |
| 4758 | + this.count -= 1; | |
| 4759 | + this.showHide(); | |
| 4760 | + this.uploader.refresh(); | |
| 4761 | + }, | |
| 4762 | + | |
| 4763 | + uploaded: function (up, file, response) { | |
| 4764 | + // var res = $.parseJSON(response.response); | |
| 4765 | + var self = this; | |
| 4766 | + | |
| 4767 | + $('#' + file.id + " b").html("100%"); | |
| 4768 | + $('#' + file.id).remove(); | |
| 4769 | + | |
| 4770 | + if(response.response !== 'error') { | |
| 4771 | + | |
| 4772 | + this.perFileCount++; | |
| 4773 | + this.UploadedFiles++; | |
| 4774 | + var $container = $('#' + this.container).find('.wpuf-attachment-list'); | |
| 4775 | + $container.append(response.response); | |
| 4776 | + | |
| 4777 | + if ( this.perFileCount > this.max ) { | |
| 4778 | + var attach_id = $('.wpuf-image-wrap:last a.attachment-delete',$container).data('attach_id'); | |
| 4779 | + self.removeExtraAttachment(attach_id); | |
| 4780 | + $('.wpuf-image-wrap',$container).last().remove(); | |
| 4781 | + this.perFileCount--; | |
| 4782 | + } | |
| 4783 | + | |
| 4784 | + } else { | |
| 4785 | + alert(response.error); | |
| 4786 | + | |
| 4787 | + this.count -= 1; | |
| 4788 | + this.showHide(); | |
| 4789 | + } | |
| 4790 | + | |
| 4791 | + var uploaded = this.UploadedFiles, | |
| 4792 | + FileProgress = up.files.length, | |
| 4793 | + imageCount = $('ul.wpuf-attachment-list > li').length; | |
| 4794 | + | |
| 4795 | + if ( imageCount >= this.max ) { | |
| 4796 | + $('#' + this.container).find('.file-selector').hide(); | |
| 4797 | + } | |
| 4798 | + | |
| 4799 | + if ( FileProgress === uploaded ) { | |
| 4800 | + if ( typeof grecaptcha !== 'undefined' && !grecaptcha.getResponse().length ) { | |
| 4801 | + return; | |
| 4802 | + } | |
| 4803 | + $(".wpuf-submit-button").removeAttr("disabled"); | |
| 4804 | + } | |
| 4805 | + }, | |
| 4806 | + | |
| 4807 | + removeAttachment: function(e) { | |
| 4808 | + e.preventDefault(); | |
| 4809 | + | |
| 4810 | + var self = this, | |
| 4811 | + el = $(e.currentTarget); | |
| 4812 | + | |
| 4813 | + swal({ | |
| 4814 | + text: wpuf_frontend_upload.confirmMsg, | |
| 4815 | + type: 'warning', | |
| 4816 | + showCancelButton: true, | |
| 4817 | + confirmButtonColor: '#d54e21', | |
| 4818 | + confirmButtonText: wpuf_frontend_upload.delete_it, | |
| 4819 | + cancelButtonText: wpuf_frontend_upload.cancel_it, | |
| 4820 | + confirmButtonClass: 'btn btn-success', | |
| 4821 | + cancelButtonClass: 'btn btn-danger', | |
| 4822 | + }).then(function () { | |
| 4823 | + var data = { | |
| 4824 | + 'attach_id' : el.data('attach_id'), | |
| 4825 | + 'nonce' : wpuf_frontend_upload.nonce, | |
| 4826 | + 'action' : 'wpuf_file_del' | |
| 4827 | + }; | |
| 4828 | + self.removed_files.push(data); | |
| 4829 | + jQuery('#del_attach').val(el.data('attach_id')); | |
| 4830 | + jQuery.post(wpuf_frontend_upload.ajaxurl, data, function() { | |
| 4831 | + self.perFileCount--; | |
| 4832 | + el.parent().parent().remove(); | |
| 4833 | + | |
| 4834 | + self.count -= 1; | |
| 4835 | + self.showHide(); | |
| 4836 | + self.uploader.refresh(); | |
| 4837 | + }); | |
| 4838 | + }); | |
| 4839 | + }, | |
| 4840 | + | |
| 4841 | + removeExtraAttachment : function( attach_id ) { | |
| 4842 | + | |
| 4843 | + | |
| 4844 | + var self = this; | |
| 4845 | + | |
| 4846 | + var data = { | |
| 4847 | + 'attach_id' : attach_id, | |
| 4848 | + 'nonce' : wpuf_frontend_upload.nonce, | |
| 4849 | + 'action' : 'wpuf_file_del' | |
| 4850 | + }; | |
| 4851 | + this.removed_files.push(data); | |
| 4852 | + jQuery.post(wpuf_frontend_upload.ajaxurl, data, function() { | |
| 4853 | + self.count -= 1; | |
| 4854 | + self.showHide(); | |
| 4855 | + self.uploader.refresh(); | |
| 4856 | + }); | |
| 4857 | + } | |
| 4858 | + | |
| 4859 | + }; | |
| 4860 | +})(jQuery); | |