pandora/static/js/pandora/toolbar.js

94 lines
3.2 KiB
JavaScript
Raw Normal View History

2011-07-29 18:37:11 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=javascript
2011-11-05 17:04:10 +00:00
'use strict';
2011-05-25 19:42:45 +00:00
pandora.ui.toolbar = function() {
2011-10-01 13:51:18 +00:00
var ui = pandora.user.ui,
isNavigationView = !ui.item
&& ['map', 'calendar'].indexOf(ui.listView) > -1,
2011-10-01 13:51:18 +00:00
that = Ox.Bar({
2011-05-25 19:42:45 +00:00
size: 24
}).css({
zIndex: 2 // fixme: remove later
});
2011-10-01 13:51:18 +00:00
ui.item && that.append(
2011-06-06 15:48:11 +00:00
pandora.$ui.backButton = pandora.ui.backButton()
2011-05-25 19:42:45 +00:00
);
that.append(
2011-10-29 17:46:46 +00:00
pandora.$ui.viewSelect = pandora.ui.viewSelect()
2011-05-25 19:42:45 +00:00
);
!ui.item && !isNavigationView && that.append(
pandora.$ui.sortSelect = pandora.ui.sortSelect()
).append(
pandora.$ui.orderButton = pandora.ui.orderButton()
);
that.append(
!ui.item
? pandora.$ui.listTitle = Ox.Label({
textAlign: 'center',
title: getListName(pandora.user.ui._list)
})
.css({
position: 'absolute',
left: getListTitleLeft() + 'px',
top: '4px',
right: (ui._list ? 324 : 310) + 'px',
width: 'auto'
})
: pandora.$ui.itemTitle = Ox.Label({
textAlign: 'center'
})
.css({
position: 'absolute',
left: '236px',
top: '4px',
right: (ui._list ? 324 : 310) + 'px',
width: 'auto'
})
.hide()
2011-10-30 21:05:57 +00:00
);
2011-05-25 19:42:45 +00:00
that.append(
2011-06-06 15:48:11 +00:00
pandora.$ui.findElement = pandora.ui.findElement()
2011-05-25 19:42:45 +00:00
);
that.bindEvent({
pandora_listview: function(data) {
var isNavigationView, wasNavigationView;
if (!pandora.user.ui.item) {
isNavigationView = ['map', 'calendar'].indexOf(data.value) > -1;
wasNavigationView = ['map', 'calendar'].indexOf(data.previousValue) > -1;
if (isNavigationView != wasNavigationView) {
if (isNavigationView) {
pandora.$ui.sortSelect.remove();
pandora.$ui.orderButton.remove();
} else {
pandora.$ui.sortSelect = pandora.ui.sortSelect().insertAfter(pandora.$ui.viewSelect);
pandora.$ui.orderButton = pandora.ui.orderButton().insertAfter(pandora.$ui.sortSelect);
}
pandora.$ui.listTitle.css({left: getListTitleLeft() + 'px'});
} else if ((data.value == 'clip') != (data.previousValue == 'clip')) {
pandora.$ui.sortSelect.replaceWith(
pandora.$ui.sortSelect = pandora.ui.sortSelect()
);
}
2011-09-27 22:12:37 +00:00
}
}
});
function getListName(listId) {
return '<b>' + (
listId == ''
? 'All ' + pandora.site.itemName.plural
2012-05-24 09:56:52 +00:00
: Ox.encodeHTMLEntities(listId.slice(listId.indexOf(':') + 1))
) + '</b>';
}
function getListTitleLeft() {
2012-03-20 19:16:16 +00:00
return 320 - (
2012-03-20 19:17:53 +00:00
['map', 'calendar'].indexOf(pandora.user.ui.listView) > -1 ? 168 : 0
);
}
that.updateListName = function(listId) {
pandora.$ui.listTitle.options({title: getListName(listId)});
};
2011-05-25 19:42:45 +00:00
return that;
};