rewrite history, again

This commit is contained in:
rolux 2011-11-09 22:32:54 +00:00
parent f93fd49bd7
commit 8a6f29cd31
11 changed files with 155 additions and 103 deletions

View file

@ -617,6 +617,7 @@
"lists": {}, "lists": {},
"mapFind": "", "mapFind": "",
"mapSelection": "", "mapSelection": "",
"page": "",
"section": "items", "section": "items",
"showAnnotations": true, "showAnnotations": true,
"showBrowser": true, "showBrowser": true,

View file

@ -24,6 +24,7 @@ urlpatterns = patterns('',
(r'^api/upload/$', 'archive.views.firefogg_upload'), (r'^api/upload/$', 'archive.views.firefogg_upload'),
(r'^url=(?P<url>.*)$', 'app.views.redirect_url'), (r'^url=(?P<url>.*)$', 'app.views.redirect_url'),
(r'^file/(?P<oshash>.*)$', 'archive.views.lookup_file'), (r'^file/(?P<oshash>.*)$', 'archive.views.lookup_file'),
(r'^api$', include('api.urls')),
(r'^api/$', include('api.urls')), (r'^api/$', include('api.urls')),
(r'^resetUI$', 'user.views.reset_ui'), (r'^resetUI$', 'user.views.reset_ui'),
(r'', include('item.urls')), (r'', include('item.urls')),

View file

@ -6,9 +6,13 @@ pandora.URL = (function() {
var self = {}, that = {}; var self = {}, that = {};
function getState(keys) { function getState() {
Ox.Log('GET STATE, UI', pandora.user.ui) Ox.Log('', 'GET STATE, UI', pandora.user.ui)
if (pandora.user.ui.page) {
return {page: pandora.user.ui.page};
}
var state = {}; var state = {};
@ -45,7 +49,7 @@ pandora.URL = (function() {
); );
} }
Ox.Log('URL', 'STATE ...', state) Ox.Log('', 'URL', 'STATE ...', state)
return state; return state;
@ -66,43 +70,7 @@ pandora.URL = (function() {
} else if (state.page) { } else if (state.page) {
if (state.page == 'home') { pandora.UI.set(state);
// if we're on page load, show screen immediately
pandora.$ui.home = pandora.ui.home()[
!pandora.$ui.appPanel ? 'showScreen' : 'fadeInScreen'
]();
} else if (
Ox.getPositionById(pandora.site.sitePages, state.page) > -1
|| state.page == 'software'
) {
if (pandora.$ui.siteDialog && pandora.$ui.siteDialog.is(':visible')) {
pandora.$ui.siteDialog.select(state.page);
} else {
pandora.$ui.siteDialog = pandora.ui.siteDialog(state.page).open();
}
} else if (state.page == 'help') {
pandora.$ui.helpDialog = pandora.ui.helpDialog().open();
} else if (['signup', 'signin'].indexOf(state.page) > -1) {
if (pandora.user.level == 'guest') {
if (pandora.$ui.accountDialog && pandora.$ui.accountDialog.is(':visible')) {
pandora.$ui.accountDialog.options(pandora.ui.accountDialogOptions(state.page));
} else {
pandora.$ui.accountDialog = pandora.ui.accountDialog(state.page).open();
}
} else {
pandora.URL.replace('/');
}
} else if (['preferences', 'signout'].indexOf(state.page) > -1) {
if (pandora.user.level == 'guest') {
pandora.URL.replace('/');
} else if (state.page == 'preferences') {
pandora.ui.preferencesDialog().open();
} else {
pandora.ui.accountSignoutDialog().open();
}
} else if (state.page == 'api') {
document.location.href = '/api/';
}
callback && callback(); callback && callback();
} else { } else {
@ -276,6 +244,10 @@ pandora.URL = (function() {
$('.OxDialog:visible').each(function() { $('.OxDialog:visible').each(function() {
Ox.UI.elements[$(this).data('oxid')].close(); Ox.UI.elements[$(this).data('oxid')].close();
}); });
if (pandora.$ui.home) {
pandora.UI.set({page: ''});
pandora.$ui.home.fadeOutScreen();
}
if ( if (
pandora.user.ui.item pandora.user.ui.item
&& pandora.user.ui.itemView == 'video' && pandora.user.ui.itemView == 'video'
@ -283,10 +255,8 @@ pandora.URL = (function() {
&& pandora.$ui.player.options('fullscreen') && pandora.$ui.player.options('fullscreen')
) { ) {
pandora.$ui.player.remove(); pandora.$ui.player.remove();
//pandora.$ui.player.options({fullscreen: false});
//$('body > .OxVideoPlayer').remove();
} }
if (!Ox.isEmpty(e.state)) { if (e.state && !Ox.isEmpty(e.state)) {
Ox.Log('', 'E.STATE', e.state) Ox.Log('', 'E.STATE', e.state)
document.title = e.state.title; document.title = e.state.title;
setState(e.state); setState(e.state);
@ -313,12 +283,15 @@ pandora.URL = (function() {
// sets the URL to the previous URL // sets the URL to the previous URL
that.pop = function() { that.pop = function() {
self.URL.pop(); self.URL.pop() || that.update();
}; };
// pushes a new URL (as string or from state) // pushes a new URL (as string or from state)
that.push = function(stateOrURL) { that.push = function(stateOrURL) {
var state, title = pandora.getPageTitle(), url; var state,
title = pandora.getPageTitle(stateOrURL)
|| pandora.getDocumentTitle(),
url;
if (Ox.isObject(stateOrURL)) { if (Ox.isObject(stateOrURL)) {
state = stateOrURL; state = stateOrURL;
} else { } else {
@ -329,8 +302,11 @@ pandora.URL = (function() {
}; };
// replaces the current URL (as string or from state) // replaces the current URL (as string or from state)
that.replace = function(stateOrURL) { that.replace = function(stateOrURL, title) {
var state, title = pandora.getPageTitle(), url; var state,
title = pandora.getPageTitle(stateOrURL)
|| pandora.getDocumentTitle(),
url;
if (Ox.isObject(stateOrURL)) { if (Ox.isObject(stateOrURL)) {
state = stateOrURL; state = stateOrURL;
} else { } else {
@ -368,7 +344,10 @@ pandora.URL = (function() {
action = 'push'; action = 'push';
} }
state = getState(); state = getState();
self.URL[action](state, pandora.getPageTitle(), ''); self.URL[action](
state,
pandora.getPageTitle(state) || pandora.getDocumentTitle()
);
} }
}; };

View file

@ -58,7 +58,7 @@ pandora.ui.accountDialogOptions = function(action, value) {
title: 'Cancel' title: 'Cancel'
}).bindEvent('click', function() { }).bindEvent('click', function() {
pandora.$ui.accountDialog.close(); pandora.$ui.accountDialog.close();
pandora.URL.update(); pandora.UI.set({page: ''});
}); });
} else if (type == 'submit') { } else if (type == 'submit') {
return Ox.Button({ return Ox.Button({
@ -74,7 +74,7 @@ pandora.ui.accountDialogOptions = function(action, value) {
title: buttonTitle[type] + '...' title: buttonTitle[type] + '...'
}).bindEvent('click', function() { }).bindEvent('click', function() {
if (['signin', 'signup'].indexOf(type) > -1) { if (['signin', 'signup'].indexOf(type) > -1) {
pandora.URL.replace({page: type}); pandora.UI.set({page: type});
} else { } else {
pandora.$ui.accountDialog.options(pandora.ui.accountDialogOptions(type)); pandora.$ui.accountDialog.options(pandora.ui.accountDialogOptions(type));
} }
@ -319,7 +319,7 @@ pandora.ui.accountSignoutDialog = function() {
title: 'Stay Signed In' title: 'Stay Signed In'
}).bindEvent('click', function() { }).bindEvent('click', function() {
that.close(); that.close();
pandora.URL.update(); pandora.UI({page: ''});
}), }),
Ox.Button({ Ox.Button({
id: 'signout', id: 'signout',

View file

@ -13,6 +13,7 @@ pandora.ui.appPanel = function() {
], ],
orientation: 'vertical' orientation: 'vertical'
}); });
setPage(pandora.user.ui.page);
that.display = function() { that.display = function() {
// fixme: move animation into Ox.App // fixme: move animation into Ox.App
var animate = $('.OxScreen').length == 0; var animate = $('.OxScreen').length == 0;
@ -27,6 +28,48 @@ pandora.ui.appPanel = function() {
pandora.$ui.appPanel = pandora.ui.appPanel().appendTo(pandora.$ui.body); pandora.$ui.appPanel = pandora.ui.appPanel().appendTo(pandora.$ui.body);
return that; return that;
} }
that.bindEvent({
pandora_page: function(data) {
setPage(data.value);
}
});
function setPage(page) {
if (page == 'home') {
// if we're on page load, show screen immediately
pandora.$ui.home = pandora.ui.home()[
!pandora.$ui.appPanel ? 'showScreen' : 'fadeInScreen'
]();
} else if (
Ox.getPositionById(pandora.site.sitePages, page) > -1
|| page == 'software'
) {
if (pandora.$ui.siteDialog && pandora.$ui.siteDialog.is(':visible')) {
pandora.$ui.siteDialog.select(page);
} else {
pandora.$ui.siteDialog = pandora.ui.siteDialog(page).open();
}
} else if (page == 'help') {
pandora.$ui.helpDialog = pandora.ui.helpDialog().open();
} else if (['signup', 'signin'].indexOf(page) > -1) {
if (pandora.user.level == 'guest') {
if (pandora.$ui.accountDialog && pandora.$ui.accountDialog.is(':visible')) {
pandora.$ui.accountDialog.options(pandora.ui.accountDialogOptions(page));
} else {
pandora.$ui.accountDialog = pandora.ui.accountDialog(page).open();
}
} else {
pandora.URL.replace('/');
}
} else if (['preferences', 'signout'].indexOf(page) > -1) {
if (pandora.user.level == 'guest') {
pandora.URL.replace('/');
} else if (page == 'preferences') {
pandora.ui.preferencesDialog().open();
} else {
pandora.ui.accountSignoutDialog().open();
}
}
}
return that; return that;
}; };

View file

@ -3,29 +3,33 @@
pandora.ui.helpDialog = function() { pandora.ui.helpDialog = function() {
var content = Ox.Element().css({margin: '16px'}), var content = Ox.Element().css({margin: '16px'}),
that = Ox.Dialog({ that = Ox.Dialog({
buttons: [ buttons: [
Ox.Button({ Ox.Button({
id: 'close', id: 'close',
title: 'Close' title: 'Close'
}).bindEvent({ }).bindEvent({
click: function() { click: function() {
that.close(); that.close();
pandora.URL.update(); }
} })
}) ],
], closeButton: true,
//closeButton: true, content: content,
content: content, height: Math.round((window.innerHeight - 24) * 0.75),
height: Math.round((window.innerHeight - 24) * 0.75), keys: {
keys: { 'escape': 'close'
'escape': 'close' },
}, maximizeButton: true,
//maximizeButton: true, minHeight: 256,
minHeight: 256, minWidth: 640,
minWidth: 640, title: 'Help',
title: 'Help', width: Math.round(window.innerWidth * 0.75)
width: Math.round(window.innerWidth * 0.75) })
}); .bindEvent({
close: function(data) {
pandora.UI.set({page: ''});
}
});
pandora.api.getPage({name: 'help'}, function(result) { pandora.api.getPage({name: 'help'}, function(result) {
//content.html(response.data.body); //content.html(response.data.body);
content.html('Help is coming soon...') content.html('Help is coming soon...')

View file

@ -134,7 +134,7 @@ pandora.ui.home = function() {
}) })
.bindEvent({ .bindEvent({
click: function() { click: function() {
pandora.URL.update(); pandora.UI.set({page: ''});
that.fadeOutScreen(); that.fadeOutScreen();
} }
}) })
@ -154,7 +154,7 @@ pandora.ui.home = function() {
}) })
.bindEvent({ .bindEvent({
click: function() { click: function() {
pandora.URL.push('/signup'); pandora.UI.set({page: 'signup'});
that.fadeOutScreen(); that.fadeOutScreen();
} }
}), }),
@ -173,7 +173,7 @@ pandora.ui.home = function() {
}) })
.bindEvent({ .bindEvent({
click: function() { click: function() {
pandora.URL.push('/signin'); pandora.UI.set({page :'signin'});
that.fadeOutScreen(); that.fadeOutScreen();
} }
}), }),
@ -192,7 +192,7 @@ pandora.ui.home = function() {
}) })
.bindEvent({ .bindEvent({
click: function() { click: function() {
pandora.URL.push('/preferences'); pandora.UI.set({page: 'preferences'});
that.fadeOutScreen(); that.fadeOutScreen();
} }
}), }),
@ -211,7 +211,7 @@ pandora.ui.home = function() {
}) })
.bindEvent({ .bindEvent({
click: function() { click: function() {
pandora.URL.push('/about'); pandora.UI.set({page: 'about'});
that.fadeOutScreen(); that.fadeOutScreen();
} }
}) })

View file

@ -11,8 +11,10 @@ pandora.ui.item = function() {
}, pandora.user.ui.itemView == 'info' && pandora.site.capabilities.canEditMetadata[pandora.user.level] ? 0 : -1, function(result) { }, pandora.user.ui.itemView == 'info' && pandora.site.capabilities.canEditMetadata[pandora.user.level] ? 0 : -1, function(result) {
if (result.status.code == 200) { if (result.status.code == 200) {
// fixme: can the history state title get updated too? // we want to cache the title in any way, so that after closing
document.title = pandora.getPageTitle(result.data.title); // a dialog and getting to this item, the title is correct
var documentTitle = pandora.getDocumentTitle(result.data.title);
document.title = pandora.getPageTitle(document.location.pathname) || documentTitle;
} }
/*if (result.status.code != 200) { /*if (result.status.code != 200) {

View file

@ -230,7 +230,7 @@ pandora.ui.mainMenu = function() {
'home', 'about', 'news', 'tour', 'faq', 'terms', 'rights', 'contact', 'software', 'home', 'about', 'news', 'tour', 'faq', 'terms', 'rights', 'contact', 'software',
'signup', 'signin', 'signout', 'preferences', 'help' 'signup', 'signin', 'signout', 'preferences', 'help'
].indexOf(data.id) > -1) { ].indexOf(data.id) > -1) {
pandora.URL.push('/' + data.id); pandora.UI.set({page: data.id});
} else if ([ } else if ([
'newlist', 'newlistfromselection', 'newsmartlist', 'newsmartlistfromresults' 'newlist', 'newlistfromselection', 'newsmartlist', 'newsmartlistfromresults'
].indexOf(data.id) > -1) { ].indexOf(data.id) > -1) {

View file

@ -112,8 +112,7 @@ pandora.ui.siteDialog = function(section) {
that.options({ that.options({
title: Ox.getObjectById(tabs, data.selected).title title: Ox.getObjectById(tabs, data.selected).title
}); });
pandora.URL.push({page: data.selected}); pandora.UI.set({page: data.selected});
//history.pushState({page: data.selected}, '', '/' + data.selected);
} }
}); });
@ -125,7 +124,6 @@ pandora.ui.siteDialog = function(section) {
}).bindEvent({ }).bindEvent({
click: function() { click: function() {
that.close(); that.close();
pandora.URL.update();
} }
}) })
], ],
@ -140,6 +138,9 @@ pandora.ui.siteDialog = function(section) {
width: Math.round(window.innerWidth * 0.75), width: Math.round(window.innerWidth * 0.75),
}) })
.bindEvent({ .bindEvent({
close: function(data) {
pandora.UI.set({page: ''});
},
resize: function(data) { resize: function(data) {
if ($tabPanel.selected() == 'contact') { if ($tabPanel.selected() == 'contact') {
pandora.$ui.contactForm.resize(); pandora.$ui.contactForm.resize();

View file

@ -492,6 +492,25 @@ pandora.getClipsQuery = function() {
return clipsQuery; return clipsQuery;
}; };
(function() {
var itemTitles = {};
pandora.getDocumentTitle = function(itemTitle) {
Ox.Log('', 'ITEM TITLES', itemTitles)
if (itemTitle) {
itemTitles[pandora.user.ui.item] = itemTitle
}
var parts = [pandora.site.site.name];
if (!pandora.user.ui.item) {
pandora.user.ui._list && parts.push('List ' + pandora.user.ui._list);
parts.push(Ox.toTitleCase(pandora.user.ui.listView) + ' View');
} else {
parts.push(itemTitles[pandora.user.ui.item] || pandora.user.ui.item);
parts.push(Ox.toTitleCase(pandora.user.ui.itemView) + ' View');
}
return parts.join(' - ');
};
}());
pandora.getFilterSizes = function() { pandora.getFilterSizes = function() {
return Ox.divideInt( return Ox.divideInt(
window.innerWidth - pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize - 1, 5 window.innerWidth - pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize - 1, 5
@ -664,24 +683,26 @@ pandora.getMetadataByIdOrName = function(item, view, str, callback) {
} }
}; };
(function() { pandora.getPageTitle = function(stateOrURL) {
var itemTitles = {}; var pages = Ox.merge([
pandora.getPageTitle = function(itemTitle) { {id: '', title: ''},
Ox.Log('', 'ITEM TITLES', itemTitles) {id: 'help', title: 'Help'},
if (itemTitle) { {id: 'home', title: ''},
itemTitles[pandora.user.ui.item] = itemTitle {id: 'preferences', title: 'Preferences'},
} {id: 'signin', title: 'Sign In'},
var parts = [pandora.site.site.name]; {id: 'signout', title: 'Sign Out'},
if (!pandora.user.ui.item) { {id: 'signup', title: 'Sign Up'},
pandora.user.ui._list && parts.push('List ' + pandora.user.ui._list); {id: 'software', title: 'Software'}
parts.push(Ox.toTitleCase(pandora.user.ui.listView) + ' View'); ], pandora.site.sitePages),
} else { page = Ox.getObjectById(
parts.push(itemTitles[pandora.user.ui.item] || pandora.user.ui.item); pages,
parts.push(Ox.toTitleCase(pandora.user.ui.itemView) + ' View'); Ox.isObject(stateOrURL) ? stateOrURL.page : stateOrURL.substr(1)
} );
return parts.join(' - '); return page
}; ? pandora.site.site.name
}()); + (page.title ? ' - ' + page.title : '')
: null;
};
pandora.getSortKeyData = function(key) { pandora.getSortKeyData = function(key) {
return Ox.getObjectById(pandora.site.itemKeys, key) return Ox.getObjectById(pandora.site.itemKeys, key)