/* global _, angular, i18n, Ladda, Odometer */ 'use strict'; angular.module('DinsorApp.directives', []) /* Layouts */ .directive('promptskillBar', [function() { return { restrict: 'C', templateUrl: '/templates/layouts/dinsor-bar.creativethailand' }; }]) .directive('cookiePolicy', [function() { return { restrict: 'C', templateUrl: '/templates/layouts/cookie-policy.creativethailand', }; }]) .directive('copyright', [function() { return { restrict: 'C', templateUrl: '/templates/layouts/copyright.creativethailand' }; }]) .directive('headBar', ['$routeParams', '$timeout', function($routeParams, $timeout) { return { restrict: 'A', template: '
', link: function(scope, element, attrs) { // scope.$watch('headbar', function(newValue, oldValue) { // console.log(newValue) console.log($routeParams) if (newValue) { scope.navigation = 'templates/layouts/header.creativethailand'; } }); } }; }]) .directive('headbarLogo', [function() { return { restrict: 'A', link: function(scope, element, attrs) { var logo = ''; //console.log(logo) if (logo) { var $img = $('
').append($('').attr('src', logo)); element.append($img.addClass('valign-wrapper')); } } } }]) .directive('sideNavigator', [function() { return { restrict: 'C', link: function(scope, element, attrs) { // element.ready(function() { // var sidenav = $('.sidenav'); sidenav.sidenav(); }); // } } }]) .directive('sitemap', [function() { return { restrict: 'A', templateUrl: '/templates/layouts/sitemap.creativethailand', 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('prelaunch', ['$window', function($window) { return { restrict: 'A', link: function(scope, element, attrs) { // scope.$parent.headbar = false; scope.$parent.footer = true; attrs.$observe('prelaunch', function(banner) { // console.log(banner); if (banner) { const $bannerIntro = element.find('.banner-intro'); $bannerIntro.css('background-image', `url('/public/uploads/banner/${ scope.banner_landing.banner_image }')`); if (scope.banner_landing.banner_url !== null) { $bannerIntro.css('cursor', 'pointer'); $bannerIntro.click(function() { $window.location.href = scope.banner_landing.banner_url; }); } } }); // to weppage function scope.toWebPage = function() { $window.location.href = '/'; } } } }]) /* 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('background-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('gallery', ['$timeout', function($timeout) { return { restrict: 'A', link: function(scope, element, attrs) { attrs.$observe('gallery', function(portfolio) { // card gallery if (portfolio) { var portfolio = JSON.parse(portfolio); // if (portfolio.length) { // 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); }); element.append($carousel.append($btnPrev).append($btnNext)); element.removeAttr('gallery'); // element.ready(function() { // carousel var carousel = element.find('.carousel.carousel-slider'); $timeout(function() { carousel.carousel({ fullWidth: true }); }, 1000); element.find('.btn-prev').click(function(e) { e.preventDefault(); e.stopPropagation(); carousel.carousel('prev'); }); element.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(url) { // card video if (url) { var videoUrl = url; // $timeout(function() { if (videoUrl.search("youtube") != -1) { var url = new URL(videoUrl); var videoId = url.searchParams.get("v"); var $iframe = $('