first
This commit is contained in:
@ -0,0 +1,26 @@
|
||||
var ewww_webp_supported = false;
|
||||
// webp detection adapted from https://developers.google.com/speed/webp/faq#how_can_i_detect_browser_support_using_javascript
|
||||
function check_webp_feature(feature, callback) {
|
||||
callback = (typeof callback !== 'undefined') ? callback : function(){};
|
||||
if (ewww_webp_supported) {
|
||||
callback(ewww_webp_supported);
|
||||
return;
|
||||
}
|
||||
var kTestImages = {
|
||||
alpha: "UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAARBxAR/Q9ERP8DAABWUDggGAAAABQBAJ0BKgEAAQAAAP4AAA3AAP7mtQAAAA==",
|
||||
};
|
||||
var img = new Image();
|
||||
img.onload = function () {
|
||||
ewww_webp_supported = (img.width > 0) && (img.height > 0);
|
||||
if (callback) {
|
||||
callback(ewww_webp_supported);
|
||||
}
|
||||
};
|
||||
img.onerror = function () {
|
||||
if (callback) {
|
||||
callback(false);
|
||||
}
|
||||
};
|
||||
img.src = "data:image/webp;base64," + kTestImages[feature];
|
||||
}
|
||||
check_webp_feature('alpha');
|
1
wp-content/plugins/ewww-image-optimizer/includes/check-webp.min.js
vendored
Normal file
1
wp-content/plugins/ewww-image-optimizer/includes/check-webp.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
var ewww_webp_supported=!1;function check_webp_feature(A,e){var w;e=void 0!==e?e:function(){},ewww_webp_supported?e(ewww_webp_supported):((w=new Image).onload=function(){ewww_webp_supported=0<w.width&&0<w.height,e&&e(ewww_webp_supported)},w.onerror=function(){e&&e(!1)},w.src="data:image/webp;base64,"+{alpha:"UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAARBxAR/Q9ERP8DAABWUDggGAAAABQBAJ0BKgEAAQAAAP4AAA3AAP7mtQAAAA=="}[A])}check_webp_feature("alpha");
|
@ -0,0 +1,64 @@
|
||||
jQuery(document).ready(function($) {
|
||||
$('#ewww-copy-debug').on( 'click', function() {
|
||||
selectText('ewww-debug-info');
|
||||
try {
|
||||
var successful = document.execCommand('copy');
|
||||
if ( successful ) {
|
||||
unselectText();
|
||||
}
|
||||
} catch(err) {
|
||||
console.log('browser cannot copy');
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
function HSregister() {
|
||||
if (typeof(Beacon) !== 'undefined' ) {
|
||||
$('.ewww-overrides-nav').on( 'click', function() {
|
||||
Beacon('article', '59710ce4042863033a1b45a6', { type: 'modal' });
|
||||
return false;
|
||||
});
|
||||
$('.ewww-contact-root').on( 'click', function() {
|
||||
Beacon('navigate', '/ask/')
|
||||
Beacon('open');
|
||||
return false;
|
||||
});
|
||||
$('.ewww-docs-root').on( 'click', function() {
|
||||
Beacon('navigate', '/answers/')
|
||||
Beacon('open');
|
||||
return false;
|
||||
});
|
||||
$('.ewww-help-beacon-multi').on( 'click', function() {
|
||||
var hsids = $(this).attr('data-beacon-articles');
|
||||
hsids = hsids.split(',');
|
||||
Beacon('suggest', hsids);
|
||||
Beacon('navigate', '/answers/');
|
||||
Beacon('open');
|
||||
return false;
|
||||
});
|
||||
$('.ewww-help-beacon-single').on( 'click', function() {
|
||||
var hsid = $(this).attr('data-beacon-article');
|
||||
Beacon('article', hsid, { type: 'modal' });
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
HSregister();
|
||||
});
|
||||
function selectText(containerid) {
|
||||
var debug_node = document.getElementById(containerid);
|
||||
if (document.selection) {
|
||||
var range = document.body.createTextRange();
|
||||
range.moveToElementText(debug_node);
|
||||
range.select();
|
||||
} else if (window.getSelection) {
|
||||
window.getSelection().selectAllChildren(debug_node);
|
||||
}
|
||||
}
|
||||
function unselectText() {
|
||||
var sel;
|
||||
if ( (sel = document.selection) && sel.empty) {
|
||||
sel.empty();
|
||||
} else if (window.getSelection) {
|
||||
window.getSelection().removeAllRanges();
|
||||
}
|
||||
}
|
445
wp-content/plugins/ewww-image-optimizer/includes/eio-bulk.js
Normal file
445
wp-content/plugins/ewww-image-optimizer/includes/eio-bulk.js
Normal file
@ -0,0 +1,445 @@
|
||||
jQuery(document).ready(function($) {
|
||||
var ewww_error_counter = 30;
|
||||
$("#ewww-delay-slider").slider({
|
||||
min: 0,
|
||||
max: 30,
|
||||
value: $("#ewww-delay").val(),
|
||||
slide: function(event, ui) {
|
||||
$("#ewww-delay").val(ui.value);
|
||||
}
|
||||
});
|
||||
var ewwwdelayinput = document.getElementById("ewww-delay");
|
||||
if (ewwwdelayinput) {
|
||||
ewwwdelayinput.onblur = function() {
|
||||
if (isNaN(this.value)) {
|
||||
this.value = 0;
|
||||
} else {
|
||||
this.value = Math.ceil(this.value);
|
||||
}
|
||||
};
|
||||
}
|
||||
var ewww_attachments = ewww_vars.attachments;
|
||||
var ewww_i = 0;
|
||||
var ewww_k = 0;
|
||||
var ewww_import_total = 0;
|
||||
var ewww_force = 0;
|
||||
var ewww_force_smart = 0;
|
||||
var ewww_webp_only = 0;
|
||||
var ewww_delay = 0;
|
||||
var ewww_batch_limit = 0;
|
||||
var ewww_aux = false;
|
||||
var ewww_main = false;
|
||||
var ewww_quota_update = 0;
|
||||
var ewww_scan_failures = 0;
|
||||
var ewww_bulk_start_time = 0;
|
||||
var ewww_bulk_elapsed_time = 0;
|
||||
var ewww_time_per_image = 0;
|
||||
var ewww_time_remaining = 0;
|
||||
var ewww_days_remaining = 0;
|
||||
var ewww_hours_remaining = 0;
|
||||
var ewww_minutes_remaining = 0;
|
||||
var ewww_seconds_remaining = 0;
|
||||
var ewww_countdown = false;
|
||||
var ewww_tiny_skip = '';
|
||||
// initialize the ajax actions for the appropriate bulk page
|
||||
var ewww_quota_update_data = {
|
||||
action: 'bulk_quota_update',
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
};
|
||||
if (ewww_vars.gallery == 'flag') {
|
||||
var ewww_init_action = 'bulk_flag_init';
|
||||
var ewww_loop_action = 'bulk_flag_loop';
|
||||
var ewww_cleanup_action = 'bulk_flag_cleanup';
|
||||
} else if (ewww_vars.gallery == 'nextgen') {
|
||||
var ewww_preview_action = 'bulk_ngg_preview';
|
||||
var ewww_init_action = 'bulk_ngg_init';
|
||||
var ewww_loop_action = 'bulk_ngg_loop';
|
||||
var ewww_cleanup_action = 'bulk_ngg_cleanup';
|
||||
} else {
|
||||
var ewww_scan_action = 'bulk_scan';
|
||||
var ewww_init_action = 'bulk_init';
|
||||
var ewww_loop_action = 'bulk_loop';
|
||||
var ewww_cleanup_action = 'bulk_cleanup';
|
||||
ewww_main = true;
|
||||
}
|
||||
var ewww_init_data = {
|
||||
action: ewww_init_action,
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
};
|
||||
var ewww_table_action = 'bulk_aux_images_table';
|
||||
var ewww_table_count_action = 'bulk_aux_images_table_count';
|
||||
var ewww_import_init_action = 'bulk_import_init';
|
||||
var ewww_import_loop_action = 'bulk_import_loop';
|
||||
$(document).on('click', '.ewww-show-debug-meta', function() {
|
||||
var post_id = $(this).data('id');
|
||||
$('.ewww-debug-meta-' + post_id).toggle();
|
||||
});
|
||||
$('.ewww-hndle').click(function() {
|
||||
return;
|
||||
$(this).next('.inside').toggle();
|
||||
var button = $(this).prev('.button-link');
|
||||
if ('true' == button.attr('aria-expanded')) {
|
||||
button.attr('aria-expanded', 'false');
|
||||
button.closest('.postbox').addClass('closed');
|
||||
button.children('.toggle-indicator').attr('aria-hidden', 'true');
|
||||
} else {
|
||||
button.attr('aria-expanded', 'true');
|
||||
button.closest('.postbox').removeClass('closed');
|
||||
button.children('.toggle-indicator').attr('aria-hidden', 'false');
|
||||
}
|
||||
});
|
||||
$('.ewww-handlediv').click(function() {
|
||||
$(this).parent().children('.inside').toggle();
|
||||
if ('true' == $(this).attr('aria-expanded')) {
|
||||
$(this).attr('aria-expanded', 'false');
|
||||
$(this).closest('.postbox').addClass('closed');
|
||||
$(this).children('.toggle-indicator').attr('aria-hidden', 'true');
|
||||
} else {
|
||||
$(this).attr('aria-expanded', 'true');
|
||||
$(this).closest('.postbox').removeClass('closed');
|
||||
$(this).children('.toggle-indicator').attr('aria-hidden', 'false');
|
||||
}
|
||||
});
|
||||
$('#ewww-aux-start').submit(function() {
|
||||
ewww_aux = true;
|
||||
if ($('#ewww-force:checkbox:checked').val()) {
|
||||
ewww_force = 1;
|
||||
}
|
||||
if ($('#ewww-force-smart:checkbox:checked').val()) {
|
||||
ewww_force_smart = 1;
|
||||
}
|
||||
if ($('#ewww-webp-only:checkbox:checked').val()) {
|
||||
ewww_webp_only = 1;
|
||||
}
|
||||
$('#ewww-aux-start').hide();
|
||||
$('.ewww-bulk-info').hide();
|
||||
$('.ewww-aux-table').hide();
|
||||
$('#ewww-show-table').hide();
|
||||
$('#ewww-scanning').show();
|
||||
ewwwStartScan();
|
||||
return false;
|
||||
});
|
||||
function ewwwStartScan() {
|
||||
var ewww_scan_data = {
|
||||
action: ewww_scan_action,
|
||||
ewww_force: ewww_force,
|
||||
ewww_force_smart: ewww_force_smart,
|
||||
ewww_webp_only: ewww_webp_only,
|
||||
ewww_scan: true,
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
};
|
||||
$.post(ajaxurl, ewww_scan_data, function(response) {
|
||||
var is_json = true;
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
is_json = false;
|
||||
}
|
||||
if ( ! is_json ) {
|
||||
$('#ewww-scanning').html('<span class="ewww-bulk-error"><b>' + ewww_vars.invalid_response + '</b></span>');
|
||||
console.log( response );
|
||||
return false;
|
||||
}
|
||||
ewww_init_data = {
|
||||
action: ewww_init_action,
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
};
|
||||
if ( ewww_response.error ) {
|
||||
$('#ewww-scanning').html('<span class="ewww-bulk-error"><b>' + ewww_response.error + '</b></span>');
|
||||
} else if ( ewww_response.remaining ) {
|
||||
$('.ewww-aux-table').hide();
|
||||
$('#ewww-show-table').hide();
|
||||
//if ( ! ewww_response.notice ) {
|
||||
// ewww_response.notice = '';
|
||||
//}
|
||||
$('#ewww-scanning').html( ewww_response.remaining );
|
||||
if ( ewww_response.notice ) {
|
||||
$('#ewww-scanning').append( '<br>' + ewww_response.notice );
|
||||
}
|
||||
if ( ewww_response.tiny_skip ) {
|
||||
$('#ewww-scanning').append( '<br>' + ewww_response.tiny_skip );
|
||||
ewww_tiny_skip = ewww_response.tiny_skip;
|
||||
console.log( 'skipped some tiny images' );
|
||||
}
|
||||
if ( ewww_response.bad_attachment ) {
|
||||
$('#ewww-scanning').append( '<br>' + ewww_vars.bad_attachment + ' ' + ewww_response.bad_attachment );
|
||||
}
|
||||
ewww_scan_failures = 0;
|
||||
ewwwStartScan();
|
||||
} else if ( ewww_response.ready ) {
|
||||
ewww_attachments = ewww_response.ready;
|
||||
$('#ewww-scanning').html(ewww_response.message);
|
||||
if ( ewww_tiny_skip ) {
|
||||
$('#ewww-scanning').append( '<br><i>' + ewww_tiny_skip + '</i>' );
|
||||
console.log( 'done, skipped some tiny images' );
|
||||
}
|
||||
$('#ewww-bulk-first').val(ewww_response.start_button);
|
||||
$('#ewww-bulk-start').show();
|
||||
} else if ( ewww_response.ready === 0 ) {
|
||||
$('#ewww-scanning').hide();
|
||||
$('#ewww-nothing').show();
|
||||
if ( ewww_tiny_skip ) {
|
||||
$('#ewww-nothing').append( '<br><i>' + ewww_tiny_skip + '</i>' );
|
||||
console.log( 'done, skipped some tiny images' );
|
||||
}
|
||||
}
|
||||
})
|
||||
.fail(function() {
|
||||
ewww_scan_failures++;
|
||||
if (ewww_scan_failures > 10) {
|
||||
$('#ewww-scanning').html('<span class="ewww-bulk-error"><b>' + ewww_vars.scan_fail + ':</b> ' + ewww_vars.bulk_fail_more + '</span>');
|
||||
} else {
|
||||
$('#ewww-scanning').html('<span class="ewww-bulk-error"><b>' + ewww_vars.scan_incomplete + '</b></span>');
|
||||
setTimeout(function() {
|
||||
ewwwStartScan();
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
}
|
||||
$('#ewww-bulk-start').submit(function() {
|
||||
ewwwStartOpt();
|
||||
return false;
|
||||
});
|
||||
function ewwwUpdateQuota() {
|
||||
if ($('#ewww-bulk-credits-available').length > 0) {
|
||||
ewww_quota_update_data.ewww_wpnonce = ewww_vars._wpnonce;
|
||||
$.post(ajaxurl, ewww_quota_update_data, function(response) {
|
||||
$('#ewww-bulk-credits-available').html(response);
|
||||
});
|
||||
}
|
||||
}
|
||||
function ewwwStartOpt () {
|
||||
ewww_k = 0;
|
||||
ewww_quota_update = setInterval( ewwwUpdateQuota, 60000 );
|
||||
$('#ewww-bulk-stop').submit(function() {
|
||||
ewww_k = 9;
|
||||
$('#ewww-bulk-stop').hide();
|
||||
return false;
|
||||
});
|
||||
if ( ! $('#ewww-delay').val().match( /^[1-9][0-9]*$/) ) {
|
||||
ewww_delay = 0;
|
||||
} else {
|
||||
ewww_delay = $('#ewww-delay').val();
|
||||
}
|
||||
if (ewww_delay) {
|
||||
ewww_batch_limit = 1;
|
||||
$('#ewww-bulk-last h2').html( ewww_vars.last_image_header );
|
||||
}
|
||||
$('.ewww-aux-table').hide();
|
||||
$('#ewww-bulk-stop').show();
|
||||
$('.ewww-bulk-form').hide();
|
||||
$('.ewww-bulk-info').hide();
|
||||
$('#ewww-bulk-forms').hide();
|
||||
$('h2').hide();
|
||||
$.post(ajaxurl, ewww_init_data, function(response) {
|
||||
var is_json = true;
|
||||
try {
|
||||
var ewww_init_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
is_json = false;
|
||||
}
|
||||
if ( ! is_json || ! response ) {
|
||||
$('#ewww-bulk-loading').append('<p class="ewww-bulk-error"><b>' + ewww_vars.invalid_response + '</b></p>');
|
||||
console.log( response );
|
||||
return false;
|
||||
}
|
||||
if ( ewww_init_response.error ) {
|
||||
$('#ewww-bulk-loading').append('<p class="ewww-bulk-error"><b>' + ewww_init_response.error + '</b></p>');
|
||||
if ( ewww_init_response.data ) {
|
||||
console.log( ewww_init_response.data );
|
||||
}
|
||||
} else {
|
||||
if ( ewww_init_response.start_time ) {
|
||||
ewww_bulk_start_time = ewww_init_response.start_time;
|
||||
}
|
||||
$('#ewww-bulk-loading').html(ewww_init_response.results);
|
||||
$('#ewww-bulk-progressbar').progressbar({ max: ewww_attachments });
|
||||
$('#ewww-bulk-counter').html( ewww_vars.optimized + ' 0/' + ewww_attachments);
|
||||
ewwwProcessImage();
|
||||
}
|
||||
});
|
||||
}
|
||||
function ewwwProcessImage() {
|
||||
if ($('#ewww-force:checkbox:checked').val()) {
|
||||
ewww_force = 1;
|
||||
}
|
||||
if ($('#ewww-force-smart:checkbox:checked').val()) {
|
||||
ewww_force_smart = 1;
|
||||
}
|
||||
if ($('#ewww-webp-only:checkbox:checked').val()) {
|
||||
ewww_webp_only = 1;
|
||||
}
|
||||
var ewww_loop_data = {
|
||||
action: ewww_loop_action,
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
ewww_force: ewww_force,
|
||||
ewww_force_smart: ewww_force_smart,
|
||||
ewww_webp_only: ewww_webp_only,
|
||||
ewww_batch_limit: ewww_batch_limit,
|
||||
ewww_error_counter: ewww_error_counter,
|
||||
};
|
||||
var ewww_jqxhr = $.post(ajaxurl, ewww_loop_data, function(response) {
|
||||
var is_json = true;
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
is_json = false;
|
||||
}
|
||||
if ( ! is_json || ! response ) {
|
||||
$('#ewww-bulk-loading').append('<p class="ewww-bulk-error"><b>' + ewww_vars.invalid_response + '</b></p>');
|
||||
clearInterval(ewww_quota_update);
|
||||
clearInterval(ewww_countdown);
|
||||
if ( ! response ) {
|
||||
console.log( 'empty response' );
|
||||
} else {
|
||||
console.log( response );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
ewww_i += ewww_response.completed;
|
||||
$('#ewww-bulk-progressbar').progressbar( "option", "value", ewww_i );
|
||||
$('#ewww-bulk-counter').html(ewww_vars.optimized + ' ' + ewww_i + '/' + ewww_attachments);
|
||||
if ( ewww_response.update_meta ) {
|
||||
var ewww_updatemeta_data = {
|
||||
action: 'ewww_bulk_update_meta',
|
||||
attachment_id: ewww_response.update_meta,
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
};
|
||||
$.post(ajaxurl, ewww_updatemeta_data);
|
||||
}
|
||||
if ( ewww_response.error ) {
|
||||
$('#ewww-bulk-loading img').hide();
|
||||
$('#ewww-bulk-progressbar').hide();
|
||||
$('#ewww-bulk-timer').hide();
|
||||
$('#ewww-bulk-counter').hide();
|
||||
$('#ewww-bulk-stop').hide();
|
||||
$('#ewww-bulk-loading').append('<p class="ewww-bulk-error"><b>' + ewww_response.error + '</b></p>');
|
||||
clearInterval(ewww_quota_update);
|
||||
clearInterval(ewww_countdown);
|
||||
ewwwUpdateQuota();
|
||||
}
|
||||
else if (ewww_k == 9) {
|
||||
if ( ewww_response.results ) {
|
||||
$('#ewww-bulk-last .inside').html( ewww_response.results );
|
||||
$('#ewww-bulk-status .inside').append( ewww_response.results );
|
||||
}
|
||||
clearInterval(ewww_quota_update);
|
||||
clearInterval(ewww_countdown);
|
||||
$('#ewww-bulk-loading').html('<p class="ewww-bulk-error"><b>' + ewww_vars.operation_stopped + '</b></p>');
|
||||
}
|
||||
else if ( response == 0 ) {
|
||||
clearInterval(ewww_quota_update);
|
||||
clearInterval(ewww_countdown);
|
||||
$('#ewww-bulk-loading').html('<p class="ewww-bulk-error"><b>' + ewww_vars.operation_stopped + '</b></p>');
|
||||
}
|
||||
else if ( ewww_i < ewww_attachments && ! ewww_response.done ) {
|
||||
if ( ewww_bulk_start_time && ewww_response.current_time ) {
|
||||
ewww_bulk_elapsed_time = ewww_response.current_time - ewww_bulk_start_time;
|
||||
ewww_time_per_image = ewww_bulk_elapsed_time / ewww_i;
|
||||
ewww_time_remaining = Math.floor((ewww_attachments - ewww_i) * ewww_time_per_image);
|
||||
ewwwTimeIncrementsUpdate();
|
||||
if ( ! ewww_countdown) {
|
||||
$('#ewww-bulk-timer').html(ewww_days_remaining + ':' + ewww_hours_remaining + ':' + ewww_minutes_remaining + ':' + ewww_seconds_remaining + ' ' + ewww_vars.time_remaining);
|
||||
ewww_countdown = setInterval( ewwwCountDown, 1000 );
|
||||
}
|
||||
}
|
||||
$('#ewww-bulk-widgets').show();
|
||||
$('#ewww-bulk-status h2').show();
|
||||
$('#ewww-bulk-last h2').show();
|
||||
if ( ewww_response.results ) {
|
||||
$('#ewww-bulk-last .inside').html( ewww_response.results );
|
||||
$('#ewww-bulk-status .inside').append( ewww_response.results );
|
||||
}
|
||||
if ( ewww_response.next_file ) {
|
||||
$('#ewww-bulk-loading').html(ewww_response.next_file);
|
||||
}
|
||||
if ( ewww_response.new_nonce ) {
|
||||
ewww_vars._wpnonce = ewww_response.new_nonce;
|
||||
}
|
||||
ewww_error_counter = 30;
|
||||
setTimeout(ewwwProcessImage, ewww_delay * 1000);
|
||||
}
|
||||
else {
|
||||
if ( ewww_response.results ) {
|
||||
$('#ewww-bulk-widgets').show();
|
||||
$('#ewww-bulk-status h2').show();
|
||||
$('#ewww-bulk-status .inside').append( ewww_response.results );
|
||||
}
|
||||
var ewww_cleanup_data = {
|
||||
action: ewww_cleanup_action,
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
};
|
||||
$.post(ajaxurl, ewww_cleanup_data, function(response) {
|
||||
$('#ewww-bulk-loading').html(response);
|
||||
$('#ewww-bulk-stop').hide();
|
||||
$('#ewww-bulk-last').hide();
|
||||
ewwwAuxCleanup();
|
||||
});
|
||||
}
|
||||
})
|
||||
.fail(function() {
|
||||
if (ewww_error_counter == 0) {
|
||||
$('#ewww-bulk-loading').html('<p class="ewww-bulk-error"><b>' + ewww_vars.operation_interrupted + ':</b> ' + ewww_vars.bulk_fail_more + '</p>');
|
||||
} else {
|
||||
$('#ewww-bulk-loading').html('<p class="ewww-bulk-error"><b>' + ewww_vars.temporary_failure + ' ' + ewww_error_counter + ' (' + ewww_vars.bulk_fail_more + ')</b></p>');
|
||||
ewww_error_counter--;
|
||||
setTimeout(function() {
|
||||
ewwwProcessImage();
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
}
|
||||
function ewwwAuxCleanup() {
|
||||
if (ewww_main == true) {
|
||||
clearInterval(ewww_quota_update);
|
||||
clearInterval(ewww_countdown);
|
||||
var ewww_table_count_data = {
|
||||
action: ewww_table_count_action,
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
ewww_inline: 1,
|
||||
};
|
||||
$.post(ajaxurl, ewww_table_count_data, function(response) {
|
||||
ewww_vars.image_count = response;
|
||||
});
|
||||
$('#ewww-show-table').show();
|
||||
$('#ewww-table-info').show();
|
||||
$('#ewww-bulk-timer').hide();
|
||||
if (ewww_aux == true) {
|
||||
$('#ewww-aux-first').hide();
|
||||
} else {
|
||||
$('#ewww-bulk-first').hide();
|
||||
}
|
||||
ewww_attachments = ewww_vars.attachments;
|
||||
ewww_init_action = 'bulk_init';
|
||||
ewww_filename_action = 'bulk_filename';
|
||||
ewww_loop_action = 'bulk_loop';
|
||||
ewww_cleanup_action = 'bulk_cleanup';
|
||||
ewww_init_data = {
|
||||
action: ewww_init_action,
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
};
|
||||
ewww_aux = false;
|
||||
ewww_i = 0;
|
||||
ewww_force = 0;
|
||||
ewww_force_smart = 0;
|
||||
ewww_webp_only = 0;
|
||||
}
|
||||
}
|
||||
function ewwwCountDown() {
|
||||
if (ewww_time_remaining > 1) {
|
||||
ewww_time_remaining--;
|
||||
}
|
||||
ewwwTimeIncrementsUpdate();
|
||||
$('#ewww-bulk-timer').html(ewww_days_remaining + ':' + ewww_hours_remaining + ':' + ewww_minutes_remaining + ':' + ewww_seconds_remaining + ' ' + ewww_vars.time_remaining);
|
||||
}
|
||||
function ewwwTimeIncrementsUpdate() {
|
||||
ewww_days_remaining = Math.floor(ewww_time_remaining / 86400);
|
||||
ewww_hours_remaining = Math.floor((ewww_time_remaining - (ewww_days_remaining * 86400)) / 3600);
|
||||
ewww_minutes_remaining = Math.floor((ewww_time_remaining - (ewww_days_remaining * 86400) - (ewww_hours_remaining * 3600)) / 60);
|
||||
ewww_seconds_remaining = ewww_time_remaining - (ewww_days_remaining * 86400) - (ewww_hours_remaining * 3600) - (ewww_minutes_remaining * 60);
|
||||
if (ewww_days_remaining < 10) { ewww_days_remaining = '0'+ewww_days_remaining; }
|
||||
if (ewww_hours_remaining < 10) { ewww_hours_remaining = '0'+ewww_hours_remaining; }
|
||||
if (ewww_minutes_remaining < 10) { ewww_minutes_remaining = '0'+ewww_minutes_remaining; }
|
||||
if (ewww_seconds_remaining < 10) { ewww_seconds_remaining = '0'+ewww_seconds_remaining; }
|
||||
}
|
||||
});
|
730
wp-content/plugins/ewww-image-optimizer/includes/eio-settings.js
Normal file
730
wp-content/plugins/ewww-image-optimizer/includes/eio-settings.js
Normal file
@ -0,0 +1,730 @@
|
||||
jQuery(document).ready(function($) {
|
||||
// Wizard bits:
|
||||
$('input:radio[name="ewww_image_optimizer_budget"]').on(
|
||||
'change',
|
||||
function() {
|
||||
if (this.checked && this.value === 'pay') {
|
||||
$('.ewwwio-premium-setup').show();
|
||||
} else {
|
||||
$('.ewwwio-premium-setup').hide();
|
||||
$('#ewww-image-optimizer-warning-opt-missing').show();
|
||||
$('#ewww-image-optimizer-warning-exec').show();
|
||||
}
|
||||
}
|
||||
);
|
||||
var ewww_wizard_required_checkboxes = $('#ewwwio-wizard-step-1 :checkbox[required]');
|
||||
ewww_wizard_required_checkboxes.on(
|
||||
'change',
|
||||
function() {
|
||||
if (ewww_wizard_required_checkboxes.is(':checked')) {
|
||||
ewww_wizard_required_checkboxes.removeAttr('required');
|
||||
} else {
|
||||
ewww_wizard_required_checkboxes.attr('required', 'required');
|
||||
}
|
||||
}
|
||||
);
|
||||
$('#ewwwio-wizard-step-1').on(
|
||||
'submit',
|
||||
function() {
|
||||
return;
|
||||
$(this).hide();
|
||||
$('#ewwwio-wizard-step-2').show();
|
||||
return false;
|
||||
}
|
||||
);
|
||||
$('.ewwwio-wizard-back').on(
|
||||
'click',
|
||||
function() {
|
||||
return;
|
||||
$('#ewwwio-wizard-step-2').hide();
|
||||
$('#ewwwio-wizard-step-1').show();
|
||||
return false;
|
||||
}
|
||||
);
|
||||
function removeQueryArg(url) {
|
||||
return url.split('?')[0];
|
||||
}
|
||||
$('.fade').fadeTo(5000,1).fadeOut(3000);
|
||||
var speed_bar_width = $('#ewww-speed-fill').data('score');
|
||||
$('#ewww-speed-fill').animate( {
|
||||
width: speed_bar_width + '%',
|
||||
}, 1000 );
|
||||
var ewww_save_bar_width = $('#ewww-savings-fill').data('score');
|
||||
$('#ewww-savings-fill').animate( {
|
||||
width: ewww_save_bar_width + '%',
|
||||
}, 1000 );
|
||||
var easy_save_bar_width = $('#easyio-savings-fill').data('score');
|
||||
$('#easyio-savings-fill').animate( {
|
||||
width: easy_save_bar_width + '%',
|
||||
}, 1000 );
|
||||
$('#ewww-show-recommendations a').on(
|
||||
'click',
|
||||
function() {
|
||||
$('.ewww-recommend').toggle();
|
||||
$('#ewww-show-recommendations a').toggle();
|
||||
return false;
|
||||
}
|
||||
);
|
||||
$('#ewww_image_optimizer_cloud_key').on('keydown', function(event){
|
||||
if (event.which === 13) {
|
||||
$('#ewwwio-api-activate').trigger('click');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
$('#ewwwio-api-activate').on('click', function() {
|
||||
var ewww_post_action = 'ewww_cloud_key_verify';
|
||||
var ewww_post_data = {
|
||||
action: ewww_post_action,
|
||||
compress_api_key: $('#ewww_image_optimizer_cloud_key').val(),
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
};
|
||||
$('#ewwwio-api-activate').hide();
|
||||
$('#ewwwio-api-activation-processing').show();
|
||||
$('#ewwwio-api-activation-result').hide();
|
||||
$.post(ajaxurl, ewww_post_data, function(response) {
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
$('#ewwwio-api-activation-processing').hide();
|
||||
$('#ewwwio-api-activation-result').html(ewww_vars.invalid_response);
|
||||
$('#ewwwio-api-activation-result').addClass('error');
|
||||
$('#ewwwio-api-activation-result').show();
|
||||
console.log( response );
|
||||
return false;
|
||||
}
|
||||
if ( ewww_response.error ) {
|
||||
$('#ewwwio-api-activation-processing').hide();
|
||||
$('#ewwwio-api-activate').show();
|
||||
$('#ewwwio-api-activation-result').html(ewww_response.error);
|
||||
$('#ewwwio-api-activation-result').addClass('error');
|
||||
$('#ewwwio-api-activation-result').show();
|
||||
} else if ( ! ewww_response.success ) {
|
||||
$('#ewwwio-api-activation-processing').hide();
|
||||
$('#ewwwio-api-activation-result').html(ewww_vars.invalid_response);
|
||||
$('#ewwwio-api-activation-result').addClass('error');
|
||||
$('#ewwwio-api-activation-result').show();
|
||||
console.log( response );
|
||||
} else {
|
||||
$('#ewwwio-api-activation-processing').hide();
|
||||
$('#ewwwio-api-activate').html('<span class="dashicons dashicons-yes"></span>');
|
||||
$('#ewwwio-api-activate').show();
|
||||
$('#ewwwio-api-activation-result').html(ewww_response.success);
|
||||
$('#ewwwio-api-activation-result').removeClass('error');
|
||||
$('#ewwwio-api-activation-result').show();
|
||||
$('.easyio-manual-ui').hide();
|
||||
$('.easyio-cloud-key-ui').show();
|
||||
$('#ewww_image_optimizer_cloud_key').attr('type', 'password');
|
||||
ewww_vars.easy_autoreg = 1;
|
||||
ewwwCloudEnable();
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
function ewwwCloudEnable() {
|
||||
if (
|
||||
$('#ewww_image_optimizer_jpg_level').val() < 20 &&
|
||||
$('#ewww_image_optimizer_png_level').val() < 20 &&
|
||||
$('#ewww_image_optimizer_gif_level').val() < 20 &&
|
||||
$('#ewww_image_optimizer_pdf_level').val() < 10
|
||||
) {
|
||||
$('#ewww_image_optimizer_jpg_level option').prop('disabled', false);
|
||||
$('#ewww_image_optimizer_png_level option').prop('disabled', false);
|
||||
$('#ewww_image_optimizer_pdf_level option').prop('disabled', false);
|
||||
$('#ewww_image_optimizer_svg_level option').prop('disabled', false);
|
||||
$('#ewww_image_optimizer_backup_files option').prop('disabled', false);
|
||||
$('#ewww_image_optimizer_jpg_level').val(30);
|
||||
$('#ewww_image_optimizer_png_level').val(20);
|
||||
$('#ewww_image_optimizer_gif_level').val(10);
|
||||
$('#ewww_image_optimizer_pdf_level').val(10);
|
||||
$('#ewww_image_optimizer_svg_level').val(10);
|
||||
}
|
||||
}
|
||||
var easyio_registration_error = '';
|
||||
$('#ewwwio-easy-activate').on( 'click', function() {
|
||||
$('#ewwwio-easy-activate').hide();
|
||||
$('#ewwwio-easy-deregister').hide();
|
||||
$('#ewwwio-easy-activation-result').hide();
|
||||
$('#ewwwio-easy-activation-processing').show();
|
||||
if (! ewww_vars.easyio_site_registered && ewww_vars.easy_autoreg) {
|
||||
var ewww_post_data = {
|
||||
action: 'ewww_exactdn_register_site',
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
blog_id: ewww_vars.blog_id,
|
||||
};
|
||||
$.post(ajaxurl, ewww_post_data, function(response) {
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
$('#ewwwio-easy-activation-processing').hide();
|
||||
$('#ewwwio-easy-activation-result').html(ewww_vars.invalid_response);
|
||||
$('#ewwwio-easy-activation-result').addClass('error');
|
||||
$('#ewwwio-easy-activation-result').show();
|
||||
console.log( 'registration response: ' + response );
|
||||
return false;
|
||||
}
|
||||
if ( ewww_response.error ) {
|
||||
easyio_registration_error = ewww_response.error;
|
||||
} else if ( ! ewww_response.status ) {
|
||||
$('#ewwwio-easy-activation-processing').hide();
|
||||
$('#ewwwio-easy-activation-result').html(ewww_vars.invalid_response);
|
||||
$('#ewwwio-easy-activation-result').addClass('error');
|
||||
$('#ewwwio-easy-activation-result').show();
|
||||
console.log( 'registration response: ' + response );
|
||||
return false;
|
||||
}
|
||||
setTimeout( activateExactDNSite, 5000 );
|
||||
return false;
|
||||
});
|
||||
} else {
|
||||
activateExactDNSite();
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
function activateExactDNSite() {
|
||||
var ewww_post_action = 'ewww_exactdn_activate';
|
||||
var ewww_post_data = {
|
||||
action: ewww_post_action,
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
};
|
||||
$.post(ajaxurl, ewww_post_data, function(response) {
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
$('#ewwwio-easy-activation-processing').hide();
|
||||
$('#ewwwio-easy-activation-result').html(ewww_vars.invalid_response);
|
||||
$('#ewwwio-easy-activation-result').addClass('error');
|
||||
$('#ewwwio-easy-activation-result').show();
|
||||
console.log( response );
|
||||
return false;
|
||||
}
|
||||
if ( ewww_response.error ) {
|
||||
if ( easyio_registration_error ) {
|
||||
ewww_response.error = easyio_registration_error + '<br>' + ewww_response.error;
|
||||
}
|
||||
$('#ewwwio-easy-activation-processing').hide();
|
||||
$('#ewwwio-easy-activate').show();
|
||||
$('#ewwwio-easy-activation-result').html(ewww_response.error);
|
||||
$('#ewwwio-easy-activation-result').addClass('error');
|
||||
$('#ewwwio-easy-activation-result').show();
|
||||
} else if ( ! ewww_response.success ) {
|
||||
$('#ewwwio-easy-activation-processing').hide();
|
||||
$('#ewwwio-easy-activation-result').html(ewww_vars.invalid_response);
|
||||
$('#ewwwio-easy-activation-result').addClass('error');
|
||||
$('#ewwwio-easy-activation-result').show();
|
||||
console.log( response );
|
||||
} else {
|
||||
$('#ewwwio-easy-activation-processing').hide();
|
||||
$('#ewwwio-easy-activation-result').html(ewww_response.success);
|
||||
$('#ewwwio-easy-activation-result').removeClass('error');
|
||||
$('#ewwwio-easy-activation-result').show();
|
||||
$('.ewwwio-exactdn-options input').prop('disabled', false);
|
||||
$('.ewwwio-exactdn-options').show();
|
||||
$('.ewwwio-easy-setup-instructions').hide();
|
||||
$('#ewww_image_optimizer_webp_container').hide();
|
||||
$('.ewww_image_optimizer_webp_setting_container').hide();
|
||||
$('.ewww_image_optimizer_webp_rewrite_setting_container').hide();
|
||||
$('#ewww_image_optimizer_webp_easyio_container').show();
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
var exactdn_blog_ids = [];
|
||||
var exactdn_blog_count = 0;
|
||||
var exactdn_cancelled = false;
|
||||
$('#ewwwio-easy-activate-network').on( 'click', function() {
|
||||
if (!confirm(ewww_vars.exactdn_network_warning)) {
|
||||
return false;
|
||||
}
|
||||
exactdn_blog_ids = Array.from(ewww_vars.network_blog_ids);
|
||||
exactdn_blog_count = exactdn_blog_ids.length;
|
||||
$('#ewww_image_optimizer_exactdn_container .button-secondary').hide();
|
||||
$('#ewwwio-easy-cancel-network-operation').show();
|
||||
$('#ewwwio-easy-activation-result').hide();
|
||||
$('#ewwwio-easy-activation-processing').show();
|
||||
$('#ewwwio-easy-activation-progressbar').progressbar({ max: exactdn_blog_count });
|
||||
$('#ewwwio-easy-activation-progressbar').show();
|
||||
activateExactDNMultiSite();
|
||||
return false;
|
||||
});
|
||||
function activateExactDNMultiSite() {
|
||||
var ewww_post_data = {
|
||||
action: 'ewww_exactdn_activate_site',
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
blog_id: exactdn_blog_ids.pop(),
|
||||
};
|
||||
$.post(ajaxurl, ewww_post_data, function(response) {
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
$('#ewwwio-easy-activation-processing').hide();
|
||||
$('#ewwwio-easy-activation-result').html(ewww_vars.invalid_response);
|
||||
$('#ewwwio-easy-activation-result').addClass('error');
|
||||
$('#ewwwio-easy-activation-result').show();
|
||||
$('#ewwwio-easy-cancel-network-operation').hide();
|
||||
console.log( response );
|
||||
return false;
|
||||
}
|
||||
var exactdn_blogs_done = exactdn_blog_count - exactdn_blog_ids.length;
|
||||
if ( ewww_response.error ) {
|
||||
$('#ewwwio-easy-activation-processing').hide();
|
||||
$('#ewwwio-easy-activation-errors').append('<p>' + ewww_response.error + '</p>');
|
||||
$('#ewwwio-easy-activation-errors').show();
|
||||
$('#ewwwio-easy-activation-progressbar').progressbar('option', 'value', exactdn_blogs_done);
|
||||
} else if ( ! ewww_response.success ) {
|
||||
$('#ewwwio-easy-activate-network').show();
|
||||
$('#ewwwio-easy-activation-processing').hide();
|
||||
$('#ewwwio-easy-activation-result').html(ewww_vars.invalid_response);
|
||||
$('#ewwwio-easy-activation-result').addClass('error');
|
||||
$('#ewwwio-easy-activation-result').show();
|
||||
$('#ewwwio-easy-cancel-network-operation').hide();
|
||||
console.log( response );
|
||||
return false;
|
||||
} else {
|
||||
$('#ewwwio-easy-activation-processing').hide();
|
||||
$('.ewwwio-easy-setup-instructions').hide();
|
||||
$('p.ewwwio-easy-description').hide();
|
||||
$('#ewwwio-easy-activation-progressbar').progressbar('option', 'value', exactdn_blogs_done);
|
||||
}
|
||||
if ( exactdn_blog_ids.length ) {
|
||||
activateExactDNMultiSite();
|
||||
} else {
|
||||
$('#ewwwio-easy-cancel-network-operation').hide();
|
||||
if (exactdn_cancelled) {
|
||||
$('#ewwwio-easy-activation-result').html(ewww_vars.operation_stopped);
|
||||
} else {
|
||||
$('#ewwwio-easy-activation-result').html(ewww_vars.exactdn_network_success);
|
||||
}
|
||||
$('#ewwwio-easy-activation-result').removeClass('error');
|
||||
$('#ewwwio-easy-activation-result').show();
|
||||
$('.ewwwio-exactdn-options input').prop('disabled', false);
|
||||
$('.ewwwio-exactdn-options').show();
|
||||
$('#ewwwio-easy-activation-progressbar').hide();
|
||||
$('#ewww_image_optimizer_webp_container').hide();
|
||||
$('.ewww_image_optimizer_webp_setting_container').hide();
|
||||
$('.ewww_image_optimizer_webp_rewrite_setting_container').hide();
|
||||
$('#ewww_image_optimizer_webp_easyio_container').show();
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
$('#ewwwio-easy-register-network').on( 'click', function() {
|
||||
if (!confirm(ewww_vars.easyio_register_warning)) {
|
||||
return false;
|
||||
}
|
||||
exactdn_blog_ids = Array.from(ewww_vars.network_blog_ids);
|
||||
exactdn_blog_count = exactdn_blog_ids.length;
|
||||
$('#ewww_image_optimizer_exactdn_container .button-secondary').hide();
|
||||
$('#ewwwio-easy-cancel-network-operation').show();
|
||||
$('#ewwwio-easy-activation-result').hide();
|
||||
$('#ewwwio-easy-activation-processing').show();
|
||||
$('#ewwwio-easy-activation-progressbar').progressbar({ max: exactdn_blog_count });
|
||||
$('#ewwwio-easy-activation-progressbar').show();
|
||||
registerExactDNSite();
|
||||
return false;
|
||||
});
|
||||
function registerExactDNSite() {
|
||||
var ewww_post_data = {
|
||||
action: 'ewww_exactdn_register_site',
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
blog_id: exactdn_blog_ids.pop(),
|
||||
};
|
||||
$.post(ajaxurl, ewww_post_data, function(response) {
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
$('#ewwwio-easy-activation-processing').hide();
|
||||
$('#ewwwio-easy-activation-result').html(ewww_vars.invalid_response);
|
||||
$('#ewwwio-easy-activation-result').addClass('error');
|
||||
$('#ewwwio-easy-activation-result').show();
|
||||
$('#ewwwio-easy-cancel-network-operation').hide();
|
||||
console.log( response );
|
||||
return false;
|
||||
}
|
||||
var exactdn_blogs_done = exactdn_blog_count - exactdn_blog_ids.length;
|
||||
if ( ewww_response.error ) {
|
||||
$('#ewwwio-easy-activation-processing').hide();
|
||||
$('#ewwwio-easy-register-network').show();
|
||||
$('#ewwwio-easy-activation-result').html(ewww_response.error);
|
||||
$('#ewwwio-easy-activation-result').addClass('error');
|
||||
$('#ewwwio-easy-activation-result').show();
|
||||
$('#ewwwio-easy-cancel-network-operation').hide();
|
||||
return false;
|
||||
} else if ( ! ewww_response.status ) {
|
||||
$('#ewwwio-easy-activation-processing').hide();
|
||||
$('#ewwwio-easy-activation-result').html(ewww_vars.invalid_response);
|
||||
$('#ewwwio-easy-activation-result').addClass('error');
|
||||
$('#ewwwio-easy-activation-result').show();
|
||||
$('#ewwwio-easy-cancel-network-operation').hide();
|
||||
console.log( response );
|
||||
return false;
|
||||
} else {
|
||||
$('#ewwwio-easy-activation-processing').hide();
|
||||
$('.ewwwio-easy-setup-instructions').hide();
|
||||
$('p.ewwwio-easy-description').hide();
|
||||
$('#ewwwio-easy-activation-progressbar').progressbar('option', 'value', exactdn_blogs_done);
|
||||
}
|
||||
if ( exactdn_blog_ids.length ) {
|
||||
registerExactDNSite();
|
||||
} else {
|
||||
if (exactdn_cancelled) {
|
||||
$('#ewwwio-easy-activation-result').html(ewww_vars.operation_stopped);
|
||||
} else {
|
||||
$('#ewwwio-easy-activation-result').html(ewww_vars.easyio_register_success);
|
||||
}
|
||||
$('#ewwwio-easy-activation-result').removeClass('error');
|
||||
$('#ewwwio-easy-activation-result').show();
|
||||
$('#ewwwio-easy-cancel-network-operation').hide();
|
||||
$('#ewwwio-easy-activation-progressbar').hide();
|
||||
$('#ewwwio-easy-activate-network').show();
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
$('#ewwwio-easy-cancel-network-operation').on('click', function() {
|
||||
exactdn_blog_ids = [];
|
||||
exactdn_cancelled = true;
|
||||
$('#ewwwio-easy-cancel-network-operation').hide();
|
||||
return false;
|
||||
});
|
||||
$('#ewwwio-easy-deregister').on( 'click', function() {
|
||||
if (!confirm(ewww_vars.easyio_deregister_warning)) {
|
||||
return false;
|
||||
}
|
||||
$('#ewwwio-easy-activate').hide();
|
||||
$('#ewwwio-easy-deregister').hide();
|
||||
$('#ewwwio-easy-activation-result').hide();
|
||||
$('#ewwwio-easy-activation-processing').show();
|
||||
if (ewww_vars.easyio_site_id) {
|
||||
deregisterExactDNSite();
|
||||
} else {
|
||||
$('#ewwwio-easy-activation-processing').hide();
|
||||
$('#ewwwio-easy-activation-result').html(ewww_vars.invalid_response);
|
||||
$('#ewwwio-easy-activation-result').addClass('error');
|
||||
$('#ewwwio-easy-activation-result').show();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
function deregisterExactDNSite() {
|
||||
var ewww_post_data = {
|
||||
action: 'ewww_exactdn_deregister_site',
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
site_id: ewww_vars.easyio_site_id,
|
||||
};
|
||||
$.post(ajaxurl, ewww_post_data, function(response) {
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
$('#ewwwio-easy-activation-processing').hide();
|
||||
$('#ewwwio-easy-activation-result').html(ewww_vars.invalid_response);
|
||||
$('#ewwwio-easy-activation-result').addClass('error');
|
||||
$('#ewwwio-easy-activation-result').show();
|
||||
console.log( 'de-registration response: ' + response );
|
||||
return false;
|
||||
}
|
||||
if ( ewww_response.error ) {
|
||||
$('#ewwwio-easy-activation-processing').hide();
|
||||
$('#ewwwio-easy-activation-result').html(ewww_response.error);
|
||||
$('#ewwwio-easy-activation-result').addClass('error');
|
||||
$('#ewwwio-easy-activation-result').show();
|
||||
} else if ( ! ewww_response.success ) {
|
||||
$('#ewwwio-easy-activation-processing').hide();
|
||||
$('#ewwwio-easy-activation-result').html(ewww_vars.invalid_response);
|
||||
$('#ewwwio-easy-activation-result').addClass('error');
|
||||
$('#ewwwio-easy-activation-result').show();
|
||||
console.log( 'de-registration response: ' + response );
|
||||
} else {
|
||||
$('#ewwwio-easy-activation-processing').hide();
|
||||
$('#ewwwio-easy-activation-result').html(ewww_response.success);
|
||||
$('#ewwwio-easy-activation-result').removeClass('error');
|
||||
$('#ewwwio-easy-activation-result').show();
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
$('#ewww_image_optimizer_webp').on(
|
||||
'click',
|
||||
function() {
|
||||
if ( $(this).prop('checked') && ewww_vars.save_space ) {
|
||||
$('#ewwwio-webp-storage-warning').fadeIn();
|
||||
return false;
|
||||
} else if ($(this).prop('checked')) {
|
||||
$('.ewww_image_optimizer_webp_setting_container').fadeIn();
|
||||
if ($('#ewww_image_optimizer_webp_for_cdn').prop('checked') || $('#ewww_image_optimizer_picture_webp').prop('checked')) {
|
||||
$('.ewww_image_optimizer_webp_rewrite_setting_container').fadeIn();
|
||||
}
|
||||
} else {
|
||||
$('.ewww_image_optimizer_webp_setting_container').fadeOut();
|
||||
$('.ewww_image_optimizer_webp_rewrite_setting_container').fadeOut();
|
||||
}
|
||||
}
|
||||
);
|
||||
$('#ewwwio-cancel-webp').on(
|
||||
'click',
|
||||
function() {
|
||||
$('#ewwwio-webp-storage-warning').fadeOut();
|
||||
return false;
|
||||
}
|
||||
);
|
||||
$('#ewwwio-easyio-webp-info').on(
|
||||
'click',
|
||||
function() {
|
||||
$('#ewwwio-webp-storage-warning').fadeOut();
|
||||
$('.ewwwio-premium-setup').show();
|
||||
}
|
||||
)
|
||||
$('#ewwwio-confirm-webp').on(
|
||||
'click',
|
||||
function() {
|
||||
$('#ewwwio-webp-storage-warning').fadeOut();
|
||||
$('#ewww_image_optimizer_webp').prop('checked', true);
|
||||
$('.ewww_image_optimizer_webp_setting_container').fadeIn();
|
||||
if ($('#ewww_image_optimizer_webp_for_cdn').prop('checked') || $('#ewww_image_optimizer_picture_webp').prop('checked')) {
|
||||
$('.ewww_image_optimizer_webp_rewrite_setting_container').fadeIn();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
);
|
||||
$('#ewww-webp-rewrite #ewww-webp-insert').on( 'click', function() {
|
||||
var ewww_webp_rewrite_action = 'ewww_webp_rewrite';
|
||||
var ewww_webp_rewrite_data = {
|
||||
action: ewww_webp_rewrite_action,
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
};
|
||||
$.post(ajaxurl, ewww_webp_rewrite_data, function(response) {
|
||||
$('#ewww-webp-rewrite-result').html(response);
|
||||
$('#ewww-webp-rewrite-result').show();
|
||||
$('#ewww-webp-rewrite-status').hide();
|
||||
$('#webp-rewrite-rules').hide();
|
||||
$('#ewww-webp-insert').hide();
|
||||
ewww_webp_image = document.getElementById('ewww-webp-image').src;
|
||||
document.getElementById('ewww-webp-image').src = removeQueryArg(ewww_webp_image) + '?m=' + new Date().getTime();
|
||||
});
|
||||
return false;
|
||||
});
|
||||
$('#ewww-webp-rewrite #ewww-webp-remove').on( 'click', function() {
|
||||
var ewww_webp_rewrite_action = 'ewww_webp_unwrite';
|
||||
var ewww_webp_rewrite_data = {
|
||||
action: ewww_webp_rewrite_action,
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
};
|
||||
$.post(ajaxurl, ewww_webp_rewrite_data, function(response) {
|
||||
$('#ewww-webp-rewrite-result').html(response);
|
||||
$('#ewww-webp-rewrite-result').show();
|
||||
$('#ewww-webp-rewrite-status').hide();
|
||||
$('#ewww-webp-remove').hide();
|
||||
ewww_webp_image = document.getElementById('ewww-webp-image').src;
|
||||
document.getElementById('ewww-webp-image').src = removeQueryArg(ewww_webp_image) + '?m' + new Date().getTime();
|
||||
});
|
||||
return false;
|
||||
});
|
||||
$('#exactdn_site_url').on( 'mouseenter',
|
||||
function() {
|
||||
$('#exactdn-site-url-copy').fadeIn();
|
||||
}
|
||||
);
|
||||
$('#exactdn_site_url').on( 'mouseleave',
|
||||
function() {
|
||||
$('#exactdn-site-url-copy').fadeOut();
|
||||
$('#exactdn-site-url-copied').fadeOut();
|
||||
}
|
||||
);
|
||||
$('#exactdn_site_url').on( 'click', function() {
|
||||
this.select();
|
||||
this.setSelectionRange(0,300); // For mobile.
|
||||
try {
|
||||
var successful = document.execCommand('copy');
|
||||
if ( successful ) {
|
||||
unselectText();
|
||||
$('#exactdn-site-url-copy').hide();
|
||||
$('#exactdn-site-url-copied').fadeIn();
|
||||
}
|
||||
} catch(err) {
|
||||
console.log('browser cannot copy');
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
$('#ewww_image_optimizer_exactdn').on( 'click', function() {
|
||||
if($(this).prop('checked')) {
|
||||
$('.ewwwio-exactdn-options').show();
|
||||
} else {
|
||||
$('.ewwwio-exactdn-options').hide();
|
||||
}
|
||||
});
|
||||
$('#ewww_image_optimizer_lazy_load').on( 'click', function() {
|
||||
if($(this).prop('checked')) {
|
||||
$('#ewww_image_optimizer_ll_exclude_container').fadeIn();
|
||||
$('#ewww_image_optimizer_ll_autoscale_container').fadeIn();
|
||||
$('#ewww_image_optimizer_ll_all_things_container').fadeIn();
|
||||
$('#ewww_image_optimizer_siip_container').fadeIn();
|
||||
$('#ewww_image_optimizer_lqip_container').fadeIn();
|
||||
} else {
|
||||
$('#ewww_image_optimizer_ll_exclude_container').fadeOut();
|
||||
$('#ewww_image_optimizer_ll_autoscale_container').fadeOut();
|
||||
$('#ewww_image_optimizer_ll_all_things_container').fadeOut();
|
||||
$('#ewww_image_optimizer_siip_container').fadeOut();
|
||||
$('#ewww_image_optimizer_lqip_container').fadeOut();
|
||||
}
|
||||
});
|
||||
$('#ewww_image_optimizer_webp_for_cdn, #ewww_image_optimizer_picture_webp').on(
|
||||
'click',
|
||||
function() {
|
||||
if ( $(this).prop('checked') && ewww_vars.cloud_media ) {
|
||||
var webp_delivery_confirm = confirm(ewww_vars.webp_cloud_warning);
|
||||
if (! webp_delivery_confirm) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( ! $('#ewww_image_optimizer_webp_for_cdn').prop('checked') && ! $('#ewww_image_optimizer_picture_webp').prop('checked') ) {
|
||||
$('.ewww_image_optimizer_webp_rewrite_setting_container').fadeOut();
|
||||
} else {
|
||||
$('.ewww_image_optimizer_webp_rewrite_setting_container').fadeIn();
|
||||
}
|
||||
}
|
||||
);
|
||||
//$('#ewww-webp-settings').hide();
|
||||
//$('#ewww-exactdn-settings').hide();
|
||||
$('#ewww-general-settings').show();
|
||||
$('li.ewww-general-nav').addClass('ewww-selected');
|
||||
if($('#ewww_image_optimizer_debug').length){
|
||||
$('#ewww-resize-settings').hide();
|
||||
}
|
||||
// New tabs.
|
||||
$('#ewww-local-settings').hide();
|
||||
$('#ewww-advanced-settings').hide();
|
||||
|
||||
//$('#ewww-optimization-settings').hide();
|
||||
$('#ewww-conversion-settings').hide();
|
||||
$('#ewww-support-settings').hide();
|
||||
$('#ewww-contribute-settings').hide();
|
||||
$('.ewww-webp-nav').on('click', function() {
|
||||
$('.ewww-tab-nav li').removeClass('ewww-selected');
|
||||
$('li.ewww-webp-nav').addClass('ewww-selected');
|
||||
$('.ewww-tab a').trigger('blur');
|
||||
$('#ewww-webp-settings').show();
|
||||
$('#ewww-general-settings').hide();
|
||||
$('#ewww-local-settings').hide();
|
||||
$('#ewww-advanced-settings').hide();
|
||||
$('#ewww-resize-settings').hide();
|
||||
$('#ewww-conversion-settings').hide();
|
||||
$('#ewww-support-settings').hide();
|
||||
$('#ewww-contribute-settings').hide();
|
||||
});
|
||||
$('.ewww-general-nav').on('click', function() {
|
||||
$('.ewww-tab-nav li').removeClass('ewww-selected');
|
||||
$('li.ewww-general-nav').addClass('ewww-selected');
|
||||
$('.ewww-tab a').trigger('blur');
|
||||
$('#ewww-webp-settings').hide();
|
||||
$('#ewww-general-settings').show();
|
||||
$('#ewww-local-settings').hide();
|
||||
$('#ewww-advanced-settings').hide();
|
||||
$('#ewww-resize-settings').hide();
|
||||
$('#ewww-conversion-settings').hide();
|
||||
$('#ewww-support-settings').hide();
|
||||
$('#ewww-contribute-settings').hide();
|
||||
});
|
||||
$('.ewww-exactdn-nav').on('click', function() {
|
||||
$('.ewww-tab-nav li').removeClass('ewww-selected');
|
||||
$('li.ewww-exactdn-nav').addClass('ewww-selected');
|
||||
$('.ewww-tab a').trigger('blur');
|
||||
$('#ewww-webp-settings').hide();
|
||||
$('#ewww-general-settings').hide();
|
||||
$('#ewww-exactdn-settings').show();
|
||||
$('#ewww-optimization-settings').hide();
|
||||
$('#ewww-resize-settings').hide();
|
||||
$('#ewww-conversion-settings').hide();
|
||||
$('#ewww-support-settings').hide();
|
||||
$('#ewww-contribute-settings').hide();
|
||||
});
|
||||
$('.ewww-optimization-nav').on('click', function() {
|
||||
$('.ewww-tab-nav li').removeClass('ewww-selected');
|
||||
$('li.ewww-optimization-nav').addClass('ewww-selected');
|
||||
$('.ewww-tab a').trigger('blur');
|
||||
$('#ewww-webp-settings').hide();
|
||||
$('#ewww-general-settings').hide();
|
||||
$('#ewww-exactdn-settings').hide();
|
||||
$('#ewww-optimization-settings').show();
|
||||
$('#ewww-resize-settings').hide();
|
||||
$('#ewww-conversion-settings').hide();
|
||||
$('#ewww-support-settings').hide();
|
||||
$('#ewww-contribute-settings').hide();
|
||||
});
|
||||
$('.ewww-local-nav').on( 'click', function() {
|
||||
$('.ewww-tab-nav li').removeClass('ewww-selected');
|
||||
$('li.ewww-local-nav').addClass('ewww-selected');
|
||||
$('.ewww-tab a').trigger('blur');
|
||||
$('#ewww-webp-settings').hide();
|
||||
$('#ewww-general-settings').hide();
|
||||
$('#ewww-local-settings').show();
|
||||
$('#ewww-advanced-settings').hide();
|
||||
$('#ewww-resize-settings').hide();
|
||||
$('#ewww-conversion-settings').hide();
|
||||
$('#ewww-support-settings').hide();
|
||||
$('#ewww-contribute-settings').hide();
|
||||
});
|
||||
$('.ewww-advanced-nav').on( 'click', function() {
|
||||
$('.ewww-tab-nav li').removeClass('ewww-selected');
|
||||
$('li.ewww-advanced-nav').addClass('ewww-selected');
|
||||
$('.ewww-tab a').trigger('blur');
|
||||
$('#ewww-webp-settings').hide();
|
||||
$('#ewww-general-settings').hide();
|
||||
$('#ewww-local-settings').hide();
|
||||
$('#ewww-advanced-settings').show();
|
||||
$('#ewww-resize-settings').hide();
|
||||
$('#ewww-conversion-settings').hide();
|
||||
$('#ewww-support-settings').hide();
|
||||
$('#ewww-contribute-settings').hide();
|
||||
});
|
||||
$('.ewww-resize-nav').on( 'click', function() {
|
||||
$('.ewww-tab-nav li').removeClass('ewww-selected');
|
||||
$('li.ewww-resize-nav').addClass('ewww-selected');
|
||||
$('.ewww-tab a').trigger('blur');
|
||||
$('#ewww-webp-settings').hide();
|
||||
$('#ewww-general-settings').hide();
|
||||
$('#ewww-local-settings').hide();
|
||||
$('#ewww-advanced-settings').hide();
|
||||
$('#ewww-resize-settings').show();
|
||||
$('#ewww-conversion-settings').hide();
|
||||
$('#ewww-support-settings').hide();
|
||||
$('#ewww-contribute-settings').hide();
|
||||
});
|
||||
$('.ewww-conversion-nav').on( 'click', function() {
|
||||
$('.ewww-tab-nav li').removeClass('ewww-selected');
|
||||
$('li.ewww-conversion-nav').addClass('ewww-selected');
|
||||
$('.ewww-tab a').trigger('blur');
|
||||
$('#ewww-webp-settings').hide();
|
||||
$('#ewww-general-settings').hide();
|
||||
$('#ewww-local-settings').hide();
|
||||
$('#ewww-advanced-settings').hide();
|
||||
$('#ewww-resize-settings').hide();
|
||||
$('#ewww-conversion-settings').show();
|
||||
$('#ewww-support-settings').hide();
|
||||
$('#ewww-contribute-settings').hide();
|
||||
});
|
||||
$('.ewww-support-nav').on( 'click', function() {
|
||||
$('.ewww-tab-nav li').removeClass('ewww-selected');
|
||||
$('li.ewww-support-nav').addClass('ewww-selected');
|
||||
$('.ewww-tab a').trigger('blur');
|
||||
$('#ewww-webp-settings').hide();
|
||||
$('#ewww-general-settings').hide();
|
||||
$('#ewww-local-settings').hide();
|
||||
$('#ewww-advanced-settings').hide();
|
||||
$('#ewww-resize-settings').hide();
|
||||
$('#ewww-conversion-settings').hide();
|
||||
$('#ewww-support-settings').show();
|
||||
$('#ewww-contribute-settings').hide();
|
||||
});
|
||||
$('.ewww-contribute-nav').on( 'click', function() {
|
||||
$('.ewww-tab-nav li').removeClass('ewww-selected');
|
||||
$('li.ewww-contribute-nav').addClass('ewww-selected');
|
||||
$('.ewww-tab a').trigger('blur');
|
||||
$('#ewww-webp-settings').hide();
|
||||
$('#ewww-general-settings').hide();
|
||||
$('#ewww-local-settings').hide();
|
||||
$('#ewww-advanced-settings').hide();
|
||||
$('#ewww-resize-settings').hide();
|
||||
$('#ewww-conversion-settings').hide();
|
||||
$('#ewww-support-settings').hide();
|
||||
$('#ewww-contribute-settings').show();
|
||||
});
|
||||
});
|
712
wp-content/plugins/ewww-image-optimizer/includes/eio-tools.js
Normal file
712
wp-content/plugins/ewww-image-optimizer/includes/eio-tools.js
Normal file
@ -0,0 +1,712 @@
|
||||
jQuery(document).ready(function($) {
|
||||
var ewww_table_action = 'bulk_aux_images_table';
|
||||
var ewww_total_pages = 0;
|
||||
var ewww_pointer = 0;
|
||||
var ewww_search_total = 0;
|
||||
var ewww_clean_meta_total = 0;
|
||||
var ewww_table_debug = 0;
|
||||
$('#ewww-show-table').on('submit',function() {
|
||||
ewww_pointer = 0;
|
||||
ewww_total_pages = Math.ceil(ewww_vars.image_count / 50);
|
||||
$('.displaying-num').text(ewww_vars.count_string);
|
||||
$('#ewww-table-info').hide();
|
||||
$('#ewww-show-table').hide();
|
||||
$('#ewww-debug-table-info').hide();
|
||||
$('#ewww-show-debug-table').hide();
|
||||
var ewww_table_data = {
|
||||
action: ewww_table_action,
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
ewww_offset: ewww_pointer,
|
||||
ewww_debug: ewww_table_debug,
|
||||
ewww_total_pages: ewww_total_pages,
|
||||
};
|
||||
$.post(ajaxurl, ewww_table_data, function(response) {
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
$('#ewww-bulk-table').html('<span style="color: red"><b>' + ewww_vars.invalid_response + '</b></span>');
|
||||
console.log( response );
|
||||
return false;
|
||||
}
|
||||
if ( ewww_response.error ) {
|
||||
$('#ewww-bulk-table').html('<span style="color: red"><b>' + ewww_response.error + '</b></span>');
|
||||
return false;
|
||||
}
|
||||
$('#ewww-bulk-table').html(ewww_response.table);
|
||||
$('.ewww-aux-table').show();
|
||||
$('.ewww-search-count').text(ewww_response.search_result);
|
||||
$('.current-page').text(ewww_response.pagination);
|
||||
// from here
|
||||
if ( ewww_response.search_total > 0 ) {
|
||||
ewww_search_total = ewww_response.search_total;
|
||||
}
|
||||
if (ewww_response.search_count < 50) {
|
||||
$('.next-page').hide();
|
||||
$('.last-page').hide();
|
||||
}
|
||||
if (ewww_table_debug) {
|
||||
$('.displaying-num').hide();
|
||||
}
|
||||
// to here
|
||||
if (ewww_vars.image_count >= 50) {
|
||||
$('.tablenav').show();
|
||||
$('.next-page').show();
|
||||
$('.last-page').show();
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
$('#ewww-show-debug-table').on( 'submit', function() {
|
||||
ewww_table_debug = 1;
|
||||
ewww_pointer = 0;
|
||||
$('#ewww-show-table').submit();
|
||||
document.body.scrollTop = 0; // For Safari.
|
||||
document.documentElement.scrollTop = 0; // For everyone else.
|
||||
return false;
|
||||
});
|
||||
$('.ewww-search-form').on( 'submit', function() {
|
||||
ewww_pointer = 0;
|
||||
var ewww_search = $('.ewww-search-input').val();
|
||||
var ewww_table_data = {
|
||||
action: ewww_table_action,
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
ewww_offset: ewww_pointer,
|
||||
ewww_debug: ewww_table_debug,
|
||||
ewww_total_pages: ewww_total_pages,
|
||||
ewww_search: ewww_search,
|
||||
};
|
||||
$.post(ajaxurl, ewww_table_data, function(response) {
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
$('#ewww-bulk-table').html('<span style="color: red"><b>' + ewww_vars.invalid_response + '</b></span>');
|
||||
console.log( response );
|
||||
return false;
|
||||
}
|
||||
if ( ewww_response.error ) {
|
||||
$('#ewww-bulk-table').html('<span style="color: red"><b>' + ewww_response.error + '</b></span>');
|
||||
return false;
|
||||
}
|
||||
$('#ewww-bulk-table').html(ewww_response.table);
|
||||
$('.ewww-search-count').text(ewww_response.search_result);
|
||||
ewww_search_total = ewww_response.search_total;
|
||||
if (ewww_response.search_count < 50) {
|
||||
$('.next-page').hide();
|
||||
$('.last-page').hide();
|
||||
}
|
||||
$('.current-page').text(ewww_response.pagination);
|
||||
});
|
||||
$('.prev-page').hide();
|
||||
$('.first-page').hide();
|
||||
$('.next-page').show();
|
||||
$('.last-page').show();
|
||||
return false;
|
||||
});
|
||||
$('.next-page').on( 'click', function() {
|
||||
var ewww_search = $('.ewww-search-input').val();
|
||||
ewww_pointer++;
|
||||
var ewww_table_data = {
|
||||
action: ewww_table_action,
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
ewww_offset: ewww_pointer,
|
||||
ewww_debug: ewww_table_debug,
|
||||
ewww_total_pages: ewww_total_pages,
|
||||
ewww_search: ewww_search,
|
||||
};
|
||||
$.post(ajaxurl, ewww_table_data, function(response) {
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
$('#ewww-bulk-table').html('<span style="color: red"><b>' + ewww_vars.invalid_response + '</b></span>');
|
||||
console.log( response );
|
||||
return false;
|
||||
}
|
||||
if ( ewww_response.error ) {
|
||||
$('#ewww-bulk-table').html('<span style="color: red"><b>' + ewww_response.error + '</b></span>');
|
||||
return false;
|
||||
}
|
||||
$('#ewww-bulk-table').html(ewww_response.table);
|
||||
$('.ewww-search-count').text(ewww_response.search_result);
|
||||
if (ewww_response.search_count < 50) {
|
||||
$('.next-page').hide();
|
||||
$('.last-page').hide();
|
||||
}
|
||||
$('.current-page').text(ewww_response.pagination);
|
||||
});
|
||||
if (ewww_vars.image_count <= ((ewww_pointer + 1) * 50)) {
|
||||
$('.next-page').hide();
|
||||
$('.last-page').hide();
|
||||
}
|
||||
$('.prev-page').show();
|
||||
$('.first-page').show();
|
||||
return false;
|
||||
});
|
||||
$('.prev-page').on( 'click', function() {
|
||||
var ewww_search = $('.ewww-search-input').val();
|
||||
ewww_pointer--;
|
||||
var ewww_table_data = {
|
||||
action: ewww_table_action,
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
ewww_offset: ewww_pointer,
|
||||
ewww_debug: ewww_table_debug,
|
||||
ewww_total_pages: ewww_total_pages,
|
||||
ewww_search: ewww_search,
|
||||
};
|
||||
$.post(ajaxurl, ewww_table_data, function(response) {
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
$('#ewww-bulk-table').html('<span style="color: red"><b>' + ewww_vars.invalid_response + '</b></span>');
|
||||
console.log( response );
|
||||
return false;
|
||||
}
|
||||
if ( ewww_response.error ) {
|
||||
$('#ewww-bulk-table').html('<span style="color: red"><b>' + ewww_response.error + '</b></span>');
|
||||
return false;
|
||||
}
|
||||
$('#ewww-bulk-table').html(ewww_response.table);
|
||||
$('.ewww-search-count').text(ewww_response.search_result);
|
||||
$('.current-page').text(ewww_response.pagination);
|
||||
});
|
||||
if (!ewww_pointer) {
|
||||
$('.prev-page').hide();
|
||||
$('.first-page').hide();
|
||||
}
|
||||
$('.next-page').show();
|
||||
$('.last-page').show();
|
||||
return false;
|
||||
});
|
||||
$('.last-page').on( 'click', function() {
|
||||
var ewww_search = $('.ewww-search-input').val();
|
||||
ewww_pointer = ewww_total_pages - 1;
|
||||
if (ewww_search || ewww_table_debug) {
|
||||
ewww_pointer = ewww_search_total - 1;
|
||||
}
|
||||
var ewww_table_data = {
|
||||
action: ewww_table_action,
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
ewww_offset: ewww_pointer,
|
||||
ewww_debug: ewww_table_debug,
|
||||
ewww_total_pages: ewww_total_pages,
|
||||
ewww_search: ewww_search,
|
||||
};
|
||||
$.post(ajaxurl, ewww_table_data, function(response) {
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
$('#ewww-bulk-table').html('<span style="color: red"><b>' + ewww_vars.invalid_response + '</b></span>');
|
||||
console.log( response );
|
||||
return false;
|
||||
}
|
||||
if ( ewww_response.error ) {
|
||||
$('#ewww-bulk-table').html('<span style="color: red"><b>' + ewww_response.error + '</b></span>');
|
||||
return false;
|
||||
}
|
||||
$('#ewww-bulk-table').html(ewww_response.table);
|
||||
$('.ewww-search-count').text(ewww_response.search_result);
|
||||
$('.current-page').text(ewww_response.pagination);
|
||||
});
|
||||
$('.next-page').hide();
|
||||
$('.last-page').hide();
|
||||
$('.prev-page').show();
|
||||
$('.first-page').show();
|
||||
return false;
|
||||
});
|
||||
$('.first-page').on( 'click', function() {
|
||||
ewww_pointer = 0;
|
||||
var ewww_search = $('.ewww-search-input').val();
|
||||
var ewww_table_data = {
|
||||
action: ewww_table_action,
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
ewww_offset: ewww_pointer,
|
||||
ewww_debug: ewww_table_debug,
|
||||
ewww_total_pages: ewww_total_pages,
|
||||
ewww_search: ewww_search,
|
||||
};
|
||||
$.post(ajaxurl, ewww_table_data, function(response) {
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
$('#ewww-bulk-table').html('<span style="color: red"><b>' + ewww_vars.invalid_response + '</b></span>');
|
||||
console.log( response );
|
||||
return false;
|
||||
}
|
||||
if ( ewww_response.error ) {
|
||||
$('#ewww-bulk-table').html('<span style="color: red"><b>' + ewww_response.error + '</b></span>');
|
||||
return false;
|
||||
}
|
||||
$('#ewww-bulk-table').html(ewww_response.table);
|
||||
$('.ewww-search-count').text(ewww_response.search_result);
|
||||
if (ewww_response.search_count < 50) {
|
||||
$('.next-page').hide();
|
||||
$('.last-page').hide();
|
||||
} else {
|
||||
$('.next-page').show();
|
||||
$('.last-page').show();
|
||||
}
|
||||
$('.prev-page').hide();
|
||||
$('.first-page').hide();
|
||||
$('.current-page').text(ewww_response.pagination);
|
||||
});
|
||||
return false;
|
||||
});
|
||||
$('#ewww-clear-table').on( 'submit', function() {
|
||||
var ewww_table_data = {
|
||||
action: 'bulk_aux_images_table_clear',
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
};
|
||||
if (confirm(ewww_vars.erase_warning)) {
|
||||
$.post(ajaxurl, ewww_table_data, function(response) {
|
||||
$('#ewww-table-info').hide();
|
||||
$('#ewww-show-table').hide();
|
||||
$('#ewww-clear-table').hide();
|
||||
$('#ewww-clear-table-info').html(response);
|
||||
});
|
||||
}
|
||||
return false;
|
||||
});
|
||||
var ewww_total_restored = 0;
|
||||
$('#ewww-restore-originals').on( 'submit', function() {
|
||||
if (!confirm(ewww_vars.tool_warning)) {
|
||||
return false;
|
||||
}
|
||||
var header_label = $(this).find('input[type="submit"]').val();
|
||||
if (header_label) {
|
||||
$('#ewwwio-tools-header').html(header_label);
|
||||
}
|
||||
$('.ewww-tool-info').hide();
|
||||
$('.ewww-tool-form').hide();
|
||||
$('.ewww-tool-divider').hide();
|
||||
$('#ewww-restore-originals-progressbar').progressbar({ max: ewww_vars.restorable_images });
|
||||
$('#ewww-restore-originals-progress').html('<p> 0/' + ewww_vars.restorable_images + '</p>');
|
||||
$('#ewww-restore-originals-progressbar').show();
|
||||
$('#ewww-restore-originals-progress').show();
|
||||
ewwwRestoreOriginals();
|
||||
return false;
|
||||
});
|
||||
function ewwwRestoreOriginals(){
|
||||
var ewww_originals_data = {
|
||||
action: 'bulk_aux_images_restore_original',
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
};
|
||||
$.post(ajaxurl, ewww_originals_data, function(response) {
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
$('#ewww-restore-originals-progressbar').hide();
|
||||
$('#ewww-restore-originals-progress').html('<span style="color: red"><b>' + ewww_vars.invalid_response + '</b></span>');
|
||||
console.log(err);
|
||||
console.log(response);
|
||||
return false;
|
||||
}
|
||||
if ( ewww_response.error ) {
|
||||
$('#ewww-restore-originals-progressbar').hide();
|
||||
$('#ewww-restore-originals-progress').html('<span style="color: red"><b>' + ewww_response.error + '</b></span>');
|
||||
return false;
|
||||
}
|
||||
if(ewww_response.finished) {
|
||||
$('#ewww-restore-originals-messages').append(ewww_vars.finished);
|
||||
$('#ewww-restore-originals-messages').show();
|
||||
return false;
|
||||
}
|
||||
if (ewww_response.messages) {
|
||||
$('#ewww-restore-originals-messages').append(ewww_response.messages);
|
||||
$('#ewww-restore-originals-messages').show();
|
||||
}
|
||||
ewww_total_restored += ewww_response.completed;
|
||||
$('#ewww-restore-originals-progressbar').progressbar("option", "value", ewww_total_restored);
|
||||
$('#ewww-restore-originals-progress').html('<p>' + ewww_total_restored + '/' + ewww_vars.restorable_images + '</p>');
|
||||
if ( ewww_total_restored > ewww_vars.restorable_images + 100 ) {
|
||||
$('#ewww-restore-originals-messages').append('<p><b>' + ewww_vars.too_far) + '</b></p>';
|
||||
}
|
||||
ewwwRestoreOriginals();
|
||||
});
|
||||
}
|
||||
var ewww_total_originals = 0;
|
||||
var ewww_original_attachments = false;
|
||||
$('#ewww-clean-originals').on( 'submit', function() {
|
||||
if (!confirm(ewww_vars.tool_warning)) {
|
||||
return false;
|
||||
}
|
||||
var header_label = $(this).find('input[type="submit"]').val();
|
||||
if (header_label) {
|
||||
$('#ewwwio-tools-header').html(header_label);
|
||||
}
|
||||
var ewww_originals_data = {
|
||||
action: 'ewwwio_get_all_attachments',
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
};
|
||||
$.post(ajaxurl, ewww_originals_data, function(response) {
|
||||
try {
|
||||
ewww_original_attachments = JSON.parse(response);
|
||||
} catch (err) {
|
||||
$('.ewww-tool-info').hide();
|
||||
$('.ewww-tool-form').hide();
|
||||
$('.ewww-tool-divider').hide();
|
||||
$('#ewww-clean-originals-progress').html('<span style="color: red"><b>' + ewww_vars.invalid_response + '</b></span>');
|
||||
$('#ewww-clean-originals-progress').show();
|
||||
console.log(err);
|
||||
console.log(response);
|
||||
return false;
|
||||
}
|
||||
if ( ewww_original_attachments.error ) {
|
||||
$('.ewww-tool-info').hide();
|
||||
$('.ewww-tool-form').hide();
|
||||
$('.ewww-tool-divider').hide();
|
||||
$('#ewww-clean-originals-progress').html(ewww_original_attachments.error);
|
||||
$('#ewww-clean-originals-progress').show();
|
||||
return false;
|
||||
}
|
||||
ewww_total_originals = ewww_original_attachments.length;
|
||||
$('.ewww-tool-info').hide();
|
||||
$('.ewww-tool-form').hide();
|
||||
$('.ewww-tool-divider').hide();
|
||||
$('#ewww-clean-originals-progressbar').progressbar({ max: ewww_total_originals });
|
||||
$('#ewww-clean-originals-progress').html('<p> 0/' + ewww_total_originals + '</p>');
|
||||
$('#ewww-clean-originals-progressbar').show();
|
||||
$('#ewww-clean-originals-progress').show();
|
||||
ewwwDeleteOriginalByID();
|
||||
});
|
||||
return false;
|
||||
});
|
||||
function ewwwDeleteOriginalByID(){
|
||||
var attachment_id = ewww_original_attachments.pop();
|
||||
var ewww_originals_data = {
|
||||
action: 'bulk_aux_images_delete_original',
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
attachment_id: attachment_id,
|
||||
};
|
||||
$.post(ajaxurl, ewww_originals_data, function(response) {
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
$('#ewww-clean-originals-progressbar').hide();
|
||||
$('#ewww-clean-originals-progress').html('<span style="color: red"><b>' + ewww_vars.invalid_response + '</b></span>');
|
||||
console.log(err);
|
||||
console.log(response);
|
||||
return false;
|
||||
}
|
||||
if ( ewww_response.error ) {
|
||||
$('#ewww-clean-originals-progressbar').hide();
|
||||
$('#ewww-clean-originals-progress').html('<span style="color: red"><b>' + ewww_response.error + '</b></span>');
|
||||
return false;
|
||||
}
|
||||
if(!ewww_original_attachments.length) {
|
||||
var ewww_originals_data = {
|
||||
action: 'bulk_aux_images_delete_original',
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
delete_originals_done: 1,
|
||||
};
|
||||
$.post(ajaxurl, ewww_originals_data);
|
||||
$('#ewww-clean-originals-progress').html(ewww_vars.finished);
|
||||
return false;
|
||||
}
|
||||
var completed = ewww_total_originals - ewww_original_attachments.length;
|
||||
$('#ewww-clean-originals-progressbar').progressbar("option", "value", completed);
|
||||
$('#ewww-clean-originals-progress').html('<p>' + completed + '/' + ewww_total_originals + '</p>');
|
||||
ewwwDeleteOriginalByID();
|
||||
});
|
||||
}
|
||||
var ewww_total_converted = 0;
|
||||
$('#ewww-clean-converted').on( 'submit', function() {
|
||||
var ewww_converted_data = {
|
||||
action: 'bulk_aux_images_count_converted',
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
};
|
||||
var header_label = $(this).find('input[type="submit"]').val();
|
||||
if (header_label) {
|
||||
$('#ewwwio-tools-header').html(header_label);
|
||||
}
|
||||
$.post(ajaxurl, ewww_converted_data, function(response) {
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
$('#ewww-clean-converted-progress').html('<span style="color: red"><b>' + ewww_vars.invalid_response + '</b></span>');
|
||||
console.log( response );
|
||||
return false;
|
||||
}
|
||||
ewww_total_converted = ewww_response.total_converted;
|
||||
$('.ewww-tool-info').hide();
|
||||
$('.ewww-tool-form').hide();
|
||||
$('.ewww-tool-divider').hide();
|
||||
$('#ewww-clean-converted-progressbar').progressbar({ max: ewww_total_converted });
|
||||
$('#ewww-clean-converted-progress').html('<p> 0/' + ewww_total_converted + '</p>');
|
||||
$('#ewww-clean-converted-progressbar').show();
|
||||
$('#ewww-clean-converted-progress').show();
|
||||
ewwwCleanConvertedOriginals(0);
|
||||
});
|
||||
return false;
|
||||
});
|
||||
function ewwwCleanConvertedOriginals(converted_offset){
|
||||
var ewww_converted_data = {
|
||||
action: 'bulk_aux_images_converted_clean',
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
};
|
||||
$.post(ajaxurl, ewww_converted_data, function(response) {
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
$('#ewww-clean-converted-progressbar').hide();
|
||||
$('#ewww-clean-converted-progress').html('<span style="color: red"><b>' + ewww_vars.invalid_response + '</b></span>');
|
||||
console.log(err);
|
||||
console.log(response);
|
||||
return false;
|
||||
}
|
||||
if ( ewww_response.error ) {
|
||||
$('#ewww-clean-converted-progressbar').hide();
|
||||
$('#ewww-clean-converted-progress').html('<span style="color: red"><b>' + ewww_response.error + '</b></span>');
|
||||
return false;
|
||||
}
|
||||
if(ewww_response.finished) {
|
||||
$('#ewww-clean-converted-progress').html(ewww_vars.finished);
|
||||
return false;
|
||||
}
|
||||
converted_offset += ewww_response.completed;
|
||||
$('#ewww-clean-converted-progressbar').progressbar("option", "value", converted_offset);
|
||||
$('#ewww-clean-converted-progress').html('<p>' + converted_offset + '/' + ewww_total_converted + '</p>');
|
||||
ewwwCleanConvertedOriginals(converted_offset);
|
||||
});
|
||||
}
|
||||
var ewww_total_webp = 0;
|
||||
var ewww_webp_cleaned = 0;
|
||||
$('#ewww-clean-webp').on( 'submit', function() {
|
||||
var ewww_webp_data = {
|
||||
action: 'ewwwio_webp_attachment_count',
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
};
|
||||
var header_label = $(this).find('input[type="submit"]').val();
|
||||
if (header_label) {
|
||||
$('#ewwwio-tools-header').html(header_label);
|
||||
}
|
||||
$.post(ajaxurl, ewww_webp_data, function(response) {
|
||||
try {
|
||||
ewww_webp_attachments = JSON.parse(response);
|
||||
} catch (err) {
|
||||
$('#ewww-clean-webp-progress').html('<span style="color: red"><b>' + ewww_vars.invalid_response + '</b></span>');
|
||||
console.log(err);
|
||||
console.log(response);
|
||||
return false;
|
||||
}
|
||||
ewww_total_webp = ewww_webp_attachments.total;
|
||||
$('.ewww-tool-info').hide();
|
||||
$('.ewww-tool-form').hide();
|
||||
$('.ewww-tool-divider').hide();
|
||||
$('#ewww-clean-webp-progressbar').progressbar({ max: ewww_total_webp });
|
||||
$('#ewww-clean-webp-progress').html('<p>' + ewww_vars.stage1 + ' 0/' + ewww_total_webp + '</p>');
|
||||
$('#ewww-clean-webp-progressbar').show();
|
||||
$('#ewww-clean-webp-progress').show();
|
||||
ewwwRemoveWebPByID();
|
||||
});
|
||||
return false;
|
||||
});
|
||||
function ewwwRemoveWebPByID(){
|
||||
var ewww_webp_data = {
|
||||
action: 'bulk_aux_images_delete_webp',
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
};
|
||||
$.post(ajaxurl, ewww_webp_data, function(response) {
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
$('#ewww-clean-webp-progressbar').hide();
|
||||
$('#ewww-clean-webp-progress').html('<span style="color: red"><b>' + ewww_vars.invalid_response + '</b></span>');
|
||||
console.log(err);
|
||||
console.log(response);
|
||||
return false;
|
||||
}
|
||||
if ( ewww_response.error ) {
|
||||
$('#ewww-clean-webp-progressbar').hide();
|
||||
$('#ewww-clean-webp-progress').html('<span style="color: red"><b>' + ewww_response.error + '</b></span>');
|
||||
return false;
|
||||
}
|
||||
if(ewww_response.finished) {
|
||||
ewww_total_webp = ewww_vars.webp_cleanable;
|
||||
ewww_webp_cleaned = 0;
|
||||
$('#ewww-clean-webp-progressbar').progressbar({ max: ewww_total_webp });
|
||||
$('#ewww-clean-webp-progressbar').progressbar("option", "value", 0);
|
||||
$('#ewww-clean-webp-progress').html('<p>' + ewww_vars.stage2 + ' 0/' + ewww_total_webp + '</p>');
|
||||
ewwwRemoveWebP();
|
||||
return false;
|
||||
}
|
||||
ewww_webp_cleaned++;
|
||||
$('#ewww-clean-webp-progressbar').progressbar("option", "value", ewww_webp_cleaned);
|
||||
$('#ewww-clean-webp-progress').html('<p>' + ewww_vars.stage1 + ' ' + ewww_webp_cleaned + '/' + ewww_total_webp + '</p>');
|
||||
ewwwRemoveWebPByID();
|
||||
});
|
||||
}
|
||||
function ewwwRemoveWebP(){
|
||||
var ewww_webp_data = {
|
||||
action: 'bulk_aux_images_webp_clean',
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
};
|
||||
$.post(ajaxurl, ewww_webp_data, function(response) {
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
$('#ewww-clean-webp-progressbar').hide();
|
||||
$('#ewww-clean-webp-progress').html('<span style="color: red"><b>' + ewww_vars.invalid_response + '</b></span>');
|
||||
console.log(err);
|
||||
console.log(response);
|
||||
return false;
|
||||
}
|
||||
if ( ewww_response.error ) {
|
||||
$('#ewww-clean-webp-progressbar').hide();
|
||||
$('#ewww-clean-webp-progress').html('<span style="color: red"><b>' + ewww_response.error + '</b></span>');
|
||||
return false;
|
||||
}
|
||||
if(ewww_response.finished) {
|
||||
$('#ewww-clean-webp-progress').html(ewww_vars.finished);
|
||||
return false;
|
||||
}
|
||||
ewww_webp_cleaned += ewww_response.completed;
|
||||
$('#ewww-clean-webp-progressbar').progressbar("option", "value", ewww_webp_cleaned);
|
||||
$('#ewww-clean-webp-progress').html('<p>' + ewww_vars.stage2 + ' ' + ewww_webp_cleaned + '/' + ewww_total_webp + '</p>');
|
||||
ewwwRemoveWebP();
|
||||
});
|
||||
}
|
||||
$('#ewww-clean-table').on( 'submit', function() {
|
||||
var header_label = $(this).find('input[type="submit"]').val();
|
||||
if (header_label) {
|
||||
$('#ewwwio-tools-header').html(header_label);
|
||||
}
|
||||
ewww_total_pages = Math.ceil(ewww_vars.image_count / 500);
|
||||
$('.ewww-tool-info').hide();
|
||||
$('.ewww-tool-form').hide();
|
||||
$('.ewww-tool-divider').hide();
|
||||
$('#ewww-clean-table-progressbar').progressbar({ max: ewww_total_pages });
|
||||
$('#ewww-clean-table-progress').html('<p>' + ewww_vars.batch + ' 0/' + ewww_total_pages + '</p>');
|
||||
$('#ewww-clean-table-progressbar').show();
|
||||
$('#ewww-clean-table-progress').show();
|
||||
var total_pages = ewww_total_pages;
|
||||
ewwwCleanup(total_pages);
|
||||
return false;
|
||||
});
|
||||
function ewwwCleanup(total_pages){
|
||||
total_pages--;
|
||||
var ewww_table_data = {
|
||||
action: 'bulk_aux_images_table_clean',
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
ewww_offset: total_pages,
|
||||
};
|
||||
$.post(ajaxurl, ewww_table_data, function(response) {
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
$('#ewww-clean-table-progressbar').hide();
|
||||
$('#ewww-clean-table-progress').html('<span style="color: red"><b>' + ewww_vars.invalid_response + '</b></span>');
|
||||
console.log( response );
|
||||
return false;
|
||||
}
|
||||
if ( ewww_response.error ) {
|
||||
$('#ewww-clean-table-progressbar').hide();
|
||||
$('#ewww-clean-table-progress').html('<span style="color: red"><b>' + ewww_response.error + '</b></span>');
|
||||
return false;
|
||||
}
|
||||
if(!total_pages>0) {
|
||||
$('#ewww-clean-table-progress').html(ewww_vars.finished);
|
||||
$('#ewww-clean-table-progressbar').progressbar("option", "value", ewww_total_pages);
|
||||
return;
|
||||
}
|
||||
$('#ewww-clean-table-progressbar').progressbar("option", "value", ewww_total_pages-total_pages);
|
||||
$('#ewww-clean-table-progress').html('<p>' + ewww_vars.batch + ' ' + (ewww_total_pages-total_pages) + '/' + ewww_total_pages + '</p>');
|
||||
ewwwCleanup(total_pages);
|
||||
});
|
||||
}
|
||||
$('#ewww-clean-meta').on( 'submit', function() {
|
||||
var header_label = $(this).find('input[type="submit"]').val();
|
||||
if (header_label) {
|
||||
$('#ewwwio-tools-header').html(header_label);
|
||||
}
|
||||
$('.ewww-tool-info').hide();
|
||||
$('.ewww-tool-form').hide();
|
||||
$('.ewww-tool-divider').hide();
|
||||
$('#ewww-clean-meta-progressbar').progressbar({ max: ewww_vars.attachment_count });
|
||||
console.log( $('#ewww-clean-meta-progressbar').progressbar("option","max"));
|
||||
$('#ewww-clean-meta-progress').html('<p>0/' + ewww_vars.attachment_string + '</p>');
|
||||
$('#ewww-clean-meta-progressbar').show();
|
||||
$('#ewww-clean-meta-progress').show();
|
||||
ewwwCleanupMeta();
|
||||
return false;
|
||||
});
|
||||
function ewwwCleanupMeta(){
|
||||
var ewww_cleanmeta_data = {
|
||||
action: 'bulk_aux_images_meta_clean',
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
ewww_offset: ewww_clean_meta_total,
|
||||
};
|
||||
$.post(ajaxurl, ewww_cleanmeta_data, function(response) {
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
$('#ewww-clean-meta-progressbar').hide();
|
||||
$('#ewww-clean-meta-progress').html('<span style="color: red"><b>' + ewww_vars.invalid_response + '</b></span>');
|
||||
console.log( response );
|
||||
return false;
|
||||
}
|
||||
if ( ewww_response.error ) {
|
||||
$('#ewww-clean-meta-progressbar').hide();
|
||||
$('#ewww-clean-meta-progress').html('<span style="color: red"><b>' + ewww_response.error + '</b></span>');
|
||||
return false;
|
||||
}
|
||||
if(ewww_response.done) {
|
||||
$('#ewww-clean-meta-progress').html(ewww_vars.finished);
|
||||
$('#ewww-clean-meta-progressbar').progressbar("value", parseInt(ewww_vars.attachment_count));
|
||||
return;
|
||||
}
|
||||
ewww_clean_meta_total += ewww_response.success;
|
||||
if (ewww_clean_meta_total > ewww_vars.attachment_count) {
|
||||
ewww_clean_meta_total = ewww_vars.attachment_count;
|
||||
}
|
||||
$('#ewww-clean-meta-progressbar').progressbar("value", ewww_clean_meta_total);
|
||||
$('#ewww-clean-meta-progress').html('<p>' + ewww_clean_meta_total + '/' + ewww_vars.attachment_string + '</p>');
|
||||
ewwwCleanupMeta();
|
||||
});
|
||||
}
|
||||
$('.ewww-aux-table').on( 'click', '.ewww-remove-image', function() {
|
||||
var imageID = $(this).data('id');
|
||||
var ewww_image_removal = {
|
||||
action: 'bulk_aux_images_remove',
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
ewww_image_id: imageID,
|
||||
};
|
||||
$.post(ajaxurl, ewww_image_removal, function(response) {
|
||||
if(response == '1') {
|
||||
$('#ewww-image-' + imageID).remove();
|
||||
var ewww_prev_count = ewww_vars.image_count;
|
||||
ewww_vars.image_count--;
|
||||
ewww_vars.count_string = ewww_vars.count_string.replace( ewww_prev_count, ewww_vars.image_count );
|
||||
$('.displaying-num').text(ewww_vars.count_string);
|
||||
} else {
|
||||
alert(ewww_vars.remove_failed);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
$('.ewww-aux-table').on( 'click', '.ewww-restore-image', function() {
|
||||
var imageID = $(this).data('id');
|
||||
var ewww_image_restore = {
|
||||
action: 'ewww_manual_image_restore_single',
|
||||
ewww_wpnonce: ewww_vars._wpnonce,
|
||||
ewww_image_id: imageID,
|
||||
};
|
||||
var original_html = $('#ewww-image-' + imageID + ' td:last-child').html();
|
||||
$('#ewww-image-' + imageID + ' td:last-child').html(ewww_vars.restoring);
|
||||
$.post(ajaxurl, ewww_image_restore, function(response) {
|
||||
var is_json = true;
|
||||
try {
|
||||
var ewww_response = JSON.parse(response);
|
||||
} catch (err) {
|
||||
alert( ewww_vars.invalid_response );
|
||||
console.log( response );
|
||||
return false;
|
||||
}
|
||||
if ( ewww_response.success == '1') {
|
||||
$('#ewww-image-' + imageID + ' td:last-child').html(ewww_vars.original_restored);
|
||||
} else if (ewww_response.error) {
|
||||
$('#ewww-image-' + imageID + ' td:last-child').html(original_html);
|
||||
alert(ewww_response.error);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
});
|
43
wp-content/plugins/ewww-image-optimizer/includes/flag.js
Normal file
43
wp-content/plugins/ewww-image-optimizer/includes/flag.js
Normal file
@ -0,0 +1,43 @@
|
||||
jQuery(document).on( 'click', '.ewww-manual-optimize', function() {
|
||||
var post_id = jQuery(this).data('id');
|
||||
var ewww_nonce = jQuery(this).data('nonce');
|
||||
var ewww_manual_optimize_data = {
|
||||
action: 'ewww_flag_manual',
|
||||
ewww_manual_nonce: ewww_nonce,
|
||||
ewww_force: 1,
|
||||
ewww_attachment_ID: post_id,
|
||||
};
|
||||
jQuery('#ewww-flag-status-' + post_id ).html( ewww_vars.optimizing );
|
||||
jQuery.post(ajaxurl, ewww_manual_optimize_data, function(response) {
|
||||
var ewww_manual_response = JSON.parse(response);
|
||||
if (ewww_manual_response.error) {
|
||||
jQuery('#ewww-flag-status-' + post_id ).html( ewww_manual_response.error );
|
||||
} else if (ewww_manual_response.success) {
|
||||
jQuery('#ewww-flag-status-' + post_id ).html( ewww_manual_response.success );
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
jQuery(document).on( 'click', '.ewww-manual-image-restore', function() {
|
||||
var post_id = jQuery(this).data('id');
|
||||
var ewww_nonce = jQuery(this).data('nonce');
|
||||
var ewww_manual_optimize_data = {
|
||||
action: 'ewww_flag_image_restore',
|
||||
ewww_manual_nonce: ewww_nonce,
|
||||
ewww_attachment_ID: post_id,
|
||||
};
|
||||
jQuery('#ewww-flag-status-' + post_id ).html( ewww_vars.restoring );
|
||||
jQuery.post(ajaxurl, ewww_manual_optimize_data, function(response) {
|
||||
var ewww_manual_response = JSON.parse(response);
|
||||
if (ewww_manual_response.error) {
|
||||
jQuery('#ewww-flag-status-' + post_id ).html( ewww_manual_response.error );
|
||||
} else if (ewww_manual_response.success) {
|
||||
jQuery('#ewww-flag-status-' + post_id ).html( ewww_manual_response.success );
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
jQuery(document).on('click', '.ewww-show-debug-meta', function() {
|
||||
var post_id = jQuery(this).data('id');
|
||||
jQuery('#ewww-debug-meta-' + post_id).toggle();
|
||||
});
|
981
wp-content/plugins/ewww-image-optimizer/includes/jquery-ui-1.10.1.custom.css
vendored
Normal file
981
wp-content/plugins/ewww-image-optimizer/includes/jquery-ui-1.10.1.custom.css
vendored
Normal file
@ -0,0 +1,981 @@
|
||||
/*! jQuery UI - v1.10.1 - 2013-03-14
|
||||
* Copyright 2013 jQuery Foundation and other contributors Licensed MIT */
|
||||
/* includes styling for progressbar and tooltip elements */
|
||||
/* Layout helpers
|
||||
----------------------------------*/
|
||||
.ui-helper-hidden {
|
||||
display: none;
|
||||
}
|
||||
.ui-helper-hidden-accessible {
|
||||
border: 0;
|
||||
clip: rect(0 0 0 0);
|
||||
height: 1px;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
padding: 0;
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
}
|
||||
.ui-helper-reset {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
outline: 0;
|
||||
line-height: 1.3;
|
||||
text-decoration: none;
|
||||
font-size: 100%;
|
||||
list-style: none;
|
||||
}
|
||||
.ui-helper-clearfix:before,
|
||||
.ui-helper-clearfix:after {
|
||||
content: "";
|
||||
display: table;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
.ui-helper-clearfix:after {
|
||||
clear: both;
|
||||
}
|
||||
.ui-helper-clearfix {
|
||||
min-height: 0; /* support: IE7 */
|
||||
}
|
||||
.ui-helper-zfix {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
top: 0;
|
||||
left: 0;
|
||||
position: absolute;
|
||||
opacity: 0;
|
||||
filter:Alpha(Opacity=0);
|
||||
}
|
||||
.ui-front {
|
||||
z-index: 100;
|
||||
}
|
||||
/* Interaction Cues
|
||||
----------------------------------*/
|
||||
.ui-state-disabled {
|
||||
cursor: default !important;
|
||||
}
|
||||
|
||||
/* Misc visuals
|
||||
----------------------------------*/
|
||||
/* Corner radius */
|
||||
.ui-corner-all,
|
||||
.ui-corner-top,
|
||||
.ui-corner-left,
|
||||
.ui-corner-tl {
|
||||
border-top-left-radius: 22px;
|
||||
}
|
||||
.ui-corner-all,
|
||||
.ui-corner-top,
|
||||
.ui-corner-right,
|
||||
.ui-corner-tr {
|
||||
border-top-right-radius: 22px;
|
||||
}
|
||||
.ui-corner-all,
|
||||
.ui-corner-bottom,
|
||||
.ui-corner-left,
|
||||
.ui-corner-bl {
|
||||
border-bottom-left-radius: 22px;
|
||||
}
|
||||
.ui-corner-all,
|
||||
.ui-corner-bottom,
|
||||
.ui-corner-right,
|
||||
.ui-corner-br {
|
||||
border-bottom-right-radius: 22px;
|
||||
}
|
||||
/* Overlays */
|
||||
.ui-widget-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.ui-progressbar {
|
||||
height: 22px;
|
||||
text-align: left;
|
||||
overflow: hidden;
|
||||
}
|
||||
.ui-progressbar .ui-progressbar-value {
|
||||
margin: 0px;
|
||||
height: 100%;
|
||||
|
||||
}
|
||||
.ui-accordion .ui-accordion-header {
|
||||
display: block;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
margin-top: 2px;
|
||||
padding: .5em .5em .5em .7em;
|
||||
min-height: 0; /* support: IE7 */
|
||||
}
|
||||
.ui-accordion .ui-accordion-icons {
|
||||
padding-left: 2.2em;
|
||||
}
|
||||
.ui-accordion .ui-accordion-noicons {
|
||||
padding-left: .7em;
|
||||
}
|
||||
.ui-accordion .ui-accordion-icons .ui-accordion-icons {
|
||||
padding-left: 2.2em;
|
||||
}
|
||||
.ui-accordion .ui-accordion-header .ui-accordion-header-icon {
|
||||
position: absolute;
|
||||
left: .5em;
|
||||
top: 50%;
|
||||
margin-top: -8px;
|
||||
}
|
||||
.ui-accordion .ui-accordion-content {
|
||||
padding: 1em 2.2em;
|
||||
border-top: 0;
|
||||
overflow: auto;
|
||||
border-top-left-radius: 0px;
|
||||
border-top-right-radius: 0px;
|
||||
}
|
||||
.ui-slider {
|
||||
position: relative;
|
||||
text-align: left;
|
||||
}
|
||||
.ui-slider .ui-slider-handle {
|
||||
position: absolute;
|
||||
z-index: 2;
|
||||
width: 1.2em;
|
||||
height: 1.2em;
|
||||
cursor: default;
|
||||
}
|
||||
.ui-slider .ui-slider-range {
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
font-size: .7em;
|
||||
display: block;
|
||||
border: 0;
|
||||
background-position: 0 0;
|
||||
}
|
||||
|
||||
/* For IE8 - See #6727 */
|
||||
.ui-slider.ui-state-disabled .ui-slider-handle,
|
||||
.ui-slider.ui-state-disabled .ui-slider-range {
|
||||
filter: inherit;
|
||||
}
|
||||
|
||||
.ui-slider-horizontal {
|
||||
height: .8em;
|
||||
}
|
||||
.ui-slider-horizontal .ui-slider-handle {
|
||||
top: -.3em;
|
||||
margin-left: -.6em;
|
||||
}
|
||||
.ui-slider-horizontal .ui-slider-range {
|
||||
top: 0;
|
||||
height: 100%;
|
||||
}
|
||||
.ui-slider-horizontal .ui-slider-range-min {
|
||||
left: 0;
|
||||
}
|
||||
.ui-slider-horizontal .ui-slider-range-max {
|
||||
right: 0;
|
||||
}
|
||||
|
||||
.ui-slider-vertical {
|
||||
width: .8em;
|
||||
height: 100px;
|
||||
}
|
||||
.ui-slider-vertical .ui-slider-handle {
|
||||
left: -.3em;
|
||||
margin-left: 0;
|
||||
margin-bottom: -.6em;
|
||||
}
|
||||
.ui-slider-vertical .ui-slider-range {
|
||||
left: 0;
|
||||
width: 100%;
|
||||
}
|
||||
.ui-slider-vertical .ui-slider-range-min {
|
||||
bottom: 0;
|
||||
}
|
||||
.ui-slider-vertical .ui-slider-range-max {
|
||||
top: 0;
|
||||
}
|
||||
/* Component containers
|
||||
----------------------------------*/
|
||||
.ui-widget-content {
|
||||
background: none repeat scroll 0% 0% #dddddd;
|
||||
-webkit-border-radius: 22px;
|
||||
border-radius: 22px;
|
||||
-webkit-box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
|
||||
box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
|
||||
}
|
||||
.ui-widget-content a {
|
||||
color: #222222;
|
||||
}
|
||||
.ui-widget-header {
|
||||
z-index: 9;
|
||||
background-color: #0074a2;
|
||||
-webkit-border-radius: 22px;
|
||||
border-radius: 22px;
|
||||
}
|
||||
.ui-widget-header a {
|
||||
color: #ffffff;
|
||||
}
|
||||
/* Interaction states
|
||||
----------------------------------*/
|
||||
.ui-state-default,
|
||||
.ui-widget-content .ui-state-default,
|
||||
.ui-widget-header .ui-state-default {
|
||||
border: 1px solid #d3d3d3;
|
||||
background: #e6e6e6 50% 50% repeat-x;
|
||||
font-weight: normal;
|
||||
color: #555555;
|
||||
}
|
||||
.ui-state-default a,
|
||||
.ui-state-default a:link,
|
||||
.ui-state-default a:visited {
|
||||
color: #555555;
|
||||
text-decoration: none;
|
||||
}
|
||||
.ui-state-hover,
|
||||
.ui-widget-content .ui-state-hover,
|
||||
.ui-widget-header .ui-state-hover,
|
||||
.ui-state-focus,
|
||||
.ui-widget-content .ui-state-focus,
|
||||
.ui-widget-header .ui-state-focus {
|
||||
border: 1px solid #999999;
|
||||
background: #dadada 50% 50% repeat-x;
|
||||
font-weight: normal;
|
||||
color: #212121;
|
||||
}
|
||||
.ui-state-hover a,
|
||||
.ui-state-hover a:hover,
|
||||
.ui-state-hover a:link,
|
||||
.ui-state-hover a:visited {
|
||||
color: #212121;
|
||||
text-decoration: none;
|
||||
}
|
||||
.ui-state-active,
|
||||
.ui-widget-content .ui-state-active,
|
||||
.ui-widget-header .ui-state-active {
|
||||
border: 1px solid #aaaaaa;
|
||||
background: #ffffff 50% 50% repeat-x;
|
||||
font-weight: normal;
|
||||
color: #212121;
|
||||
}
|
||||
.ui-state-active a,
|
||||
.ui-state-active a:link,
|
||||
.ui-state-active a:visited {
|
||||
color: #212121;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/* Interaction Cues
|
||||
----------------------------------*/
|
||||
.ui-state-highlight,
|
||||
.ui-widget-content .ui-state-highlight,
|
||||
.ui-widget-header .ui-state-highlight {
|
||||
border: 1px solid #fcefa1;
|
||||
color: #363636;
|
||||
}
|
||||
.ui-state-highlight a,
|
||||
.ui-widget-content .ui-state-highlight a,
|
||||
.ui-widget-header .ui-state-highlight a {
|
||||
color: #363636;
|
||||
}
|
||||
.ui-state-error,
|
||||
.ui-widget-content .ui-state-error,
|
||||
.ui-widget-header .ui-state-error {
|
||||
border: 1px solid #cd0a0a;
|
||||
color: #cd0a0a;
|
||||
}
|
||||
.ui-state-error a,
|
||||
.ui-widget-content .ui-state-error a,
|
||||
.ui-widget-header .ui-state-error a {
|
||||
color: #cd0a0a;
|
||||
}
|
||||
.ui-state-error-text,
|
||||
.ui-widget-content .ui-state-error-text,
|
||||
.ui-widget-header .ui-state-error-text {
|
||||
color: #cd0a0a;
|
||||
}
|
||||
.ui-priority-primary,
|
||||
.ui-widget-content .ui-priority-primary,
|
||||
.ui-widget-header .ui-priority-primary {
|
||||
font-weight: bold;
|
||||
}
|
||||
.ui-priority-secondary,
|
||||
.ui-widget-content .ui-priority-secondary,
|
||||
.ui-widget-header .ui-priority-secondary {
|
||||
opacity: .7;
|
||||
filter:Alpha(Opacity=70);
|
||||
font-weight: normal;
|
||||
}
|
||||
.ui-state-disabled,
|
||||
.ui-widget-content .ui-state-disabled,
|
||||
.ui-widget-header .ui-state-disabled {
|
||||
opacity: .35;
|
||||
filter:Alpha(Opacity=35);
|
||||
background-image: none;
|
||||
}
|
||||
.ui-state-disabled .ui-icon {
|
||||
filter:Alpha(Opacity=35); /* For IE8 - See #6059 */
|
||||
}
|
||||
/* jQuery UI Tooltip 1.10.1 */
|
||||
.ui-tooltip {
|
||||
padding: 8px;
|
||||
position: absolute;
|
||||
z-index: 9999;
|
||||
max-width: 300px;
|
||||
min-width: 130px;
|
||||
border-radius: 8px;
|
||||
background: #fff;
|
||||
}
|
||||
body .ui-tooltip {
|
||||
border-width: 1px;
|
||||
}
|
||||
.ui-tooltip, .arrow:after {
|
||||
border: 1px solid #272727;
|
||||
}
|
||||
.ui-tooltip {
|
||||
padding: 5px 10px;
|
||||
}
|
||||
.arrow {
|
||||
width: 70px;
|
||||
height: 16px;
|
||||
overflow: hidden;
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
margin-left: -35px;
|
||||
bottom: -16px;
|
||||
z-index: 99999;
|
||||
}
|
||||
.arrow.top {
|
||||
top: -16px;
|
||||
bottom: auto;
|
||||
}
|
||||
.arrow.left {
|
||||
left: 20%;
|
||||
}
|
||||
.arrow:after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
left: 20px;
|
||||
top: -20px;
|
||||
width: 25px;
|
||||
height: 25px;
|
||||
background-color: #FFF;
|
||||
-webkit-transform: rotate(45deg);
|
||||
-moz-transform: rotate(45deg);
|
||||
-ms-transform: rotate(45deg);
|
||||
-o-transform: rotate(45deg);
|
||||
tranform: rotate(45deg);
|
||||
}
|
||||
.arrow.top:after {
|
||||
bottom: -20px;
|
||||
top: auto;
|
||||
}
|
||||
/* media library actions and details */
|
||||
a.ewww-remove-image, a.ewww-restore-image {
|
||||
cursor: pointer;
|
||||
}
|
||||
.ewww-attachment-detail table td, .ewww-attachment-detail table th {
|
||||
padding: 8px 10px;
|
||||
}
|
||||
.ewww-attachment-detail table th {
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
}
|
||||
.ewww-attachment-detail table {
|
||||
width: 100%;
|
||||
border: 1px solid #e5e5e5;
|
||||
border-collapse: collapse;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.ewww-attachment-detail {
|
||||
padding: 13px 0px 0px;
|
||||
}
|
||||
.ewww-variant-icon {
|
||||
color: white;
|
||||
background-color: #f1900e;
|
||||
border-radius: 50%;
|
||||
font-size: 10px;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
line-height: 16px;
|
||||
text-align: center;
|
||||
display: inline-block;
|
||||
padding-bottom: 0px;
|
||||
}
|
||||
/* bulk and settings ui */
|
||||
#ewww-bulk-credits-available {
|
||||
margin-left: 20px;
|
||||
padding: 4px 8px;
|
||||
position: relative;
|
||||
top: -3px;
|
||||
border: 1px solid #2271b1;
|
||||
border-radius: 2px;
|
||||
text-shadow: none;
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
line-height: normal;
|
||||
color: #2271b1;
|
||||
background: #f6f7f7;
|
||||
}
|
||||
h2.ewww-hndle {
|
||||
font-size: 14px;
|
||||
padding: 8px 12px;
|
||||
margin: 0;
|
||||
line-height: 1.4;
|
||||
user-select: none;
|
||||
border-bottom: 1px solid #eee;
|
||||
touch-action: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
button.ewww-handlediv {
|
||||
color: #72777c;
|
||||
display: block;
|
||||
cursor: pointer;
|
||||
float: right;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
}
|
||||
.js .postbox .ewww-handlediv .toggle-indicator:before {
|
||||
margin-top: 4px;
|
||||
width: 20px;
|
||||
border-radius: 50%;
|
||||
text-indent: -1px;
|
||||
}
|
||||
.js .postbox.closed .ewww-handlediv .toggle-indicator:before {
|
||||
content: "\f140";
|
||||
}
|
||||
.ewww-bulk-error, .ewww-ajax-error {
|
||||
color: red;
|
||||
}
|
||||
.ewww-bulk-error a, .ewww-bulk-error a:visited {
|
||||
color: red;
|
||||
}
|
||||
#ewww-bulk-controls {
|
||||
border: solid 1px #e5e5e5;
|
||||
background: #fff;
|
||||
padding: 10px;
|
||||
float: right;
|
||||
width: 24%;
|
||||
max-width: 360px;
|
||||
margin-left: 15px;
|
||||
}
|
||||
#ewww-bulk-forms {
|
||||
float: left;
|
||||
min-width: 50%;
|
||||
max-width: 65%;
|
||||
border: solid 1px #e5e5e5;
|
||||
background: #fff;
|
||||
padding: 0 10px 12px;
|
||||
}
|
||||
#ewww-delay-slider {
|
||||
margin: 0 0 15px 10px;
|
||||
max-width: 500px;
|
||||
}
|
||||
#ewww-delay {
|
||||
max-width: 50px;
|
||||
min-width: 30px;
|
||||
}
|
||||
.ngg-admin .ewww_bulk_wrap {
|
||||
margin-left: 20px;
|
||||
}
|
||||
.ngg-admin .wrap h2.wp-heading-inline {
|
||||
display: inline-block;
|
||||
margin-right: 5px;
|
||||
}
|
||||
@media screen and (max-width: 780px) {
|
||||
#ewww-bulk-controls {
|
||||
float: none;
|
||||
margin-left: 0px;
|
||||
max-width: none;
|
||||
width: auto;
|
||||
}
|
||||
#ewww-bulk-forms {
|
||||
margin: 10px 0;
|
||||
float: none;
|
||||
max-width: none;
|
||||
width: auto;
|
||||
}
|
||||
}
|
||||
/* settings tabs */
|
||||
.ewww-tab span { font-size: 14px; font-weight: 600; color: #555; text-decoration: none; line-height: 36px; padding: 0 10px; }
|
||||
.ewww-tab span:hover { color: #464646; }
|
||||
.ewww-tab { margin: 0 0 0 5px; padding: 0px; border-width: 1px 1px 1px; border-style: solid solid none; border-image: none; border-color: #ccc; display: inline-block; background-color: #e4e4e4; cursor: pointer }
|
||||
.ewww-tab:hover { background-color: #fff }
|
||||
.ewww-selected { background-color: #f1f1f1; margin-bottom: -1px; border-bottom: 1px solid #f1f1f1 }
|
||||
.ewww-selected span { color: #000; }
|
||||
.ewww-selected:hover { background-color: #f1f1f1; }
|
||||
.ewww-tab-nav { list-style: none; margin: 10px 0 0; padding-left: 5px; border-bottom: 1px solid #ccc; }
|
||||
/* optimization status section */
|
||||
#ewww-widgets {
|
||||
width: 100%;
|
||||
/* max-width: 1400px; */
|
||||
clear: right;
|
||||
}
|
||||
#ewww-status .inside {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
.ewww-blocks {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
#ewww-status h2.ewww-hndle {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.ewww-blocks div.ewww-status-detail {
|
||||
border-left: 1px solid #e2e2e2;
|
||||
margin: 0px;
|
||||
padding: 2em;
|
||||
}
|
||||
.ewww-blocks div.ewww-status-detail:first-child {
|
||||
border-left: 0;
|
||||
}
|
||||
.ewww-blocks div.ewww-status-detail {
|
||||
border-top: 1px solid #e2e2e2;
|
||||
/* display: block; */
|
||||
text-align: center;
|
||||
/* margin: 2em; */
|
||||
}
|
||||
.ewww-blocks #ewww-notices {
|
||||
text-align: left;
|
||||
}
|
||||
#ewww-notices p:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
.ewww-guage {
|
||||
position: relative;
|
||||
margin: 0 auto 1rem;
|
||||
padding: 0;
|
||||
width: 120px;
|
||||
height: 120px;
|
||||
}
|
||||
.ewww-guage svg {
|
||||
-webkit-transform: rotate(-90deg);
|
||||
transform: rotate(-90deg);
|
||||
}
|
||||
.ewww-inactive,
|
||||
.ewww-active {
|
||||
fill: none;
|
||||
}
|
||||
.ewww-inactive {
|
||||
stroke: #e6e6e6;
|
||||
}
|
||||
#ewww-score-bars {
|
||||
flex:1 1 auto;
|
||||
}
|
||||
#ewww-compress, #ewww-savings, #easyio-savings {
|
||||
flex: 1 1 120px;
|
||||
}
|
||||
#ewww-savings p {
|
||||
margin: 0.5em 0;
|
||||
}
|
||||
#ewww-compress-guage .ewww-active {
|
||||
stroke-linecap: round;
|
||||
}
|
||||
#ewww-compress-guage .ewww-red {
|
||||
stroke: #dc3232;
|
||||
}
|
||||
#ewww-compress-guage .ewww-orange {
|
||||
stroke: #ffb900;
|
||||
}
|
||||
#ewww-compress-guage .ewww-green {
|
||||
stroke: #46b450;
|
||||
}
|
||||
#ewww-resize-guage .ewww-active {
|
||||
stroke: #1d3c71;
|
||||
stroke-linecap: round;
|
||||
}
|
||||
#ewww-savings-guage .ewww-active {
|
||||
stroke: #3eadc9;
|
||||
stroke-linecap: round;
|
||||
}
|
||||
#easyio-savings-guage .ewww-active {
|
||||
stroke: #3eadc9;
|
||||
stroke: #1d3c71;
|
||||
stroke-linecap: round;
|
||||
}
|
||||
#ewww-compress-guage .ewww-score {
|
||||
color: #444;
|
||||
}
|
||||
#ewww-resize-guage .ewww-score {
|
||||
color: #1d3c71;
|
||||
}
|
||||
.ewww-score {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
transform: translate(-50%, -50%);
|
||||
font-size: 1.3rem;
|
||||
font-weight: bold;
|
||||
line-height: 1.5;
|
||||
}
|
||||
#ewww-savings-guage .ewww-score {
|
||||
font-size: 1rem;
|
||||
color: #3eadc9;
|
||||
white-space: nowrap;
|
||||
}
|
||||
#easyio-savings-guage .ewww-score {
|
||||
font-size: 1rem;
|
||||
color: #1d3c71;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.ewww-bar-container {
|
||||
background-color: #e6e6e6;
|
||||
/* border: 1px solid #ccd0d4; */
|
||||
border-radius: 6px;
|
||||
/* box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04); */
|
||||
height: 12px;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
.ewww-bar-fill {
|
||||
margin: 0;
|
||||
height: 100%;
|
||||
width: 0;
|
||||
}
|
||||
#ewww-speed-container .ewww-red {
|
||||
background-color: #dc3232;
|
||||
}
|
||||
#ewww-speed-container .ewww-orange {
|
||||
background-color: #ffb900;
|
||||
}
|
||||
#ewww-speed-container .ewww-green {
|
||||
background-color: #46b450;
|
||||
}
|
||||
#ewww-savings-container .ewww-bar-fill {
|
||||
background-color: #3eadc9;
|
||||
}
|
||||
#easyio-savings-container .ewww-bar-fill {
|
||||
background-color: #1d3c71;
|
||||
}
|
||||
.ewww-bar-caption {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.ewww-bar-caption p {
|
||||
margin: 0.5em 0;
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
}
|
||||
.ewww-bar-score {
|
||||
font-size: 1.0rem;
|
||||
font-weight: bold;
|
||||
line-height: 1.5;
|
||||
}
|
||||
#ewww-savings-flex .ewww-bar-score {
|
||||
color: #3eadc9;
|
||||
}
|
||||
#easyio-savings-flex .ewww-bar-score {
|
||||
color: #1d3c71;
|
||||
}
|
||||
.ewww-recommend {
|
||||
display: none;
|
||||
text-align: left;
|
||||
border-top: 1px solid #ccd0d4;
|
||||
border-bottom: 1px solid #ccd0d4;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.ui-tooltip ul.ewww-tooltip/*, .ewww-recommend ul.ewww-tooltip*/ {
|
||||
list-style: disc outside none;
|
||||
}
|
||||
.ui-tooltip ul.ewww-tooltip li/*, .ewww-recommend ul.ewww-tooltip li*/ {
|
||||
margin-left: 1em;
|
||||
}
|
||||
/* other settings UI */
|
||||
#ewww-rescue-mode {
|
||||
margin: 10px 0;
|
||||
}
|
||||
p.debug-actions {
|
||||
clear: both;
|
||||
}
|
||||
#ewww-debug-info {
|
||||
border:1px solid #e5e5e5;
|
||||
background: #fff;
|
||||
overflow: auto;
|
||||
height: 300px;
|
||||
width: 800px;
|
||||
margin-top: 5px;
|
||||
}
|
||||
#ewww-webp-rewrite #webp-rewrite-rules {
|
||||
background-color: white;
|
||||
border: 1px solid #ccd0d4;
|
||||
clear: both;
|
||||
padding: 10px;
|
||||
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
#ewww-webp-rewrite button {
|
||||
margin-top: 1em;
|
||||
}
|
||||
#ewww-webp-image {
|
||||
float: right;
|
||||
padding: 0 0 10px 10px;
|
||||
/*padding: 0 1px 10px 10px;*/
|
||||
}
|
||||
div#ewww-webp-rewrite-status {
|
||||
font-weight: bold;
|
||||
}
|
||||
p#ewww-webp-rewrite-status {
|
||||
font-style: italic;
|
||||
}
|
||||
#ewwwio-easy-activate, #ewwwio-easy-deactivate, #ewwwio-easy-activate-network, #ewwwio-easy-register-network {
|
||||
margin-top: 10px;
|
||||
}
|
||||
#ewwwio-easy-deregister {
|
||||
vertical-align: bottom;
|
||||
padding-left: 20px;
|
||||
line-height: 2.15;
|
||||
}
|
||||
.ewwwio-notice {
|
||||
background-color: white;
|
||||
border: 1px solid #ccd0d4;
|
||||
border-left: 4px solid #3eadc9;
|
||||
margin: 10px 10px 15px 0;
|
||||
padding: 12px;
|
||||
}
|
||||
.ewwwio-notice.notice-warning {
|
||||
border-left-color: #ffb900;
|
||||
}
|
||||
.ewwwio-notice.notice-success {
|
||||
border-left-color: #46b450;
|
||||
}
|
||||
#ewwwio-easy-register-failed {
|
||||
display: none;
|
||||
}
|
||||
#ewwwio-api-activation-result, #ewwwio-easy-activation-result, #ewww-webp-rewrite-result {
|
||||
display: none;
|
||||
background-color: white;
|
||||
border: 1px solid #ccd0d4;
|
||||
border-left: 4px solid #3eadc9;
|
||||
margin: 10px 10px 15px 0;
|
||||
padding: 12px;
|
||||
font-weight: bold;
|
||||
}
|
||||
#ewww-webp-rewrite-result {
|
||||
margin-right: 110px;
|
||||
}
|
||||
#ewwwio-api-activation-result.error, #ewwwio-easy-activation-result.error, #ewww-webp-rewrite-result.error {
|
||||
border-left-color: #dc3232;
|
||||
}
|
||||
#ewwwio-easy-activation-progressbar {
|
||||
margin: 10px 0;
|
||||
}
|
||||
#ewww-webp-rewrite-result p {
|
||||
/* margin: 0.5em 0; */
|
||||
}
|
||||
#ewww_image_optimizer_cloud_key_container th, #ewww_image_optimizer_exactdn_container th, #swis_promo_container th {
|
||||
color: #3eadc9;
|
||||
}
|
||||
#ewww_image_optimizer_cloud_key_container td, #ewww_image_optimizer_exactdn_container td, #swis_promo_container td {
|
||||
background-color: white;
|
||||
border: 1px solid #ccd0d4;
|
||||
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
#ewww_image_optimizer_cloud_key_container .dashicons-yes {
|
||||
font-size: 30px;
|
||||
}
|
||||
#ewwwio-exactdn-anchor {
|
||||
display: block;
|
||||
position: relative;
|
||||
top: -40px;
|
||||
visibility: hidden;
|
||||
}
|
||||
#exactdn_site_url {
|
||||
cursor: pointer;
|
||||
}
|
||||
/* .top-bar is for the ewww.io iframe(s) */
|
||||
.ewww-attachment-detail-container, .top-bar, #exactdn-site-url-copied, #exactdn-site-url-copy, #ewwwio-api-activation-processing, #ewwwio-easy-activation-processing, #ewwwio-webp-storage-warning {
|
||||
display: none;
|
||||
}
|
||||
#ewwwio-rescue ul {
|
||||
list-style: disc;
|
||||
margin-left: 10px;
|
||||
}
|
||||
#ewwwio-wizard, #ewwwio-rescue {
|
||||
display: flex;
|
||||
max-width: 450px;
|
||||
flex-direction: column;
|
||||
margin: auto;
|
||||
padding: 5% 0;
|
||||
}
|
||||
#ewwwio-rescue .ewww-help-beacon-single {
|
||||
margin: 0px;
|
||||
}
|
||||
#ewwwio-wizard-header, #ewwwio-rescue-header {
|
||||
background-color: #3eadc9;
|
||||
}
|
||||
#ewwwio-wizard-header img, #ewwwio-rescue-header img {
|
||||
margin: 15px auto;
|
||||
display: block;
|
||||
}
|
||||
#ewwwio-wizard-body, #ewwwio-rescue-body {
|
||||
background-color: #fff;
|
||||
padding: 20px;
|
||||
}
|
||||
.ewwwio-intro-text {
|
||||
font-weight: bold;
|
||||
font-size: 1.3em;
|
||||
margin: 1em 0;
|
||||
}
|
||||
.ewwwio-wizard-form {
|
||||
margin: auto 0;
|
||||
}
|
||||
.ewwwio-wizard-form-group {
|
||||
margin-bottom: 2em;
|
||||
}
|
||||
.ewwwio-wizard-form .ewwwio-premium-setup {
|
||||
display: none;
|
||||
margin-left: 2em;
|
||||
}
|
||||
.ewwwio-wizard-form .ewwwio-premium-setup label {
|
||||
font-weight: bold;
|
||||
}
|
||||
.ewwwio-wizard-form .description {
|
||||
margin-bottom: 20px;
|
||||
color: #666;
|
||||
}
|
||||
.ewwwio-wizard-form #ewww_image_optimizer_cloud_key {
|
||||
width: 100%;
|
||||
max-width: 300px;
|
||||
}
|
||||
.ewwwio-flex-space-between {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
#ewwwio-banner {
|
||||
display: flex;
|
||||
margin: 0px;
|
||||
padding: 15px;
|
||||
background-color: #3eadc9;
|
||||
}
|
||||
#ewwwio-banner div {
|
||||
width: 100%;
|
||||
}
|
||||
#ewwwio-banner img:first-child {
|
||||
margin: auto 10px auto 0;
|
||||
}
|
||||
#ewwwio-banner a.ewww-help-beacon-single img {
|
||||
padding: 0;
|
||||
}
|
||||
#ewwwio-banner p:first-of-type {
|
||||
/* margin-top: 0; */
|
||||
}
|
||||
#ewwwio-banner p {
|
||||
color: #fff;
|
||||
/* margin-bottom: 1.0em; */
|
||||
/* line-height: 1; */
|
||||
}
|
||||
#ewwwio-banner #ewww-review a:first-child {
|
||||
padding-left: 20px;
|
||||
}
|
||||
#ewwwio-banner #ewww-review {
|
||||
white-space: nowrap;
|
||||
}
|
||||
#ewwwio-banner a {
|
||||
color: #272727;
|
||||
}
|
||||
#ewwwio-banner a span.dashicons {
|
||||
color: #fff;
|
||||
text-decoration: none;
|
||||
font-size: 16px;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
#ewwwio-banner #ewww-news-button {
|
||||
margin-top: 0;
|
||||
}
|
||||
#ewww-settings-form a.ewww-orange-button {
|
||||
background: #f18f07;
|
||||
border-color: #f18f07;
|
||||
}
|
||||
#ewww-settings-form a.ewww-orange-button:hover {
|
||||
background: #f39c12;
|
||||
border-color: #f18f07;
|
||||
}
|
||||
#ewww-settings-form a.ewww-orange-button:focus {
|
||||
box-shadow: 0 0 0 1px #fff,0 0 0 3px #f18f07;
|
||||
}
|
||||
#ewww-general-settings a.ewww-upgrade {
|
||||
font-weight:bold;
|
||||
background-color: #3eadc9;
|
||||
border-color: #3eadc9;
|
||||
}
|
||||
#ewww-general-settings a.ewww-upgrade:hover {
|
||||
background-color: #40bad4;
|
||||
border-color: #3ca0be;
|
||||
}
|
||||
#ewww-general-settings a.ewww-upgrade:focus {
|
||||
box-shadow: 0 0 0 1px #fff,0 0 0 3px #3ca0be;
|
||||
}
|
||||
.ewww-help-beacon-multi, .ewww-help-beacon-single, .ewww-help-external {
|
||||
margin: 3px;
|
||||
}
|
||||
/* mobile rules */
|
||||
@media screen and (max-width: 868px) {
|
||||
.ewww-blocks {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.ewww-blocks div.ewww-status-detail {
|
||||
padding: 1em 2em;
|
||||
}
|
||||
.ewww-status-detail p {
|
||||
margin: 0.5em 0;
|
||||
}
|
||||
.ewww-blocks #ewww-notices {
|
||||
width: 100%;
|
||||
border-left: 0;
|
||||
}
|
||||
.ewww-overrides-nav {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
@media screen and (max-width: 600px) {
|
||||
#ewwwio-banner img:first-child {
|
||||
width: 100px;
|
||||
height: auto;
|
||||
}
|
||||
.ewww-blocks div.ewww-status-detail {
|
||||
padding: 1em;
|
||||
}
|
||||
.ewww-tab-nav {
|
||||
border-style: none;
|
||||
}
|
||||
.ewww-tab {
|
||||
margin: 0 0 3px 3px;
|
||||
border-style: solid;
|
||||
}
|
||||
.ewww-selected {
|
||||
border-color: #ccc;
|
||||
}
|
||||
.ewww-tab span {
|
||||
font-size: 12px;
|
||||
padding: 2px 3px;
|
||||
|
||||
}
|
||||
}
|
||||
@media screen and (max-width: 782px) {
|
||||
#ewwwio-banner .ewwwio-flex-space-between {
|
||||
flex-direction: column-reverse;
|
||||
}
|
||||
#ewwwio-banner #ewww-review a:first-child {
|
||||
padding-left: 0;
|
||||
}
|
||||
p.debug-actions {
|
||||
margin-top: 30px;
|
||||
clear: none;
|
||||
}
|
||||
#ewww-debug-info {
|
||||
width: auto;
|
||||
}
|
||||
#ewww-settings-disable-resizes th, #ewww-settings-disable-resizes td {
|
||||
display: table-cell;
|
||||
}
|
||||
#ewwwio-wizard-form input[type="checkbox"], #ewwwio-wizard-form input[type="radio"] {
|
||||
margin-top: 5px;
|
||||
}
|
||||
#ewww_image_optimizer_cloud_key_container td, #ewww_image_optimizer_exactdn_container td, #swis_promo_container td {
|
||||
padding: 10px;
|
||||
}
|
||||
}
|
@ -0,0 +1,547 @@
|
||||
(function(window, factory) {
|
||||
var globalInstall = function(){
|
||||
factory(window.lazySizes);
|
||||
window.removeEventListener('lazyunveilread', globalInstall, true);
|
||||
};
|
||||
|
||||
factory = factory.bind(null, window, window.document);
|
||||
|
||||
if(typeof module == 'object' && module.exports){
|
||||
factory(require('lazysizes'));
|
||||
} else if (typeof define == 'function' && define.amd) {
|
||||
define(['lazysizes'], factory);
|
||||
} else if(window.lazySizes) {
|
||||
globalInstall();
|
||||
} else {
|
||||
window.addEventListener('lazyunveilread', globalInstall, true);
|
||||
}
|
||||
}(window, function(window, document, lazySizes) {
|
||||
/*jshint eqnull:true */
|
||||
'use strict';
|
||||
var regBgUrlEscape;
|
||||
var autosizedElems = [];
|
||||
|
||||
if(document.addEventListener){
|
||||
regBgUrlEscape = /\(|\)|\s|'/;
|
||||
|
||||
addEventListener('lazybeforeunveil', function(e){
|
||||
if(e.detail.instance != lazySizes){return;}
|
||||
|
||||
var bg, bgWebP;
|
||||
if(!e.defaultPrevented) {
|
||||
|
||||
if(e.target.preload == 'none'){
|
||||
e.target.preload = 'auto';
|
||||
}
|
||||
|
||||
// handle data-back (so as not to conflict with the stock data-bg)
|
||||
bg = e.target.getAttribute('data-back');
|
||||
if (bg) {
|
||||
if(ewww_webp_supported) {
|
||||
console.log('checking for data-back-webp');
|
||||
bgWebP = e.target.getAttribute('data-back-webp');
|
||||
if (bgWebP) {
|
||||
console.log('replacing data-back with data-back-webp');
|
||||
bg = bgWebP;
|
||||
}
|
||||
}
|
||||
var dPR = (window.devicePixelRatio || 1);
|
||||
var targetWidth = Math.round(e.target.offsetWidth * dPR);
|
||||
var targetHeight = Math.round(e.target.offsetHeight * dPR);
|
||||
if ( 0 === bg.search(/\[/) ) {
|
||||
} else if (!shouldAutoScale(e.target)||!shouldAutoScale(e.target.parentNode)){
|
||||
} else if (lazySizes.hC(e.target,'wp-block-cover')) {
|
||||
console.log('found wp-block-cover with data-back');
|
||||
if (lazySizes.hC(e.target,'has-parallax')) {
|
||||
console.log('also has-parallax with data-back');
|
||||
targetWidth = Math.round(window.screen.width * dPR);
|
||||
targetHeight = Math.round(window.screen.height * dPR);
|
||||
} else if (targetHeight<300) {
|
||||
targetHeight = 430;
|
||||
}
|
||||
bg = constrainSrc(bg,targetWidth,targetHeight,'bg-cover');
|
||||
} else if (lazySizes.hC(e.target,'cover-image')){
|
||||
console.log('found .cover-image with data-back');
|
||||
bg = constrainSrc(bg,targetWidth,targetHeight,'bg-cover');
|
||||
} else if (lazySizes.hC(e.target,'elementor-bg')){
|
||||
console.log('found elementor-bg with data-back');
|
||||
bg = constrainSrc(bg,targetWidth,targetHeight,'bg-cover');
|
||||
} else if (lazySizes.hC(e.target,'et_parallax_bg')){
|
||||
console.log('found et_parallax_bg with data-back');
|
||||
bg = constrainSrc(bg,targetWidth,targetHeight,'bg-cover');
|
||||
} else if (lazySizes.hC(e.target,'bg-image-crop')){
|
||||
console.log('found bg-image-crop with data-back');
|
||||
bg = constrainSrc(bg,targetWidth,targetHeight,'bg-cover');
|
||||
} else {
|
||||
console.log('found other data-back');
|
||||
bg = constrainSrc(bg,targetWidth,targetHeight,'bg');
|
||||
}
|
||||
if ( e.target.style.backgroundImage && -1 === e.target.style.backgroundImage.search(/^initial/) ) {
|
||||
// Convert JSON for multiple URLs.
|
||||
if ( 0 === bg.search(/\[/) ) {
|
||||
console.log('multiple URLs to append');
|
||||
bg = JSON.parse(bg);
|
||||
bg.forEach(
|
||||
function(bg_url){
|
||||
bg_url = (regBgUrlEscape.test(bg_url) ? JSON.stringify(bg_url) : bg_url );
|
||||
}
|
||||
);
|
||||
bg = 'url("' + bg.join('"), url("') + '"';
|
||||
var new_bg = e.target.style.backgroundImage + ', ' + bg;
|
||||
console.log('setting .backgroundImage: ' + new_bg );
|
||||
e.target.style.backgroundImage = new_bg;
|
||||
} else {
|
||||
console.log( 'appending bg url: ' + e.target.style.backgroundImage + ', url(' + (regBgUrlEscape.test(bg) ? JSON.stringify(bg) : bg ) + ')' );
|
||||
e.target.style.backgroundImage = e.target.style.backgroundImage + ', url("' + (regBgUrlEscape.test(bg) ? JSON.stringify(bg) : bg ) + '")';
|
||||
}
|
||||
} else {
|
||||
// Convert JSON for multiple URLs.
|
||||
if ( 0 === bg.search(/\[/) ) {
|
||||
console.log('multiple URLs to insert');
|
||||
bg = JSON.parse(bg);
|
||||
bg.forEach(
|
||||
function(bg_url){
|
||||
bg_url = (regBgUrlEscape.test(bg_url) ? JSON.stringify(bg_url) : bg_url );
|
||||
}
|
||||
);
|
||||
bg = 'url("' + bg.join('"), url("') + '"';
|
||||
console.log('setting .backgroundImage: ' + bg );
|
||||
e.target.style.backgroundImage = bg;
|
||||
} else {
|
||||
console.log('setting .backgroundImage: ' + 'url(' + (regBgUrlEscape.test(bg) ? JSON.stringify(bg) : bg ) + ')');
|
||||
e.target.style.backgroundImage = 'url(' + (regBgUrlEscape.test(bg) ? JSON.stringify(bg) : bg ) + ')';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
|
||||
var shouldAutoScale = function(target){
|
||||
if (eio_lazy_vars.skip_autoscale == 1) {
|
||||
console.log('autoscale disabled globally');
|
||||
return false;
|
||||
}
|
||||
if (target.hasAttributes()) {
|
||||
var attrs = target.attributes
|
||||
var regNoScale = /skip-autoscale/;
|
||||
for (var i = attrs.length - 1; i >= 0; i--) {
|
||||
if (regNoScale.test(attrs[i].name)) {
|
||||
console.log('autoscale disabled by attr');
|
||||
return false;
|
||||
}
|
||||
if (regNoScale.test(attrs[i].value)) {
|
||||
console.log('autoscale disabled by attr value');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
var constrainSrc = function(url,objectWidth,objectHeight,objectType,upScale = false){
|
||||
if (url===null){
|
||||
return url;
|
||||
}
|
||||
console.log('constrain ' + url + ' to ' + objectWidth + 'x' + objectHeight + ' with type ' + objectType);
|
||||
var regW = /w=(\d+)/;
|
||||
var regFit = /fit=(\d+),(\d+)/;
|
||||
var regResize = /resize=(\d+),(\d+)/;
|
||||
var regSVG = /\.svg(\?.+)?$/;
|
||||
var decUrl = decodeURIComponent(url);
|
||||
if (regSVG.exec(decUrl)){
|
||||
return url;
|
||||
}
|
||||
console.log('domain to test: ' + eio_lazy_vars.exactdn_domain);
|
||||
if (url.search('\\?') > 0 && url.search(eio_lazy_vars.exactdn_domain) > 0){
|
||||
console.log('domain matches URL with a ?');
|
||||
var resultResize = regResize.exec(decUrl);
|
||||
if(resultResize && (objectWidth < resultResize[1] || upScale)){
|
||||
if('img-w'===objectType){
|
||||
console.log('resize param found, replacing in ' + objectType);
|
||||
return decUrl.replace(regResize, 'w=' + objectWidth );
|
||||
}
|
||||
if('img-h'===objectType){
|
||||
console.log('resize param found, replacing in ' + objectType);
|
||||
return decUrl.replace(regResize, 'h=' + objectHeight );
|
||||
}
|
||||
console.log('resize param found, replacing');
|
||||
return decUrl.replace(regResize, 'resize=' + objectWidth + ',' + objectHeight);
|
||||
}
|
||||
var resultW = regW.exec(url);
|
||||
if(resultW && (objectWidth <= resultW[1] || upScale)){
|
||||
if('img-h'===objectType){
|
||||
console.log('w param found, replacing in ' + objectType);
|
||||
return decUrl.replace(regW, 'h=' + objectHeight );
|
||||
}
|
||||
if('bg-cover'===objectType || 'img-crop'===objectType){
|
||||
var diff = Math.abs(resultW[1] - objectWidth);
|
||||
if ( diff > 20 || objectHeight < 1080 ) {
|
||||
console.log('w param found, replacing in ' + objectType);
|
||||
return url.replace(regW, 'resize=' + objectWidth + ',' + objectHeight );
|
||||
}
|
||||
console.log('w param found, but only ' + diff + ' pixels off, ignoring');
|
||||
return url;
|
||||
}
|
||||
console.log('w param found, replacing');
|
||||
return url.replace(regW, 'w=' + objectWidth);
|
||||
}
|
||||
var resultFit = regFit.exec(decUrl);
|
||||
if(resultFit && (objectWidth < resultFit[1] || upScale)){
|
||||
if('bg-cover'===objectType || 'img-crop'===objectType){
|
||||
var wDiff = Math.abs(resultFit[1] - objectWidth);
|
||||
var hDiff = Math.abs(resultFit[2] - objectHeight);
|
||||
if ( wDiff > 20 || hDiff > 20 ) {
|
||||
console.log('fit param found, replacing in ' + objectType);
|
||||
return url.replace(regW, 'resize=' + objectWidth + ',' + objectHeight );
|
||||
}
|
||||
console.log('fit param found, but only w' + wDiff + '/h' + hDiff + ' pixels off, ignoring');
|
||||
return url;
|
||||
}
|
||||
if('img-w'===objectType){
|
||||
console.log('fit param found, replacing in ' + objectType);
|
||||
return decUrl.replace(regFit, 'w=' + objectWidth );
|
||||
}
|
||||
if('img-h'===objectType){
|
||||
console.log('fit param found, replacing in ' + objectType);
|
||||
return decUrl.replace(regFit, 'h=' + objectHeight );
|
||||
}
|
||||
console.log('fit param found, replacing');
|
||||
return decUrl.replace(regFit, 'fit=' + objectWidth + ',' + objectHeight);
|
||||
}
|
||||
if(!resultW && !resultFit && !resultResize){
|
||||
console.log('no param found, appending');
|
||||
if('img'===objectType){
|
||||
console.log('for ' + objectType);
|
||||
return url + '&fit=' + objectWidth + ',' + objectHeight;
|
||||
}
|
||||
if('bg-cover'===objectType || 'img-crop'===objectType){
|
||||
console.log('for ' + objectType);
|
||||
return url + '&resize=' + objectWidth + ',' + objectHeight;
|
||||
}
|
||||
if('img-h'===objectType || objectHeight>objectWidth){
|
||||
console.log('img-h or fallback height>width, using h param');
|
||||
return url + '&h=' + objectHeight;
|
||||
}
|
||||
console.log('fallback using w param');
|
||||
return url + '&w=' + objectWidth;
|
||||
}
|
||||
}
|
||||
if (url.search('\\?') == -1 && url.search(eio_lazy_vars.exactdn_domain) > 0){
|
||||
console.log('domain matches URL without a ?, appending query string');
|
||||
if('img'===objectType){
|
||||
console.log('for ' + objectType);
|
||||
return url + '?fit=' + objectWidth + ',' + objectHeight;
|
||||
}
|
||||
if('bg-cover'===objectType || 'img-crop'===objectType){
|
||||
console.log('for ' + objectType);
|
||||
return url + '?resize=' + objectWidth + ',' + objectHeight;
|
||||
}
|
||||
if('img-h'===objectType || objectHeight>objectWidth){
|
||||
console.log('img-h or fallback height>width, using h param');
|
||||
return url + '?h=' + objectHeight;
|
||||
}
|
||||
console.log('fallback using w param');
|
||||
return url + '?w=' + objectWidth;
|
||||
}
|
||||
console.log('boo, just using same url');
|
||||
return url;
|
||||
};
|
||||
|
||||
var getImgType = function(elem){
|
||||
if ( lazySizes.hC(elem,'et_pb_jt_filterable_grid_item_image') || lazySizes.hC(elem,'ss-foreground-image') || lazySizes.hC(elem,'img-crop') ) {
|
||||
console.log('img that needs a hard crop');
|
||||
return 'img-crop';
|
||||
} else if (
|
||||
lazySizes.hC(elem,'object-cover') &&
|
||||
( lazySizes.hC(elem,'object-top') || lazySizes.hC(elem,'object-bottom') )
|
||||
) {
|
||||
console.log('cover img that needs a width scale');
|
||||
return 'img-w';
|
||||
} else if (
|
||||
lazySizes.hC(elem,'object-cover') &&
|
||||
( lazySizes.hC(elem,'object-left') || lazySizes.hC(elem,'object-right') )
|
||||
) {
|
||||
console.log('cover img that needs a height scale');
|
||||
return 'img-h';
|
||||
} else if ( lazySizes.hC(elem,'ct-image') && lazySizes.hC(elem,'object-cover') ) {
|
||||
console.log('Oxygen cover img that needs a hard crop');
|
||||
return 'img-crop';
|
||||
} else if ( ! elem.getAttribute('data-srcset') && ! elem.srcset && elem.offsetHeight > elem.offsetWidth && getAspectRatio(elem) > 1 ) {
|
||||
console.log('non-srcset img with portrait display, landscape in real life');
|
||||
return 'img-crop';
|
||||
}
|
||||
console.log('plain old img, constraining');
|
||||
return 'img';
|
||||
};
|
||||
|
||||
var getDimensionsFromURL = function(url){
|
||||
var regDims = /-(\d+)x(\d+)\./;
|
||||
var resultDims = regDims.exec(url);
|
||||
if (resultDims && resultDims[1] > 1 && resultDims[2] > 1) {
|
||||
return {w:resultDims[1],h:resultDims[2]};
|
||||
}
|
||||
return {w:0,h:0};
|
||||
};
|
||||
|
||||
var getRealDimensionsFromImg = function(img){
|
||||
var realWidth = img.getAttribute('data-eio-rwidth');
|
||||
var realHeight = img.getAttribute('data-eio-rheight');
|
||||
if (realWidth > 1 && realHeight > 1) {
|
||||
return {w:realWidth,h:realHeight};
|
||||
}
|
||||
return {w:0,h:0};
|
||||
};
|
||||
|
||||
var getSrcsetDims = function(img) {
|
||||
var srcSet;
|
||||
if (img.srcset){
|
||||
srcSet = img.srcset.split(',');
|
||||
} else {
|
||||
var srcSetAttr = img.getAttribute('data-srcset');
|
||||
if (srcSetAttr){
|
||||
srcSet = srcSetAttr.split(',');
|
||||
}
|
||||
}
|
||||
if (srcSet){
|
||||
var i = 0;
|
||||
var len = srcSet.length;
|
||||
if (len){
|
||||
for (; i < len; i++){
|
||||
var src = srcSet[i].trim().split(' ');
|
||||
if (src[0].length) {
|
||||
var nextDims = getDimensionsFromURL(src[0]);
|
||||
if (nextDims.w && nextDims.h){
|
||||
var srcSetDims = nextDims;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (srcSetDims.w && srcSetDims.h){
|
||||
return srcSetDims;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {w:0,h:0};
|
||||
}
|
||||
|
||||
var getAspectRatio = function(img){
|
||||
var width = img.getAttribute('width');
|
||||
var height = img.getAttribute('height');
|
||||
if (width > 1 && height > 1){
|
||||
console.log('found dims ' + width + 'x' + height + ', returning ' + width/height);
|
||||
return width / height;
|
||||
}
|
||||
var src = false;
|
||||
if (img.src && img.src.search('http') > -1) {
|
||||
src = img.src;
|
||||
}
|
||||
if (!src) {
|
||||
src = img.getAttribute('data-src');
|
||||
}
|
||||
if (src){
|
||||
var urlDims = getDimensionsFromURL(src);
|
||||
if (urlDims.w && urlDims.h) {
|
||||
console.log('found dims from URL: ' + urlDims.w + 'x' + urlDims.h);
|
||||
return urlDims.w / urlDims.h;
|
||||
}
|
||||
}
|
||||
var realDims = getRealDimensionsFromImg(img);
|
||||
if (realDims.w && realDims.h){
|
||||
console.log('found dims from eio-attrs: ' + realDims.w + 'x' + realDims.h);
|
||||
return realDims.w / realDims.h;
|
||||
}
|
||||
var srcSetDims = getSrcsetDims(img);
|
||||
if (srcSetDims.w && srcSetDims.h){
|
||||
console.log('largest found dims from srcset: ' + srcSetDims.w + 'x' + srcSetDims.h);
|
||||
return srcSetDims.w / srcSetDims.h;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
var updateImgElem = function(target,upScale=false){
|
||||
var dPR = (window.devicePixelRatio || 1);
|
||||
var targetWidth = Math.round(target.offsetWidth * dPR);
|
||||
var targetHeight = Math.round(target.offsetHeight * dPR);
|
||||
|
||||
var src = target.getAttribute('data-src');
|
||||
var webpsrc = target.getAttribute('data-src-webp');
|
||||
if(ewww_webp_supported && webpsrc && -1 == src.search('webp=1') && !upScale){
|
||||
console.log('using data-src-webp');
|
||||
src = webpsrc;
|
||||
}
|
||||
if (!shouldAutoScale(target)||!shouldAutoScale(target.parentNode)){
|
||||
return;
|
||||
}
|
||||
var imgType = getImgType(target);
|
||||
var newSrc = constrainSrc(src,targetWidth,targetHeight,imgType,upScale);
|
||||
if (newSrc && src != newSrc){
|
||||
console.log('new src: ' + newSrc);
|
||||
if (upScale){
|
||||
target.setAttribute('src', newSrc);
|
||||
}
|
||||
target.setAttribute('data-src', newSrc);
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener('lazybeforesizes', function(e){
|
||||
var src = e.target.getAttribute('data-src');
|
||||
console.log('auto-sizing ' + src + ' to: ' + e.detail.width);
|
||||
var imgAspect = getAspectRatio(e.target);
|
||||
if (e.target.clientHeight > 1 && imgAspect) {
|
||||
var minimum_width = Math.ceil(imgAspect * e.target.clientHeight);
|
||||
console.log('minimum_width = ' + minimum_width);
|
||||
if (e.detail.width+2 < minimum_width) {
|
||||
e.detail.width = minimum_width;
|
||||
}
|
||||
}
|
||||
if (e.target._lazysizesWidth === undefined) {
|
||||
return;
|
||||
}
|
||||
console.log('previous width was ' + e.target._lazysizesWidth);
|
||||
if (e.detail.width < e.target._lazysizesWidth) {
|
||||
console.log('no way! ' + e.detail.width + ' is smaller than ' + e.target._lazysizesWidth);
|
||||
e.detail.width = e.target._lazysizesWidth;
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('lazybeforeunveil', function(e){
|
||||
var target = e.target;
|
||||
console.log('loading an image');
|
||||
console.log(target);
|
||||
var srcset = target.getAttribute('data-srcset');
|
||||
if (target.naturalWidth && ! srcset) {
|
||||
console.log('natural width of ' + target.getAttribute('src') + ' is ' + target.naturalWidth);
|
||||
console.log('we have an image with no srcset');
|
||||
if ((target.naturalWidth > 1) && (target.naturalHeight > 1)) {
|
||||
// For each image with a natural width which isn't
|
||||
// a 1x1 image, check its size.
|
||||
var dPR = (window.devicePixelRatio || 1);
|
||||
var physicalWidth = target.naturalWidth;
|
||||
var physicalHeight = target.naturalHeight;
|
||||
var realDims = getRealDimensionsFromImg(target);
|
||||
if (realDims.w && realDims.w > physicalWidth) {
|
||||
console.log( 'using ' + realDims.w + 'w instead of ' + physicalWidth + 'w and ' + realDims.h + 'h instead of ' + physicalHeight + 'h from data-eio-r*')
|
||||
physicalWidth = realDims.w;
|
||||
physicalHeight = realDims.h;
|
||||
}
|
||||
var wrongWidth = (target.clientWidth && (target.clientWidth * 1.25 * dPR < physicalWidth));
|
||||
var wrongHeight = (target.clientHeight && (target.clientHeight * 1.25 * dPR < physicalHeight));
|
||||
console.log('displayed at ' + Math.round(target.clientWidth * dPR) + 'w x ' + Math.round(target.clientHeight * dPR) + 'h, natural/physical is ' +
|
||||
physicalWidth + 'w x ' + physicalHeight + 'h!');
|
||||
console.log('the data-src: ' + target.getAttribute('data-src') );
|
||||
if (wrongWidth || wrongHeight) {
|
||||
updateImgElem(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(ewww_webp_supported) {
|
||||
console.log('webp supported');
|
||||
//console.log(srcset);
|
||||
if (srcset) {
|
||||
console.log('srcset available');
|
||||
var webpsrcset = target.getAttribute('data-srcset-webp');
|
||||
if(webpsrcset){
|
||||
console.log('replacing data-srcset with data-srcset-webp');
|
||||
target.setAttribute('data-srcset', webpsrcset);
|
||||
}
|
||||
}
|
||||
var webpsrc = target.getAttribute('data-src-webp');
|
||||
if(!webpsrc){
|
||||
console.log('no data-src-webp attr');
|
||||
return;
|
||||
}
|
||||
console.log('replacing data-src with data-src-webp');
|
||||
target.setAttribute('data-src', webpsrc);
|
||||
}
|
||||
});
|
||||
|
||||
// Based on http://modernjavascript.blogspot.de/2013/08/building-better-debounce.html
|
||||
var debounce = function(func) {
|
||||
var timeout, timestamp;
|
||||
var wait = 99;
|
||||
var run = function(){
|
||||
timeout = null;
|
||||
func();
|
||||
};
|
||||
var later = function() {
|
||||
var last = Date.now() - timestamp;
|
||||
|
||||
if (last < wait) {
|
||||
setTimeout(later, wait - last);
|
||||
} else {
|
||||
(window.requestIdleCallback || run)(run);
|
||||
}
|
||||
};
|
||||
|
||||
return function() {
|
||||
timestamp = Date.now();
|
||||
|
||||
if (!timeout) {
|
||||
timeout = setTimeout(later, wait);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var recheckLazyElements = function(event = false) {
|
||||
console.log('rechecking elements:');
|
||||
if (event.type) {
|
||||
console.log(event.type);
|
||||
if ('load'===event.type) {
|
||||
lazySizes.autoSizer.checkElems();
|
||||
}
|
||||
}
|
||||
var dPR = (window.devicePixelRatio || 1);
|
||||
var autosizedElems = document.getElementsByClassName(lazySizes.cfg.loadedClass);
|
||||
var i;
|
||||
var len = autosizedElems.length;
|
||||
if(len){
|
||||
i = 0;
|
||||
|
||||
for(; i < len; i++){
|
||||
var autosizedElem = autosizedElems[i];
|
||||
if (autosizedElem.src && ! autosizedElem.srcset && autosizedElem.naturalWidth > 1 && autosizedElem.naturalHeight > 1 && autosizedElem.clientWidth > 1 && autosizedElem.clientHeight > 1){
|
||||
console.log(autosizedElem);
|
||||
console.log('natural width of ' + autosizedElem.src + ' is ' + autosizedElem.naturalWidth);
|
||||
// For each image with a natural width which isn't
|
||||
// a 1x1 image, check its size.
|
||||
var physicalWidth = autosizedElem.naturalWidth;
|
||||
var physicalHeight = autosizedElem.naturalHeight;
|
||||
var maxWidth = window.innerWidth;
|
||||
var maxHeight = window.innerHeight;
|
||||
var realDims = getRealDimensionsFromImg(autosizedElem);
|
||||
var urlDims = getDimensionsFromURL(autosizedElem.src);
|
||||
|
||||
if (realDims.w) {
|
||||
maxWidth = realDims.w;
|
||||
} else if (urlDims.w) {
|
||||
maxWidth = urlDims.w;
|
||||
}
|
||||
if (realDims.h) {
|
||||
maxHeight = realDims.h;
|
||||
} else if (urlDims.h) {
|
||||
maxHeight = urlDims.h;
|
||||
}
|
||||
console.log( 'max image size is ' + maxWidth + 'w, ' + maxHeight + 'h');
|
||||
|
||||
// For upscaling, the goal is to get to 1x dPR, we won't waste bandwidth on retina/2x images.
|
||||
var desiredWidth = autosizedElem.clientWidth;
|
||||
var desiredHeight = autosizedElem.clientHeight;
|
||||
var wrongWidth = (desiredWidth > physicalWidth * 1.1 && maxWidth >= desiredWidth);
|
||||
var wrongHeight = (desiredHeight > physicalHeight * 1.1 && maxHeight >= desiredHeight);
|
||||
console.log('displayed at ' + Math.round(desiredWidth) + 'w x ' + Math.round(desiredHeight) + 'h, natural/physical is ' +
|
||||
physicalWidth + 'w x ' + physicalHeight + 'h');
|
||||
if (wrongWidth || wrongHeight) {
|
||||
console.log('requesting upsize');
|
||||
updateImgElem(autosizedElem,true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var debouncedRecheckElements = debounce(recheckLazyElements);
|
||||
|
||||
addEventListener('load', recheckLazyElements);
|
||||
addEventListener('resize', debouncedRecheckElements);
|
||||
setTimeout(recheckLazyElements, 20000);
|
||||
}));
|
@ -0,0 +1,17 @@
|
||||
if (typeof ewww_webp_supported === 'undefined') {
|
||||
var ewww_webp_supported = false;
|
||||
}
|
||||
window.lazySizesConfig = window.lazySizesConfig || {};
|
||||
window.lazySizesConfig.expand = document.documentElement.clientHeight > 500 && document.documentElement.clientWidth > 500 ? 1000 : 740;
|
||||
if (typeof eio_lazy_vars === 'undefined'){
|
||||
console.log('setting failsafe lazy vars');
|
||||
eio_lazy_vars = {
|
||||
exactdn_domain: '.exactdn.com',
|
||||
threshold: 0,
|
||||
skip_autoscale: 0,
|
||||
};
|
||||
}
|
||||
if (eio_lazy_vars.threshold > 50) {
|
||||
window.lazySizesConfig.expand = eio_lazy_vars.threshold;
|
||||
}
|
||||
console.log( 'root margin: ' + window.lazySizesConfig.expand );
|
760
wp-content/plugins/ewww-image-optimizer/includes/lazysizes.js
Normal file
760
wp-content/plugins/ewww-image-optimizer/includes/lazysizes.js
Normal file
@ -0,0 +1,760 @@
|
||||
// version 5.3.0
|
||||
(function(window, factory) {
|
||||
var lazySizes = factory(window, window.document, Date);
|
||||
window.lazySizes = lazySizes;
|
||||
if(typeof module == 'object' && module.exports){
|
||||
module.exports = lazySizes;
|
||||
}
|
||||
}(typeof window != 'undefined' ?
|
||||
window : {}, function l(window, document, Date) { // Pass in the windoe Date function also for SSR because the Date class can be lost
|
||||
'use strict';
|
||||
/*jshint eqnull:true */
|
||||
|
||||
var lazysizes, lazySizesCfg;
|
||||
|
||||
(function(){
|
||||
var prop;
|
||||
|
||||
var lazySizesDefaults = {
|
||||
lazyClass: 'lazyload',
|
||||
loadedClass: 'lazyloaded',
|
||||
loadingClass: 'lazyloading',
|
||||
preloadClass: 'lazypreload',
|
||||
errorClass: 'lazyerror',
|
||||
//strictClass: 'lazystrict',
|
||||
autosizesClass: 'lazyautosizes',
|
||||
fastLoadedClass: 'ls-is-cached',
|
||||
iframeLoadMode: 0,
|
||||
srcAttr: 'data-src',
|
||||
srcsetAttr: 'data-srcset',
|
||||
sizesAttr: 'data-sizes',
|
||||
//preloadAfterLoad: false,
|
||||
minSize: 40,
|
||||
customMedia: {},
|
||||
init: true,
|
||||
expFactor: 1.5,
|
||||
hFac: 0.8,
|
||||
loadMode: 2,
|
||||
loadHidden: true,
|
||||
ricTimeout: 0,
|
||||
throttleDelay: 125,
|
||||
};
|
||||
|
||||
lazySizesCfg = window.lazySizesConfig || window.lazysizesConfig || {};
|
||||
|
||||
for(prop in lazySizesDefaults){
|
||||
if(!(prop in lazySizesCfg)){
|
||||
lazySizesCfg[prop] = lazySizesDefaults[prop];
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
if (!document || !document.getElementsByClassName) {
|
||||
return {
|
||||
init: function () {},
|
||||
cfg: lazySizesCfg,
|
||||
noSupport: true,
|
||||
};
|
||||
}
|
||||
|
||||
var docElem = document.documentElement;
|
||||
|
||||
var supportPicture = window.HTMLPictureElement;
|
||||
|
||||
var _addEventListener = 'addEventListener';
|
||||
|
||||
var _getAttribute = 'getAttribute';
|
||||
|
||||
/**
|
||||
* Update to bind to window because 'this' becomes null during SSR
|
||||
* builds.
|
||||
*/
|
||||
var addEventListener = window[_addEventListener].bind(window);
|
||||
|
||||
var setTimeout = window.setTimeout;
|
||||
|
||||
var requestAnimationFrame = window.requestAnimationFrame || setTimeout;
|
||||
|
||||
var requestIdleCallback = window.requestIdleCallback;
|
||||
|
||||
var regPicture = /^picture$/i;
|
||||
|
||||
var loadEvents = ['load', 'error', 'lazyincluded', '_lazyloaded'];
|
||||
|
||||
var regClassCache = {};
|
||||
|
||||
var forEach = Array.prototype.forEach;
|
||||
|
||||
var hasClass = function(ele, cls) {
|
||||
if(!regClassCache[cls]){
|
||||
regClassCache[cls] = new RegExp('(\\s|^)'+cls+'(\\s|$)');
|
||||
}
|
||||
return regClassCache[cls].test(ele[_getAttribute]('class') || '') && regClassCache[cls];
|
||||
};
|
||||
|
||||
var addClass = function(ele, cls) {
|
||||
if (!hasClass(ele, cls)){
|
||||
ele.setAttribute('class', (ele[_getAttribute]('class') || '').trim() + ' ' + cls);
|
||||
}
|
||||
};
|
||||
|
||||
var removeClass = function(ele, cls) {
|
||||
var reg;
|
||||
if ((reg = hasClass(ele,cls))) {
|
||||
ele.setAttribute('class', (ele[_getAttribute]('class') || '').replace(reg, ' '));
|
||||
}
|
||||
};
|
||||
|
||||
var addRemoveLoadEvents = function(dom, fn, add){
|
||||
var action = add ? _addEventListener : 'removeEventListener';
|
||||
if(add){
|
||||
addRemoveLoadEvents(dom, fn);
|
||||
}
|
||||
loadEvents.forEach(function(evt){
|
||||
dom[action](evt, fn);
|
||||
});
|
||||
};
|
||||
|
||||
var triggerEvent = function(elem, name, detail, noBubbles, noCancelable){
|
||||
var event = document.createEvent('Event');
|
||||
|
||||
if(!detail){
|
||||
detail = {};
|
||||
}
|
||||
|
||||
detail.instance = lazysizes;
|
||||
|
||||
event.initEvent(name, !noBubbles, !noCancelable);
|
||||
|
||||
event.detail = detail;
|
||||
|
||||
elem.dispatchEvent(event);
|
||||
return event;
|
||||
};
|
||||
|
||||
var updatePolyfill = function (el, full){
|
||||
var polyfill;
|
||||
if( !supportPicture && ( polyfill = (window.picturefill || lazySizesCfg.pf) ) ){
|
||||
if(full && full.src && !el[_getAttribute]('srcset')){
|
||||
el.setAttribute('srcset', full.src);
|
||||
}
|
||||
polyfill({reevaluate: true, elements: [el]});
|
||||
} else if(full && full.src){
|
||||
el.src = full.src;
|
||||
}
|
||||
};
|
||||
|
||||
var getCSS = function (elem, style){
|
||||
return (getComputedStyle(elem, null) || {})[style];
|
||||
};
|
||||
|
||||
var getWidth = function(elem, parent, width){
|
||||
width = width || elem.offsetWidth;
|
||||
|
||||
while(width < lazySizesCfg.minSize && parent && !elem._lazysizesWidth){
|
||||
width = parent.offsetWidth;
|
||||
parent = parent.parentNode;
|
||||
}
|
||||
|
||||
return width;
|
||||
};
|
||||
|
||||
var rAF = (function(){
|
||||
var running, waiting;
|
||||
var firstFns = [];
|
||||
var secondFns = [];
|
||||
var fns = firstFns;
|
||||
|
||||
var run = function(){
|
||||
var runFns = fns;
|
||||
|
||||
fns = firstFns.length ? secondFns : firstFns;
|
||||
|
||||
running = true;
|
||||
waiting = false;
|
||||
|
||||
while(runFns.length){
|
||||
runFns.shift()();
|
||||
}
|
||||
|
||||
running = false;
|
||||
};
|
||||
|
||||
var rafBatch = function(fn, queue){
|
||||
if(running && !queue){
|
||||
fn.apply(this, arguments);
|
||||
} else {
|
||||
fns.push(fn);
|
||||
|
||||
if(!waiting){
|
||||
waiting = true;
|
||||
(document.hidden ? setTimeout : requestAnimationFrame)(run);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
rafBatch._lsFlush = run;
|
||||
|
||||
return rafBatch;
|
||||
})();
|
||||
|
||||
var rAFIt = function(fn, simple){
|
||||
return simple ?
|
||||
function() {
|
||||
rAF(fn);
|
||||
} :
|
||||
function(){
|
||||
var that = this;
|
||||
var args = arguments;
|
||||
rAF(function(){
|
||||
fn.apply(that, args);
|
||||
});
|
||||
}
|
||||
;
|
||||
};
|
||||
|
||||
var throttle = function(fn){
|
||||
var running;
|
||||
var lastTime = 0;
|
||||
var gDelay = lazySizesCfg.throttleDelay;
|
||||
var rICTimeout = lazySizesCfg.ricTimeout;
|
||||
var run = function(){
|
||||
running = false;
|
||||
lastTime = Date.now();
|
||||
fn();
|
||||
};
|
||||
var idleCallback = requestIdleCallback && rICTimeout > 49 ?
|
||||
function(){
|
||||
requestIdleCallback(run, {timeout: rICTimeout});
|
||||
|
||||
if(rICTimeout !== lazySizesCfg.ricTimeout){
|
||||
rICTimeout = lazySizesCfg.ricTimeout;
|
||||
}
|
||||
} :
|
||||
rAFIt(function(){
|
||||
setTimeout(run);
|
||||
}, true)
|
||||
;
|
||||
|
||||
return function(isPriority){
|
||||
var delay;
|
||||
|
||||
if((isPriority = isPriority === true)){
|
||||
rICTimeout = 33;
|
||||
}
|
||||
|
||||
if(running){
|
||||
return;
|
||||
}
|
||||
|
||||
running = true;
|
||||
|
||||
delay = gDelay - (Date.now() - lastTime);
|
||||
|
||||
if(delay < 0){
|
||||
delay = 0;
|
||||
}
|
||||
|
||||
if(isPriority || delay < 9){
|
||||
idleCallback();
|
||||
} else {
|
||||
setTimeout(idleCallback, delay);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
//based on http://modernjavascript.blogspot.de/2013/08/building-better-debounce.html
|
||||
var debounce = function(func) {
|
||||
var timeout, timestamp;
|
||||
var wait = 99;
|
||||
var run = function(){
|
||||
timeout = null;
|
||||
func();
|
||||
};
|
||||
var later = function() {
|
||||
var last = Date.now() - timestamp;
|
||||
|
||||
if (last < wait) {
|
||||
setTimeout(later, wait - last);
|
||||
} else {
|
||||
(requestIdleCallback || run)(run);
|
||||
}
|
||||
};
|
||||
|
||||
return function() {
|
||||
timestamp = Date.now();
|
||||
|
||||
if (!timeout) {
|
||||
timeout = setTimeout(later, wait);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var loader = (function(){
|
||||
var preloadElems, isCompleted, resetPreloadingTimer, loadMode, started;
|
||||
|
||||
var eLvW, elvH, eLtop, eLleft, eLright, eLbottom, isBodyHidden;
|
||||
|
||||
var regImg = /^img$/i;
|
||||
var regIframe = /^iframe$/i;
|
||||
|
||||
var supportScroll = ('onscroll' in window) && !(/(gle|ing)bot/.test(navigator.userAgent));
|
||||
|
||||
var shrinkExpand = 0;
|
||||
var currentExpand = 0;
|
||||
|
||||
var isLoading = 0;
|
||||
var lowRuns = -1;
|
||||
|
||||
var resetPreloading = function(e){
|
||||
isLoading--;
|
||||
if(!e || isLoading < 0 || !e.target){
|
||||
isLoading = 0;
|
||||
}
|
||||
};
|
||||
|
||||
var isVisible = function (elem) {
|
||||
if (isBodyHidden == null) {
|
||||
isBodyHidden = getCSS(document.body, 'visibility') == 'hidden';
|
||||
}
|
||||
|
||||
return isBodyHidden || !(getCSS(elem.parentNode, 'visibility') == 'hidden' && getCSS(elem, 'visibility') == 'hidden');
|
||||
};
|
||||
|
||||
var isNestedVisible = function(elem, elemExpand){
|
||||
var outerRect;
|
||||
var parent = elem;
|
||||
var visible = isVisible(elem);
|
||||
|
||||
eLtop -= elemExpand;
|
||||
eLbottom += elemExpand;
|
||||
eLleft -= elemExpand;
|
||||
eLright += elemExpand;
|
||||
|
||||
while(visible && (parent = parent.offsetParent) && parent != document.body && parent != docElem){
|
||||
visible = ((getCSS(parent, 'opacity') || 1) > 0);
|
||||
|
||||
if(visible && getCSS(parent, 'overflow') != 'visible'){
|
||||
outerRect = parent.getBoundingClientRect();
|
||||
visible = eLright > outerRect.left &&
|
||||
eLleft < outerRect.right &&
|
||||
eLbottom > outerRect.top - 1 &&
|
||||
eLtop < outerRect.bottom + 1
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
return visible;
|
||||
};
|
||||
|
||||
var checkElements = function() {
|
||||
var eLlen, i, rect, autoLoadElem, loadedSomething, elemExpand, elemNegativeExpand, elemExpandVal,
|
||||
beforeExpandVal, defaultExpand, preloadExpand, hFac;
|
||||
var lazyloadElems = lazysizes.elements;
|
||||
|
||||
if((loadMode = lazySizesCfg.loadMode) && isLoading < 8 && (eLlen = lazyloadElems.length)){
|
||||
|
||||
i = 0;
|
||||
|
||||
lowRuns++;
|
||||
|
||||
for(; i < eLlen; i++){
|
||||
|
||||
if(!lazyloadElems[i] || lazyloadElems[i]._lazyRace){continue;}
|
||||
|
||||
if(!supportScroll || (lazysizes.prematureUnveil && lazysizes.prematureUnveil(lazyloadElems[i]))){unveilElement(lazyloadElems[i]);continue;}
|
||||
|
||||
if(!(elemExpandVal = lazyloadElems[i][_getAttribute]('data-expand')) || !(elemExpand = elemExpandVal * 1)){
|
||||
elemExpand = currentExpand;
|
||||
}
|
||||
|
||||
if (!defaultExpand) {
|
||||
defaultExpand = (!lazySizesCfg.expand || lazySizesCfg.expand < 1) ?
|
||||
docElem.clientHeight > 500 && docElem.clientWidth > 500 ? 500 : 370 :
|
||||
lazySizesCfg.expand;
|
||||
|
||||
lazysizes._defEx = defaultExpand;
|
||||
|
||||
preloadExpand = defaultExpand * lazySizesCfg.expFactor;
|
||||
hFac = lazySizesCfg.hFac;
|
||||
isBodyHidden = null;
|
||||
|
||||
if(currentExpand < preloadExpand && isLoading < 1 && lowRuns > 2 && loadMode > 2 && !document.hidden){
|
||||
currentExpand = preloadExpand;
|
||||
lowRuns = 0;
|
||||
} else if(loadMode > 1 && lowRuns > 1 && isLoading < 6){
|
||||
currentExpand = defaultExpand;
|
||||
} else {
|
||||
currentExpand = shrinkExpand;
|
||||
}
|
||||
}
|
||||
|
||||
if(beforeExpandVal !== elemExpand){
|
||||
eLvW = innerWidth + (elemExpand * hFac);
|
||||
elvH = innerHeight + elemExpand;
|
||||
elemNegativeExpand = elemExpand * -1;
|
||||
beforeExpandVal = elemExpand;
|
||||
}
|
||||
|
||||
rect = lazyloadElems[i].getBoundingClientRect();
|
||||
|
||||
if ((eLbottom = rect.bottom) >= elemNegativeExpand &&
|
||||
(eLtop = rect.top) <= elvH &&
|
||||
(eLright = rect.right) >= elemNegativeExpand * hFac &&
|
||||
(eLleft = rect.left) <= eLvW &&
|
||||
(eLbottom || eLright || eLleft || eLtop) &&
|
||||
(lazySizesCfg.loadHidden || isVisible(lazyloadElems[i])) &&
|
||||
((isCompleted && isLoading < 3 && !elemExpandVal && (loadMode < 3 || lowRuns < 4)) || isNestedVisible(lazyloadElems[i], elemExpand))){
|
||||
unveilElement(lazyloadElems[i]);
|
||||
loadedSomething = true;
|
||||
if(isLoading > 9){break;}
|
||||
} else if(!loadedSomething && isCompleted && !autoLoadElem &&
|
||||
isLoading < 4 && lowRuns < 4 && loadMode > 2 &&
|
||||
(preloadElems[0] || lazySizesCfg.preloadAfterLoad) &&
|
||||
(preloadElems[0] || (!elemExpandVal && ((eLbottom || eLright || eLleft || eLtop) || lazyloadElems[i][_getAttribute](lazySizesCfg.sizesAttr) != 'auto')))){
|
||||
autoLoadElem = preloadElems[0] || lazyloadElems[i];
|
||||
}
|
||||
}
|
||||
|
||||
if(autoLoadElem && !loadedSomething){
|
||||
unveilElement(autoLoadElem);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var throttledCheckElements = throttle(checkElements);
|
||||
|
||||
var switchLoadingClass = function(e){
|
||||
var elem = e.target;
|
||||
|
||||
if (elem._lazyCache) {
|
||||
delete elem._lazyCache;
|
||||
return;
|
||||
}
|
||||
|
||||
resetPreloading(e);
|
||||
addClass(elem, lazySizesCfg.loadedClass);
|
||||
removeClass(elem, lazySizesCfg.loadingClass);
|
||||
addRemoveLoadEvents(elem, rafSwitchLoadingClass);
|
||||
triggerEvent(elem, 'lazyloaded');
|
||||
};
|
||||
var rafedSwitchLoadingClass = rAFIt(switchLoadingClass);
|
||||
var rafSwitchLoadingClass = function(e){
|
||||
rafedSwitchLoadingClass({target: e.target});
|
||||
};
|
||||
|
||||
var changeIframeSrc = function(elem, src){
|
||||
var loadMode = elem.getAttribute('data-load-mode') || lazySizesCfg.iframeLoadMode;
|
||||
|
||||
// loadMode can be also a string!
|
||||
if (loadMode == 0) {
|
||||
elem.contentWindow.location.replace(src);
|
||||
} else if (loadMode == 1) {
|
||||
elem.src = src;
|
||||
}
|
||||
};
|
||||
|
||||
var handleSources = function(source){
|
||||
var customMedia;
|
||||
|
||||
var sourceSrcset = source[_getAttribute](lazySizesCfg.srcsetAttr);
|
||||
|
||||
if( (customMedia = lazySizesCfg.customMedia[source[_getAttribute]('data-media') || source[_getAttribute]('media')]) ){
|
||||
source.setAttribute('media', customMedia);
|
||||
}
|
||||
|
||||
if(sourceSrcset){
|
||||
source.setAttribute('srcset', sourceSrcset);
|
||||
}
|
||||
};
|
||||
|
||||
var lazyUnveil = rAFIt(function (elem, detail, isAuto, sizes, isImg){
|
||||
var src, srcset, parent, isPicture, event, firesLoad;
|
||||
|
||||
if(!(event = triggerEvent(elem, 'lazybeforeunveil', detail)).defaultPrevented){
|
||||
|
||||
if(sizes){
|
||||
if(isAuto){
|
||||
addClass(elem, lazySizesCfg.autosizesClass);
|
||||
} else {
|
||||
elem.setAttribute('sizes', sizes);
|
||||
}
|
||||
}
|
||||
|
||||
srcset = elem[_getAttribute](lazySizesCfg.srcsetAttr);
|
||||
src = elem[_getAttribute](lazySizesCfg.srcAttr);
|
||||
|
||||
if(isImg) {
|
||||
parent = elem.parentNode;
|
||||
isPicture = parent && regPicture.test(parent.nodeName || '');
|
||||
}
|
||||
|
||||
firesLoad = detail.firesLoad || (('src' in elem) && (srcset || src || isPicture));
|
||||
|
||||
event = {target: elem};
|
||||
|
||||
addClass(elem, lazySizesCfg.loadingClass);
|
||||
|
||||
if(firesLoad){
|
||||
clearTimeout(resetPreloadingTimer);
|
||||
resetPreloadingTimer = setTimeout(resetPreloading, 2500);
|
||||
addRemoveLoadEvents(elem, rafSwitchLoadingClass, true);
|
||||
}
|
||||
|
||||
if(isPicture){
|
||||
forEach.call(parent.getElementsByTagName('source'), handleSources);
|
||||
}
|
||||
|
||||
if(srcset){
|
||||
elem.setAttribute('srcset', srcset);
|
||||
} else if(src && !isPicture){
|
||||
if(regIframe.test(elem.nodeName)){
|
||||
changeIframeSrc(elem, src);
|
||||
} else {
|
||||
elem.src = src;
|
||||
}
|
||||
}
|
||||
|
||||
if(isImg && (srcset || isPicture)){
|
||||
updatePolyfill(elem, {src: src});
|
||||
}
|
||||
}
|
||||
|
||||
if(elem._lazyRace){
|
||||
delete elem._lazyRace;
|
||||
}
|
||||
removeClass(elem, lazySizesCfg.lazyClass);
|
||||
|
||||
rAF(function(){
|
||||
// Part of this can be removed as soon as this fix is older: https://bugs.chromium.org/p/chromium/issues/detail?id=7731 (2015)
|
||||
var isLoaded = elem.complete && elem.naturalWidth > 1;
|
||||
|
||||
if( !firesLoad || isLoaded){
|
||||
if (isLoaded) {
|
||||
addClass(elem, lazySizesCfg.fastLoadedClass);
|
||||
}
|
||||
switchLoadingClass(event);
|
||||
elem._lazyCache = true;
|
||||
setTimeout(function(){
|
||||
if ('_lazyCache' in elem) {
|
||||
delete elem._lazyCache;
|
||||
}
|
||||
}, 9);
|
||||
}
|
||||
if (elem.loading == 'lazy') {
|
||||
isLoading--;
|
||||
}
|
||||
}, true);
|
||||
});
|
||||
|
||||
var unveilElement = function (elem){
|
||||
if (elem._lazyRace) {return;}
|
||||
var detail;
|
||||
|
||||
var isImg = regImg.test(elem.nodeName);
|
||||
|
||||
//allow using sizes="auto", but don't use. it's invalid. Use data-sizes="auto" or a valid value for sizes instead (i.e.: sizes="80vw")
|
||||
var sizes = isImg && (elem[_getAttribute](lazySizesCfg.sizesAttr) || elem[_getAttribute]('sizes'));
|
||||
var isAuto = sizes == 'auto';
|
||||
|
||||
if( (isAuto || !isCompleted) && isImg && (elem[_getAttribute]('src') || elem.srcset) && !elem.complete && !hasClass(elem, lazySizesCfg.errorClass) && hasClass(elem, lazySizesCfg.lazyClass)){return;}
|
||||
|
||||
detail = triggerEvent(elem, 'lazyunveilread').detail;
|
||||
|
||||
if(isAuto){
|
||||
autoSizer.updateElem(elem, true, elem.offsetWidth);
|
||||
}
|
||||
|
||||
elem._lazyRace = true;
|
||||
isLoading++;
|
||||
|
||||
lazyUnveil(elem, detail, isAuto, sizes, isImg);
|
||||
};
|
||||
|
||||
var afterScroll = debounce(function(){
|
||||
lazySizesCfg.loadMode = 3;
|
||||
throttledCheckElements();
|
||||
});
|
||||
|
||||
var altLoadmodeScrollListner = function(){
|
||||
if(lazySizesCfg.loadMode == 3){
|
||||
lazySizesCfg.loadMode = 2;
|
||||
}
|
||||
afterScroll();
|
||||
};
|
||||
|
||||
var onload = function(){
|
||||
if(isCompleted){return;}
|
||||
if(Date.now() - started < 999){
|
||||
setTimeout(onload, 999);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
isCompleted = true;
|
||||
|
||||
lazySizesCfg.loadMode = 3;
|
||||
|
||||
throttledCheckElements();
|
||||
|
||||
addEventListener('scroll', altLoadmodeScrollListner, true);
|
||||
};
|
||||
|
||||
return {
|
||||
_: function(){
|
||||
started = Date.now();
|
||||
|
||||
lazysizes.elements = document.getElementsByClassName(lazySizesCfg.lazyClass);
|
||||
preloadElems = document.getElementsByClassName(lazySizesCfg.lazyClass + ' ' + lazySizesCfg.preloadClass);
|
||||
|
||||
addEventListener('scroll', throttledCheckElements, true);
|
||||
|
||||
addEventListener('resize', throttledCheckElements, true);
|
||||
|
||||
addEventListener('pageshow', function (e) {
|
||||
if (e.persisted) {
|
||||
var loadingElements = document.querySelectorAll('.' + lazySizesCfg.loadingClass);
|
||||
|
||||
if (loadingElements.length && loadingElements.forEach) {
|
||||
requestAnimationFrame(function () {
|
||||
loadingElements.forEach( function (img) {
|
||||
if (img.complete) {
|
||||
unveilElement(img);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if(window.MutationObserver){
|
||||
new MutationObserver( throttledCheckElements ).observe( docElem, {childList: true, subtree: true, attributes: true} );
|
||||
} else {
|
||||
docElem[_addEventListener]('DOMNodeInserted', throttledCheckElements, true);
|
||||
docElem[_addEventListener]('DOMAttrModified', throttledCheckElements, true);
|
||||
setInterval(throttledCheckElements, 999);
|
||||
}
|
||||
|
||||
addEventListener('hashchange', throttledCheckElements, true);
|
||||
|
||||
//, 'fullscreenchange'
|
||||
['focus', 'mouseover', 'click', 'load', 'transitionend', 'animationend'].forEach(function(name){
|
||||
document[_addEventListener](name, throttledCheckElements, true);
|
||||
});
|
||||
|
||||
if((/d$|^c/.test(document.readyState))){
|
||||
onload();
|
||||
} else {
|
||||
addEventListener('load', onload);
|
||||
document[_addEventListener]('DOMContentLoaded', throttledCheckElements);
|
||||
setTimeout(onload, 20000);
|
||||
}
|
||||
|
||||
if(lazysizes.elements.length){
|
||||
checkElements();
|
||||
rAF._lsFlush();
|
||||
} else {
|
||||
throttledCheckElements();
|
||||
}
|
||||
},
|
||||
checkElems: throttledCheckElements,
|
||||
unveil: unveilElement,
|
||||
_aLSL: altLoadmodeScrollListner,
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
var autoSizer = (function(){
|
||||
var autosizesElems;
|
||||
|
||||
var sizeElement = rAFIt(function(elem, parent, event, width){
|
||||
var sources, i, len;
|
||||
elem._lazysizesWidth = width;
|
||||
width += 'px';
|
||||
|
||||
elem.setAttribute('sizes', width);
|
||||
|
||||
if(regPicture.test(parent.nodeName || '')){
|
||||
sources = parent.getElementsByTagName('source');
|
||||
for(i = 0, len = sources.length; i < len; i++){
|
||||
sources[i].setAttribute('sizes', width);
|
||||
}
|
||||
}
|
||||
|
||||
if(!event.detail.dataAttr){
|
||||
updatePolyfill(elem, event.detail);
|
||||
}
|
||||
});
|
||||
var getSizeElement = function (elem, dataAttr, width){
|
||||
var event;
|
||||
var parent = elem.parentNode;
|
||||
|
||||
if(parent){
|
||||
width = getWidth(elem, parent, width);
|
||||
event = triggerEvent(elem, 'lazybeforesizes', {width: width, dataAttr: !!dataAttr});
|
||||
|
||||
if(!event.defaultPrevented){
|
||||
width = event.detail.width;
|
||||
|
||||
if(width && width !== elem._lazysizesWidth){
|
||||
sizeElement(elem, parent, event, width);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var updateElementsSizes = function(){
|
||||
var i;
|
||||
var len = autosizesElems.length;
|
||||
if(len){
|
||||
i = 0;
|
||||
|
||||
for(; i < len; i++){
|
||||
getSizeElement(autosizesElems[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var debouncedUpdateElementsSizes = debounce(updateElementsSizes);
|
||||
|
||||
return {
|
||||
_: function(){
|
||||
autosizesElems = document.getElementsByClassName(lazySizesCfg.autosizesClass);
|
||||
addEventListener('resize', debouncedUpdateElementsSizes);
|
||||
},
|
||||
checkElems: debouncedUpdateElementsSizes,
|
||||
updateElem: getSizeElement
|
||||
};
|
||||
})();
|
||||
|
||||
var init = function(){
|
||||
if(!init.i && document.getElementsByClassName){
|
||||
init.i = true;
|
||||
autoSizer._();
|
||||
loader._();
|
||||
}
|
||||
};
|
||||
|
||||
setTimeout(function(){
|
||||
if(lazySizesCfg.init){
|
||||
init();
|
||||
}
|
||||
});
|
||||
|
||||
lazysizes = {
|
||||
cfg: lazySizesCfg,
|
||||
autoSizer: autoSizer,
|
||||
loader: loader,
|
||||
init: init,
|
||||
uP: updatePolyfill,
|
||||
aC: addClass,
|
||||
rC: removeClass,
|
||||
hC: hasClass,
|
||||
fire: triggerEvent,
|
||||
gW: getWidth,
|
||||
rAF: rAF,
|
||||
};
|
||||
|
||||
return lazysizes;
|
||||
}
|
||||
));
|
1
wp-content/plugins/ewww-image-optimizer/includes/lazysizes.min.js
vendored
Normal file
1
wp-content/plugins/ewww-image-optimizer/includes/lazysizes.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
701
wp-content/plugins/ewww-image-optimizer/includes/load-webp.js
Normal file
701
wp-content/plugins/ewww-image-optimizer/includes/load-webp.js
Normal file
@ -0,0 +1,701 @@
|
||||
/*globals jQuery,Window,HTMLElement,HTMLDocument,HTMLCollection,NodeList,MutationObserver */
|
||||
/*exported Arrive*/
|
||||
/*jshint latedef:false */
|
||||
|
||||
/*
|
||||
* arrive.js
|
||||
* v2.4.1
|
||||
* https://github.com/uzairfarooq/arrive
|
||||
* MIT licensed
|
||||
*
|
||||
* Copyright (c) 2014-2017 Uzair Farooq
|
||||
*/
|
||||
var Arrive = (function(window, $, undefined) {
|
||||
|
||||
"use strict";
|
||||
|
||||
if(!window.MutationObserver || typeof HTMLElement === 'undefined'){
|
||||
return; //for unsupported browsers
|
||||
}
|
||||
|
||||
var arriveUniqueId = 0;
|
||||
|
||||
var utils = (function() {
|
||||
var matches = HTMLElement.prototype.matches || HTMLElement.prototype.webkitMatchesSelector || HTMLElement.prototype.mozMatchesSelector
|
||||
|| HTMLElement.prototype.msMatchesSelector;
|
||||
|
||||
return {
|
||||
matchesSelector: function(elem, selector) {
|
||||
return elem instanceof HTMLElement && matches.call(elem, selector);
|
||||
},
|
||||
// to enable function overloading - By John Resig (MIT Licensed)
|
||||
addMethod: function (object, name, fn) {
|
||||
var old = object[ name ];
|
||||
object[ name ] = function(){
|
||||
if ( fn.length == arguments.length ) {
|
||||
return fn.apply( this, arguments );
|
||||
}
|
||||
else if ( typeof old == 'function' ) {
|
||||
return old.apply( this, arguments );
|
||||
}
|
||||
};
|
||||
},
|
||||
callCallbacks: function(callbacksToBeCalled, registrationData) {
|
||||
if (registrationData && registrationData.options.onceOnly && registrationData.firedElems.length == 1) {
|
||||
// as onlyOnce param is true, make sure we fire the event for only one item
|
||||
callbacksToBeCalled = [callbacksToBeCalled[0]];
|
||||
}
|
||||
|
||||
for (var i = 0, cb; (cb = callbacksToBeCalled[i]); i++) {
|
||||
if (cb && cb.callback) {
|
||||
cb.callback.call(cb.elem, cb.elem);
|
||||
}
|
||||
}
|
||||
|
||||
if (registrationData && registrationData.options.onceOnly && registrationData.firedElems.length == 1) {
|
||||
// unbind event after first callback as onceOnly is true.
|
||||
registrationData.me.unbindEventWithSelectorAndCallback.call(
|
||||
registrationData.target, registrationData.selector, registrationData.callback
|
||||
);
|
||||
}
|
||||
},
|
||||
// traverse through all descendants of a node to check if event should be fired for any descendant
|
||||
checkChildNodesRecursively: function(nodes, registrationData, matchFunc, callbacksToBeCalled) {
|
||||
// check each new node if it matches the selector
|
||||
for (var i=0, node; (node = nodes[i]); i++) {
|
||||
if (matchFunc(node, registrationData, callbacksToBeCalled)) {
|
||||
callbacksToBeCalled.push({ callback: registrationData.callback, elem: node });
|
||||
}
|
||||
|
||||
if (node.childNodes.length > 0) {
|
||||
utils.checkChildNodesRecursively(node.childNodes, registrationData, matchFunc, callbacksToBeCalled);
|
||||
}
|
||||
}
|
||||
},
|
||||
mergeArrays: function(firstArr, secondArr){
|
||||
// Overwrites default options with user-defined options.
|
||||
var options = {},
|
||||
attrName;
|
||||
for (attrName in firstArr) {
|
||||
if (firstArr.hasOwnProperty(attrName)) {
|
||||
options[attrName] = firstArr[attrName];
|
||||
}
|
||||
}
|
||||
for (attrName in secondArr) {
|
||||
if (secondArr.hasOwnProperty(attrName)) {
|
||||
options[attrName] = secondArr[attrName];
|
||||
}
|
||||
}
|
||||
return options;
|
||||
},
|
||||
toElementsArray: function (elements) {
|
||||
// check if object is an array (or array like object)
|
||||
// Note: window object has .length property but it's not array of elements so don't consider it an array
|
||||
if (typeof elements !== 'undefined' && (typeof elements.length !== 'number' || elements === window)) {
|
||||
elements = [elements];
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
// Class to maintain state of all registered events of a single type
|
||||
var EventsBucket = (function() {
|
||||
var EventsBucket = function() {
|
||||
// holds all the events
|
||||
|
||||
this._eventsBucket = [];
|
||||
// function to be called while adding an event, the function should do the event initialization/registration
|
||||
this._beforeAdding = null;
|
||||
// function to be called while removing an event, the function should do the event destruction
|
||||
this._beforeRemoving = null;
|
||||
};
|
||||
|
||||
EventsBucket.prototype.addEvent = function(target, selector, options, callback) {
|
||||
var newEvent = {
|
||||
target: target,
|
||||
selector: selector,
|
||||
options: options,
|
||||
callback: callback,
|
||||
firedElems: []
|
||||
};
|
||||
|
||||
if (this._beforeAdding) {
|
||||
this._beforeAdding(newEvent);
|
||||
}
|
||||
|
||||
this._eventsBucket.push(newEvent);
|
||||
return newEvent;
|
||||
};
|
||||
|
||||
EventsBucket.prototype.removeEvent = function(compareFunction) {
|
||||
for (var i=this._eventsBucket.length - 1, registeredEvent; (registeredEvent = this._eventsBucket[i]); i--) {
|
||||
if (compareFunction(registeredEvent)) {
|
||||
if (this._beforeRemoving) {
|
||||
this._beforeRemoving(registeredEvent);
|
||||
}
|
||||
|
||||
// mark callback as null so that even if an event mutation was already triggered it does not call callback
|
||||
var removedEvents = this._eventsBucket.splice(i, 1);
|
||||
if (removedEvents && removedEvents.length) {
|
||||
removedEvents[0].callback = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
EventsBucket.prototype.beforeAdding = function(beforeAdding) {
|
||||
this._beforeAdding = beforeAdding;
|
||||
};
|
||||
|
||||
EventsBucket.prototype.beforeRemoving = function(beforeRemoving) {
|
||||
this._beforeRemoving = beforeRemoving;
|
||||
};
|
||||
|
||||
return EventsBucket;
|
||||
})();
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* General class for binding/unbinding arrive and leave events
|
||||
*/
|
||||
var MutationEvents = function(getObserverConfig, onMutation) {
|
||||
var eventsBucket = new EventsBucket(),
|
||||
me = this;
|
||||
|
||||
var defaultOptions = {
|
||||
fireOnAttributesModification: false
|
||||
};
|
||||
|
||||
// actual event registration before adding it to bucket
|
||||
eventsBucket.beforeAdding(function(registrationData) {
|
||||
var
|
||||
target = registrationData.target,
|
||||
observer;
|
||||
|
||||
// mutation observer does not work on window or document
|
||||
if (target === window.document || target === window) {
|
||||
target = document.getElementsByTagName("html")[0];
|
||||
}
|
||||
|
||||
// Create an observer instance
|
||||
observer = new MutationObserver(function(e) {
|
||||
onMutation.call(this, e, registrationData);
|
||||
});
|
||||
|
||||
var config = getObserverConfig(registrationData.options);
|
||||
|
||||
observer.observe(target, config);
|
||||
|
||||
registrationData.observer = observer;
|
||||
registrationData.me = me;
|
||||
});
|
||||
|
||||
// cleanup/unregister before removing an event
|
||||
eventsBucket.beforeRemoving(function (eventData) {
|
||||
eventData.observer.disconnect();
|
||||
});
|
||||
|
||||
this.bindEvent = function(selector, options, callback) {
|
||||
options = utils.mergeArrays(defaultOptions, options);
|
||||
|
||||
var elements = utils.toElementsArray(this);
|
||||
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
eventsBucket.addEvent(elements[i], selector, options, callback);
|
||||
}
|
||||
};
|
||||
|
||||
this.unbindEvent = function() {
|
||||
var elements = utils.toElementsArray(this);
|
||||
eventsBucket.removeEvent(function(eventObj) {
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
if (this === undefined || eventObj.target === elements[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
this.unbindEventWithSelectorOrCallback = function(selector) {
|
||||
var elements = utils.toElementsArray(this),
|
||||
callback = selector,
|
||||
compareFunction;
|
||||
|
||||
if (typeof selector === "function") {
|
||||
compareFunction = function(eventObj) {
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
if ((this === undefined || eventObj.target === elements[i]) && eventObj.callback === callback) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
else {
|
||||
compareFunction = function(eventObj) {
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
if ((this === undefined || eventObj.target === elements[i]) && eventObj.selector === selector) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
eventsBucket.removeEvent(compareFunction);
|
||||
};
|
||||
|
||||
this.unbindEventWithSelectorAndCallback = function(selector, callback) {
|
||||
var elements = utils.toElementsArray(this);
|
||||
eventsBucket.removeEvent(function(eventObj) {
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
if ((this === undefined || eventObj.target === elements[i]) && eventObj.selector === selector && eventObj.callback === callback) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* Processes 'arrive' events
|
||||
*/
|
||||
var ArriveEvents = function() {
|
||||
// Default options for 'arrive' event
|
||||
var arriveDefaultOptions = {
|
||||
fireOnAttributesModification: false,
|
||||
onceOnly: false,
|
||||
existing: false
|
||||
};
|
||||
|
||||
function getArriveObserverConfig(options) {
|
||||
var config = {
|
||||
attributes: false,
|
||||
childList: true,
|
||||
subtree: true
|
||||
};
|
||||
|
||||
if (options.fireOnAttributesModification) {
|
||||
config.attributes = true;
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
function onArriveMutation(mutations, registrationData) {
|
||||
mutations.forEach(function( mutation ) {
|
||||
var newNodes = mutation.addedNodes,
|
||||
targetNode = mutation.target,
|
||||
callbacksToBeCalled = [],
|
||||
node;
|
||||
|
||||
// If new nodes are added
|
||||
if( newNodes !== null && newNodes.length > 0 ) {
|
||||
utils.checkChildNodesRecursively(newNodes, registrationData, nodeMatchFunc, callbacksToBeCalled);
|
||||
}
|
||||
else if (mutation.type === "attributes") {
|
||||
if (nodeMatchFunc(targetNode, registrationData, callbacksToBeCalled)) {
|
||||
callbacksToBeCalled.push({ callback: registrationData.callback, elem: targetNode });
|
||||
}
|
||||
}
|
||||
|
||||
utils.callCallbacks(callbacksToBeCalled, registrationData);
|
||||
});
|
||||
}
|
||||
|
||||
function nodeMatchFunc(node, registrationData, callbacksToBeCalled) {
|
||||
// check a single node to see if it matches the selector
|
||||
if (utils.matchesSelector(node, registrationData.selector)) {
|
||||
if(node._id === undefined) {
|
||||
node._id = arriveUniqueId++;
|
||||
}
|
||||
// make sure the arrive event is not already fired for the element
|
||||
if (registrationData.firedElems.indexOf(node._id) == -1) {
|
||||
registrationData.firedElems.push(node._id);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
arriveEvents = new MutationEvents(getArriveObserverConfig, onArriveMutation);
|
||||
|
||||
var mutationBindEvent = arriveEvents.bindEvent;
|
||||
|
||||
// override bindEvent function
|
||||
arriveEvents.bindEvent = function(selector, options, callback) {
|
||||
|
||||
if (typeof callback === "undefined") {
|
||||
callback = options;
|
||||
options = arriveDefaultOptions;
|
||||
} else {
|
||||
options = utils.mergeArrays(arriveDefaultOptions, options);
|
||||
}
|
||||
|
||||
var elements = utils.toElementsArray(this);
|
||||
|
||||
if (options.existing) {
|
||||
var existing = [];
|
||||
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
var nodes = elements[i].querySelectorAll(selector);
|
||||
for (var j = 0; j < nodes.length; j++) {
|
||||
existing.push({ callback: callback, elem: nodes[j] });
|
||||
}
|
||||
}
|
||||
|
||||
// no need to bind event if the callback has to be fired only once and we have already found the element
|
||||
if (options.onceOnly && existing.length) {
|
||||
return callback.call(existing[0].elem, existing[0].elem);
|
||||
}
|
||||
|
||||
setTimeout(utils.callCallbacks, 1, existing);
|
||||
}
|
||||
|
||||
mutationBindEvent.call(this, selector, options, callback);
|
||||
};
|
||||
|
||||
return arriveEvents;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* Processes 'leave' events
|
||||
*/
|
||||
var LeaveEvents = function() {
|
||||
// Default options for 'leave' event
|
||||
var leaveDefaultOptions = {};
|
||||
|
||||
function getLeaveObserverConfig() {
|
||||
var config = {
|
||||
childList: true,
|
||||
subtree: true
|
||||
};
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
function onLeaveMutation(mutations, registrationData) {
|
||||
mutations.forEach(function( mutation ) {
|
||||
var removedNodes = mutation.removedNodes,
|
||||
callbacksToBeCalled = [];
|
||||
|
||||
if( removedNodes !== null && removedNodes.length > 0 ) {
|
||||
utils.checkChildNodesRecursively(removedNodes, registrationData, nodeMatchFunc, callbacksToBeCalled);
|
||||
}
|
||||
|
||||
utils.callCallbacks(callbacksToBeCalled, registrationData);
|
||||
});
|
||||
}
|
||||
|
||||
function nodeMatchFunc(node, registrationData) {
|
||||
return utils.matchesSelector(node, registrationData.selector);
|
||||
}
|
||||
|
||||
leaveEvents = new MutationEvents(getLeaveObserverConfig, onLeaveMutation);
|
||||
|
||||
var mutationBindEvent = leaveEvents.bindEvent;
|
||||
|
||||
// override bindEvent function
|
||||
leaveEvents.bindEvent = function(selector, options, callback) {
|
||||
|
||||
if (typeof callback === "undefined") {
|
||||
callback = options;
|
||||
options = leaveDefaultOptions;
|
||||
} else {
|
||||
options = utils.mergeArrays(leaveDefaultOptions, options);
|
||||
}
|
||||
|
||||
mutationBindEvent.call(this, selector, options, callback);
|
||||
};
|
||||
|
||||
return leaveEvents;
|
||||
};
|
||||
|
||||
|
||||
var arriveEvents = new ArriveEvents(),
|
||||
leaveEvents = new LeaveEvents();
|
||||
|
||||
function exposeUnbindApi(eventObj, exposeTo, funcName) {
|
||||
// expose unbind function with function overriding
|
||||
utils.addMethod(exposeTo, funcName, eventObj.unbindEvent);
|
||||
utils.addMethod(exposeTo, funcName, eventObj.unbindEventWithSelectorOrCallback);
|
||||
utils.addMethod(exposeTo, funcName, eventObj.unbindEventWithSelectorAndCallback);
|
||||
}
|
||||
|
||||
/*** expose APIs ***/
|
||||
function exposeApi(exposeTo) {
|
||||
exposeTo.arrive = arriveEvents.bindEvent;
|
||||
exposeUnbindApi(arriveEvents, exposeTo, "unbindArrive");
|
||||
|
||||
exposeTo.leave = leaveEvents.bindEvent;
|
||||
exposeUnbindApi(leaveEvents, exposeTo, "unbindLeave");
|
||||
}
|
||||
|
||||
exposeApi(HTMLElement.prototype);
|
||||
exposeApi(NodeList.prototype);
|
||||
exposeApi(HTMLCollection.prototype);
|
||||
exposeApi(HTMLDocument.prototype);
|
||||
exposeApi(Window.prototype);
|
||||
|
||||
var Arrive = {};
|
||||
// expose functions to unbind all arrive/leave events
|
||||
exposeUnbindApi(arriveEvents, Arrive, "unbindAllArrive");
|
||||
exposeUnbindApi(leaveEvents, Arrive, "unbindAllLeave");
|
||||
|
||||
return Arrive;
|
||||
|
||||
})(window, null, undefined);
|
||||
|
||||
var ewww_webp_supported = false;
|
||||
// webp detection adapted from https://developers.google.com/speed/webp/faq#how_can_i_detect_browser_support_using_javascript
|
||||
function check_webp_feature(feature, callback) {
|
||||
if (ewww_webp_supported) {
|
||||
callback(ewww_webp_supported);
|
||||
return;
|
||||
}
|
||||
var kTestImages = {
|
||||
alpha: "UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAARBxAR/Q9ERP8DAABWUDggGAAAABQBAJ0BKgEAAQAAAP4AAA3AAP7mtQAAAA==",
|
||||
animation: "UklGRlIAAABXRUJQVlA4WAoAAAASAAAAAAAAAAAAQU5JTQYAAAD/////AABBTk1GJgAAAAAAAAAAAAAAAAAAAGQAAABWUDhMDQAAAC8AAAAQBxAREYiI/gcA"
|
||||
};
|
||||
var img = new Image();
|
||||
img.onload = function () {
|
||||
ewww_webp_supported = (img.width > 0) && (img.height > 0);
|
||||
callback(ewww_webp_supported);
|
||||
};
|
||||
img.onerror = function () {
|
||||
callback(false);
|
||||
};
|
||||
img.src = "data:image/webp;base64," + kTestImages[feature];
|
||||
}
|
||||
function ewwwLoadImages(ewww_webp_supported) {
|
||||
if (ewww_webp_supported) {
|
||||
var nggImages = document.querySelectorAll('.batch-image img, .image-wrapper a, .ngg-pro-masonry-item a, .ngg-galleria-offscreen-seo-wrapper a');
|
||||
for (var i = 0, len = nggImages.length; i < len; i++){
|
||||
ewwwAttr(nggImages[i], 'data-src', nggImages[i].getAttribute('data-webp'));
|
||||
ewwwAttr(nggImages[i], 'data-thumbnail', nggImages[i].getAttribute('data-webp-thumbnail'));
|
||||
}
|
||||
var revImages = document.querySelectorAll('.rev_slider ul li');
|
||||
for (var i = 0, len = revImages.length; i < len; i++){
|
||||
ewwwAttr(revImages[i], 'data-thumb', revImages[i].getAttribute('data-webp-thumb'));
|
||||
var param_num = 1;
|
||||
while ( param_num < 11 ) {
|
||||
ewwwAttr(revImages[i], 'data-param' + param_num, revImages[i].getAttribute('data-webp-param' + param_num));
|
||||
param_num++;
|
||||
}
|
||||
}
|
||||
var revImages = document.querySelectorAll('.rev_slider img');
|
||||
for (var i = 0, len = revImages.length; i < len; i++){
|
||||
ewwwAttr(revImages[i], 'data-lazyload', revImages[i].getAttribute('data-webp-lazyload'));
|
||||
}
|
||||
var wooImages = document.querySelectorAll('div.woocommerce-product-gallery__image');
|
||||
for (var i = 0, len = wooImages.length; i < len; i++){
|
||||
ewwwAttr(wooImages[i], 'data-thumb', wooImages[i].getAttribute('data-webp-thumb'));
|
||||
}
|
||||
}
|
||||
var videos = document.querySelectorAll('video');
|
||||
for (var i = 0, len = videos.length; i < len; i++){
|
||||
if (ewww_webp_supported) {
|
||||
ewwwAttr(videos[i], 'poster', videos[i].getAttribute('data-poster-webp'));
|
||||
} else {
|
||||
ewwwAttr(videos[i], 'poster', videos[i].getAttribute('data-poster-image'));
|
||||
}
|
||||
}
|
||||
var lazies = document.querySelectorAll('img.ewww_webp_lazy_load');
|
||||
for (var i = 0, len = lazies.length; i < len; i++){
|
||||
console.log('parsing an image: ' + lazies[i].getAttribute('data-src'));
|
||||
if (ewww_webp_supported) {
|
||||
console.log('webp good');
|
||||
ewwwAttr(lazies[i], 'data-lazy-srcset', lazies[i].getAttribute('data-lazy-srcset-webp'));
|
||||
ewwwAttr(lazies[i], 'data-srcset', lazies[i].getAttribute('data-srcset-webp'));
|
||||
ewwwAttr(lazies[i], 'data-lazy-src', lazies[i].getAttribute('data-lazy-src-webp'));
|
||||
ewwwAttr(lazies[i], 'data-src', lazies[i].getAttribute('data-src-webp'));
|
||||
ewwwAttr(lazies[i], 'data-orig-file', lazies[i].getAttribute('data-webp-orig-file'));
|
||||
ewwwAttr(lazies[i], 'data-medium-file', lazies[i].getAttribute('data-webp-medium-file'));
|
||||
ewwwAttr(lazies[i], 'data-large-file', lazies[i].getAttribute('data-webp-large-file'));
|
||||
var jpsrcset = lazies[i].getAttribute('srcset');
|
||||
if (jpsrcset != null && jpsrcset !== false && jpsrcset.includes('R0lGOD')) {
|
||||
ewwwAttr(lazies[i], 'src', lazies[i].getAttribute('data-lazy-src-webp'));
|
||||
}
|
||||
}
|
||||
lazies[i].className = lazies[i].className.replace(/\bewww_webp_lazy_load\b/, '');
|
||||
}
|
||||
var elems = document.querySelectorAll('.ewww_webp');
|
||||
for (var i = 0, len = elems.length; i < len; i++){
|
||||
console.log('parsing an image: ' + elems[i].getAttribute('data-src'));
|
||||
if (ewww_webp_supported) {
|
||||
ewwwAttr(elems[i], 'srcset', elems[i].getAttribute('data-srcset-webp'));
|
||||
ewwwAttr(elems[i], 'src', elems[i].getAttribute('data-src-webp'));
|
||||
ewwwAttr(elems[i], 'data-orig-file', elems[i].getAttribute('data-webp-orig-file'));
|
||||
ewwwAttr(elems[i], 'data-medium-file', elems[i].getAttribute('data-webp-medium-file'));
|
||||
ewwwAttr(elems[i], 'data-large-file', elems[i].getAttribute('data-webp-large-file'));
|
||||
ewwwAttr(elems[i], 'data-large_image', elems[i].getAttribute('data-webp-large_image'));
|
||||
ewwwAttr(elems[i], 'data-src', elems[i].getAttribute('data-webp-src'));
|
||||
} else {
|
||||
ewwwAttr(elems[i], 'srcset', elems[i].getAttribute('data-srcset-img'));
|
||||
ewwwAttr(elems[i], 'src', elems[i].getAttribute('data-src-img'));
|
||||
}
|
||||
elems[i].className = elems[i].className.replace(/\bewww_webp\b/, 'ewww_webp_loaded');
|
||||
}
|
||||
if (window.jQuery && jQuery.fn.isotope && jQuery.fn.imagesLoaded) {
|
||||
jQuery('.fusion-posts-container-infinite').imagesLoaded( function() {
|
||||
if ( jQuery( '.fusion-posts-container-infinite' ).hasClass( 'isotope' ) ) {
|
||||
jQuery( '.fusion-posts-container-infinite' ).isotope();
|
||||
}
|
||||
});
|
||||
jQuery('.fusion-portfolio:not(.fusion-recent-works) .fusion-portfolio-wrapper').imagesLoaded( function() {
|
||||
jQuery( '.fusion-portfolio:not(.fusion-recent-works) .fusion-portfolio-wrapper' ).isotope();
|
||||
});
|
||||
}
|
||||
}
|
||||
check_webp_feature('alpha', ewwwWebPInit);
|
||||
function ewwwWebPInit(ewww_webp_supported) {
|
||||
ewwwLoadImages(ewww_webp_supported);
|
||||
ewwwNggLoadGalleries(ewww_webp_supported);
|
||||
document.arrive('.ewww_webp', function() {
|
||||
ewwwLoadImages(ewww_webp_supported);
|
||||
});
|
||||
document.arrive('.ewww_webp_lazy_load', function() {
|
||||
ewwwLoadImages(ewww_webp_supported);
|
||||
});
|
||||
document.arrive('videos', function() {
|
||||
ewwwLoadImages(ewww_webp_supported);
|
||||
});
|
||||
if (document.readyState == 'loading') {
|
||||
console.log('deferring ewwwJSONParserInit until DOMContentLoaded')
|
||||
document.addEventListener('DOMContentLoaded', ewwwJSONParserInit);
|
||||
} else {
|
||||
console.log(document.readyState);
|
||||
console.log('running JSON parsers post haste')
|
||||
if ( typeof galleries !== 'undefined' ) {
|
||||
console.log('galleries found, parsing')
|
||||
ewwwNggParseGalleries(ewww_webp_supported);
|
||||
}
|
||||
ewwwWooParseVariations(ewww_webp_supported);
|
||||
}
|
||||
}
|
||||
function ewwwAttr(elem, attr, value) {
|
||||
if (value != null && value !== false) {
|
||||
elem.setAttribute(attr, value);
|
||||
}
|
||||
}
|
||||
function ewwwJSONParserInit() {
|
||||
if ( typeof galleries !== 'undefined' ) {
|
||||
check_webp_feature('alpha', ewwwNggParseGalleries);
|
||||
}
|
||||
check_webp_feature('alpha', ewwwWooParseVariations);
|
||||
}
|
||||
function ewwwWooParseVariations(ewww_webp_supported) {
|
||||
if (!ewww_webp_supported) {
|
||||
return;
|
||||
}
|
||||
var elems = document.querySelectorAll('form.variations_form');
|
||||
for (var i = 0, len = elems.length; i < len; i++){
|
||||
var variations = elems[i].getAttribute('data-product_variations');
|
||||
var variations_changed = false;
|
||||
try {
|
||||
variations = JSON.parse(variations);
|
||||
//console.log(variations);
|
||||
console.log('parsing WC variations');
|
||||
for ( var num in variations ) {
|
||||
if (variations[ num ] !== undefined && variations[ num ].image !== undefined) {
|
||||
console.log(variations[num].image);
|
||||
if (variations[num].image.src_webp !== undefined) {
|
||||
variations[num].image.src = variations[num].image.src_webp;
|
||||
variations_changed = true;
|
||||
}
|
||||
if (variations[num].image.srcset_webp !== undefined) {
|
||||
variations[num].image.srcset = variations[num].image.srcset_webp;
|
||||
variations_changed = true;
|
||||
}
|
||||
if (variations[num].image.full_src_webp !== undefined) {
|
||||
variations[num].image.full_src = variations[num].image.full_src_webp;
|
||||
variations_changed = true;
|
||||
}
|
||||
if (variations[num].image.gallery_thumbnail_src_webp !== undefined) {
|
||||
variations[num].image.gallery_thumbnail_src = variations[num].image.gallery_thumbnail_src_webp;
|
||||
variations_changed = true;
|
||||
}
|
||||
if (variations[num].image.thumb_src_webp !== undefined) {
|
||||
variations[num].image.thumb_src = variations[num].image.thumb_src_webp;
|
||||
variations_changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (variations_changed) {
|
||||
ewwwAttr(elems[i], 'data-product_variations', JSON.stringify(variations));
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
console.log(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
function ewwwNggParseGalleries(ewww_webp_supported) {
|
||||
if (ewww_webp_supported) {
|
||||
for(var galleryIndex in galleries) {
|
||||
var gallery = galleries[galleryIndex];
|
||||
galleries[galleryIndex].images_list = ewwwNggParseImageList(gallery.images_list);
|
||||
}
|
||||
}
|
||||
}
|
||||
function ewwwNggLoadGalleries(ewww_webp_supported) {
|
||||
if (ewww_webp_supported) {
|
||||
document.addEventListener('ngg.galleria.themeadded', function(event, themename){
|
||||
window.ngg_galleria._create_backup = window.ngg_galleria.create;
|
||||
window.ngg_galleria.create = function(gallery_parent, themename) {
|
||||
var gallery_id = $(gallery_parent).data('id');
|
||||
galleries['gallery_' + gallery_id].images_list = ewwwNggParseImageList(galleries['gallery_' + gallery_id].images_list);
|
||||
return window.ngg_galleria._create_backup(gallery_parent, themename);
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
function ewwwNggParseImageList(images_list) {
|
||||
console.log('parsing gallery images');
|
||||
for(var nggIndex in images_list) {
|
||||
var nggImage = images_list[nggIndex];
|
||||
if (typeof nggImage['image-webp'] !== typeof undefined) {
|
||||
images_list[nggIndex]['image'] = nggImage['image-webp'];
|
||||
delete images_list[nggIndex]['image-webp'];
|
||||
}
|
||||
if (typeof nggImage['thumb-webp'] !== typeof undefined) {
|
||||
images_list[nggIndex]['thumb'] = nggImage['thumb-webp'];
|
||||
delete images_list[nggIndex]['thumb-webp'];
|
||||
}
|
||||
if (typeof nggImage['full_image_webp'] !== typeof undefined) {
|
||||
images_list[nggIndex]['full_image'] = nggImage['full_image_webp'];
|
||||
delete images_list[nggIndex]['full_image_webp'];
|
||||
}
|
||||
if (typeof nggImage['srcsets'] !== typeof undefined) {
|
||||
for(var nggSrcsetIndex in nggImage['srcsets']) {
|
||||
nggSrcset = nggImage['srcsets'][nggSrcsetIndex];
|
||||
if (typeof nggImage['srcsets'][nggSrcsetIndex + '-webp'] !== typeof undefined) {
|
||||
images_list[nggIndex]['srcsets'][nggSrcsetIndex] = nggImage['srcsets'][nggSrcsetIndex + '-webp'];
|
||||
delete images_list[nggIndex]['srcsets'][nggSrcsetIndex + '-webp'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (typeof nggImage['full_srcsets'] !== typeof undefined) {
|
||||
for(var nggFSrcsetIndex in nggImage['full_srcsets']) {
|
||||
nggFSrcset = nggImage['full_srcsets'][nggFSrcsetIndex];
|
||||
if (typeof nggImage['full_srcsets'][nggFSrcsetIndex + '-webp'] !== typeof undefined) {
|
||||
images_list[nggIndex]['full_srcsets'][nggFSrcsetIndex] = nggImage['full_srcsets'][nggFSrcsetIndex + '-webp'];
|
||||
delete images_list[nggIndex]['full_srcsets'][nggFSrcsetIndex + '-webp'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return images_list;
|
||||
}
|
1
wp-content/plugins/ewww-image-optimizer/includes/load-webp.min.js
vendored
Normal file
1
wp-content/plugins/ewww-image-optimizer/includes/load-webp.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
51
wp-content/plugins/ewww-image-optimizer/includes/ls.print.js
Normal file
51
wp-content/plugins/ewww-image-optimizer/includes/ls.print.js
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
This lazySizes extension adds better support for print.
|
||||
In case the user starts to print lazysizes will load all images.
|
||||
*/
|
||||
(function(window, factory) {
|
||||
var globalInstall = function(){
|
||||
factory(window.lazySizes);
|
||||
window.removeEventListener('lazyunveilread', globalInstall, true);
|
||||
};
|
||||
|
||||
factory = factory.bind(null, window, window.document);
|
||||
|
||||
if(typeof module == 'object' && module.exports){
|
||||
factory(require('lazysizes'));
|
||||
} else if(window.lazySizes) {
|
||||
globalInstall();
|
||||
} else {
|
||||
window.addEventListener('lazyunveilread', globalInstall, true);
|
||||
}
|
||||
}(window, function(window, document, lazySizes) {
|
||||
/*jshint eqnull:true */
|
||||
'use strict';
|
||||
var config, elements, onprint, printMedia;
|
||||
// see also: http://tjvantoll.com/2012/06/15/detecting-print-requests-with-javascript/
|
||||
if(window.addEventListener){
|
||||
config = lazySizes && lazySizes.cfg;
|
||||
elements = config.lazyClass || 'lazyload';
|
||||
onprint = function(){
|
||||
var i, len;
|
||||
if(typeof elements == 'string'){
|
||||
elements = document.getElementsByClassName(elements);
|
||||
}
|
||||
|
||||
if(lazySizes){
|
||||
for(i = 0, len = elements.length; i < len; i++){
|
||||
lazySizes.loader.unveil(elements[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
addEventListener('beforeprint', onprint, false);
|
||||
|
||||
if(!('onbeforeprint' in window) && window.matchMedia && (printMedia = matchMedia('print')) && printMedia.addListener){
|
||||
printMedia.addListener(function(){
|
||||
if(printMedia.matches){
|
||||
onprint();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}));
|
2
wp-content/plugins/ewww-image-optimizer/includes/ls.print.min.js
vendored
Normal file
2
wp-content/plugins/ewww-image-optimizer/includes/ls.print.min.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/*! lazysizes - v5.1.0 */
|
||||
!function(a,b){var c=function(){b(a.lazySizes),a.removeEventListener("lazyunveilread",c,!0)};b=b.bind(null,a,a.document),"object"==typeof module&&module.exports?b(require("lazysizes")):a.lazySizes?c():a.addEventListener("lazyunveilread",c,!0)}(window,function(a,b,c){"use strict";var d,e,f,g;a.addEventListener&&(d=c&&c.cfg,e=d.lazyClass||"lazyload",f=function(){var a,d;if("string"==typeof e&&(e=b.getElementsByClassName(e)),c)for(a=0,d=e.length;a<d;a++)c.loader.unveil(e[a])},addEventListener("beforeprint",f,!1),!("onbeforeprint"in a)&&a.matchMedia&&(g=matchMedia("print"))&&g.addListener&&g.addListener(function(){g.matches&&f()}))});
|
@ -0,0 +1,118 @@
|
||||
(function(window, factory) {
|
||||
var globalInstall = function(){
|
||||
factory(window.lazySizes);
|
||||
window.removeEventListener('lazyunveilread', globalInstall, true);
|
||||
};
|
||||
|
||||
factory = factory.bind(null, window, window.document);
|
||||
|
||||
if(typeof module == 'object' && module.exports){
|
||||
factory(require('lazysizes'));
|
||||
} else if (typeof define == 'function' && define.amd) {
|
||||
define(['lazysizes'], factory);
|
||||
} else if(window.lazySizes) {
|
||||
globalInstall();
|
||||
} else {
|
||||
window.addEventListener('lazyunveilread', globalInstall, true);
|
||||
}
|
||||
}(window, function(window, document, lazySizes) {
|
||||
/*jshint eqnull:true */
|
||||
'use strict';
|
||||
var regBgUrlEscape;
|
||||
|
||||
if(document.addEventListener){
|
||||
regBgUrlEscape = /\(|\)|\s|'/;
|
||||
|
||||
addEventListener('lazybeforeunveil', function(e){
|
||||
if(e.detail.instance != lazySizes){return;}
|
||||
|
||||
var bg, bgWebP;
|
||||
if(!e.defaultPrevented) {
|
||||
|
||||
if(e.target.preload == 'none'){
|
||||
e.target.preload = 'auto';
|
||||
}
|
||||
|
||||
// handle data-back (so as not to conflict with the stock data-bg)
|
||||
bg = e.target.getAttribute('data-back');
|
||||
if (bg) {
|
||||
if(ewww_webp_supported) {
|
||||
console.log('checking for data-back-webp');
|
||||
bgWebP = e.target.getAttribute('data-back-webp');
|
||||
if (bgWebP) {
|
||||
console.log('replacing data-back with data-back-webp');
|
||||
bg = bgWebP;
|
||||
}
|
||||
}
|
||||
var dPR = (window.devicePixelRatio || 1);
|
||||
var targetWidth = Math.round(e.target.offsetWidth * dPR);
|
||||
var targetHeight = Math.round(e.target.offsetHeight * dPR);
|
||||
if ( 0 === bg.search(/\[/) ) {
|
||||
} else if (!shouldAutoScale(e.target)||!shouldAutoScale(e.target.parentNode)){
|
||||
} else if (window.lazySizes.hC(e.target,'wp-block-cover')) {
|
||||
console.log('found wp-block-cover with data-back');
|
||||
if (window.lazySizes.hC(e.target,'has-parallax')) {
|
||||
console.log('also has-parallax with data-back');
|
||||
targetWidth = Math.round(window.screen.width * dPR);
|
||||
targetHeight = Math.round(window.screen.height * dPR);
|
||||
} else if (targetHeight<300) {
|
||||
targetHeight = 430;
|
||||
}
|
||||
bg = constrainSrc(bg,targetWidth,targetHeight,'bg-cover');
|
||||
} else if (window.lazySizes.hC(e.target,'cover-image')){
|
||||
console.log('found .cover-image with data-back');
|
||||
bg = constrainSrc(bg,targetWidth,targetHeight,'bg-cover');
|
||||
} else if (window.lazySizes.hC(e.target,'elementor-bg')){
|
||||
console.log('found elementor-bg with data-back');
|
||||
bg = constrainSrc(bg,targetWidth,targetHeight,'bg-cover');
|
||||
} else if (window.lazySizes.hC(e.target,'et_parallax_bg')){
|
||||
console.log('found et_parallax_bg with data-back');
|
||||
bg = constrainSrc(bg,targetWidth,targetHeight,'bg-cover');
|
||||
} else if (window.lazySizes.hC(e.target,'bg-image-crop')){
|
||||
console.log('found bg-image-crop with data-back');
|
||||
bg = constrainSrc(bg,targetWidth,targetHeight,'bg-cover');
|
||||
} else {
|
||||
console.log('found other data-back');
|
||||
bg = constrainSrc(bg,targetWidth,targetHeight,'bg');
|
||||
}
|
||||
if ( e.target.style.backgroundImage && -1 === e.target.style.backgroundImage.search(/^initial/) ) {
|
||||
// Convert JSON for multiple URLs.
|
||||
if ( 0 === bg.search(/\[/) ) {
|
||||
console.log('multiple URLs to append');
|
||||
bg = JSON.parse(bg);
|
||||
bg.forEach(
|
||||
function(bg_url){
|
||||
bg_url = (regBgUrlEscape.test(bg_url) ? JSON.stringify(bg_url) : bg_url );
|
||||
}
|
||||
);
|
||||
bg = 'url("' + bg.join('"), url("') + '"';
|
||||
var new_bg = e.target.style.backgroundImage + ', ' + bg;
|
||||
console.log('setting .backgroundImage: ' + new_bg );
|
||||
e.target.style.backgroundImage = new_bg;
|
||||
} else {
|
||||
console.log( 'appending bg url: ' + e.target.style.backgroundImage + ', url(' + (regBgUrlEscape.test(bg) ? JSON.stringify(bg) : bg ) + ')' );
|
||||
e.target.style.backgroundImage = e.target.style.backgroundImage + ', url("' + (regBgUrlEscape.test(bg) ? JSON.stringify(bg) : bg ) + '")';
|
||||
}
|
||||
} else {
|
||||
// Convert JSON for multiple URLs.
|
||||
if ( 0 === bg.search(/\[/) ) {
|
||||
console.log('multiple URLs to insert');
|
||||
bg = JSON.parse(bg);
|
||||
bg.forEach(
|
||||
function(bg_url){
|
||||
bg_url = (regBgUrlEscape.test(bg_url) ? JSON.stringify(bg_url) : bg_url );
|
||||
}
|
||||
);
|
||||
bg = 'url("' + bg.join('"), url("') + '"';
|
||||
console.log('setting .backgroundImage: ' + bg );
|
||||
e.target.style.backgroundImage = bg;
|
||||
} else {
|
||||
console.log('setting .backgroundImage: ' + 'url(' + (regBgUrlEscape.test(bg) ? JSON.stringify(bg) : bg ) + ')');
|
||||
e.target.style.backgroundImage = 'url(' + (regBgUrlEscape.test(bg) ? JSON.stringify(bg) : bg ) + ')';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
}));
|
@ -0,0 +1,184 @@
|
||||
/*
|
||||
This plugin extends lazySizes to lazyLoad:
|
||||
background images, videos/posters and scripts
|
||||
|
||||
Background-Image:
|
||||
For background images, use data-bg attribute:
|
||||
<div class="lazyload" data-bg="bg-img.jpg"></div>
|
||||
|
||||
Video:
|
||||
For video/audio use data-poster and preload="none":
|
||||
<video class="lazyload" preload="none" data-poster="poster.jpg" src="src.mp4">
|
||||
<!-- sources -->
|
||||
</video>
|
||||
|
||||
For video that plays automatically if in view:
|
||||
<video
|
||||
class="lazyload"
|
||||
preload="none"
|
||||
muted=""
|
||||
data-autoplay=""
|
||||
data-poster="poster.jpg"
|
||||
src="src.mp4">
|
||||
</video>
|
||||
|
||||
Scripts:
|
||||
For scripts use data-script:
|
||||
<div class="lazyload" data-script="module-name.js"></div>
|
||||
|
||||
|
||||
Script modules using require:
|
||||
For modules using require use data-require:
|
||||
<div class="lazyload" data-require="module-name"></div>
|
||||
*/
|
||||
|
||||
(function(window, factory) {
|
||||
var globalInstall = function(){
|
||||
factory(window.lazySizes);
|
||||
window.removeEventListener('lazyunveilread', globalInstall, true);
|
||||
};
|
||||
|
||||
factory = factory.bind(null, window, window.document);
|
||||
|
||||
if(typeof module == 'object' && module.exports){
|
||||
factory(require('lazysizes'));
|
||||
} else if (typeof define == 'function' && define.amd) {
|
||||
define(['lazysizes'], factory);
|
||||
} else if(window.lazySizes) {
|
||||
globalInstall();
|
||||
} else {
|
||||
window.addEventListener('lazyunveilread', globalInstall, true);
|
||||
}
|
||||
}(window, function(window, document, lazySizes) {
|
||||
/*jshint eqnull:true */
|
||||
'use strict';
|
||||
var bgLoad, regBgUrlEscape;
|
||||
var uniqueUrls = {};
|
||||
|
||||
if(document.addEventListener){
|
||||
regBgUrlEscape = /\(|\)|\s|'/;
|
||||
|
||||
bgLoad = function (url, cb){
|
||||
var img = document.createElement('img');
|
||||
img.onload = function(){
|
||||
img.onload = null;
|
||||
img.onerror = null;
|
||||
img = null;
|
||||
cb();
|
||||
};
|
||||
img.onerror = img.onload;
|
||||
|
||||
img.src = url;
|
||||
|
||||
if(img && img.complete && img.onload){
|
||||
img.onload();
|
||||
}
|
||||
};
|
||||
|
||||
addEventListener('lazybeforeunveil', function(e){
|
||||
if(e.detail.instance != lazySizes){return;}
|
||||
|
||||
var tmp, load, bg, poster;
|
||||
if(!e.defaultPrevented) {
|
||||
|
||||
var target = e.target;
|
||||
|
||||
if(target.preload == 'none'){
|
||||
target.preload = target.getAttribute('data-preload') || 'auto';
|
||||
}
|
||||
|
||||
if (target.getAttribute('data-autoplay') != null) {
|
||||
if (target.getAttribute('data-expand') && !target.autoplay) {
|
||||
try {
|
||||
target.play();
|
||||
} catch (er) {}
|
||||
} else {
|
||||
requestAnimationFrame(function () {
|
||||
target.setAttribute('data-expand', '-10');
|
||||
lazySizes.aC(target, lazySizes.cfg.lazyClass);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
tmp = target.getAttribute('data-link');
|
||||
if(tmp){
|
||||
addStyleScript(tmp, true);
|
||||
}
|
||||
|
||||
// handle data-script
|
||||
tmp = target.getAttribute('data-script');
|
||||
if(tmp){
|
||||
e.detail.firesLoad = true;
|
||||
load = function(){
|
||||
e.detail.firesLoad = false;
|
||||
lazySizes.fire(target, '_lazyloaded', {}, true, true);
|
||||
};
|
||||
addStyleScript(tmp, null, load);
|
||||
}
|
||||
|
||||
// handle data-require
|
||||
tmp = target.getAttribute('data-require');
|
||||
if(tmp){
|
||||
if(lazySizes.cfg.requireJs){
|
||||
lazySizes.cfg.requireJs([tmp]);
|
||||
} else {
|
||||
addStyleScript(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
// handle data-bg
|
||||
bg = target.getAttribute('data-bg');
|
||||
if (bg) {
|
||||
e.detail.firesLoad = true;
|
||||
load = function(){
|
||||
target.style.backgroundImage = 'url(' + (regBgUrlEscape.test(bg) ? JSON.stringify(bg) : bg ) + ')';
|
||||
e.detail.firesLoad = false;
|
||||
lazySizes.fire(target, '_lazyloaded', {}, true, true);
|
||||
};
|
||||
|
||||
bgLoad(bg, load);
|
||||
}
|
||||
|
||||
// handle data-poster
|
||||
poster = target.getAttribute('data-poster');
|
||||
if(poster){
|
||||
e.detail.firesLoad = true;
|
||||
load = function(){
|
||||
target.poster = poster;
|
||||
e.detail.firesLoad = false;
|
||||
lazySizes.fire(target, '_lazyloaded', {}, true, true);
|
||||
};
|
||||
|
||||
bgLoad(poster, load);
|
||||
|
||||
}
|
||||
}
|
||||
}, false);
|
||||
|
||||
}
|
||||
|
||||
function addStyleScript(src, style, cb){
|
||||
if(uniqueUrls[src]){
|
||||
return;
|
||||
}
|
||||
var elem = document.createElement(style ? 'link' : 'script');
|
||||
var insertElem = document.getElementsByTagName('script')[0];
|
||||
|
||||
if(style){
|
||||
elem.rel = 'stylesheet';
|
||||
elem.href = src;
|
||||
} else {
|
||||
elem.onload = function(){
|
||||
elem.onerror = null;
|
||||
elem.onload = null;
|
||||
cb();
|
||||
};
|
||||
elem.onerror = elem.onload;
|
||||
|
||||
elem.src = src;
|
||||
}
|
||||
uniqueUrls[src] = true;
|
||||
uniqueUrls[elem.src || elem.href] = true;
|
||||
insertElem.parentNode.insertBefore(elem, insertElem);
|
||||
}
|
||||
}));
|
109
wp-content/plugins/ewww-image-optimizer/includes/media.js
Normal file
109
wp-content/plugins/ewww-image-optimizer/includes/media.js
Normal file
@ -0,0 +1,109 @@
|
||||
jQuery(document).on('click', '.ewww-manual-optimize', function() {
|
||||
var post_id = jQuery(this).data('id');
|
||||
var ewww_nonce = jQuery(this).data('nonce');
|
||||
var ewww_manual_optimize_data = {
|
||||
action: 'ewww_manual_optimize',
|
||||
ewww_manual_nonce: ewww_nonce,
|
||||
ewww_force: 1,
|
||||
ewww_attachment_ID: post_id,
|
||||
};
|
||||
post_id = jQuery(this).closest('.ewww-media-status').data('id');
|
||||
jQuery('#ewww-media-status-' + post_id ).html( ewww_vars.optimizing );
|
||||
jQuery.post(ajaxurl, ewww_manual_optimize_data, function(response) {
|
||||
var ewww_manual_response = JSON.parse(response);
|
||||
if (ewww_manual_response.error) {
|
||||
jQuery('#ewww-media-status-' + post_id ).html( ewww_manual_response.error );
|
||||
} else if (ewww_manual_response.success) {
|
||||
jQuery('#ewww-media-status-' + post_id ).html( ewww_manual_response.success );
|
||||
}
|
||||
if (ewww_manual_response.basename) {
|
||||
var attachment_span = jQuery('#post-' + post_id + ' .column-title .filename .screen-reader-text').html();
|
||||
jQuery('#post-' + post_id + ' .column-title .filename').html('<span class="screen-reader-text">' + attachment_span + '</span>' + ewww_manual_response.basename);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
jQuery(document).on('click', '.ewww-manual-convert', function() {
|
||||
var post_id = jQuery(this).data('id');
|
||||
var ewww_nonce = jQuery(this).data('nonce');
|
||||
var ewww_manual_optimize_data = {
|
||||
action: 'ewww_manual_optimize',
|
||||
ewww_manual_nonce: ewww_nonce,
|
||||
ewww_force: 1,
|
||||
ewww_convert: 1,
|
||||
ewww_attachment_ID: post_id,
|
||||
};
|
||||
post_id = jQuery(this).closest('.ewww-media-status').data('id');
|
||||
jQuery('#ewww-media-status-' + post_id ).html( ewww_vars.optimizing );
|
||||
jQuery.post(ajaxurl, ewww_manual_optimize_data, function(response) {
|
||||
var ewww_manual_response = JSON.parse(response);
|
||||
if (ewww_manual_response.error) {
|
||||
jQuery('#ewww-media-status-' + post_id ).html( ewww_manual_response.error );
|
||||
} else if (ewww_manual_response.success) {
|
||||
jQuery('#ewww-media-status-' + post_id ).html( ewww_manual_response.success );
|
||||
}
|
||||
if (ewww_manual_response.basename) {
|
||||
var attachment_span = jQuery('#post-' + post_id + ' .column-title .filename .screen-reader-text').html();
|
||||
jQuery('#post-' + post_id + ' .column-title .filename').html('<span class="screen-reader-text">' + attachment_span + '</span>' + ewww_manual_response.basename);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
jQuery(document).on('click', '.ewww-manual-restore', function() {
|
||||
var post_id = jQuery(this).data('id');
|
||||
var ewww_nonce = jQuery(this).data('nonce');
|
||||
var ewww_manual_optimize_data = {
|
||||
action: 'ewww_manual_restore',
|
||||
ewww_manual_nonce: ewww_nonce,
|
||||
ewww_attachment_ID: post_id,
|
||||
};
|
||||
post_id = jQuery(this).closest('.ewww-media-status').data('id');
|
||||
jQuery('#ewww-media-status-' + post_id ).html( ewww_vars.restoring );
|
||||
jQuery.post(ajaxurl, ewww_manual_optimize_data, function(response) {
|
||||
var ewww_manual_response = JSON.parse(response);
|
||||
if (ewww_manual_response.error) {
|
||||
jQuery('#ewww-media-status-' + post_id ).html( ewww_manual_response.error );
|
||||
} else if (ewww_manual_response.success) {
|
||||
jQuery('#ewww-media-status-' + post_id ).html( ewww_manual_response.success );
|
||||
}
|
||||
if (ewww_manual_response.basename) {
|
||||
var attachment_span = jQuery('#post-' + post_id + ' .column-title .filename .screen-reader-text').html();
|
||||
jQuery('#post-' + post_id + ' .column-title .filename').html('<span class="screen-reader-text">' + attachment_span + '</span>' + ewww_manual_response.basename);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
jQuery(document).on('click', '.ewww-manual-image-restore', function() {
|
||||
var post_id = jQuery(this).data('id');
|
||||
var ewww_nonce = jQuery(this).data('nonce');
|
||||
var ewww_manual_optimize_data = {
|
||||
action: 'ewww_manual_image_restore',
|
||||
ewww_manual_nonce: ewww_nonce,
|
||||
ewww_attachment_ID: post_id,
|
||||
};
|
||||
post_id = jQuery(this).closest('.ewww-media-status').data('id');
|
||||
jQuery('#ewww-media-status-' + post_id ).html( ewww_vars.restoring );
|
||||
jQuery.post(ajaxurl, ewww_manual_optimize_data, function(response) {
|
||||
var ewww_manual_response = JSON.parse(response);
|
||||
if (ewww_manual_response.error) {
|
||||
jQuery('#ewww-media-status-' + post_id ).html( ewww_manual_response.error );
|
||||
} else if (ewww_manual_response.success) {
|
||||
jQuery('#ewww-media-status-' + post_id ).html( ewww_manual_response.success );
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
jQuery(document).on('click', '.ewww-show-debug-meta', function() {
|
||||
var post_id = jQuery(this).data('id');
|
||||
jQuery('#ewww-debug-meta-' + post_id).toggle();
|
||||
});
|
||||
jQuery(document).on('click', '#ewww-image-optimizer-media-listmode .notice-dismiss', function() {
|
||||
var ewww_dismiss_media_data = {
|
||||
action: 'ewww_dismiss_media_notice',
|
||||
};
|
||||
jQuery.post(ajaxurl, ewww_dismiss_media_data, function(response) {
|
||||
if (response) {
|
||||
console.log(response);
|
||||
}
|
||||
});
|
||||
});
|
@ -0,0 +1,39 @@
|
||||
jQuery(document).on( 'click', '.ewww-manual-optimize', function() {
|
||||
var post_id = jQuery(this).data('id');
|
||||
var ewww_nonce = jQuery(this).data('nonce');
|
||||
var ewww_manual_optimize_data = {
|
||||
action: 'ewww_ngg_manual',
|
||||
ewww_manual_nonce: ewww_nonce,
|
||||
ewww_force: 1,
|
||||
ewww_attachment_ID: post_id,
|
||||
};
|
||||
jQuery('#ewww-nextcellent-status-' + post_id ).html( ewww_vars.optimizing );
|
||||
jQuery.post(ajaxurl, ewww_manual_optimize_data, function(response) {
|
||||
var ewww_manual_response = JSON.parse(response);
|
||||
if (ewww_manual_response.error) {
|
||||
jQuery('#ewww-nextcellent-status-' + post_id ).html( ewww_manual_response.error );
|
||||
} else if (ewww_manual_response.success) {
|
||||
jQuery('#ewww-nextcellent-status-' + post_id ).html( ewww_manual_response.success );
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
jQuery(document).on( 'click', '.ewww-manual-cloud-restore', function() {
|
||||
var post_id = jQuery(this).data('id');
|
||||
var ewww_nonce = jQuery(this).data('nonce');
|
||||
var ewww_manual_optimize_data = {
|
||||
action: 'ewww_ngg_cloud_restore',
|
||||
ewww_manual_nonce: ewww_nonce,
|
||||
ewww_attachment_ID: post_id,
|
||||
};
|
||||
jQuery('#ewww-nextcellent-status-' + post_id ).html( ewww_vars.restoring );
|
||||
jQuery.post(ajaxurl, ewww_manual_optimize_data, function(response) {
|
||||
var ewww_manual_response = JSON.parse(response);
|
||||
if (ewww_manual_response.error) {
|
||||
jQuery('#ewww-nextcellent-status-' + post_id ).html( ewww_manual_response.error );
|
||||
} else if (ewww_manual_response.success) {
|
||||
jQuery('#ewww-nextcellent-status-' + post_id ).html( ewww_manual_response.success );
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
43
wp-content/plugins/ewww-image-optimizer/includes/nextgen.js
Normal file
43
wp-content/plugins/ewww-image-optimizer/includes/nextgen.js
Normal file
@ -0,0 +1,43 @@
|
||||
jQuery(document).on( 'click', '.ewww-manual-optimize', function() {
|
||||
var post_id = jQuery(this).data('id');
|
||||
var ewww_nonce = jQuery(this).data('nonce');
|
||||
var ewww_manual_optimize_data = {
|
||||
action: 'ewww_ngg_manual',
|
||||
ewww_manual_nonce: ewww_nonce,
|
||||
ewww_force: 1,
|
||||
ewww_attachment_ID: post_id,
|
||||
};
|
||||
jQuery('#ewww-nextgen-status-' + post_id ).html( ewww_vars.optimizing );
|
||||
jQuery.post(ajaxurl, ewww_manual_optimize_data, function(response) {
|
||||
var ewww_manual_response = JSON.parse(response);
|
||||
if (ewww_manual_response.error) {
|
||||
jQuery('#ewww-nextgen-status-' + post_id ).html( ewww_manual_response.error );
|
||||
} else if (ewww_manual_response.success) {
|
||||
jQuery('#ewww-nextgen-status-' + post_id ).html( ewww_manual_response.success );
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
jQuery(document).on( 'click', '.ewww-manual-image-restore', function() {
|
||||
var post_id = jQuery(this).data('id');
|
||||
var ewww_nonce = jQuery(this).data('nonce');
|
||||
var ewww_manual_optimize_data = {
|
||||
action: 'ewww_ngg_image_restore',
|
||||
ewww_manual_nonce: ewww_nonce,
|
||||
ewww_attachment_ID: post_id,
|
||||
};
|
||||
jQuery('#ewww-nextgen-status-' + post_id ).html( ewww_vars.restoring );
|
||||
jQuery.post(ajaxurl, ewww_manual_optimize_data, function(response) {
|
||||
var ewww_manual_response = JSON.parse(response);
|
||||
if (ewww_manual_response.error) {
|
||||
jQuery('#ewww-nextgen-status-' + post_id ).html( ewww_manual_response.error );
|
||||
} else if (ewww_manual_response.success) {
|
||||
jQuery('#ewww-nextgen-status-' + post_id ).html( ewww_manual_response.success );
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
jQuery(document).on('click', '.ewww-show-debug-meta', function() {
|
||||
var post_id = jQuery(this).data('id');
|
||||
jQuery('#ewww-debug-meta-' + post_id).toggle();
|
||||
});
|
@ -0,0 +1,66 @@
|
||||
window.onload = function() {
|
||||
checkImageSizes();
|
||||
var adminBarButton = document.getElementById('wp-admin-bar-resize-detection');
|
||||
if (adminBarButton) {
|
||||
adminBarButton.onclick = function() {
|
||||
adminBarButton.classList.toggle('ewww-fade');
|
||||
clearScaledImages();
|
||||
checkImageSizes();
|
||||
setTimeout(function() {
|
||||
adminBarButton.classList.toggle('ewww-fade');
|
||||
}, 500);
|
||||
};
|
||||
}
|
||||
}
|
||||
function checkImageSizes() {
|
||||
// Find images which have width or height greater than their natural
|
||||
// width or height, and give them a stark and ugly marker, as well
|
||||
// as a useful title.
|
||||
var imgs = document.getElementsByTagName("img");
|
||||
for (i = 0; i < imgs.length; i++) {
|
||||
imgs[i].classList.remove('scaled-image');
|
||||
checkImageScale(imgs[i]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function checkImageScale(img) {
|
||||
if (!img.src) {
|
||||
return;
|
||||
}
|
||||
if ('string' == typeof img.src && img.src.search(/\.svg/) > -1) {
|
||||
return;
|
||||
}
|
||||
if ('string' == typeof img.src && img.src.search(/data:image/) > -1) {
|
||||
return;
|
||||
}
|
||||
console.log('checking size of: ' + img.src);
|
||||
if (img.naturalWidth) {
|
||||
if (img.naturalWidth > 25 && img.naturalHeight > 25 && img.clientWidth > 25 && img.clientHeight > 25) {
|
||||
// For each image with a natural width which isn't
|
||||
// a 1x1 image, check its size.
|
||||
var dPR = (window.devicePixelRatio || 1);
|
||||
var wrongWidth = (img.clientWidth * 1.5 * dPR < img.naturalWidth);
|
||||
var wrongHeight = (img.clientHeight * 1.5 * dPR < img.naturalHeight);
|
||||
if (wrongWidth || wrongHeight) {
|
||||
img.classList.add('scaled-image');
|
||||
img.title = "Forced to wrong size: " +
|
||||
img.clientWidth + "x" + img.clientHeight + ", natural is " +
|
||||
img.naturalWidth + "x" + img.naturalHeight + "!";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function clearScaledImages() {
|
||||
var scaledImages = document.querySelectorAll('img.scaled-image');
|
||||
for (var i = 0, len = scaledImages.length; i < len; i++){
|
||||
scaledImages[i].classList.remove('scaled-image');
|
||||
}
|
||||
}
|
||||
document.addEventListener('lazyloaded', function(e){
|
||||
e.target.classList.remove('scaled-image');
|
||||
var current_title = e.target.title;
|
||||
if (0 === current_title.search('Forced to wrong size')) {
|
||||
e.target.title = '';
|
||||
}
|
||||
checkImageScale(e.target);
|
||||
});
|
1
wp-content/plugins/ewww-image-optimizer/includes/resize-detection.min.js
vendored
Normal file
1
wp-content/plugins/ewww-image-optimizer/includes/resize-detection.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
function checkImageSizes(){var e=document.getElementsByTagName("img");for(i=0;i<e.length;i++)e[i].classList.remove("scaled-image"),checkImageScale(e[i]);return!1}function checkImageScale(e){var t,a;e.src&&("string"==typeof e.src&&-1<e.src.search(/\.svg/)||"string"==typeof e.src&&-1<e.src.search(/data:image/)||e.naturalWidth&&25<e.naturalWidth&&25<e.naturalHeight&&25<e.clientWidth&&25<e.clientHeight&&(a=window.devicePixelRatio||1,t=1.5*e.clientWidth*a<e.naturalWidth,a=1.5*e.clientHeight*a<e.naturalHeight,(t||a)&&(e.classList.add("scaled-image"),e.title="Forced to wrong size: "+e.clientWidth+"x"+e.clientHeight+", natural is "+e.naturalWidth+"x"+e.naturalHeight+"!")))}function clearScaledImages(){for(var e=document.querySelectorAll("img.scaled-image"),t=0,a=e.length;t<a;t++)e[t].classList.remove("scaled-image")}window.onload=function(){checkImageSizes();var e=document.getElementById("wp-admin-bar-resize-detection");e&&(e.onclick=function(){e.classList.toggle("ewww-fade"),clearScaledImages(),checkImageSizes(),setTimeout(function(){e.classList.toggle("ewww-fade")},500)})},document.addEventListener("lazyloaded",function(e){e.target.classList.remove("scaled-image"),0===e.target.title.search("Forced to wrong size")&&(e.target.title=""),checkImageScale(e.target)});
|
55
wp-content/plugins/ewww-image-optimizer/includes/webp.js
Normal file
55
wp-content/plugins/ewww-image-optimizer/includes/webp.js
Normal file
@ -0,0 +1,55 @@
|
||||
jQuery(document).ready(function($) {
|
||||
var ewww_error_counter = 30;
|
||||
var sleep_action = 'ewww_sleep';
|
||||
var init_action = 'webp_init';
|
||||
var loop_action = 'webp_loop';
|
||||
var cleanup_action = 'webp_cleanup';
|
||||
var init_data = {
|
||||
action: init_action,
|
||||
ewww_wpnonce: ewww_vars.ewww_wpnonce,
|
||||
};
|
||||
$('#webp-start').submit(function() {
|
||||
startMigrate();
|
||||
return false;
|
||||
});
|
||||
function startMigrate () {
|
||||
$('.webp-form').hide();
|
||||
$.post(ajaxurl, init_data, function(response) {
|
||||
$('#webp-loading').html(response);
|
||||
processLoop();
|
||||
});
|
||||
}
|
||||
function processLoop () {
|
||||
var loop_data = {
|
||||
action: loop_action,
|
||||
ewww_wpnonce: ewww_vars.ewww_wpnonce,
|
||||
};
|
||||
var jqxhr = $.post(ajaxurl, loop_data, function(response) {
|
||||
if (response) {
|
||||
$('#webp-status').append( response );
|
||||
$('#webp-loading').hide();
|
||||
processLoop();
|
||||
} else {
|
||||
var cleanup_data = {
|
||||
action: cleanup_action,
|
||||
ewww_wpnonce: ewww_vars.ewww_wpnonce,
|
||||
};
|
||||
$.post(ajaxurl, cleanup_data, function(response) {
|
||||
$('#webp-loading').hide();
|
||||
$('#webp-status').append(response);
|
||||
});
|
||||
}
|
||||
})
|
||||
.fail(function() {
|
||||
if (ewww_error_counter == 0) {
|
||||
$('#webp-loading').html('<p style="color: red"><b>Operation Interrupted</b></p>');
|
||||
} else {
|
||||
$('#webp-loading').html('<p style="color: red"><b>Temporary failure, retrying for ' + ewww_error_counter + ' more seconds.</b></p>');
|
||||
ewww_error_counter--;
|
||||
setTimeout(function() {
|
||||
processLoop();
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user