define('jira/jquery/plugins/livestamp/livestamp', [ 'jquery', 'jira/skate', 'jira/moment', 'jira/util/data/meta', 'jira/jquery/plugins/livestamp/time' ], function ($, skate, moment, Meta, Time) { "use strict"; var UPDATE_INTERVAL = 6000; var relativize = Meta.getBoolean("date-relativize"); skate('livestamp', { type: skate.type.CLASSNAME, prototype: { update: function() { var $this = $(this); var forceRelativize = $this.data('relativize'); var timestamp = $this.attr("datetime"); if (timestamp) { //reset the timezone to what's specified by the timestamp timestamp = isNaN(timestamp) ? // assuming iso8601 timestamp, let moment#zone() handle it moment(timestamp).zone(timestamp) : // unix epoch timestamp (in milli-seconds) moment(parseInt(timestamp, 10)) ; if (moment.isMoment(timestamp) && timestamp.isValid()) { var tsFormat = $this.data("datetime-format"); tsFormat = tsFormat ? tsFormat : "fullAge"; // TODO We should transition to longAge. if (!(relativize || forceRelativize)) { // We should try not to have any tsFormats like 'AgeAge' tsFormat = tsFormat.replace("Age", ""); } var to = Time.formatDate(timestamp, Time.FormatType.types[tsFormat], forceRelativize); if ($this.text() !== to) { $this.text(to); } return true; } } return false; }, onTimeout: function() { if (this.timerId) { clearTimeout(this.timerId); this.timerId = false; } var ok = this.update(); if (ok) { this.timerId = setTimeout(this.onTimeout.bind(this), UPDATE_INTERVAL); } } }, // // Event listeners // // On attribute updated attributes: function(elem) { elem.onTimeout(); }, attached: function(elem) { elem.onTimeout(); }, detached: function(elem) { clearTimeout(elem.timerId); elem.timerId = false; } }); // @Deprecated $.fn.livestamp = function () { return this; }; }); // Make extension available in global scope immediately / synchronously. // TODO INC-71 - remove synchronous require (function() { require('jira/jquery/plugins/livestamp/livestamp'); })();