/* global _, angular, i18n */ 'use strict'; var controllers = angular.module('Client.controllers', []); controllers.controller('app', ['$scope','$location','$q','$window','$timeout','$cookies','user','client','program','course','member','learner', function($scope, $location, $q, $window, $timeout, $cookies, user, client, program, course, member, learner) { // //$scope.apikey = '[#apikey]'; //$scope.mobile = false; $scope.year = new Date().getFullYear(); // initial $scope.service = {client, program, course, user, member, learner} $scope.course = {}; $scope.lrs = {}; $scope.institute = {}, $scope.user = {}, $scope.learner = {}, $scope.retry = false; $scope.mobile = screen.width <= 600; // $scope.currentUrl = $location.host(); //$scope.bgAcademy = {'background-color':'#f5f5f5'}; $scope.route = ''; /* layout */ $scope.headbar = true; $scope.fullpage = false; // $scope.loading = true; // $scope.member = true; $scope.authorize = false; $scope.barCookies = false; $scope.init = function() { // prelaunch banner var prelaunch = sessionStorage.getItem("prelaunch"); // if(prelaunch==null) { // $window.location.href = '/prelaunch'; // sessionStorage.setItem("prelaunch", true); // } // $timeout(function() { // $scope.mobile = window.matchMedia("(max-width: 600px)").matches; // console.log($scope.mobile); // }, 900); var interval = setInterval(function() { //console.log(document.readyState) if(document.readyState == 'complete') { //console.log(document.readyState) $window.scrollTo(0, 0); clearInterval(interval); } }, 4000); return; }; $scope.scrollToTop = function () { // Scroll to Top of Page. var deferred = $q.defer(); deferred.resolve(angular.element("html, body").animate({ "scrollTop": 0 })); return deferred.promise; } $scope.back = function () { //console.log('back'); $window.history.back(); }; $scope.timeout = function(delay, callback) { $timeout(function() { if(callback!=undefined) { callback; } else true; }, delay); } $scope.gotoUrl = function(uri) { $window.location = uri; } $scope.openUrl = function(uri, target) { $window.open(uri, target); } $scope.active = function(path) { //console.log(path) return $location.path().match(new RegExp(path + '.*', 'i')) != null; }; $scope.logout = function() { $scope.service.user.clear(); $window.location.href = '/'; }; // $scope.$on('$viewContentLoaded', function(event, viewConfig) { //Here your view content is fully loaded !! $timeout(function() { $scope.loading = false; $scope.checkCookies(); $scope.modalSlider(); }, 900); // /* $(window).focus(function() { console.log('window active') }); $(window).blur(function() { console.log('window inactive') }); */ }); $scope.$on( "$routeChangeStart", function(event, route, current) { $scope.member = true; $scope.loading = true; $scope.fullpage = false; //console.log(route); // $scope.service.client.logged(); // }); // privacy policy cookie $scope.checkCookies = function() { var accept = $cookies.get('privacy'); if(accept != 'accept'){ $scope.policy = true; } } $scope.setCookies = function() { var expireDate = new Date(); expireDate.setDate(expireDate.getDate() + 365); document.cookie = "privacy=accept; expires=" + expireDate + "; path=/"; $scope.policy = false; } /* Modal */ $scope.modalSlider = function() { const $modal = $('
').addClass('modal modal-slider').attr('id', 'modal_slider'); const $content = $('').addClass('modal-content'); // const $link = $('').attr('href','https://eservice.tfac.or.th/cpd_list/CPD_list.php').attr('target', '_blank').css('width', '100%'); const $image = $('