From a3f37e8c23fcf30d16b995ed877de8c794eb90e5 Mon Sep 17 00:00:00 2001 From: Andy Meerwaldt Date: Thu, 30 Jul 2015 13:13:58 +0200 Subject: [PATCH] Making object from the recalculate scores JS. --- js/wp-seo-admin.js | 135 ++++++++++++++++++++++------------------- js/wp-seo-admin.min.js | 2 +- 2 files changed, 72 insertions(+), 65 deletions(-) diff --git a/js/wp-seo-admin.js b/js/wp-seo-admin.js index 2a590ce169d..0bdd475f526 100644 --- a/js/wp-seo-admin.js +++ b/js/wp-seo-admin.js @@ -255,81 +255,88 @@ function wpseo_recalculate_scores(current_page) { progress_bar.progressbar( { 'value' : 0 } ); /** - * Updates the progressbar and the sum of the posts below it. - * - * @param total_posts + * Objects to do the recalculate stuff + * @type {{update_progressbar: Function, calculate_score: Function, parse_response: Function, get_posts_to_recalculate: Function}} */ - var update_progressbar = function( total_posts ) { - var current_value = count_element.text(); - var new_value = parseInt( current_value ) + total_posts; - var new_width = new_value * (100 / total_count); + var wpseo_recalculate = { - progress_bar.progressbar( 'value', new_width ); + /** + * Updates the progressbar and the sum of the posts below it. + * + * @param total_posts + */ + update_progressbar : function( total_posts ) { + var current_value = count_element.text(); + var new_value = parseInt( current_value ) + total_posts; + var new_width = new_value * (100 / total_count); - count_element.html( new_value ); - }; + progress_bar.progressbar( 'value', new_width ); - /** - * Passing the post to the analyzer to calculates its core - * - * @param post - */ - var calculate_score = function( post ) { - var tmpAnalyzer = new YoastSEO_Analyzer( post ); - tmpAnalyzer.runQueue(); - var score = tmpAnalyzer.analyzeScorer.__totalScore; - - // Doing request to update the score - jQuery.post( - ajaxurl, - { - action: 'wpseo_update_score', - nonce : jQuery( '#wpseo_recalculate_nonce' ).val(), - post_id : post.post_id, - score : score - } - ); - }; + count_element.html( new_value ); + }, - /** - * Parse the response given by request in get_posts_to_recalculate. - * - * @param response - */ - var parse_response = function( response ) { - if (response !== '') { - if ( response.total_posts !== undefined ) { - for( var i = 0; i < response.total_posts; i++) { - calculate_score( resp.posts[i] ); + /** + * Passing the post to the analyzer to calculates its core + * + * @param post + */ + calculate_score : function( post ) { + var tmpAnalyzer = new YoastSEO_Analyzer( post ); + tmpAnalyzer.runQueue(); + var score = tmpAnalyzer.analyzeScorer.__totalScore; + + // Doing request to update the score + jQuery.post( + ajaxurl, + { + action: 'wpseo_update_score', + nonce : jQuery( '#wpseo_recalculate_nonce' ).val(), + post_id : post.post_id, + score : score + } + ); + }, + + /** + * Parse the response given by request in get_posts_to_recalculate. + * + * @param response + */ + parse_response : function( response ) { + if (response !== '') { + if ( response.total_posts !== undefined ) { + for( var i = 0; i < response.total_posts; i++) { + wpseo_recalculate.calculate_score( resp.posts[i] ); + } + + wpseo_recalculate.update_progressbar( response.total_posts ); } - update_progressbar( response.total_posts ); + if ( response.next_page !== undefined ) { + wpseo_recalculate.get_posts_to_recalculate( response.next_page ); + } } + }, - if ( response.next_page !== undefined ) { - get_posts_to_recalculate( response.next_page ); - } + /** + * Getting the posts which has to be recalculated. + * + * @param current_page + */ + get_posts_to_recalculate : function ( current_page ) { + jQuery.post( + ajaxurl, + { + action: 'wpseo_recalculate_scores', + nonce : jQuery( '#wpseo_recalculate_nonce' ).val(), + paged : current_page + }, + wpseo_recalculate.parse_response, + 'json' + ); } }; - /** - * Getting the posts which has to be recalculated. - * - * @param current_page - */ - var get_posts_to_recalculate = function ( current_page ) { - jQuery.post( - ajaxurl, - { - action: 'wpseo_recalculate_scores', - nonce : jQuery( '#wpseo_recalculate_nonce' ).val(), - paged : current_page - }, - parse_response, - 'json' - ); - }; - - get_posts_to_recalculate( current_page ); + wwpseo_recalculate.get_posts_to_recalculate( current_page ); } diff --git a/js/wp-seo-admin.min.js b/js/wp-seo-admin.min.js index fcf4502b592..f7dfad059a7 100644 --- a/js/wp-seo-admin.min.js +++ b/js/wp-seo-admin.min.js @@ -1 +1 @@ -"use strict";function wpseoDetectWrongVariables(a){var b=!1,c="",d=[],e=["userid","name","user_description"],f=["date"],g=["title","parent_title","excerpt","excerpt_only","caption","focuskw","pt_single","pt_plural","modified","id"],h=["term404","searchphrase"],i=["term_title","term_description"],j=["category","category_description","tag","tag_description"];a.hasClass("posttype-template")?d=d.concat(h,i):a.hasClass("homepage-template")?d=d.concat(e,f,g,h,i,j):a.hasClass("taxonomy-template")?d=d.concat(e,f,g,h):a.hasClass("author-template")?d=d.concat(g,f,h,i,j):a.hasClass("date-template")?d=d.concat(e,g,h,i,j):a.hasClass("search-template")?d=d.concat(e,f,g,i,j,["term404"]):a.hasClass("error404-template")&&(d=d.concat(e,f,g,i,j,["searchphrase"])),jQuery.each(d,function(d,e){if(c=a.attr("id")+"-"+e+"-warning",-1!==a.val().search("%%"+e+"%%")){a.addClass("wpseo_variable_warning");var f=wpseoAdminL10n.variable_warning.replace("%s","%%"+e+"%%");jQuery("#"+c).length?jQuery("#"+c).html(f):a.after('
'+f+"
"),b=!0}else jQuery("#"+c).length&&jQuery("#"+c).remove()}),b===!1&&a.removeClass("wpseo_variable_warning")}function setWPOption(a,b,c,d){jQuery.post(ajaxurl,{action:"wpseo_set_option",option:a,newval:b,_wpnonce:d},function(a){a&&jQuery("#"+c).hide()})}function wpseoKillBlockingFiles(a){jQuery.post(ajaxurl,{action:"wpseo_kill_blocking_files",_ajax_nonce:a},function(a){"success"===a?jQuery("#blocking_files").hide():jQuery("#block_files").html(a)})}function wpseoCopyHomeMeta(){jQuery("#og_frontpage_desc").val(jQuery("#meta_description").val())}function wpseoSetTabHash(){var a=jQuery("#wpseo-conf");if(a.length){var b=a.attr("action").split("#")[0];a.attr("action",b+window.location.hash)}}function wpseo_add_fb_admin(){var a=jQuery("#TB_ajaxContent");jQuery.post(ajaxurl,{_wpnonce:a.find("input[name=fb_admin_nonce]").val(),admin_name:a.find("input[name=fb_admin_name]").val(),admin_id:a.find("input[name=fb_admin_id]").val(),action:"wpseo_add_fb_admin"},function(b){var c=jQuery.parseJSON(b);switch(a.find("p.notice").remove(),c.success){case 1:a.find("input[type=text]").val(""),jQuery("#user_admin").append(c.html),jQuery("#connected_fb_admins").show(),tb_remove();break;case 0:jQuery(c.html).insertAfter(a.find("h3"))}})}function wpseo_recalculate_scores(a){var b=parseInt(jQuery("#wpseo_count_total").text()),c=jQuery("#wpseo_count"),d=jQuery("#wpseo_progressbar");c.text(0),d.progressbar({value:0});var e=function(a){var e=c.text(),f=parseInt(e)+a,g=f*(100/b);d.progressbar("value",g),c.html(f)},f=function(a){var b=new YoastSEO_Analyzer(a);b.runQueue();var c=b.analyzeScorer.__totalScore;jQuery.post(ajaxurl,{action:"wpseo_update_score",nonce:jQuery("#wpseo_recalculate_nonce").val(),post_id:a.post_id,score:c})},g=function(a){if(""!==a){if(void 0!==a.total_posts){for(var b=0;b
'+f+""),b=!0}else jQuery("#"+c).length&&jQuery("#"+c).remove()}),b===!1&&a.removeClass("wpseo_variable_warning")}function setWPOption(a,b,c,d){jQuery.post(ajaxurl,{action:"wpseo_set_option",option:a,newval:b,_wpnonce:d},function(a){a&&jQuery("#"+c).hide()})}function wpseoKillBlockingFiles(a){jQuery.post(ajaxurl,{action:"wpseo_kill_blocking_files",_ajax_nonce:a},function(a){"success"===a?jQuery("#blocking_files").hide():jQuery("#block_files").html(a)})}function wpseoCopyHomeMeta(){jQuery("#og_frontpage_desc").val(jQuery("#meta_description").val())}function wpseoSetTabHash(){var a=jQuery("#wpseo-conf");if(a.length){var b=a.attr("action").split("#")[0];a.attr("action",b+window.location.hash)}}function wpseo_add_fb_admin(){var a=jQuery("#TB_ajaxContent");jQuery.post(ajaxurl,{_wpnonce:a.find("input[name=fb_admin_nonce]").val(),admin_name:a.find("input[name=fb_admin_name]").val(),admin_id:a.find("input[name=fb_admin_id]").val(),action:"wpseo_add_fb_admin"},function(b){var c=jQuery.parseJSON(b);switch(a.find("p.notice").remove(),c.success){case 1:a.find("input[type=text]").val(""),jQuery("#user_admin").append(c.html),jQuery("#connected_fb_admins").show(),tb_remove();break;case 0:jQuery(c.html).insertAfter(a.find("h3"))}})}function wpseo_recalculate_scores(a){var b=(parseInt(jQuery("#wpseo_count_total").text()),jQuery("#wpseo_count")),c=jQuery("#wpseo_progressbar");b.text(0),c.progressbar({value:0});wwpseo_recalculate.get_posts_to_recalculate(a)}jQuery(document).ready(function(){jQuery(".screen-meta-toggle a").click(function(){jQuery("#sidebar-container").toggle()}),jQuery("#enablexmlsitemap").change(function(){jQuery("#sitemapinfo").toggle(jQuery(this).is(":checked"))}).change(),jQuery("#breadcrumbs-enable").change(function(){jQuery("#breadcrumbsinfo").toggle(jQuery(this).is(":checked"))}).change(),jQuery("#disable_author_sitemap").change(function(){jQuery("#xml_user_block").toggle(!jQuery(this).is(":checked"))}).change(),jQuery("#cleanpermalinks").change(function(){jQuery("#cleanpermalinksdiv").toggle(jQuery(this).is(":checked"))}).change(),jQuery("#wpseo-tabs").find("a").click(function(){jQuery("#wpseo-tabs").find("a").removeClass("nav-tab-active"),jQuery(".wpseotab").removeClass("active");var a=jQuery(this).attr("id").replace("-tab","");jQuery("#"+a).addClass("active"),jQuery(this).addClass("nav-tab-active")}),jQuery("#company_or_person").change(function(){var a=jQuery(this).val();"company"===a?(jQuery("#knowledge-graph-company").show(),jQuery("#knowledge-graph-person").hide()):"person"===a?(jQuery("#knowledge-graph-company").hide(),jQuery("#knowledge-graph-person").show()):(jQuery("#knowledge-graph-company").hide(),jQuery("#knowledge-graph-person").hide())}).change(),jQuery(".template").change(function(){wpseoDetectWrongVariables(jQuery(this))}).change();var a=window.location.hash.replace("#top#","");(""===a||"#_=_"===a)&&(a=jQuery(".wpseotab").attr("id")),jQuery("#"+a).addClass("active"),jQuery("#"+a+"-tab").addClass("nav-tab-active"),jQuery(".nav-tab-active").click()}),jQuery(window).on("hashchange",wpseoSetTabHash),jQuery(document).on("ready",wpseoSetTabHash); \ No newline at end of file