From e2fd291e8f8b70287ef27eb056465a1ec43a278d Mon Sep 17 00:00:00 2001 From: "Collin J. Doering" Date: Thu, 22 Jan 2015 00:24:52 -0500 Subject: [PATCH] Fixed opening issue with links within page-content Previously, all anchor clicks within #page-content was handled by a event listener that checked whether the anchor's href was to an 'external' url and if so loaded it directly. Otherwise it passed the value of the anchors href attribute to the jquery address plugin (via the $.address.value function). This unfortunately cause clicking on anchors to work fine but when opening them in a new page or window (or copying the link) caused the link to reference the html snippet of the page/post instead of the entire application. To rectify this, this commit simply transforms internal urls href attribute after the snippet is loaded into #page-content. Signed-off-by: Collin J. Doering --- js/default.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/js/default.js b/js/default.js index 2176e08..8506716 100644 --- a/js/default.js +++ b/js/default.js @@ -34,18 +34,15 @@ // var pageId = '#page-content', navId = '#nav'; function newContentCallback() { - $('#page-content a').click(function (evt) { + $('#page-content a').each(function (i) { var page_href = $(this).attr('href'), external_url_regexp = /https?:\/\/.*/, mailto_regexp = /mailto:.*/, files_regexp = /files\/.*/, images_regexp = /images\/.*/; - if (external_url_regexp.test(page_href) || mailto_regexp.test(page_href) || files_regexp.test(page_href) || images_regexp.test(page_href)) { - window.location.href = page_href; - } else { - evt.preventDefault(); - $.address.value(page_href); + if (!(external_url_regexp.test(page_href) || mailto_regexp.test(page_href) || files_regexp.test(page_href) || images_regexp.test(page_href))) { + $(this).attr('href', "/#" + page_href); } }); }