pandora/static/js/pandora/home.padma.js

596 lines
22 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 = {},
that = $('<div>')
2012-01-30 23:56:41 +00:00
.addClass('OxScreen')
.css({
position: 'absolute',
width: '100%',
height: '100%',
opacity: 0,
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,
top: 0,
right: 0,
bottom: 0,
width: '560px',
margin: window.innerHeight / 2 - 80 + 'px auto 0 auto'
})
.appendTo(that),
2012-01-30 23:56:41 +00:00
$reflectionImage = $('<img>')
.attr({src: '/static/png/logo256.png'})
.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',
2012-02-15 09:23:30 +00:00
margin: '0 auto 0 auto',
2012-01-30 23:56:41 +00:00
MozTransform: 'scaleY(-1)',
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),
2012-01-30 23:56:41 +00:00
$logo = $('<img>')
.attr({
id: 'logo',
src: '/static/png/logo256.png'
})
.css({
position: 'absolute',
left: 0,
right: 0,
2012-02-15 09:23:30 +00:00
width: '320px',
margin: '0 auto 0 auto',
2012-01-30 23:56:41 +00:00
cursor: 'pointer'
})
.bind({
click: function() {
$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
})
.click(function(e) {
// fixme: why?
e.stopPropagation();
})
.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({
title: '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: []});
pandora.$ui.findSelect.value('*');
pandora.$ui.findInput.value(value);
that.fadeOutScreen();
pandora.UI.set({
page: '',
find: {
conditions: value === ''
? []
: [{key: '*', value: value, operator: '='}],
operator: '&'
}
});
}
})
2012-02-15 09:23:30 +00:00
.appendTo($box),
2012-01-30 23:56:41 +00:00
$browseButton = Ox.Button({
title: '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({
page: pandora.user.ui.page == 'home' ? '' : pandora.user.ui.page
});
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({
title: '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();
}
}),
$signinButton = Ox.Button({
title: '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();
}
}),
$preferencesButton = Ox.Button({
title: '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();
}
}),
$aboutButton = Ox.Button({
title: 'About ' + 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),
$lists = $('<div>')
.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 showLists() {
pandora.api.findLists({
query: {
conditions: [{key: 'status', value: 'featured', operator: '=='}],
operator: '&'
},
keys: ['user', 'name', 'description'],
sort: [{key: 'position', operator: '+'}]
}, function(result) {
var lists = result.data.items,
counter = 0, items = 8, mouse = false, position = 0, selected = 0,
2012-02-15 09:23:30 +00:00
color = Ox.Theme() == 'classic'
? 'rgb(32, 32, 32)' : 'rgb(224, 224, 224)',
2012-02-15 09:23:30 +00:00
$label, $icon, $text,
$listsBox, $listsContainer, $listsContent,
$listBox = [], $listIcon = [],
2012-02-15 09:23:30 +00:00
$previousButton, $nextButton;
$lists.empty();
2012-02-15 09:23:30 +00:00
if (lists.length) {
$label = Ox.Label({
textAlign: 'center',
title: '<b>Featured List' + (lists.length >= items ? 's' : '') + '</b>',
width: 512
})
.css({
position: 'absolute',
left: 0,
top: 0,
right: 0,
bottom: 0,
margin: '0 auto 0 auto'
})
.appendTo($lists);
$text = Ox.Label({
width: 386
})
.addClass('OxSelectable')
.css({
position: 'absolute',
left: '24px',
top: '24px',
right: 0,
height: '104px',
borderTopLeftRadius: '32px',
borderBottomLeftRadius: '32px',
padding: '8px 8px 8px 130px',
overflowY: 'auto',
textOverflow: 'ellipsis',
whiteSpace: 'normal'
})
.html(
'<b>' + lists[selected].name + '</b><br><br>'
+ lists[selected].description
)
.appendTo($lists);
pandora.createLinks($text);
2012-02-15 09:23:30 +00:00
$icon = Ox.Element({
element: '<img>',
tooltip: 'View List'
})
.attr({
src: '/list/' + lists[selected].user + ':'
+ lists[selected].name + '/icon256.jpg'
})
.css({
position: 'absolute',
left: 0,
top: '24px',
right: '390px',
width: '122px',
height: '122px',
borderRadius: '32px',
margin: '0 auto 0 auto',
cursor: 'pointer'
})
.bindEvent({
anyclick: function() {
openList(selected);
}
})
.appendTo($lists);
if (lists.length >= items) {
$listsBox = $('<div>')
.css({
position: 'absolute',
left: 0,
top: '150px',
right: 0,
height: '65px', // 4+57+4
width: '560px', // 16+8+512+8+16
margin: '0 auto 0 auto'
})
.appendTo($lists);
$listsContainer = $('<div>')
.css({
position: 'absolute',
left: '20px',
right: '20px',
height: '65px',
width: '520px',
overflow: 'hidden'
})
.appendTo($listsBox);
$listsContent = $('<div>')
.css({
position: 'absolute',
width: lists.length * 65 + 'px',
height: '65px'
})
.appendTo($listsContainer);
if (lists.length > items) {
$previousButton = Ox.Button({
title: 'left',
type: 'image'
})
.addClass(position > 0 ? 'visible' : '')
.css({
position: 'absolute',
left: 0,
top: '25px',
opacity: 0
})
.hide()
.bindEvent({
mousedown: function() {
scrollToPosition(position - 1, true);
},
mouserepeat: function() {
scrollToPosition(position - 1, false);
}
})
.appendTo($listsBox);
$nextButton = Ox.Button({
title: 'right',
type: 'image'
})
.addClass(position < lists.length - 1 ? 'visible' : '')
.css({
position: 'absolute',
right: 0,
top: '25px',
opacity: 0
})
.hide()
.bindEvent({
mousedown: function() {
counter = 0;
2012-02-15 09:23:30 +00:00
scrollToPosition(position + 1, true);
},
mouserepeat: function() {
if (counter++ % 10 == 0) {
scrollToPosition(position + 1, false);
}
2012-02-15 09:23:30 +00:00
}
})
.appendTo($listsBox);
$listsBox.bind({
mouseenter: function() {
mouse = true;
$('.visible').show().stop().animate({
opacity: 1
}, 250);
},
mouseleave: function() {
mouse = false;
$('.visible').stop().animate({
opacity: 0
}, 250, function() {
$(this).hide();
});
},
mousewheel: function(e, delta, deltaX, deltaY) {
Ox.print('mwd', deltaX)
scrollToPosition(position + Math.round(deltaX), true);
2012-02-15 09:23:30 +00:00
}
});
self.keydown = function(e) {
var focused = Ox.Focus.focused(),
key = Ox.KEYS[e.keyCode];
if (
focused === null
|| !Ox.UI.elements[focused].hasClass('OxInput')
) {
if (key == 'left' && selected > 0) {
selectList(selected - 1);
} else if (key == 'up' && selected > 0) {
selectList(0);
} else if (key == 'right' && selected < lists.length - 1) {
selectList(selected + 1);
} else if (key == 'down' && selected < lists.length - 1) {
selectList(lists.length - 1);
}
}
};
2012-02-15 09:23:30 +00:00
Ox.$document.bind({keydown: self.keydown});
}
lists.forEach(function(list, i) {
$listBox[i] = $('<div>')
.css({
float: 'left',
width: '57px',
height: '57px',
padding: '2px',
margin: '2px',
borderRadius: '16px',
boxShadow: '0 0 2px ' + (i == selected ? color : 'transparent')
})
.appendTo($listsContent);
$listIcon[i] = Ox.Element({
2012-02-15 09:23:30 +00:00
element: '<img>',
tooltip: list.name
})
.attr({
src: '/list/' + list.user + ':'
+ list.name + '/icon256.jpg'
})
.css({
width: '57px',
height: '57px',
borderRadius: '16px',
cursor: 'pointer'
})
.bindEvent({
doubleclick: function() {
openList(i);
},
singleclick: function() {
selectList(i);
}
})
.appendTo($listBox[i]);
2012-02-15 09:23:30 +00:00
});
}
$lists.animate({opacity: 1}, 250);
}
function openList(i) {
that.fadeOutScreen();
pandora.UI.set({
page: '',
find: {
conditions: [{
key: 'list',
value: lists[i].user + ':'
+ lists[i].name,
operator: '=='
}],
operator: '&'
}
});
}
function scrollToPosition(i, animate) {
if (i >= 0 && i <= lists.length - items && i != position) {
position = i;
$listsContent.stop().animate({
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 == lists.length - items) {
$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) {
$listsBox.trigger('mouseenter');
}
});
}
}
function selectList(i) {
if (i >= 0 && i <= lists.length - 1 && i != selected) {
$listBox[selected].css({
2012-02-15 09:23:30 +00:00
boxShadow: 'none'
});
selected = i;
$listBox[selected].css({
2012-02-15 09:23:30 +00:00
boxShadow: '0 0 2px ' + color
});
if (selected < position) {
scrollToPosition(selected, true);
} else if (selected > position + items - 1) {
scrollToPosition(selected - items + 1, true);
}
$icon.attr({
src: '/list/' + lists[selected].user + ':'
+ lists[selected].name + '/icon256.jpg'
});
$text.html(
'<b>' + lists[selected].name + '</b><br><br>'
+ lists[selected].description
);
}
}
});
2012-01-30 23:56:41 +00:00
}
that.fadeInScreen = function() {
2012-02-15 09:23:30 +00:00
$box.css({marginTop: '80px'});
2012-01-30 23:56:41 +00:00
that.appendTo(Ox.UI.$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);
2012-02-15 09:23:30 +00:00
showLists();
2012-01-30 23:56:41 +00:00
});
});
return that;
};
that.fadeOutScreen = function() {
2012-02-17 09:38:03 +00:00
that.animate({opacity: 0}, 500, function() {
2012-01-30 23:56:41 +00:00
that.remove();
});
2012-02-19 12:58:49 +00:00
pandora.$ui.tv && pandora.$ui.tv.unmute();
2012-02-15 09:23:30 +00:00
self.keydown && Ox.$document.unbind({keydown: self.keydown});
2012-01-30 23:56:41 +00:00
return that;
};
that.showScreen = function() {
that.css({opacity: 1}).appendTo(Ox.UI.$body);
2012-02-17 09:38:03 +00:00
$box.animate({marginTop: '80px'}, 500);
setTimeout(function() {
that.find('*').animate({opacity: 1}, 250, function() {
$findInput.focusInput(true);
showLists();
});
}, 250);
2012-01-30 23:56:41 +00:00
return that;
};
return that;
};