| @@ -32,8 +32,67 @@ | ||
| 32 | 32 | } |
| 33 | 33 | }); |
| 34 | 34 | })(wp.media.view); |
| 35 | 35 | |
| 36 | +function createPopupProBlocker() { | |
| 37 | + | |
| 38 | + var link = document.createElement('link'); | |
| 39 | + link.rel = 'stylesheet'; | |
| 40 | + link.href = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css'; | |
| 41 | + document.head.appendChild(link); | |
| 42 | + | |
| 43 | + var overlay = document.createElement('div'); | |
| 44 | + overlay.classList.add('vizualizer-renew-notice-overlay'); | |
| 45 | + overlay.id = 'overlay-visualizer'; | |
| 46 | + document.body.appendChild(overlay); | |
| 47 | + | |
| 48 | + var popup = document.createElement('div'); | |
| 49 | + popup.classList.add('vizualizer-renew-notice-popup'); | |
| 50 | + | |
| 51 | + var closeIcon = document.createElement('i'); | |
| 52 | + closeIcon.classList.add('fas', 'fa-times', 'vizualizer-renew-notice-close-icon'); | |
| 53 | + closeIcon.addEventListener('click', function() { | |
| 54 | + document.body.removeChild(overlay); | |
| 55 | + popup.style.display = 'none'; | |
| 56 | + }); | |
| 57 | + popup.appendChild(closeIcon); | |
| 58 | + | |
| 59 | + var heading = document.createElement('h1'); | |
| 60 | + heading.textContent = 'Alert!'; | |
| 61 | + heading.classList.add('vizualizer-renew-notice-heading'); | |
| 62 | + popup.appendChild(heading); | |
| 63 | + | |
| 64 | + var message = document.createElement('p'); | |
| 65 | + message.textContent = 'In order to edit premium charts, benefit from updates and support for Visualizer Premium plugin, please renew your license code or activate it.'; | |
| 66 | + message.classList.add('vizualizer-renew-notice-message'); | |
| 67 | + popup.appendChild(message); | |
| 68 | + | |
| 69 | + var buttonsContainer = document.createElement('div'); | |
| 70 | + buttonsContainer.classList.add('vizualizer-renew-notice-buttons-container'); | |
| 71 | + | |
| 72 | + var link1 = document.createElement('a'); | |
| 73 | + link1.href = 'https://store.themeisle.com/'; | |
| 74 | + link1.target = '_blank'; | |
| 75 | + var button1 = document.createElement('button'); | |
| 76 | + button1.innerHTML = '<span class="fas fa-shopping-cart"></span> Renew License'; | |
| 77 | + button1.classList.add('vizualizer-renew-notice-button', 'vizualizer-renew-notice-renew-button'); | |
| 78 | + link1.appendChild(button1); | |
| 79 | + buttonsContainer.appendChild(link1); | |
| 80 | + | |
| 81 | + var link2 = document.createElement('a'); | |
| 82 | + link2.href = '/wp-admin/options-general.php#visualizer_pro_license'; | |
| 83 | + var button2 = document.createElement('button'); | |
| 84 | + button2.innerHTML = '<span class="fas fa-key"></span> Activate License'; | |
| 85 | + button2.classList.add('vizualizer-renew-notice-button', 'vizualizer-renew-notice-activate-button'); | |
| 86 | + link2.appendChild(button2); | |
| 87 | + buttonsContainer.appendChild(link2); | |
| 88 | + | |
| 89 | + popup.appendChild(buttonsContainer); | |
| 90 | + | |
| 91 | + document.body.appendChild(popup); | |
| 92 | + | |
| 93 | +} | |
| 94 | + | |
| 36 | 95 | (function ($, vmv, vu) { |
| 37 | 96 | var resizeTimeout; |
| 38 | 97 | |
| 39 | 98 | $.fn.adjust = function () { |
| @@ -76,8 +135,16 @@ | ||
| 76 | 135 | $(this).parent('form').submit(); |
| 77 | 136 | }); |
| 78 | 137 | |
| 79 | 138 | $('.visualizer-chart-shortcode').click(function (e) { |
| 139 | + | |
| 140 | + if ( ! visualizer.is_pro_user && e.target.classList.contains('viz-is-pro-chart') ) { | |
| 141 | + createPopupProBlocker(); | |
| 142 | + e.preventDefault(); | |
| 143 | + e.stopPropagation(); | |
| 144 | + return; | |
| 145 | + } | |
| 146 | + | |
| 80 | 147 | var range, selection; |
| 81 | 148 | |
| 82 | 149 | if (window.getSelection && document.createRange) { |
| 83 | 150 | selection = window.getSelection(); |
| @@ -125,9 +192,15 @@ | ||
| 125 | 192 | |
| 126 | 193 | return false; |
| 127 | 194 | }); |
| 128 | 195 | |
| 129 | - $('.visualizer-chart-edit').click(function () { | |
| 196 | + $('.visualizer-chart-edit').click(function (event) { | |
| 197 | + | |
| 198 | + if ( ! visualizer.is_pro_user && event.target.classList.contains('viz-is-pro-chart') ) { | |
| 199 | + createPopupProBlocker(); | |
| 200 | + return; | |
| 201 | + } | |
| 202 | + | |
| 130 | 203 | var wnd = window; |
| 131 | 204 | var view = new vmv.Chart( { |
| 132 | 205 | action: vu.edit.indexOf('&chart') != -1 ? vu.edit : vu.edit + '&chart=' + $(this).attr('data-chart') |
| 133 | 206 | } ); |
| @@ -140,10 +213,22 @@ | ||
| 140 | 213 | view.open(); |
| 141 | 214 | |
| 142 | 215 | return false; |
| 143 | 216 | }); |
| 217 | + $(".visualizer-chart-clone").on("click", function ( event ) { | |
| 218 | + if ( ! visualizer.is_pro_user && event.target.classList.contains('viz-is-pro-chart') ) { | |
| 219 | + createPopupProBlocker(); | |
| 220 | + event.preventDefault(); | |
| 221 | + } | |
| 222 | + }); | |
| 144 | 223 | |
| 145 | - $(".visualizer-chart-export").on("click", function () { | |
| 224 | + $(".visualizer-chart-export").on("click", function (event) { | |
| 225 | + | |
| 226 | + if ( ! visualizer.is_pro_user && event.target.classList.contains('viz-is-pro-chart') ) { | |
| 227 | + createPopupProBlocker(); | |
| 228 | + return; | |
| 229 | + } | |
| 230 | + | |
| 146 | 231 | $.ajax({ |
| 147 | 232 | url: $(this).attr("data-chart"), |
| 148 | 233 | method: "get", |
| 149 | 234 | success: function (data, textStatus, jqXHR) { |
| @@ -162,9 +247,13 @@ | ||
| 162 | 247 | }); |
| 163 | 248 | return false; |
| 164 | 249 | }); |
| 165 | 250 | |
| 166 | - $(".visualizer-chart-image").on("click", function () { | |
| 251 | + $(".visualizer-chart-image").on("click", function (event) { | |
| 252 | + if ( ! visualizer.is_pro_user && event.target.classList.contains('viz-is-pro-chart') ) { | |
| 253 | + createPopupProBlocker(); | |
| 254 | + return; | |
| 255 | + } | |
| 167 | 256 | $('body').trigger('visualizer:action:specificchart', {action: 'image', id: $(this).attr("data-chart"), data: null, dataObj: {name: $(this).attr("data-chart-title")}}); |
| 168 | 257 | return false; |
| 169 | 258 | }); |
| 170 | 259 | |
| @@ -172,8 +261,14 @@ | ||
| 172 | 261 | if(location.href.indexOf('vaction=addnew') !== -1){ |
| 173 | 262 | $('.add-new-chart').first().trigger('click'); |
| 174 | 263 | } |
| 175 | 264 | |
| 265 | + //if vaction=edit is found as a GET request parameter, show the modal. | |
| 266 | + if(location.href.indexOf('vaction=edit') !== -1 && location.href.indexOf('chart=') !== -1){ | |
| 267 | + const chartId = location.href.split('chart=')[1].split('&')[0]; | |
| 268 | + $('.visualizer-chart-edit').attr('data-chart', chartId).trigger('click'); | |
| 269 | + } | |
| 270 | + | |
| 176 | 271 | $(window).resize(function () { |
| 177 | 272 | clearTimeout(resizeTimeout); |
| 178 | 273 | resizeTimeout = setTimeout(function () { |
| 179 | 274 | $('.visualizer-chart-canvas').adjust(); |
| @@ -184,5 +279,30 @@ | ||
| 184 | 279 | alert( $(this).attr('data-viz-error') ); |
| 185 | 280 | }); |
| 186 | 281 | $('.visualizer-chart:not(.visualizer-chart-display), .visualizer-library-pagination').fadeIn(500); |
| 187 | 282 | }); |
| 188 | -})(jQuery, visualizer.media.view, visualizer.urls); | |
| 283 | +})(jQuery, visualizer.media.view, visualizer.urls); | |
| 284 | + | |
| 285 | + | |
| 286 | +document.querySelectorAll('.visualizer-chart').forEach(function (chart) { | |
| 287 | + const translatable = chart.querySelector('.visualizer-languages-list'); | |
| 288 | + if ( ! translatable ) { | |
| 289 | + return; | |
| 290 | + } | |
| 291 | + | |
| 292 | + const chartId = chart.querySelector('.visualizer-chart-canvas')?.id?.replace('visualizer-', ''); | |
| 293 | + | |
| 294 | + if ( ! chartId ) { | |
| 295 | + return; | |
| 296 | + } | |
| 297 | + | |
| 298 | + const translatableActions = translatable.querySelectorAll('[data-lang_code]'); | |
| 299 | + translatableActions.forEach(function (action) { | |
| 300 | + action.addEventListener('click', function () { | |
| 301 | + window?.tiTrk?.with('visualizer')?.add({ | |
| 302 | + feature: 'chart-library', | |
| 303 | + featureComponent: 'chart-language-translations-used', | |
| 304 | + groupId: chartId, | |
| 305 | + }); | |
| 306 | + }); | |
| 307 | + }); | |
| 308 | +}); | |