global.js
103 lines
| 1 | // serialize the form to JSON |
| 2 | jQuery.fn.serializeObject=function(){"use strict";var a={},b=function(b,c){var d=a[c.name];"undefined"!=typeof d&&d!==null?Array.isArray(d)?d.push(c.value):a[c.name]=[d,c.value]:a[c.name]=c.value};return jQuery.each(this.serializeArray(),b),a}; |
| 3 | (function( $ ) { |
| 4 | "use strict"; |
| 5 | |
| 6 | $(function(){ |
| 7 | var $feedback_popup = $('.aux-feedback-notice'), |
| 8 | $theme_menu = $('.toplevel_page_auxin-welcome'); |
| 9 | |
| 10 | // skip if feedback popup is not present |
| 11 | if( ! $feedback_popup.length ){ |
| 12 | return; |
| 13 | } |
| 14 | |
| 15 | // apply animation and position to popup |
| 16 | var $feedback_popup_top_offset = $theme_menu.length ? $theme_menu.offset().top -20 : '130'; |
| 17 | $theme_menu.addClass('aux-highlight-focus'); |
| 18 | $feedback_popup.css('top', $feedback_popup_top_offset ).removeClass('aux-not-animated'); |
| 19 | |
| 20 | // highlight selected rating |
| 21 | $feedback_popup.find('.aux-rate-cell').on( 'click', function(){ |
| 22 | $('.aux-feedback-notice .aux-rate-cell').removeClass('checked'); |
| 23 | $(this).addClass('checked'); |
| 24 | }); |
| 25 | |
| 26 | $feedback_popup.find('input[name="theme_rate"]').on('change', function(){ |
| 27 | var rateValue = $(this).val(), |
| 28 | $status_progress = $('.aux-sending-status'), |
| 29 | $conditional_sections = $('.aux-conditional-section'); |
| 30 | |
| 31 | $status_progress.removeClass('aux-hide'); |
| 32 | $conditional_sections.addClass('aux-disappear'); |
| 33 | |
| 34 | $.ajax({ |
| 35 | url: auxin.ajaxurl, |
| 36 | type: "post", |
| 37 | data: { |
| 38 | form : $('.aux-popup-feedback-form').serializeObject(), |
| 39 | action : 'send_feedback' // the ajax handler, |
| 40 | } |
| 41 | }).done( function( response ){ |
| 42 | |
| 43 | if ( response.success ) { |
| 44 | $status_progress.addClass('aux-hide'); |
| 45 | |
| 46 | if ( rateValue > 8 ) { |
| 47 | $('.aux-rate-on-market').removeClass('aux-disappear'); |
| 48 | } else { |
| 49 | $('.aux-feedback-detail').removeClass('aux-disappear'); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | }); |
| 54 | }); |
| 55 | |
| 56 | $('.aux-close-form:not(.btn-submit)').on('click', function(){ |
| 57 | |
| 58 | $.ajax({ |
| 59 | url: auxin.ajaxurl, |
| 60 | type: 'post', |
| 61 | data: { |
| 62 | action: 'aux-remove-feedback-notice', |
| 63 | form : $('.aux-popup-feedback-form').serializeObject(), |
| 64 | } |
| 65 | }).done(function(response){ |
| 66 | $('.aux-feedback-notice').remove(); |
| 67 | }); |
| 68 | |
| 69 | }); |
| 70 | |
| 71 | $('.aux-close-form.btn-submit').on('click', function(){ |
| 72 | |
| 73 | $.ajax({ |
| 74 | url: auxin.ajaxurl, |
| 75 | type: 'post', |
| 76 | data: { |
| 77 | action: 'send_feedback', |
| 78 | form : $('.aux-popup-feedback-form').serializeObject(), |
| 79 | } |
| 80 | }).done(function(response){ |
| 81 | $('.aux-feedback-notice').remove(); |
| 82 | }); |
| 83 | |
| 84 | }); |
| 85 | |
| 86 | $('.aux-remind-later').on('click', function(){ |
| 87 | |
| 88 | $.ajax({ |
| 89 | url: auxin.ajaxurl, |
| 90 | type: 'post', |
| 91 | data: { |
| 92 | action: 'remind_feedback', |
| 93 | form : $('.aux-popup-feedback-form').serializeObject() |
| 94 | } |
| 95 | }); |
| 96 | |
| 97 | $('.aux-feedback-notice').remove(); |
| 98 | |
| 99 | }); |
| 100 | }) |
| 101 | |
| 102 | })( jQuery ); |
| 103 |