var app=angular.module("newsApp",["ui.router","ng.post","news.controller","news.service","news.directive"]);app.config(["$stateProvider","$urlRouterProvider",function(e,o){e.state("index",{url:"/index",templateUrl:"template/index.html",controller:"indexCtrl"}).state("index.list",{url:"/list",templateUrl:"template/newsList.html",controller:"listCtrl"}).state("index.secondlist",{url:"/secondlist",templateUrl:"template/secondList.html",controller:"secondListCtrl"}).state("detail",{url:"/detail/:id",templateUrl:"template/detail.html",controller:"detailCtrl"}).state("login",{url:"/login",templateUrl:"template/logins.html",controller:"loginsCtrl"}).state("register",{url:"/register",templateUrl:"template/register.html",controller:"registerCtrl"}).state("setting",{url:"/setting",templateUrl:"template/setting.html",controller:"settingCtrl"}),o.when("","/index/list")}]),function(){var e=angular.module("news.controller",[]);e.controller("indexCtrl",["$scope","$rootScope","$http","cookie","$window",function(e,o,t,n,l){var s=n.getCookie("token"),i=n.getCookie("username");t.post("http://localhost:81/angular/news/index.php/login_api/auto_login",{params:{token:s,username:i}}).success(function(e){console.log(e),e.code||(window.location.href="#/login")}),e.tabs=[{name:"国内最新",id:1,url:"#/index/list"},{name:"游戏焦点",id:2,url:"#/index/secondlist"},{name:"登录",id:3,url:"#/login"}],o.id=1,e.toggleTab=function(e,t){console.log(e),o.id=e,l.location.href=t}}]),e.controller("listCtrl",["$scope","$http",function(e,o){e.isShowSwiper=!0,e.page=1,e.isShow=!1,e.news=[];var t=function(){o.jsonp("http://localhost:12345/newsApi",{params:{page:e.page,channelId:"5572a109b3cdc86cf39001db",channelName:"国内最新",callback:"JSON_CALLBACK"}}).success(function(o){e.isShow=!0,console.log(o),e.news=e.news.concat(o.showapi_res_body.pagebean.contentlist)})};t(),e.searchName="",e.isSearch=!1,e.search=function(){e.isSearch=!0},e.cancelSearch=function(){e.isSearch=!1},e.loadMore=function(){e.isShow=!1,e.page++,t()}}]),e.controller("secondListCtrl",["$scope","$http","$rootScope",function(e,o,t){e.isShowSwiper=!0,t.id=2,e.page=1,e.isShow=!1,e.news=[];var n=function(){o.jsonp("http://localhost:12345/newsApi",{params:{page:e.page,channelId:"5572a108b3cdc86cf39001d6",channelName:"游戏焦点",callback:"JSON_CALLBACK"}}).success(function(o){e.isShow=!0,console.log(o),e.news=e.news.concat(o.showapi_res_body.pagebean.contentlist)})};n(),e.searchName="",e.isSearch=!1,e.search=function(){e.isSearch=!0},e.cancelSearch=function(){e.isSearch=!1},e.loadMore=function(){e.isShow=!1,e.page++,n()}}]),e.controller("detailCtrl",["$scope","$http","$state",function(e,o,t){e.isShowGallery=!1,e.showGallery=function(o,t){e.isShowGallery=o,console.log(t),e.imgUrl="background-image:url("+t+")"},console.log(t.params),o.jsonp("http://localhost:12345/newsApi",{params:{page:1,channelId:"5572a109b3cdc86cf39001db",channelName:"国内最新",callback:"JSON_CALLBACK"}}).success(function(o){console.log(o),e.new=o.showapi_res_body.pagebean.contentlist[t.params.id],console.log(e.new)})}]),e.controller("loginsCtrl",["$scope","$http","cookie",function(e,o,t){e.login=function(){console.log("username:"+e.username),console.log("password:"+e.password),o.post("http://localhost:81/angular/news/index.php/login_api/login",{params:{username:e.username,password:e.password}}).success(function(e){console.log(e),e.code&&(t.setCookie("token",e.info.token),t.setCookie("username",e.username),window.location.href="#/index/list")})}}]),e.controller("registerCtrl",["$scope","$http","cookie",function(e,o,t){e.register=function(){console.log("username:"+e.username),console.log("password:"+e.password),o.post("http://localhost:81/angular/news/index.php/login_api/register",{params:{username:e.username,password:e.password}}).success(function(e){console.log(e),e.code&&(t.setCookie("username",e.username),t.setCookie("token",e.info.token),window.location.href="#/index/list")})}}]),e.controller("settingCtrl",["$scope","$http","cookie",function(e,o,t){var n=t.getCookie("token"),l=t.getCookie("username");o.post("http://localhost:81/angular/news/index.php/login_api/auto_login",{params:{token:n,username:l}}).success(function(e){console.log(e),e.code||(window.location.href="#/login")})}])}(),function(){var e=angular.module("news.service",[]);e.service("cookie",["$document",function(e){return{setCookie:function(o,t){var n=10,l=new Date;l.setTime(l.getTime()+24*n*60*60*1e3),e[0].cookie=o+"="+t+";expires="+l},getCookie:function(o){var t,n=new RegExp("(^|)"+o+"=([^;]*)(;|$)");if(t=e[0].cookie.match(n))return t[2]}}}])}(),function(){var e=angular.module("news.directive",[]);e.directive("newsList",[function(){return{templateUrl:"directive/newsList.html"}}]),e.directive("searchBar",[function(){return{templateUrl:"directive/searchBar.html"}}]),e.directive("swiper",[function(){return{templateUrl:"directive/swiper.html",link:function(e,o,t){new Swiper(".swiper-container",{pagination:".swiper-pagination",paginationClickable:!0})}}}])}();