| @@ -1,146 +1,159 @@ | ||
| 1 | -// eslint-disable-next-line no-unused-vars | |
| 2 | -// import config from '@config'; | |
| 3 | -// import '@styles/admin'; | |
| 4 | -// Uncomment the following line if needed: | |
| 5 | -// import 'airbnb-browser-shims'; | |
| 6 | - | |
| 7 | -// Your code goes here ... | |
| 8 | - | |
| 9 | -// enable submit and deactivate button while clicking on survey list items | |
| 10 | -(function ($) { | |
| 11 | - | |
| 12 | - var publishSliderButtonFunc = function ( view = false ) { | |
| 13 | - $('.depicter-publish-slider:not([disabled])').on('click', function () { | |
| 14 | - var $this = $(this); | |
| 15 | - $this.find('.btn-label').hide(); | |
| 16 | - $this.find('.depicter-state-icon').show(); | |
| 17 | - var sliderID = $this.parents('tbody,#elementor-controls').find('select').val(); | |
| 18 | - var data = { | |
| 19 | - action: 'depicter/document/store', | |
| 20 | - ID: sliderID.replace( '#', ''), | |
| 21 | - status: 'published' | |
| 22 | - }; | |
| 23 | - | |
| 24 | - $.ajax({ | |
| 25 | - url: depicterParams.ajaxUrl, | |
| 26 | - type: 'POST', | |
| 27 | - data: data, | |
| 28 | - headers: { | |
| 29 | - 'X-DEPICTER-CSRF': depicterParams.token | |
| 30 | - } | |
| 31 | - }).done(function (response) { | |
| 32 | - if (response.hits) { | |
| 33 | - $this.attr('disabled', true); | |
| 34 | - $this.parents('.depicter-notice-btns').siblings('.depicter-notice-txts').hide(); | |
| 35 | - $this.find('.btn-label').html(depicterParams.publishedText); | |
| 36 | - $this.find('.btn-label').show(); | |
| 37 | - $this.find('.depicter-state-icon').hide(); | |
| 38 | - if (view) { | |
| 39 | - view.$el.find('.depicter-notice-wrapper').remove(); | |
| 40 | - } else { | |
| 41 | - $('.fl-module-module').find('.depicter-notice-wrapper').remove(); | |
| 42 | - } | |
| 43 | - } else { | |
| 44 | - $this.find('.btn-label').show(); | |
| 45 | - $this.find('.depicter-state-icon').hide(); | |
| 46 | - } | |
| 47 | - }); | |
| 48 | - | |
| 49 | - }); | |
| 50 | - } | |
| 51 | - | |
| 52 | - var editSliderButtonFunc = function () { | |
| 53 | - $('.depicter-edit-slider').on('click', function(){ | |
| 54 | - var sliderID = $(this).parents('tbody, #elementor-controls').find('select').val(); | |
| 55 | - var editorUrl = depicterParams.editorUrl.replace( 'document=1', 'document=' + sliderID.replace('#', '') ); | |
| 56 | - window.open( editorUrl ); | |
| 57 | - }); | |
| 58 | - } | |
| 59 | - | |
| 60 | - $(document).ready(function () { | |
| 61 | - | |
| 62 | - var $feedbackContainer = $('.depicter-survey-container'); | |
| 63 | - // show the popup survey | |
| 64 | - $('#deactivate-depicter').on('click', function (e) { | |
| 65 | - e.preventDefault(); | |
| 66 | - $feedbackContainer.addClass('show'); | |
| 67 | - }); | |
| 68 | - | |
| 69 | - // close the popup survey | |
| 70 | - $feedbackContainer.on('click', function(e) { | |
| 71 | - if ((!$(e.target).parents('.depicter-survey-list').length && !$(e.target).is('.depicter-survey-list')) || $(e.target).is('.depicter-close')) { | |
| 72 | - $feedbackContainer.removeClass('show'); | |
| 73 | - } | |
| 74 | - }); | |
| 75 | - | |
| 76 | - // enable submit button if one reason clicked | |
| 77 | - $feedbackContainer.find('input[name="dep_deactivation_reason"]').each(function () { | |
| 78 | - $(this).on('click', function () { | |
| 79 | - $feedbackContainer.find('.depicter-submit').attr('disabled', false); | |
| 80 | - }); | |
| 81 | - }); | |
| 82 | - | |
| 83 | - var ajaxDeactivationRequest = function (reason, userDescriptionText) { | |
| 84 | - $.ajax({ | |
| 85 | - url: depDeactivationParams.ajaxUrl, | |
| 86 | - method: 'POST', | |
| 87 | - data: { | |
| 88 | - _wpnonce: $feedbackContainer.find('#_wpnonce').val(), | |
| 89 | - action: 'depicter/deactivate/feedback', | |
| 90 | - issueRelatesTo: reason, | |
| 91 | - userDescription: userDescriptionText, | |
| 92 | - }, | |
| 93 | - }).done(function (res) { | |
| 94 | - location.href = $('#deactivate-depicter').attr('href'); | |
| 95 | - }); | |
| 96 | - }; | |
| 97 | - | |
| 98 | - // send deactivation feedback | |
| 99 | - $feedbackContainer.find('.depicter-submit').on('click', function () { | |
| 100 | - var $selectedRadioInput = $feedbackContainer.find('input[name="dep_deactivation_reason"]:checked'), | |
| 101 | - reason = $selectedRadioInput.val(), | |
| 102 | - userDescriptionText = $selectedRadioInput.parent('div').find('input[type="text"').length ? $selectedRadioInput.parent('div').find('input[type="text"').val() : ''; | |
| 103 | - ajaxDeactivationRequest(reason, userDescriptionText); | |
| 104 | - $(this).parent('.depicter-button-wrapper').addClass('loading'); | |
| 105 | - }); | |
| 106 | - | |
| 107 | - // deactivate plugin if click on skip | |
| 108 | - $feedbackContainer.find('.depicter-skip').on('click', function() { | |
| 109 | - ajaxDeactivationRequest('skip', ''); | |
| 110 | - $(this).parent('.depicter-button-wrapper').addClass('loading skipped'); | |
| 111 | - location.href = $('#deactivate-depicter').attr('href'); | |
| 112 | - }); | |
| 113 | - | |
| 114 | - // ─── Beaver Builder Js ─────────────────────────────────────────── | |
| 115 | - | |
| 116 | - var beaverBuilderControls = function () { | |
| 117 | - var $tbody = $('.fl-field-control-wrapper select[name="document_id"]').parents('tbody'); | |
| 118 | - | |
| 119 | - $tbody.find(' > tr:not(#fl-field-document_id)').hide(); | |
| 120 | - var sliderID = $('.fl-field-control-wrapper select[name="document_id"]').val(); | |
| 121 | - $('#fl-field-slider_control_buttons_' + sliderID.replace( '#', '')).show(); | |
| 122 | - | |
| 123 | - editSliderButtonFunc(); | |
| 124 | - | |
| 125 | - publishSliderButtonFunc(); | |
| 126 | - } | |
| 127 | - | |
| 128 | - if (typeof FLBuilder != 'undefined') { | |
| 129 | - $('body').on('fl-builder.settings-form-init', function () { | |
| 130 | - $('.fl-field-control-wrapper select[name="document_id"]').on('change', function () { | |
| 131 | - beaverBuilderControls(); | |
| 132 | - }); | |
| 133 | - beaverBuilderControls(); | |
| 134 | - }); | |
| 135 | - } | |
| 136 | - | |
| 137 | - }); | |
| 138 | - | |
| 139 | - if ( window.elementor ) { | |
| 140 | - elementor.hooks.addAction( 'panel/open_editor/widget', function( panel, model, view ) { | |
| 141 | - editSliderButtonFunc(); | |
| 142 | - publishSliderButtonFunc(view); | |
| 143 | - }); | |
| 144 | - } | |
| 145 | - | |
| 146 | -})(jQuery); | |
| 1 | +// eslint-disable-next-line no-unused-vars | |
| 2 | +// import config from '@config'; | |
| 3 | +// import '@styles/admin'; | |
| 4 | +// Uncomment the following line if needed: | |
| 5 | +// import 'airbnb-browser-shims'; | |
| 6 | + | |
| 7 | +// Your code goes here ... | |
| 8 | + | |
| 9 | +// enable submit and deactivate button while clicking on survey list items | |
| 10 | +(function ($) { | |
| 11 | + | |
| 12 | + var publishSliderButtonFunc = function (view = false) { | |
| 13 | + $('.depicter-publish-slider:not([disabled])').off('click'); | |
| 14 | + $('.depicter-publish-slider:not([disabled])').on('click', function () { | |
| 15 | + var $this = $(this); | |
| 16 | + $this.find('.btn-label').hide(); | |
| 17 | + $this.find('.depicter-state-icon').show(); | |
| 18 | + var sliderID = $this.data('document-id') || $this.parents('tbody,#elementor-controls').find('select').val().replace( '#', ''); | |
| 19 | + var data = { | |
| 20 | + action: 'depicter/document/store', | |
| 21 | + ID: sliderID, | |
| 22 | + status: 'published' | |
| 23 | + }; | |
| 24 | + | |
| 25 | + $.ajax({ | |
| 26 | + url: depicterParams.ajaxUrl, | |
| 27 | + type: 'POST', | |
| 28 | + data: data, | |
| 29 | + headers: { | |
| 30 | + 'X-DEPICTER-CSRF': depicterParams.token | |
| 31 | + } | |
| 32 | + }).done(function (response) { | |
| 33 | + if (response.hits) { | |
| 34 | + $this.attr('disabled', true); | |
| 35 | + $this.parents('.depicter-notice-btns').siblings('.depicter-notice-txts').hide(); | |
| 36 | + $this.find('.btn-label').html(depicterParams.publishedText); | |
| 37 | + $this.find('.btn-label').show(); | |
| 38 | + $this.find('.depicter-state-icon').hide(); | |
| 39 | + if (view) { | |
| 40 | + view.$el.find('.depicter-notice-wrapper').remove(); | |
| 41 | + } else { | |
| 42 | + $('.fl-module-module').find('.depicter-notice-wrapper').remove(); | |
| 43 | + } | |
| 44 | + } else { | |
| 45 | + $this.find('.btn-label').show(); | |
| 46 | + $this.find('.depicter-state-icon').hide(); | |
| 47 | + } | |
| 48 | + }); | |
| 49 | + | |
| 50 | + }); | |
| 51 | + } | |
| 52 | + | |
| 53 | + var editSliderButtonFunc = function () { | |
| 54 | + $('.depicter-edit-slider').off('click'); | |
| 55 | + $('.depicter-edit-slider').on('click', function () { | |
| 56 | + var sliderID = $(this).data('document-id') || $(this).parents('tbody, #elementor-controls').find('select').val().replace('#', ''); | |
| 57 | + var editorUrl = depicterParams.editorUrl.replace( 'document=1', 'document=' + sliderID ); | |
| 58 | + window.open( editorUrl ); | |
| 59 | + }); | |
| 60 | + } | |
| 61 | + | |
| 62 | + $(document).ready(function () { | |
| 63 | + | |
| 64 | + var $feedbackContainer = $('.depicter-survey-container'); | |
| 65 | + // show the popup survey | |
| 66 | + $('#deactivate-depicter').on('click', function (e) { | |
| 67 | + e.preventDefault(); | |
| 68 | + $feedbackContainer.addClass('show'); | |
| 69 | + }); | |
| 70 | + | |
| 71 | + // close the popup survey | |
| 72 | + $feedbackContainer.on('click', function(e) { | |
| 73 | + if ((!$(e.target).parents('.depicter-survey-list').length && !$(e.target).is('.depicter-survey-list')) || $(e.target).is('.depicter-close')) { | |
| 74 | + $feedbackContainer.removeClass('show'); | |
| 75 | + } | |
| 76 | + }); | |
| 77 | + | |
| 78 | + // enable submit button if one reason clicked | |
| 79 | + $feedbackContainer.find('input[name="dep_deactivation_reason"]').each(function () { | |
| 80 | + $(this).on('click', function () { | |
| 81 | + $feedbackContainer.find('.depicter-submit').attr('disabled', false); | |
| 82 | + }); | |
| 83 | + }); | |
| 84 | + | |
| 85 | + var ajaxDeactivationRequest = function (reason, userDescriptionText) { | |
| 86 | + $.ajax({ | |
| 87 | + url: depDeactivationParams.ajaxUrl, | |
| 88 | + method: 'POST', | |
| 89 | + data: { | |
| 90 | + _wpnonce: $feedbackContainer.find('#_wpnonce').val(), | |
| 91 | + action: 'depicter/deactivate/feedback', | |
| 92 | + issueRelatesTo: reason, | |
| 93 | + userDescription: userDescriptionText, | |
| 94 | + }, | |
| 95 | + }).done(function (res) { | |
| 96 | + location.href = $('#deactivate-depicter').attr('href'); | |
| 97 | + }); | |
| 98 | + }; | |
| 99 | + | |
| 100 | + // send deactivation feedback | |
| 101 | + $feedbackContainer.find('.depicter-submit').on('click', function () { | |
| 102 | + var $selectedRadioInput = $feedbackContainer.find('input[name="dep_deactivation_reason"]:checked'), | |
| 103 | + reason = $selectedRadioInput.val(), | |
| 104 | + userDescriptionText = $selectedRadioInput.parent('div').find('input[type="text"').length ? $selectedRadioInput.parent('div').find('input[type="text"').val() : ''; | |
| 105 | + ajaxDeactivationRequest(reason, userDescriptionText); | |
| 106 | + $(this).parent('.depicter-button-wrapper').addClass('loading'); | |
| 107 | + }); | |
| 108 | + | |
| 109 | + // deactivate plugin if click on skip | |
| 110 | + $feedbackContainer.find('.depicter-skip').on('click', function() { | |
| 111 | + ajaxDeactivationRequest('skip', ''); | |
| 112 | + $(this).parent('.depicter-button-wrapper').addClass('loading skipped'); | |
| 113 | + location.href = $('#deactivate-depicter').attr('href'); | |
| 114 | + }); | |
| 115 | + | |
| 116 | + // ─── Beaver Builder Js ─────────────────────────────────────────── | |
| 117 | + | |
| 118 | + var beaverBuilderControls = function () { | |
| 119 | + var $tbody = $('.fl-field-control-wrapper select[name="document_id"]').parents('tbody'); | |
| 120 | + | |
| 121 | + $tbody.find(' > tr:not(#fl-field-document_id)').hide(); | |
| 122 | + var sliderID = $('.fl-field-control-wrapper select[name="document_id"]').val(); | |
| 123 | + if (sliderID) { | |
| 124 | + $('#fl-field-slider_control_buttons_' + sliderID.replace( '#', '')).show(); | |
| 125 | + } | |
| 126 | + | |
| 127 | + editSliderButtonFunc(); | |
| 128 | + | |
| 129 | + publishSliderButtonFunc(); | |
| 130 | + } | |
| 131 | + | |
| 132 | + if (typeof FLBuilder != 'undefined') { | |
| 133 | + $('body').on('fl-builder.settings-form-init', function () { | |
| 134 | + $('.fl-field-control-wrapper select[name="document_id"]').on('change', function () { | |
| 135 | + beaverBuilderControls(); | |
| 136 | + }); | |
| 137 | + beaverBuilderControls(); | |
| 138 | + }); | |
| 139 | + } | |
| 140 | + | |
| 141 | + if (typeof CtBuilderAjax != 'undefined') { | |
| 142 | + $('#oxygen-sidebar-control-panel-basic-styles').bind('DOMSubtreeModified', function(){ | |
| 143 | + if ( $(this).find('.depicter-edit-slider').length ) { | |
| 144 | + editSliderButtonFunc(); | |
| 145 | + publishSliderButtonFunc(); | |
| 146 | + } | |
| 147 | + }); | |
| 148 | + } | |
| 149 | + | |
| 150 | + }); | |
| 151 | + | |
| 152 | + if ( window.elementor ) { | |
| 153 | + elementor.hooks.addAction( 'panel/open_editor/widget', function( panel, model, view ) { | |
| 154 | + editSliderButtonFunc(); | |
| 155 | + publishSliderButtonFunc(view); | |
| 156 | + }); | |
| 157 | + } | |
| 158 | + | |
| 159 | +})(jQuery); | |