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'); forceRemoveHighlightPopup() if ($(element).find("span.sm").length > 0) { if ($(element).find("span.sm").text().length == 0) { $(element).find("span.sm").remove() }else { $(element).removeHighlight('.sm'); } } if ($(element).find("span.arGMhighlight").length > 0) { if ($(element).find("span.arGMhighlight").text().length == 0) { $(element).find("span.arGMhighlight").remove() }else { $(element).removeHighlight("span.arGMhighlight"); } } if ($(element).find("span.arEMhighlight").length > 0) { $(element).find("span.arEMhighlight").removeAttr('style'); $(element).find("span.arEMhighlight").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("span.arWChighlight").length > 0) { if ($(element).find("span.arWChighlight").text().length == 0){ $(element).find("span.arWChighlight").remove(); }else { $(element).find("span.arWChighlight").removeAttr('style'); $(element).removeHighlight('.arWChighlight'); } if ($(element).find("span.WordCompHighlight").length > 0) $(element).find('.WordCompHighlight').contents().unwrap(); } } $(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 () { var sm = spellHL; clearAllhighlighting(); var thisSMword; var contentWrapper = $('#content_ifr').contents().find('body'); if ($("#writer_Spelling").is(":checked")) { for (var i = 0; i < sm.detail.length; i++) { if ($('span.sm:contains(' + sm.detail[i].string + ')').length == 0) { contentWrapper.highlightRegex('\\b' + sm.detail[i].string + '\\b', {'className': 'sm'}); thisSMword = $(contentWrapper).find('span.sm'); $(contentWrapper).find('span.sm:contains(' + sm.detail[i].string + ')').data('suggestions', sm.detail[i].suggestions.option); } } var beforeHover; var afterHover; $(thisSMword).unbind('click').bind('click', function (e) { if (e.target.className == 'sm') { $(contentWrapper).find("#load_spelling-popup").remove(); beforeHover = $(this).prop("textContent"); var p; if (typeof p === 'undefined') p = $(contentWrapper).find('span.sm:contains(' + $(this).prop("textContent") + ')').data('suggestions'); // since 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); // bind CSS before load html $(contentWrapper).find("#load_spelling-popup").load("../wp-content/plugins/atomic-reach-audience-engager/custom/html/popups.php .writer-spelling_fix", {}, function () { $(contentWrapper).find(".writer-spelling_fix").removeClass("writer-hide"); $(contentWrapper).find(".suggestions_header-sm").prepend(beforeHover); //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').append('Revise: ' + d + '
'); //.append("' + p[key] + '
'); $(contentWrapper).find('.writer-grammar_fix .replacement_list').append('' + p[key] + '
'); } } // close the pop up $(contentWrapper).find('.writer-modal-header > #wcClose').bind('click', function (e) { $(contentWrapper).find("#load_links-popup").remove(); }); }); } } }) } else { clearAllhighlighting(); } }); } $("#writer_EM").change(function () { clearAllhighlighting(); var contentWrapper = $('#content_ifr').contents().find('body'); var thisEMword; if ($("#writer_EM").is(":checked")) { var em = emWords; $.each(em, function (i, v) { if ($('span.arEMhighlight:contains(' + i + ')').length == 0) { contentWrapper.highlightRegex('\\b' + i + '\\b', {'className': 'arEMhighlight'}); thisEMword = $(contentWrapper).find('span.arEMhighlight'); if (v == 'red') { $(contentWrapper).find('span.arEMhighlight:contains(' + i + ')').css({'border-bottom-color': 'rgb(125, 208, 255)'}); } else if (v == 'green') { $(contentWrapper).find('span.arEMhighlight:contains(' + i + ')').css({'border-bottom-color': 'rgb(255, 243, 128)'}); } $(contentWrapper).find('span.arEMhighlight:contains(' + i + ')').data('val', v); } }); // for loop $(thisEMword).unbind('click').bind('click', function (e) { if(e.target.className == 'arEMhighlight') { $(contentWrapper).find("#load_emotion-popup").remove(); var p; if (typeof p === 'undefined') p = $(contentWrapper).find('span.arEMhighlight:contains(' + $(this).prop("textContent") + ')').data('val'); var thisWord = $(this).prop("textContent"); if ($(contentWrapper).find("#load_emotion-popup").length < 1) { $(this).append(''); _this = $(this); $(contentWrapper).find("#load_emotion-popup").load("../wp-content/plugins/atomic-reach-audience-engager/custom/html/popups.php .writer-emotion_fix", {}, function () { $(contentWrapper).find('.writer-emotion_fix .suggestions_header-em b').text(thisWord); if (p == "red") { $(contentWrapper).find('.writer-emotion_fix .ar-emRED').show(); } else if (p == "green") { $(contentWrapper).find('.writer-emotion_fix .ar-emGREEN').show(); } $(contentWrapper).find(".writer-emotion_fix").removeClass("writer-hide"); // Fix popup Position if (e.pageY < $(contentWrapper).find("#load_emotion-popup > div").outerHeight() + 20) { var bottom = "0"; var top = null; } else { var bottom = null; var top = "-" + $(contentWrapper).find("#load_emotion-popup > div").outerHeight() + "px"; } if (e.pageX > $(contentWrapper).find("#load_emotion-popup > div").outerWidth()) { var tempWidth = $(contentWrapper).find("#load_emotion-popup > div").outerWidth() - 40; var left = "-" + tempWidth + "px"; } else { var left = "0"; } $(contentWrapper).find("#load_emotion-popup").css({ "left": (left == null ? left : left.replace('--', '-')), "top": (top == null ? top : top.replace('--', '-')), "bottom": (bottom == null ? bottom : bottom.replace('--', '-')) }); $(contentWrapper).find('.writer-modal-header > #wcClose').bind('click', function (e) { $(contentWrapper).find("#load_emotion-popup").remove(); }); });//end load } } }); } else { clearAllhighlighting(); } });//end change $("#writer_ParaDensity").change(function () { clearAllhighlighting(); var contentWrapper = $('#content_ifr').contents().find('body'); if ($("#writer_ParaDensity").is(":checked")) { var pwd = pwdHL.detail.paragraphs; var maxWords = pwdHL.recommended.paragraphWordDensityMax; var regex = /\s+/gi; $.each($(contentWrapper).find('p,li'), function (ind, val) { if (pwd[ind] != "length_hit" && pwd[ind] != "" && typeof pwd[ind] != "undefined") { $(this).wrapInner(""); $(this).data("value", pwd[ind]); //console.log($(this)); var word_count = $(this).text().trim().replace(regex, ' ').split(' ').length; $(this).data("wordcount", word_count); } }); // end each loop 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'); }) var responseData = $(this).parents('p,li').data(); if ($(contentWrapper).find("#load_ParaComp-popup").length == 0) { $(this).append(''); $(contentWrapper).find("#load_ParaComp-popup").load("../wp-content/plugins/atomic-reach-audience-engager/custom/html/popups.php .writer-paragraph_Complexity", function () { titleText = responseData.value.matchResult; 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(".suggestions_header-pwd").html(responseData.wordcount + ' words'); $($(contentWrapper).find(".writer-paragraph_Complexity p")[0]).text(); $(contentWrapper).find(".writer-paragraph_Complexity").removeClass("writer-hide"); if (e.pageY > $(contentWrapper).find("#load_ParaComp-popup > div").outerHeight() + 50) { var top = '0'; var bottom = null; } else { var top = null; var bottom = "-" + $(contentWrapper).find("#load_ParaComp-popup > div").outerHeight() + "px"; } $(contentWrapper).find("#load_ParaComp-popup").css({ "top": top, "bottom": bottom }); })//end load } }, function () { $(contentWrapper).find("#load_ParaComp-popup").remove(); }) ; } else { clearAllhighlighting(); } }); /* $("#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('textContent').split(/[\?\.\!]\n|[\?\.\!]\s/); for (var x = 0; x < sent.length; x++) { 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.php .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 wc = soHL.synonyms; var contentWrapper = $('#content_ifr').contents().find('body'); var sugg = []; $.each($(contentWrapper).find('p,li'), function (i, v) { if (typeof wc[i] != "undefined") { var sent = $(v).prop('textContent').split(/[\?\.\!]\n|[\?\.\!]\s/); for (var x = 0; x < sent.length; x++) { if (typeof wc[i][x] !== "undefined" && wc[i][x] != 'UNAVAILABLE') { $(this).wrapInner(""); var _this = $(this); var wordCount = 0; $.each(wc[i][x], function (i2, v2) { //if (wordCount >= wordsToHighlight) return false; $(_this).find("span.WordCompHighlight").highlightRegex('\\b' + i2 + '\\b', {'className': 'arWChighlight'}); thisWDword = $(contentWrapper).find('span.WordCompHighlight > span.arWChighlight'); sugg = []; //reset variable for (var k = 0; k < v2.length; k++) { sugg.push(v2[k]); } $(_this).find('span.arWChighlight:contains(' + i2 + ')').data('suggestions', sugg); wordCount ++; }); } } } }); var contentWrapper = $('#content_ifr').contents().find('body'); var beforeHover; var afterHover; $(thisWDword).unbind('click').bind('click', function (e) { if(e.target.className == 'arWChighlight') { $(contentWrapper).find("#load_wordComplexity-popup").remove(); beforeHover = $(this).prop("textContent"); 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(' + beforeHover + ')').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.php .writer_wordComplexity", function () { $(contentWrapper).find(".writer_wordComplexity").removeClass("writer-hide"); $(contentWrapper).find(".writer_wordComplexity .wordCompWord span").html(thisword); var haystack = []; var skip; if ($.isArray(p)) { for (var key in p) { if (p.hasOwnProperty(key)) { skip = false; var words = ''; for (var x = 0; x < p[key][1].length; x++) { if (typeof p[key][1][x][0] != "undefined") { if ($.inArray(p[key][1][x][0], haystack) == -1) { words += "" + p[key][1][x][0].replace("_", " ") + ""; } else { skip = true; } haystack.push(p[key][1][x][0]); } } if (typeof words != 'undefined' && !skip) { if (typeof p[key][0] == "string") $(contentWrapper).find('.writer_wordComplexity .wordCompright').append("" + p[key][0] + "
"); $(contentWrapper).find('.writer_wordComplexity .wordCompright').append('' + words.replace(/,\s*$/, "") + "
"); } } } 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; } if (e.pageX > $(contentWrapper).find("#load_wordComplexity-popup > div").outerWidth()) { var tempWidth = $(contentWrapper).find("#load_wordComplexity-popup > div").outerWidth() - 40; var left = "-" + tempWidth + "px"; } else { var left = 0; } $(contentWrapper).find("#load_wordComplexity-popup").css({ "left": left, "top": top, "bottom": bottom }); /*$(contentWrapper).find('.writer_wordComplexity .wordCompright .word-complexity-sug .ar-synonym .i').unbind("click").bind("click", function (e) { $(this).parents(".word-complexity-sug").next('.word-complexity-def').slideToggle(); $(contentWrapper).find(".writer_wordComplexity .word-complexity-def").not($(this).parents(".word-complexity-sug").next('.word-complexity-def')).slideUp(); });*/ // REPLACE WORD $(contentWrapper).find('.writer_wordComplexity .wordCompright .word-complexity-sug .ar-synonym').unbind("click").bind("click", function (e) { var x = $(this).children('strong').text(); afterHover = x; var r = this.closest("span.arWChighlight").childNodes[0].textContent; this.closest("span.arWChighlight").childNodes[0].textContent = x; $(this).children('strong').text(r); }); } // close the pop up $(contentWrapper).find('.writer-modal-header > #wcClose').bind('click', function (e) { $(contentWrapper).find("#load_wordComplexity-popup").remove(); if (typeof afterHover != 'undefined') if (beforeHover != afterHover) $(contentWrapper).find('span.arWChighlight:contains(' + afterHover + ')').removeClass('arWChighlight').contents().unwrap(); }); });//end .load } } }) } else { clearAllhighlighting(); } }); $("#aw_moretips_WP p").unbind('click').bind('click', function (e) { e.preventDefault(); $("ul#aw_titletips_WP").slideToggle(); }); } }); function addToDictionary(w) { return jQuery.ajax({ url: 'admin-ajax.php', data: {action: 'ar_analyzer_custom_dictionary', word: w}, async: false }).responseText == 'OK'; } }); function forceRemoveHighlightPopup(){ var element = jQuery("#content_ifr").contents().find('body'); if (jQuery(element).find('.writer-modal').length > 0) { jQuery(element).find('.writer-modal').remove() } } function escapeCharForRegex(word) { return word.replace(/(\.|\"|\'|\?|\/|\)|\(|\[|\])/g,"\\$1"); }