initial commit
This commit is contained in:
199
hamrokhaanpaan/wp-content/plugins/video-thumbnails/js/bulk.js
Normal file
199
hamrokhaanpaan/wp-content/plugins/video-thumbnails/js/bulk.js
Normal file
@ -0,0 +1,199 @@
|
||||
var video_thumbnails_bulk_scanner;
|
||||
|
||||
jQuery(function ($) {
|
||||
|
||||
function VideoThumbnailsBulkScanner( posts ) {
|
||||
this.currentItem = 0;
|
||||
this.posts = posts;
|
||||
this.paused = false;
|
||||
this.newThumbnails = 0;
|
||||
this.existingThumbnails = 0;
|
||||
this.delay = 1000;
|
||||
this.delayTimer = false;
|
||||
this.logList = $('#vt-bulk-scan-results .log');
|
||||
this.progressBar = $('#vt-bulk-scan-results .progress-bar');
|
||||
this.language = video_thumbnails_bulk_language;
|
||||
}
|
||||
|
||||
VideoThumbnailsBulkScanner.prototype.log = function(text) {
|
||||
$('<li>'+text+'</li>').prependTo(this.logList).hide().slideDown(200);
|
||||
console.log(text);
|
||||
};
|
||||
|
||||
VideoThumbnailsBulkScanner.prototype.disableSubmit = function(text) {
|
||||
$('#video-thumbnails-bulk-scan-options input[type="submit"]').attr('disabled','disabled');
|
||||
};
|
||||
|
||||
VideoThumbnailsBulkScanner.prototype.enableSubmit = function(text) {
|
||||
$('#video-thumbnails-bulk-scan-options input[type="submit"]').removeAttr('disabled');
|
||||
};
|
||||
|
||||
VideoThumbnailsBulkScanner.prototype.findPosts = function(text) {
|
||||
var data = {
|
||||
action: 'video_thumbnails_bulk_posts_query',
|
||||
params: $('#video-thumbnails-bulk-scan-options').serialize()
|
||||
};
|
||||
var self = this;
|
||||
this.disableSubmit();
|
||||
$('#queue-count').text(this.language.working);
|
||||
$.post(ajaxurl, data, function(response) {
|
||||
self.posts = $.parseJSON( response );
|
||||
if ( self.posts.length == 1 ) {
|
||||
queueText = self.language.queue_singular;
|
||||
} else {
|
||||
queueText = self.language.queue_plural.replace('%d',self.posts.length);
|
||||
}
|
||||
$('#queue-count').text(queueText);
|
||||
if ( self.posts.length > 0 ) {
|
||||
self.enableSubmit();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
VideoThumbnailsBulkScanner.prototype.startScan = function() {
|
||||
this.disableSubmit();
|
||||
this.paused = false;
|
||||
if ( this.currentItem == 0 ) {
|
||||
this.log( this.language.started );
|
||||
this.progressBar.show();
|
||||
this.resetProgressBar();
|
||||
$('#video-thumbnails-bulk-scan-options').slideUp();
|
||||
} else {
|
||||
this.log( this.language.resumed );
|
||||
}
|
||||
this.scanCurrentItem();
|
||||
};
|
||||
|
||||
VideoThumbnailsBulkScanner.prototype.pauseScan = function() {
|
||||
this.clearSchedule();
|
||||
this.paused = true;
|
||||
this.log( this.language.paused );
|
||||
};
|
||||
|
||||
VideoThumbnailsBulkScanner.prototype.toggleScan = function() {
|
||||
if ( this.paused ) {
|
||||
this.startScan();
|
||||
} else {
|
||||
this.pauseScan();
|
||||
}
|
||||
};
|
||||
|
||||
VideoThumbnailsBulkScanner.prototype.scanCompleted = function() {
|
||||
if ( this.posts.length == 1 ) {
|
||||
message = this.language.done + ' ' + this.language.final_count_singular;
|
||||
} else {
|
||||
message = this.language.done + ' ' + this.language.final_count_plural.replace('%d',this.posts.length);
|
||||
}
|
||||
this.log( message );
|
||||
};
|
||||
|
||||
VideoThumbnailsBulkScanner.prototype.resetProgressBar = function() {
|
||||
$('#vt-bulk-scan-results .percentage').html('0%');
|
||||
this.progressBar
|
||||
.addClass('disable-animation')
|
||||
.css('width','0')
|
||||
this.progressBar.height();
|
||||
this.progressBar.removeClass('disable-animation');
|
||||
};
|
||||
|
||||
VideoThumbnailsBulkScanner.prototype.updateProgressBar = function() {
|
||||
console.log( percentage = ( this.currentItem + 1 ) / this.posts.length );
|
||||
if ( percentage == 1 ) {
|
||||
progressText = this.language.done;
|
||||
this.scanCompleted();
|
||||
} else {
|
||||
progressText = Math.round(percentage*100)+'%';
|
||||
}
|
||||
$('#vt-bulk-scan-results .percentage').html(progressText);
|
||||
this.progressBar.css('width',(percentage*100)+'%');
|
||||
};
|
||||
|
||||
VideoThumbnailsBulkScanner.prototype.updateCounter = function() {
|
||||
$('#vt-bulk-scan-results .stats .scanned').html( (this.currentItem+1) + '/' + this.posts.length );
|
||||
$('#vt-bulk-scan-results .stats .found-new').html( this.newThumbnails );
|
||||
$('#vt-bulk-scan-results .stats .found-existing').html( this.existingThumbnails );
|
||||
}
|
||||
|
||||
VideoThumbnailsBulkScanner.prototype.updateStats = function() {
|
||||
this.updateProgressBar();
|
||||
this.updateCounter();
|
||||
}
|
||||
|
||||
VideoThumbnailsBulkScanner.prototype.scheduleNextItem = function() {
|
||||
if ( ( this.currentItem + 1 ) < this.posts.length ) {
|
||||
var self = this;
|
||||
self.currentItem++;
|
||||
this.delayTimer = setTimeout(function() {
|
||||
self.scanCurrentItem();
|
||||
}, this.delay);
|
||||
}
|
||||
}
|
||||
|
||||
VideoThumbnailsBulkScanner.prototype.clearSchedule = function() {
|
||||
clearTimeout( this.delayTimer );
|
||||
}
|
||||
|
||||
VideoThumbnailsBulkScanner.prototype.scanCurrentItem = function() {
|
||||
|
||||
if ( this.paused ) return false;
|
||||
|
||||
if ( this.currentItem < this.posts.length ) {
|
||||
|
||||
this.log( '[ID: ' + this.posts[this.currentItem] + '] ' + this.language.scanning_of.replace('%1$s',this.currentItem+1).replace('%2$s',this.posts.length) );
|
||||
|
||||
var data = {
|
||||
action: 'video_thumbnails_get_thumbnail_for_post',
|
||||
post_id: this.posts[this.currentItem]
|
||||
};
|
||||
var self = this;
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
type: "POST",
|
||||
data: data,
|
||||
success: function(response) {
|
||||
var result = $.parseJSON( response );
|
||||
if ( result.length == 0 ) {
|
||||
self.log( '[ID: ' + self.posts[self.currentItem] + '] ' + self.language.no_thumbnail );
|
||||
} else {
|
||||
if ( result.type == 'new' ) {
|
||||
resultText = self.language.new_thumbnail;
|
||||
} else {
|
||||
resultText = self.language.existing_thumbnail;
|
||||
}
|
||||
self.log( '[ID: ' + self.posts[self.currentItem] + '] ' + resultText + ' ' + result.url );
|
||||
if ( result.type == 'new' ) {
|
||||
self.newThumbnails++;
|
||||
} else {
|
||||
self.existingThumbnails++;
|
||||
}
|
||||
}
|
||||
self.updateStats();
|
||||
self.scheduleNextItem();
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
self.log( '[ID: ' + self.posts[self.currentItem] + '] ' + self.language.error + ' ' + errorThrown );
|
||||
self.updateStats();
|
||||
self.scheduleNextItem();
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
this.updateStats();
|
||||
this.currentItem = 0;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
video_thumbnails_bulk_scanner = new VideoThumbnailsBulkScanner();
|
||||
video_thumbnails_bulk_scanner.findPosts();
|
||||
|
||||
$('#video-thumbnails-bulk-scan-options').on('change',function(e){
|
||||
video_thumbnails_bulk_scanner.findPosts();
|
||||
});
|
||||
|
||||
$('#video-thumbnails-bulk-scan-options').on('submit',function(e){
|
||||
e.preventDefault();
|
||||
video_thumbnails_bulk_scanner.startScan();
|
||||
});
|
||||
|
||||
});
|
@ -0,0 +1,201 @@
|
||||
jQuery(function ($) {
|
||||
|
||||
/**
|
||||
* Custom field detection
|
||||
*/
|
||||
$('#vt_detect_custom_field').on('click',function(e) {
|
||||
e.preventDefault();
|
||||
var data = {
|
||||
action: 'video_thumbnail_custom_field_detection'
|
||||
};
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
data: data,
|
||||
success: function(response){
|
||||
if (response) {
|
||||
$('#custom_field').val(response);
|
||||
} else {
|
||||
alert(video_thumbnails_settings_language.detection_failed);
|
||||
}
|
||||
},
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown) {
|
||||
alert(video_thumbnails_settings_language.ajax_error + ' ' + XMLHttpRequest.status + ' ' + XMLHttpRequest.statusText);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Debugging tests
|
||||
*/
|
||||
$('a.toggle-video-thumbnails-test-content').on('click',function(e) {
|
||||
e.preventDefault();
|
||||
$(this).closest('.video-thumbnails-test').toggleClass('closed');
|
||||
});
|
||||
|
||||
function enable_video_thumbnails_tests() {
|
||||
$('.video-thumbnails-test-button').attr('disabled',false);
|
||||
}
|
||||
|
||||
function disable_video_thumbnails_tests() {
|
||||
$('.video-thumbnails-test-button').attr('disabled',true);
|
||||
}
|
||||
|
||||
/* Provider testing */
|
||||
|
||||
function test_single_provider(provider_slug) {
|
||||
disable_video_thumbnails_tests();
|
||||
$('#'+provider_slug+'-provider-test').addClass('test-working');
|
||||
$('#'+provider_slug+'-provider-test .retest-video-provider').val(video_thumbnails_settings_language.working);
|
||||
var data = {
|
||||
action: 'video_thumbnail_provider_test',
|
||||
provider_slug: provider_slug
|
||||
};
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
data: data,
|
||||
success: function(response){
|
||||
$('#'+provider_slug+'-provider-test .test-results').html(response);
|
||||
$('#'+provider_slug+'-provider-test .retest-video-provider').val(video_thumbnails_settings_language.retest);
|
||||
$('#'+provider_slug+'-provider-test').removeClass('test-working');
|
||||
done_testing_single_provider();
|
||||
},
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown) {
|
||||
$('#'+provider_slug+'-provider-test .test-results').html('<p>' + video_thumbnails_settings_language.ajax_error + ' ' + XMLHttpRequest.status + ' ' + XMLHttpRequest.statusText + '</p>');
|
||||
$('#'+provider_slug+'-provider-test .retest-video-provider').val(video_thumbnails_settings_language.retest);
|
||||
$('#'+provider_slug+'-provider-test').removeClass('test-working');
|
||||
done_testing_single_provider();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var provider_index = 0;
|
||||
var testing_all_providers = false;
|
||||
|
||||
function done_testing_single_provider() {
|
||||
// If we aren't testing providers, don't do anything
|
||||
if (testing_all_providers==false) {
|
||||
enable_video_thumbnails_tests();
|
||||
}
|
||||
provider_index = provider_index + 1;
|
||||
if (provider_index>=video_thumbnails_provider_slugs.provider_slugs.length) {
|
||||
testing_all_providers = false;
|
||||
enable_video_thumbnails_tests();
|
||||
return;
|
||||
} else {
|
||||
test_single_provider(video_thumbnails_provider_slugs.provider_slugs[provider_index]);
|
||||
}
|
||||
}
|
||||
|
||||
$('#test-all-video-thumbnail-providers').on('click',function(e) {
|
||||
e.preventDefault();
|
||||
$('#provider-test-results').removeClass('hidden');
|
||||
$(this).parent().remove();
|
||||
testing_all_providers = true;
|
||||
test_single_provider(video_thumbnails_provider_slugs.provider_slugs[provider_index]);
|
||||
});
|
||||
|
||||
$('.retest-video-provider').on('click',function(e) {
|
||||
e.preventDefault();
|
||||
test_single_provider( $(this).data('provider-slug') );
|
||||
});
|
||||
|
||||
/* Markup detection testing */
|
||||
$('#test-markup-detection').on('click',function(e) {
|
||||
disable_video_thumbnails_tests();
|
||||
e.preventDefault();
|
||||
var data = {
|
||||
action: 'video_thumbnail_markup_detection_test',
|
||||
markup: $('#markup-input').val()
|
||||
};
|
||||
document.getElementById( 'markup-test-result' ).innerHTML = '<p>' + video_thumbnails_settings_language.working + '</p>';
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
data: data,
|
||||
success: function(response){
|
||||
document.getElementById( 'markup-test-result' ).innerHTML = response;
|
||||
enable_video_thumbnails_tests();
|
||||
},
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown) {
|
||||
document.getElementById( 'markup-test-result' ).innerHTML = '<p>' + video_thumbnails_settings_language.ajax_error + ' ' + XMLHttpRequest.status + ' ' + XMLHttpRequest.statusText + '</p>';
|
||||
enable_video_thumbnails_tests();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/* Media download testing */
|
||||
$('#test-video-thumbnail-saving-media').on('click',function(e) {
|
||||
disable_video_thumbnails_tests();
|
||||
$('#media-test-result').html( '<p>' + video_thumbnails_settings_language.working + '</p>' );
|
||||
e.preventDefault();
|
||||
var data = {
|
||||
action: 'video_thumbnail_image_download_test'
|
||||
};
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
data: data,
|
||||
success: function(response){
|
||||
$('#media-test-result').html(response);
|
||||
enable_video_thumbnails_tests();
|
||||
},
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown) {
|
||||
$('#media-test-result').html('<p>' + video_thumbnails_settings_language.ajax_error + ' ' + XMLHttpRequest.status + ' ' + XMLHttpRequest.statusText + '</p>');
|
||||
enable_video_thumbnails_tests();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#delete-video-thumbnail-test-images').on('click',function(e) {
|
||||
disable_video_thumbnails_tests();
|
||||
$('#media-test-result').html( '<p>' + video_thumbnails_settings_language.working + '</p>' );
|
||||
e.preventDefault();
|
||||
var data = {
|
||||
action: 'video_thumbnail_delete_test_images'
|
||||
};
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
data: data,
|
||||
success: function(response){
|
||||
$('#media-test-result').html(response);
|
||||
enable_video_thumbnails_tests();
|
||||
},
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown) {
|
||||
$('#media-test-result').html('<p>' + video_thumbnails_settings_language.ajax_error + ' ' + XMLHttpRequest.status + ' ' + XMLHttpRequest.statusText + '</p>');
|
||||
enable_video_thumbnails_tests();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Clear all video thumbnails
|
||||
*/
|
||||
function clear_all_video_thumbnails( nonce ) {
|
||||
var confimation_result = confirm(video_thumbnails_settings_language.clear_all_confirmation);
|
||||
if (confimation_result){
|
||||
var data = {
|
||||
action: 'clear_all_video_thumbnails',
|
||||
nonce: nonce
|
||||
};
|
||||
document.getElementById( 'clear-all-video-thumbnails-result' ).innerHTML = '<p>' + video_thumbnails_settings_language.working + '</p>';
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
data: data,
|
||||
success: function(response){
|
||||
document.getElementById( 'clear-all-video-thumbnails-result' ).innerHTML = response;
|
||||
},
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown) {
|
||||
document.getElementById( 'clear-all-video-thumbnails-result' ).innerHTML = '<p>' + video_thumbnails_settings_language.ajax_error + ' ' + XMLHttpRequest.status + ' ' + XMLHttpRequest.statusText + '</p>';
|
||||
}
|
||||
});
|
||||
}
|
||||
else{
|
||||
//
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user