/* global _, angular, i18n, Ladda, Odometer */ 'use strict'; angular.module('DinsorApp.directives', []) /* Layouts */ .directive('headBar', ['$location', '$timeout', function($location, $timeout) { return { restrict: 'A', templateUrl: 'templates/layouts/header.modernbangkok', link: function(scope, element, attrs) { // scope.menu = [ { "title": "หน้าหลัก", "path": "/", "state": "1" }, { "title": "นโยบาย", "path": "/policy", "state": "1" }, { "title": "บทความ", "path": "/article", "state": "1" }, { "title": "ผู้สมัคร", "path": "/candidates", "state": "0" }, { "title": "ความเคลื่อนไหว", "path": "/news", "state": "1" }, { "title": "สมัครอาสา", "path": "/volunteer", "state": "1" }, { "title": "เกี่ยวกับเรา", "path": "/about-us", "state": "1" }, { "title": "ติดต่อเรา", "path": "/contact-us", "state": "1" } ]; // scope.$on('$viewContentLoaded', function(event, viewConfig) { $timeout(function() { scope.navigationChange(); }, 600); // }); scope.$on( "$routeChangeStart", function(event, route, current) { scope.navigationChange(); }); // navigation background change scope.navigationChange = function() { // $('.header-page').css('height', $('header').height()); var path = $location.path().split("/"); // // if($location.path() == '/' || path[1] == 'candidate') { if($location.path() == '/') { // $('header').css('position', 'absolute'); $('nav').css('color', 'white'); }else { // $('header').css('position', 'relative'); $('nav').css('color', 'black'); } } $(document).ready(function(){ $('.sidenav').sidenav(); }); // } }; }]) .directive('sitemap', [function() { return { restrict: 'A', templateUrl: '/templates/layouts/sitemap.modernbangkok', link: function(scope, element, attrs) { attrs.$observe('sitemap', function(program) { //scope.service.program.data('sitemap', institution).then(function(data) { //console.log(data) // scope.sitemap = data; //}); }); } }; }]) // .directive('copyright', [function() { // return { // restrict: 'C', // templateUrl: '/templates/layouts/copyright.modernbangkok' // }; // }]) .directive('cookiePolicy', [function() { return { restrict: 'C', templateUrl: '/templates/layouts/cookie.modernbangkok', }; }]) /* elements */ .directive('image', [function() { return { restrict: 'A', link: function(scope, element, attrs) { attrs.$observe('image', function(image) { var img = new Image(); img.onload = function() { var ratio = this.height / this.width; element.css('padding-top', ratio *100+'%'); element.css('position','relative'); } img.src = 'https:' + image; element.removeAttr('image'); element.css('background-image', "url('"+image+"')").addClass('cover'); // element.removeAttr('image'); }); } } }]) .directive('background', [function() { return { restrict: 'A', link: function(scope, element, attrs) { attrs.$observe('background', function(image) { var img = new Image(); img.onload = function() { var height = (this.height / this.width) * 100; if(attrs.height) { element.css('height', attrs.height + 'px'); }else { element.css('height', height + 'vw'); } } if (image.indexOf("http://") != 0 || image.indexOf("https://") != 0) { img.src = 'https:' + image; } img.src = image; element.css("background-image", "url('"+image+"')"); // background position if(attrs.position == 'center') { element.addClass('bg-cover-center'); }else { element.addClass('background-image width'); } element.removeAttr('background'); }); } } }]) .directive('icon', [function() { return { restrict: 'A', link: function(scope, element, attrs) { attrs.$observe('icon', function(image) { var $img = $(''); var img = new Image(); img.onload = function() { $img.attr('src', image); element.append($img); } img.src = image; element.removeAttr('icon'); }); } } }]) .directive('aos', ['$timeout', function($timeout) { return { restrict: 'A', link: function(scope, element, attrs) { $timeout(function() { AOS.init({ disable: 'mobile' }); }, 300); // } } }]) .directive('portfolio', [function() { return { restrict: 'A', link: function(scope, element, attrs) { attrs.$observe('portfolio', function(id) { if(id) { /* Portfolio */ scope.service.app.portfolio(id).then(function(respone) { var portfolio = respone.data; // console.log(portfolio); if(portfolio.length) { var $container = $('
').addClass('container'); // gallery carousel var $carousel = $('
').addClass('card-gallery carousel carousel-slider relative'); var $gradient = $('
').addClass('background-gradient-left-right'); var $btnPrev = $('').addClass('btn-prev absolute').append($('').attr('src', '/public/img/icon/icon-prev-white.png')); var $btnNext = $('').addClass('btn-next absolute').append($('').attr('src', '/public/img/icon/icon-next-white.png')); angular.forEach(portfolio, function(item) { var $item = $('
').addClass('carousel-item relative'); var $image = $('').attr('src', item.image); // $item.append($image); $carousel.append($item); }); $container.append($carousel.append($btnPrev).append($btnNext)); element.append($container); // element.ready(function() { // carousel $carousel.carousel({ fullWidth: true }); $carousel.find('.btn-prev').click(function(e) { e.preventDefault(); e.stopPropagation(); $carousel.carousel('prev'); }); $carousel.find('.btn-next').click(function(e) { e.preventDefault(); e.stopPropagation(); $carousel.carousel('next'); }); }); // } }); } // }); } } }]) .directive('video', ['$timeout', function($timeout) { return { restrict: 'A', link: function(scope, element, attrs) { attrs.$observe('video', function(id) { if(id) { /* Video & Media */ scope.service.app.media(id).then(function(respone) { var media = respone.data; // console.log(media); if(media.length) { var videoHight = 675; if(scope.mobile) videoHight = 200; // var $headerTitle = $('

').addClass('card-title fc-flexica semi-bold margin-0').text('คลิป'); var $videoPreview = $('
').addClass('video-preview'); // var $programVideo = $('
').addClass('program-video owl-carousel'); var $programVideo = $('
').addClass('program-media row'); var $container = $('
').addClass('container'); $timeout(function() { scope.previewVideo(media[0].url); // angular.forEach(media, function(item) { var url = item.url; // var $col = $('
').addClass('item relative cursor-pointer overflow-hidden'); // var $backgroundBlack = $('
').addClass('background-black').css('opacity', '0.5').css('z-index', '2'); // var $icon = $('').addClass('card-icon absolute-center').attr('src', '/public/img/icon/icon-play-video.png'); // var $thumbnail = $('').addClass('card-thumbnail black').attr('src', scope.loadThumbnail(item.thumbnail, url)); var $col = $('
').addClass('col s6 m4 l4'); var $card = $('
').addClass('card-video relative cursor-pointer overflow-hidden'); var $thumbnail = $('').addClass('card-thumbnail').attr('src', scope.loadThumbnail(item.thumbnail, url)); var $backgroundBlack = $('
').addClass('background-black').css('opacity', '0.5').css('z-index', '2'); var $icon = $('').addClass('card-icon absolute-center').attr('src', '/public/img/icon/icon-play-video.png'); // $col.on('click', function() { scope.previewVideo(url); }); $card.append($thumbnail).append($backgroundBlack).append($icon); $programVideo.append($col.append($card)); }); // element.ready(function() { // // owl carousel // $programVideo.owlCarousel({ // loop: false, // margin: 10, // nav: false, // responsive:{ // 0:{ // items: 2 // }, // 600:{ // items: 3 // }, // 1000:{ // items: 3 // } // } // }); // }); }, 1000); scope.previewVideo = function(videoUrl) { $videoPreview.empty(); // // $timeout(function() { if(videoUrl.search("youtube") != -1) { var url = new URL(videoUrl); var videoId = url.searchParams.get("v"); var $iframe = $('