1/* 2* Customization and Configuration Angular scripts 3* 4* 5* @project Indirect Public Administration Theme 6* @version 1.0 7* @date 26/01/2017 8* @package layout 9* @author Lucas Matias Caetano 10* @copyright 2017 PRODEST. 11* 12*/ 13'use strict'; 14 15 16var videosApp = angular.module('videosApp', []); 17 18videosApp.controller('youtubeController', function ($scope, $http, $filter) { 19 20 var type, id, contentType; 21 var api_key = "AIzaSyBPCF9_AA4DITRRBIrm0zXovYcoygJDrBs"; 22 var urlYoutube = angular.element('#url').val(); 23 var parametros; 24 var maxResultados = '12'; 25 26 var d = new Date(); 27 var hour = d.getHours(); 28 29 if (hour >= 22 && hour < 6) { 30 api_key = "AIzaSyBPCF9_AA4DITRRBIrm0zXovYcoygJDrBs"; 31 } 32 else if (hour >= 6 && hour < 9) { 33 api_key = "AIzaSyAP758dqkzCrULPvCtQCDkldJr6uU16utc"; 34 } 35 else if (hour >= 9 && hour < 12) { 36 api_key = "AIzaSyAS_RPfBeVIewvb7CJYM4UjAV5G5mIsPcI"; 37 } 38 else if (hour >= 12 && hour < 15) { 39 api_key = "AIzaSyB3vC9-fxs-MQ1LcVox4-ojzHazyDAOQlE"; 40 } 41 else if (hour >= 15 && hour < 18) { 42 api_key = "AIzaSyBsLRAvbBaQvSqdfhAoy9IZMMKRVL-gCyc"; 43 } 44 else if (hour >= 18 && hour < 22) { 45 api_key = "AIzaSyAsfPW0dUHzMIKuQA9PpSEXkWgZEb_IfJ8"; 46 } 47 48 /*https://regex101.com/*/ 49 var reg = new RegExp(/^.*(youtu.be\/|list|watch)(|\?v|)=([^#\&\?]*).*(?:&|$)|^(?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?(?:\/)(channel)?(?:(?!=).)*\/(.*)$/g); 50 var match = reg.exec(urlYoutube); 51 52 if (match != null) { 53 if (match[4] != undefined) { 54 type = match[4]; 55 id = match[5]; 56 } else { 57 type = match[1]; 58 id = match[3]; 59 } 60 //console.log("type: " + type); 61 //console.log("id: " + id); 62 switch (type) { 63 case "list": 64 contentType = "playlistItems"; 65 parametros = { 66 params: { 67 part: 'snippet', 68 playlistId: id, 69 key: api_key, 70 pageToken: $scope.nextPage ? $scope.nextPage : '', 71 maxResults: maxResultados 72 } 73 }; 74 break; 75 case "watch": 76 contentType = "videos"; 77 parametros = { 78 params: { 79 part: 'snippet', 80 id: id, 81 key: api_key 82 } 83 }; 84 break; 85 case "channel"://traz os últimos vídeos 86 //contentType = "channels"; 87 contentType = "search"; 88 parametros = { 89 params: { 90 part: 'snippet', 91 channelId: id, 92 key: api_key, 93 order: 'date', 94 type: 'video', 95 maxResults: maxResultados 96 } 97 }; 98 break; 99 default: 100 contentType = "search"; 101 parametros = { 102 params: { 103 part: 'id,snippet', 104 key: api_key, 105 type: "video", 106 maxResults: maxResultados, 107 pageToken: $scope.nextPage ? $scope.nextPage : '', 108 fields: 'items/id,items/snippet/title,items/snippet/description,items/snippet/thumbnails/default,items/snippet/channelTitle,nextPageToken,prevPageToken' 109 } 110 }; 111 break; 112 } 113 114 $scope.youtubeData = []; 115 $scope.nextPage = ""; 116 117 118 $scope.getYoutubeData = function () { 119 $http.get('https://www.googleapis.com/youtube/v3/' + contentType, 120 parametros 121 ).success(function (data) { 122 if (data.items.length === 0) { 123 $scope.youtubeData = 'Página não encontrada!'; 124 } 125 if (type != "channel") { 126 $scope.totalResults = (data.pageInfo.totalResults / data.pageInfo.resultsPerPage); 127 128 if (data.pageInfo.totalResults % data.pageInfo.resultsPerPage) { 129 $scope.totalResults = Math.floor($scope.totalResults); 130 $scope.totalResults = $scope.totalResults + 1; 131 } 132 $scope.parcialResults = (data.items[data.items.length - 1].snippet.position + 1) / data.pageInfo.resultsPerPage; 133 if ((data.items[data.items.length - 1].snippet.position + 1) % data.pageInfo.resultsPerPage) { 134 $scope.parcialResults = Math.floor($scope.parcialResults); 135 $scope.parcialResults = $scope.parcialResults + 1; 136 } 137 $scope.nextPageToken = data.nextPageToken; 138 $scope.prevPageToken = data.prevPageToken; 139 140 } 141 142 $scope.youtubeData = data.items; 143 window.scrollTo(0, 0); 144 }); 145 } 146 147 $scope.getYoutubeData(); 148 149 $scope.checkDataLength = function (data) { 150 return (data.length >= 1); 151 }; 152
153 $scope.callNextPageFn = function (nextPage) { 154 $scope.nextPage = nextPage; 155 parametros["params"]["pageToken"] = nextPage; 156 $scope.getYoutubeData(); 157 }; 158 159 $scope.getVideoId = function (data) { 160 var id = ""; 161 switch (type) { 162 case "list": 163 id = data.snippet.resourceId.videoId; 164 break; 165 case "watch": 166 id = data.id; 167 break; 168 case "channel": 169 id = data.id.videoId; 170 break; 171 default: 172 id = data.id.videoId; 173 break; 174 175 } 176 return (id); 177 }; 178 179 180 } 181}).filter('cmdate', [ 182 '$filter', function($filter) { 183 return function (input, format) { 184 //moment.locale('pt-br'); 185 //var a = moment(input).fromNow(); 186 //return a; 187 return $filter('date')(new Date(input), format); 188 }; 189 } 190]).filter('ellipsis', function () { 191 return function (text, length) { 192 if (text.length > length) { 193 return text.substr(0, length) + '...'; 194 } 195 return text; 196 } 197}).directive('showHide', function () { 198 return { 199 link: function (scope, element, attributes, controller) { 200 scope.$watch(attributes.showHide, function (v) { 201 if (v) { 202 element.show(); 203 } else { 204 element.hide(); 205 } 206 }); 207 208 } 209 }; 210}).directive('prettyp', function () { 211 return function (scope, element, attrs) { 212 213 $("a[rel^='prettyVideo']").prettyPhoto({ 214 animation_speed: 'normal', 215 theme: 'video', 216 slideshow: 3000, 217 autoplay_slideshow: false, 218 social_tools: false, 219 default_width: 850, 220 default_height: 480, 221 callback: function () { 222 $(".video-item").each(function () { 223 if ($(this).find(".video-play").hasClass("fa-pause")) { 224 $(this).find(".video-play").removeClass("fa-pause"); 225 $(this).find(".video-play").addClass("fa-play"); 226 } 227 }); 228 } 229 }); 230 231 } 232}).directive("owlCarousel", ['$timeout', function ($timeout) { 233 return { 234 restrict: 'E', 235 transclude: false, 236 link: function (scope) { 237 238 $('#NAV-ID-' + scope.contentId).empty(); 239 scope.initCarousel = function (element) { 240 $timeout(function () { 241 // provide any default options you want 242 var defaultOptions = { 243 loop: true, 244 margin: 10, 245 slideBy: 3, 246 nav: true, 247 autoplay: true, 248 navContainer: '.carousel-nav', 249 navElement: 'span', 250 navText: ['<i title="Anterior" class="fa fa-chevron-left"></i>', '<i title="Pr\u00f3ximo" class="fa fa-chevron-right"></i>'], 251 navClass: ["owl left previous", "owl right next"], 252 autoplayHoverPause: true, 253 items: 3, //2 items above 1000px browser width 254 responsive: { 255 // breakpoint from 0 up 256 0: { 257 items: 1 258 }, 259 // breakpoint from 480 up 260 480: { 261 items: 1 262 }, 263 // breakpoint from 768 up 264 768: { 265 items: 2 266 }, 267 980: { 268 items: 3 269 } 270 } 271 272 }; 273 var customOptions = scope.$eval($(element).attr('data-options'));
274 // combine the two options objects 275 for (var key in customOptions) { 276 defaultOptions[key] = customOptions[key]; 277 } 278 279 if ($(element).attr('data-length') == 1) { 280 defaultOptions["items"] = 1; 281 defaultOptions["slideBy"] = 1; 282 defaultOptions["responsive"] = {}; 283 } 284 // init carousel 285 var $owl = $(element).owlCarousel(defaultOptions); 286 287 /*======================================================== 288 * Carousel Group News 289 ========================================================== */ 290 291 function equalHeightNewsCarousel() { 292 293 $(".rp-carousel-news").each(function () { 294 var maxHeight = 0; 295 $(this).find(".item-carousel").each(function () { 296 if (maxHeight < $(this).height()) { 297 maxHeight = $(this).height(); 298 } 299 }); 300 if (maxHeight > 0) { 301 $(this).find(".item-carousel").each(function () { 302 if ($(this).height() < maxHeight) { 303 var difHeight = maxHeight - $(this).height(); 304 $(this).find(".learn-more").css("padding-top", difHeight + "px"); 305 } 306 }); 307 } 308 309 }); 310 } 311 equalHeightNewsCarousel(); 312 $(window).on("load resize", function (e) { 313 $owl.trigger('refresh.owl.carousel'); 314 equalHeightNewsCarousel(); 315 }); 316 317 }, 50); 318 }; 319 } 320 }; 321}]) 322.directive('owlCarouselItem', [function () { 323 return { 324 restrict: 'A', 325 transclude: false, 326 link: function (scope, element) { 327 // wait for the last item in the ng-repeat then call init 328 if (scope.$last) { 329 scope.initCarousel(element.parent()); 330 } 331 } 332 }; 333}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.