2013-11-02 22:42:57 +00:00
|
|
|
/**
|
|
|
|
* (C) Copyright Collin Doering 2013
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2014-12-16 06:34:04 +00:00
|
|
|
*
|
2013-11-02 22:42:57 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2014-12-16 06:34:04 +00:00
|
|
|
*
|
2013-11-02 22:42:57 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-03-05 23:20:03 +00:00
|
|
|
*/
|
2013-11-02 22:42:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* File:. default.js
|
|
|
|
* Author: Collin J. Doering
|
|
|
|
* Date: Sep 6, 2013
|
2015-01-07 06:59:29 +00:00
|
|
|
* Description: Client-side logic for blog-rekahsoft-ca
|
2013-11-02 22:42:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
//------------------------
|
2015-01-20 04:35:43 +00:00
|
|
|
/*jslint browser: true*/
|
|
|
|
/*global jQuery, MathJax*/
|
|
|
|
//------------------------
|
2013-11-02 22:42:57 +00:00
|
|
|
|
2015-08-05 06:53:53 +00:00
|
|
|
// Global array for processing piwik analytics commands
|
|
|
|
var _paq = _paq || [];
|
|
|
|
_paq.push(["setDoNotTrack", true]);
|
|
|
|
_paq.push(['enableLinkTracking']);
|
|
|
|
|
|
|
|
// Asynchronously load piwik.js
|
|
|
|
(function() {
|
|
|
|
var u="//analytics.rekahsoft.ca/";
|
|
|
|
_paq.push(['setTrackerUrl', u+'piwik.php']);
|
|
|
|
_paq.push(['setSiteId', 1]);
|
|
|
|
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
|
|
|
|
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
|
|
|
|
})();
|
|
|
|
|
2015-01-20 04:35:43 +00:00
|
|
|
(function ($, mj) {
|
|
|
|
"use strict";
|
2015-01-06 09:08:40 +00:00
|
|
|
|
2015-01-23 19:24:28 +00:00
|
|
|
// The identity function
|
|
|
|
function idFun(x) {
|
|
|
|
return x;
|
|
|
|
}
|
2014-03-05 23:20:03 +00:00
|
|
|
|
2015-01-23 06:31:20 +00:00
|
|
|
var router = (function () {
|
|
|
|
var routes = [
|
|
|
|
{ // Post pages handler
|
|
|
|
acceptUrls: /posts\/.*\.html/,
|
|
|
|
rewriteGetUrl: idFun,
|
|
|
|
rewriteVirtualUrl: idFun,
|
|
|
|
ajaxCallbacks: {
|
|
|
|
beforeSend: function () {
|
|
|
|
$('#nav-menu li.active').removeClass('active');
|
|
|
|
$('#nav-menu li a[rel="address:/blog.html"]').parent('li').addClass('active');
|
|
|
|
}
|
2015-01-23 00:32:07 +00:00
|
|
|
}
|
|
|
|
},
|
2015-01-23 06:31:20 +00:00
|
|
|
{ // Tag pages handler
|
|
|
|
acceptUrls: /tags\/.*(\d*)\.html/,
|
|
|
|
rewriteGetUrl: function (url) {
|
|
|
|
var tag_not_regexp = /(tags\/.*[^\d]+)(\.html)/;
|
|
|
|
if (tag_not_regexp.test(url)) {
|
|
|
|
return url.replace(tag_not_regexp, "$11$2");
|
|
|
|
}
|
2015-01-23 19:24:28 +00:00
|
|
|
return url;
|
2015-01-23 06:31:20 +00:00
|
|
|
},
|
|
|
|
rewriteVirtualUrl: function (url) {
|
|
|
|
var tag_one_regexp = /(tags\/.*)1(\.html)/;
|
|
|
|
if (tag_one_regexp.test(url)) {
|
|
|
|
return url.replace(tag_one_regexp, "$1$2");
|
|
|
|
}
|
2015-01-23 19:24:28 +00:00
|
|
|
return url;
|
2015-01-23 06:31:20 +00:00
|
|
|
},
|
|
|
|
ajaxCallbacks: {
|
|
|
|
beforeSend: function () {
|
|
|
|
$('#nav-menu li.active').removeClass('active');
|
|
|
|
$('#nav-menu li a[rel="address:/blog.html"]').parent('li').addClass('active');
|
|
|
|
}
|
2015-01-23 00:32:07 +00:00
|
|
|
}
|
|
|
|
},
|
2015-01-23 06:31:20 +00:00
|
|
|
{ // Blog pages handler
|
|
|
|
acceptUrls: /blog\d*\.html/,
|
|
|
|
rewriteGetUrl: function (url) {
|
|
|
|
if (url === "/blog.html") {
|
2015-01-23 19:24:28 +00:00
|
|
|
url = "/blog1.html";
|
2015-01-23 06:31:20 +00:00
|
|
|
}
|
|
|
|
return "pages" + url;
|
|
|
|
},
|
|
|
|
rewriteVirtualUrl: function (url) {
|
|
|
|
if (url === "/blog1.html") {
|
|
|
|
url = "/blog.html";
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
},
|
|
|
|
ajaxCallbacks: {
|
|
|
|
beforeSend: function () {
|
|
|
|
// Set the blog menuitem as active
|
|
|
|
$('a.menuitem[rel="address:/blog.html"]').closest('ul').find('li.active').removeClass('active');
|
|
|
|
$('a.menuitem[rel="address:/blog.html"]').closest('li').addClass('active');
|
|
|
|
}
|
2015-01-23 00:32:07 +00:00
|
|
|
}
|
|
|
|
},
|
2015-01-23 06:31:20 +00:00
|
|
|
{ // Default page handler
|
|
|
|
acceptUrls: /.*/,
|
|
|
|
rewriteGetUrl: function (url) {
|
|
|
|
if (url === "/") {
|
2015-08-11 05:36:42 +00:00
|
|
|
url = "/index.html";
|
2015-01-23 06:31:20 +00:00
|
|
|
}
|
|
|
|
return "pages" + url;
|
|
|
|
},
|
|
|
|
rewriteVirtualUrl: function (url) {
|
2015-08-11 05:36:42 +00:00
|
|
|
if (url === "/index.html") {
|
2015-02-01 08:19:31 +00:00
|
|
|
url = "/";
|
2015-01-23 06:31:20 +00:00
|
|
|
}
|
|
|
|
return url;
|
|
|
|
},
|
|
|
|
ajaxCallbacks: {
|
|
|
|
beforeSend: function (url, virt_url) {
|
2015-02-01 08:19:31 +00:00
|
|
|
if (virt_url === "/") {
|
2015-08-11 05:36:42 +00:00
|
|
|
virt_url = "/index.html";
|
2015-02-01 08:19:31 +00:00
|
|
|
}
|
|
|
|
|
2015-01-23 06:31:20 +00:00
|
|
|
// Initially set the active menuitem in the nav
|
|
|
|
$('a.menuitem[rel="address:' + virt_url + '"]').closest('ul').find('li.active').removeClass('active');
|
|
|
|
$('a.menuitem[rel="address:' + virt_url + '"]').closest('li').addClass('active');
|
|
|
|
}
|
2015-01-23 00:32:07 +00:00
|
|
|
}
|
2015-01-23 06:31:20 +00:00
|
|
|
}],
|
2015-01-23 19:24:28 +00:00
|
|
|
callback = idFun,
|
2015-01-23 06:31:20 +00:00
|
|
|
|
2015-01-23 19:24:28 +00:00
|
|
|
spec = {
|
|
|
|
runRouter: function runRouter(url) {
|
|
|
|
function runRouter_help(spec) {
|
|
|
|
var i, new_virt_url;
|
|
|
|
for (i = 0; i < routes.length; i += 1) {
|
|
|
|
if (routes[i].acceptUrls.test(spec.url)) {
|
|
|
|
new_virt_url = routes[i].rewriteVirtualUrl(spec.url);
|
|
|
|
if (new_virt_url === spec.url) {
|
|
|
|
if (spec.hasRedirect) {
|
|
|
|
$.address.value(new_virt_url);
|
|
|
|
} else {
|
|
|
|
callback(routes[i].rewriteGetUrl(spec.url), spec.url, routes[i].ajaxCallbacks);
|
|
|
|
}
|
|
|
|
} else if (spec.numRecur <= spec.recurDepth) {
|
|
|
|
runRouter_help({ url: new_virt_url,
|
|
|
|
hasRedirect: true,
|
|
|
|
numRecur: spec.numRecur + 1,
|
|
|
|
recurDepth: spec.recurDepth });
|
|
|
|
} else {
|
2015-02-01 08:22:18 +00:00
|
|
|
console.log("Exceeded recursion depth for router");
|
2015-01-23 19:24:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
runRouter_help({ url: url,
|
|
|
|
hasRedirect: false,
|
|
|
|
numRecur: 1,
|
|
|
|
recurDepth: 5 });
|
|
|
|
},
|
|
|
|
setCallback: function setCallback(cb) {
|
|
|
|
if (typeof cb === 'function') {
|
|
|
|
callback = cb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return spec;
|
|
|
|
}()),
|
|
|
|
|
2015-08-11 05:36:42 +00:00
|
|
|
page = (function () {
|
|
|
|
// var pageId = '#page-content', navId = '#nav';
|
2015-01-23 19:24:28 +00:00
|
|
|
|
2015-08-11 05:36:42 +00:00
|
|
|
function loadPageContent(page_href, virt_href, handlerCallback) {
|
|
|
|
// Track page view with piwik
|
|
|
|
_paq.push(['setDocumentTitle', document.domain + '/' + virt_href]);
|
|
|
|
_paq.push(['trackPageView']);
|
2015-08-05 06:53:53 +00:00
|
|
|
|
2015-08-11 05:36:42 +00:00
|
|
|
// Remove loading error from page-content
|
|
|
|
$('#page-content').removeClass('loading-error');
|
2015-01-23 19:24:28 +00:00
|
|
|
|
2015-08-11 05:36:42 +00:00
|
|
|
// Add .loading to #page-content and #nav to facilitate a loading animation
|
|
|
|
$('#page-content, #nav').removeClass('loading-done').addClass('loading');
|
2015-01-23 19:24:28 +00:00
|
|
|
|
2015-08-11 05:36:42 +00:00
|
|
|
// Run current handlers onSuccess callback (if it exists)
|
|
|
|
if (handlerCallback.hasOwnProperty('beforeSend') && typeof handlerCallback.beforeSend === 'function') {
|
|
|
|
handlerCallback.beforeSend(page_href, virt_href);
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('beforeSend a.menuitem');
|
|
|
|
|
|
|
|
$('#page-content').load(page_href + ' #page-content', function (dta, status, xhr) {
|
|
|
|
if (status === "error") {
|
|
|
|
/* Remove .loading from #page-content and #nav to stop the loading
|
|
|
|
* animation. Then add .loading-error to #page-content if its the sites
|
|
|
|
* first load (#page-content has class .init). Finally, display an error
|
|
|
|
* message in #status.
|
|
|
|
*/
|
|
|
|
$('#page-content, #nav').removeClass('loading');
|
|
|
|
if ($('#page-content.init')[0]) {
|
|
|
|
// TODO: instead of immediately displaying error, check if the content is stored in local storage
|
|
|
|
$('#page-content').addClass('loading-error').html('<p class="container border-box">Error initially loading blog.rekahsoft.ca. Check the url! Given "' + page_href + '"</p>');
|
|
|
|
} else if ($('#status.error')[0]) {
|
|
|
|
$('#status').prepend('<p class="message">Error retrieving page ' + page_href + '</p>');
|
|
|
|
} else {
|
|
|
|
$('#status').prepend('<p class="message">Error retrieving page ' + page_href + '</p>');
|
|
|
|
$('#status').addClass('error').slideDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run current handles onError callback (if it exists)
|
|
|
|
if (handlerCallback.hasOwnProperty('onError') && typeof handlerCallback.onError === 'function') {
|
|
|
|
handlerCallback.onError();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Remove the initial loading gif (if its there)
|
|
|
|
$('#page-content').removeClass('init');
|
|
|
|
|
|
|
|
// Remove any status message errors or successes
|
|
|
|
$('#status').slideUp('normal', function () {
|
|
|
|
$('#status').removeClass('error').removeClass('success').children('p.message').remove();
|
|
|
|
});
|
2015-01-23 19:24:28 +00:00
|
|
|
|
2015-08-11 05:36:42 +00:00
|
|
|
// Stop animations in the nav and page-content and scroll to the top of the page in a set amount of time
|
|
|
|
setTimeout(function () {
|
|
|
|
// Replace old page-content with new page-content
|
|
|
|
$('#page-content').html(dta);
|
2015-01-23 19:24:28 +00:00
|
|
|
|
2015-08-11 05:36:42 +00:00
|
|
|
// Stop page loading
|
|
|
|
$('#page-content, #nav').removeClass('loading');
|
|
|
|
|
|
|
|
// Reload any new maths using MathJax
|
|
|
|
$('#page-content .math').each(function (math_elem) {
|
|
|
|
mj.Hub.Queue(["Typeset", mj.Hub, math_elem[0]]);
|
2015-06-28 08:03:17 +00:00
|
|
|
});
|
|
|
|
|
2015-08-11 05:36:42 +00:00
|
|
|
// Rewrite new URLs within new content inserted into #page-content
|
|
|
|
$('#page-content a').each(function (i) {
|
|
|
|
var href = $(this).attr('href'),
|
|
|
|
external_url_regexp = /https?:\/\/.*/,
|
|
|
|
mailto_regexp = /mailto:.*/,
|
|
|
|
files_regexp = /files\/.*/,
|
|
|
|
images_regexp = /images\/.*/;
|
2015-01-23 19:24:28 +00:00
|
|
|
|
2015-08-11 05:36:42 +00:00
|
|
|
if (!(external_url_regexp.test(href) || mailto_regexp.test(href) || files_regexp.test(href) || images_regexp.test(href))) {
|
|
|
|
$(this).attr('href', "/#" + href);
|
2015-01-23 06:31:20 +00:00
|
|
|
}
|
2015-08-11 05:36:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Add fullscreen functionality to inline-images and figures
|
|
|
|
$('article.post p > img').click(function () {
|
|
|
|
$(this).get(0).toggleFullScreen();
|
|
|
|
});
|
|
|
|
$('figure').click(function () {
|
|
|
|
$(this).children('img').get(0).toggleFullScreen();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Run current handles onSuccess callback (if it exists)
|
|
|
|
if (handlerCallback.hasOwnProperty('onSuccess') && typeof handlerCallback.onSuccess === 'function') {
|
|
|
|
handlerCallback.onSuccess();
|
2015-01-23 19:24:28 +00:00
|
|
|
}
|
|
|
|
|
2015-08-11 05:36:42 +00:00
|
|
|
// Scroll to top of the page
|
|
|
|
if ($('body').scrollTop() > $('#nav').offset().top - 15) {
|
|
|
|
$('html, body').animate({
|
|
|
|
scrollTop: $('#nav').offset().top - 15
|
|
|
|
}, 'fast');
|
2015-01-23 06:31:20 +00:00
|
|
|
}
|
2015-08-11 05:36:42 +00:00
|
|
|
}, 250);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-01-23 06:31:20 +00:00
|
|
|
|
2015-08-11 05:36:42 +00:00
|
|
|
function init(router) {
|
|
|
|
router.setCallback(loadPageContent);
|
2015-01-23 00:32:07 +00:00
|
|
|
|
2015-08-11 05:36:42 +00:00
|
|
|
$(document).ready(function () {
|
|
|
|
$('#nav-menu a.menuitem').click(function () {
|
|
|
|
$(this).closest('ul').find('li.active').removeClass('active');
|
|
|
|
$(this).closest('li').addClass('active');
|
|
|
|
//$('.navbar-collapse').collapse('hide');
|
|
|
|
});
|
2015-01-23 19:24:28 +00:00
|
|
|
|
2015-08-11 05:36:42 +00:00
|
|
|
$('#status a.close-button').click(function () {
|
|
|
|
$(this).parent().slideUp(function () {
|
|
|
|
$(this).removeClass('error').removeClass('success');
|
|
|
|
$(this).children('p.message').remove();
|
2015-01-23 19:24:28 +00:00
|
|
|
});
|
2015-08-11 05:36:42 +00:00
|
|
|
});
|
2015-01-23 19:24:28 +00:00
|
|
|
|
2015-08-11 05:36:42 +00:00
|
|
|
// Callback for when the inital page has completely loaded (including images, etc..)
|
|
|
|
$.address.change(function (event) {
|
|
|
|
console.log("Change " + event.value);
|
|
|
|
router.runRouter(event.value);
|
2015-01-23 19:24:28 +00:00
|
|
|
});
|
2015-08-11 05:36:42 +00:00
|
|
|
});
|
|
|
|
}
|
2015-01-23 19:24:28 +00:00
|
|
|
|
2015-08-11 05:36:42 +00:00
|
|
|
var spec = {
|
|
|
|
init: init
|
|
|
|
};
|
|
|
|
return spec;
|
|
|
|
}());
|
2015-01-23 06:31:20 +00:00
|
|
|
|
2015-08-11 05:36:42 +00:00
|
|
|
// Start of execution
|
2015-01-23 06:31:20 +00:00
|
|
|
page.init(router);
|
2015-01-20 04:35:43 +00:00
|
|
|
}(jQuery, MathJax));
|
2015-06-28 07:37:31 +00:00
|
|
|
|
|
|
|
// Modified from: https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Using_full_screen_mode
|
|
|
|
function toggleFullScreen() {
|
|
|
|
if (!document.fullscreenElement && // alternative standard method
|
|
|
|
!document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement ) { // current working methods
|
|
|
|
if (document.documentElement.requestFullscreen) {
|
|
|
|
this.requestFullscreen();
|
|
|
|
} else if (document.documentElement.msRequestFullscreen) {
|
|
|
|
this.msRequestFullscreen();
|
|
|
|
} else if (document.documentElement.mozRequestFullScreen) {
|
|
|
|
this.mozRequestFullScreen();
|
|
|
|
} else if (document.documentElement.webkitRequestFullscreen) {
|
|
|
|
this.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (document.exitFullscreen) {
|
|
|
|
document.exitFullscreen();
|
|
|
|
} else if (document.msExitFullscreen) {
|
|
|
|
document.msExitFullscreen();
|
|
|
|
} else if (document.mozCancelFullScreen) {
|
|
|
|
document.mozCancelFullScreen();
|
|
|
|
} else if (document.webkitExitFullscreen) {
|
|
|
|
document.webkitExitFullscreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Element.prototype.toggleFullScreen = toggleFullScreen;
|