use new module load syntax

This commit is contained in:
rolux 2011-09-09 23:05:20 +00:00
parent 131fe30a58
commit e76cbc998e

View file

@ -8,173 +8,172 @@
// fixme: don't reload full right panel on sortSelect // fixme: don't reload full right panel on sortSelect
// fixme: clear items cache after login/logout // fixme: clear items cache after login/logout
Ox.load('UI', { Ox.load({
debug: true, UI: {
hideScreen: false, debug: true,
loadImages: true, hideScreen: false,
showScreen: true, loadImages: true,
theme: 'modern' showScreen: true,
theme: 'modern'
},
Geo: {}
}, function(browserSupported) { }, function(browserSupported) {
// fixme: use Ox.extend() // fixme: use Ox.extend()
Ox.load('Geo', function() { window.pandora = new Ox.App({url: '/api/'}).bindEvent({
window.pandora = new Ox.App({url: '/api/'}).bindEvent({ load: function(data) {
load: function(data) { if (!browserSupported) {
return;
}
if (!browserSupported) { Ox.extend(pandora, {
return; requests: {},
} ui: {}
});
loadResources('/static/json/pandora.json', function() {
Ox.print('Ox.App load', data);
// Ox.UI.hideLoadingScreen();
Ox.extend(pandora, { Ox.extend(pandora, {
requests: {}, $ui: {
ui: {} body: $('body'),
document: $(document),
window: $(window)
.resize(resizeWindow)
.unload(unloadWindow)
},
site: data.site,
user: data.user.level == 'guest' ? Ox.extend({}, data.site.user) : data.user
}); });
Ox.extend(pandora.site, {
loadResources('/static/json/pandora.json', function() { findKeys: $.map(data.site.itemKeys, function(key, i) {
return key.find ? key : null;
Ox.print('Ox.App load', data); }),
sectionFolders: {
// Ox.UI.hideLoadingScreen(); items: [
{id: 'personal', title: 'Personal Lists'},
Ox.extend(pandora, { {id: 'favorite', title: 'Favorite Lists', showBrowser: false},
$ui: { {id: 'featured', title: 'Featured Lists', showBrowser: false},
body: $('body'), {id: 'volumes', title: 'Local Volumes'}
document: $(document), ],
window: $(window) edits: [
.resize(resizeWindow) {id: 'personal', title: 'Personal Edits'},
.unload(unloadWindow) {id: 'favorite', title: 'Favorite Edits', showBrowser: false},
}, {id: 'featured', title: 'Featured Edits', showBrowser: false}
site: data.site, ],
user: data.user.level == 'guest' ? Ox.extend({}, data.site.user) : data.user texts: [
}); {id: 'personal', title: 'Personal Texts'},
Ox.extend(pandora.site, { {id: 'favorite', title: 'Favorite Texts', showBrowser: false},
findKeys: $.map(data.site.itemKeys, function(key, i) { {id: 'featured', title: 'Featured Texts', showBrowser: false}
return key.find ? key : null; ]
}), },
sectionFolders: { sortKeys: $.map(data.site.itemKeys, function(key, i) {
items: [ return key.columnWidth ? key : null;
{id: 'personal', title: 'Personal Lists'},
{id: 'favorite', title: 'Favorite Lists', showBrowser: false},
{id: 'featured', title: 'Featured Lists', showBrowser: false},
{id: 'volumes', title: 'Local Volumes'}
],
edits: [
{id: 'personal', title: 'Personal Edits'},
{id: 'favorite', title: 'Favorite Edits', showBrowser: false},
{id: 'featured', title: 'Featured Edits', showBrowser: false}
],
texts: [
{id: 'personal', title: 'Personal Texts'},
{id: 'favorite', title: 'Favorite Texts', showBrowser: false},
{id: 'featured', title: 'Featured Texts', showBrowser: false}
]
},
sortKeys: $.map(data.site.itemKeys, function(key, i) {
return key.columnWidth ? key : null;
})
});
Ox.extend(pandora.user, {
infoRatio: 16 / 9,
sectionElement: 'buttons',
selectedMovies: [],
videoFormat: Ox.UI.getVideoFormat(pandora.site.video.formats)
});
// fixme: this should not happen
if (!pandora.user.ui.lists[pandora.user.ui.list]) {
pandora.user.ui.lists[pandora.user.ui.list] = pandora.user.ui.lists[''];
}
if (data.user.level == 'guest' && $.browser.mozilla) {
pandora.user.ui.theme = 'classic';
}
pandora.URL.parse();
window.onpopstate = function(event) {
pandora.URL.update();
};
Ox.UI.hideLoadingScreen();
Ox.Theme(pandora.user.ui.theme);
pandora.$ui.appPanel = pandora.ui.appPanel().display();
Ox.Request.requests() && pandora.$ui.loadingIcon.start();
pandora.$ui.body.ajaxStart(pandora.$ui.loadingIcon.start);
pandora.$ui.body.ajaxStop(pandora.$ui.loadingIcon.stop);
pandora.site.sectionButtonsWidth = pandora.$ui.sectionButtons.width() + 8;
}, '/static/');
}
});
function loadResources(json, callback, prefix) {
prefix = prefix || '';
$.getJSON(json, function(files) {
var promises = [];
files.forEach(function(file) {
// fixme: opera doesnt fire onload for svg
// fixme: we don't have any svgs, right?
if ($.browser.opera && Ox.endsWith(file, '.svg')) {
return;
}
var dfd = new $.Deferred();
promises.push(dfd.promise());
Ox.loadFile(prefix + file, function() {
dfd.resolve();
});
});
$.when.apply(null, promises)
.done(function() {
callback();
}) })
.fail(function() { });
throw new Error('File not found.') Ox.extend(pandora.user, {
}); infoRatio: 16 / 9,
}); sectionElement: 'buttons',
} selectedMovies: [],
videoFormat: Ox.UI.getVideoFormat(pandora.site.video.formats)
function resizeWindow() { });
pandora.resizeFolders(); // fixme: this should not happen
if (!pandora.user.ui.item) { if (!pandora.user.ui.lists[pandora.user.ui.list]) {
pandora.$ui.list.size(); pandora.user.ui.lists[pandora.user.ui.list] = pandora.user.ui.lists[''];
pandora.resizeGroups(pandora.$ui.rightPanel.width());
if (pandora.user.ui.listView == 'map') {
pandora.$ui.map.resize();
} }
} else {
//Ox.print('pandora.$ui.window.resize');
pandora.$ui.browser.scrollToSelection();
pandora.user.ui.itemView == 'info' && pandora.$ui.item.resize();
pandora.user.ui.itemView == 'player' && pandora.$ui.player.options({
// fixme: duplicated
height: pandora.$ui.contentPanel.size(1),
width: pandora.$ui.document.width() - pandora.$ui.mainPanel.size(0) - 1
});
pandora.user.ui.itemView == 'timeline' && pandora.$ui.editor.options({
// fixme: duplicated
height: pandora.$ui.contentPanel.size(1),
width: pandora.$ui.document.width() - pandora.$ui.mainPanel.size(0) - 1
});
}
}
function unloadWindow() { if (data.user.level == 'guest' && $.browser.mozilla) {
// fixme: ajax request has to have async set to false for this to work pandora.user.ui.theme = 'classic';
pandora.user.ui.section == 'items' && }
['player', 'timeline'].indexOf(pandora.user.ui.itemView) > -1 &&
pandora.user.ui.item &&
pandora.UI.set(
'videoPosition|' + pandora.user.ui.item,
pandora.$ui[
pandora.user.ui.itemView == 'player' ? 'player' : 'editor'
].options('position')
);
}
pandora.URL.parse();
window.onpopstate = function(event) {
pandora.URL.update();
};
Ox.UI.hideLoadingScreen();
Ox.Theme(pandora.user.ui.theme);
pandora.$ui.appPanel = pandora.ui.appPanel().display();
Ox.Request.requests() && pandora.$ui.loadingIcon.start();
pandora.$ui.body.ajaxStart(pandora.$ui.loadingIcon.start);
pandora.$ui.body.ajaxStop(pandora.$ui.loadingIcon.stop);
pandora.site.sectionButtonsWidth = pandora.$ui.sectionButtons.width() + 8;
}, '/static/');
}
}); });
function loadResources(json, callback, prefix) {
prefix = prefix || '';
$.getJSON(json, function(files) {
var promises = [];
files.forEach(function(file) {
// fixme: opera doesnt fire onload for svg
// fixme: we don't have any svgs, right?
if ($.browser.opera && Ox.endsWith(file, '.svg')) {
return;
}
var dfd = new $.Deferred();
promises.push(dfd.promise());
Ox.loadFile(prefix + file, function() {
dfd.resolve();
});
});
$.when.apply(null, promises)
.done(function() {
callback();
})
.fail(function() {
throw new Error('File not found.')
});
});
}
function resizeWindow() {
pandora.resizeFolders();
if (!pandora.user.ui.item) {
pandora.$ui.list.size();
pandora.resizeGroups(pandora.$ui.rightPanel.width());
if (pandora.user.ui.listView == 'map') {
pandora.$ui.map.resize();
}
} else {
//Ox.print('pandora.$ui.window.resize');
pandora.$ui.browser.scrollToSelection();
pandora.user.ui.itemView == 'info' && pandora.$ui.item.resize();
pandora.user.ui.itemView == 'player' && pandora.$ui.player.options({
// fixme: duplicated
height: pandora.$ui.contentPanel.size(1),
width: pandora.$ui.document.width() - pandora.$ui.mainPanel.size(0) - 1
});
pandora.user.ui.itemView == 'timeline' && pandora.$ui.editor.options({
// fixme: duplicated
height: pandora.$ui.contentPanel.size(1),
width: pandora.$ui.document.width() - pandora.$ui.mainPanel.size(0) - 1
});
}
}
function unloadWindow() {
// fixme: ajax request has to have async set to false for this to work
pandora.user.ui.section == 'items' &&
['player', 'timeline'].indexOf(pandora.user.ui.itemView) > -1 &&
pandora.user.ui.item &&
pandora.UI.set(
'videoPosition|' + pandora.user.ui.item,
pandora.$ui[
pandora.user.ui.itemView == 'player' ? 'player' : 'editor'
].options('position')
);
}
}); });