settings.js
216 lines
| 1 | function embedPressRemoveURLParameter(url, parameter) { |
| 2 | //prefer to use l.search if you have a location/link object |
| 3 | let urlparts = url.split('?'); |
| 4 | if (urlparts.length >= 2) { |
| 5 | |
| 6 | let prefix = encodeURIComponent(parameter) + '='; |
| 7 | let pars = urlparts[1].split(/[&;]/g); |
| 8 | |
| 9 | //reverse iteration as may be destructive |
| 10 | for (var i = pars.length; i-- > 0;) { |
| 11 | //idiom for string.startsWith |
| 12 | if (pars[i].lastIndexOf(prefix, 0) !== -1) { |
| 13 | pars.splice(i, 1); |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | return urlparts[0] + (pars.length > 0 ? '?' + pars.join('&') : ''); |
| 18 | } |
| 19 | return url; |
| 20 | } |
| 21 | jQuery(document).ready( function($){ |
| 22 | |
| 23 | // Sidebar Menu Toggle |
| 24 | $('.sidebar__dropdown .sidebar__link--toggler').on('click', function(e) { |
| 25 | e.preventDefault(); |
| 26 | let $this = $(this); |
| 27 | let $sidebarItem = $('.sidebar__item'); |
| 28 | $sidebarItem.removeClass('show'); |
| 29 | $this.parent().addClass('show'); |
| 30 | if($this.siblings('.dropdown__menu').hasClass('show')){ |
| 31 | $this.siblings('.dropdown__menu').removeClass('show'); |
| 32 | $this.siblings('.dropdown__menu').slideUp(); |
| 33 | $sidebarItem.removeClass('show'); |
| 34 | }else{ |
| 35 | $('.dropdown__menu.show').slideUp().removeClass('show'); |
| 36 | $this.siblings('.dropdown__menu').addClass('show'); |
| 37 | // $('.sidebar__menu .dropdown__menu.show').slideUp(); |
| 38 | $this.siblings('.dropdown__menu').slideDown(); |
| 39 | } |
| 40 | }) |
| 41 | |
| 42 | // Sidebar Toggle |
| 43 | $('.sidebar__toggler').on('click', function(e) { |
| 44 | e.preventDefault(); |
| 45 | $(this).siblings('.sidebar__menu').slideToggle(); |
| 46 | }) |
| 47 | |
| 48 | // Logo Remove |
| 49 | $('#yt_preview__remove').on('click', function(e) { |
| 50 | e.preventDefault(); |
| 51 | $('.preview__logo__input').val(''); |
| 52 | $('#yt_logo_url').val(''); |
| 53 | $('#yt_logo_id').val(''); |
| 54 | $("#yt_logo_preview").attr('src', ''); |
| 55 | $('.preview__box img').attr('src', ''); |
| 56 | $("#yt_logo__upload__preview").hide(); |
| 57 | $("#yt_logo_upload_wrap").show(); |
| 58 | }) |
| 59 | |
| 60 | // Logo Controller |
| 61 | let rangeSlider = function(){ |
| 62 | let slider = $('.logo__adjust__controller__inputs'), |
| 63 | previewImg = $('.preview__logo'), |
| 64 | opRange = $('.opacity__range'), |
| 65 | xRange = $('.x__range'), |
| 66 | yRange = $('.y__range'), |
| 67 | value = $('.range__value'); |
| 68 | |
| 69 | slider.each(function(){ |
| 70 | |
| 71 | value.each(function(){ |
| 72 | var value = $(this).prev().attr('value'); |
| 73 | $(this).html(value); |
| 74 | }); |
| 75 | |
| 76 | opRange.on('input', function(){ |
| 77 | $(this).next(value).val(this.value); |
| 78 | console.log(this.value / 100); |
| 79 | previewImg.css('opacity', this.value / 100); |
| 80 | }); |
| 81 | xRange.on('input', function(){ |
| 82 | $(this).next(value).val(this.value); |
| 83 | previewImg.css('right', this.value + "%"); |
| 84 | }); |
| 85 | yRange.on('input', function(){ |
| 86 | $(this).next(value).val(this.value); |
| 87 | previewImg.css('bottom', this.value + "%"); |
| 88 | }); |
| 89 | }); |
| 90 | }; |
| 91 | |
| 92 | rangeSlider(); |
| 93 | |
| 94 | $('.template__wrapper .input__switch input').on('click', function() { |
| 95 | $(this).parents('.form__control__wrap').children('.logo__adjust__wrap').slideToggle(); |
| 96 | }) |
| 97 | |
| 98 | let proFeatureAlert = function() { |
| 99 | |
| 100 | $(document).on('click', '.isPro', function () { |
| 101 | $(this).siblings('.pro__alert__wrap').fadeIn(); |
| 102 | }); |
| 103 | |
| 104 | $(document).on('click', '.pro__alert__card .button', function (e) { |
| 105 | e.preventDefault(); |
| 106 | $(this).parents('.pro__alert__wrap').fadeOut(); |
| 107 | }); |
| 108 | } |
| 109 | |
| 110 | proFeatureAlert(); |
| 111 | |
| 112 | // custom logo upload for youtube |
| 113 | $(document).on('click', '#yt_logo_upload_wrap', function(e){ |
| 114 | e.preventDefault(); |
| 115 | let curElement = $('.preview__logo'); |
| 116 | let $yt_logo_upload_wrap = $("#yt_logo_upload_wrap"); |
| 117 | let $yt_logo__upload__preview = $("#yt_logo__upload__preview"); |
| 118 | let $yt_logo_preview = $("#yt_logo_preview"); |
| 119 | let $yt_logo_url = $('#yt_logo_url'); |
| 120 | let $yt_logo_id = $('#yt_logo_id'); |
| 121 | let button = $(this), |
| 122 | yt_logo_uploader = wp.media({ |
| 123 | title: 'Custom Logo', |
| 124 | library : { |
| 125 | uploadedTo : wp.media.view.settings.post.id, |
| 126 | type : 'image' |
| 127 | }, |
| 128 | button: { |
| 129 | text: 'Use this image' |
| 130 | }, |
| 131 | multiple: false |
| 132 | }).on('select', function() { |
| 133 | let attachment = yt_logo_uploader.state().get('selection').first().toJSON(); |
| 134 | if (attachment && attachment.id && attachment.url){ |
| 135 | $yt_logo_upload_wrap.hide(); |
| 136 | $yt_logo_url.val(attachment.url); |
| 137 | $yt_logo_id.val(attachment.id); |
| 138 | $yt_logo_preview.attr('src', attachment.url); |
| 139 | $yt_logo__upload__preview.show(); |
| 140 | curElement.attr('src', attachment.url); |
| 141 | }else{ |
| 142 | console.log('something went wrong using selected image'); |
| 143 | } |
| 144 | }).open(); |
| 145 | }); |
| 146 | |
| 147 | |
| 148 | // Elements |
| 149 | $(document).on('change', '.element-check', function (e) { |
| 150 | let $input = $(this); |
| 151 | $.ajax({ |
| 152 | url: ajaxurl, |
| 153 | type: 'post', |
| 154 | data: { |
| 155 | action: 'embedpress_elements_action', |
| 156 | _wpnonce: embedpressObj.nonce, |
| 157 | element_type: $input.data('type'), |
| 158 | element_name: $input.data('name'), |
| 159 | checked: $input.is(":checked"), |
| 160 | }, |
| 161 | success: function(response) { |
| 162 | if (response && response.success){ |
| 163 | showSuccessMessage(); |
| 164 | }else{ |
| 165 | showErrorMessage(); |
| 166 | } |
| 167 | }, |
| 168 | error: function(error) { |
| 169 | showErrorMessage(); |
| 170 | }, |
| 171 | }); |
| 172 | }); |
| 173 | /** |
| 174 | * It shows success message in a toast alert |
| 175 | * */ |
| 176 | function showSuccessMessage() { |
| 177 | let $success_message_node = $('.toast__message--success'); |
| 178 | $success_message_node.addClass('show'); |
| 179 | setTimeout(function (){ |
| 180 | $success_message_node.removeClass('show'); |
| 181 | }, 3000); |
| 182 | } |
| 183 | /** |
| 184 | * It shows error message in a toast alert |
| 185 | * */ |
| 186 | function showErrorMessage(){ |
| 187 | let $error_message_node = $('.toast__message--error'); |
| 188 | $error_message_node.addClass('show'); |
| 189 | setTimeout(function (){ |
| 190 | $error_message_node.removeClass('show'); |
| 191 | }, 3000); |
| 192 | } |
| 193 | |
| 194 | $('.ep-color-picker').wpColorPicker(); |
| 195 | |
| 196 | |
| 197 | // license |
| 198 | $(document).on('click', '.embedpress-license-deactivation-btn', function (e) { |
| 199 | let $this = $(this); |
| 200 | setTimeout(function (){ |
| 201 | $this.attr('disabled', 'disabled'); |
| 202 | }, 2000); |
| 203 | $this.html('Deactivating.....'); |
| 204 | }); |
| 205 | $(document).on('click', '.embedpress-license-activation-btn', function (e) { |
| 206 | let $this = $(this); |
| 207 | let val = $('#embedpress-pro-license-key').val(); |
| 208 | if (val){ |
| 209 | setTimeout(function (){ |
| 210 | $this.attr('disabled', 'disabled'); |
| 211 | }, 2000); |
| 212 | $this.html('Activating.....'); |
| 213 | } |
| 214 | }); |
| 215 | }); |
| 216 |