diff --git a/t/Gruntfile.js b/t/Gruntfile.js index bb25666..47d8d22 100644 --- a/t/Gruntfile.js +++ b/t/Gruntfile.js @@ -11,7 +11,8 @@ module.exports = function(grunt){ './lib/main.js', './lib/directive/**/*.js', './lib/service/**/*.js', - './lib/list/**/*.js' + './lib/list/**/*.js', + './lib/search/**/*.js' ], dest:'./build/main.js' } diff --git a/t/build/main.js b/t/build/main.js index 05fc11e..bb6486f 100644 --- a/t/build/main.js +++ b/t/build/main.js @@ -125,6 +125,24 @@ app.config(['$stateProvider', '$urlRouterProvider',function($stateProvider, $url controller: '' } } + }) + + .state('search',{ + url: '/search/:type', + views:{ + header:{ + templateUrl: '../html/views/search.html', + controller: 'Search' + }, + container:{ + templateUrl: '', + controller: '' + }, + footer:{ + templateUrl: '', + controller: '' + } + } }); }]); ; @@ -263,32 +281,51 @@ app.controller('musicListController', ['$rootScope', 'musicList',function($rootS } musicList.getData($rootScope.keywordsObj.music); }]); -;/*搜索*/ -var SearchController = function($scope, $rootScope, $location, bookList, musicList, movieList){ +;/*负责搜索结果的导向*/ +var Search = function($scope, $rootScope, $location, bookList, musicList, movieList){ var path = $location.path(); + $rootScope.isNoLoaded = false; + //跳回列表页 $scope.search = function(){ var keywords = $scope.keywords; - if(path.indexOf('/book') !== -1 || path === '/'){ + if(path.indexOf('/book') !== -1){ if(keywords){ $rootScope.keywordsObj.book = keywords; } - bookList.getData($rootScope.keywordsObj.book); + $location.path('/book'); - }else if(path.indexOf('/music') !== -1 || path === '/music'){ + }else if(path.indexOf('/music') !== -1){ if(keywords){ $rootScope.keywordsObj.music = keywords; } - musicList.getData($rootScope.keywordsObj.music); + $location.path('/music'); - }else if(path.indexOf('/movie') !== -1 || path === '/movie'){ + }else if(path.indexOf('/movie') !== -1){ if(keywords){ $rootScope.keywordsObj.movie = keywords; } - movieList.getData($rootScope.keywordsObj.movie); + $location.path('/movie'); } }; }; +Search.$inject = ['$scope', '$rootScope', '$location', 'bookList', 'musicList', 'movieList']; +app.controller('Search', Search);;/*仅负责搜索页面的打开*/ +var SearchController = function($scope, $rootScope, $location){ + var path = $location.path(); + $scope.goToSearch = function(){ + if(path.indexOf('/book') !== -1 || path === '/'){ + $location.path('/search/book'); + + }else if(path.indexOf('/music') !== -1 || path === '/music'){ + $location.path('/search/music'); + + + }else if(path.indexOf('/movie') !== -1 || path === '/movie'){ + $location.path('/search/movie'); + } + }; + +}; -SearchController.$inject = ['$scope', '$rootScope', '$location', 'bookList', 'musicList', 'movieList']; - +SearchController.$inject = ['$scope', '$rootScope', '$location']; app.controller('SearchController', SearchController); diff --git a/t/build/main.min.js b/t/build/main.min.js index 664fc1e..28478dc 100644 --- a/t/build/main.min.js +++ b/t/build/main.min.js @@ -1,2 +1,2 @@ /*! wlhmyit 2014-12-12 */ -var app=angular.module("app",["ui.router"]);app.run(["$rootScope",function(a){a.version="0.1",a.author="vczero",a.author_alias="鬼谣",a.isNoLoaded=!0,a.bookList=[],a.musicList=[],a.movieList=[],a.keywordsObj={book:"",music:"",movie:""}}]),app.constant("ServiceConfig",{book_search:"https://api.douban.com/v2/book/search",book_search_id:"https://api.douban.com/v2/book/",music_search:"https://api.douban.com/v2/music/search",music_search_id:"https://api.douban.com/v2/music/",movie_search:"https://api.douban.com/v2/movie/search",movie_search_id:"https://api.douban.com/v2/movie/subject/"}),app.config(["$stateProvider","$urlRouterProvider",function(a,b){b.otherwise("/"),a.state("index",{url:"/",views:{header:{templateUrl:"../html/views/list_header.html",controller:"SearchController"},container:{templateUrl:"../html/views/list_book.html",controller:"BookListController"},footer:{templateUrl:"../html/views/list_footer.html",controller:""}}}).state("book_list",{url:"/book",views:{header:{templateUrl:"../html/views/list_header.html",controller:"SearchController"},container:{templateUrl:"../html/views/list_book.html",controller:"BookListController"},footer:{templateUrl:"../html/views/list_footer.html",controller:""}}}).state("book_detail",{url:"/book/:id",views:{header:{templateUrl:"../html/views/list_header.html",controller:"SearchController"},container:{templateUrl:"../html/views/detail_book.html",controller:"BookDetailController"},footer:{templateUrl:"../html/views/list_footer.html",controller:""}}}).state("music_lsit",{url:"/music",views:{header:{templateUrl:"../html/views/list_header.html",controller:"SearchController"},container:{templateUrl:"../html/views/list_music.html",controller:"musicListController"},footer:{templateUrl:"../html/views/list_footer.html",controller:""}}}).state("movie_lsit",{url:"/movie",views:{header:{templateUrl:"../html/views/list_header.html",controller:"SearchController"},container:{templateUrl:"../html/views/list_movie.html",controller:"movieListController"},footer:{templateUrl:"../html/views/list_footer.html",controller:""}}})}]),app.directive("loading",function(){var a='
';return{restrict:"AE",template:a,replace:!0}}),app.directive("tip",function(){var a='
';return{restrict:"AE",template:a,replace:!0}}),app.factory("bookList",["$rootScope","$http","ServiceConfig",function(a,b,c){a.isNoLoaded=!0;var d={getData:function(d){a.isNoLoaded=!0,b.jsonp(c.book_search+"?callback=searchBookList&count=10&q="+d),window.searchBookList=function(b){b.books.length&&(a.isNoLoaded=!1);for(var c=[],d=0;d
- +
- +
\ No newline at end of file diff --git a/t/html/views/search.html b/t/html/views/search.html new file mode 100644 index 0000000..5d123fe --- /dev/null +++ b/t/html/views/search.html @@ -0,0 +1,8 @@ +
+
+ +
+
+ +
+
\ No newline at end of file diff --git a/t/lib/list/searchController.js b/t/lib/list/searchController.js deleted file mode 100644 index 08eba1f..0000000 --- a/t/lib/list/searchController.js +++ /dev/null @@ -1,28 +0,0 @@ -/*搜索*/ -var SearchController = function($scope, $rootScope, $location, bookList, musicList, movieList){ - var path = $location.path(); - $scope.search = function(){ - var keywords = $scope.keywords; - if(path.indexOf('/book') !== -1 || path === '/'){ - if(keywords){ - $rootScope.keywordsObj.book = keywords; - } - bookList.getData($rootScope.keywordsObj.book); - - }else if(path.indexOf('/music') !== -1 || path === '/music'){ - if(keywords){ - $rootScope.keywordsObj.music = keywords; - } - musicList.getData($rootScope.keywordsObj.music); - - }else if(path.indexOf('/movie') !== -1 || path === '/movie'){ - if(keywords){ - $rootScope.keywordsObj.movie = keywords; - } - movieList.getData($rootScope.keywordsObj.movie); - } - }; -}; - -SearchController.$inject = ['$scope', '$rootScope', '$location', 'bookList', 'musicList', 'movieList']; -app.controller('SearchController', SearchController); diff --git a/t/lib/main.js b/t/lib/main.js index f43e370..6497cfa 100644 --- a/t/lib/main.js +++ b/t/lib/main.js @@ -125,5 +125,23 @@ app.config(['$stateProvider', '$urlRouterProvider',function($stateProvider, $url controller: '' } } + }) + + .state('search',{ + url: '/search/:type', + views:{ + header:{ + templateUrl: '../html/views/search.html', + controller: 'Search' + }, + container:{ + templateUrl: '', + controller: '' + }, + footer:{ + templateUrl: '', + controller: '' + } + } }); }]); diff --git a/t/lib/search/Search.js b/t/lib/search/Search.js new file mode 100644 index 0000000..a49d74a --- /dev/null +++ b/t/lib/search/Search.js @@ -0,0 +1,29 @@ +/*负责搜索结果的导向*/ +var Search = function($scope, $rootScope, $location, bookList, musicList, movieList){ + var path = $location.path(); + $rootScope.isNoLoaded = false; + //跳回列表页 + $scope.search = function(){ + var keywords = $scope.keywords; + if(path.indexOf('/book') !== -1){ + if(keywords){ + $rootScope.keywordsObj.book = keywords; + } + $location.path('/book'); + + }else if(path.indexOf('/music') !== -1){ + if(keywords){ + $rootScope.keywordsObj.music = keywords; + } + $location.path('/music'); + + }else if(path.indexOf('/movie') !== -1){ + if(keywords){ + $rootScope.keywordsObj.movie = keywords; + } + $location.path('/movie'); + } + }; +}; +Search.$inject = ['$scope', '$rootScope', '$location', 'bookList', 'musicList', 'movieList']; +app.controller('Search', Search); \ No newline at end of file diff --git a/t/lib/search/searchController.js b/t/lib/search/searchController.js new file mode 100644 index 0000000..43510de --- /dev/null +++ b/t/lib/search/searchController.js @@ -0,0 +1,20 @@ +/*仅负责搜索页面的打开*/ +var SearchController = function($scope, $rootScope, $location){ + var path = $location.path(); + $scope.goToSearch = function(){ + if(path.indexOf('/book') !== -1 || path === '/'){ + $location.path('/search/book'); + + }else if(path.indexOf('/music') !== -1 || path === '/music'){ + $location.path('/search/music'); + + + }else if(path.indexOf('/movie') !== -1 || path === '/movie'){ + $location.path('/search/movie'); + } + }; + +}; + +SearchController.$inject = ['$scope', '$rootScope', '$location']; +app.controller('SearchController', SearchController);