/* global _, angular, i18n, Ladda, Odometer */ 'use strict'; angular.module('DinsorApp.directives', []) /* layouts */ .directive('dinsorBar', [function() { return { restrict: 'C', templateUrl: '/templates/layouts/dinsor-bar.valuecreation' }; }]) .directive('privacy', [function() { return { restrict: 'C', templateUrl: '/templates/layouts/privacy.valuecreation', }; }]) .directive('copyright', [function() { return { restrict: 'C', templateUrl: '/templates/layouts/copyright.valuecreation' }; }]) .directive('headBar', [function() { return { restrict: 'A', template: '
', link: function(scope, element, attrs) { scope.$watch('headbar', function(newValue, oldValue) { // console.log(newValue) if(newValue) { scope.navigation = 'templates/layouts/header.valuecreation'; } }); } }; }]) .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('sitemap', [function() { return { restrict: 'A', templateUrl: '/templates/layouts/sitemap.valuecreation', 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; //}); }); } }; }]) /* 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('language', [function() { return { restrict: 'A', link: function(scope, element, attrs) { attrs.$observe('language', function(lang) { if (lang == '') { lang = 'th'; } var $icon = $('').attr('width', '35').attr('src', '/public/img/icon/icon-globe-'+ lang +'.png'); element.append($icon); }); } } }]) .directive('tabBar', [function() { return { restrict: 'A', link: function(scope, element, attrs) { $(document).ready(function() { element.find('.tabs').tabs(); }); // } } }]) .directive('carouselSlider', [function() { return { restrict: 'A', link: function(scope, element, attrs) { var resourceUrl = scope.resourceUrl; var $carousel = $('
').addClass('carousel carousel-slider'); element.append($carousel); scope.service.app.banners().then(function(banners) { // console.log(banners); angular.forEach(banners, function(item) { // if(item.banner_status == 1) { var bannerUrl = resourceUrl + item.banner_img; var $item = $('').addClass('carousel-item').attr('href', item.banner_link); var $image = $('
').addClass('relative'); var $gradient = $('
').addClass('bg-gradient'); // var img = new Image(); // img.onload = function() { // var ratio = this.height / this.width; // $image.css('padding-top', ratio *100+'%'); // $carousel.css('padding-top', ratio *100+'%'); // } // img.src = 'https:' + bannerUrl; $carousel.css('padding-top', '56.25%'); $image.css('height', '100%'); $image.css('background-image', "url('"+ bannerUrl +"')").addClass('background-image width center-bottom'); $item.append($image.append($gradient)); $carousel.append($item); // } }); $(document).ready(function() { // initialization carrousel slider $carousel.carousel({ fullWidth: true, indicators: true }); // auto next slide banner setInterval(function () { $carousel.carousel('next'); }, 6000); }); // }); // } } }]) /* style */ .directive('fitBrief', ['$timeout', function($timeout) { return { restrict: 'A', priority: 10, link: function(scope, element, attrs) { scope.$watch(attrs.ngBindHtml, function(value) { var fontSize = parseInt(element.css('font-size')); var margin = element.parent().css('margin'); //console.log(margin) $timeout(function() { if(value !=undefined) { var blockBrief = element.prev(); var brief = blockBrief.find('.brief'); // //console.log(blockBrief); //console.log(blockBrief.outerHeight()); //console.log(brief.height()) var marginTop = (blockBrief.height() -brief.height()) /fontSize; element.children().children().children(':first-child').css('margin-top', -marginTop+'em').css('margin-left', '-4%'); } }) }) } } }]) /* page */ .directive('page', [function() { return { restrict: 'A', link: function(scope, element, attrs) { var paddingTop = 64; attrs.$observe('page', function(name) { element.removeAttr('page').attr('id', name); }); } }; }]) .directive('pageBanner', [function() { return { restrict: 'A', link: function(scope, element, attrs) { var designWidth = 1920; attrs.$observe('pageBanner', function(banner) { if(banner) { element.removeAttr('page-banner') //if(attrs.fit=='width') { //var img = new Image(); //img.onload = function() { // var height = this.height / designWidth; // element.css('height', height *100+'vw'); //} //img.src = 'https:' + banner; element.css('background-image', "url('"+banner+"')").addClass(attrs.fit); } }); } } }]) .directive('popupIntro', [function() { return { restrict: 'A', link: function(scope, element, attrs) { //mockup var banners = [ { "banner_img": "https://valuecreation.ditp.go.th/uploads/iLHfXi0jwCAuPY6.jpg", "banner_url": "https://valuecreation.ditp.go.th/" }, { "banner_img": "https://valuecreation.ditp.go.th/uploads/gES9Vsu4DoIryWz.jpg", "banner_url": "https://valuecreation.ditp.go.th/" } ]; // var $modal = $('
').addClass('modal'); var $btnClose = $('').addClass('modal-close btn-floating red'); $btnClose.append($('').addClass('material-icons').text('close')); var $slider = $('
').addClass('slider relative'); var $ul = $('