images
3 years ago
javascript
3 years ago
stylesheet
2 years ago
admin.php
2 years ago
connect-oneclick.php
2 years ago
connect.php
2 years ago
dashboard-oneclick.php
2 years ago
dashboard.php
2 years ago
diag.php
3 years ago
help.php
3 years ago
oneclick.php
2 years ago
safemode.php
3 years ago
safemode.tpl
4 years ago
dashboard.php
984 lines
| 1 | <style> |
| 2 | .rml_btn { |
| 3 | float: right; |
| 4 | color: #989898 !important; |
| 5 | font-size: 13px; |
| 6 | cursor: pointer; |
| 7 | text-decoration: underline !important; |
| 8 | } |
| 9 | |
| 10 | .rml_btn:hover{ |
| 11 | color: #212529 !important; |
| 12 | /*text-decoration: underline !important;*/ |
| 13 | } |
| 14 | </style> |
| 15 | |
| 16 | <div> |
| 17 | <div class="row"> |
| 18 | <div class="col-md-12"> |
| 19 | <?php nitropack_display_admin_notices(); ?> |
| 20 | </div> |
| 21 | </div> |
| 22 | <?php if (count(get_nitropack()->Notifications->get('system')) > 0) { ?> |
| 23 | <div class="row"> |
| 24 | <div class="col-12 mb-3"> |
| 25 | <div class="card-overlay-blurrable np-widget" id="notifications"> |
| 26 | <div class="card card-d-item"> |
| 27 | <div class="card-body"> |
| 28 | <h5 class="card-title" style="display: inline-block;"><?php esc_html_e( 'Notifications', 'nitropack' ); ?></h5> |
| 29 | <ul class="list-group list-group-flush" id="notifications-list"> |
| 30 | <?php foreach(get_nitropack()->Notifications->get('system') as $notification) : ?> |
| 31 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"> |
| 32 | <div class="col-10"> |
| 33 | <?php echo $notification['message']; ?> |
| 34 | </div> |
| 35 | <div class="col-2"> <a class="rml_btn" data-notification_end="<?php echo $notification['end_date']; ?>" data-notification_id="<?php echo $notification['id']; ?>">Remind me later</a> </div> |
| 36 | </li> |
| 37 | <?php endforeach; ?> |
| 38 | </ul> |
| 39 | </div> |
| 40 | </div> |
| 41 | </div> |
| 42 | </div> |
| 43 | </div> |
| 44 | <?php } ?> |
| 45 | <div class="row"> |
| 46 | <div class="col-md-6 mb-3"> |
| 47 | <div class="card-overlay-blurrable np-widget" id="optimizations-widget"> |
| 48 | <div class="card card-d-item"> |
| 49 | <div class="card-body"> |
| 50 | <h5 class="card-title"><?php esc_html_e( 'Optimized Pages', 'nitropack' ); ?> |
| 51 | <span id="pending-optimizations-section" class="pull-right mt-1" style="display:none;font-size: 12px;color: #28a745"><?php esc_html_e( 'Processing', 'nitropack' ); ?> |
| 52 | <span id="pending-optimizations-count">X</span> page(s) in the background <i class="fa fa-spinner fa-spin"></i> |
| 53 | <a href="https://support.nitropack.io/hc/en-us/articles/4766337974801" target="_blank" rel="noopener noreferrer" class="pull-right"><i data-info-tooltip class="mx-2 info-tooltip fa fa-info-circle text-primary" data-toggle="tooltip" data-placement="top" title="<?php esc_html_e( 'Click to learn more', 'nitropack' ); ?>"></i></a> |
| 54 | </span> |
| 55 | |
| 56 | </h5> |
| 57 | <div class="row mt-4" data-hideable> |
| 58 | <div id="optimized-pages"><span data-optimized-pages-total>0</span></div> |
| 59 | <div id="last-cache-purge" class="text-secondary"><?php esc_html_e( 'Last cache purge:', 'nitropack' ); ?> <span data-last-cache-purge><?php esc_html_e( 'Never', 'nitropack' ); ?></span></div> |
| 60 | <div id="last-cache-purge-reason" class="text-secondary"><?php esc_html_e( 'Reason:', 'nitropack' ); ?> <span data-purge-reason><?php esc_html_e( 'Unknown', 'nitropack' ); ?></span></div> |
| 61 | </div> |
| 62 | <div class="row mt-4 optimizations-hidden" data-hideable> |
| 63 | <div class="optimizations-subcount"><span data-optimized-pages-mobile>0</span> <?php esc_html_e( 'mobile pages', 'nitropack' ); ?></div> |
| 64 | <div class="optimizations-subcount"><span data-optimized-pages-tablet>0</span> <?php esc_html_e( 'tablet pages', 'nitropack' ); ?></div> |
| 65 | <div class="optimizations-subcount"><span data-optimized-pages-desktop>0</span> <?php esc_html_e( 'desktop pages', 'nitropack' ); ?></div> |
| 66 | </div> |
| 67 | <div class="row mt-5 justify-content-center"> |
| 68 | <i id="np-purge-cache-loading"class="fa fa-refresh fa-spin" style="margin:5px;font-size:48px;display:none;"></i> |
| 69 | <i id="np-purge-cache-success" class="fa fa-check-circle" style="margin:5px;font-size:48px;display:none;"></i> |
| 70 | <i id="np-purge-cache-error" class="fa fa-times-circle" style="margin:5px;font-size:48px;display:none;"></i> |
| 71 | <button id="optimizations-purge-cache" class="btn btn-light btn-outline-secondary btn-widget-optimizations"><?php esc_html_e( 'Purge Cache', 'nitropack' ); ?></button> |
| 72 | </div> |
| 73 | </div> |
| 74 | </div> |
| 75 | </div> |
| 76 | </div> |
| 77 | <div class="col-md-6 mb-3"> |
| 78 | <div class="card-overlay-blurrable np-widget" id="plan-details-widget"> |
| 79 | <div class="card card-d-item"> |
| 80 | <div class="card-body"> |
| 81 | <h5 class="card-title"><?php esc_html_e( 'Plan', 'nitropack' ); ?></h5> |
| 82 | <div class="mt-3"> |
| 83 | <h5 class="font-weight-lighter"><span data-plan-title>Unknown</span> <a target="_blank" href="https://nitropack.io/user/billing" class="btn btn-primary btn-sm ml-3"><?php esc_html_e( 'Manage plan', 'nitropack' ); ?></a></h5> |
| 84 | </div> |
| 85 | <ul class="list-group list-group-flush" id="plan-quotas"> |
| 86 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"><?php esc_html_e( 'Next Reset', 'nitropack' ); ?> <span data-next-reset><?php esc_html_e( 'No ETA', 'nitropack' ); ?></span></li> |
| 87 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"><?php esc_html_e( 'Next Billing', 'nitropack' ); ?> <span data-next-billing><?php esc_html_e( 'No ETA', 'nitropack' ); ?></span></li> |
| 88 | </ul> |
| 89 | <p class="mb-0 mt-2"><i class="fa fa-info-circle text-primary" aria-hidden="true"></i> <?php esc_html_e( 'You will be notified if you approach the plan resource limit', 'nitropack' ); ?></p> |
| 90 | </div> |
| 91 | </div> |
| 92 | </div> |
| 93 | </div> |
| 94 | <div class="col-md-6 mb-3"> |
| 95 | <div class="card-overlay-blurrable np-widget" id="quicksetup-widget"> |
| 96 | <div class="card card-d-item"> |
| 97 | <div class="card-body"> |
| 98 | <h5 class="card-title"><?php esc_html_e( 'Optimization Mode', 'nitropack' ); ?></h5> |
| 99 | <p><small><?php esc_html_e( 'Slide to change your settings. This will update the level of optimization.', 'nitropack' ); ?></small></p> |
| 100 | |
| 101 | <div id="range-container"> |
| 102 | <div id="labels"></div> |
| 103 | <div id="range-element"> |
| 104 | <div id="divisors"></div> |
| 105 | <input id="range" type="range" min="1" max="5" step="1" value="0" /> |
| 106 | </div> |
| 107 | </div> |
| 108 | |
| 109 | <div id="description"> |
| 110 | <div class="text dummy"> |
| 111 | <h6 class="text-success"><?php esc_html_e( 'Dummy', 'nitropack' ); ?></h6> |
| 112 | <p><small></small></p> |
| 113 | </div> |
| 114 | <div class="text standard"> |
| 115 | <h6 class="text-info"><?php esc_html_e( 'Standard', 'nitropack' ); ?></h6> |
| 116 | <p><small><?php esc_html_e( 'A basic set of optimizations enough to get you up and running. Includes CDN and lossless image optimization.', 'nitropack' ); ?></small></p> |
| 117 | </div> |
| 118 | <div class="text medium"> |
| 119 | <h6 class="text-success"><?php esc_html_e( 'Medium', 'nitropack' ); ?></h6> |
| 120 | <p><small><?php esc_html_e( 'Well-balanced and suitable for many cases.', 'nitropack' ); ?></small></p> |
| 121 | </div> |
| 122 | <div class="text strong"> |
| 123 | <h6 class="nitropack_success_text"><?php esc_html_e( 'Strong', 'nitropack' ); ?></h6> |
| 124 | <p><small><?php esc_html_e( 'Very stable. Includes advanced features like automatic image lazy loading and font definition modification. This is the recommended optimization mode.', 'nitropack' ); ?></small></p> |
| 125 | </div> |
| 126 | <div class="text ludicrous"> |
| 127 | <h6 class="text-danger"><?php esc_html_e( 'Ludicrous', 'nitropack' ); ?></h6> |
| 128 | <p><small><?php esc_html_e( 'A pre-defined configuration aiming to achieve the fastest possible speed. Prioritizes rendering.', 'nitropack' ); ?></small></p> |
| 129 | </div> |
| 130 | <div class="text custom"> |
| 131 | <h6><?php esc_html_e( 'Manual', 'nitropack' ); ?></h6> |
| 132 | <p><small><?php esc_html_e( 'Use your own settings.', 'nitropack' ); ?> <a id="manual-settings-url" href="javascript:void(0);" target="_blank"><?php esc_html_e( 'Click here', 'nitropack' ); ?></a><?php esc_html_e( 'to configure them.', 'nitropack' ); ?></small></p> |
| 133 | </div> |
| 134 | </div> |
| 135 | </div> |
| 136 | </div> |
| 137 | </div> |
| 138 | </div> |
| 139 | <div class="col-md-6 mb-3"> |
| 140 | <div class="card-overlay-blurrable np-widget" id="settings-widget"> |
| 141 | <div class="card card-d-item"> |
| 142 | <div class="card-body"> |
| 143 | <h5 class="card-title"><?php esc_html_e( 'Settings', 'nitropack' ); ?></h5> |
| 144 | <ul class="list-group list-group-flush"> |
| 145 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"> |
| 146 | <span><?php esc_html_e( 'Cache Warmup', 'nitropack' ); ?> |
| 147 | <?php |
| 148 | $sitemap = get_option('np_warmup_sitemap', false); |
| 149 | $toolTipDisplayState = $sitemap ? '' : 'd-none'; |
| 150 | ?> |
| 151 | <i class="fa fa-info-circle text-primary warmup-tooltip <?php echo $toolTipDisplayState; ?>" data-toggle="tooltip" data-placement="top" title="<?php echo esc_html_e($sitemap); ?>" aria-hidden="true"></i> |
| 152 | </br> |
| 153 | <small><?php esc_html_e( 'Learn more about this feature', 'nitropack' ); ?> <a href="https://support.nitropack.io/hc/en-us/articles/1500002555901-Cache-Warmup-WordPress-" target="_blank" rel="noreferrer noopener"><?php esc_html_e( 'here', 'nitropack' ); ?></a></small> |
| 154 | </span> |
| 155 | <span id="loading-warmup-status"> |
| 156 | <?php esc_html_e( 'Loading cache warmup status', 'nitropack' ); ?> <i class="fa fa-refresh fa-spin" style="color: var(--blue);"></i> |
| 157 | </span> |
| 158 | <span id="warmup-toggle" style="display: none;"> |
| 159 | <label id="warmup-status-slider" class="switch"> |
| 160 | <input type="checkbox" id="warmup-status"> |
| 161 | <span class="slider"></span> |
| 162 | </label> |
| 163 | </span> |
| 164 | </li> |
| 165 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"> |
| 166 | <span><?php esc_html_e( 'Safe Mode', 'nitropack' ); ?></br> |
| 167 | <small><?php esc_html_e( 'Learn more about this feature', 'nitropack' ); ?> <a href="https://support.nitropack.io/hc/en-us/articles/360060910574-Safe-Mode" target="_blank" rel="noreferrer noopener"><?php esc_html_e( 'here', 'nitropack' ); ?></a></small> |
| 168 | </span> |
| 169 | <span id="loading-safemode-status"> |
| 170 | <?php esc_html_e( 'Loading safe mode status', 'nitropack' ); ?> <i class="fa fa-refresh fa-spin" style="color: var(--blue);"></i> |
| 171 | </span> |
| 172 | <span id="safemode-toggle" style="display: none;"> |
| 173 | <label id="safemode-status-slider" class="switch"> |
| 174 | <input type="checkbox" id="safemode-status"> |
| 175 | <span class="slider"></span> |
| 176 | </label> |
| 177 | </span> |
| 178 | </li> |
| 179 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"> |
| 180 | <span id="detecting-compression" style="display: none;"><?php esc_html_e( 'Testing current compression status', 'nitropack' ); ?> <a href="javascript:void(0);"><i class="fa fa-refresh fa-spin" style="color: var(--blue);"></i></a></span> |
| 181 | <span id="detected-compression"><?php esc_html_e( 'HTML Compression', 'nitropack' ); ?> <a href="javascript:void(0);" id="compression-test-btn" data-toggle="tooltip" data-placement="top" title="<?php esc_html_e( 'Automatically detect whether compression is needed', 'nitropack' ); ?>"><i class="fa fa-refresh" style="color: var(--blue);"></i></a></span> |
| 182 | <span> |
| 183 | <label class="switch"> |
| 184 | <input type="checkbox" id="compression-status" <?php echo (int)$enableCompression === 1 ? "checked" : ""; ?>> |
| 185 | <span class="slider"></span> |
| 186 | </label> |
| 187 | </span> |
| 188 | </li> |
| 189 | <?php if (nitropack_render_woocommerce_cart_cache_option()) { ?> |
| 190 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"> |
| 191 | <span><?php esc_html_e( 'Ecommerce Cart Cache', 'nitropack' ); ?> <span class="badge badge-info"><?php echo nitropack_is_cart_cache_available() ? __( 'New', 'nitropack' ) : '<a href="https://' . NITROPACKIO_HOST . '/pricing" target="_blank" rel="noopener noreferrer" class="text-white">'.__( 'Requires a paid subscription', 'nitropack' ).'</a>'; ?></span></br> |
| 192 | <small><?php esc_html_e( 'Your visitors will enjoy full site speed while browsing with items in cart. Fully optimized page cache will be served.', 'nitropack' ); ?></small> |
| 193 | </span> |
| 194 | <span id="cart-cache-toggle"> |
| 195 | <label class="switch" id="cart-cache-status-slider"> |
| 196 | <input type="checkbox" id="cart-cache-status" <?php if (nitropack_is_cart_cache_active()) echo "checked"; ?> <?php if (!nitropack_is_cart_cache_available()) echo "disabled"; ?>> |
| 197 | <span class="slider"></span> |
| 198 | </label> |
| 199 | </span> |
| 200 | </li> |
| 201 | <?php } ?> |
| 202 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"> |
| 203 | <span> |
| 204 | <a href="javascript:void(0);" class="btn btn-danger text-white" id="disconnect-btn"><i class="fa fa-power-off text-white"></i> <?php esc_html_e( 'Disconnect', 'nitropack' ); ?></a> |
| 205 | </span> |
| 206 | </li> |
| 207 | </ul> |
| 208 | <p class="mb-0 mt-2"><i class="fa fa-info-circle text-primary" aria-hidden="true"></i> <?php esc_html_e( 'You can further configure how NitroPack\'s optimization behaves through your account at', 'nitropack' ); ?> <a href="https://<?php echo NITROPACKIO_HOST; ?>/" target="_blank">https://<?php echo NITROPACKIO_HOST; ?>/ <i class="fa fa-external-link"></i></a>.</p> |
| 209 | </div> |
| 210 | </div> |
| 211 | </div> |
| 212 | </div> |
| 213 | <div class="col-md-6 mb-3"> |
| 214 | <div class="card-overlay-blurrable np-widget" id="automations-widget"> |
| 215 | <div class="card card-d-item"> |
| 216 | <div class="card-body"> |
| 217 | <h5 class="card-title"><?php esc_html_e( 'Automated Behavior', 'nitropack' ); ?></h5> |
| 218 | <ul class="list-group list-group-flush"> |
| 219 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"> |
| 220 | <span><?php esc_html_e( 'Purge affected cache when content is updated or published', 'nitropack' ); ?></span> |
| 221 | <span id="auto-purge-toggle"> |
| 222 | <label id="auto-purge-status-slider" class="switch"> |
| 223 | <input type="checkbox" id="auto-purge-status" <?php if ($autoCachePurge) echo "checked"; ?>> |
| 224 | <span class="slider"></span> |
| 225 | </label> |
| 226 | </span> |
| 227 | </li> |
| 228 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"> |
| 229 | <span>Use legacy purge<br/> |
| 230 | <small>Selecting this forces NitroPack to use the old cache invalidation algorithm</small> |
| 231 | </span> |
| 232 | <span id="legacy-purge-toggle"> |
| 233 | <label id="legacy-purge-status-slider" class="switch"> |
| 234 | <input type="checkbox" id="legacy-purge-status" <?php if ($legacyPurge) echo "checked"; ?>> |
| 235 | <span class="slider"></span> |
| 236 | </label> |
| 237 | </span> |
| 238 | </li> |
| 239 | <?php if (\NitroPack\Integration\Plugin\BeaverBuilder::isActive()) { ?> |
| 240 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"> |
| 241 | <span><?php esc_html_e( 'Purge NitroPack cache when Beaver Builder cache is purged', 'nitropack' ); ?><br/> |
| 242 | <small><?php esc_html_e( 'Warning: This will perform a full NitroPack cache purge', 'nitropack' ); ?></small> |
| 243 | </span> |
| 244 | <span id="bb-purge-toggle"> |
| 245 | <label id="bb-purge-status-slider" class="switch"> |
| 246 | <input type="checkbox" id="bb-purge-status" <?php if ($bbCacheSyncPurge) echo "checked"; ?>> |
| 247 | <span class="slider"></span> |
| 248 | </label> |
| 249 | </span> |
| 250 | </li> |
| 251 | <?php } ?> |
| 252 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"> |
| 253 | <span><?php esc_html_e( 'Select what post/page types get optimized', 'nitropack' ); ?></span> |
| 254 | <span id="cacheable-post-types-btn"> |
| 255 | <a href="javascript:void(0);" class="btn btn-light btn-outline-secondary" data-toggle="modal" data-target="#cacheable-post-types-modal"><i class="fa fa-cog"></i></a> |
| 256 | </span> |
| 257 | </li> |
| 258 | </ul> |
| 259 | </div> |
| 260 | </div> |
| 261 | </div> |
| 262 | </div> |
| 263 | </div> |
| 264 | </div> |
| 265 | |
| 266 | <!-- Post Types Modal --> |
| 267 | <div class="modal" id="cacheable-post-types-modal" tabindex="-1" role="dialog" aria-labelledby="cacheable-post-types-title" aria-hidden="true" data-backdrop="false"> |
| 268 | <div class="modal-dialog modal-dialog-centered" role="document"> |
| 269 | <div class="modal-content"> |
| 270 | <div class="modal-header"> |
| 271 | <h5 class="modal-title" id="cacheable-post-types-title"><?php esc_html_e( 'Configure page types that can be optimized', 'nitropack' ); ?></h5> |
| 272 | <button type="button" class="close" data-dismiss="modal" aria-label="Close"> |
| 273 | <span aria-hidden="true">×</span> |
| 274 | </button> |
| 275 | </div> |
| 276 | <div class="modal-body nitropack-scrollable-modal-body"> |
| 277 | <ul class="list-group list-group-flush"> |
| 278 | <?php foreach ($objectTypes as $objectType) {?> |
| 279 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center border-0"> |
| 280 | <span><?php echo $objectType->label; ?></span> |
| 281 | <span id="post-type-<?php echo $objectType->name; ?>-toggle"> |
| 282 | <label id="post-type-<?php echo $objectType->name; ?>-status-slider" class="switch"> |
| 283 | <input class="cacheable-post-type" name="<?php echo $objectType->name; ?>" type="checkbox" id="post-type-post-status" <?php if (in_array($objectType->name, $cacheableObjectTypes)) echo 'checked'; ?>> |
| 284 | <span class="slider"></span> |
| 285 | </label> |
| 286 | </span> |
| 287 | </li> |
| 288 | <?php if (!empty($objectType->taxonomies)) {?> |
| 289 | <?php foreach ($objectType->taxonomies as $taxonomyType) {?> |
| 290 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center list-group-item-indented border-0"> |
| 291 | <span><?php echo $taxonomyType->label; ?></span> |
| 292 | <span id="post-type-<?php echo $taxonomyType->name; ?>-toggle"> |
| 293 | <label id="post-type-<?php echo $taxonomyType->name; ?>-status-slider" class="switch"> |
| 294 | <input class="cacheable-post-type" name="<?php echo $taxonomyType->name; ?>" type="checkbox" id="post-type-post-status" <?php if (in_array($taxonomyType->name, $cacheableObjectTypes)) echo 'checked'; ?>> |
| 295 | <span class="slider"></span> |
| 296 | </label> |
| 297 | </span> |
| 298 | </li> |
| 299 | <?php }?> |
| 300 | <?php }?> |
| 301 | <?php }?> |
| 302 | </ul> |
| 303 | </div> |
| 304 | <div class="modal-footer"> |
| 305 | <button type="button" class="btn btn-secondary" data-dismiss="modal"><?php esc_html_e( 'Close', 'nitropack' ); ?></button> |
| 306 | <button type="button" class="btn btn-primary" id="save-cacheable-post-types"><?php esc_html_e( 'Save changes', 'nitropack' ); ?> <i class="fa fa-spinner fa-spin d-none"></i></button> |
| 307 | </div> |
| 308 | </div> |
| 309 | </div> |
| 310 | </div> |
| 311 | <script> |
| 312 | |
| 313 | |
| 314 | ($ => { |
| 315 | var getOptimizationsTimeout = null; |
| 316 | let isClearing = false; |
| 317 | |
| 318 | $(window).on("load",function() { |
| 319 | $("#optimizations-widget").cardOverlay("loading", {message: "Loading optimizations data"}); |
| 320 | $("#plan-details-widget").cardOverlay("loading", {message: "Loading plan data"}); |
| 321 | $("#quicksetup-widget").cardOverlay("loading", {message: "Loading settings"}); |
| 322 | $(function () { $('[data-toggle="tooltip"]').tooltip()}); |
| 323 | getOptimizations(); |
| 324 | getPlan(); |
| 325 | getQuickSetup(); |
| 326 | |
| 327 | |
| 328 | <?php if ($checkedCompression != 1) { ?> |
| 329 | autoDetectCompression(); |
| 330 | <?php } ?> |
| 331 | }); |
| 332 | |
| 333 | $(document).on('click', '[data-hideable]', function(e) { |
| 334 | e.preventDefault(); |
| 335 | |
| 336 | $('[data-hideable]').removeClass('optimizations-hidden'); |
| 337 | |
| 338 | $(this).addClass('optimizations-hidden'); |
| 339 | }); |
| 340 | |
| 341 | $(document).on('click', '#optimizations-invalidate-cache', function(e) { |
| 342 | e.preventDefault(); |
| 343 | //Overlay.loading("Invalidating cache..."); |
| 344 | |
| 345 | invalidateEvent = new Event("cache.invalidate.request"); |
| 346 | window.dispatchEvent(invalidateEvent); |
| 347 | }); |
| 348 | |
| 349 | $(document).on('click', '#optimizations-purge-cache', function(e) { |
| 350 | e.preventDefault(); |
| 351 | //Overlay.loading("Purging cache..."); |
| 352 | purgeCache(); |
| 353 | }); |
| 354 | |
| 355 | let purgeCache = () => { |
| 356 | let purgeEvent = new Event("cache.purge.request"); |
| 357 | window.dispatchEvent(purgeEvent); |
| 358 | } |
| 359 | |
| 360 | $(document).on('click', '[nitropack-rc-data]', function(e) { |
| 361 | e.preventDefault(); |
| 362 | if (isClearing) return; |
| 363 | let currentButton = $(this); |
| 364 | $.ajax({ |
| 365 | url: ajaxurl, |
| 366 | type: "POST", |
| 367 | dataType: "text", |
| 368 | data: { |
| 369 | action: 'nitropack_clear_residual_cache', |
| 370 | gde: currentButton.attr('nitropack-rc-data') |
| 371 | }, |
| 372 | beforeSend: function () { |
| 373 | currentButton.parent(".alert-warning").hide(); |
| 374 | isClearing = true; |
| 375 | }, |
| 376 | success: function(resp) { |
| 377 | result = JSON.parse(resp); |
| 378 | Notification[result.type](result.message); |
| 379 | }, |
| 380 | error: function(resp) { |
| 381 | result = JSON.parse(resp); |
| 382 | Notification[result.type](result.message); |
| 383 | }, |
| 384 | complete: function() { |
| 385 | isClearing = false; |
| 386 | setTimeout(function(){location.reload();}, 3000); |
| 387 | } |
| 388 | }); |
| 389 | }); |
| 390 | |
| 391 | $("#btn-run-warmup").on("click", function(e) { |
| 392 | runWarmup(); |
| 393 | }) |
| 394 | |
| 395 | $("#btn-stop-warmup").on("click", function(e) { |
| 396 | disableWarmup(); |
| 397 | }) |
| 398 | |
| 399 | var estimateWarmup = (id, retry) => { |
| 400 | id = id || null; |
| 401 | retry = retry || 0; |
| 402 | if (!id) { |
| 403 | $("#settings-widget").cardOverlay("loading", {message: "<?php esc_html_e( 'Estimating optimizations usage', 'nitropack' ); ?>"}); |
| 404 | //$("#estimation-spinner").show(); |
| 405 | //$("#warmup-status-slider").hide(); |
| 406 | |
| 407 | $.post(ajaxurl, { |
| 408 | action: 'nitropack_estimate_warmup' |
| 409 | }, function(response) { |
| 410 | var resp = JSON.parse(response); |
| 411 | if (resp.type == "success") { |
| 412 | setTimeout( (function(id){ |
| 413 | estimateWarmup(id); |
| 414 | })(resp.res), 1000 ); |
| 415 | } else { |
| 416 | $("#settings-widget").cardOverlay("error", {message: "<?php esc_html_e( 'Warmup estimation failed', 'nitropack' ); ?>", timeout: 3000}); |
| 417 | } |
| 418 | }); |
| 419 | } else { |
| 420 | $.post(ajaxurl, { |
| 421 | action: 'nitropack_estimate_warmup', |
| 422 | estId: id |
| 423 | }, function(response) { |
| 424 | var resp = JSON.parse(response); |
| 425 | if (resp.type == "success") { |
| 426 | if (isNaN(resp.res) || resp.res == -1) { // Still calculating |
| 427 | if (retry >= 10) { |
| 428 | $("#settings-widget").cardOverlay("error", {message: "<?php esc_html_e( 'Warmup estimation failed. Please try again or contact support if the issue persists.', 'nitropack' ); ?>", dismissable: true}); |
| 429 | } else { |
| 430 | setTimeout( (function(id, retry){ |
| 431 | estimateWarmup(id, retry); |
| 432 | })(id, retry+1), 1000 ); |
| 433 | } |
| 434 | } else { |
| 435 | if (resp.res == 0) { |
| 436 | $("#settings-widget").cardOverlay("notify", {message: "<?php esc_html_e( 'We could not find any links for warming up on your home page', 'nitropack' ); ?>", timeout: 3000}); |
| 437 | } else { |
| 438 | var confirmHtml = '<p>Enabling cache warmup will optimize ' + resp.res + ' pages. Would you like to continue?</p>'; |
| 439 | confirmHtml += '<p><a href="javascript:void(0);" onclick="rejectWarmup()" class="btn btn-default btn-sm"><?php esc_html_e( 'No', 'nitropack' ); ?></a> <a href="javascript:void(0);" onclick="confirmWarmup()" class="btn btn-success btn-sm"><?php esc_html_e( 'Yes', 'nitropack' ); ?></p></a>'; |
| 440 | $("#settings-widget").cardOverlay("notify", {message: confirmHtml}); |
| 441 | |
| 442 | if (resp.sitemap_indication) { |
| 443 | jQuery('.warmup-tooltip').removeClass('d-none'); |
| 444 | jQuery('.warmup-tooltip').attr('title', resp.sitemap_indication); |
| 445 | } |
| 446 | } |
| 447 | } |
| 448 | } else { |
| 449 | $("#settings-widget").cardOverlay("error", {message: "<?php esc_html_e( 'Warmup estimation failed', 'nitropack' ); ?>", timeout: 3000}); |
| 450 | } |
| 451 | }); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | window.confirmWarmup = function() { |
| 456 | $("#settings-widget").cardOverlay("loading", {message: "<?php esc_html_e( 'Enabling warmup', 'nitropack' ); ?>"}); |
| 457 | enableWarmup(); |
| 458 | } |
| 459 | |
| 460 | window.rejectWarmup = function() { |
| 461 | $("#settings-widget").cardOverlay("clear"); |
| 462 | } |
| 463 | |
| 464 | var enableWarmup = () => { |
| 465 | jQuery.post(ajaxurl, { |
| 466 | action: 'nitropack_enable_warmup' |
| 467 | }, function(response) { |
| 468 | var resp = JSON.parse(response); |
| 469 | if (resp.type == "success") { |
| 470 | $("#settings-widget").cardOverlay("clear"); |
| 471 | $("#warmup-status").attr("checked", true); |
| 472 | } else { |
| 473 | setTimeout(enableWarmup, 1000); |
| 474 | } |
| 475 | }); |
| 476 | } |
| 477 | |
| 478 | var disableWarmup = () => { |
| 479 | jQuery.post(ajaxurl, { |
| 480 | action: 'nitropack_disable_warmup' |
| 481 | }, function(response) { |
| 482 | var resp = JSON.parse(response); |
| 483 | if (resp.type == "success") { |
| 484 | // Success notification |
| 485 | jQuery('.warmup-tooltip').addClass('d-none'); |
| 486 | jQuery('.warmup-tooltip').attr('title', ''); |
| 487 | } else { |
| 488 | // Error notification |
| 489 | } |
| 490 | }); |
| 491 | } |
| 492 | |
| 493 | var runWarmup = () => { |
| 494 | jQuery.post(ajaxurl, { |
| 495 | action: 'nitropack_run_warmup' |
| 496 | }, function(response) { |
| 497 | var resp = JSON.parse(response); |
| 498 | if (resp.type == "success") { |
| 499 | // Success notification |
| 500 | } else { |
| 501 | // Error notification |
| 502 | } |
| 503 | }); |
| 504 | } |
| 505 | |
| 506 | var enableSafemode = () => { |
| 507 | jQuery.post(ajaxurl, { |
| 508 | action: 'nitropack_enable_safemode' |
| 509 | }, function(response) { |
| 510 | var resp = JSON.parse(response); |
| 511 | if (resp.type == "success") { |
| 512 | $("#safemode-status").attr("checked", true); |
| 513 | $("#nitropack-smenabled-notice").parent().show(); |
| 514 | // Success notification |
| 515 | } else { |
| 516 | $("#safemode-status").attr("checked", false); |
| 517 | // Error notification |
| 518 | } |
| 519 | }); |
| 520 | } |
| 521 | |
| 522 | var disableSafemode = () => { |
| 523 | jQuery.post(ajaxurl, { |
| 524 | action: 'nitropack_disable_safemode' |
| 525 | }, function(response) { |
| 526 | var resp = JSON.parse(response); |
| 527 | if (resp.type == "success") { |
| 528 | // Success notification |
| 529 | $("#nitropack-smenabled-notice").parent().hide(); |
| 530 | } else { |
| 531 | // Error notification |
| 532 | } |
| 533 | }); |
| 534 | } |
| 535 | |
| 536 | |
| 537 | |
| 538 | var getOptimizations = _ => { |
| 539 | var url = '<?php echo $optimizationDetailsUrl; ?>'; |
| 540 | ((s, e, f) => { |
| 541 | if (window.fetch) { |
| 542 | fetch(url) |
| 543 | .then(resp => resp.json()) |
| 544 | .then(s) |
| 545 | .catch(e) |
| 546 | .finally(f); |
| 547 | } else { |
| 548 | $.ajax({ |
| 549 | url: url, |
| 550 | type: 'GET', |
| 551 | dataType: 'json', |
| 552 | success: s, |
| 553 | error: e, |
| 554 | complete: f |
| 555 | }) |
| 556 | } |
| 557 | })(data => { |
| 558 | $('[data-last-cache-purge]').text(data.last_cache_purge.timeAgo); |
| 559 | if (data.last_cache_purge.reason) { |
| 560 | $('[data-purge-reason]').text(data.last_cache_purge.reason); |
| 561 | $('#last-cache-purge-reason').show(); |
| 562 | } else { |
| 563 | $('#last-cache-purge-reason').hide(); |
| 564 | } |
| 565 | |
| 566 | if (data.pending_count) { |
| 567 | $("#pending-optimizations-count").text(data.pending_count); |
| 568 | $("#pending-optimizations-section").show(); |
| 569 | } else { |
| 570 | $("#pending-optimizations-section").hide(); |
| 571 | } |
| 572 | |
| 573 | $('[data-optimized-pages-desktop]').text(data.optimized_pages.desktop); |
| 574 | $('[data-optimized-pages-mobile]').text(data.optimized_pages.mobile); |
| 575 | $('[data-optimized-pages-tablet]').text(data.optimized_pages.tablet); |
| 576 | $('[data-optimized-pages-total]').text(data.optimized_pages.total); |
| 577 | |
| 578 | $("#optimizations-widget").cardOverlay("clear"); |
| 579 | }, __ => { |
| 580 | $("#optimizations-widget").cardOverlay("error", {message: "<?php esc_html_e( 'Error while fetching optimizations data', 'nitropack' ); ?>"}); |
| 581 | }, __ => { |
| 582 | if (!getOptimizationsTimeout) { |
| 583 | getOptimizationsTimeout = setTimeout(function() {getOptimizationsTimeout = null; getOptimizations();}, 60000); |
| 584 | } |
| 585 | }); |
| 586 | } |
| 587 | |
| 588 | var getPlan = _ => { |
| 589 | var url = '<?php echo $planDetailsUrl; ?>'; |
| 590 | ((s, e, f) => { |
| 591 | if (window.fetch) { |
| 592 | fetch(url) |
| 593 | .then(resp => resp.json()) |
| 594 | .then(s) |
| 595 | .catch(e) |
| 596 | .finally(f); |
| 597 | } else { |
| 598 | $.ajax({ |
| 599 | url: url, |
| 600 | type: 'GET', |
| 601 | dataType: 'json', |
| 602 | success: s, |
| 603 | error: e, |
| 604 | complete: f |
| 605 | }) |
| 606 | } |
| 607 | })(data => { |
| 608 | $('[data-plan-title]').text(data.plan_title); |
| 609 | $('[data-next-billing]').text(data.next_billing ? data.next_billing : 'N/A'); |
| 610 | $('[data-next-reset]').text(data.next_reset ? data.next_reset : 'N/A'); |
| 611 | |
| 612 | for (prop in data) { |
| 613 | if (prop.indexOf("show_") === 0) continue; |
| 614 | if (prop.indexOf("label_") === 0) continue; |
| 615 | if (prop.indexOf("max_") === 0) continue; |
| 616 | if ( |
| 617 | typeof data["show_" + prop] != "undefined" && |
| 618 | data["show_" + prop] && |
| 619 | typeof data["label_" + prop] != "undefined" && |
| 620 | typeof data["max_" + prop] != "undefined" |
| 621 | ) { |
| 622 | let propertyLabel = data["label_" + prop]; |
| 623 | let propertyValue = data[prop]; |
| 624 | let propertyLimit = data["max_" + prop]; |
| 625 | $("#plan-quotas").append('<li class="list-group-item px-0 d-flex justify-content-between align-items-center">' + propertyLabel + ' <span><span data-optimizations>' + propertyValue + '</span> out of <span data-max-optimizations>' + propertyLimit + '</span></span></li>'); |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | $("#plan-details-widget").cardOverlay("clear"); |
| 630 | }, __ => { |
| 631 | $("#plan-details-widget").cardOverlay("error", {message: "<?php esc_html_e( 'Error while fetching plan data', 'nitropack' ); ?>"}); |
| 632 | }, __ => { |
| 633 | }); |
| 634 | } |
| 635 | |
| 636 | var getQuickSetup = _ => { |
| 637 | var url = '<?php echo $quickSetupUrl; ?>'; |
| 638 | ((s, e, f) => { |
| 639 | if (window.fetch) { |
| 640 | fetch(url) |
| 641 | .then(resp => resp.json()) |
| 642 | .then(s) |
| 643 | .catch(e) |
| 644 | .finally(f); |
| 645 | } else { |
| 646 | $.ajax({ |
| 647 | url: url, |
| 648 | type: 'GET', |
| 649 | dataType: 'json', |
| 650 | success: s, |
| 651 | error: e, |
| 652 | complete: f |
| 653 | }) |
| 654 | } |
| 655 | })(data => { |
| 656 | $('#range').val(data.optimization_level); |
| 657 | $('#manual-settings-url').attr('href', data.manual_settings_url); |
| 658 | |
| 659 | document.getElementById('range').oninput(false); |
| 660 | $("#quicksetup-widget").cardOverlay("clear"); |
| 661 | }, __ => { |
| 662 | $("#quicksetup-widget").cardOverlay("error", {message: "<?php esc_html_e( 'Error while fetching the optimization level settings', 'nitropack' ); ?>"}); |
| 663 | }, __ => { |
| 664 | }); |
| 665 | } |
| 666 | |
| 667 | window.addEventListener("cache.invalidate.success", getOptimizations); |
| 668 | if ($('#np-onstate-cache-purge').length) { |
| 669 | window.addEventListener("cache.purge.success", function(){setTimeout(function(){document.cookie = "nitropack_apwarning=1; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=<?php echo nitropack_cookiepath(); ?>"; window.location.reload()}, 1500)}); |
| 670 | } else { |
| 671 | window.addEventListener("cache.purge.success", getOptimizations); |
| 672 | } |
| 673 | |
| 674 | |
| 675 | var autoDetectCompression = function() { |
| 676 | $("#settings-widget").cardOverlay("loading", {message: "<?php esc_html_e( 'Testing current compression status', 'nitropack' ); ?>"}); |
| 677 | |
| 678 | $.post(ajaxurl, { |
| 679 | action: 'nitropack_test_compression_ajax' |
| 680 | }, function(response) { |
| 681 | var resp = JSON.parse(response); |
| 682 | if (resp.status == "success") { |
| 683 | if (resp.hasCompression) { // compression already enabled |
| 684 | $("#compression-status").attr("checked", false); |
| 685 | $("#settings-widget").cardOverlay("success", {message: "<?php esc_html_e( 'Compression is already enabled on your server! There is no need to enable it in NitroPack.', 'nitropack' ); ?>", timeout: 3000}); |
| 686 | } else { // no compression - enable ours |
| 687 | $("#compression-status").attr("checked", true); |
| 688 | $("#settings-widget").cardOverlay("success", {message: "<?php esc_html_e( 'No compression was detected! We will now enable it in NitroPack.', 'nitropack' ); ?>", timeout: 3000}); |
| 689 | } |
| 690 | Notification.success('Compression settings saved'); |
| 691 | } else { |
| 692 | $("#settings-widget").cardOverlay("error", {message: "<?php esc_html_e( 'Could not determine compression status automatically. Please configure it manually.', 'nitropack' ); ?>", timeout: 3000}); |
| 693 | } |
| 694 | }); |
| 695 | } |
| 696 | |
| 697 | $("#compression-status").on("click", function(e) { |
| 698 | $.post(ajaxurl, { |
| 699 | action: 'nitropack_set_compression_ajax', |
| 700 | data: { |
| 701 | compressionStatus: $(this).is(":checked") ? 1 : 0 |
| 702 | } |
| 703 | }, function(response) { |
| 704 | Notification.success("<?php esc_html_e( 'Compression settings saved', 'nitropack' ); ?>"); |
| 705 | }); |
| 706 | }); |
| 707 | |
| 708 | $("#auto-purge-status").on("click", function(e) { |
| 709 | $.post(ajaxurl, { |
| 710 | action: 'nitropack_set_auto_cache_purge_ajax', |
| 711 | autoCachePurgeStatus: $(this).is(":checked") ? 1 : 0 |
| 712 | }, function(response) { |
| 713 | Notification.success("<?php esc_html_e( 'Automatic cache purge settings saved', 'nitropack' ); ?>"); |
| 714 | }); |
| 715 | }); |
| 716 | |
| 717 | $("#cart-cache-status").on("click", function(e) { |
| 718 | $.post(ajaxurl, { |
| 719 | action: 'nitropack_set_cart_cache_ajax', |
| 720 | cartCacheStatus: $(this).is(":checked") ? 1 : 0 |
| 721 | }, function(response) { |
| 722 | var resp = JSON.parse(response); |
| 723 | if (resp.type == "success") { |
| 724 | Notification.success(resp.message); |
| 725 | } else { |
| 726 | Notification.error(resp.message); |
| 727 | } |
| 728 | }); |
| 729 | }); |
| 730 | |
| 731 | $("#bb-purge-status").on("click", function(e) { |
| 732 | $.post(ajaxurl, { |
| 733 | action: 'nitropack_set_bb_cache_purge_sync_ajax', |
| 734 | bbCachePurgeSyncStatus: $(this).is(":checked") ? 1 : 0 |
| 735 | }, function(response) { |
| 736 | Notification.success("<?php esc_html_e( 'Beaver Builder cache purge sync settings are saved.', 'nitropack' ); ?>"); |
| 737 | }); |
| 738 | }); |
| 739 | |
| 740 | $("#legacy-purge-status").on("click", function(e) { |
| 741 | $.post(ajaxurl, { |
| 742 | action: 'nitropack_set_legacy_purge_ajax', |
| 743 | legacyPurgeStatus: $(this).is(":checked") ? 1 : 0 |
| 744 | }, function(response) { |
| 745 | Notification.success('Legacy cache purge settings are saved.'); |
| 746 | }); |
| 747 | }); |
| 748 | |
| 749 | $("#save-cacheable-post-types").on("click", function(e) { |
| 750 | $(this).find("i").removeClass("d-none"); |
| 751 | $.ajax({ |
| 752 | url: ajaxurl, |
| 753 | type: "POST", |
| 754 | data: { |
| 755 | action: 'nitropack_set_cacheable_post_types', |
| 756 | cacheableObjectTypes: $('.cacheable-post-type:checked').map(function(i, el){ return el.name; }).toArray() |
| 757 | }, |
| 758 | success: function() { |
| 759 | Notification.success("<?php esc_html_e( 'Changes saved', 'nitropack' ); ?>"); |
| 760 | }, |
| 761 | error: function() { |
| 762 | Notification.error("<?php esc_html_e( 'There was an error while saving the changes. Please try again.', 'nitropack' ); ?>"); |
| 763 | }, |
| 764 | complete: function() { |
| 765 | $("#save-cacheable-post-types i").addClass("d-none"); |
| 766 | $("#cacheable-post-types-modal").modal("hide"); |
| 767 | } |
| 768 | }); |
| 769 | }); |
| 770 | |
| 771 | $(document).on('click', "#compression-test-btn", e => { |
| 772 | e.preventDefault(); |
| 773 | |
| 774 | autoDetectCompression(); |
| 775 | }); |
| 776 | |
| 777 | window.confirmDisconnect = function() { |
| 778 | $("#settings-widget").cardOverlay("loading", {message: "<?php esc_html_e( 'Disconnecting...', 'nitropack' ); ?>"}); |
| 779 | $.ajax({ |
| 780 | url: ajaxurl, |
| 781 | type: "POST", |
| 782 | data: { |
| 783 | action: "nitropack_disconnect" |
| 784 | }, |
| 785 | complete: function() { |
| 786 | location.reload(); |
| 787 | } |
| 788 | }); |
| 789 | } |
| 790 | |
| 791 | window.closeModalOverlay = function() { |
| 792 | $("#settings-widget").cardOverlay("clear"); |
| 793 | } |
| 794 | |
| 795 | window.performCachePurge = () => { |
| 796 | purgeCache(); |
| 797 | closeModalOverlay(); |
| 798 | } |
| 799 | |
| 800 | $(document).on('click', "#disconnect-btn", e => { |
| 801 | e.preventDefault(); |
| 802 | |
| 803 | var confirmHtml = "<p><?php esc_html_e( 'Are you sure that you wish to disconnect?', 'nitropack' ); ?></p>"; |
| 804 | confirmHtml += '<p id="disconnectConfirmBtns"><a href="javascript:void(0);" onclick="closeModalOverlay()" class="btn btn-default btn-sm">No</a> <a href="javascript:void(0);" onclick="confirmDisconnect()" class="btn btn-info btn-sm">Disconnect</a></p>'; |
| 805 | $("#settings-widget").cardOverlay("notify", {message: confirmHtml}); |
| 806 | }); |
| 807 | |
| 808 | $("#warmup-status-slider").on("click", function(e) { |
| 809 | e.preventDefault(); |
| 810 | var isEnabled = $("#warmup-status").is(":checked"); |
| 811 | if (isEnabled) { |
| 812 | disableWarmup(); |
| 813 | $("#warmup-status").attr("checked", false); |
| 814 | } else { |
| 815 | estimateWarmup(); |
| 816 | } |
| 817 | }); |
| 818 | |
| 819 | var loadWarmupStatus = function() { |
| 820 | $.ajax({ |
| 821 | url: ajaxurl, |
| 822 | type: "POST", |
| 823 | data: { |
| 824 | action: "nitropack_warmup_stats" |
| 825 | }, |
| 826 | dataType: "json", |
| 827 | success: function(resp) { |
| 828 | if (resp.type == "success") { |
| 829 | $("#warmup-status").attr("checked", !!resp.stats.status); |
| 830 | $("#loading-warmup-status").hide(); |
| 831 | $("#warmup-toggle").show(); |
| 832 | } else { |
| 833 | setTimeout(loadWarmupStatus, 500); |
| 834 | } |
| 835 | } |
| 836 | }); |
| 837 | } |
| 838 | loadWarmupStatus(); |
| 839 | |
| 840 | $("#safemode-status-slider").on("click", function (e) { |
| 841 | e.preventDefault(); |
| 842 | let isEnabled = $("#safemode-status").is(":checked"); |
| 843 | if (isEnabled) { |
| 844 | let confirmHtml = '<p><strong>Purge Cache?</strong></p>' + |
| 845 | '<p>It is recommended to perform a full cache purge so all changes are correctly applied.</p>' + |
| 846 | '<p>Would you like to purge the cache now?</p>' + |
| 847 | '<p><a href="javascript:void(0);" onclick="closeModalOverlay()" class="btn btn-default btn-sm">No</a> <a href="javascript:void(0);" onclick="performCachePurge()" class="btn btn-info btn-sm">Yes (Recommended)</a></p>'; |
| 848 | $("#settings-widget").cardOverlay("notify", {message: confirmHtml, dismissable: false}); |
| 849 | disableSafemode(); |
| 850 | $("#safemode-status").attr("checked", false); |
| 851 | } else { |
| 852 | enableSafemode(); |
| 853 | $("#safemode-status").attr("checked", true); |
| 854 | } |
| 855 | }); |
| 856 | |
| 857 | var loadSafemodeStatus = function() { |
| 858 | $.ajax({ |
| 859 | url: ajaxurl, |
| 860 | type: "POST", |
| 861 | data: { |
| 862 | action: "nitropack_safemode_status" |
| 863 | }, |
| 864 | dataType: "json", |
| 865 | success: function(resp) { |
| 866 | if (resp.type == "success") { |
| 867 | $("#safemode-status").attr("checked", !!resp.isEnabled); |
| 868 | $("#nitropack-smenabled-notice").length && !!resp.isEnabled ? $("#nitropack-smenabled-notice").parent().show() : $("#nitropack-smenabled-notice").parent().hide(); |
| 869 | $("#loading-safemode-status").hide(); |
| 870 | $("#safemode-toggle").show(); |
| 871 | } else { |
| 872 | setTimeout(loadSafemodeStatus, 500); |
| 873 | } |
| 874 | } |
| 875 | }); |
| 876 | } |
| 877 | loadSafemodeStatus(); |
| 878 | })(jQuery); |
| 879 | |
| 880 | (_ => { |
| 881 | const classIndex = { |
| 882 | 1: 'range-success', |
| 883 | 2: 'range-warning', |
| 884 | 3: 'range-danger', |
| 885 | 4: 'range-ludicrous', |
| 886 | 5: 'range-manual', |
| 887 | }; |
| 888 | |
| 889 | let rangeInputElement = document.getElementById('range'); |
| 890 | |
| 891 | let className = document.getElementsByClassName("label"); |
| 892 | |
| 893 | let min = parseInt(rangeInputElement.min); |
| 894 | let max = parseInt(rangeInputElement.max); |
| 895 | |
| 896 | const atTimeout = (_ => { |
| 897 | var timeout; |
| 898 | |
| 899 | return (callback, time) => { |
| 900 | clearTimeout(timeout); |
| 901 | timeout = setTimeout(callback, time) |
| 902 | }; |
| 903 | })(); |
| 904 | |
| 905 | const saveSetting = function(value) { |
| 906 | return new Promise((resolve, reject) => { |
| 907 | var xhr = new XMLHttpRequest(); |
| 908 | |
| 909 | xhr.open("POST", '<?php echo $quickSetupSaveUrl; ?>', true); |
| 910 | |
| 911 | //Send the proper header information along with the request |
| 912 | xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); |
| 913 | |
| 914 | xhr.onreadystatechange = function() { // Call a function when the state changes. |
| 915 | if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { |
| 916 | resolve(); |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | xhr.send("setting=" + value); |
| 921 | }); |
| 922 | } |
| 923 | |
| 924 | let changeMode = function(do_save) { |
| 925 | |
| 926 | let children = document.getElementById('description').children; |
| 927 | let shown; |
| 928 | |
| 929 | if(this.getAttribute("value")) { |
| 930 | shown = parseInt(this.getAttribute("value")); |
| 931 | } |
| 932 | if(this.value) { |
| 933 | shown = parseInt(this.value); |
| 934 | } |
| 935 | |
| 936 | for (var i = 0; i < children.length; i++) { |
| 937 | children.item(i).classList.toggle('hidden', i != shown); |
| 938 | } |
| 939 | |
| 940 | document.getElementById('range').classList.remove('range-success', 'range-warning', 'range-danger', 'range-ludicrous', 'range-manual'); |
| 941 | |
| 942 | rangeInputElement.value = shown; |
| 943 | |
| 944 | if (classIndex[shown]) { |
| 945 | document.getElementById('range').classList.add(classIndex[shown]); |
| 946 | } |
| 947 | |
| 948 | if (do_save) { |
| 949 | atTimeout(async function() { |
| 950 | jQuery("#quicksetup-widget").cardOverlay("loading", {message: "Saving..."}); |
| 951 | await saveSetting(shown); |
| 952 | jQuery("#quicksetup-widget").cardOverlay("clear"); |
| 953 | }, 0); |
| 954 | } |
| 955 | }; |
| 956 | |
| 957 | rangeInputElement.oninput = changeMode; |
| 958 | //rangeInputElement.oninput(false); |
| 959 | |
| 960 | for (var i = min; i <= max; i++) { |
| 961 | let divisor = document.createElement('div'); |
| 962 | let textDescription = document.getElementById('description').children.item(i).getElementsByTagName('p').item(0).textContent; |
| 963 | |
| 964 | let label = document.createElement('div'); |
| 965 | |
| 966 | divisor.classList.add("divisor"); |
| 967 | document.getElementById('divisors').appendChild(divisor); |
| 968 | |
| 969 | label.setAttribute('data-toggle', 'tooltip'); |
| 970 | label.setAttribute('data-placement', 'top'); |
| 971 | label.setAttribute('title', textDescription); |
| 972 | label.setAttribute('value', i); |
| 973 | label.textContent = document.getElementById('description').children.item(i).getElementsByTagName('h6').item(0).textContent; |
| 974 | label.classList.add("label"); |
| 975 | document.getElementById('labels').appendChild(label); |
| 976 | } |
| 977 | |
| 978 | |
| 979 | for (var i = 0; i < className.length; i++) { |
| 980 | className[i].addEventListener('click', changeMode, false); |
| 981 | } |
| 982 | })(); |
| 983 | </script> |
| 984 |