gutenberg
3 years ago
gutenbergComponents
3 years ago
autoupdate_banner.js
3 years ago
banner_main.js
3 years ago
circle-progress.js
3 years ago
datatables.min.js
4 years ago
jquery.multi-select.js
4 years ago
jquery.tagsinput.min.js
4 years ago
referral_program.js
3 years ago
sidebar-plugin.js
3 years ago
speed.js
3 years ago
two_admin.js
1 year ago
two_admin_bar.js
4 years ago
two_bf_countdown.js
3 years ago
two_deactivate_plugin.js
3 years ago
two_elementor_editor.js
2 years ago
two_preview.js
3 years ago
two_update_white_label.js
1 year ago
two_white_label.js
2 years ago
speed.js
626 lines
| 1 | /* Do request to get optimized images count */ |
| 2 | jQuery.ajax({ |
| 3 | type: 'POST', |
| 4 | url: two_speed.ajax_url, |
| 5 | dataType: 'json', |
| 6 | data: { |
| 7 | action: "two_get_optimized_images", |
| 8 | nonce: two_speed.nonce, |
| 9 | } |
| 10 | }).success(function(res){ |
| 11 | let total_images_count, optimized_images_count; |
| 12 | if( typeof res['data'] != 'undefined' ) { |
| 13 | total_images_count = res['data']['total_images_count']; |
| 14 | optimized_images_count = res['data']['optimized_images_count'] |
| 15 | jQuery('.two-adminBar.two_empty_images_count').text(optimized_images_count + ' of ' + total_images_count); |
| 16 | jQuery('.two-settings-basic.two_empty_images_count').text(optimized_images_count); |
| 17 | } |
| 18 | }); |
| 19 | |
| 20 | /* Keeping time interval to check page optimized or not every 3 min*/ |
| 21 | var two_is_page_optimized_interval; |
| 22 | var reanalyzing_status; |
| 23 | jQuery(document).ready(function () { |
| 24 | if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { |
| 25 | jQuery('body').addClass('two_elementor_dark'); |
| 26 | } |
| 27 | |
| 28 | let link_exceed = '', limit_exceed_content = ''; |
| 29 | if (two_speed.optimize_entire_website != false && jQuery('#wpcontent').length > 0 && typeof two_limit_exceed_popup_content !== 'undefined' ) { |
| 30 | link_exceed = two_limit_exceed_popup_content.exceed_url; |
| 31 | limit_exceed_content = '<div class="two-limit-exceed-main-container">' + |
| 32 | '<div class="two-limit-exceed-container">' + |
| 33 | '<span class="two-limit-exceed-close" onclick="two_close_limit_exceed()"></span>' + |
| 34 | '<p class="two-limit-exceed-title">' + two_limit_exceed_popup_content.exceed_title + '</p>' + |
| 35 | '<p class="two-limit-exceed-description">' + two_limit_exceed_popup_content.exceed_desc_1 + '<br>' |
| 36 | + two_limit_exceed_popup_content.exceed_desc_2 + |
| 37 | '</p>' + |
| 38 | '<a class="two-limit-exceed-button" href="' + link_exceed + '">' + two_limit_exceed_popup_content.exceed_button_text |
| 39 | + '</a>' + |
| 40 | '</div>' + |
| 41 | '</div>' + |
| 42 | '</div>'; |
| 43 | jQuery('#wpcontent').append(limit_exceed_content); |
| 44 | } |
| 45 | |
| 46 | /* Do request to get reanalyzing_status updated*/ |
| 47 | let posts = []; |
| 48 | jQuery('.two-no-scores').each( function() { |
| 49 | if (!posts.includes(jQuery(this)) && jQuery(this).data('no-score-for') != '' ) { |
| 50 | posts.push(jQuery(this).data('no-score-for')); |
| 51 | } |
| 52 | }); |
| 53 | let unique_posts = [...new Set(posts)]; |
| 54 | if ( unique_posts.length > 0 ) { |
| 55 | reanalyzing_status = setInterval(function () { |
| 56 | jQuery.each(unique_posts,function( index, value ){ |
| 57 | let post_id = value; |
| 58 | jQuery.ajax({ |
| 59 | type: "POST", |
| 60 | url: two_speed.ajax_url, |
| 61 | dataType: 'json', |
| 62 | data: { |
| 63 | action: "two_get_page_score", |
| 64 | post_id: post_id, |
| 65 | nonce: two_speed.nonce, |
| 66 | } |
| 67 | }).success(function (results) { |
| 68 | let score_data = results['data']; |
| 69 | if (score_data && score_data['previous_score'] && score_data['previous_score']['status'] != 'inprogress' |
| 70 | && score_data['current_score'] && score_data['current_score']['status'] != 'inprogress') { |
| 71 | if (jQuery('.two_reanalyze_button').data('from-wp-admin') == 1 |
| 72 | || jQuery('.two_reanalyze_link').data('from-wp-admin') == 1 ) { |
| 73 | after_reanalyze_admin_bar(results,post_id); |
| 74 | } else if (jQuery('.two_reanalyze_button').data('from-elementor') == 1 |
| 75 | || jQuery('.two_reanalyze_link').data('from-elementor') == 1 ) { |
| 76 | after_reanalyze_elementor(results); |
| 77 | } |
| 78 | clearInterval(reanalyzing_status); |
| 79 | } |
| 80 | }); |
| 81 | }); |
| 82 | |
| 83 | }, 10000); |
| 84 | } |
| 85 | /* Add an action to check a page score.*/ |
| 86 | jQuery(".two-notoptimized a").on("click", function () { |
| 87 | if ( !jQuery(".two_ongoing_optimization").length > 0 ) { |
| 88 | if (typeof jQuery(this).attr("href") != 'undefined') { |
| 89 | return; |
| 90 | } |
| 91 | if (two_speed.optimize_entire_website != false) { |
| 92 | two_limit_exceed_popup(); |
| 93 | } else { |
| 94 | two_optimize_page(this); |
| 95 | } |
| 96 | } else { |
| 97 | jQuery(".two-optimization-in-progress-tooltip").addClass("two-hidden"); |
| 98 | jQuery(this).next(".two-optimization-in-progress-tooltip").removeClass("two-hidden"); |
| 99 | } |
| 100 | }); |
| 101 | |
| 102 | jQuery(".two-optimization-in-progress-close").on("click",function(){ |
| 103 | jQuery(".two-optimization-in-progress-tooltip").addClass("two-hidden"); |
| 104 | }); |
| 105 | |
| 106 | if ( jQuery('.two_admin_bar_menu_main_notif').length > 0 ) { |
| 107 | jQuery('.two_admin_bar_notif_menu').addClass('two_pages_optimizing'); |
| 108 | if ( jQuery('.two_admin_bar_menu_content.two_optimized').length > 0 ) { |
| 109 | jQuery('.two_admin_bar_notif_menu .two_admin_bar_menu_header span').addClass('two_green_info'); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | jQuery("#two_optimize_now_button").on("click", function () { |
| 114 | two_optimize_page(this); |
| 115 | /* Run ajax every 3 min to check if page optimized */ |
| 116 | two_is_page_optimized_interval = setInterval( two_is_page_optimized, 180000, this ); |
| 117 | }); |
| 118 | |
| 119 | /* Add a hover action to show scores.*/ |
| 120 | jQuery(".two-optimized .two-optimized-see-more").mouseenter(function () { |
| 121 | jQuery(this).parent().parent().find(".two-score-container").removeClass("two-hidden"); |
| 122 | }).mouseleave( function () { |
| 123 | jQuery(this).parent().parent().find(".two-score-container").addClass("two-hidden"); |
| 124 | }); |
| 125 | /* Draw circle on given scores.*/ |
| 126 | jQuery('.two-score-circle').each(function () { |
| 127 | two_draw_score_circle(this); |
| 128 | }); |
| 129 | |
| 130 | /* Show/hide Image optimizer menu content container */ |
| 131 | jQuery("#wp-admin-bar-two_adminbar_info").mouseenter(function(){ |
| 132 | jQuery(".two_admin_bar_menu_main").removeClass("two_hidden"); |
| 133 | }).mouseleave(function() { |
| 134 | jQuery(".two_admin_bar_menu_main").addClass("two_hidden"); |
| 135 | }); |
| 136 | |
| 137 | /* Show/hide Booster optimizer notif content container */ |
| 138 | if ( jQuery(".two_admin_bar_menu_main_notif").hasClass("two_hidden") ) { |
| 139 | jQuery("#wp-admin-bar-two_adminbar_progress_info").mouseenter(function () { |
| 140 | jQuery(".two_admin_bar_menu_main_notif").removeClass("two_hidden"); |
| 141 | }).mouseleave(function () { |
| 142 | jQuery(".two_admin_bar_menu_main_notif").addClass("two_hidden"); |
| 143 | }); |
| 144 | } |
| 145 | |
| 146 | jQuery(".two_admin_bar_menu_main_notif_optimized_close").on("click", function() { |
| 147 | jQuery(this).parent().remove(); |
| 148 | if ( !jQuery('.two_admin_bar_menu_main_notif').children().length > 0 ) { |
| 149 | jQuery('#wp-admin-bar-two_adminbar_progress_info').remove(); |
| 150 | } |
| 151 | var post_id = jQuery(this).data("post_id"); |
| 152 | jQuery.ajax({ |
| 153 | url: two_speed.ajax_url, |
| 154 | type: "POST", |
| 155 | data: { |
| 156 | action: "two_optimized_notif_closed", |
| 157 | post_id: post_id, |
| 158 | nonce: two_speed.nonce |
| 159 | }, |
| 160 | success: function (result) { |
| 161 | /* Show/hide Booster optimizer notif content container */ |
| 162 | if ( jQuery(".two_admin_bar_menu_main_notif").hasClass("two_hidden") ) { |
| 163 | jQuery("#wp-admin-bar-two_adminbar_progress_info").mouseenter(function () { |
| 164 | jQuery(".two_admin_bar_menu_main_notif").removeClass("two_hidden"); |
| 165 | }).mouseleave(function () { |
| 166 | jQuery(".two_admin_bar_menu_main_notif").addClass("two_hidden"); |
| 167 | }); |
| 168 | } |
| 169 | console.log(result); |
| 170 | } |
| 171 | }); |
| 172 | }); |
| 173 | |
| 174 | jQuery(".two_clear_cache").on("click", function (e) { |
| 175 | e.preventDefault(); |
| 176 | two_clear_cache(this); |
| 177 | }); |
| 178 | |
| 179 | jQuery(".two_optimized_cont").on("click", function() { |
| 180 | if( jQuery(this).find(".two_arrow").hasClass("two_up_arrow") ) { |
| 181 | jQuery(this).find(".two_score_block_container").addClass("two_hidden"); |
| 182 | jQuery(this).find(".two_arrow").addClass("two_down_arrow").removeClass("two_up_arrow"); |
| 183 | } else { |
| 184 | jQuery(".two_score_block_container").addClass("two_hidden"); |
| 185 | jQuery(".two_optimized_congrats_row .two_arrow").addClass("two_down_arrow").removeClass("two_up_arrow"); |
| 186 | jQuery(this).find(".two_score_block_container").removeClass("two_hidden"); |
| 187 | jQuery(this).find(".two_arrow").addClass("two_up_arrow").removeClass("two_down_arrow"); |
| 188 | } |
| 189 | }); |
| 190 | |
| 191 | jQuery('.two-faq-item').on('click', function () { |
| 192 | jQuery(this).toggleClass('active'); |
| 193 | }); |
| 194 | jQuery('.two-disconnect-link a').on('click', function () { |
| 195 | jQuery('.two-disconnect-popup').appendTo('body').addClass('open'); |
| 196 | return false; |
| 197 | }); |
| 198 | jQuery('.two-button-cancel, .two-close-img').on('click', function () { |
| 199 | jQuery('.two-disconnect-popup').removeClass('open'); |
| 200 | return false; |
| 201 | }); |
| 202 | |
| 203 | jQuery('.two-open-contact-care-team').on('click', function(e) { |
| 204 | e.preventDefault(); |
| 205 | jQuery('.two_admin_bar_menu_main').trigger('mouseleave'); |
| 206 | jQuery('.two-contact-care-popup-main').removeClass('two-hidden'); |
| 207 | jQuery('body').addClass('two-overflow-hidden'); |
| 208 | }); |
| 209 | jQuery('.two-contact-care-close').on('click', function() { |
| 210 | jQuery('.two-contact-care-popup-main').addClass('two-hidden'); |
| 211 | jQuery('body').removeClass('two-overflow-hidden'); |
| 212 | }); |
| 213 | |
| 214 | jQuery('.two-button-io-active-optimize').on('click',function(e) { |
| 215 | e.preventDefault(); |
| 216 | if ( !jQuery(this).hasClass('two-button-io-disable') ) { |
| 217 | jQuery(this).addClass('two-button-io-disable'); |
| 218 | jQuery(this).text(''); |
| 219 | jQuery(this).css('opacity','0.8'); |
| 220 | jQuery(this).append("<span class='two-loading'></span>"); |
| 221 | } |
| 222 | jQuery.ajax({ |
| 223 | type: 'POST', |
| 224 | url: two_speed.ajax_url, |
| 225 | dataType: 'json', |
| 226 | data: { |
| 227 | action: "two_setFlowIdNotificationId", |
| 228 | nonce: two_speed.nonce, |
| 229 | } |
| 230 | }).success(function(res){ |
| 231 | window.location.href = res.data; |
| 232 | }); |
| 233 | }); |
| 234 | }); |
| 235 | |
| 236 | function two_limit_exceed_popup() { |
| 237 | jQuery('.two-limit-exceed-main-container').css('display','flex'); |
| 238 | }; |
| 239 | |
| 240 | function two_close_limit_exceed() { |
| 241 | jQuery('.two-limit-exceed-main-container').css('display', 'none'); |
| 242 | } |
| 243 | |
| 244 | /* Recount google speed score */ |
| 245 | function two_clear_cache(that) { |
| 246 | let clear_cache_from = ''; |
| 247 | if ( jQuery(that).hasClass('two_cache_button') ) { |
| 248 | jQuery(that).text(''); |
| 249 | jQuery(that).css('opacity','0.8'); |
| 250 | jQuery(that).append("<span class='two-loading'></span>"); |
| 251 | } else { |
| 252 | jQuery(that).text( two_speed.clearing ); |
| 253 | jQuery(that).prepend("<span class='two_cache_clearing'></span>"); |
| 254 | } |
| 255 | if ( typeof jQuery(that).data('from') !== undefined ) { |
| 256 | clear_cache_from = jQuery(that).data('from'); |
| 257 | } |
| 258 | jQuery.ajax({ |
| 259 | type: "POST", |
| 260 | url: ajaxurl, |
| 261 | dataType: 'json', |
| 262 | data: { |
| 263 | action: "two_settings", |
| 264 | task: "clear_cache", |
| 265 | clear_cache_from: clear_cache_from, |
| 266 | nonce: two_speed.nonce, |
| 267 | } |
| 268 | }).done(function (data) { |
| 269 | if ( jQuery(that).hasClass('two_cache_button') ) { |
| 270 | jQuery(that).css('opacity','1'); |
| 271 | jQuery(that).closest('.two-loading').remove(); |
| 272 | jQuery(that).text(two_speed.clear); |
| 273 | } else { |
| 274 | jQuery(".two_cache_clearing").remove(); |
| 275 | if (data.success) { |
| 276 | jQuery(that).text(two_speed.cleared); |
| 277 | jQuery(that).addClass("two_cache_cleared"); |
| 278 | } else { |
| 279 | jQuery(that).text(two_speed.clear); |
| 280 | } |
| 281 | } |
| 282 | }).error(function (data) { |
| 283 | if ( jQuery(that).hasClass('two_cache_button') ) { |
| 284 | jQuery(that).css('opacity','1'); |
| 285 | jQuery(that).closest('.two-loading').remove(); |
| 286 | jQuery(that).text(two_speed.clear); |
| 287 | } else { |
| 288 | jQuery(".two_cache_clearing").remove(); |
| 289 | jQuery(that).text(two_speed.clear); |
| 290 | } |
| 291 | }); |
| 292 | } |
| 293 | |
| 294 | /* Checking is page optimized */ |
| 295 | function two_is_page_optimized( that ) { |
| 296 | var post_id = jQuery(that).data("post-id"); |
| 297 | jQuery.ajax({ |
| 298 | url: two_speed.ajax_url, |
| 299 | type: "POST", |
| 300 | data: { |
| 301 | action: "two_is_page_optimized", |
| 302 | post_id: post_id, |
| 303 | nonce: two_speed.nonce |
| 304 | }, |
| 305 | success: function (result) { |
| 306 | if ( result['success'] ) { |
| 307 | clearInterval(two_is_page_optimized_interval); |
| 308 | jQuery(".two_in_progress_cont").remove(); |
| 309 | after_reanalyze_admin_bar(result,post_id); |
| 310 | jQuery(".two_empty_front_optimized_content").removeClass("two_hidden"); |
| 311 | } |
| 312 | }, |
| 313 | error: function () {}, |
| 314 | }); |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * Optimize the page. |
| 319 | * @param that |
| 320 | */ |
| 321 | function two_optimize_page(that) { |
| 322 | if ( !jQuery(that).hasClass('two-button-disabled') ) { |
| 323 | var post_id = jQuery(that).data("post-id"); |
| 324 | var initiator = jQuery(that).data("initiator"); |
| 325 | if (jQuery(that).attr('id') == 'two_optimize_now_button') { |
| 326 | jQuery(".two_admin_bar_menu_header.two_frontpage_not_optimized img, .two_admin_bar_menu_header.two_frontpage_optimized img").hide(); |
| 327 | jQuery(".two_admin_bar_menu_header.two_frontpage_not_optimized,.two_admin_bar_menu_header.two_frontpage_optimized").removeClass("two_frontpage_not_optimized").addClass("two_frontpage_optimizing"); |
| 328 | jQuery(".two_frontpage_optimizing span").removeClass('two_hidden'); |
| 329 | var two_in_progress_cont = jQuery(".two_in_progress_cont").html(); |
| 330 | jQuery(".two_admin_bar_menu_content.two_not_optimized_content, .two_optimized").empty().append(two_in_progress_cont).addClass("two_in_progress_cont"); |
| 331 | } else if (jQuery(that).hasClass("two_optimize_button_elementor")) { |
| 332 | jQuery(".elementor-control-title, .two_elementor_control_container").addClass("two-hidden"); |
| 333 | jQuery(".two-score-section,.two-elementor-container-title").addClass("two-hidden"); |
| 334 | jQuery(".two_elementor_settings_content").addClass("two-optimizing"); |
| 335 | jQuery(".two-page-speed.two-optimizing").removeClass("two-hidden"); |
| 336 | } else { |
| 337 | var parent = jQuery(that).parent().parent(); |
| 338 | parent.find(".two-optimizing").removeClass("two-hidden"); |
| 339 | parent.find(".two-optimizing").addClass("two_ongoing_optimization"); |
| 340 | parent.find(".two-notoptimized").addClass("two-hidden"); |
| 341 | } |
| 342 | jQuery.ajax({ |
| 343 | url: two_speed.ajax_url, |
| 344 | type: "GET", |
| 345 | data: { |
| 346 | action: "two_optimize_page", |
| 347 | post_id: post_id, |
| 348 | initiator: initiator, |
| 349 | nonce: two_speed.nonce |
| 350 | }, |
| 351 | success: function (result) { |
| 352 | }, |
| 353 | error: function (xhr, ajaxOptions, thrownError) { |
| 354 | clearInterval(two_is_page_optimized_interval); |
| 355 | }, |
| 356 | }); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | function two_reanalyze_score(that){ |
| 361 | if ( !jQuery(that).hasClass('two-button-disabled') ) { |
| 362 | var post_id = jQuery(that).data("post_id"); |
| 363 | jQuery('.two-pages-list-reanalyzing[data-post-id="' + post_id + '"]').removeClass("two-hidden"); |
| 364 | jQuery('.two-optimized-see-more[data-post-id="' + post_id + '"]').addClass("two-hidden"); |
| 365 | let reanalyzing_container = jQuery('.two-any-reanalyzing-score-section[data-id="' + post_id + '"]'); |
| 366 | let reanalyze_score_for; |
| 367 | if ( reanalyzing_container.find(".two-score-container-both .two-no-scores").length > 1 |
| 368 | || reanalyzing_container.find(".two_score_container_both.two-no-scores").length > 1 ) { |
| 369 | reanalyze_score_for = 'both'; |
| 370 | reanalyzing_container.find(".two-score-container-both .two_reanalyze_link").addClass("two-hidden"); |
| 371 | reanalyzing_container.find(".two_score_container_both .two_reanalyze_link").addClass("two-hidden"); |
| 372 | reanalyzing_container.find(".two_score_container_both .two_reanalyze_link").next(".two-page-speed.two-optimizing").removeClass("two-hidden"); |
| 373 | reanalyzing_container.find(".two-score-container-both .two_reanalyze_link").next(".two-page-speed.two-optimizing").removeClass("two-hidden"); |
| 374 | reanalyzing_container.find(".two_reanalyze_container .two-page-speed.two-optimizing").removeClass("two-hidden"); |
| 375 | reanalyzing_container.find(".two_reanalyze_button").text("Reanalyzing..."); |
| 376 | } else { |
| 377 | if (jQuery(that).parent().hasClass("two-new-scores") || jQuery(that).hasClass("two_reanalyze_button")) { |
| 378 | reanalyze_score_for = 'new'; |
| 379 | reanalyzing_container.find(".two_reanalyze_container .two-page-speed.two-optimizing").removeClass("two-hidden"); |
| 380 | reanalyzing_container.find(".two_reanalyze_button").text("Reanalyzing..."); |
| 381 | } else if (jQuery(that).parent().hasClass("two-old-scores")) { |
| 382 | reanalyze_score_for = 'old'; |
| 383 | } |
| 384 | if (jQuery(that).hasClass("two_reanalyze_button")) { |
| 385 | reanalyzing_container.find(".two-new-scores").addClass("two-no-scores"); |
| 386 | reanalyzing_container.find(".two-new-scores .two_reanalyze_link").addClass("two-hidden"); |
| 387 | reanalyzing_container.find(".two-new-scores .two_reanalyze_link").next(".two-page-speed.two-optimizing").removeClass("two-hidden"); |
| 388 | } else { |
| 389 | jQuery(that).addClass("two-hidden"); |
| 390 | jQuery(that).find(".two-page-speed.two-optimizing").removeClass("two-hidden"); |
| 391 | } |
| 392 | } |
| 393 | reanalyzing_container.find(".two_elementor_control_container .two_optimize_button_elementor.two_optimize_button").addClass("two-button-disabled"); |
| 394 | reanalyzing_container.find("#two_optimize_now_button").addClass("two-button-disabled"); |
| 395 | reanalyzing_container.find(".two_reanalyze_button").addClass("two-button-disabled"); |
| 396 | |
| 397 | jQuery.ajax({ |
| 398 | type: "POST", |
| 399 | url: two_speed.ajax_url, |
| 400 | dataType: 'json', |
| 401 | data: { |
| 402 | action: "two_recount_score", |
| 403 | reanalyze_score_for: reanalyze_score_for, |
| 404 | post_id: post_id, |
| 405 | nonce: two_speed.nonce, |
| 406 | } |
| 407 | }).success(function (results) { |
| 408 | if ( jQuery('.two_reanalyze_button').data('from-wp-admin') == 1 |
| 409 | || jQuery('.two_reanalyze_link').data('from-wp-admin') == 1) { |
| 410 | after_reanalyze_admin_bar(results,post_id); |
| 411 | } else if ( jQuery('.two_reanalyze_button').data('from-elementor') == 1 |
| 412 | || jQuery('.two_reanalyze_link').data('from-elementor') == 1) { |
| 413 | after_reanalyze_elementor(results); |
| 414 | } |
| 415 | }).error(function (data) { |
| 416 | console.log('error'); |
| 417 | }); |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | /** |
| 422 | * Draw circle on given score. |
| 423 | * @param that |
| 424 | */ |
| 425 | function two_draw_score_circle(that) { |
| 426 | var score = parseInt(jQuery(that).data('score')); |
| 427 | var size = parseInt(jQuery(that).data('size')); |
| 428 | var thickness = parseInt(jQuery(that).data('thickness')); |
| 429 | var color = score <= 49 ? "rgb(253, 60, 49)" : (score >= 90 ? "rgb(12, 206, 107)" : "rgb(255, 164, 0)"); |
| 430 | var background_color = score <= 49 ? "#FD3C311A" : (score >= 90 ? "#22B3391A" : "#fd3c311a"); |
| 431 | if ( jQuery(that).hasClass('two_circle_with_bg') ) { |
| 432 | jQuery(that).css('background-color',background_color); |
| 433 | } |
| 434 | jQuery(that).parent().find('.two-load-time').html(jQuery(that).data('loading-time')); |
| 435 | var _this = that; |
| 436 | jQuery(_this).circleProgress({ |
| 437 | value: score / 100, |
| 438 | size: size, |
| 439 | startAngle: -Math.PI / 4 * 2, |
| 440 | lineCap: 'round', |
| 441 | emptyFill: "rgba(255, 255, 255, 0)", |
| 442 | thickness: thickness, |
| 443 | fill: { |
| 444 | color: color |
| 445 | } |
| 446 | }).on('circle-animation-progress', function (event, progress) { |
| 447 | if (score != 0) { |
| 448 | content = Math.round(score * progress); |
| 449 | jQuery(that).find('.two-score-circle-animated').html(content).css({"color": color}); |
| 450 | jQuery(that).find('canvas').html(Math.round(score * progress)); |
| 451 | } |
| 452 | }); |
| 453 | } |
| 454 | |
| 455 | /* Adding button in Elementor edit panel navigation view */ |
| 456 | function two_add_elementor_button() { |
| 457 | window.elementor.modules.layouts.panel.pages.menu.Menu.addItem({ |
| 458 | name: two_speed.title, |
| 459 | icon: "two-element-menu-icon", |
| 460 | title: two_speed.title, |
| 461 | type: "page", |
| 462 | callback: () => { |
| 463 | try { |
| 464 | window.$e.route("panel/page-settings/two_optimize") |
| 465 | } catch (e) { |
| 466 | window.$e.route("panel/page-settings/settings"), window.$e.route("panel/page-settings/two_optimize") |
| 467 | } |
| 468 | } |
| 469 | }, "more") |
| 470 | } |
| 471 | /* show 10web Booster button in sidebar only for pages and posts */ |
| 472 | if ( (two_speed.post_type == 'page' || two_speed.post_type == 'post') && two_speed.post_status == 'publish' |
| 473 | && two_speed.post_optimizable ) { |
| 474 | jQuery(window).on("elementor:init", () => { |
| 475 | window.elementor.on("panel:init", () => { |
| 476 | setTimeout(two_add_elementor_button) |
| 477 | }) |
| 478 | }); |
| 479 | } |
| 480 | |
| 481 | function after_reanalyze_elementor(results) { |
| 482 | clearInterval(reanalyzing_status); |
| 483 | let data; |
| 484 | if( typeof results['data'] !== 'undefined' && typeof results['data']['previous_score'] !== 'undefined' ) { |
| 485 | data = results['data']; |
| 486 | jQuery(".two-old-scores").removeClass("two-no-scores"); |
| 487 | // /* TODO check this */ |
| 488 | // /* setting attr("data") is for case when no any score are set yet empty case */ |
| 489 | // jQuery(".two-old-scores .two-score-mobile .two-score-circle").attr("data-score", data["previous_score"]["mobile_score"]); |
| 490 | // jQuery(".two-old-scores .two-score-mobile .two-score-circle").attr("data-loading-time", data["previous_score"]["mobile_tti"]); |
| 491 | // jQuery(".two-old-scores .two-score-desktop .two-score-circle").attr("data-score", data["previous_score"]["desktop_score"]); |
| 492 | // jQuery(".two-old-scores .two-score-desktop .two-score-circle").attr("data-loading-time", data["previous_score"]["desktop_tti"]); |
| 493 | |
| 494 | /* setting data(score) is for case when need to change one time rendered element attr */ |
| 495 | jQuery(".two-old-scores .two-score-mobile .two-score-circle").data("score", data["previous_score"]["mobile_score"]); |
| 496 | jQuery(".two-old-scores .two-score-mobile .two-score-circle").data("loading-time", data["previous_score"]["mobile_tti"]); |
| 497 | jQuery(".two-old-scores .two-score-desktop .two-score-circle").data("score", data["previous_score"]["desktop_score"]); |
| 498 | jQuery(".two-old-scores .two-score-desktop .two-score-circle").data("loading-time", data["previous_score"]["desktop_tti"]); |
| 499 | jQuery('.two-old-scores .two-score-circle').each(function() { |
| 500 | two_draw_score_circle(this); |
| 501 | }); |
| 502 | } |
| 503 | if( typeof results['data'] !== 'undefined' && typeof results['data']['current_score'] !== 'undefined' ) { |
| 504 | data = results['data']; |
| 505 | jQuery(".two-new-scores").removeClass("two-no-scores"); |
| 506 | // /* setting attr("data") is for case when no any score are set yet empty case */ |
| 507 | // jQuery(".two-new-scores .two-score-mobile .two-score-circle").attr("data-score", data["current_score"]["mobile_score"]); |
| 508 | // jQuery(".two-new-scores .two-score-mobile .two-score-circle").attr("data-loading-time", data["current_score"]["mobile_tti"]); |
| 509 | // jQuery(".two-new-scores .two-score-desktop .two-score-circle").attr("data-score", data["current_score"]["desktop_score"]); |
| 510 | // jQuery(".two-new-scores .two-score-desktop .two-score-circle").attr("data-loading-time", data["current_score"]["desktop_tti"]); |
| 511 | |
| 512 | /* setting data(score) is for case when need to change one time rendered element attr */ |
| 513 | jQuery(".two-new-scores .two-score-mobile .two-score-circle").data("score", data["current_score"]["mobile_score"]); |
| 514 | jQuery(".two-new-scores .two-score-mobile .two-score-circle").data("loading-time", data["current_score"]["mobile_tti"]); |
| 515 | jQuery(".two-new-scores .two-score-desktop .two-score-circle").data("score", data["current_score"]["desktop_score"]); |
| 516 | jQuery(".two-new-scores .two-score-desktop .two-score-circle").data("loading-time", data["current_score"]["desktop_tti"]); |
| 517 | jQuery('.two-new-scores .two-score-circle').each(function() { |
| 518 | two_draw_score_circle(this); |
| 519 | }); |
| 520 | jQuery(".two_reanalyze_container .two-page-speed.two-optimizing").addClass("two-hidden"); |
| 521 | jQuery(".two_reanalyze_button").text("Reanalyze"); |
| 522 | } |
| 523 | jQuery(".two-score-container-both .two_reanalyze_link").next(".two-page-speed.two-optimizing").addClass("two-hidden"); |
| 524 | jQuery(".two_elementor_control_container .two_optimize_button_elementor.two_optimize_button").removeClass("two-button-disabled"); |
| 525 | jQuery(".two_reanalyze_button").removeClass("two-button-disabled"); |
| 526 | } |
| 527 | function after_reanalyze_admin_bar(results,post_id) { |
| 528 | clearInterval(reanalyzing_status); |
| 529 | var data; |
| 530 | let the_score_container = jQuery('.two-any-reanalyzing-score-section[data-id="' + post_id + '"]'); |
| 531 | if( typeof results['data'] !== 'undefined' && typeof results['data']['previous_score'] !== 'undefined' |
| 532 | && typeof results['data']['previous_score']['desktop_score'] !== 'undefined' ) { |
| 533 | the_score_container.find(".two-old-scores").removeClass("two-no-scores"); |
| 534 | data = results['data']; |
| 535 | the_score_container.find(".two_score_container.two_score_container_mobile_old .two-score-circle").data("score", data["previous_score"]["mobile_score"]); |
| 536 | the_score_container.find(".two_score_container.two_score_container_mobile_old .two_load_time").text(data["previous_score"]["mobile_tti"] + 's'); |
| 537 | the_score_container.find(".two_score_container.two_score_container_desktop_old .two-score-circle").data("score", data["previous_score"]["desktop_score"]); |
| 538 | the_score_container.find(".two_score_container.two_score_container_desktop_old .two_load_time").text(data["previous_score"]["desktop_tti"] + 's'); |
| 539 | the_score_container.find('.two-old-scores .two-score-circle').each(function() { |
| 540 | two_draw_score_circle(this); |
| 541 | }); |
| 542 | } |
| 543 | if( typeof results['data'] !== 'undefined' && typeof results['data']['current_score'] !== 'undefined' |
| 544 | && typeof results['data']['current_score']['desktop_score'] !== 'undefined' ) { |
| 545 | the_score_container.find(".two-new-scores").removeClass("two-no-scores"); |
| 546 | data = results['data']; |
| 547 | the_score_container.find(".two_score_container.two_score_container_mobile .two-score-circle").data("score", data["current_score"]["mobile_score"]); |
| 548 | the_score_container.find(".two_score_container.two_score_container_mobile .two_load_time").text(data["current_score"]["mobile_tti"] + 's'); |
| 549 | the_score_container.find(".two_score_container.two_score_container_desktop .two-score-circle").data("score", data["current_score"]["desktop_score"]); |
| 550 | the_score_container.find(".two_score_container.two_score_contain er_desktop .two_load_time").text(data["current_score"]["desktop_tti"] + 's'); |
| 551 | the_score_container.find('.two-new-scores .two-score-circle').each(function() { |
| 552 | two_draw_score_circle(this); |
| 553 | }); |
| 554 | the_score_container.find(".two_reanalyze_container .two-page-speed.two-optimizing").addClass("two-hidden"); |
| 555 | the_score_container.find(".two_reanalyze_button").text("Reanalyze"); |
| 556 | } |
| 557 | the_score_container.find(".two_score_container_both .two_reanalyze_link").next(".two-page-speed.two-optimizing").addClass("two-hidden"); |
| 558 | jQuery(".two_admin_bar_menu_header.two_frontpage_not_optimized img, .two_admin_bar_menu_header.two_frontpage_optimized img").show(); |
| 559 | jQuery(".two_frontpage_optimizing span").addClass('two_hidden'); |
| 560 | the_score_container.find(".two_reanalyze_button").removeClass("two-button-disabled"); |
| 561 | the_score_container.find("#two_optimize_now_button").removeClass("two-button-disabled"); |
| 562 | jQuery('.two-pages-list-reanalyzing[data-post-id="' + post_id + '"]').addClass("two-hidden"); |
| 563 | jQuery('.two-optimized-see-more[data-post-id="' + post_id + '"]').removeClass("two-hidden"); |
| 564 | } |
| 565 | |
| 566 | /** |
| 567 | * Run ajax action and Sign Up to dashboard via magic link |
| 568 | * |
| 569 | * @param that object |
| 570 | */ |
| 571 | function two_sign_up_dashboard_magic_link( that ) { |
| 572 | if ( jQuery(that).hasClass("two-disable-link") ) { |
| 573 | return false; |
| 574 | } |
| 575 | |
| 576 | var email_input = jQuery(that).parent().parent().find(".two-sign-up-input"); |
| 577 | |
| 578 | jQuery(".two-error-msg").remove(); |
| 579 | email_input.removeClass("two-input-error"); |
| 580 | jQuery(that).addClass('two-disable-link'); |
| 581 | jQuery(that).text(''); |
| 582 | jQuery(that).addClass('two-loading'); |
| 583 | |
| 584 | var email = email_input.val(); |
| 585 | if (email === '') { |
| 586 | window.location.href = two_speed.connection_link; |
| 587 | } |
| 588 | |
| 589 | var EmailRegex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/; |
| 590 | if (!EmailRegex.test(email) && email !== '') { |
| 591 | email_input.after('<p class="two-error-msg">' + two_speed.wrong_email + '</p>'); |
| 592 | email_input.addClass("two-input-error"); |
| 593 | jQuery(that).text(two_speed.sign_up); |
| 594 | jQuery(that).removeClass('two-disable-link'); |
| 595 | jQuery(that).removeClass('two-loading'); |
| 596 | return; |
| 597 | } |
| 598 | jQuery.ajax( { |
| 599 | type: "POST", |
| 600 | url: two_speed.ajax_url, |
| 601 | dataType: 'json', |
| 602 | data: { |
| 603 | action: "two_sign_up_dashboard_magic_link", |
| 604 | email: email, |
| 605 | nonce: two_speed.nonce, |
| 606 | }, |
| 607 | success: function (result) { |
| 608 | if ( result['status'] === 'success' ) { |
| 609 | window.location.href = result['booster_connect_url']; |
| 610 | } |
| 611 | else { |
| 612 | jQuery(that).text(two_speed.sign_up); |
| 613 | jQuery(that).removeClass('two-disable-link'); |
| 614 | jQuery(that).removeClass('two-loading'); |
| 615 | email_input.after('<p class="two-error-msg">' + two_speed.something_wrong + '</p>'); |
| 616 | return; |
| 617 | } |
| 618 | }, |
| 619 | error: function (xhr) { |
| 620 | jQuery(that).text(two_speed.sign_up); |
| 621 | jQuery(that).removeClass('two-disable-link'); |
| 622 | jQuery(that).removeClass('two-loading'); |
| 623 | email_input.after('<p class="two-error-msg">' + two_speed.something_wrong + '</p>'); |
| 624 | } |
| 625 | }); |
| 626 | } |