Skip to content

Commit

Permalink
recent-channel-list
Browse files Browse the repository at this point in the history
  • Loading branch information
rnons committed Oct 19, 2012
1 parent fae13a3 commit 2b16649
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 15 deletions.
6 changes: 6 additions & 0 deletions css/popup.css
Expand Up @@ -89,4 +89,10 @@ a:hover{opacity:0.8}
background: url("../img/rated.png") no-repeat right top;
z-index: 9999;
}
.del-recent-channel {
float: right;
height: 20px;
background: url("../img/rated.png") no-repeat right top;
z-index: 9999;
}

4 changes: 1 addition & 3 deletions popup.html
Expand Up @@ -82,11 +82,9 @@
<div id="ss_intros">推荐兆赫</div>
<div id="fast_songs_sec">上升最快</div>
</div>
<div style="display: none">
re
<div id="channel_recent" style="display: none">
</div>
<div id="channel_fav" style="display: none">
fa
</div>
</div>
</ul>
Expand Down
43 changes: 43 additions & 0 deletions scripts/player.js
@@ -1,3 +1,29 @@
// https://github.com/prettycode/Object.identical.js
Object.identical = function (a, b, sortArrays) {
function sort(object) {

if (sortArrays === true && Array.isArray(object)) {
return object.sort();
}
else if (typeof object !== "object" || object === null) {
return object;
}

var result = [];

Object.keys(object).sort().forEach(function(key) {
result.push({
key: key,
value: sort(object[key])
});
});

return result;
}

return JSON.stringify(sort(a)) === JSON.stringify(sort(b));
};

var radio = opera.extension.bgProcess.radio;
console.log(radio.channel);

Expand Down Expand Up @@ -196,6 +222,23 @@ $(".channel-box li").live("click", function () {
radio.powerOn();
showSong();
}
var c = {};
c.cid = $(this).data("cid");
c.name = $(this).text();
c.intro = $(this).find("a").attr("title");
var recent_channels = [];
if (localStorage.recent_channels !== 'undefined') {
recent_channels = JSON.parse(localStorage.recent_channels);
var i=recent_channels.length
while (i--) {
if (Object.identical(recent_channels[i], c)) {
recent_channels.splice(i, 1);
}
}
}
console.log(c.name);
recent_channels.push(c);
localStorage.recent_channels = JSON.stringify(recent_channels);
})

$("#close_c").bind("click", function () {
Expand Down
70 changes: 58 additions & 12 deletions scripts/popup.js
Expand Up @@ -8,6 +8,7 @@ for (c in intro_channels) {
intro = intro_channels[c].intro;
$('<li data-cid=' + cid + ' class="channel"><a title=' + intro +'>' + name + '</a></li>').appendTo('div#ss_intros');
}

for (c in fast_channels) {
//console.log(channels[c].cid, channels[c].name);
cid = fast_channels[c].cid;
Expand All @@ -17,16 +18,27 @@ for (c in fast_channels) {
}
$('<button class="rate-channel" title="rate"/>').appendTo('li.channel');

if ( typeof localStorage.fav_channels !== 'undefined') {
var fav_channels = JSON.parse(localStorage.fav_channels);
for (c in fav_channels) {
cid = fav_channels[c].cid;
name = fav_channels[c].name;
intro = fav_channels[c].intro;
$('<li data-cid=' + cid + ' class="channel-fav"><a title=' + intro +'>' + name + '</a></li>').appendTo('div#channel_fav');
if (localStorage.fav_channels !== 'undefined') {
var fav_channels = JSON.parse(localStorage.fav_channels);
for (c in fav_channels) {
cid = fav_channels[c].cid;
name = fav_channels[c].name;
intro = fav_channels[c].intro;
$('<li data-cid=' + cid + ' class="channel-fav"><a title=' + intro +'>' + name + '</a></li>').appendTo('div#channel_fav');
}
$('<button class="unrate-channel" title="unrate"/>').appendTo('li.channel-fav');
}
$('<button class="unrate-channel" title="unrate"/>').appendTo('li.channel-fav');

if (localStorage.recent_channels !== 'undefined') {
var recent_channels = JSON.parse(localStorage.recent_channels);
for (c in recent_channels) {
cid = recent_channels[c].cid;
name = recent_channels[c].name;
intro = recent_channels[c].intro;
$('<li data-cid=' + cid + ' class="channel-recent"><a title=' + intro +'>' + name + '</a></li>').appendTo('div#channel_recent');
}
$('<button class="del-recent-channel" title="unrate"/>').appendTo('li.channel-recent');
}
});

$('.channel-tab > li').click(function() {
Expand All @@ -45,7 +57,18 @@ $('.rate-channel').live("click", function (e) {
if ( typeof localStorage.fav_channels !== 'undefined') {
fav_channels = JSON.parse(localStorage.fav_channels);
}
fav_channels.push(c)
//console.log(fav_channels.indexOf(c));
//if ( fav_channels.indexOf(c) === -1 ) {
var flag = 0;
var i=fav_channels.length
while (i--) {
if (Object.identical(fav_channels[i], c)) {
flag += 1;
}
}
if (flag === 0 ) {
fav_channels.push(c)
}
localStorage.fav_channels = JSON.stringify(fav_channels);
e.stopPropagation();
});
Expand All @@ -57,14 +80,37 @@ $('.unrate-channel').live("click", function (e) {
c.name = $channel.text();
c.intro = $channel.find("a").attr("title");
fav_channels = JSON.parse(localStorage.fav_channels);
while (fav_channels.indexOf(c) !== -1) {
fav_channels.splice(fav_channels.indexOf(c), 1);
// if (fav_channels.indexOf(c) !== -1) { doesn't work
var i=fav_channels.length;
while (i--) {
if (Object.identical(fav_channels[i], c)) {
fav_channels.splice(i, 1);
}
}

fav_channels.pop(c)
//fav_channels.pop(c)
localStorage.fav_channels = JSON.stringify(fav_channels);
e.stopPropagation();
});
$('.del-recent-channel').live("click", function (e) {
$channel = $(this).parent();
var c = {};
c.cid = $channel.data("cid");
c.name = $channel.text();
c.intro = $channel.find("a").attr("title");
recent_channels = JSON.parse(localStorage.recent_channels);
// if (recent_channels.indexOf(c) !== -1) { doesn't work
var i=recent_channels.length;
while (i--) {
if (Object.identical(recent_channels[i], c)) {
recent_channels.splice(i, 1);
}
}

//recent_channels.pop(c)
localStorage.recent_channels = JSON.stringify(recent_channels);
e.stopPropagation();
});
// console.log(channels[i].cid, channels[i].name);
//console.log(channels[0].cid, channels[0].name);

Expand Down

0 comments on commit 2b16649

Please sign in to comment.