145 lines
4.0 KiB
JavaScript
145 lines
4.0 KiB
JavaScript
var slideShowIndex = 0;
|
|
var slideShowSlides = []; //An array of arrays - each sub-array contains the image path, title, description, width, and height.//
|
|
var scrollerScrollTime = 3500;
|
|
var scrollerInitialDelay = 5000;
|
|
var scrollerTransitionTime = 1000;
|
|
|
|
window.status="";
|
|
|
|
var layoutManager;
|
|
|
|
//Handle the document ready event which is where any initialization code goes.
|
|
$(document).ready(function($) {
|
|
// layoutManager = new LayoutManager("main-view");
|
|
//
|
|
// layoutManager.defaultUrl = '#!/Home';
|
|
// layoutManager.pageClassFades = [
|
|
// {cls: 'full', fadeIn: "#menu", fadeOut: null},
|
|
// {cls: 'dialog', fadeIn: null, fadeOut: "#menu"}
|
|
// ];
|
|
// layoutManager.viewMetadataDefaults = {classes: 'full'};
|
|
// layoutManager.viewMetadata = {
|
|
// // weddings: {
|
|
// // load: "element.data('scroller', new ItemScroller($('div.scrollViewport'), 142, scrollerScrollTime, scrollerInitialDelay, scrollerTransitionTime, false));",
|
|
// // unload:"element.data('scroller').release(); element.data('scroller', undefined);"
|
|
// // },
|
|
// };
|
|
|
|
var lastHash;
|
|
var delimiter = '-';
|
|
var $viewContainer = $('#contentContainer');
|
|
|
|
//Associate a function with the history jquery addon that will load the url content after the history is updated.
|
|
$.history.init(function(hash) {
|
|
//Remove any prefix characters.
|
|
if(hash) {
|
|
if(hash.startsWith('!/')) hash = hash.substring(2);
|
|
else if(hash.startsWith('/')) hash = hash.substring(1);
|
|
}
|
|
|
|
//Default the hash if not provided.
|
|
if(!hash || hash.length == 0) {
|
|
hash = 'menu';
|
|
}
|
|
|
|
//Shouldn't happen - but in case it does then ignore the case.
|
|
if(lastHash != hash) {
|
|
var lastHashPageName = getPageName(lastHash);
|
|
var hashPageName = getPageName(hash);
|
|
var hashPageData = getPageData(hash);
|
|
|
|
lastHash = hash;
|
|
|
|
//If the page has changed then load the new page and transition, otherwise transition to the new view within the page.
|
|
if(!lastHashPageName || lastHashPageName != hashPageName) {
|
|
$.ajax({url: hashPageName + ".html", dataType: 'html', async: true}).done(function(data) {
|
|
$viewContainer.fadeOut(250, function() {
|
|
$viewContainer.empty();
|
|
$viewContainer.html(data);
|
|
//TODO: First ensure the view is setup correctly? Use the hash to run the correct handler attached to the view's first element?
|
|
setupPage($viewContainer.children().first(), hashPageData, false);
|
|
|
|
$viewContainer.fadeIn(500, function() {
|
|
//TODO: Done?
|
|
});
|
|
});
|
|
}).fail(function(error) {
|
|
console.log(error);
|
|
});
|
|
}
|
|
else {
|
|
setupPage($viewContainer.children().first(), hashPageData, true);
|
|
}
|
|
}
|
|
});
|
|
|
|
function setupPage($view, data, internal) {
|
|
var handler = $view.data('display-handler');
|
|
|
|
if(handler) {
|
|
handler(data, internal);
|
|
}
|
|
}
|
|
function getPageName(hash) {
|
|
if(hash) {
|
|
var index = hash.indexOf(delimiter);
|
|
|
|
if(index > 0) { //Should never be zero.
|
|
return hash.substring(0, index);
|
|
}
|
|
else {
|
|
return hash;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
function getPageData(hash) {
|
|
if(hash) {
|
|
var index = hash.indexOf(delimiter);
|
|
|
|
if(index > 0) { //Should never be zero.
|
|
return hash.substring(index + 1);
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
/*
|
|
var websocket = new WebSocket('ws://petitteton.com/');
|
|
|
|
websocket.onopen = function() {
|
|
websocket.ping();
|
|
};
|
|
websocket.onerror = function(error) {
|
|
console.log('Websocket error: ' + error);
|
|
};
|
|
websocket.onmessage = function(message) {
|
|
console.log('Server: ' + message);
|
|
};
|
|
*/
|
|
});
|
|
|
|
|
|
//Override the jQuery.html(html) function to strip any <runonce>..</runonce> scripts and execute them.
|
|
// (function(){
|
|
// var htmlOriginal = jQuery.fn.html;
|
|
// jQuery.fn.html = function(html) {
|
|
// if(html != undefined) {
|
|
// var data = brainstormFramework.extractViewData(html);
|
|
//
|
|
// htmlOriginal.apply(this, [data.view]);
|
|
//
|
|
// if(data.script && data.script.length > 0) {
|
|
// try {
|
|
// eval(data.script);
|
|
// } catch(err) {
|
|
// alert(err);
|
|
// }
|
|
// }
|
|
// }
|
|
// else {
|
|
// htmlOriginal.apply(this, html);
|
|
// }
|
|
// }
|
|
// })();
|