'use strict'; angular.module('DinsorApp.filters', []) .filter('title', [function() { // return function(page) { // var title = 'Creative Thailand'; // if(page != undefined) { if(page.length > 0) { title = title.toUpperCase() + "'s " + page; } } // return title; } }]) .filter('viewport', [function() { // return function(device) { // var viewport = 'width=device-width, initial-scale=1.0'; // // if(device=='mobile') { // viewport = 'width=device-width, initial-scale=1.0'; // } if(!_.isUndefined(device)) { // var viewportTag = document.querySelector("meta[name=viewport]"); var devices = device.replace(/[\s,]+/g, ',').split(","); // console.log(devices); function responsiveDevice() { if(!devices.includes('mobile') && screen.width <= 600) { viewport = 'width=1440'; } if(!devices.includes('tablet') && (screen.width > 600 && screen.width <= 1024)) { viewport = 'width=1920'; } // if(!devices.includes('laptop') && (screen.width > 1024 && screen.width < 1920)) { // viewport = 'width=1920'; // } // viewportTag.setAttribute('content', viewport); } responsiveDevice(); // $(window).on('resize',function() { // viewport = 'width=device-width, initial-scale=1.0'; // responsiveDevice(); // }); } // return viewport; } }]) .filter('fullName', [function() { // return function(profile) { if(profile) { return profile.first_name+' '+profile.last_name; } } }]) .filter('capitalize', [function() { // return function(word) { if(word) { var words = word.toLowerCase().split(' '); function capitalize(str) { return str.charAt(0).toUpperCase() + str.slice(1); } // words.map(capitalize); return words.join(' '); } } }]) .filter('price', function() { // return function(price) { // if (parseInt(price) >0) return price + ' บาท'; } }) .filter('textdate', [function() { // return function(date) { // if(date) { var strDate = ''; var yearAdj = 543; //console.log(date) var months = ['ม.ค.','ก.พ.','มี.ค.','เม.ย.','พ.ค.','มิ.ย.','ก.ค.','ส.ค.','ก.ย.','ต.ค.','พ.ย.','ธ.ค.']; if (typeof date === 'string') { // var t = date.split(/[- :]/); // date = new Date(t[0], t[1] - 1, t[2], t[3] || 0, t[4] || 0, t[5] || 0); } else { date = new Date(date * 1000); } return date.getDate() + " " + months[date.getMonth()] + " " + (date.getFullYear() + yearAdj) } return ''; } }]) .filter('time', [function() { // return function(text) { if(text!=undefined && text.length >0) return text.replace(/[\s]/g, '') + ' น.'; return ''; } }]) .filter('minute', [function() { // return function(time) { // var min = Math.floor(time / 60); if (min >0) return min + ' นาที'; return ''; } }]) .filter('score', [function() { // return function(item) { //console.log(item) if (item.scored == undefined) { item.scored = '-'; } return (item.score >0) ?'(คะแนน '+item.scored+'/'+item.score+')' :'(ไม่มีคะแนน)'; } }]) .filter('progress', [function() { // return function(progress) { // var text = 'จากการเรียน '+progress+'%
คะแนนเต็ม 100%'; return text; } }]) .filter('unsafe', ['$sce', function ($sce) { return function (htmlText) { return $sce.trustAsHtml(htmlText); } }]) .filter('privilege', [function() { // return function(privilege) { // return privilege; } }]) .filter('thaidate', [function() { // return function(date) { // var strDate = ''; var yearAdj = 543; var months = ['ม.ค.','ก.พ.','มี.ค.','เม.ย.','พ.ค.','มิ.ย.','ก.ค.','ส.ค.','ก.ย.','ต.ค.','พ.ย.','ธ.ค.']; //months = ['ม.ค.','ก.พ.','มี.ค.','เม.ย.','พ.ค.','มิ.ย.','ก.ค.','ส.ค.','ก.ย.','ต.ค.','พ.ย.','ธ.ค.']; if (typeof date === 'string') { var t = date.split(/[- :]/); date = new Date(t[0], t[1] - 1, t[2], t[3] || 0, t[4] || 0, t[5] || 0); } else { date = date * 1000; } strDate = date.getDate() + " " + months[date.getMonth()] + " " + (date.getFullYear() + yearAdj) return strDate; } }]) .filter('date_format', [function() { // return function(strDate) { if(strDate) { var date = new Date(strDate.replace(/-/g, '/')); var day = (date.getDate() < 10 ? '0' : '') + date.getDate(); var month = (date.getMonth() < 10 ? '0' : '') + (date.getMonth() + 1); var year = date.getFullYear(); strDate = day + "/" + month + "/" + year; } return strDate; } }]) .filter('date_format_en', [function() { // return function(strDate) { if(strDate) { var date = new Date(strDate.replace(/-/g, '/')); var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; strDate = months[date.getMonth()] + " " + date.getDate() + ", " + date.getFullYear(); } return strDate; } }]) .filter('nl2br', ['$sanitize', function($sanitize) { var tag = (/xhtml/i).test(document.doctype) ? '
' : '
'; // return function(msg) { // ngSanitize's linky filter changes \r and \n to and respectively msg = (msg + '').replace(/(\r\n|\n\r|\r|\n| | | | )/g, tag + '$1'); return $sanitize(msg); }; }]) .filter('trustAsHtml', ['$sce', function($sce) { // return function(text) { return $sce.trustAsHtml(text); }; }]) .filter('trustAsResourceUrl', ['$sce', function($sce) { // return function(val) { return $sce.trustAsResourceUrl(val); }; }]) .filter('filter_url', [function() { // return function(url) { // if (url.indexOf("www") === -1) { url = "https://" + url; } return url; }; }])