jQuery(document).ready(function ($) { $("#aranalyzer_metabox").on("change", ".onoffswitch > input[type=checkbox]", function(e){ jQuery(".onoffswitch > input[type=checkbox]").not($(this)).prop('checked', false); }) function clearAllhighlighting() { var element = $('#content_ifr').contents().find('body'); if ($(element).find("span.arSMhighlight").length > 0) { $(element).find("span.arSMhighlight").removeAttr('style'); $(element).find("span.arSMhighlight").contents().unwrap(); } if ($(element).find("span.arGMhighlight").length > 0) { $(element).find("span.arGMhighlight").removeAttr('style'); $(element).find("span.arGMhighlight").contents().unwrap(); } if ($(element).find("span.SenCompHighlight").length > 0) { $(element).find("span.SenCompHighlight").removeAttr('style'); $(element).find("span.SenCompHighlight").contents().unwrap(); } if ($(element).find("span.pwdHighlight").length > 0) { $(element).find("span.pwdHighlight").removeAttr('style'); $(element).find("span.pwdHighlight").contents().unwrap(); } if ($(element).find("span.arLNhighlight").length > 0) { $(element).find("span.arLNhighlight").removeAttr('style'); $(element).find("span.arLNhighlight").contents().unwrap(); } if ($(element).find(".writer_wordComplexity").length > 0) $(element).find(".writer_wordComplexity").addClass("writer-hide"); if ($(element).find("span.arWChighlight").length > 0) { $(element).find("span.arWChighlight").removeAttr('style'); $(element).removeHighlight('.arWChighlight'); if ($(element).find("span.WordCompHighlight").length > 0) $(element).removeHighlight('.WordCompHighlight'); } } $(document).ajaxComplete(function (event, xhr, settings) { var settingsURL = settings.url.match("admin-ajax.php"); if (settingsURL) { if (typeof spellHL != "undefined") if (spellHL.length == 0) { $('#ar-spellingHighlightButton').remove(); } else { $("#writer_Spelling").change(function () { clearAllhighlighting(); var thisSMword; var contentWrapper = $('#content_ifr').contents().find('body'); if ($("#writer_Spelling").is(":checked")) { for (var i = 0; i < spellHL.detail.length; i++) { if ($('span.arSMhighlight:contains(' + spellHL.detail[i].string + ')').length == 0) { contentWrapper.highlightRegex('\\b'+spellHL.detail[i].string+'\\b', {'className': 'arSMhighlight'}); thisSMword = $(contentWrapper).find('span.arSMhighlight'); thisSMword.css({'background-color': 'rgba(234, 129, 142, 0.7)', 'position': 'relative', 'display': 'inline'}); $(contentWrapper).find('span.arSMhighlight:contains(' + spellHL.detail[i].string + ')').data('suggestions', spellHL.detail[i].suggestions.option); } } $(thisSMword).hover(function (e) { if (e.pageX > $(contentWrapper).width() - 200) { var left = -180; } else { var left = 0; } if (e.pageY > $(contentWrapper).height() - 180) { var top = -115; } else { var bottom = 0; } var p; if (typeof p === 'undefined') p = $(contentWrapper).find('span.arSMhighlight:contains(' + $(this).prop("textContent") + ')').data('suggestions'); // sice hover function was being called multiple time, it now checks if #load_spelling_popup exists. If not it // creates it otherwise nothing. if ($(contentWrapper).find("#load_spelling-popup").length < 1) { $(this).append('
'); _this = $(this); $(contentWrapper).find("#load_spelling-popup").css({ "position": "absolute", "bottom": "0px", "left": left + "px", "top": top + "px", "bottom": bottom + "px", "display": "inline" }); // bind CSS before load html $(contentWrapper).find("#load_spelling-popup").load("../wp-content/plugins/atomic-reach-audience-engager/custom/html/popups.html .writer-spelling_fix", {}, function () { $(contentWrapper).find(".writer-spelling_fix").removeClass("writer-hide").css({ "position": "absolute", "display": "inline", "z-index": "999999", "width": "260px", "text-align": "center", "border": "2px solid #666666", "background-color": "#EA818E", "border-radius": "7px" }); //var p = $(contentWrapper).find(_this.data('suggestions')); if ($.isArray(p)) { for (var key in p) { if (p.hasOwnProperty(key)) { $(contentWrapper).find('.writer-spelling_fix .spellings_list').prepend('Revise: ' + d + '
'); //.append("' + p[key] + '
'); } } $(contentWrapper).find('.writer-grammar_fix a.grammar-suggestion-link').click(function (e) { e.preventDefault(); newwindow = window.open(l, 'name', 'height=400,width=450'); if (window.focus) { newwindow.focus() } return false; }) }); } }, function () { setTimeout(function () { if ($(contentWrapper).find("#load_grammar-popup").length > 0) if (!$(contentWrapper).find("#load_grammar-popup").is(":hover")) { $(contentWrapper).find("#load_grammar-popup").remove(); } }, 500); }); } else { var contentWrapper = $('#content_ifr').contents().find('body'); $(contentWrapper).removeClass("noun").removeHighlight('.arGMhighlight'); $(contentWrapper).find(".writer-grammar_fix").addClass("writer-hide"); } }); } if (typeof linkHL != "undefined") if (linkHL.invalid == 0) { $('#ar-linksHighlightButton').remove(); } else { $("#writer_Links").change(function () { clearAllhighlighting(); var contentWrapper = $('#content_ifr').contents().find('body'); if ($("#writer_Links").is(":checked")) { for (var i = 0; i < linkHL.detail.length; i++) { link = contentWrapper.find('a[href="' + linkHL.detail[i] + '"]'); if (link.parent('span').length != 1 || !link.parent('span').hasClass('highlight')) { link.wrap('' + ' '); } } $(contentWrapper).find("span.arLNhighlight").hover(function (e) { if ($(contentWrapper).find("#load_links-popup").length == 0) { $(this).append(''); _this = $(this); $(contentWrapper).find("#load_links-popup").css({ 'left': '0', 'bottom': '0', 'position': 'absolute', 'display': 'inline' }); $(contentWrapper).find("#load_links-popup").load("../wp-content/plugins/atomic-reach-audience-engager/custom/html/popups.html .writer-links_fix", function () { $(contentWrapper).find(".writer-links_fix").removeClass("writer-hide"); var p = _this.data('suggestions'); for (var key in p) { if (p.hasOwnProperty(key)) { $(contentWrapper).find('.writer-links_fix div').prepend('' + p[key] + '
'); } } }); } }, function () { setTimeout(function () { if (!$(contentWrapper).find("#load_links-popup").is(":hover")) { $(contentWrapper).find("#load_links-popup").remove(); } }, 500); }); } else { var contentWrapper = $('#content_ifr').contents().find('body'); $(contentWrapper).removeClass("noun").find('span.arLNhighlight > a').unwrap(); $(contentWrapper).find(".writer-links_fix").addClass("writer-hide"); } }); } $("#writer_ParaDensity").change(function () { clearAllhighlighting(); var contentWrapper = $('#content_ifr').contents().find('body'); if ($("#writer_ParaDensity").is(":checked")) { var p = pwdHL.detail.paragraphs; $.each($(contentWrapper).find('p'), function(ind, val){ if (p[ind] != "length_hit" && p[ind] != "" && typeof p[ind] != "undefined"){ //$(this).highlight($(val).prop('innerText'), "pwdHighlight"); $(this).wrapInner( ""); $(this).find('span.pwdHighlight').css({ 'background-color': 'rgba(220, 220, 244, 0.7)', 'position': 'relative', 'display': 'inline' }); $(this).data("value", p[ind]); } }); var contentWrapper = $('#content_ifr').contents().find('body'); $(contentWrapper).find("span.pwdHighlight").hover(function (e) { $(this).click(function () { $(this).children("#load_ParaComp-popup").remove(); $(this).unbind('hover'); }) if (e.pageY > $(contentWrapper).height() - 180) { var top = -155; } else { var bottom = 0; } var responseData = $(this).parents('p').data(); if ($(contentWrapper).find("#load_ParaComp-popup").length == 0) { $(this).append(''); $(contentWrapper).find("#load_ParaComp-popup").css({ 'left': "0", 'bottom': bottom + 'px', 'top': top + 'px', 'position': 'absolute', 'display': 'inline' }); $(contentWrapper).find("#load_ParaComp-popup").load("../wp-content/plugins/atomic-reach-audience-engager/custom/html/popups.html .writer-paragraph_Complexity", function () { titleText = responseData.value.matchResult; maxWords = pwdHL.recommended.paragraphWordDensityMax; switch (responseData.value.matchResult) { case "toolong": titleText = "Too Long"; break; case "tooshort": titleText = "Too Short"; break; } $($(contentWrapper).find(".writer-paragraph_Complexity p")[0]).text(titleText); $(contentWrapper).find("#numberOfWords").text(maxWords); $($(contentWrapper).find(".writer-paragraph_Complexity p")[0]).text(); $(contentWrapper).find(".writer-paragraph_Complexity").removeClass("writer-hide"); }) } }, function () { $(contentWrapper).find("#load_ParaComp-popup").remove(); }) ; } else { var contentWrapper = $('#content_ifr').contents().find('body'); $(contentWrapper).find("span.pwdHighlight").contents().unwrap(); $(contentWrapper).find(".writer-paragraph_Complexity").addClass("writer-hide"); } }); $("#writer_SenComp").change(function () { clearAllhighlighting(); if ($("#writer_SenComp").is(":checked")) { var contentWrapper = $('#content_ifr').contents().find('body'); $.each($(contentWrapper).find('p'), function(i,v) { if (typeof soHL.sentences[i] != "undefined"){ var sent = $(v).prop('innerText').split(/[\?\.\!]\n|[\?\.\!]\s/); for (var x = 0; x < sent.length; x++) { //console.log("------"+sent[x].trim()+" -- "+soHL.sentences[i][x] + $(this)); if (soHL.sentences[i][x] != "UNAVAILABLE") { $(this).highlight(sent[x].trim(), "SenCompHighlight"); //$(this).wrapInner(''); $(this).find("span.SenCompHighlight").css({ "background-color": 'rgba(246, 197, 164, 0.70)', "position": "relative", "display": "inline"}); $(this).data("value", soHL.sentences[i][x]) } } } }); var contentWrapper = $('#content_ifr').contents().find('body'); $(contentWrapper).find("span.SenCompHighlight").hover(function (e) { console.log($(this)); $(this).click(function () { $(this).children("#load_SenComp-popup").remove(); $(this).unbind('hover'); }); if (e.pageY > $(contentWrapper).height() - 180) { var top = -155; } else { var bottom = 0; } var responseData = $(this).parents('p').data(); if ($(contentWrapper).find("#load_SenComp-popup").length == 0) $(this).append(''); $(contentWrapper).find("#load_SenComp-popup").css({ 'left': '0', 'bottom': bottom + 'px', 'top': top + 'px', 'z-index': '99999', 'font-weight': "normal", 'text-decoration': "none", 'position': 'absolute', 'display': 'inline' }); $(contentWrapper).find("#load_SenComp-popup").load("../wp-content/plugins/atomic-reach-audience-engager/custom/html/popups.html .writer-sentence_Complexity", function () { //$( $(".writer-word_Complexity")[0] ).text(responseData.value.matchResult); console.log(responseData.value); if (responseData.value == "TOO COMPLEX") { $(contentWrapper).find('.writer-sentence_Complexity .ar-tooComplex').show(); } else if (responseData.value == "TOO SIMPLE") { $(contentWrapper).find('.writer-sentence_Complexity .ar-tooSimple').show(); } $(contentWrapper).find('.writer-sentence_Complexity').removeClass("writer-hide"); }); }, function () { $(contentWrapper).find("#load_SenComp-popup").remove(); }) } else { var contentWrapper = $('#content_ifr').contents().find('body'); if ($(contentWrapper).find("span.SenCompHighlight").length > 0) { contentWrapper.removeHighlight(".SenCompHighlight"); $(contentWrapper).find(".writer-sentence_Complexity").addClass("writer-hide"); } } }); // +++++++++++++ WORD COMPLEXITY +++++++++++++++++++ $("#writer_WordComp").change(function () { if ($("#writer_WordComp").is(":checked")) { clearAllhighlighting(); var so = soHL; var contentWrapper = $('#content_ifr').contents().find('body'); //var pArray = new Array(); var sugg = []; $.each($(contentWrapper).find('p'), function(i,v) { if (typeof so.synonyms[i] != "undefined") { //pArray[i] = new Array(); var sent = $(v).prop('innerText').split(/[\?\.\!]\n|[\?\.\!]\s/); for (var x = 0; x < sent.length; x++) { //pArray[i][x] = sent[x].trim(); if (typeof so.synonyms[i][x] !== "undefined") { //$(this).highlight(sent[x].trim(), "WordCompHighlight"); $(this).wrapInner(""); var _this = $(this); $.each(so.synonyms[i][x], function(i2, v2) { //if ($(_this).find('span.arWChighlight:contains(' + i2 + ')').length == 0) { $(_this).find("span.WordCompHighlight").highlightRegex('\\b'+i2+'\\b', {'className': 'arWChighlight'}); thisWDword = $(contentWrapper).find('span.WordCompHighlight > span.arWChighlight'); thisWDword.css({ 'background-color': 'rgba(255, 222, 137, 0.7)', 'position': 'relative', 'display': 'inline' }); sugg = []; //reset variable for (var k = 0; k < v2.length; k++) { sugg.push(v2[k]); } $(_this).find('span.arWChighlight:contains(' + i2 + ')').data('suggestions', sugg); //} // return false; }); } } } }); var contentWrapper = $('#content_ifr').contents().find('body'); var topbottom; $(thisWDword).hover(function (e) { var thisword = $(this).text(); if (e.pageX > $(contentWrapper).width() - 200) { var left = -180; } else { var left = 0; } var p; if (typeof p === 'undefined') p = $(contentWrapper).find('span.arWChighlight:contains(' + $(this).prop("textContent") + ')').data('suggestions'); if ($(contentWrapper).find("#load_wordComplexity-popup").length < 1) { $(this).append(''); $(contentWrapper).find("#load_wordComplexity-popup").css({ "position": "absolute", "display": "inline", }); $(contentWrapper).find("#load_wordComplexity-popup").load("../wp-content/plugins/atomic-reach-audience-engager/custom/html/popups.html .writer_wordComplexity", function () { $(contentWrapper).find(".writer_wordComplexity").removeClass("writer-hide").css({ "position": "absolute", "display": "inline", "font-weight": "normal", "text-decoration": "none", "z-index": "999", "width": "480px", "text-align": "center", "color": "#666666", "border": "2px solid #666666", "background-color": "rgb(255, 222, 137)", "border-radius": "7px" }); $(contentWrapper).find(".writer_wordComplexity .wordCompWord").append(thisword); if ($.isArray(p)) { for (var key in p) { if (p.hasOwnProperty(key)) { var words = ''; for (var x = 0; x < p[key][1].length; x++) { if (typeof p[key][1][x][0] != "undefined") words += "" + p[key][1][x][0].replace("_", " ") + ", "; } if (typeof words != 'undefined') $(contentWrapper).find('.writer_wordComplexity .wordCompright').append('' + words.replace(/,\s*$/, "") + " i
"); if (typeof p[key][0] == "string") $(contentWrapper).find('.writer_wordComplexity .wordCompright').append("" + p[key][0]) + "
"; } } if (e.pageY < $(contentWrapper).find("#load_wordComplexity-popup > div").outerHeight()+20) { var bottom = "-"+$(contentWrapper).find("#load_wordComplexity-popup > div").outerHeight()+"px"; var top = null; }else{ var bottom = null; var top = 0; } $(contentWrapper).find("#load_wordComplexity-popup").css({ "left": "0", "top": top, "bottom": bottom }); $(contentWrapper).find('.writer_wordComplexity .wordCompright .word-complexity-sug').unbind( "click").bind( "click", function(e){ /*if ($(this).next(".word-complexity-def").is(':visible')) { $(this).next(".word-complexity-def").slideUp(function(){ $(this).next(".word-complexity-def").slideToggle(); }); }else{*/ $(this).next(".word-complexity-def").slideToggle(); //} }); } else { } });//end .load } }, function () { setTimeout(function () { if ($(contentWrapper).find("#load_wordComplexity-popup").length > 0) if (!$(contentWrapper).find("#load_wordComplexity-popup").is(":hover")) { $(contentWrapper).find("#load_wordComplexity-popup").remove(); } }, 900); }) } else { var contentWrapper = $('#content_ifr').contents().find('body'); if ($(contentWrapper).find("span.arWChighlight").length > 0) { contentWrapper.removeClass("noun").removeHighlight('.arWChighlight'); } if ($(contentWrapper).find("span.WordCompHighlight").length > 0) { contentWrapper.removeClass("noun").removeHighlight('.WordCompHighlight'); //$(contentWrapper).find("span.WordCompHighlight").contents().unwrap(); } if ($(contentWrapper).find(".writer_wordComplexity").length > 0) $(contentWrapper).find(".writer_wordComplexity").addClass("writer-hide"); } }); $("#aw_moretips_WP p").unbind('click').bind('click', function(e){ e.preventDefault(); $("ul#aw_titletips_WP").slideToggle(); }); //$("#aud_info_WP").); } }); function addToDictionary(w) { return jQuery.ajax({ url: 'admin-ajax.php', data: {action: 'ar_analyzer_custom_dictionary', word: w}, async: false }).responseText == 'OK'; } });