Major changes to the structure of pages to utilize the flex layout system.
This commit is contained in:
@@ -6,30 +6,105 @@ var scrollerTransitionTime = 1000;
|
||||
|
||||
window.status="";
|
||||
|
||||
var layoutManager;
|
||||
|
||||
//Handle the document ready event which is where any initialization code goes.
|
||||
$(document).ready(function($) {
|
||||
var layoutManager = new LayoutManager("main-view");
|
||||
// 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);"
|
||||
// // },
|
||||
// };
|
||||
|
||||
layoutManager.defaultUrl = '#!/Home';
|
||||
layoutManager.pageClassFades = [
|
||||
{cls: 'full', fadeIn: null, fadeOut: null}
|
||||
];
|
||||
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(url) {
|
||||
if(!url || url.length == 0) {
|
||||
url = layoutManager.defaultUrl;
|
||||
$.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);
|
||||
}
|
||||
}
|
||||
|
||||
layoutManager.show(url);
|
||||
});
|
||||
|
||||
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/');
|
||||
|
||||
@@ -47,24 +122,24 @@ $(document).ready(function($) {
|
||||
|
||||
|
||||
//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);
|
||||
}
|
||||
}
|
||||
})();
|
||||
// (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);
|
||||
// }
|
||||
// }
|
||||
// })();
|
||||
Reference in New Issue
Block a user