diff --git a/css/player.css b/css/player.css index 78361c2..49eb725 100644 --- a/css/player.css +++ b/css/player.css @@ -1041,3 +1041,18 @@ li { .settings-content { padding: 20px; } + +.btn-group button,.btn-pagination,.btn-pagination:focus { + background-color: #333333; + color: #ffffff; + border-color: #333333; +} + +.btn-group button:hover,.btn-pagination:hover { + background-color: #ffffff; + color: #333333; +} + +.searchbox li>a:hover{ +color: #333333; +} \ No newline at end of file diff --git a/js/app.js b/js/app.js index 914d1a2..387f359 100644 --- a/js/app.js +++ b/js/app.js @@ -928,20 +928,22 @@ $scope.tab = 0; $scope.keywords = ''; $scope.loading = false; + $scope.curpagelog = [1,1,1]; // [网易,虾米,QQ] + $scope.totalpagelog = [1,1,1]; + $scope.curpage = 1; + $scope.totalpage = 1; $scope.changeTab = function(newTab){ $scope.loading = true; $scope.tab = newTab; $scope.result = []; + updateCurrentPage(); + updateTotalPage(); if ($scope.keywords===''){ $scope.loading = false; }else{ - loWeb.get('/search?source=' + getSourceName($scope.tab) + '&keywords=' + $scope.keywords).success(function(data) { - // update the textarea - $scope.result = data.result; - $scope.loading = false; - }); + performSearch(); } }; @@ -950,6 +952,8 @@ }; $scope.$watch('keywords', function (tmpStr) { + updateCurrentPage(-1); + updateTotalPage(-1); if (!tmpStr || tmpStr.length === 0){ $scope.result = []; return 0; @@ -958,16 +962,63 @@ // go ahead and retrieve the data if (tmpStr === $scope.keywords) { - $scope.loading = true; - loWeb.get('/search?source=' + getSourceName($scope.tab) + '&keywords=' + $scope.keywords).success(function(data) { - // update the textarea - $scope.result = data.result; - $scope.loading = false; - }); + performSearch(); } }); + + function performSearch(){ + loWeb.get('/search?source=' + getSourceName($scope.tab) + '&keywords=' + $scope.keywords+'&curpage='+ $scope.curpage).success(function(data) { + // update the textarea + $scope.result = data.result; + updateTotalPage(data.total); + $scope.loading = false; + }); + } + + function updateCurrentPage(cp){ + if(cp === -1){ // when search words changes,pagenums should be reset. + $scope.curpagelog = [1,1,1]; + $scope.curpage = 1; + } + else if(cp >= 0) + $scope.curpage = $scope.curpagelog[$scope.tab] = cp; + else // only tab changed + $scope.curpage = $scope.curpagelog[$scope.tab]; + } + + function updateTotalPage(totalItem){ + if(totalItem === -1) { + $scope.totalpagelog = [1,1,1]; + $scope.totalpage = 1; + } + else if(totalItem >=0) + $scope.totalpage=$scope.totalpagelog[$scope.tab] = Math.ceil(totalItem/20); + else + //just switch tab + $scope.totalpage=$scope.totalpagelog[$scope.tab]; + } + + $scope.nextPage = function(){ + $scope.curpage = $scope.curpagelog[$scope.tab] += 1; + performSearch(); + } + + $scope.previousPage = function(){ + $scope.curpage = $scope.curpagelog[$scope.tab] -= 1; + performSearch(); + } }]); + app.directive('pagination',function(){ + return { + restrict: "EA", + replace:false, + template: ' \ + \ + ', + } +}); + app.directive('errSrc', function() { // http://stackoverflow.com/questions/16310298/if-a-ngsrc-path-resolves-to-a-404-is-there-a-way-to-fallback-to-a-default return { diff --git a/js/provider/netease.js b/js/provider/netease.js index 81d266e..e2114c5 100644 --- a/js/provider/netease.js +++ b/js/provider/netease.js @@ -231,9 +231,10 @@ var netease = (function() { // use chrome extension to modify referer. var target_url = 'http://music.163.com/api/search/pc'; var keyword = getParameterByName('keywords', url); + var curpage = getParameterByName('curpage', url); var req_data = { 's': keyword, - 'offset': 0, + 'offset': 20*(curpage-1), 'limit': 20, 'type': 1 }; @@ -269,7 +270,7 @@ var netease = (function() { } tracks.push(default_track); }); - return fn({"result":tracks}); + return fn({"result":tracks,"total":data.result.songCount}); }); } }; diff --git a/js/provider/qq.js b/js/provider/qq.js index f9682a0..2f8f9ec 100644 --- a/js/provider/qq.js +++ b/js/provider/qq.js @@ -205,11 +205,12 @@ var qq = (function() { return { success: function(fn) { var keyword = getParameterByName('keywords', url); + var curpage = getParameterByName('curpage', url); var target_url = 'http://i.y.qq.com/s.music/fcgi-bin/search_for_qq_cp?' + 'g_tk=938407465&uin=0&format=jsonp&inCharset=utf-8' + '&outCharset=utf-8¬ice=0&platform=h5&needNewCode=1' + '&w=' + keyword + '&zhidaqu=1&catZhida=1' + - '&t=0&flag=1&ie=utf-8&sem=1&aggr=0&perpage=20&n=20&p=1' + + '&t=0&flag=1&ie=utf-8&sem=1&aggr=0&perpage=20&n=20&p=' + curpage + '&remoteplace=txt.mqq.all&_=1459991037831&jsonpCallback=jsonp4'; hm({ url:target_url, @@ -224,7 +225,7 @@ var qq = (function() { var track = qq_convert_song(item); tracks.push(track); }); - return fn({"result":tracks}); + return fn({"result":tracks,"total":data.data.song.totalnum}); }); } }; diff --git a/js/provider/xiami.js b/js/provider/xiami.js index 2f5a72a..2e8182f 100644 --- a/js/provider/xiami.js +++ b/js/provider/xiami.js @@ -139,7 +139,8 @@ var xiami = (function() { return { success: function(fn) { var keyword = getParameterByName('keywords', url); - var target_url = 'http://api.xiami.com/web?v=2.0&app_key=1&key=' + keyword + '&page=1&limit=50&callback=jsonp154&r=search/songs'; + var curpage = getParameterByName('curpage', url); + var target_url = 'http://api.xiami.com/web?v=2.0&app_key=1&key=' + keyword + '&page='+ curpage +'&limit=20&callback=jsonp154&r=search/songs'; hm({ url:target_url, method: 'GET', @@ -153,7 +154,7 @@ var xiami = (function() { var track = xm_convert_song(item, 'artist_name'); tracks.push(track); }); - return fn({"result":tracks}); + return fn({"result":tracks,"total":data.data.total}); }); } }; diff --git a/listen1.html b/listen1.html index 229e074..ce1fd70 100644 --- a/listen1.html +++ b/listen1.html @@ -232,11 +232,11 @@