pandora/static/js/home.padma.js

483 lines
16 KiB
JavaScript
Raw Normal View History

2012-01-30 23:56:41 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=javascript
'use strict';
pandora.ui.home = function() {
2012-02-15 09:23:30 +00:00
var self = {},
2012-02-15 09:23:30 +00:00
that = $('<div>')
2012-01-30 23:56:41 +00:00
.addClass('OxScreen')
.css({
position: 'absolute',
width: '100%',
height: '100%',
opacity: 0,
2013-02-19 13:58:53 +00:00
overflowY: 'auto',
2012-02-19 12:58:49 +00:00
zIndex: 1001
2012-01-30 23:56:41 +00:00
}),
2012-02-15 09:23:30 +00:00
$box = $('<div>')
.css({
position: 'absolute',
left: 0,
2013-02-19 13:58:53 +00:00
top: '80px',
2012-02-15 09:23:30 +00:00
right: 0,
width: '560px',
2013-02-19 13:58:53 +00:00
margin: '0 auto 0 auto'
2012-02-15 09:23:30 +00:00
})
.appendTo(that),
2012-01-30 23:56:41 +00:00
$reflectionImage = $('<img>')
.attr({src: '/static/png/logo.png'})
2012-01-30 23:56:41 +00:00
.css({
position: 'absolute',
left: 0,
2012-02-15 09:23:30 +00:00
top: '80px',
2012-01-30 23:56:41 +00:00
right: 0,
bottom: 0,
width: '320px',
height: 'auto',
2012-02-15 09:23:30 +00:00
margin: '0 auto 0 auto',
2012-01-30 23:56:41 +00:00
MozTransform: 'scaleY(-1)',
MsTransform: 'scaleY(-1)',
2012-01-30 23:56:41 +00:00
OTransform: 'scaleY(-1)',
WebkitTransform: 'scaleY(-1)'
})
2012-02-15 09:23:30 +00:00
.appendTo($box),
2012-01-30 23:56:41 +00:00
$reflectionGradient = $('<div>')
.addClass('OxReflection')
.css({
position: 'absolute',
left: 0,
2012-02-15 09:23:30 +00:00
top: '80px',
2012-01-30 23:56:41 +00:00
right: 0,
width: '320px',
height: '160px',
2012-02-15 09:23:30 +00:00
margin: '0 auto 0 auto',
2012-01-30 23:56:41 +00:00
})
2012-02-15 09:23:30 +00:00
.appendTo($box),
2013-02-19 13:58:53 +00:00
$logo = Ox.Element({
element: '<img>',
tooltip: function() {
return Ox._('Enter {0}', [pandora.site.site.name]);
}
2013-02-19 13:58:53 +00:00
})
2012-01-30 23:56:41 +00:00
.attr({
id: 'logo',
src: '/static/png/logo.png'
2012-01-30 23:56:41 +00:00
})
.css({
position: 'absolute',
left: 0,
right: 0,
2012-02-15 09:23:30 +00:00
width: '320px',
height: 'auto',
2012-02-15 09:23:30 +00:00
margin: '0 auto 0 auto',
2012-01-30 23:56:41 +00:00
cursor: 'pointer'
})
.bindEvent({
anyclick: function() {
2012-01-30 23:56:41 +00:00
$browseButton.triggerEvent('click');
}
})
2012-02-15 09:23:30 +00:00
.appendTo($box),
2012-01-30 23:56:41 +00:00
$findInput = Ox.Input({
2012-02-15 09:23:30 +00:00
width: 252
2012-01-30 23:56:41 +00:00
})
.css({
position: 'absolute',
left: 0,
2012-02-15 09:23:30 +00:00
top: '104px',
right: '260px',
2012-01-30 23:56:41 +00:00
bottom: 0,
2012-02-15 09:23:30 +00:00
margin: '0 auto 0 auto',
2012-01-30 23:56:41 +00:00
opacity: 0
})
.on({
click: function(e) {
// fixme: why?
e.stopPropagation();
}
2012-01-30 23:56:41 +00:00
})
.bindEvent({
submit: function(data) {
if (data.value) {
$findButton.triggerEvent('click');
} else {
$browseButton.triggerEvent('click');
}
}
})
2012-02-15 09:23:30 +00:00
.appendTo($box),
2012-01-30 23:56:41 +00:00
$findButton = Ox.Button({
2013-05-09 10:13:58 +00:00
title: Ox._('Find'),
2012-02-15 09:23:30 +00:00
width: 122
2012-01-30 23:56:41 +00:00
})
.css({
position: 'absolute',
2012-02-15 09:23:30 +00:00
left: '130px',
top: '104px',
2012-01-30 23:56:41 +00:00
right: 0,
bottom: 0,
2012-02-15 09:23:30 +00:00
margin: '0 auto 0 auto',
2012-01-30 23:56:41 +00:00
opacity: 0
})
.bindEvent({
click: function() {
var folder = pandora.getListData().folder,
value = $findInput.value();
folder && pandora.$ui.folderList[folder].options({selected: []});
2013-10-07 19:41:20 +00:00
if (pandora.user.ui.section == 'items') {
pandora.$ui.findSelect.value('*');
pandora.$ui.findInput.value(value);
}
2012-01-30 23:56:41 +00:00
that.fadeOutScreen();
pandora.UI.set({
page: '',
find: {
conditions: value === ''
? []
: [{key: '*', value: value, operator: '='}],
operator: '&'
2013-10-07 19:41:20 +00:00
},
section: 'items'
2012-01-30 23:56:41 +00:00
});
}
})
2012-02-15 09:23:30 +00:00
.appendTo($box),
2012-01-30 23:56:41 +00:00
$browseButton = Ox.Button({
2013-05-09 10:13:58 +00:00
title: Ox._('Browse'),
2012-02-15 09:23:30 +00:00
width: 122
2012-01-30 23:56:41 +00:00
})
.css({
position: 'absolute',
2012-02-15 09:23:30 +00:00
left: '390px',
top: '104px',
2012-01-30 23:56:41 +00:00
right: 0,
bottom: 0,
2012-02-15 09:23:30 +00:00
margin: '0 auto 0 auto',
2012-01-30 23:56:41 +00:00
opacity: 0
})
.bindEvent({
click: function() {
pandora.UI.set({
2013-10-07 19:41:20 +00:00
page: pandora.user.ui.page == 'home' ? '' : pandora.user.ui.page,
section: 'items'
});
2012-01-30 23:56:41 +00:00
that.fadeOutScreen();
}
})
2012-02-15 09:23:30 +00:00
.appendTo($box),
2012-01-30 23:56:41 +00:00
$signupButton = Ox.Button({
2013-05-09 10:13:58 +00:00
title: Ox._('Sign Up'),
2012-02-15 09:23:30 +00:00
width: 122
2012-01-30 23:56:41 +00:00
})
.css({
position: 'absolute',
left: 0,
2012-02-15 09:23:30 +00:00
top: '144px',
right: '390px',
2012-01-30 23:56:41 +00:00
bottom: 0,
2012-02-15 09:23:30 +00:00
margin: '0 auto 0 auto',
2012-01-30 23:56:41 +00:00
opacity: 0
})
.bindEvent({
click: function() {
pandora.UI.set({page: 'signup'});
that.fadeOutScreen();
}
}),
2012-01-30 23:56:41 +00:00
$signinButton = Ox.Button({
2013-05-09 10:13:58 +00:00
title: Ox._('Sign In'),
2012-02-15 09:23:30 +00:00
width: 122
2012-01-30 23:56:41 +00:00
})
.css({
position: 'absolute',
left: 0,
2012-02-15 09:23:30 +00:00
top: '144px',
right: '130px',
2012-01-30 23:56:41 +00:00
bottom: 0,
2012-02-15 09:23:30 +00:00
margin: '0 auto 0 auto',
2012-01-30 23:56:41 +00:00
opacity: 0
})
.bindEvent({
click: function() {
pandora.UI.set({page :'signin'});
that.fadeOutScreen();
}
}),
2012-01-30 23:56:41 +00:00
$preferencesButton = Ox.Button({
2013-05-09 10:13:58 +00:00
title: Ox._('Preferences'),
2012-02-15 09:23:30 +00:00
width: 252
2012-01-30 23:56:41 +00:00
})
.css({
position: 'absolute',
left: 0,
2012-02-15 09:23:30 +00:00
top: '144px',
right: '260px',
2012-01-30 23:56:41 +00:00
bottom: 0,
2012-02-15 09:23:30 +00:00
margin: '0 auto 0 auto',
2012-01-30 23:56:41 +00:00
opacity: 0
})
.bindEvent({
click: function() {
pandora.UI.set({page: 'preferences'});
that.fadeOutScreen();
}
}),
2012-01-30 23:56:41 +00:00
$aboutButton = Ox.Button({
2013-05-09 10:13:58 +00:00
title: Ox._('About {0}', [pandora.site.site.name]),
2012-02-15 09:23:30 +00:00
width: 252
2012-01-30 23:56:41 +00:00
})
.css({
position: 'absolute',
2012-02-15 09:23:30 +00:00
left: '260px',
top: '144px',
2012-01-30 23:56:41 +00:00
right: 0,
bottom: 0,
2012-02-15 09:23:30 +00:00
margin: '0 auto 0 auto',
2012-01-30 23:56:41 +00:00
opacity: 0
})
.bindEvent({
click: function() {
pandora.UI.set({page: 'about'});
that.fadeOutScreen();
}
})
2012-02-15 09:23:30 +00:00
.appendTo($box),
$features = $('<div>')
2012-02-15 09:23:30 +00:00
.attr({id: 'lists'})
2012-01-30 23:56:41 +00:00
.css({
position: 'absolute',
left: 0,
2012-02-15 09:23:30 +00:00
top: '184px',
2012-01-30 23:56:41 +00:00
right: 0,
bottom: 0,
2012-02-15 09:23:30 +00:00
width: '560px',
margin: '0 auto 0 auto',
opacity: 0
2012-01-30 23:56:41 +00:00
})
2012-02-15 09:23:30 +00:00
.appendTo($box);
2012-01-30 23:56:41 +00:00
if (pandora.user.level == 'guest') {
2012-02-15 09:23:30 +00:00
$signupButton.appendTo($box);
$signinButton.appendTo($box);
2012-01-30 23:56:41 +00:00
} else {
2012-02-15 09:23:30 +00:00
$preferencesButton.appendTo($box);
}
function showFeatures() {
var $space,
featured = {},
find = {
query: {
conditions: [{key: 'status', value: 'featured', operator: '=='}],
operator: '&'
},
keys: ['description', 'modified', 'name', 'user'],
sort: [{key: 'position', operator: '+'}]
2012-02-15 09:23:30 +00:00
},
2014-02-09 08:45:13 +00:00
items, lists, edits, texts;
2017-02-09 03:50:27 +00:00
pandora.api.getHomeItems({active: true}, function(result) {
items = result.data.items;
lists = 1;
edits = 1;
texts = 1;
show();
});
function show() {
var counter = 0, max = 8, mouse = false, position = 0, selected = 0,
color = Ox.Theme() == 'oxlight' ? 'rgb(0, 0, 0)'
: Ox.Theme() == 'oxmedium' ? 'rgb(0, 0, 0)'
: 'rgb(255, 255, 255)',
2017-02-09 03:50:27 +00:00
$label, $texts,
$featuresBox, $featuresContainer, $featuresContent,
$featureBox = [], $featureIcon = [],
$previousButton, $nextButton;
if (items.length) {
2017-02-09 03:50:27 +00:00
$features.empty();
$texts = Ox.Element().appendTo($features);
var top = 24;
items.forEach(function(item) {
var $text, $icon;
$icon = Ox.Element({
element: '<img>',
tooltip: getTooltip(item)
2012-02-15 09:23:30 +00:00
})
2017-02-09 03:50:27 +00:00
.attr({
src: item.image
2012-02-15 09:23:30 +00:00
})
.css({
2017-02-09 03:50:27 +00:00
left: 0,
right: '390px',
width: '122px',
height: '122px',
borderRadius: '32px',
marginRight: '8px',
cursor: 'pointer',
float: 'left'
2012-02-15 09:23:30 +00:00
})
2017-02-09 03:50:27 +00:00
.bindEvent({
anyclick: function() {
openItem(item);
2012-02-15 09:23:30 +00:00
}
});
2017-02-09 03:50:27 +00:00
$text = Ox.Label({
//width: 386 + 122
})
.addClass('OxSelectable')
.css({
//position: 'absolute',
left: '24px',
//top: top + 'px',
right: 0,
height: 'auto',
padding: '8px 8px 8px 8px',
borderRadius: '32px',
marginBottom: '16px',
overflowY: 'auto',
lineHeight: '14px',
textOverflow: 'ellipsis',
whiteSpace: 'normal'
})
.append($icon)
.append(
Ox.Element().css({
//padding: '8px',
}).html(getHTML(item))
)
.appendTo($texts);
pandora.createLinks($text);
top += 130;
});
$features.animate({opacity: 1}, 250);
}
function getHTML(item) {
2017-02-09 03:50:27 +00:00
return '<b>' + Ox.encodeHTMLEntities(item.title) + '</b><br><br>' + item.text;
}
function getTooltip(item) {
2017-02-09 03:50:27 +00:00
return Ox._('View {0}', [Ox._(Ox.toTitleCase(item.title))])
}
2017-02-09 03:50:27 +00:00
function openItem(item) {
2012-02-15 09:23:30 +00:00
that.fadeOutScreen();
2017-02-09 03:50:27 +00:00
if (item.type == 'custom') {
pandora.URL.push(item.link);
} else {
pandora.UI.set(Ox.extend({
section: item.type == 'list' ? 'items' : item.type + 's',
page: ''
}, item.type == 'list' ? {
find: {
conditions: [{
key: 'list',
value: item.contentid,
operator: '=='
}],
operator: '&'
}
} : item.type == 'collection' ? {
findDocuments: {
conditions: [{
key: 'collection',
value: item.contentid,
operator: '=='
}],
operator: '&'
}
} : item.type == 'edit' ? {
edit: item.contentid
} : {
}));
}
2012-02-15 09:23:30 +00:00
}
2012-02-15 09:23:30 +00:00
function scrollToPosition(i, animate) {
if (i >= 0 && i <= items.length - max && i != position) {
2012-02-15 09:23:30 +00:00
position = i;
$featuresContent.stop().animate({
2012-02-15 09:23:30 +00:00
left: (position * -65) + 'px'
}, animate ? 250 : 0, function() {
if (position == 0) {
$previousButton.removeClass('visible').stop().animate({
opacity: 0
}, 250, function() {
$previousButton.hide();
});
} else {
$previousButton.addClass('visible');
}
if (position == items.length - max) {
2012-02-15 09:23:30 +00:00
$nextButton.removeClass('visible').stop().animate({
opacity: 0
}, 250, function() {
$nextButton.hide();
});
2012-02-15 09:23:30 +00:00
} else {
$nextButton.addClass('visible');
}
if (mouse) {
$featuresBox.trigger('mouseenter');
2012-02-15 09:23:30 +00:00
}
});
}
}
2017-02-09 03:50:27 +00:00
}
2012-01-30 23:56:41 +00:00
}
that.fadeInScreen = function() {
that.appendTo(Ox.$body).animate({opacity: 1}, 500, function() {
2012-02-15 09:23:30 +00:00
that.find('*').animate({opacity: 1}, 250, function() {
2012-01-30 23:56:41 +00:00
$findInput.focusInput(true);
2013-07-10 12:27:44 +00:00
showFeatures();
2012-01-30 23:56:41 +00:00
});
});
return that;
};
that.fadeOutScreen = function() {
2013-02-19 13:58:53 +00:00
$('.OxTooltip').remove();
2012-02-17 09:38:03 +00:00
that.animate({opacity: 0}, 500, function() {
2012-01-30 23:56:41 +00:00
that.remove();
});
pandora.$ui.tv && pandora.$ui.tv.unmute().find('.OxControls.OxVolume').hide();
2012-05-28 14:10:11 +00:00
self.keydown && Ox.$document.off({keydown: self.keydown});
2012-01-30 23:56:41 +00:00
return that;
};
that.showScreen = function(callback) {
2013-07-09 11:18:41 +00:00
var $elements = that.find('*'), count = 0;
$box.css({top: window.innerHeight / 2 - 80 + 'px'});
that.css({opacity: 1}).appendTo(Ox.$body);
2012-02-20 18:44:49 +00:00
$findInput.focusInput(true);
2013-07-09 11:18:41 +00:00
$box.animate({top: '80px'}, 500, function() {
$elements.animate({opacity: 1}, 250, function() {
if (++count == $elements.length) {
2013-07-10 12:27:44 +00:00
showFeatures();
2013-07-09 11:18:41 +00:00
callback && callback();
}
2012-02-17 09:38:03 +00:00
});
2013-07-09 11:18:41 +00:00
});
2012-01-30 23:56:41 +00:00
return that;
};
return that;
};