/
netflixq.js
53 lines (40 loc) · 1.21 KB
/
netflixq.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Y.use('node', function(Y) {
var selectors = {
Q_LIST: '#netflixq',
REMOVE_TARGET: 'img.remove'
};
var lStore = (('localStorage' in window) && window['localStorage'] !== null) ? window.localStorage : false ;
function getList() {
return JSON.parse(lStore.getItem('NetflixQList'));
}
function saveList (toSave) {
lStore.setItem('NetflixQList', JSON.stringify(toSave));
}
var movies = [],
movieTemp = '<div class="movie" id="{id}"><img width="16" height="16" class="remove" src="no.png"><a target="_blank" href="{url}">{title}</a></div>';
Y.each(getList(), function(v,k) {
v.id = k;
movies.push(Y.Lang.sub(movieTemp, v));
});
if(movies.length > 0) {
Y.one(selectors.Q_LIST).setContent(movies.join(''));
}
//Clicks on the remove box
Y.one(selectors.Q_LIST).delegate('click', function(e) {
var toRemove = e.target.ancestor('div');
var nq = getList();
if(!Y.Lang.isNull(nq)) {
delete nq[toRemove.get('id')];
}
saveList(nq);
toRemove.transition({
duration: 0.3, // seconds
// easing: 'ease-out',
height: 0,
padding: 0,
opacity: 0
}, function() {
toRemove.remove().destroy();
});
}, selectors.REMOVE_TARGET);
});