make external links work in info view

This commit is contained in:
rolux 2011-08-07 17:05:49 +00:00
parent d5d8701dc1
commit 05112101cc
2 changed files with 29 additions and 27 deletions

View file

@ -3,12 +3,11 @@
pandora.URL = (function() { pandora.URL = (function() {
var old = { var regexps = {
user: { '^\\?url=': function(url) {
ui: {} Ox.print('URL', url)
} document.location = decodeURIComponent(url.substr(5));
}, },
regexps = {
'^\\?': function(url) { '^\\?': function(url) {
pandora.Query.fromString(url); pandora.Query.fromString(url);
pandora.UI.set({ pandora.UI.set({
@ -33,7 +32,7 @@ pandora.URL = (function() {
sitePage: url sitePage: url
}); });
}, },
'^(find)$': function() { '^find$': function() {
pandora.Query.fromString('?find='); // fixme: silly hack pandora.Query.fromString('?find='); // fixme: silly hack
pandora.UI.set({ pandora.UI.set({
section: 'items', section: 'items',
@ -47,6 +46,11 @@ pandora.URL = (function() {
}); });
pandora.UI.set(['lists', pandora.user.ui.list, 'listView'].join('|'), url); pandora.UI.set(['lists', pandora.user.ui.list, 'listView'].join('|'), url);
}, },
'^texts$': function() {
pandora.UI.set({
section: 'texts'
});
},
'^[0-9A-Z]': function(url) { '^[0-9A-Z]': function(url) {
var split = url.split('/'), var split = url.split('/'),
item = split[0], item = split[0],
@ -61,11 +65,6 @@ pandora.URL = (function() {
item: item, item: item,
itemView: view itemView: view
}); });
},
'^texts$': function() {
pandora.UI.set({
section: 'texts'
});
} }
}; };
@ -75,8 +74,11 @@ pandora.URL = (function() {
if (arguments.length == 1) { // fixme: remove later if (arguments.length == 1) { // fixme: remove later
url = title; url = title;
} }
history.pushState({}, pandora.site.site.name + (title ? ' - ' + title : ''), '/' + url); if (url[0] != '/') {
old.user.ui = $.extend({}, pandora.user.ui); // make a clone url = '/' + url;
}
history.pushState({}, pandora.site.site.name + (title ? ' - ' + title : ''), url);
oldUserUI = Ox.clone(pandora.user.ui);
this.update(); this.update();
}, },
@ -97,29 +99,29 @@ pandora.URL = (function() {
update: function() { update: function() {
this.parse(); this.parse();
if (pandora.user.ui.section != old.user.ui.section) { if (pandora.user.ui.section != oldUserUI.section) {
pandora.$ui.appPanel.replaceElement(1, pandora.$ui.mainPanel = pandora.ui.mainPanel()); pandora.$ui.appPanel.replaceElement(1, pandora.$ui.mainPanel = pandora.ui.mainPanel());
} else if (pandora.user.ui.sitePage != old.user.ui.sitePage) { } else if (pandora.user.ui.sitePage != oldUserUI.sitePage) {
pandora.$ui.mainPanel.replaceElement(1, pandora.$ui.rightPanel = pandora.ui.rightPanel()); pandora.$ui.mainPanel.replaceElement(1, pandora.$ui.rightPanel = pandora.ui.rightPanel());
} else if (!pandora.user.ui.item || !old.user.ui.item) { } else if (!pandora.user.ui.item || !oldUserUI.item) {
pandora.$ui.mainPanel.replaceElement(1, pandora.$ui.rightPanel = pandora.ui.rightPanel()); pandora.$ui.mainPanel.replaceElement(1, pandora.$ui.rightPanel = pandora.ui.rightPanel());
pandora.$ui.leftPanel.replaceElement(2, pandora.$ui.info = pandora.ui.info()); pandora.$ui.leftPanel.replaceElement(2, pandora.$ui.info = pandora.ui.info());
} else { } else {
pandora.$ui.contentPanel.replaceElement(1, pandora.ui.item()); pandora.$ui.contentPanel.replaceElement(1, pandora.ui.item());
pandora.$ui.leftPanel.replaceElement(2, pandora.$ui.info = pandora.ui.info()); pandora.$ui.leftPanel.replaceElement(2, pandora.$ui.info = pandora.ui.info());
} }
// fixme: should be 'editor', not 'timeline'
if ( if (
old.user.ui.item && oldUserUI.item &&
['player', 'timeline'].indexOf(old.user.ui.itemView) > -1 ['player', 'timeline'].indexOf(oldUserUI.itemView) > -1
) { ) {
pandora.UI.set( pandora.UI.set(
'videoPosition|' + old.user.ui.item, 'videoPosition|' + oldUserUI.item,
pandora.$ui[ pandora.$ui[
old.user.ui.itemView == 'player' ? 'player' : 'editor' oldUserUI.itemView == 'player' ? 'player' : 'editor'
].options('position') ].options('position')
); );
} }
//delete old.user.ui;
} }
}; };

View file

@ -89,9 +89,9 @@ pandora.ui.infoView = function(data) {
.bind({ .bind({
click: function(e) { click: function(e) {
var $target = $(e.target); var $target = $(e.target);
if ($target.is('.OxLink')) { if ($target.is('a')) {
Ox.print('LINK', $target.data('link')); pandora.URL.set($target.attr('href'));
pandora.URL.set($target.data('link')); return false;
} }
} }
}) })
@ -304,7 +304,7 @@ pandora.ui.infoView = function(data) {
.css(css) .css(css)
.html( .html(
formatKey(key) + data[key].map(function(value) { formatKey(key) + data[key].map(function(value) {
return '<a href="' + value.url + '">' + value.source + '</a>' return '<a href="/?url=' + encodeURIComponent(value.url) + '">' + value.source + '</a>'
}).join(', ') }).join(', ')
) )
.appendTo($text); .appendTo($text);
@ -431,7 +431,7 @@ pandora.ui.infoView = function(data) {
function formatValue(value, key) { function formatValue(value, key) {
return (Ox.isArray(value) ? value : [value]).map(function(value) { return (Ox.isArray(value) ? value : [value]).map(function(value) {
return key ? return key ?
'<span class="OxLink" data-link="?find=' + key + ':' + value + '">' + value + '</span>' '<a href="/?find=' + key + ':' + value + '">' + value + '</a>'
: value; : value;
//return key ? '<a href="/?find=' + key + ':' + value + '">' + value + '</a>' : value; //return key ? '<a href="/?find=' + key + ':' + value + '">' + value + '</a>' : value;
}).join(', '); }).join(', ');