| Server IP : 62.72.47.131 / Your IP : 216.73.217.34 Web Server : Apache/2.4.66 (Debian) System : Linux 975cdb959a49 5.14.0-611.55.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue May 19 15:19:29 EDT 2026 x86_64 User : ( 501) PHP Version : 8.3.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/html/wp-content/plugins/intl-datetime-calendar/js/ |
Upload File : |
(function(){"use strict";const formatterCache=new Map;function isIntlSupported(){try{if(typeof Intl==="undefined"||typeof Intl.DateTimeFormat==="undefined"){return false}if(typeof Intl.supportedValuesOf!=="function"){console.warn("Intl.supportedValuesOf not available limited calendar support")}new Intl.DateTimeFormat("en",{dateStyle:"full"}).format(new Date);return true}catch(e){return false}}function getFormatter(locale,options){const cacheKey=locale+"|"+JSON.stringify(options);if(!formatterCache.has(cacheKey)){formatterCache.set(cacheKey,new Intl.DateTimeFormat(locale,options))}return formatterCache.get(cacheKey)}function phpFormatToIntlOptions(phpFormat,type){const options={};if(type==="date"||type==="datetime"){options.year="numeric";options.month="long";options.day="numeric"}if(type==="time"||type==="datetime"){options.hour="2-digit";options.minute="2-digit"}if(!phpFormat){return options}const formatMap={Y:{year:"numeric"},y:{year:"2-digit"},F:{month:"long"},M:{month:"short"},m:{month:"2-digit"},n:{month:"numeric"},d:{day:"2-digit"},j:{day:"numeric"},D:{weekday:"short"},l:{weekday:"long"},g:{hour:"numeric",hour12:true},h:{hour:"2-digit",hour12:true},G:{hour:"numeric",hour12:false},H:{hour:"2-digit",hour12:false},i:{minute:"2-digit"},s:{second:"2-digit"},a:{hour12:true,hourCycle:"h12"},A:{hour12:true,hourCycle:"h12"}};for(const char in formatMap){if(formatMap.hasOwnProperty(char)&&phpFormat.includes(char)){Object.assign(options,formatMap[char])}}return options}function formatDateWithCustomFormat(date,format,locale,calendar){if(!date||!format){return""}const getFormatterFor=function(formatChar,extraOptions){extraOptions=extraOptions||{};const cacheKey=formatChar+"|"+locale+"|"+calendar+"|"+JSON.stringify(extraOptions);if(!formatterCache.has(cacheKey)){const options=Object.assign({calendar:calendar},extraOptions);switch(formatChar){case"Y":options.year="numeric";break;case"y":options.year="2-digit";break;case"F":options.month="long";break;case"M":options.month="short";break;case"m":options.month="2-digit";break;case"n":options.month="numeric";break;case"d":options.day="2-digit";break;case"j":options.day="numeric";break;case"D":options.weekday="short";break;case"l":options.weekday="long";break;case"a":case"A":options.hour="numeric";options.hour12=true;break;case"g":options.hour="numeric";options.hour12=true;break;case"h":options.hour="2-digit";options.hour12=true;break;case"G":options.hour="numeric";options.hour12=false;break;case"H":options.hour="2-digit";options.hour12=false;break;case"i":options.minute="2-digit";break;case"s":options.second="2-digit";break}formatterCache.set(cacheKey,new Intl.DateTimeFormat(locale,options))}return formatterCache.get(cacheKey)};const dayOfWeekMap={w:date.getDay(),N:date.getDay()===0?7:date.getDay()};const isThai=locale&&locale.indexOf("th")===0;const isBuddhist=calendar==="buddhist";let result="";let i=0;while(i<format.length){let char=format.charAt(i);if(isThai&&isBuddhist&&(char==="B"||char==="b")){if(char==="B"){result+=String(date.getFullYear()+543)}else{result+=String(date.getFullYear()+543).slice(-2)}i++;continue}if(dayOfWeekMap[char]!==undefined){result+=dayOfWeekMap[char];i++;continue}if(char==="\\"&&i+1<format.length){result+=format.charAt(++i);i++;continue}if(/[YyFMmndjDlaAgGhHis]/.test(char)){try{const formatter=getFormatterFor(char);if(char==="a"||char==="A"){const timeParts=formatter.formatToParts(date);const ampmPart=timeParts.find(function(part){return part.type==="dayPeriod"});if(ampmPart){result+=char==="a"?ampmPart.value.toLowerCase():ampmPart.value.toUpperCase()}else{result+=char==="a"?date.getHours()<12?"am":"pm":date.getHours()<12?"AM":"PM"}}else if(char==="g"){const hourParts=formatter.formatToParts(date);const hourPart=hourParts.find(function(part){return part.type==="hour"});if(hourPart){result+=hourPart.value}else{result+=date.getHours()%12||12}}else{result+=formatter.format(date)}}catch(e){result+=fallbackFormat(date,char)}}else{result+=char}i++}return result}function getWPLocale(){return window.intlDateTimeCalendarSettings&&window.intlDateTimeCalendarSettings.locale||"en"}function formatWithFallback(date,elementSettings){const wpSettings=getSettings();let format;if(elementSettings.customFormat){format=elementSettings.customFormat}else{const type=elementSettings.type||"date";if(type==="date"){format=wpSettings.wp_date_format}else if(type==="time"){format=wpSettings.wp_time_format}else{format=wpSettings.wp_date_format+" "+wpSettings.wp_time_format}}let result="";for(let i=0;i<format.length;i++){const char=format.charAt(i);if(char==="\\"&&i+1<format.length){result+=format.charAt(++i)}else{result+=fallbackFormat(date,char)}}return result}function formatDateTime(timestamp,settings){if(!timestamp){return""}try{const date=new Date(parseInt(timestamp,10));if(isNaN(date.getTime())){return""}const locale=getWPLocale();const calendar=settings.calendar||window.intlDateTimeCalendarSettings&&window.intlDateTimeCalendarSettings.calendar_type||"gregory";if((settings.dateFormat==="custom"||settings.timeFormat==="custom")&&settings.customFormat){return formatDateWithCustomFormat(date,settings.customFormat,locale,calendar)}const formatType=settings.type||"date";let wpFormat;if(formatType==="date"){wpFormat=window.intlDateTimeCalendarSettings&&window.intlDateTimeCalendarSettings.wp_date_format||"F j, Y"}else if(formatType==="time"){wpFormat=window.intlDateTimeCalendarSettings&&window.intlDateTimeCalendarSettings.wp_time_format||"g:i a"}else{const dateFormat=window.intlDateTimeCalendarSettings&&window.intlDateTimeCalendarSettings.wp_date_format||"F j, Y";const timeFormat=window.intlDateTimeCalendarSettings&&window.intlDateTimeCalendarSettings.wp_time_format||"g:i a";wpFormat=dateFormat+" "+timeFormat}const formatOptions=phpFormatToIntlOptions(wpFormat,formatType);formatOptions.calendar=calendar;const formatter=getFormatter(locale,formatOptions);return formatter.format(date)}catch(e){console.error("[Intl DateTime Calendar] Error formatting date:",e,settings);try{const fallbackDate=new Date(parseInt(timestamp,10));return formatWithFallback(fallbackDate,settings)}catch(fallbackError){console.error("[Intl DateTime Calendar] Error fallback formatting date:",fallbackError);return""}}}function fallbackFormat(date,char){const formatChars={d:padZero(date.getDate()),j:date.getDate(),D:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][date.getDay()],l:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][date.getDay()],w:date.getDay(),N:date.getDay()===0?7:date.getDay(),m:padZero(date.getMonth()+1),n:date.getMonth()+1,F:["January","February","March","April","May","June","July","August","September","October","November","December"][date.getMonth()],M:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][date.getMonth()],Y:date.getFullYear(),y:String(date.getFullYear()).slice(-2),a:date.getHours()<12?"am":"pm",A:date.getHours()<12?"AM":"PM",g:date.getHours()%12||12,h:padZero(date.getHours()%12||12),G:date.getHours(),H:padZero(date.getHours()),i:padZero(date.getMinutes()),s:padZero(date.getSeconds())};return formatChars[char]!==undefined?formatChars[char]:char}function padZero(num){return num<10?"0"+num:num}function getSettings(){const settings=window.intlDateTimeCalendarSettings||{};return{locale:settings.locale||"en",calendar_type:settings.calendar_type||"gregory",wp_date_format:settings.wp_date_format||"F j, Y",wp_time_format:settings.wp_time_format||"g:i a"}}function processDateTimeElements(){const settings=getSettings();const elements=document.querySelectorAll(".intl-datetime-element:not([data-intl-processed])");elements.forEach(function(el){const timestamp=el.dataset.intlDatetime;if(!timestamp){return}if(el.dataset.customFormat==="human-diff"){el.setAttribute("data-intl-processed","true");return}el.setAttribute("data-intl-processed","true");const elementSettings={calendar:el.dataset.calendar||settings.calendar_type,locale:settings.locale,type:"datetime",dateFormat:el.dataset.dateFormat||"wp",timeFormat:el.dataset.timeFormat||"wp",customFormat:el.dataset.customFormat||null};const hasDate=elementSettings.dateFormat!=="none";const hasTime=elementSettings.timeFormat!=="none";if(hasDate&&!hasTime){elementSettings.type="date"}else if(!hasDate&&hasTime){elementSettings.type="time"}const formattedDate=formatDateTime(timestamp,elementSettings);if(formattedDate){const link=el.querySelector("a");if(link){link.textContent=formattedDate}else{el.textContent=formattedDate}try{const originalDate=new Date(parseInt(timestamp,10));if(!isNaN(originalDate.getTime())){el.setAttribute("title",formatWithFallback(originalDate,elementSettings))}}catch{}}})}function fixDateTimeInBlocks(){const settings=getSettings();const elements=document.querySelectorAll("time.intl-datetime-element:not([data-intl-processed])");elements.forEach(function(el){const timestamp=el.dataset.intlDatetime;if(!timestamp){return}if(el.dataset.customFormat==="human-diff"){el.setAttribute("data-intl-processed","true");return}el.setAttribute("data-intl-processed","true");const dateFormat=el.dataset.dateFormat;const timeFormat=el.dataset.timeFormat;const customFormat=el.dataset.customFormat;const elementSettings={calendar:el.dataset.calendar||settings.calendar_type,locale:settings.locale};if(dateFormat==="custom"||timeFormat==="custom"){elementSettings.dateFormat=dateFormat;elementSettings.timeFormat=timeFormat;elementSettings.customFormat=customFormat;elementSettings.type="custom"}else{let formatType="datetime";if(dateFormat==="wp"&&timeFormat==="none"){formatType="date"}else if(dateFormat==="none"&&timeFormat==="wp"){formatType="time"}else{const container=el.closest(".wp-block-post-date, .wp-block-post-time");if(container){formatType=container.classList.contains("wp-block-post-date")?"date":"time"}}elementSettings.type=formatType}const formattedDate=formatDateTime(timestamp,elementSettings);if(!formattedDate){return}const link=el.querySelector("a");if(link){link.textContent=formattedDate}else{el.textContent=formattedDate}})}function debounce(func,wait){let timeout;return function(){const context=this;const args=arguments;clearTimeout(timeout);timeout=setTimeout(function(){func.apply(context,args)},wait)}}function onReady(){processDateTimeElements();fixDateTimeInBlocks();const processDebounced=debounce(function(){processDateTimeElements();fixDateTimeInBlocks()},250);if(typeof MutationObserver==="function"){const observer=new MutationObserver(processDebounced);observer.observe(document.body,{childList:true,subtree:true})}}function init(){if(!window.intlDateTimeCalendarSettings){console.error("[Intl DateTime Calendar] Settings not loaded properly")}if(!isIntlSupported()){console.warn("Intl API is not fully supported in this browser. Date formatting will use browser defaults.");return}if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",onReady)}else{onReady()}}init()})();