'use strict'; angular.module('PromptSkill.filters', []) .filter('title', [function() { // return function(page) { // //console.log($('title').text()) var title = "PROMPT SKILL's E-Learning Platform"; // if (page != undefined) { if (page.length > 0) { title = page + " : " + title; } } // return title; } }]) .filter('viewport', [function() { // 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'; } } 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('time', [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, format) { // 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 * 1000); var day = (date.getDate() < 10 ? '0' : '') + date.getDate(); var month = (date.getMonth() + 1 < 10 ? '0' : '') + (date.getMonth() + 1); var year = date.getFullYear(); // strDate = day + "/" + month + "/" + year; } return strDate; } }]) .filter('date_format_th', [function() { // return function(strDate) { if (strDate) { var date = new Date(strDate * 1000); var months = ['มกราคม', 'กุมภาพันธ์', 'มีนาคม', 'เมษายน', 'พฤษภาคม', 'มิถุนายน', 'กรกฎาคม', 'สิงหาคม', 'กันยายน', 'ตุลาคม', 'พฤศจิกายน', 'ธันวาคม']; var yearAdj = 543; // var day = date.getDate(); // var day = (date.getDate() < 10 ? '0' : '') + date.getDate(); var month = months[date.getMonth()]; var year = date.getFullYear() + yearAdj; // strDate = day + " " + month + " " + year; } return strDate; } }]) .filter('isEmpty', [function() { // return function(object) { // console.log(object) if (object != undefined) { return Object.keys(object).length > 0; } return false; }; }]) .filter('numberRoundUp', [function() { // return function(val) { return Math.ceil(val); }; }]) .filter('phrase', [function(locale) { // return function(text, locale) { // console.log(locale) if (text) { if (locale) { return locale[text]; } return text; } }; }]) .filter('truncateDecimal2', [function() { // return function(input) { if (isNaN(input)) return input; return Math.floor(parseFloat(input) * 100) / 100; }; }])