'use strict'; angular.module('PromptSkill.filters', []) .filter('title', [function() { // return function(page) { // var title = 'PROMPT SKILL'; // if(page != undefined) { if(page.length > 0) { title = page + ' | ' + title + "'s "; } } // return title; } }]) .filter('viewport', ['ngMeta', function(ngMeta) { // return function(device) { // var viewport = 'width=device-width, initial-scale=1.0'; if(!_.isUndefined(device)) { 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'; } // window.addEventListener("resize", function () { // if (window.innerWidth > window.innerHeight) { // viewport = 'width=1440'; // ngMeta.setTag('device', 'width=1440'); // alert(viewport); // } else { // viewport = 'width=device-width, initial-scale=1.0'; // } // }); // if (window.matchMedia("(orientation: landscape)").matches && screen.width <= 1024) { // viewport = 'width=1440'; // } else { // } } responsiveDevice(); } // return viewport; } }]) .filter('coursename', ['$sanitize', function($sanitize) { // var tag = (/xhtml/i).test(document.doctype) ? '
' : '
'; return function(text) { // ngSanitize's linky filter changes \r and \n to and respectively text = (text + '').replace(/(\r\n|\n\r|\r|\n| | | | )/g, tag + '$1'); // text = text.split(tag); //console.log(text) if (text[1]!=undefined) { text[1] = ''+text[1]+''; } return $sanitize(text.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('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('numberRoundUp', [function() { // return function(val) { return Math.ceil(val); }; }]) .filter('isEmpty', [function() { // return function(object) { if(object) { return Object.keys(object).length > 0; } }; }]) .filter('time', ['$filter', function($filter) { // return function(minute, locale) { let time_str = '-'; minute = parseInt(minute); if(minute) { const hours = Math.floor(minute / 60); const minutes = minute % 60; time_str = minutes > 0 ? `${hours} ${$filter('phrase')('Hour', locale)} ${minutes} ${$filter('phrase')('Minutes', locale)}` : `${hours} ${$filter('phrase')('Hour', locale)}`; } return time_str; }; }]) .filter('toLocaleString', [function() { // return function(num) { if(num!=undefined) { return parseInt(num).toLocaleString(); } }; }]) .filter('phrase', [function(locale) { // return function(text, locale) { // console.log(text) if(text) { if(locale) { return locale[text]; } return text; } }; }]) .filter('locale', [function() { // return function(locale) { // let language = ''; switch (locale) { case 'en-US': language = 'EN'; break; default: language = 'TH'; } return language; }; }]) .filter('currency', [function() { // return function(unit, payment) { // if(payment=='paysolution') { switch (unit) { case 'USD': unit = '01'; break; default: unit = '00'; } } return unit; }; }]) .filter('price', [function() { // return function(price, unit) { // if(price) { const options = { minimumFractionDigits: 2, maximumFractionDigits: 2 }; price = parseFloat(price).toLocaleString(undefined, options); switch (unit) { case 'USD': price = `US$${price}`; break; case 'Baht': price = `${price} บาท`; break; default: price = '-'; } } return price; }; }]) // .filter('wordcut', [function() { // // // return function(text) { // // // if(text) { // var wordcut = require("wordcut"); // wordcut.init(); // console.log(text); // return wordcut.cut(text); // } // }; // }]) ;