{"version":3,"file":"TimeCircles.min.js","sources":["https:\/\/udl.id\/theme\/remui\/amd\/src\/TimeCircles.js"],"sourcesContent":["\/* eslint-disable *\/\n\/**\n * Basic structure: TC_Class is the public class that is returned upon being called\n *\n * So, if you do\n * var tc = $(\".timer\").TimeCircles();\n *\n * tc will contain an instance of the public TimeCircles class. It is important to\n * note that TimeCircles is not chained in the conventional way, check the\n * documentation for more info on how TimeCircles can be chained.\n *\n * After being called\/created, the public TimerCircles class will then- for each element\n * within it's collection, either fetch or create an instance of the private class.\n * Each function called upon the public class will be forwarded to each instance\n * of the private classes within the relevant element collection\n **\/\n 'use strict';\n (function(factory) {\n if (typeof define === 'function' && define.amd) {\n \/\/ AMD. Register as an anonymous module.\n define(['jquery', 'core\/notification'], factory);\n } else if (typeof exports === 'object') {\n \/\/ Node\/CommonJS.\n factory(require('jquery', 'core\/notification'));\n } else {\n \/\/ Browser globals.\n factory(jQuery);\n }\n }(function($, notification) {\n\n var useWindow = window;\n\n \/\/ From https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Object\/keys.\n if (!Object.keys) {\n Object.keys = (function() {\n var hasOwnProperty = Object.prototype.hasOwnProperty,\n hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'),\n dontEnums = [\n 'toString',\n 'toLocaleString',\n 'valueOf',\n 'hasOwnProperty',\n 'isPrototypeOf',\n 'propertyIsEnumerable',\n 'constructor'\n ],\n dontEnumsLength = dontEnums.length;\n\n return function(obj) {\n if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) {\n throw new TypeError('Object.keys called on non-object');\n }\n\n var result = [], prop, i;\n\n for (prop in obj) {\n if (hasOwnProperty.call(obj, prop)) {\n result.push(prop);\n }\n }\n\n if (hasDontEnumBug) {\n for (i = 0; i < dontEnumsLength; i++) {\n if (hasOwnProperty.call(obj, dontEnums[i])) {\n result.push(dontEnums[i]);\n }\n }\n }\n return result;\n };\n }());\n }\n\n \/\/ Used to disable some features on IE8.\n var limited_mode = false;\n var tick_duration = 200; \/\/ In ms.\n\n var debug = (location.hash === \"#debug\");\n function debug_log(msg) {\n if (debug) {\n notification.exception({\n debuginfo: '',\n msg: msg\n });\n }\n }\n\n var allUnits = [\"Days\", \"Hours\", \"Minutes\", \"Seconds\"];\n var nextUnits = {\n Seconds: \"Minutes\",\n Minutes: \"Hours\",\n Hours: \"Days\",\n Days: \"Years\"\n };\n var secondsIn = {\n Seconds: 1,\n Minutes: 60,\n Hours: 3600,\n Days: 86400,\n Months: 2678400,\n Years: 31536000\n };\n\n \/**\n * Converts hex color code into object containing integer values for the r,g,b use\n * This function (hexToRgb) originates from:\n * http:\/\/stackoverflow.com\/questions\/5623838\/rgb-to-hex-and-hex-to-rgb\n * @param {string} hex color code\n *\/\n function hexToRgb(hex) {\n\n \/\/ Verify already RGB (e.g. \"rgb(0,0,0)\") or RGBA (e.g. \"rgba(0,0,0,0.5)\").\n var rgba = \/^rgba?\\(([\\d]+),([\\d]+),([\\d]+)(,([\\d\\.]+))?\\)$\/;\n if (rgba.test(hex)) {\n var result = rgba.exec(hex);\n return {\n r: parseInt(result[1]),\n g: parseInt(result[2]),\n b: parseInt(result[3]),\n a: parseInt(result[5] ? result[5] : 1)\n };\n }\n\n \/\/ Expand shorthand form (e.g. \"03F\") to full form (e.g. \"0033FF\").\n var shorthandRegex = \/^#?([a-f\\d])([a-f\\d])([a-f\\d])$\/i;\n hex = hex.replace(shorthandRegex, function(m, r, g, b) {\n return r + r + g + g + b + b;\n });\n\n var result = \/^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$\/i.exec(hex);\n return result ? {\n r: parseInt(result[1], 16),\n g: parseInt(result[2], 16),\n b: parseInt(result[3], 16)\n } : null;\n }\n\n function isCanvasSupported() {\n var elem = document.createElement('canvas');\n return !!(elem.getContext && elem.getContext('2d'));\n }\n\n \/**\n * Function s4() and guid() originate from:\n * http:\/\/stackoverflow.com\/questions\/105034\/how-to-create-a-guid-uuid-in-javascript\n *\/\n function s4() {\n return Math.floor((1 + Math.random()) * 0x10000)\n .toString(16)\n .substring(1);\n }\n\n \/**\n * Creates a unique id\n * @returns {String}\n *\/\n function guid() {\n return s4() + s4() + '-' + s4() + '-' + s4() + '-' +\n s4() + '-' + s4() + s4() + s4();\n }\n\n if (!Array.prototype.indexOf) {\n \/**\n * Array.prototype.indexOf fallback for IE8\n * @param {Mixed} mixed\n * @returns {Number}\n *\/\n Array.prototype.indexOf = function(elt \/*, from*\/) {\n var len = this.length >>> 0;\n\n var from = Number(arguments[1]) || 0;\n from = (from < 0) ? Math.ceil(from) : Math.floor(from);\n if (from < 0) {\n from += len;\n }\n\n for (; from < len; from++) {\n if (from in this && this[from] === elt) {\n return from;\n }\n }\n return -1;\n };\n }\n\n function parse_date(str) {\n var match = str.match(\/^[0-9]{4}-[0-9]{2}-[0-9]{2}\\s[0-9]{1,2}:[0-9]{2}:[0-9]{2}$\/);\n if (match !== null && match.length > 0) {\n var parts = str.split(\" \");\n var date = parts[0].split(\"-\");\n var time = parts[1].split(\":\");\n return new Date(date[0], date[1] - 1, date[2], time[0], time[1], time[2]);\n }\n \/\/ Fallback for different date formats.\n var d = Date.parse(str);\n if (!isNaN(d)) {\n return d;\n }\n d = Date.parse(str.replace(\/-\/g, '\/').replace('T', ' '));\n if (!isNaN(d)) {\n return d;\n }\n \/\/ Cant find anything.\n return new Date();\n }\n\n function parse_times(diff, old_diff, total_duration, units, floor) {\n var raw_time = {};\n var raw_old_time = {};\n var time = {};\n var pct = {};\n var old_pct = {};\n var old_time = {};\n\n var greater_unit = null;\n for (var i = 0; i < units.length; i++) {\n var unit = units[i];\n var maxUnits;\n\n if (greater_unit === null) {\n maxUnits = total_duration \/ secondsIn[unit];\n } else {\n maxUnits = secondsIn[greater_unit] \/ secondsIn[unit];\n }\n\n var curUnits = (diff \/ secondsIn[unit]);\n var oldUnits = (old_diff \/ secondsIn[unit]);\n\n if (floor) {\n if (curUnits > 0) {\n curUnits = Math.floor(curUnits);\n } else {\n curUnits = Math.ceil(curUnits);\n }\n if (oldUnits > 0) {\n oldUnits = Math.floor(oldUnits);\n } else {\n oldUnits = Math.ceil(oldUnits);\n }\n }\n\n if (unit !== \"Hours\") {\n curUnits = curUnits % maxUnits;\n oldUnits = oldUnits % maxUnits;\n }\n\n raw_time[unit] = curUnits;\n time[unit] = Math.abs(curUnits);\n raw_old_time[unit] = oldUnits;\n old_time[unit] = Math.abs(oldUnits);\n pct[unit] = Math.abs(curUnits) \/ maxUnits;\n old_pct[unit] = Math.abs(oldUnits) \/ maxUnits;\n\n greater_unit = unit;\n }\n\n return {\n raw_time: raw_time,\n raw_old_time: raw_old_time,\n time: time,\n old_time: old_time,\n pct: pct,\n old_pct: old_pct\n };\n }\n\n var TC_Instance_List = {};\n function updateUsedWindow() {\n if (typeof useWindow.TC_Instance_List !== \"undefined\") {\n TC_Instance_List = useWindow.TC_Instance_List;\n }\n else {\n useWindow.TC_Instance_List = TC_Instance_List;\n }\n initializeAnimationFrameHandler(useWindow);\n };\n\n function initializeAnimationFrameHandler(w) {\n var vendors = ['webkit', 'moz'];\n for (var x = 0; x < vendors.length && !w.requestAnimationFrame; ++x) {\n w.requestAnimationFrame = w[vendors[x] + 'RequestAnimationFrame'];\n w.cancelAnimationFrame = w[vendors[x] + 'CancelAnimationFrame'];\n }\n\n if (!w.requestAnimationFrame || !w.cancelAnimationFrame) {\n w.requestAnimationFrame = function(callback, element, instance) {\n if (typeof instance === \"undefined\") {\n instance = {data: {last_frame: 0}};\n }\n var currTime = new Date().getTime();\n var timeToCall = Math.max(0, 16 - (currTime - instance.data.last_frame));\n var id = w.setTimeout(function() {\n callback(currTime + timeToCall);\n }, timeToCall);\n instance.data.last_frame = currTime + timeToCall;\n return id;\n };\n w.cancelAnimationFrame = function(id) {\n clearTimeout(id);\n };\n }\n }\n\n var TC_Instance = function(element, options) {\n this.element = element;\n this.container;\n this.listeners = null;\n this.data = {\n paused: false,\n last_frame: 0,\n animation_frame: null,\n interval_fallback: null,\n timer: false,\n total_duration: null,\n prev_time: null,\n drawn_units: [],\n text_elements: {\n Days: null,\n Hours: null,\n Minutes: null,\n Seconds: null\n },\n attributes: {\n canvas: null,\n context: null,\n item_size: null,\n line_width: null,\n radius: null,\n outer_radius: null\n },\n state: {\n fading: {\n Days: false,\n Hours: false,\n Minutes: false,\n Seconds: false\n }\n }\n };\n\n this.config = null;\n this.setOptions(options);\n this.initialize();\n };\n\n TC_Instance.prototype.clearListeners = function() {\n this.listeners = { all: [], visible: [] };\n };\n\n TC_Instance.prototype.addTime = function(seconds_to_add) {\n if (this.data.attributes.ref_date instanceof Date) {\n var d = this.data.attributes.ref_date;\n d.setSeconds(d.getSeconds() + seconds_to_add);\n }\n else if (!isNaN(this.data.attributes.ref_date)) {\n this.data.attributes.ref_date += (seconds_to_add * 1000);\n }\n };\n\n TC_Instance.prototype.initialize = function(clear_listeners) {\n \/\/ Initialize drawn units.\n this.data.drawn_units = [];\n for (var i = 0; i < Object.keys(this.config.time).length; i++) {\n var unit = Object.keys(this.config.time)[i];\n if (this.config.time[unit].show) {\n this.data.drawn_units.push(unit);\n }\n }\n\n \/\/ Avoid stacking.\n $(this.element).children('div.time_circles').remove();\n\n if (typeof clear_listeners === \"undefined\") {\n clear_listeners = true;\n }\n if (clear_listeners || this.listeners === null) {\n this.clearListeners();\n }\n this.container = $(\"