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
two_preview.js
254 lines
| 1 | jQuery("document").ready(function () { |
| 2 | jQuery("style").remove(); |
| 3 | jQuery("link:not(#two_preview_css-css):not(#two_google-fonts-css)").remove(); |
| 4 | jQuery("body").html('<div id="two_preview_container"></div>') |
| 5 | |
| 6 | let two_local_flow_id = localStorage.getItem("two_flow_id"); |
| 7 | let two_flow_id = two_preview_vars.flow_id; |
| 8 | |
| 9 | if(two_local_flow_id !== two_flow_id){ |
| 10 | two_update_flow_status("1"); |
| 11 | localStorage.removeItem("two_preview_mode"); |
| 12 | localStorage.removeItem("two_mode_flow_status"); |
| 13 | localStorage.setItem("two_flow_id", two_flow_id); |
| 14 | } |
| 15 | let two_preview_mode = localStorage.getItem("two_preview_mode"); |
| 16 | let two_mode_flow_status = localStorage.getItem("two_mode_flow_status"); |
| 17 | |
| 18 | let two_modes = JSON.parse(two_preview_vars.two_modes); |
| 19 | let two_incompatible_plugins = false; |
| 20 | let two_mandatory_incompatible_plugins = false; |
| 21 | const mandatory_plugins = ['wp-optimize/wp-optimize.php', 'wp-rocket/wp-rocket.php', 'nitropack/main.php']; |
| 22 | if(two_preview_vars.incompatible_plugins){ |
| 23 | two_incompatible_plugins = JSON.parse(two_preview_vars.incompatible_plugins); |
| 24 | } |
| 25 | if (two_incompatible_plugins) { |
| 26 | two_mandatory_incompatible_plugins = !!Object.keys(two_incompatible_plugins).find((plugin) => mandatory_plugins.includes( plugin )) |
| 27 | } |
| 28 | let current_mode_key = "extreme"; |
| 29 | let current_mode = two_modes[current_mode_key]; |
| 30 | let current_mode_level = 1; |
| 31 | let current_mode_next = current_mode["next"]; |
| 32 | |
| 33 | if (two_preview_mode && two_modes[two_preview_mode]["next"]) { |
| 34 | current_mode = two_modes[two_preview_mode]; |
| 35 | current_mode_key = current_mode["mode"]; |
| 36 | current_mode_level = parseInt(current_mode["level"]); |
| 37 | current_mode_next = current_mode["next"]; |
| 38 | } |
| 39 | |
| 40 | let two_preview_contact_us_html = get_two_preview_contact_us_html(); |
| 41 | let two_incompatible_plugins_html = get_two_incompatible_plugins_html(two_mandatory_incompatible_plugins); |
| 42 | let two_preview_html = get_two_preview_html(current_mode, two_modes); |
| 43 | |
| 44 | if(current_mode_next === "0"){ |
| 45 | jQuery("#two_preview_container").html(two_preview_contact_us_html); |
| 46 | }else if(two_mode_flow_status && two_incompatible_plugins){ |
| 47 | jQuery("#two_preview_container").html(two_incompatible_plugins_html); |
| 48 | }else{ |
| 49 | jQuery("#two_preview_container").html(two_preview_html); |
| 50 | } |
| 51 | jQuery("body").on("click", ".two_change_mode", function () { |
| 52 | current_mode = two_modes[current_mode_next]; |
| 53 | current_mode_key = current_mode["mode"]; |
| 54 | current_mode_level = parseInt(current_mode["level"]); |
| 55 | current_mode_next = current_mode["next"]; |
| 56 | |
| 57 | if(current_mode_next === "0"){ |
| 58 | // contact_us |
| 59 | // set mode no_optimize |
| 60 | jQuery("#two_preview_container").html(two_preview_contact_us_html); |
| 61 | two_update_flow_status("3"); |
| 62 | two_flow_set_mode("extreme" , "1"); |
| 63 | }else{ |
| 64 | let two_preview_html = get_two_preview_html(current_mode, two_modes); |
| 65 | jQuery("#two_preview_container").html(two_preview_html); |
| 66 | } |
| 67 | jQuery("#two_preview_iframe").attr("src", current_mode.preview_url); |
| 68 | localStorage.setItem("two_preview_mode", current_mode_key); |
| 69 | }); |
| 70 | jQuery("body").on("click", ".two_save_mode", function () { |
| 71 | //finish flow set global mode |
| 72 | //check incompatible plugins |
| 73 | let global_set_mode = jQuery(this).data("mode"); |
| 74 | localStorage.setItem("two_mode_flow_status", "1"); |
| 75 | localStorage.setItem("two_preview_mode", current_mode_key); |
| 76 | two_update_flow_status("2"); |
| 77 | if(two_incompatible_plugins) { |
| 78 | two_flow_set_mode(global_set_mode); |
| 79 | jQuery("#two_preview_container").html(two_incompatible_plugins_html); |
| 80 | }else{ |
| 81 | jQuery("#two_looks_good_form").submit(); |
| 82 | } |
| 83 | }); |
| 84 | jQuery("body").on("click", ".two_contact_us_button", function (e) { |
| 85 | e.preventDefault(); |
| 86 | two_update_flow_status("4"); |
| 87 | window.location.replace(two_preview_vars.contact_us_url); |
| 88 | }); |
| 89 | |
| 90 | jQuery("body").append("<iframe id='two_preview_iframe' src='"+current_mode.preview_url+"'></iframe>"); |
| 91 | |
| 92 | jQuery('.two_incompatible_plugin label').click(function() { |
| 93 | if( jQuery('.two_checkbox:checkbox:checked').length === 0 ) { |
| 94 | jQuery('.two_disable_incompatible_plugins').addClass('deactivated').prop('disabled', true); |
| 95 | } else { |
| 96 | jQuery('.two_disable_incompatible_plugins').removeClass('deactivated').prop('disabled', false); |
| 97 | } |
| 98 | }); |
| 99 | }); |
| 100 | |
| 101 | /*jQuery(document).on('click','.two_preview_close',function() { |
| 102 | jQuery('.two_preview_tools').toggleClass('two_preview_tools_closed'); |
| 103 | });*/ |
| 104 | |
| 105 | |
| 106 | function get_two_incompatible_plugins_html(two_mandatory_incompatible_plugins) { |
| 107 | if(two_preview_vars.incompatible_plugins){ |
| 108 | let two_incompatible_plugins = JSON.parse(two_preview_vars.incompatible_plugins); |
| 109 | let incompatible_plugins_html = ""; |
| 110 | for (let two_i in two_incompatible_plugins) { |
| 111 | if (two_mandatory_incompatible_plugins) { |
| 112 | incompatible_plugins_html += `<div class='two_incompatible_plugin with-restricted'><input class="two_checkbox" name="incompatible_plugins[]" checked type="checkbox" value="` + two_i + `"><span class="restricted-mark"></span>` + two_incompatible_plugins[two_i] + `</div>`; |
| 113 | } |
| 114 | else { |
| 115 | incompatible_plugins_html += `<div class='two_incompatible_plugin'><label> |
| 116 | <input class="two_checkbox" name="incompatible_plugins[]" checked type="checkbox" value="` + two_i + `"> |
| 117 | ` + two_incompatible_plugins[two_i] + `<span class="checkmark"></span></label> |
| 118 | </div>`; |
| 119 | } |
| 120 | } |
| 121 | let return_html = `<div class='two_not_available'>` + two_preview_vars.two_company_name + ` Booster onboarding flow <br/>is available only on desktop</div> |
| 122 | <div class='two_preview_tools'> |
| 123 | <div class="two_incompatible_plugins_container">`; |
| 124 | if (two_mandatory_incompatible_plugins) { |
| 125 | return_html += `<p class="two_preview_tools_title">` + two_preview_vars.two_company_name + ` Booster will not work with these plugins</p> |
| 126 | <p class="two_preview_tools_desc last-step">Proceeding will temporarly deactivate these plugins.</p>` |
| 127 | } |
| 128 | else { |
| 129 | return_html += `<p class="two_preview_tools_title">Some plugins are conflicting with ` + two_preview_vars.two_company_name + ` Booster</p> |
| 130 | <p class="two_preview_tools_desc last-step">We recommend deactivating these plugins. By clicking ‘Next’ the selected plugins will be deactivated.</p>` |
| 131 | } |
| 132 | |
| 133 | return_html += `<div class="two_preview_tools_info two_preview_tools_content incompatible_plugins"> |
| 134 | <form action="` + two_preview_vars.ajaxurl + `" method="post"> |
| 135 | <div class="two_incompatible_plugins"> |
| 136 | ` + incompatible_plugins_html + ` |
| 137 | </div> |
| 138 | <input type="hidden" name="nonce" value="`+two_preview_vars.ajaxnonce+`"> |
| 139 | <input type="hidden" name="action" value="two_flow_incompatible_plugins"> |
| 140 | <div class="two_preview_tools_content_buttons"> |
| 141 | <button class="two_disable_incompatible_plugins two_preview_button" name="two_disable_incompatible_plugins" type="submit">NEXT</button> |
| 142 | </div> |
| 143 | </form> |
| 144 | </div> |
| 145 | </div> |
| 146 | </div>`; |
| 147 | return return_html; |
| 148 | } |
| 149 | return ""; |
| 150 | |
| 151 | } |
| 152 | |
| 153 | function get_two_preview_html(current_mode, two_modes) { |
| 154 | let two_next_mode_key = current_mode["next"]; |
| 155 | if(two_next_mode_key === "0"){ |
| 156 | return ""; |
| 157 | } |
| 158 | |
| 159 | let next_mode = two_modes[two_next_mode_key]; |
| 160 | let current_mode_level = parseInt(current_mode["level"]); |
| 161 | let current_mode_key = current_mode["mode"]; |
| 162 | |
| 163 | return_html = ` |
| 164 | <div class='two_not_available'>` + two_preview_vars.two_company_name + ` Booster onboarding flow <br/>is available only on desktop</div> |
| 165 | <div class='two_preview_tools'> |
| 166 | <div class="two_preview_tools-wrap"> |
| 167 | <div class='two_preview_tools-first-block'> |
| 168 | <p class="two_preview_tools_title with_icon">` + two_preview_vars.two_company_name + ` Booster</p> |
| 169 | <p class="two_preview_tools_desc first-step">This is the preview of your optimized homepage.</p> |
| 170 | <p class="two_preview_tools_notice"><span>Your live website is unaffected.</span></p> |
| 171 | </div>`; |
| 172 | |
| 173 | if (current_mode_level === 1) { |
| 174 | return_html += ` |
| 175 | <div class="two_preview_tools_content"> |
| 176 | <p class="two_preview_tools_desc two_bold">Is this preview identical to your live homepage?</p>`; |
| 177 | } else { |
| 178 | |
| 179 | return_html += ` |
| 180 | <div class="two_preview_tools_content"> |
| 181 | <p class="two_preview_count">Preview ` + current_mode_level + `</p> |
| 182 | <p class="two_preview_tools_desc">Is this preview identical to your live homepage?</p>`; |
| 183 | } |
| 184 | return_html += ` |
| 185 | <div class="two_preview_tools_buttons"> |
| 186 | <form style="display: none !important;" id="two_looks_good_form" action="` + two_preview_vars.ajaxurl + `" method="post"> |
| 187 | <input type="hidden" name="action" value="two_flow_set_mode"> |
| 188 | <input type="hidden" name="mode" value="`+current_mode_key+`"> |
| 189 | <input type="hidden" name="test_mode" value="0"> |
| 190 | <input type="hidden" name="redirect" value="1"> |
| 191 | <input type="hidden" name="nonce" value="`+two_preview_vars.ajaxnonce+`"> |
| 192 | </form> |
| 193 | <p class="two_change_mode" data-level="` + next_mode['level'] + `" data-mode="` + two_next_mode_key + `" data-url="` + next_mode['preview_url'] + `">Something is off</p> |
| 194 | <p class="two_save_mode" data-mode="`+current_mode_key+`">Looks good</p> |
| 195 | </div> |
| 196 | </div> |
| 197 | </div> |
| 198 | </div>` |
| 199 | |
| 200 | return return_html; |
| 201 | } |
| 202 | |
| 203 | function get_two_preview_contact_us_html() { |
| 204 | let return_html = ` |
| 205 | <div class='two_not_available'>` + two_preview_vars.two_company_name + ` Booster onboarding flow <br/>is available only on desktop</div> |
| 206 | <div class='two_preview_tools'> |
| 207 | <div class="two_preview_tools_content_centered"> |
| 208 | <p class="two_preview_tools_title">We know how to help you!</p> |
| 209 | <p class="two_preview_tools_desc last-step">We’re sorry you’re still having issues. A unique website like yours requires a unique solution.</p> |
| 210 | <div class="two_preview_tools_notice last-step"> |
| 211 | <div> |
| 212 | <span class="two_preview_chat"></span> |
| 213 | <div class="two_contact_us-desc">Please drop us a message and we’ll try to fix it on our end.</div> |
| 214 | </div> |
| 215 | <a class="two_contact_us_button two_preview_button" href="\` + two_preview_vars.contact_us_url + \`">CONTACT US</a> |
| 216 | </div> |
| 217 | </div> |
| 218 | </div>` |
| 219 | return return_html; |
| 220 | } |
| 221 | |
| 222 | function two_flow_set_mode(mode , test_mode="0", redirect_url = false){ |
| 223 | jQuery.ajax({ |
| 224 | type: "POST", |
| 225 | url: two_preview_vars.ajaxurl, |
| 226 | dataType: 'json', |
| 227 | data: { |
| 228 | action: "two_flow_set_mode", |
| 229 | mode: mode, |
| 230 | test_mode: test_mode, |
| 231 | nonce: two_preview_vars.ajaxnonce, |
| 232 | } |
| 233 | }).done(function (data) { |
| 234 | if(redirect_url){ |
| 235 | window.location.href = redirect_url; |
| 236 | } |
| 237 | }); |
| 238 | } |
| 239 | |
| 240 | function two_update_flow_status(status){ |
| 241 | jQuery.ajax({ |
| 242 | type: "POST", |
| 243 | url: two_preview_vars.ajaxurl, |
| 244 | dataType: 'json', |
| 245 | data: { |
| 246 | action: "two_update_flow_status", |
| 247 | status:status, |
| 248 | nonce: two_preview_vars.ajaxnonce, |
| 249 | } |
| 250 | }).done(function (data) { |
| 251 | |
| 252 | }); |
| 253 | } |
| 254 |