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 <collin.doering@rekahsoft.ca>
This commit is contained in:
Collin J. Doering 2015-01-22 00:24:52 -05:00
parent 046f97a2bb
commit e2fd291e8f
1 changed files with 3 additions and 6 deletions

View File

@ -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);
}
});
}