if (!window["WPAC"]) var WPAC = {}; WPAC._Options = WPAC._Options || {}; WPAC._BodyRegex = new RegExp("]*>((.|\n|\r)*)", "i"); WPAC._ExtractBody = function(html) { try { return jQuery("
"+WPAC._BodyRegex.exec(html)[1]+"
"); } catch (e) { return false; } } WPAC._TitleRegex = new RegExp("]*>(.*?)<\\/title>", "im"); WPAC._ExtractTitle = function(html) { try { return WPAC._TitleRegex.exec(html)[1]; } catch (e) { return false; } } WPAC._ShowMessage = function (message, type) { var top = WPAC._Options.popupMarginTop + jQuery("#wpadminbar").outerHeight(); var backgroundColor = WPAC._Options.popupBackgroundColorLoading; var textColor = WPAC._Options.popupTextColorLoading; if (type == "error") { backgroundColor = WPAC._Options.popupBackgroundColorError; textColor = WPAC._Options.popupTextColorError; } else if (type == "success") { backgroundColor = WPAC._Options.popupBackgroundColorSuccess; textColor = WPAC._Options.popupTextColorSuccess; } jQuery.blockUI({ message: message, fadeIn: WPAC._Options.popupFadeIn, fadeOut: WPAC._Options.popupFadeOut, timeout:(type == "loading") ? 0 : WPAC._Options.popupTimeout, centerY: false, centerX: true, showOverlay: (type == "loading"), css: { width: WPAC._Options.popupWidth + "%", left: ((100-WPAC._Options.popupWidth)/2) + "%", top: top + "px", border: "none", padding: WPAC._Options.popupPadding + "px", backgroundColor: backgroundColor, "-webkit-border-radius": WPAC._Options.popupCornerRadius + "px", "-moz-border-radius": WPAC._Options.popupCornerRadius + "px", "border-radius": WPAC._Options.popupCornerRadius + "px", opacity: WPAC._Options.popupOpacity/100, color: textColor, textAlign: WPAC._Options.popupTextAlign, cursor: (type == "loading") ? "wait" : "default", "font-size": WPAC._Options.popupTextFontSize }, overlayCSS: { backgroundColor: "#000", opacity: 0 }, baseZ: WPAC._Options.popupZindex }); } WPAC._DebugErrorShown = false; WPAC._Debug = function(level, message) { if (!WPAC._Options.debug) return; // Fix console.log.apply for IE9 // see http://stackoverflow.com/a/5539378/516472 if (Function.prototype.call && Function.prototype.call.bind && typeof window["console"] != "undefined" && console && typeof console.log == "object" && typeof window["console"][level].apply === "undefined") { console[level] = Function.prototype.call.bind(console[level], console); } if (typeof window["console"] === "undefined" || typeof window["console"][level] === "undefined" || typeof window["console"][level].apply === "undefined") { if (!WPAC._DebugErrorShown) alert("Unfortunately the console object is undefined or is not supported in your browser, debugging WP Ajaxify Comments is disabled! Please use Firebug, Google Chrome or Internet Explorer 9 or above with enabled Developer Tools (F12) for debugging WP Ajaxify Comments."); WPAC._DebugErrorShown = true; return; } var args = jQuery.merge(["[WP Ajaxify Comments] " + message], jQuery.makeArray(arguments).slice(2)); console[level].apply(console, args); } WPAC._DebugSelector = function(elementType, selector, optional) { if (!WPAC._Options.debug) return; var element = jQuery(selector); if (!element.length) { WPAC._Debug(optional ? "info" : "error", "Search %s (selector: '%s')... Not found", elementType, selector); } else { WPAC._Debug("info", "Search %s (selector: '%s')... Found: %o", elementType, selector, element); } } WPAC._AddQueryParamStringToUrl = function(url, param, value) { return new Uri(url).replaceQueryParam(param, value).toString(); } WPAC._LoadFallbackUrl = function(fallbackUrl) { WPAC._ShowMessage(WPAC._Options.textReloadPage, "loading"); var url = WPAC._AddQueryParamStringToUrl(fallbackUrl, "WPACRandom", (new Date()).getTime()); WPAC._Debug("info", "Something went wrong. Reloading page (URL: '%s')...", url); var reload = function() { location.href = url; }; if (!WPAC._Options.debug) { reload(); } else { WPAC._Debug("info", "Sleep for 5s to enable analyzing debug messages..."); window.setTimeout(reload, 5000); } } WPAC._ScrollToAnchor = function(anchor, updateHash, scrollComplete) { scrollComplete = scrollComplete || function() {}; var anchorElement = jQuery(anchor) if (anchorElement.length) { WPAC._Debug("info", "Scroll to anchor element %o (scroll speed: %s ms)...", anchorElement, WPAC._Options.scrollSpeed); var animateComplete = function() { if (updateHash) window.location.hash = anchor; scrollComplete(); } var scrollTargetTopOffset = anchorElement.offset().top if (jQuery(window).scrollTop() == scrollTargetTopOffset) { animateComplete(); } else { jQuery("html,body").animate({scrollTop: scrollTargetTopOffset}, { duration: WPAC._Options.scrollSpeed, complete: animateComplete }); } return true; } else { WPAC._Debug("error", "Anchor element not found (selector: '%s')", anchor); return false; } } WPAC._UpdateUrl= function(url) { if (url.split("#")[0] == window.location.href.split("#")[0]) { return; } if (window.history.replaceState) { window.history.replaceState({}, window.document.title, url); } else { WPAC._Debug("info", "Browser does not support window.history.replaceState() to update the URL without reloading the page", anchor); } } WPAC._ReplaceComments = function(data, commentUrl, useFallbackUrl, formData, selectorCommentsContainer, selectorCommentForm, selectorRespondContainer, beforeSelectElements, beforeUpdateComments, afterUpdateComments) { var fallbackUrl = useFallbackUrl ? WPAC._AddQueryParamStringToUrl(commentUrl, "WPACFallback", "1") : commentUrl; var oldCommentsContainer = jQuery(selectorCommentsContainer); if (!oldCommentsContainer.length) { WPAC._Debug("error", "Comment container on current page not found (selector: '%s')", selectorCommentsContainer); WPAC._LoadFallbackUrl(fallbackUrl); return false; } var extractedBody = WPAC._ExtractBody(data); if (extractedBody === false) { WPAC._Debug("error", "Unsupported server response, unable to extract body (data: '%s')", data); WPAC._LoadFallbackUrl(fallbackUrl); return false; } beforeSelectElements(extractedBody); var newCommentsContainer = extractedBody.find(selectorCommentsContainer); if (!newCommentsContainer.length) { WPAC._Debug("error", "Comment container on requested page not found (selector: '%s')", selectorCommentsContainer); WPAC._LoadFallbackUrl(fallbackUrl); return false; } beforeUpdateComments(extractedBody, commentUrl); // Update title var extractedTitle = WPAC._ExtractTitle(data); if (extractedBody !== false) // Decode HTML entities (see http://stackoverflow.com/a/5796744) document.title = jQuery('