jquery.browser,cookie,timeago from npmjs (#5636)
This commit is contained in:
Родитель
1aa6d6af27
Коммит
6f7eea91a1
|
@ -13,7 +13,10 @@ STATIC_JQUERY_UI := static/js/node_lib/ui/
|
|||
|
||||
NODE_LIBS_JS := \
|
||||
less/dist/less.js \
|
||||
jquery/dist/jquery.js
|
||||
jquery/dist/jquery.js \
|
||||
jquery.browser/dist/jquery.browser.js \
|
||||
jquery.cookie/jquery.cookie.js \
|
||||
timeago/jquery.timeago.js \
|
||||
|
||||
NODE_LIBS_JQUERY_UI := \
|
||||
jquery-ui/ui/version.js \
|
||||
|
|
|
@ -14,9 +14,12 @@
|
|||
"clean-css": "4.1.3",
|
||||
"clean-css-cli": "4.1.4",
|
||||
"jquery": "1.12.0",
|
||||
"jquery.browser": "0.1.0",
|
||||
"jquery.cookie": "1.4.1",
|
||||
"jquery-ui": "1.12.1",
|
||||
"less": "2.7.2",
|
||||
"stylus": "0.54.5",
|
||||
"timeago": "1.5.4",
|
||||
"uglify-js": "3.0.15"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -674,7 +674,7 @@ MINIFY_BUNDLES = {
|
|||
'js/zamboni/init.js',
|
||||
'js/impala/capabilities.js',
|
||||
'js/lib/format.js',
|
||||
'js/lib/jquery.cookie.js',
|
||||
'js/node_lib/jquery.cookie.js',
|
||||
'js/zamboni/storage.js',
|
||||
'js/zamboni/buttons.js',
|
||||
'js/zamboni/tabs.js',
|
||||
|
@ -748,7 +748,7 @@ MINIFY_BUNDLES = {
|
|||
# Impala and Legacy: Things to be loaded at the top of the page
|
||||
'preload': (
|
||||
'js/node_lib/jquery.js',
|
||||
'js/lib/jquery.browser.js',
|
||||
'js/node_lib/jquery.browser.js',
|
||||
'js/impala/preloaded.js',
|
||||
'js/zamboni/analytics.js',
|
||||
),
|
||||
|
@ -764,7 +764,7 @@ MINIFY_BUNDLES = {
|
|||
'js/zamboni/init.js',
|
||||
'js/impala/capabilities.js',
|
||||
'js/lib/format.js',
|
||||
'js/lib/jquery.cookie.js',
|
||||
'js/node_lib/jquery.cookie.js',
|
||||
'js/zamboni/storage.js',
|
||||
'js/zamboni/buttons.js',
|
||||
'js/lib/jquery.pjax.js',
|
||||
|
@ -853,7 +853,7 @@ MINIFY_BUNDLES = {
|
|||
),
|
||||
'zamboni/discovery': (
|
||||
'js/node_lib/jquery.js',
|
||||
'js/lib/jquery.browser.js',
|
||||
'js/node_lib/jquery.browser.js',
|
||||
'js/lib/underscore.js',
|
||||
'js/zamboni/browser.js',
|
||||
'js/zamboni/init.js',
|
||||
|
@ -863,7 +863,7 @@ MINIFY_BUNDLES = {
|
|||
'js/zamboni/analytics.js',
|
||||
|
||||
# Add-ons details
|
||||
'js/lib/jquery.cookie.js',
|
||||
'js/node_lib/jquery.cookie.js',
|
||||
'js/zamboni/storage.js',
|
||||
'js/zamboni/buttons.js',
|
||||
'js/lib/ui.lightbox.js',
|
||||
|
@ -894,7 +894,7 @@ MINIFY_BUNDLES = {
|
|||
'js/impala/formset.js',
|
||||
'js/zamboni/devhub.js',
|
||||
'js/zamboni/validator.js',
|
||||
'js/lib/jquery.timeago.js',
|
||||
'js/node_lib/jquery.timeago.js',
|
||||
),
|
||||
'zamboni/editors': (
|
||||
'js/lib/highcharts.src.js',
|
||||
|
|
|
@ -1,193 +0,0 @@
|
|||
/*!
|
||||
* jQuery Browser Plugin 0.1.0
|
||||
* https://github.com/gabceb/jquery-browser-plugin
|
||||
*
|
||||
* Original jquery-browser code Copyright 2005, 2015 jQuery Foundation, Inc. and other contributors
|
||||
* http://jquery.org/license
|
||||
*
|
||||
* Modifications Copyright 2015 Gabriel Cebrian
|
||||
* https://github.com/gabceb
|
||||
*
|
||||
* Released under the MIT license
|
||||
*
|
||||
* Date: 05-07-2015
|
||||
*/
|
||||
/*global window: false */
|
||||
|
||||
(function (factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['jquery'], function ($) {
|
||||
return factory($);
|
||||
});
|
||||
} else if (typeof module === 'object' && typeof module.exports === 'object') {
|
||||
// Node-like environment
|
||||
module.exports = factory(require('jquery'));
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(window.jQuery);
|
||||
}
|
||||
}(function(jQuery) {
|
||||
"use strict";
|
||||
|
||||
function uaMatch( ua ) {
|
||||
// If an UA is not provided, default to the current browser UA.
|
||||
if ( ua === undefined ) {
|
||||
ua = window.navigator.userAgent;
|
||||
}
|
||||
ua = ua.toLowerCase();
|
||||
|
||||
var match = /(edge)\/([\w.]+)/.exec( ua ) ||
|
||||
/(opr)[\/]([\w.]+)/.exec( ua ) ||
|
||||
/(chrome)[ \/]([\w.]+)/.exec( ua ) ||
|
||||
/(iemobile)[\/]([\w.]+)/.exec( ua ) ||
|
||||
/(version)(applewebkit)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) ||
|
||||
/(webkit)[ \/]([\w.]+).*(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) ||
|
||||
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
|
||||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
|
||||
/(msie) ([\w.]+)/.exec( ua ) ||
|
||||
ua.indexOf("trident") >= 0 && /(rv)(?::| )([\w.]+)/.exec( ua ) ||
|
||||
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
|
||||
[];
|
||||
|
||||
var platform_match = /(ipad)/.exec( ua ) ||
|
||||
/(ipod)/.exec( ua ) ||
|
||||
/(windows phone)/.exec( ua ) ||
|
||||
/(iphone)/.exec( ua ) ||
|
||||
/(kindle)/.exec( ua ) ||
|
||||
/(silk)/.exec( ua ) ||
|
||||
/(android)/.exec( ua ) ||
|
||||
/(win)/.exec( ua ) ||
|
||||
/(mac)/.exec( ua ) ||
|
||||
/(linux)/.exec( ua ) ||
|
||||
/(cros)/.exec( ua ) ||
|
||||
/(playbook)/.exec( ua ) ||
|
||||
/(bb)/.exec( ua ) ||
|
||||
/(blackberry)/.exec( ua ) ||
|
||||
[];
|
||||
|
||||
var browser = {},
|
||||
matched = {
|
||||
browser: match[ 5 ] || match[ 3 ] || match[ 1 ] || "",
|
||||
version: match[ 2 ] || match[ 4 ] || "0",
|
||||
versionNumber: match[ 4 ] || match[ 2 ] || "0",
|
||||
platform: platform_match[ 0 ] || ""
|
||||
};
|
||||
|
||||
if ( matched.browser ) {
|
||||
browser[ matched.browser ] = true;
|
||||
browser.version = matched.version;
|
||||
browser.versionNumber = parseInt(matched.versionNumber, 10);
|
||||
}
|
||||
|
||||
if ( matched.platform ) {
|
||||
browser[ matched.platform ] = true;
|
||||
}
|
||||
|
||||
// These are all considered mobile platforms, meaning they run a mobile browser
|
||||
if ( browser.android || browser.bb || browser.blackberry || browser.ipad || browser.iphone ||
|
||||
browser.ipod || browser.kindle || browser.playbook || browser.silk || browser[ "windows phone" ]) {
|
||||
browser.mobile = true;
|
||||
}
|
||||
|
||||
// These are all considered desktop platforms, meaning they run a desktop browser
|
||||
if ( browser.cros || browser.mac || browser.linux || browser.win ) {
|
||||
browser.desktop = true;
|
||||
}
|
||||
|
||||
// Chrome, Opera 15+ and Safari are webkit based browsers
|
||||
if ( browser.chrome || browser.opr || browser.safari ) {
|
||||
browser.webkit = true;
|
||||
}
|
||||
|
||||
// IE11 has a new token so we will assign it msie to avoid breaking changes
|
||||
if ( browser.rv || browser.iemobile) {
|
||||
var ie = "msie";
|
||||
|
||||
matched.browser = ie;
|
||||
browser[ie] = true;
|
||||
}
|
||||
|
||||
// Edge is officially known as Microsoft Edge, so rewrite the key to match
|
||||
if ( browser.edge ) {
|
||||
delete browser.edge;
|
||||
var msedge = "msedge";
|
||||
|
||||
matched.browser = msedge;
|
||||
browser[msedge] = true;
|
||||
}
|
||||
|
||||
// Blackberry browsers are marked as Safari on BlackBerry
|
||||
if ( browser.safari && browser.blackberry ) {
|
||||
var blackberry = "blackberry";
|
||||
|
||||
matched.browser = blackberry;
|
||||
browser[blackberry] = true;
|
||||
}
|
||||
|
||||
// Playbook browsers are marked as Safari on Playbook
|
||||
if ( browser.safari && browser.playbook ) {
|
||||
var playbook = "playbook";
|
||||
|
||||
matched.browser = playbook;
|
||||
browser[playbook] = true;
|
||||
}
|
||||
|
||||
// BB10 is a newer OS version of BlackBerry
|
||||
if ( browser.bb ) {
|
||||
var bb = "blackberry";
|
||||
|
||||
matched.browser = bb;
|
||||
browser[bb] = true;
|
||||
}
|
||||
|
||||
// Opera 15+ are identified as opr
|
||||
if ( browser.opr ) {
|
||||
var opera = "opera";
|
||||
|
||||
matched.browser = opera;
|
||||
browser[opera] = true;
|
||||
}
|
||||
|
||||
// Stock Android browsers are marked as Safari on Android.
|
||||
if ( browser.safari && browser.android ) {
|
||||
var android = "android";
|
||||
|
||||
matched.browser = android;
|
||||
browser[android] = true;
|
||||
}
|
||||
|
||||
// Kindle browsers are marked as Safari on Kindle
|
||||
if ( browser.safari && browser.kindle ) {
|
||||
var kindle = "kindle";
|
||||
|
||||
matched.browser = kindle;
|
||||
browser[kindle] = true;
|
||||
}
|
||||
|
||||
// Kindle Silk browsers are marked as Safari on Kindle
|
||||
if ( browser.safari && browser.silk ) {
|
||||
var silk = "silk";
|
||||
|
||||
matched.browser = silk;
|
||||
browser[silk] = true;
|
||||
}
|
||||
|
||||
// Assign the name and platform variable
|
||||
browser.name = matched.browser;
|
||||
browser.platform = matched.platform;
|
||||
return browser;
|
||||
}
|
||||
|
||||
// Run the matching process, also assign the function to the returned object
|
||||
// for manual, jQuery-free use if desired
|
||||
window.jQBrowser = uaMatch( window.navigator.userAgent );
|
||||
window.jQBrowser.uaMatch = uaMatch;
|
||||
|
||||
// Only assign to jQuery.browser if jQuery is loaded
|
||||
if ( jQuery ) {
|
||||
jQuery.browser = window.jQBrowser;
|
||||
}
|
||||
|
||||
return window.jQBrowser;
|
||||
}));
|
|
@ -1,96 +0,0 @@
|
|||
/**
|
||||
* Cookie plugin
|
||||
*
|
||||
* Copyright (c) 2006 Klaus Hartl (stilbuero.de)
|
||||
* Dual licensed under the MIT and GPL licenses:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create a cookie with the given name and value and other optional parameters.
|
||||
*
|
||||
* @example $.cookie('the_cookie', 'the_value');
|
||||
* @desc Set the value of a cookie.
|
||||
* @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
|
||||
* @desc Create a cookie with all available options.
|
||||
* @example $.cookie('the_cookie', 'the_value');
|
||||
* @desc Create a session cookie.
|
||||
* @example $.cookie('the_cookie', null);
|
||||
* @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
|
||||
* used when the cookie was set.
|
||||
*
|
||||
* @param String name The name of the cookie.
|
||||
* @param String value The value of the cookie.
|
||||
* @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
|
||||
* @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
|
||||
* If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
|
||||
* If set to null or omitted, the cookie will be a session cookie and will not be retained
|
||||
* when the the browser exits.
|
||||
* @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
|
||||
* @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
|
||||
* @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
|
||||
* require a secure protocol (like HTTPS).
|
||||
* @type undefined
|
||||
*
|
||||
* @name $.cookie
|
||||
* @cat Plugins/Cookie
|
||||
* @author Klaus Hartl/klaus.hartl@stilbuero.de
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get the value of a cookie with the given name.
|
||||
*
|
||||
* @example $.cookie('the_cookie');
|
||||
* @desc Get the value of a cookie.
|
||||
*
|
||||
* @param String name The name of the cookie.
|
||||
* @return The value of the cookie.
|
||||
* @type String
|
||||
*
|
||||
* @name $.cookie
|
||||
* @cat Plugins/Cookie
|
||||
* @author Klaus Hartl/klaus.hartl@stilbuero.de
|
||||
*/
|
||||
jQuery.cookie = function(name, value, options) {
|
||||
if (typeof value != 'undefined') { // name and value given, set cookie
|
||||
options = options || {};
|
||||
if (value === null) {
|
||||
value = '';
|
||||
options.expires = -1;
|
||||
}
|
||||
var expires = '';
|
||||
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
|
||||
var date;
|
||||
if (typeof options.expires == 'number') {
|
||||
date = new Date();
|
||||
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
|
||||
} else {
|
||||
date = options.expires;
|
||||
}
|
||||
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
|
||||
}
|
||||
// CAUTION: Needed to parenthesize options.path and options.domain
|
||||
// in the following expressions, otherwise they evaluate to undefined
|
||||
// in the packed version for some reason...
|
||||
var path = options.path ? '; path=' + (options.path) : '';
|
||||
var domain = options.domain ? '; domain=' + (options.domain) : '';
|
||||
var secure = options.secure ? '; secure' : '';
|
||||
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
|
||||
} else { // only name given, get cookie
|
||||
var cookieValue = null;
|
||||
if (document.cookie && document.cookie != '') {
|
||||
var cookies = document.cookie.split(';');
|
||||
for (var i = 0; i < cookies.length; i++) {
|
||||
var cookie = jQuery.trim(cookies[i]);
|
||||
// Does this cookie string begin with the name we want?
|
||||
if (cookie.substring(0, name.length + 1) == (name + '=')) {
|
||||
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cookieValue;
|
||||
}
|
||||
};
|
|
@ -1,231 +0,0 @@
|
|||
/**
|
||||
* Timeago is a jQuery plugin that makes it easy to support automatically
|
||||
* updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago").
|
||||
*
|
||||
* @name timeago
|
||||
* @version 1.5.3
|
||||
* @requires jQuery v1.2.3+
|
||||
* @author Ryan McGeary
|
||||
* @license MIT License - http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
* For usage and examples, visit:
|
||||
* http://timeago.yarp.com/
|
||||
*
|
||||
* Copyright (c) 2008-2015, Ryan McGeary (ryan -[at]- mcgeary [*dot*] org)
|
||||
*/
|
||||
|
||||
(function (factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['jquery'], factory);
|
||||
} else if (typeof module === 'object' && typeof module.exports === 'object') {
|
||||
factory(require('jquery'));
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(jQuery);
|
||||
}
|
||||
}(function ($) {
|
||||
$.timeago = function(timestamp) {
|
||||
if (timestamp instanceof Date) {
|
||||
return inWords(timestamp);
|
||||
} else if (typeof timestamp === "string") {
|
||||
return inWords($.timeago.parse(timestamp));
|
||||
} else if (typeof timestamp === "number") {
|
||||
return inWords(new Date(timestamp));
|
||||
} else {
|
||||
return inWords($.timeago.datetime(timestamp));
|
||||
}
|
||||
};
|
||||
var $t = $.timeago;
|
||||
|
||||
$.extend($.timeago, {
|
||||
settings: {
|
||||
refreshMillis: 60000,
|
||||
allowPast: true,
|
||||
allowFuture: false,
|
||||
localeTitle: false,
|
||||
cutoff: 0,
|
||||
autoDispose: true,
|
||||
strings: {
|
||||
prefixAgo: null,
|
||||
prefixFromNow: null,
|
||||
suffixAgo: "ago",
|
||||
suffixFromNow: "from now",
|
||||
inPast: 'any moment now',
|
||||
seconds: "less than a minute",
|
||||
minute: "about a minute",
|
||||
minutes: "%d minutes",
|
||||
hour: "about an hour",
|
||||
hours: "about %d hours",
|
||||
day: "a day",
|
||||
days: "%d days",
|
||||
month: "about a month",
|
||||
months: "%d months",
|
||||
year: "about a year",
|
||||
years: "%d years",
|
||||
wordSeparator: " ",
|
||||
numbers: []
|
||||
}
|
||||
},
|
||||
|
||||
inWords: function(distanceMillis) {
|
||||
if (!this.settings.allowPast && ! this.settings.allowFuture) {
|
||||
throw 'timeago allowPast and allowFuture settings can not both be set to false.';
|
||||
}
|
||||
|
||||
var $l = this.settings.strings;
|
||||
var prefix = $l.prefixAgo;
|
||||
var suffix = $l.suffixAgo;
|
||||
if (this.settings.allowFuture) {
|
||||
if (distanceMillis < 0) {
|
||||
prefix = $l.prefixFromNow;
|
||||
suffix = $l.suffixFromNow;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.settings.allowPast && distanceMillis >= 0) {
|
||||
return this.settings.strings.inPast;
|
||||
}
|
||||
|
||||
var seconds = Math.abs(distanceMillis) / 1000;
|
||||
var minutes = seconds / 60;
|
||||
var hours = minutes / 60;
|
||||
var days = hours / 24;
|
||||
var years = days / 365;
|
||||
|
||||
function substitute(stringOrFunction, number) {
|
||||
var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, distanceMillis) : stringOrFunction;
|
||||
var value = ($l.numbers && $l.numbers[number]) || number;
|
||||
return string.replace(/%d/i, value);
|
||||
}
|
||||
|
||||
var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) ||
|
||||
seconds < 90 && substitute($l.minute, 1) ||
|
||||
minutes < 45 && substitute($l.minutes, Math.round(minutes)) ||
|
||||
minutes < 90 && substitute($l.hour, 1) ||
|
||||
hours < 24 && substitute($l.hours, Math.round(hours)) ||
|
||||
hours < 42 && substitute($l.day, 1) ||
|
||||
days < 30 && substitute($l.days, Math.round(days)) ||
|
||||
days < 45 && substitute($l.month, 1) ||
|
||||
days < 365 && substitute($l.months, Math.round(days / 30)) ||
|
||||
years < 1.5 && substitute($l.year, 1) ||
|
||||
substitute($l.years, Math.round(years));
|
||||
|
||||
var separator = $l.wordSeparator || "";
|
||||
if ($l.wordSeparator === undefined) { separator = " "; }
|
||||
return $.trim([prefix, words, suffix].join(separator));
|
||||
},
|
||||
|
||||
parse: function(iso8601) {
|
||||
var s = $.trim(iso8601);
|
||||
s = s.replace(/\.\d+/,""); // remove milliseconds
|
||||
s = s.replace(/-/,"/").replace(/-/,"/");
|
||||
s = s.replace(/T/," ").replace(/Z/," UTC");
|
||||
s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
|
||||
s = s.replace(/([\+\-]\d\d)$/," $100"); // +09 -> +0900
|
||||
return new Date(s);
|
||||
},
|
||||
datetime: function(elem) {
|
||||
var iso8601 = $t.isTime(elem) ? $(elem).attr("datetime") : $(elem).attr("title");
|
||||
return $t.parse(iso8601);
|
||||
},
|
||||
isTime: function(elem) {
|
||||
// jQuery's `is()` doesn't play well with HTML5 in IE
|
||||
return $(elem).get(0).tagName.toLowerCase() === "time"; // $(elem).is("time");
|
||||
}
|
||||
});
|
||||
|
||||
// functions that can be called via $(el).timeago('action')
|
||||
// init is default when no action is given
|
||||
// functions are called with context of a single element
|
||||
var functions = {
|
||||
init: function() {
|
||||
var refresh_el = $.proxy(refresh, this);
|
||||
refresh_el();
|
||||
var $s = $t.settings;
|
||||
if ($s.refreshMillis > 0) {
|
||||
this._timeagoInterval = setInterval(refresh_el, $s.refreshMillis);
|
||||
}
|
||||
},
|
||||
update: function(timestamp) {
|
||||
var date = (timestamp instanceof Date) ? timestamp : $t.parse(timestamp);
|
||||
$(this).data('timeago', { datetime: date });
|
||||
if ($t.settings.localeTitle) {
|
||||
$(this).attr("title", date.toLocaleString());
|
||||
}
|
||||
refresh.apply(this);
|
||||
},
|
||||
updateFromDOM: function() {
|
||||
$(this).data('timeago', { datetime: $t.parse( $t.isTime(this) ? $(this).attr("datetime") : $(this).attr("title") ) });
|
||||
refresh.apply(this);
|
||||
},
|
||||
dispose: function () {
|
||||
if (this._timeagoInterval) {
|
||||
window.clearInterval(this._timeagoInterval);
|
||||
this._timeagoInterval = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$.fn.timeago = function(action, options) {
|
||||
var fn = action ? functions[action] : functions.init;
|
||||
if (!fn) {
|
||||
throw new Error("Unknown function name '"+ action +"' for timeago");
|
||||
}
|
||||
// each over objects here and call the requested function
|
||||
this.each(function() {
|
||||
fn.call(this, options);
|
||||
});
|
||||
return this;
|
||||
};
|
||||
|
||||
function refresh() {
|
||||
var $s = $t.settings;
|
||||
|
||||
//check if it's still visible
|
||||
if ($s.autoDispose && !$.contains(document.documentElement,this)) {
|
||||
//stop if it has been removed
|
||||
$(this).timeago("dispose");
|
||||
return this;
|
||||
}
|
||||
|
||||
var data = prepareData(this);
|
||||
|
||||
if (!isNaN(data.datetime)) {
|
||||
if ( $s.cutoff === 0 || Math.abs(distance(data.datetime)) < $s.cutoff) {
|
||||
$(this).text(inWords(data.datetime));
|
||||
} else {
|
||||
if ($(this).attr('title').length > 0) {
|
||||
$(this).text($(this).attr('title'));
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
function prepareData(element) {
|
||||
element = $(element);
|
||||
if (!element.data("timeago")) {
|
||||
element.data("timeago", { datetime: $t.datetime(element) });
|
||||
var text = $.trim(element.text());
|
||||
if ($t.settings.localeTitle) {
|
||||
element.attr("title", element.data('timeago').datetime.toLocaleString());
|
||||
} else if (text.length > 0 && !($t.isTime(element) && element.attr("title"))) {
|
||||
element.attr("title", text);
|
||||
}
|
||||
}
|
||||
return element.data("timeago");
|
||||
}
|
||||
|
||||
function inWords(date) {
|
||||
return $t.inWords(distance(date));
|
||||
}
|
||||
|
||||
function distance(date) {
|
||||
return (new Date().getTime() - date.getTime());
|
||||
}
|
||||
|
||||
// fix for IE6 suckage
|
||||
document.createElement("abbr");
|
||||
document.createElement("time");
|
||||
}));
|
Загрузка…
Ссылка в новой задаче