Нет описания

script.js 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. (function($, window) {
  2. }).call(this, jQuery, window);
  3. var underscore = angular.module('underscore', []);
  4. underscore.factory('_', ['$window', function($window) {
  5. return $window._; // assumes underscore has already been loaded on the page
  6. }]);
  7. var publicToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoicHVibGljIiwicm9sZXMiOlsicHVibGljIl0sImV4cCI6MTczNDE2NTcxMCwiaWF0IjoxNDc0OTY1NzEwLCJuYmYiOjE0NzQ5NjU3MTAsImlkZW50aXR5IjoiNTdlOWVmMjZjMjU0ZmQ4N2Q3ZmQ4MzM2In0.-9fcm5s8qYbdqBDUX7cZJ5J3AX91fe6VrCLs_S-_eBU";
  8. var ottCats = [
  9. {title: 'MCOT HD', cat: [ 'MCOT HD'], varName: 'sports' },
  10. {title: 'Economic', cat: [ 'ข่าวทันสถานการณ์'], varName: 'econs' },
  11. {title: 'Money', cat: [ 'เศรษฐกิจ'], varName: 'money'}
  12. ];
  13. angular.module('ottApp', ['ui.router', 'ngSanitize','bootstrapLightbox', 'mcot.services', 'slimdir', 'mcot.filters'])
  14. .config([
  15. '$locationProvider',
  16. '$stateProvider', '$urlRouterProvider', '$sceDelegateProvider', function( $locationProvider, $stateProvider, $urlRouterProvider, $sceDelegateProvider) {
  17. $locationProvider.html5Mode(true).hashPrefix('!');
  18. $sceDelegateProvider.resourceUrlWhitelist([
  19. // Allow same origin resource loads.
  20. 'self',
  21. // Allow loading from our assets domain. Notice the difference between * and **.
  22. 'http://simplico.net:6066/**',
  23. 'http://119.46.61.109/**',
  24. 'http://cdn.mcot.net/**',
  25. 'http://git.simplico.net/**']);
  26. $urlRouterProvider.otherwise('/app.index');
  27. $stateProvider
  28. .state('app', {
  29. abstract: true,
  30. //url: '/',
  31. templateUrl: '/static/templates/app.html',
  32. controller: 'AppCtrl',
  33. ncyBreadcrumb: {
  34. label: 'Home'
  35. }
  36. })
  37. .state('app.index', {
  38. //url: '/',
  39. url: '/',
  40. templateUrl: '/static/templates/app.index.html',
  41. controller: 'IndexCtrl',
  42. ncyBreadcrumb: {
  43. label: 'Index'
  44. }
  45. })
  46. .state('app.view', {
  47. url: '/view/:id',
  48. templateUrl: '/static/templates/app.view.html',
  49. controller: 'ViewCtrl',
  50. })
  51. .state('app.program', {
  52. url: '/program',
  53. templateUrl: '/static/templates/app.program.html',
  54. controller: 'ProgramCtrl',
  55. ncyBreadcrumb: {
  56. label: 'Program'
  57. }
  58. });
  59. // for dev
  60. var myAppId = '707598586069289'; // for prod
  61. //var myAppId = '105438229594549'; // for dev
  62. // You can set appId with setApp method
  63. // FacebookProvider.setAppId('myAppId');
  64. /**
  65. * After setting appId you need to initialize the module.
  66. * You can pass the appId on the init method as a shortcut too.
  67. */
  68. }
  69. ])
  70. .filter('find_image_size', function(){
  71. return function(doc, key) {
  72. if( doc.medias === undefined )
  73. return '';
  74. var r = $.grep(doc.medias, function(e){ return e.ott_image == key; });
  75. if (r.length == 0) {
  76. // not found
  77. return doc.feature_url;
  78. } else {
  79. return r[0].value;
  80. }
  81. };
  82. })
  83. .controller('MainCtrl', function($state, $scope, PUBLIC_TOKEN, $timeout, $uibModal){
  84. $scope.ottCats = ottCats;
  85. $state.transitionTo('app.index');
  86. $scope.openMenu = function() {
  87. console.log("open menu");
  88. $uibModal.open({
  89. animation: true,
  90. ariaLabelledBy: 'modal-title-bottom',
  91. ariaDescribedBy: 'modal-body-bottom',
  92. templateUrl: '/static/templates/menumodal.html',
  93. size: 'lg',
  94. controller: function($scope) {
  95. $scope.name = 'bottom';
  96. }
  97. });
  98. };
  99. })
  100. .controller('AppCtrl', function($state, $scope, $timeout, $window,$rootScope){
  101. })
  102. .controller('ViewCtrl', function($state, $stateParams, mcotcms, $scope, PUBLIC_TOKEN, $rootScope, $location, $filter, $timeout){
  103. $scope.id = $stateParams.id;
  104. console.log("vew ...");
  105. $scope.sideTab = 'breakingNews';
  106. mcotcms.post_api(PUBLIC_TOKEN, "LIST", {query: {'categories.text': "Breaking News"}})
  107. .then(function(success){
  108. console.log(" Breaking ");
  109. $scope.breakings = success.data.output;
  110. console.log($scope.breakings);
  111. });
  112. mcotcms.post_api(PUBLIC_TOKEN, "GET", {id: $scope.id})
  113. .then(function(success){
  114. $scope.post = success.data.output;
  115. $rootScope.title = success.data.output.title;
  116. $scope.cats = _.map($scope.post.categories, function(o) { return o.text }).join(',');
  117. $scope.catText = _.filter($scope.post.categories, function(o) {
  118. if( o.text !== 'root' && o.text !== 'TNA' ) {
  119. return true;
  120. }else {
  121. return false;
  122. }
  123. } );
  124. $scope.tags = _.map($scope.post.focus_tags, function(o) { return o.text });
  125. if($scope.tags.length > 0 ) {
  126. mcotcms.post_api(PUBLIC_TOKEN, "LIST", {query: {'tags.text': {'$all': $scope.tags}, 'is_active': true }, limit: 25})
  127. .then(function(success){
  128. $scope.focusTags = success.data.output;
  129. });
  130. }
  131. $rootScope.url = $location.absUrl();
  132. $rootScope.title = $scope.post.title;
  133. $rootScope.description = $scope.post.description;
  134. $rootScope.image = $filter("image_server")($scope.post, "-600x315x2");
  135. });
  136. })
  137. .controller('ProgramCtrl', function($state, $scope, $timeout, $window,$rootScope){
  138. })
  139. .controller('IndexCtrl', function($state, $scope, $timeout, PUBLIC_TOKEN, $rootScope, $http, mcotcms){
  140. mcotcms.post_api(PUBLIC_TOKEN, "LIST", {query: {'categories.text': {'$all': ["OTT Top Story"]}, 'is_active': true}})
  141. .then(function(success){
  142. console.log('post ', success.data.output);
  143. $scope.topStory = success.data.output;
  144. });
  145. mcotcms.post_api(PUBLIC_TOKEN, "LIST", {query: {'categories.text': {'$all': ["OTT Top Picks"]}, 'is_active': true} , 'limit': 10})
  146. .then(function(success){
  147. $scope.topPicks = success.data.output;
  148. });
  149. mcotcms.post_api(PUBLIC_TOKEN, "LIST", {query: {'categories.text': {'$all': ["OTT Recommended"]}, 'is_active': true} , 'limit': 2})
  150. .then(function(success){
  151. $scope.recs = success.data.output;
  152. });
  153. $scope.ottCats.forEach(function(e) {
  154. mcotcms.post_api(PUBLIC_TOKEN, "LIST", {query: {'categories.text': {'$all': e.cat}, 'is_active': true} , 'limit': 10})
  155. .then(function(success){
  156. console.log('ott mmm ');
  157. $scope[e.varName] = success.data.output
  158. });
  159. });
  160. $timeout(function(){
  161. $(".regular").slick({
  162. dots: true,
  163. infinite: true,
  164. slidesToShow: 5,
  165. slidesToScroll: 5,
  166. autoplay: false,
  167. autoplaySpeed: 6000,
  168. responsive: [
  169. {
  170. breakpoint: 1024,
  171. settings: {
  172. slidesToShow: 2,
  173. slidesToScroll: 2,
  174. infinite: true,
  175. dots: true
  176. }
  177. },
  178. {
  179. breakpoint: 600,
  180. settings: {
  181. slidesToShow: 2,
  182. slidesToScroll: 2
  183. }
  184. },
  185. {
  186. breakpoint: 480,
  187. settings: {
  188. slidesToShow: 2,
  189. slidesToScroll: 2
  190. }
  191. }
  192. ]
  193. });
  194. }, 1000);
  195. });