Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

2012 Rewrite: v1.1.0pre

New:
* New parser, made as public API ($.prettyDate.parse).
* Timezones fully supported as supported by ES5 Date.parse and
  ISO 8601.
* Recognition of (+ unit tests)
 - 1 week
 - 1 month
 - # months
 - 1 year
 - # years
   I've taken months and years with a low-end margin (since days
   in a month/year varies). Also use a 2-week buffer between
   the date and the 1+ next year. So if something is 1 year and 2
   weeks ago, it shows 1 year not 2 years already.
* Documentation blocks.
* /demo: Add all variations (same as /test).
* /demo: Add dynamic language switcher menu

Changes:
* "isUTC" option no longer needed. ISO 8601 timestamps can
  contain timestamps themselves (and should!). Previously this
  was relevant because the lazy parsing implementation removed
  [TZ] from the string. But now that this is taken into
  consideration, it will be more accurate.
  I considered keeping it, but couldn't make it work reliably.
  It has to be in the timestamp itself for it to be relevant.
* Removed .fromUTC().
* Converted line endings to Unix (git-diff ^M warnings).
* Rename /localization and files to match jquery-ui convention.
  New directory: /i18n
  The filenames were mostly already there, renamed:
 - 'jquery-prettydate-fr.js'
 - 'jquery-prettydate-lv.js'
* Added new lines at EOFs.
* Update upstream libs.
* Update demo markup.
* Update unit tests.
* Update Dutch translation (i18n.nl).
* Bump version number to next +'pre'.

Issues:
* Fix indentation and missing semicolons in various places
* Fix "same has been deprecated since 2009 (e88049a0), use
   assert.deepEqual instead".
* Passed JSHint.
* Closes #2: Bad results when server and client timezones differ.
* Closes #6: "1 weeks" -> "1 week".
* Closes #8: Adding support for months and years.

Libs:
* curl 'http://code.jquery.com/jquery.js'; > libs/jquery.js
* git submodule add git://github.com/jquery/qunit.git libs/jquery.qunit
  • Loading branch information...
commit f4d3d0d5333181bba580a2c2f72d9666174d1398 1 parent 2fb5a28
@Krinkle Krinkle authored
Showing with 9,965 additions and 6,596 deletions.
  1. +3 −0  .gitmodules
  2. +1 −0  .jshintignore
  3. +28 −0 .jshintrc
  4. +157 −74 demo/index.html
  5. +11 −0 i18n/jquery.prettydate-cn.js
  6. +11 −0 i18n/jquery.prettydate-da.js
  7. +11 −0 i18n/jquery.prettydate-de.js
  8. +11 −0 i18n/jquery.prettydate-es.js
  9. +11 −0 i18n/jquery.prettydate-fr.js
  10. +11 −0 i18n/jquery.prettydate-id.js
  11. +11 −0 i18n/jquery.prettydate-lv.js
  12. +16 −0 i18n/jquery.prettydate-nl.js
  13. +11 −0 i18n/jquery.prettydate-pl.js
  14. +11 −0 i18n/jquery.prettydate-pt-BR.js
  15. +11 −0 i18n/jquery.prettydate-sv.js
  16. +11 −0 i18n/jquery.prettydate-th.js
  17. +11 −0 i18n/jquery.prettydate-tr.js
  18. +215 −118 jquery.prettydate.js
  19. +0 −4,377 lib/jquery.js
  20. +9,301 −0 libs/jquery.js
  21. +1 −0  libs/jquery.qunit
  22. +0 −11 localization/jquery-prettydate-fr.js
  23. +0 −11 localization/jquery-prettydate-lv.js
  24. +0 −11 localization/jquery.prettydate-cn.js
  25. +0 −11 localization/jquery.prettydate-da.js
  26. +0 −11 localization/jquery.prettydate-de.js
  27. +0 −11 localization/jquery.prettydate-es.js
  28. +0 −11 localization/jquery.prettydate-id.js
  29. +0 −11 localization/jquery.prettydate-nl.js
  30. +0 −11 localization/jquery.prettydate-pl.js
  31. +0 −11 localization/jquery.prettydate-pt-BR.js
  32. +0 −11 localization/jquery.prettydate-sv.js
  33. +0 −11 localization/jquery.prettydate-th.js
  34. +0 −11 localization/jquery.prettydate-tr.js
  35. +22 −61 test/index.html
  36. +89 −0 test/jquery.prettydate.test.js
  37. +0 −226 test/qunit/qunit.css
  38. +0 −1,597 test/qunit/qunit.js
View
3  .gitmodules
@@ -0,0 +1,3 @@
+[submodule "libs/jquery.qunit"]
+ path = libs/jquery.qunit
+ url = git://github.com/jquery/qunit.git
View
1  .jshintignore
@@ -0,0 +1 @@
+libs/
View
28 .jshintrc
@@ -0,0 +1,28 @@
+{
+ "predef": [
+ "QUnit"
+ ],
+
+ "camelcase": true,
+ "curly": true,
+ "eqeqeq": true,
+ "immed": true,
+ "latedef": true,
+ "newcap": true,
+ "noarg": true,
+ "noempty": true,
+ "nonew": true,
+ "plusplus": true,
+ "quotmark": "single",
+ "undef": true,
+ "unused": true,
+ "strict": false,
+ "trailing": true,
+
+ "browser": true,
+ "jquery": true,
+
+ "nomen": true,
+ "onevar": true,
+ "white": true
+}
View
231 demo/index.html
@@ -1,87 +1,170 @@
<!DOCTYPE html>
-<html>
+<html lang="en">
<head>
- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
- <title>jQuery pretty date plugin demo</title>
- <script src="../lib/jquery.js"></script>
+ <meta charset="utf-8">
+ <title>jQuery prettyDate Demo</title>
+ <script src="../libs/jquery.js"></script>
<script src="../jquery.prettydate.js"></script>
+ <style>
+ * {
+ margin: 0;
+ padding: 0;
+ }
+ body {
+ background: #eee;
+ font: 14px/21px sans-serif;
+ color: #333;
+ position: relative;
+ }
+ h1 {
+ text-align: center;
+ padding: 1em 0;
+ }
+ a {
+ text-decoration: none;
+ color: #0645ad;
+ }
+ a:hover {
+ text-decoration: underline;
+ }
+ fieldset, p {
+ margin: 0.5em 0;
+ }
+ .fork {
+ position: fixed;
+ top: 0; right: 0;
+ background: url(https://a248.e.akamai.net/assets.github.com/img/7afbc8b248c68eb468279e8c17986ad46549fb71/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67) no-repeat 100% 0;
+ width: 150px;
+ height: 150px;
+ float: right;
+ }
+ .entries {
+ margin: 0 auto 3em;
+ padding: 0.5em 0.5em 0;
+ background: #fff;
+ width: 500px;
+ overflow: hidden;
+ }
+ fieldset, .entry {
+ background: #f2f2f2;
+ border: 1px solid #ddd;
+ padding: 0.25em 0.5em;
+ margin-bottom: 0.5em;
+ list-style: none;
+ overflow: hidden;
+ }
+ .entry .extra {
+ float: right;
+ }
+ </style>
<script>
- $(function() {
- // set a fixed date for the demo to be independent of the current date
- $.prettyDate.now = function() {
- return new Date("2008/01/28 22:25:00");
+ jQuery(function ($) {
+ // Generate demo's with javascript to keep HTML less repetative
+ var zulus, $langs,
+ msgsEn = $.extend({}, $.prettyDate.messages),
+ $langMenu = $('<select>'),
+ $entries = $('.entries ul').empty();
+
+
+ function doPretty() {
+ $('.time').prettyDate({
+ // No need to update as the time is fixed
+ interval: false
+ });
}
- $("a").prettyDate();
- });
- </script>
-</head>
-<body>
-
-</body>
-</html>
-<ul>
-<li class="entry" id="post57">
- <p>blah blah blah...</p>
- <small class="extra">
- Posted <span class="time"><a href="/2008/01/blah/57/" title="2008-01-28T20:24:17Z"><span>January 28th, 2008</span></a></span>
- by <span class="author"><a href="/john/">John Resig</a></span>
- </small>
-</li>
-<li class="entry" id="post57">
- <p>blah blah blah...</p>
- <small class="extra">
- Posted <span class="time"><a href="/2008/01/blah/57/" title="2008-01-27T22:24:17Z"><span>January 27th, 2008</span></a></span>
- by <span class="author"><a href="/john/">John Resig</a></span>
+ zulus = [
+ '2012-01-01T00:00:00Z',
+ '2008-01-28T22:24:30Z',
+ '2008-01-28T22:23:05Z',
+ '2008-01-28T22:20:05Z',
+ '2008-01-28T20:24:17Z',
+ '2008-01-27T08:00:00Z',
+ '2008-01-26T08:00:00Z',
+ '2008-01-21T08:00:00Z',
+ '2008-01-14T08:00:00Z',
+ '2007-12-28T08:00:00Z',
+ '2007-12-15T08:00:00Z',
+ '2007-01-14T08:00:00Z',
+ '2006-03-07T08:00:00Z'
+ ];
+ $.each(zulus, function (i, zulu) {
+ $entries.append(
+ $('<li>', {
+ addClass: 'entry',
+ html: '<a href="#' + zulu + '">Blah blah blah</a>' +
+ ' <small class="extra"><span class="time" title="' +
+ zulu + '">' + new Date($.prettyDate.parse(zulu)).toDateString() + '</span>' +
+ ' &nbsp;&bull;&nbsp; ' + '<a class="author" href="#/author/john/">John Resig</a></small>'
+ })
+ );
- </small>
-</li>
-<li class="entry" id="post57">
- <p>blah blah blah...</p>
- <small class="extra">
- Posted <span class="time"><a href="/2008/01/blah/57/" title="2008-01-26T22:24:17Z"><span>January 26th, 2008</span></a></span>
- by <span class="author"><a href="/john/">John Resig</a></span>
+ });
- </small>
-</li>
-<li class="entry" id="post57">
- <p>blah blah blah...</p>
- <small class="extra">
- Posted <span class="time"><a href="/2008/01/blah/57/" title="2008-01-25T22:24:17Z"><span>January 25th, 2008</span></a></span>
- by <span class="author"><a href="/john/">John Resig</a></span>
- </small>
-</li>
-<li class="entry" id="post57">
- <p>blah blah blah...</p>
- <small class="extra">
- Posted <span class="time"><a href="/2008/01/blah/57/" title="2008-01-24T22:24:17Z"><span>January 24th, 2008</span></a></span>
- by <span class="author"><a href="/john/">John Resig</a></span>
+ $langs = $.map([
+ 'cn',
+ 'da',
+ 'de',
+ 'es',
+ 'fr',
+ 'id',
+ 'lv',
+ 'nl',
+ 'pl',
+ 'pt-BR',
+ 'sv',
+ 'th',
+ 'tr'
+ ], function (lang) {
+ return $('<option>').text(lang).prop('value', lang);
+ });
+ $langs.unshift(
+ $('<option>').text('en').prop({
+ value: '',
+ selected: true
+ })
+ );
- </small>
-</li>
-<li class="entry" id="post57">
- <p>blah blah blah...</p>
- <small class="extra">
- Posted <span class="time"><a href="/2008/01/blah/57/" title="2008-01-14T22:24:17Z"><span>January 14th, 2008</span></a></span>
- by <span class="author"><a href="/john/">John Resig</a></span>
+ $langMenu
+ .prop('id', 'lang-menu')
+ .append($langs)
+ .on('change', function () {
+ if (this.value !== '') {
+ // $.getScript, but with cache
+ $.ajax({
+ url: '../i18n/jquery.prettydate-' + this.value + '.js',
+ dateType: 'script',
+ cache: true
+ }).done(doPretty);
+ } else {
+ $.prettyDate.messages = msgsEn;
+ doPretty();
+ }
+ })
+ .wrap('<fieldset>')
+ .parent()
+ .prependTo('.entries');
- </small>
-</li>
-<li class="entry" id="post57">
- <p>blah blah blah...</p>
- <small class="extra">
- Posted <span class="time"><a href="/2008/01/blah/57/" title="2008-01-04T22:24:17Z"><span>January 4th, 2008</span></a></span>
- by <span class="author"><a href="/john/">John Resig</a></span>
+ // Fixed date for the demo to be independent of the current date
+ // (prevents everything from becoming "5 years ago...")
+ $.prettyDate.now = function () {
+ return new Date(1201559100000);
+ }
- </small>
-</li>
-<li class="entry" id="post57">
- <p>blah blah blah...</p>
- <small class="extra">
- Posted <span class="time"><a href="/2008/01/blah/57/" title="2007-12-15T22:24:17Z"><span>December 15th, 2008</span></a></span>
- by <span class="author"><a href="/john/">John Resig</a></span>
+ $('<p>').text('Local time: ' + $.prettyDate.now()).prependTo('.entries');
- </small>
-</li>
-</ul>
+ doPretty();
+ });
+ </script>
+</head>
+<body>
+ <a class="fork" href="https://github.com/jzaefferer/jquery-prettydate" title="Fork jquery.prettydate on GitHub!"></a>
+ <h1><a href="./">jQuery prettyDate Demo</a></h1>
+ <div class="entries">
+ <ul><em>Loading...</em></ul>
+ <hr>
+ <p><a href="https://github.com/jzaefferer/jquery-prettydate">Source code: github.com/jzaefferer/jquery-prettydate</a></p>
+ </div>
+</body>
+</html>
View
11 i18n/jquery.prettydate-cn.js
@@ -0,0 +1,11 @@
+/* Chinse */
+$.extend($.prettyDate.messages, {
+ now: '刚刚',
+ minute: '1分钟前',
+ minutes: $.prettyDate.template('{0}分钟前'),
+ hour: '1小时前',
+ hours: $.prettyDate.template('{0}小时前'),
+ yesterday: '昨天',
+ days: $.prettyDate.template('{0}天前'),
+ weeks: $.prettyDate.template('{0}星期前')
+});
View
11 i18n/jquery.prettydate-da.js
@@ -0,0 +1,11 @@
+/* Danish */
+$.extend($.prettyDate.messages, {
+ now: 'lige nu',
+ minute: 'et minut siden',
+ minutes: $.prettyDate.template('{0} minutter siden'),
+ hour: 'en time siden',
+ hours: $.prettyDate.template('{0} timer siden'),
+ yesterday: 'i går',
+ days: $.prettyDate.template('{0} dage siden'),
+ weeks: $.prettyDate.template('{0} uger siden')
+});
View
11 i18n/jquery.prettydate-de.js
@@ -0,0 +1,11 @@
+/* German */
+$.extend($.prettyDate.messages, {
+ now: 'gerade eben',
+ minute: 'vor einer Minute',
+ minutes: $.prettyDate.template('vor {0} Minuten'),
+ hour: 'vor einer Stunde',
+ hours: $.prettyDate.template('vor {0} Stunden'),
+ yesterday: 'gestern',
+ days: $.prettyDate.template('vor {0} Tagen'),
+ weeks: $.prettyDate.template('vor {0} Wochen')
+});
View
11 i18n/jquery.prettydate-es.js
@@ -0,0 +1,11 @@
+/* Spanish */
+$.extend($.prettyDate.messages, {
+ now: 'recién',
+ minute: 'hace 1 minuto',
+ minutes: $.prettyDate.template('hace {0} minutos'),
+ hour: 'hace 1 hora',
+ hours: $.prettyDate.template('hace {0} horas'),
+ yesterday: 'ayer',
+ days: $.prettyDate.template('hace {0} días'),
+ weeks: $.prettyDate.template('hace {0} semanas')
+});
View
11 i18n/jquery.prettydate-fr.js
@@ -0,0 +1,11 @@
+/* French */
+$.extend($.prettyDate.messages, {
+ now: 'à l\'instant',
+ minute: 'il y a 1 minute',
+ minutes: $.prettyDate.template(' il y a {0} minutes'),
+ hour: ' il y a 1 heure',
+ hours: $.prettyDate.template('il y a {0} heures'),
+ yesterday: 'Hier',
+ days: $.prettyDate.template('il y a {0} jours'),
+ weeks: $.prettyDate.template('il y a {0} semaines')
+});
View
11 i18n/jquery.prettydate-id.js
@@ -0,0 +1,11 @@
+/* Indonesian */
+$.extend($.prettyDate.messages, {
+ now: 'sekarang',
+ minute: '1 menit lalu',
+ minutes: $.prettyDate.template('{0} Menit lalu'),
+ hour: '1 jam lalu',
+ hours: $.prettyDate.template('{0} Jam lalu'),
+ yesterday: 'Kemarin',
+ days: $.prettyDate.template('{0} Hari lalu'),
+ weeks: $.prettyDate.template('{0} Minggu lalu')
+});
View
11 i18n/jquery.prettydate-lv.js
@@ -0,0 +1,11 @@
+/* Latvian */
+$.extend($.prettyDate.messages, {
+ now: 'tikko',
+ minute: 'pirms minūtes',
+ minutes: $.prettyDate.template('pirms {0} minūtēm'),
+ hour: 'pirms stundas',
+ hours: $.prettyDate.template('pirms {0} stundām'),
+ yesterday: 'vakar',
+ days: $.prettyDate.template('pirms {0} dienām'),
+ weeks: $.prettyDate.template('pirms {0} nedēļām')
+});
View
16 i18n/jquery.prettydate-nl.js
@@ -0,0 +1,16 @@
+/* Dutch */
+$.extend($.prettyDate.messages, {
+ now: 'nu net',
+ minute: 'een minuut geleden',
+ minutes: $.prettyDate.template('{0} minuten geleden'),
+ hour: '1 uur geleden',
+ hours: $.prettyDate.template('{0} uur geleden'),
+ yesterday: 'gisteren',
+ days: $.prettyDate.template('{0} dagen geleden'),
+ week: '1 week geleden',
+ weeks: $.prettyDate.template('{0} weken geleden'),
+ month: '1 maand geleden',
+ months: $.prettyDate.template('{0} maanden geleden'),
+ year: '1 jaar geleden',
+ years: $.prettyDate.template('{0} jaren geleden')
+});
View
11 i18n/jquery.prettydate-pl.js
@@ -0,0 +1,11 @@
+/* Polish */
+$.extend($.prettyDate.messages, {
+ now: 'przed chwilą',
+ minute: 'minutę temu',
+ minutes: $.prettyDate.template('{0} minut temu'),
+ hour: 'godzinę temu',
+ hours: $.prettyDate.template('{0} godzin temu'),
+ yesterday: 'wczoraj',
+ days: $.prettyDate.template('{0} dni temu'),
+ weeks: $.prettyDate.template('{0} tygodni temu')
+});
View
11 i18n/jquery.prettydate-pt-BR.js
@@ -0,0 +1,11 @@
+/* Portugês Brasil */
+$.extend($.prettyDate.messages, {
+ now: 'agora',
+ minute: 'há 1 minuto',
+ minutes: $.prettyDate.template('há {0} minutos'),
+ hour: 'há 1 hora',
+ hours: $.prettyDate.template('há {0} horas'),
+ yesterday: 'ontem',
+ days: $.prettyDate.template('há {0} dias'),
+ weeks: $.prettyDate.template('há {0} semanas')
+});
View
11 i18n/jquery.prettydate-sv.js
@@ -0,0 +1,11 @@
+/* Swedish */
+$.extend($.prettyDate.messages, {
+ now: 'just nu',
+ minute: 'en minut sedan',
+ minutes: $.prettyDate.template('{0} minuter sedan'),
+ hour: 'en timme sedan',
+ hours: $.prettyDate.template('{0} timmar sedan'),
+ yesterday: 'igår',
+ days: $.prettyDate.template('{0} dagar sedan'),
+ weeks: $.prettyDate.template('{0} veckor sedan')
+});
View
11 i18n/jquery.prettydate-th.js
@@ -0,0 +1,11 @@
+/* Thai */
+$.extend($.prettyDate.messages, {
+ now: 'ปัจจุบัน',
+ minute: 'นาที',
+ minutes: $.prettyDate.template('{0} นาทีที่แล้ว'),
+ hour: 'ชั่วโมง',
+ hours: $.prettyDate.template('{0} ชั่วโมงที่แล้ว'),
+ yesterday: 'เมื่อวาน',
+ days: $.prettyDate.template('{0} วันที่แล้ว'),
+ weeks: $.prettyDate.template('{0} สัปดาห์ที่แล้ว')
+});
View
11 i18n/jquery.prettydate-tr.js
@@ -0,0 +1,11 @@
+/* Turkish */
+$.extend($.prettyDate.messages, {
+ now: 'Az önce',
+ minute: '1 dakika önce',
+ minutes: $.prettyDate.template('{0} dakika önce'),
+ hour: '1 saat önce',
+ hours: $.prettyDate.template('{0} saat önce'),
+ yesterday: 'Dün',
+ days: $.prettyDate.template('{0} gün önce'),
+ weeks: $.prettyDate.template('{0} hafta önce')
+});
View
333 jquery.prettydate.js
@@ -1,118 +1,215 @@
-/*
- * jQuery pretty date plug-in 1.0.0
- *
- * http://bassistance.de/jquery-plugins/jquery-plugin-prettydate/
- *
- * Based on John Resig's prettyDate http://ejohn.org/blog/javascript-pretty-date
- *
- * Copyright (c) 2009 Jörn Zaefferer
- *
- * $Id: jquery.validate.js 6096 2009-01-12 14:12:04Z joern.zaefferer $
- *
- * Dual licensed under the MIT and GPL licenses:
- * http://www.opensource.org/licenses/mit-license.php
- * http://www.gnu.org/licenses/gpl.html
- */
-
-(function($) {
-
-$.prettyDate = {
-
- template: function(source, params) {
- if ( arguments.length == 1 )
- return function() {
- var args = $.makeArray(arguments);
- args.unshift(source);
- return $.prettyDate.template.apply( this, args );
- };
- if ( arguments.length > 2 && params.constructor != Array ) {
- params = $.makeArray(arguments).slice(1);
- }
- if ( params.constructor != Array ) {
- params = [ params ];
- }
- $.each(params, function(i, n) {
- source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n);
- });
- return source;
- },
-
- now: function() {
- return new Date();
- },
-
- fromUTC: function (utcDate, isUTC) {
- if (!isUTC) {
- return utcDate;
- } else {
- var date = new Date();
- date.setUTCDate(utcDate.getDate());
- date.setUTCHours(utcDate.getHours());
- date.setUTCMonth(utcDate.getMonth());
- date.setUTCFullYear(utcDate.getFullYear());
- date.setUTCMinutes(utcDate.getMinutes());
- date.setUTCSeconds(utcDate.getSeconds());
- date.setUTCMilliseconds(utcDate.getMilliseconds());
- return date;
- }
- },
-
- // Takes an ISO time and returns a string representing how
- // long ago the date represents.
- format: function(time, isUTC) {
- var date = $.prettyDate.fromUTC(new Date((time || "").replace(/-/g,"/").replace(/[TZ]/g," ")), isUTC),
- diff = ($.prettyDate.now().getTime() - date.getTime()) / 1000,
- day_diff = Math.floor(diff / 86400);
-
- if ( isNaN(day_diff) || day_diff < 0 || day_diff >= 31 )
- return;
-
- var messages = $.prettyDate.messages;
- return day_diff == 0 && (
- diff < 60 && messages.now ||
- diff < 120 && messages.minute ||
- diff < 3600 && messages.minutes(Math.floor( diff / 60 )) ||
- diff < 7200 && messages.hour ||
- diff < 86400 && messages.hours(Math.floor( diff / 3600 ))) ||
- day_diff == 1 && messages.yesterday ||
- day_diff < 7 && messages.days(day_diff) ||
- day_diff < 31 && messages.weeks(Math.ceil( day_diff / 7 ));
- }
-
-};
-
-$.prettyDate.messages = {
- now: "just now",
- minute: "1 minute ago",
- minutes: $.prettyDate.template("{0} minutes ago"),
- hour: "1 hour ago",
- hours: $.prettyDate.template("{0} hours ago"),
- yesterday: "Yesterday",
- days: $.prettyDate.template("{0} days ago"),
- weeks: $.prettyDate.template("{0} weeks ago")
-};
-
-$.fn.prettyDate = function(options) {
- options = $.extend({
- value: function() {
- return $(this).attr(options.attribute);
- },
- interval: 10000,
- attribute: "title",
- isUTC: false
- }, options);
- var elements = this;
- function format() {
- elements.each(function() {
- var date = $.prettyDate.format(options.value.apply(this), options.isUTC);
- if ( date && $(this).text() != date )
- $(this).text( date );
- });
- }
- format();
- if (options.interval)
- setInterval(format, options.interval);
- return this;
-};
-
-})(jQuery);
+/*
+ * jQuery prettyDate v1.1.0pre
+ *
+ * @author John Resig (ejohn.org), 2008-2011
+ * @author Jörn Zaefferer, 2009
+ * @author Timo Tijhof, 2012
+ *
+ * Based on http://ejohn.org/blog/javascript-pretty-date
+ * Documentation: http://bassistance.de/jquery-plugins/jquery-plugin-prettydate/
+ *
+ * Dual licensed under the MIT and GPL licenses:
+ * http://www.opensource.org/licenses/mit-license.php
+ * http://www.gnu.org/licenses/gpl.html
+ */
+
+(function ($) {
+ 'use strict';
+
+ var slice = Array.prototype.slice,
+ rES5ts = /^(\d{4}|[+\-]\d{6})(?:-(\d{2})(?:-(\d{2}))?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?(?:(Z)|([+\-])(\d{2})(?::(\d{2}))?)?)?$/,
+ // Indexes in a rES5ts match list that are required for Date.UTC,
+ // Use in a loop to replace undefined with 0 (otherwise Date.UTC would give NaN)
+ dateUrcReqIndx = [1, 4, 5, 6, 7, 10, 11];
+
+ $.prettyDate = {
+
+ /**
+ * Replace numerial placeholders ({0}, {1}, ..) with the value
+ * at that index in the array or variadic list of arugments.
+ * When called with only a source, a function is returned that calls itself
+ * again, that time with the arguments passed to apply the template.
+ *
+ * @param {string} source Text containing {#} placeholders where
+ * '#' is a number referring to an index in `params`.
+ * @param {string|Array} [params...] List of replacement values or a
+ * varadic argument list starting where this argument is the first one.
+ */
+ template: function (source, params) {
+ if (arguments.length === 1) {
+ return function () {
+ var args = slice.call(arguments);
+ args.unshift(source);
+ return $.prettyDate.template.apply(this, args);
+ };
+ }
+ // Detect different call patterns:
+ // * template(source, [1, 2, 3])
+ // * template(source, 1, 2, 3)
+ if (!$.isArray(params)) {
+ params = slice.call(arguments, 1);
+ }
+ $.each(params, function (i, n) {
+ source = source.replace(new RegExp('\\{' + i + '\\}', 'g'), n);
+ });
+ return source;
+ },
+
+ /**
+ * Offset from which the relative date will be generated.
+ * @return {Date}
+ */
+ now: function () {
+ return new Date();
+ },
+
+ /**
+ * Implementation of the ES5 Date.parse specification (ES5 §15.9.4.2,
+ * which is a subset of ISO 8601), see http://es5.github.com/#x15.9.1.15.
+
+ * Since Date.parse already existed in old browsers and there would be
+ * many forms to be tested for, don't use feature-detection but just
+ * implement it straight up.
+ *
+ * Based on https://github.com/csnover/js-iso8601
+ *
+ * @example
+ * '2012'
+ * '2012-01-07'
+ * '2012-01-07T23:30:59Z'
+ * '2012-01-07T23:30:59+01:00'
+ * '2012-01-07T23:30:59.001+01:00'
+ * @param {string} timestamp
+ * @return {number} Unix epoch or NaN.
+ */
+ parse: function (timestamp) {
+ var i, k, minutesOffset,
+ m = rES5ts.exec(timestamp);
+ if (!m) {
+ return NaN;
+ }
+ for (i = 0; (k = dateUrcReqIndx[i]); i += 1) {
+ m[k] = +m[k] || 0;
+ }
+ // Undefined days and months are allowed
+ m[2] = +m[2] || 1;
+ m[3] = +m[3] || 1;
+
+ if (m[8] !== 'Z' && m[9] !== undefined) {
+ minutesOffset = m[10] * 60 + m[11];
+
+ if (m[9] === '+') {
+ minutesOffset = 0 - minutesOffset;
+ }
+ } else {
+ minutesOffset = 0;
+ }
+
+ return Date.UTC(
+ // Year
+ m[1],
+ // Month
+ m[2] - 1,
+ // Day
+ m[3],
+ // Hour
+ m[4],
+ // Minutes
+ // Date.UTC allows values higher than 59 here,
+ // it increments hours, days etc. if needed.
+ m[5] + minutesOffset,
+ // Seconds
+ m[6],
+ // Milliseconds
+ m[7]
+ );
+ },
+
+ /**
+ * Takes an ISO time and returns a string representing how
+ * long ago the date represents.
+ * @param {string} targetTs Timestamp in ISO 8601 format.
+ * @return {string}
+ */
+ format: function (target) {
+ var messages,
+ targetTime = $.prettyDate.parse(target),
+ nowTime = $.prettyDate.now().getTime(),
+ diff = (nowTime - targetTime) / 1000,
+ dayDiff = Math.floor(diff / 86400);
+
+ if (isNaN(dayDiff) || dayDiff < 0) {
+ return;
+ }
+
+ messages = $.prettyDate.messages;
+ return dayDiff === 0 && (
+ diff < 60 && messages.now ||
+ diff < 120 && messages.minute ||
+ diff < 3600 && messages.minutes(Math.floor(diff / 60)) ||
+ diff < 7200 && messages.hour ||
+ diff < 86400 && messages.hours(Math.floor(diff / 3600))) ||
+ dayDiff === 1 && messages.yesterday ||
+ dayDiff < 7 && messages.days(dayDiff) ||
+ dayDiff < 8 && messages.week ||
+ dayDiff < 14 && messages.days(dayDiff) ||
+ dayDiff < 30 && messages.weeks(Math.ceil(dayDiff / 7)) ||
+ dayDiff < 32 && messages.month ||
+ dayDiff < 363 && messages.months(Math.ceil(dayDiff / 31)) ||
+ dayDiff <= 380 && messages.year ||
+ dayDiff > 380 && messages.years(Math.ceil(dayDiff / 365));
+ }
+
+ };
+
+ $.prettyDate.messages = {
+ now: 'just now',
+ minute: '1 minute ago',
+ minutes: $.prettyDate.template('{0} minutes ago'),
+ hour: '1 hour ago',
+ hours: $.prettyDate.template('{0} hours ago'),
+ yesterday: 'Yesterday',
+ days: $.prettyDate.template('{0} days ago'),
+ week: '1 week ago',
+ weeks: $.prettyDate.template('{0} weeks ago'),
+ month: '1 month ago',
+ months: $.prettyDate.template('{0} months ago'),
+ year: '1 year ago',
+ years: $.prettyDate.template('{0} years ago')
+ };
+
+ /**
+ * @context {jQuery}
+ * @param {Object} options
+ * - {number|false} interval Time in milliseconds between updates,
+ * or set to false to disable auto updating interval.
+ * - {string} attribute Name of attribute where the timestamp should
+ * be accessed from.
+ * - {Function} value Overrides 'attribute', a custom function to get the
+ * timestamp. 'this' context is set to the HTMLElement.
+ */
+ $.fn.prettyDate = function (options) {
+ options = $.extend({
+ interval: 10000,
+ attribute: 'title',
+ value: function () {
+ return $(this).attr(options.attribute);
+ }
+ }, options);
+ var elements = this;
+ function format() {
+ elements.each(function () {
+ var date = $.prettyDate.format(options.value.apply(this));
+ if (date && $(this).text() !== date) {
+ $(this).text(date);
+ }
+ });
+ }
+ format();
+ if (options.interval) {
+ setInterval(format, options.interval);
+ }
+ return this;
+ };
+
+}(jQuery));
View
4,377 lib/jquery.js
0 additions, 4,377 deletions not shown
View
9,301 libs/jquery.js
9,301 additions, 0 deletions not shown
1  libs/jquery.qunit
@@ -0,0 +1 @@
+Subproject commit e34ffb61488459f6823ded82e19865ba4b46e2ed
View
11 localization/jquery-prettydate-fr.js
@@ -1,11 +0,0 @@
-/* French */
-$.prettyDate.messages = {
- now: "à l'instant",
- minute: "il y a 1 minute",
- minutes: $.prettyDate.template(" il y a {0} minutes"),
- hour: " il y a 1 heure",
- hours: $.prettyDate.template("il y a {0} heures"),
- yesterday: "Hier",
- days: $.prettyDate.template("il y a {0} jours"),
- weeks: $.prettyDate.template("il y a {0} semaines")
-};
View
11 localization/jquery-prettydate-lv.js
@@ -1,11 +0,0 @@
-/* Latvian */
-$.prettyDate.messages = {
- now: "tikko",
- minute: "pirms minūtes",
- minutes: $.prettyDate.template("pirms {0} minūtēm"),
- hour: "pirms stundas",
- hours: $.prettyDate.template("pirms {0} stundām"),
- yesterday: "vakar",
- days: $.prettyDate.template("pirms {0} dienām"),
- weeks: $.prettyDate.template("pirms {0} nedēļām")
-};
View
11 localization/jquery.prettydate-cn.js
@@ -1,11 +0,0 @@
-/* Chinse */
-$.prettyDate.messages = {
- now: "刚刚",
- minute: "1分钟前",
- minutes: $.prettyDate.template("{0}分钟前"),
- hour: "1小时前",
- hours: $.prettyDate.template("{0}小时前"),
- yesterday: "昨天",
- days: $.prettyDate.template("{0}天前"),
- weeks: $.prettyDate.template("{0}星期前")
-};
View
11 localization/jquery.prettydate-da.js
@@ -1,11 +0,0 @@
-/* Danish */
-$.prettyDate.messages = {
- now: "lige nu",
- minute: "et minut siden",
- minutes: $.prettyDate.template("{0} minutter siden"),
- hour: "en time siden",
- hours: $.prettyDate.template("{0} timer siden"),
- yesterday: "i går",
- days: $.prettyDate.template("{0} dage siden"),
- weeks: $.prettyDate.template("{0} uger siden")
-};
View
11 localization/jquery.prettydate-de.js
@@ -1,11 +0,0 @@
-/* German */
-$.prettyDate.messages = {
- now: "gerade eben",
- minute: "vor einer Minute",
- minutes: $.prettyDate.template("vor {0} Minuten"),
- hour: "vor einer Stunde",
- hours: $.prettyDate.template("vor {0} Stunden"),
- yesterday: "gestern",
- days: $.prettyDate.template("vor {0} Tagen"),
- weeks: $.prettyDate.template("vor {0} Wochen")
-};
View
11 localization/jquery.prettydate-es.js
@@ -1,11 +0,0 @@
-/* Spanish */
-$.prettyDate.messages = {
- now: "recién",
- minute: "hace 1 minuto",
- minutes: $.prettyDate.template("hace {0} minutos"),
- hour: "hace 1 hora",
- hours: $.prettyDate.template("hace {0} horas"),
- yesterday: "ayer",
- days: $.prettyDate.template("hace {0} días"),
- weeks: $.prettyDate.template("hace {0} semanas")
-};
View
11 localization/jquery.prettydate-id.js
@@ -1,11 +0,0 @@
-/* Indonesian */
-$.prettyDate.messages = {
- now: "sekarang",
- minute: "1 menit lalu",
- minutes: $.prettyDate.template("{0} Menit lalu"),
- hour: "1 jam lalu",
- hours: $.prettyDate.template("{0} Jam lalu"),
- yesterday: "Kemarin",
- days: $.prettyDate.template("{0} Hari lalu"),
- weeks: $.prettyDate.template("{0} Minggu lalu")
-};
View
11 localization/jquery.prettydate-nl.js
@@ -1,11 +0,0 @@
-/* Dutch */
-$.prettyDate.messages = {
- now: "nu net",
- minute: "een minuut geleden",
- minutes: $.prettyDate.template("{0} minuten geleden"),
- hour: "1 uur geleden",
- hours: $.prettyDate.template("{0} uur geleden"),
- yesterday: "gisteren",
- days: $.prettyDate.template("{0} dagen geleden"),
- weeks: $.prettyDate.template("{0} weken geleden")
-}
View
11 localization/jquery.prettydate-pl.js
@@ -1,11 +0,0 @@
-/* Polish */
-$.prettyDate.messages = {
- now: "przed chwilą",
- minute: "minutę temu",
- minutes: $.prettyDate.template("{0} minut temu"),
- hour: "godzinę temu",
- hours: $.prettyDate.template("{0} godzin temu"),
- yesterday: "wczoraj",
- days: $.prettyDate.template("{0} dni temu"),
- weeks: $.prettyDate.template("{0} tygodni temu")
-};
View
11 localization/jquery.prettydate-pt-BR.js
@@ -1,11 +0,0 @@
-/* Portugês Brasil */
-$.prettyDate.messages = {
-now: "agora",
-minute: "há 1 minuto",
-minutes: $.prettyDate.template("há {0} minutos"),
-hour: "há 1 hora",
-hours: $.prettyDate.template("há {0} horas"),
-yesterday: "ontem",
-days: $.prettyDate.template("há {0} dias"),
-weeks: $.prettyDate.template("há {0} semanas")
-};
View
11 localization/jquery.prettydate-sv.js
@@ -1,11 +0,0 @@
-/* Swedish */
-$.prettyDate.messages = {
- now: "just nu",
- minute: "en minut sedan",
- minutes: $.prettyDate.template("{0} minuter sedan"),
- hour: "en timme sedan",
- hours: $.prettyDate.template("{0} timmar sedan"),
- yesterday: "igår",
- days: $.prettyDate.template("{0} dagar sedan"),
- weeks: $.prettyDate.template("{0} veckor sedan")
-};
View
11 localization/jquery.prettydate-th.js
@@ -1,11 +0,0 @@
-/* Thai */
-$.prettyDate.messages = {
- now: "ปัจจุบัน",
- minute: "นาที",
- minutes: $.prettyDate.template("{0} นาทีที่แล้ว"),
- hour: "ชั่วโมง",
- hours: $.prettyDate.template("{0} ชั่วโมงที่แล้ว"),
- yesterday: "เมื่อวาน",
- days: $.prettyDate.template("{0} วันที่แล้ว"),
- weeks: $.prettyDate.template("{0} สัปดาห์ที่แล้ว")
-};
View
11 localization/jquery.prettydate-tr.js
@@ -1,11 +0,0 @@
-/* Turkish */
-$.prettyDate.messages = {
- now: "Az önce",
- minute: "1 dakika önce",
- minutes: $.prettyDate.template("{0} dakika önce"),
- hour: "1 saat önce",
- hours: $.prettyDate.template("{0} saat önce"),
- yesterday: "Dün",
- days: $.prettyDate.template("{0} gün önce"),
- weeks: $.prettyDate.template("{0} hafta önce")
-};
View
83 test/index.html
@@ -1,74 +1,35 @@
<!DOCTYPE html>
-<html id="html">
+<html lang="en">
<head>
- <title>jQuery - Pretty date plugin testsuite</title>
- <link rel="Stylesheet" media="screen" href="qunit/qunit.css" />
- <script src="qunit/qunit.js"></script>
- <script src="../lib/jquery.js"></script>
+ <title>jQuery prettyDate Test</title>
+ <link rel="stylesheet" href="../libs/jquery.qunit/qunit/qunit.css">
+ <script src="../libs/jquery.qunit/qunit/qunit.js"></script>
+ <script src="../libs/jquery.js"></script>
<script src="../jquery.prettydate.js"></script>
-
- <script>
- $.prettyDate.now = function() {
- return new Date("2008/01/28 22:25:00");
- };
- test("standalone format", function() {
- same($("#main a").map(function() {
- return $.prettyDate.format(this.title) || "can't format";
- }).get(), ["2 hours ago", "Yesterday", "2 days ago", "2 weeks ago", "can't format"])
- });
- test("plugin", function() {
- same($("#main a").prettyDate().map(function() {
- return $(this).text();
- }).get(), ["2 hours ago", "Yesterday", "2 days ago", "2 weeks ago", "x"])
- })
- test("localized", function() {
- var org = $.extend({}, $.prettyDate.messages);
- $.prettyDate.messages.hours = $.prettyDate.template("text {0} text");
- $("#main a:first").prettyDate();
- same($("#main a:first").text(), "text 2 text");
- $.prettyDate.messages = org;
- })
- test("attribute", function() {
- same($("#alternate a").prettyDate({attribute: "date"}).map(function() {
- return $(this).text();
- }).get(), ["2 hours ago"])
- })
- test("UTC", function() {
- $.prettyDate.now = function() {
- var date = new Date("2008/01/28 22:25:00");
- date = new Date(date.getTime() - date.getTimezoneOffset() * 60 * 1000);
- return date;
- };
- same($("#utc a").prettyDate({isUTC: true}).map(function() {
- return $(this).text();
- }).get(), ["2 hours ago", "Yesterday", "2 days ago", "2 weeks ago", "x"])
- })
- </script>
</head>
<body>
- <h1 id="qunit-header">jquery-prettydate Test Suite</h1>
- <h2 id="qunit-banner"></h2>
- <div id="qunit-testrunner-toolbar"></div>
- <h2 id="qunit-userAgent"></h2>
- <ol id="qunit-tests"></ol>
+ <div id="qunit"></div>
<div id="qunit-fixture">
+ <!-- Now: 2008-01-28 22:25:00.000 UTC -->
<div id="main">
- <a title="2008-01-28T20:24:17Z">x</a>
- <a title="2008-01-27T22:24:17Z">x</a>
- <a title="2008-01-26T22:24:17Z">x</a>
- <a title="2008-01-14T22:24:17Z">x</a>
- <a title="2007-12-15T22:24:17Z">x</a>
+ <a title="2012-01-01T00:00:00Z">fallback</a>
+ <a title="2008-01-28T22:24:30Z">fallback</a>
+ <a title="2008-01-28T22:23:05Z">fallback</a>
+ <a title="2008-01-28T22:20:05Z">fallback</a>
+ <a title="2008-01-28T20:24:17Z">fallback</a>
+ <a title="2008-01-27T08:00:00Z">fallback</a>
+ <a title="2008-01-26T08:00:00Z">fallback</a>
+ <a title="2008-01-21T08:00:00Z">fallback</a>
+ <a title="2008-01-14T08:00:00Z">fallback</a>
+ <a title="2007-12-28T08:00:00Z">fallback</a>
+ <a title="2007-12-15T08:00:00Z">fallback</a>
+ <a title="2007-01-14T08:00:00Z">fallback</a>
+ <a title="2006-03-07T08:00:00Z">fallback</a>
</div>
<div id="alternate">
- <a date="2008-01-28T20:24:17Z">x</a>
- </div>
- <div id="utc">
- <a title="2008-01-28T20:24:17Z">x</a>
- <a title="2008-01-27T22:24:17Z">x</a>
- <a title="2008-01-26T22:24:17Z">x</a>
- <a title="2008-01-14T22:24:17Z">x</a>
- <a title="2007-12-15T22:24:17Z">x</a>
+ <a data-mytimestamp="2008-01-28T20:24:17Z">fallback</a>
</div>
</div>
+ <script src="jquery.prettydate.test.js"></script>
</body>
</html>
View
89 test/jquery.prettydate.test.js
@@ -0,0 +1,89 @@
+(function ($, QUnit) {
+
+ QUnit.module('prettyDate', {
+ setup: function () {
+ this.orgNow = $.prettyDate.now;
+ this.orgMessages = $.prettyDate.messages;
+ $.prettyDate.messages = $.extend(true, {}, this.orgMessages);
+ },
+ teardown: function () {
+ // Restore
+ $.prettyDate.now = this.orgNow;
+ $.prettyDate.messages = this.orgMessages;
+ }
+ });
+
+ // Fixed "now" to make unit testing easier
+ $.prettyDate.now = function () {
+ // 2008-01-28 22:25:00.000 UTC
+ return new Date(1201559100000);
+ };
+ var $main = $('#main a'),
+ $alt = $('#alternate a');
+
+
+ QUnit.test('Plain', 2, function (assert) {
+ var expected = [
+ 'fallback',
+ 'just now',
+ '1 minute ago',
+ '4 minutes ago',
+ '2 hours ago',
+ 'Yesterday',
+ '2 days ago',
+ '1 week ago',
+ '2 weeks ago',
+ '1 month ago',
+ '2 months ago',
+ '1 year ago',
+ '2 years ago'
+ ];
+ assert.deepEqual(
+ $.map($main.toArray(), function (el) {
+ return $.prettyDate.format(el.title) || 'fallback';
+ }),
+ expected,
+ 'jQuery.prettyDate'
+ );
+ assert.deepEqual(
+ $.map($main.prettyDate().toArray(), function (el) {
+ return $(el).text();
+ }),
+ expected,
+ '.prettyDate()'
+ );
+ });
+
+ QUnit.test('Local timezone has influence as expected', function (assert) {
+ $.prettyDate.now = function () {
+ var fixed = new Date(1201559100000),
+ local = new Date();
+ // Corrupt "now" with local computer timezone
+ fixed.setTime(fixed.getTime() - (local.getTimezoneOffset() * 60 * 1000));
+ return fixed;
+ };
+ var hourOffset = Math.floor(new Date().getTimezoneOffset() / 60);
+ assert.deepEqual(
+ $.map($main.eq(4).prettyDate().toArray(), function (el) {
+ return $(el).text();
+ }),
+ [(2 - hourOffset) + ' hours ago']
+ );
+ });
+
+ QUnit.test('messages', function (assert) {
+ $.prettyDate.messages.hours = $.prettyDate.template('text {0} text');
+ $main.eq(4).prettyDate();
+ assert.equal($main.eq(4).text(), 'text 2 text');
+ });
+
+ QUnit.test('option "attribute"', function (assert) {
+ assert.deepEqual(
+ $.map($alt.prettyDate({ attribute: 'data-mytimestamp' }).toArray(), function (el) {
+ return $(el).text();
+ }),
+ ['2 hours ago']
+ );
+ });
+
+}(jQuery, QUnit));
View
226 test/qunit/qunit.css
@@ -1,226 +0,0 @@
-/**
- * QUnit v1.2.0 - A JavaScript Unit Testing Framework
- *
- * http://docs.jquery.com/QUnit
- *
- * Copyright (c) 2011 John Resig, Jörn Zaefferer
- * Dual licensed under the MIT (MIT-LICENSE.txt)
- * or GPL (GPL-LICENSE.txt) licenses.
- */
-
-/** Font Family and Sizes */
-
-#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult {
- font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif;
-}
-
-#qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
-#qunit-tests { font-size: smaller; }
-
-
-/** Resets */
-
-#qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult {
- margin: 0;
- padding: 0;
-}
-
-
-/** Header */
-
-#qunit-header {
- padding: 0.5em 0 0.5em 1em;
-
- color: #8699a4;
- background-color: #0d3349;
-
- font-size: 1.5em;
- line-height: 1em;
- font-weight: normal;
-
- border-radius: 15px 15px 0 0;
- -moz-border-radius: 15px 15px 0 0;
- -webkit-border-top-right-radius: 15px;
- -webkit-border-top-left-radius: 15px;
-}
-
-#qunit-header a {
- text-decoration: none;
- color: #c2ccd1;
-}
-
-#qunit-header a:hover,
-#qunit-header a:focus {
- color: #fff;
-}
-
-#qunit-banner {
- height: 5px;
-}
-
-#qunit-testrunner-toolbar {
- padding: 0.5em 0 0.5em 2em;
- color: #5E740B;
- background-color: #eee;
-}
-
-#qunit-userAgent {
- padding: 0.5em 0 0.5em 2.5em;
- background-color: #2b81af;
- color: #fff;
- text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
-}
-
-
-/** Tests: Pass/Fail */
-
-#qunit-tests {
- list-style-position: inside;
-}
-
-#qunit-tests li {
- padding: 0.4em 0.5em 0.4em 2.5em;
- border-bottom: 1px solid #fff;
- list-style-position: inside;
-}
-
-#qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running {
- display: none;
-}
-
-#qunit-tests li strong {
- cursor: pointer;
-}
-
-#qunit-tests li a {
- padding: 0.5em;
- color: #c2ccd1;
- text-decoration: none;
-}
-#qunit-tests li a:hover,
-#qunit-tests li a:focus {
- color: #000;
-}
-
-#qunit-tests ol {
- margin-top: 0.5em;
- padding: 0.5em;
-
- background-color: #fff;
-
- border-radius: 15px;
- -moz-border-radius: 15px;
- -webkit-border-radius: 15px;
-
- box-shadow: inset 0px 2px 13px #999;
- -moz-box-shadow: inset 0px 2px 13px #999;
- -webkit-box-shadow: inset 0px 2px 13px #999;
-}
-
-#qunit-tests table {
- border-collapse: collapse;
- margin-top: .2em;
-}
-
-#qunit-tests th {
- text-align: right;
- vertical-align: top;
- padding: 0 .5em 0 0;
-}
-
-#qunit-tests td {
- vertical-align: top;
-}
-
-#qunit-tests pre {
- margin: 0;
- white-space: pre-wrap;
- word-wrap: break-word;
-}
-
-#qunit-tests del {
- background-color: #e0f2be;
- color: #374e0c;
- text-decoration: none;
-}
-
-#qunit-tests ins {
- background-color: #ffcaca;
- color: #500;
- text-decoration: none;
-}
-
-/*** Test Counts */
-
-#qunit-tests b.counts { color: black; }
-#qunit-tests b.passed { color: #5E740B; }
-#qunit-tests b.failed { color: #710909; }
-
-#qunit-tests li li {
- margin: 0.5em;
- padding: 0.4em 0.5em 0.4em 0.5em;
- background-color: #fff;
- border-bottom: none;
- list-style-position: inside;
-}
-
-/*** Passing Styles */
-
-#qunit-tests li li.pass {
- color: #5E740B;
- background-color: #fff;
- border-left: 26px solid #C6E746;
-}
-
-#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
-#qunit-tests .pass .test-name { color: #366097; }
-
-#qunit-tests .pass .test-actual,
-#qunit-tests .pass .test-expected { color: #999999; }
-
-#qunit-banner.qunit-pass { background-color: #C6E746; }
-
-/*** Failing Styles */
-
-#qunit-tests li li.fail {
- color: #710909;
- background-color: #fff;
- border-left: 26px solid #EE5757;
- white-space: pre;
-}
-
-#qunit-tests > li:last-child {
- border-radius: 0 0 15px 15px;
- -moz-border-radius: 0 0 15px 15px;
- -webkit-border-bottom-right-radius: 15px;
- -webkit-border-bottom-left-radius: 15px;
-}
-
-#qunit-tests .fail { color: #000000; background-color: #EE5757; }
-#qunit-tests .fail .test-name,
-#qunit-tests .fail .module-name { color: #000000; }
-
-#qunit-tests .fail .test-actual { color: #EE5757; }
-#qunit-tests .fail .test-expected { color: green; }
-
-#qunit-banner.qunit-fail { background-color: #EE5757; }
-
-
-/** Result */
-
-#qunit-testresult {
- padding: 0.5em 0.5em 0.5em 2.5em;
-
- color: #2b81af;
- background-color: #D2E0E6;
-
- border-bottom: 1px solid white;
-}
-
-/** Fixture */
-
-#qunit-fixture {
- position: absolute;
- top: -10000px;
- left: -10000px;
-}
View
1,597 test/qunit/qunit.js
@@ -1,1597 +0,0 @@
-/**
- * QUnit v1.2.0 - A JavaScript Unit Testing Framework
- *
- * http://docs.jquery.com/QUnit
- *
- * Copyright (c) 2011 John Resig, Jörn Zaefferer
- * Dual licensed under the MIT (MIT-LICENSE.txt)
- * or GPL (GPL-LICENSE.txt) licenses.
- */
-
-(function(window) {
-
-var defined = {
- setTimeout: typeof window.setTimeout !== "undefined",
- sessionStorage: (function() {
- try {
- return !!sessionStorage.getItem;
- } catch(e) {
- return false;
- }
- })()
-};
-
-var testId = 0,
- toString = Object.prototype.toString,
- hasOwn = Object.prototype.hasOwnProperty;
-
-var Test = function(name, testName, expected, testEnvironmentArg, async, callback) {
- this.name = name;
- this.testName = testName;
- this.expected = expected;
- this.testEnvironmentArg = testEnvironmentArg;
- this.async = async;
- this.callback = callback;
- this.assertions = [];
-};
-Test.prototype = {
- init: function() {
- var tests = id("qunit-tests");
- if (tests) {
- var b = document.createElement("strong");
- b.innerHTML = "Running " + this.name;
- var li = document.createElement("li");
- li.appendChild( b );
- li.className = "running";
- li.id = this.id = "test-output" + testId++;
- tests.appendChild( li );
- }
- },
- setup: function() {
- if (this.module != config.previousModule) {
- if ( config.previousModule ) {
- runLoggingCallbacks('moduleDone', QUnit, {
- name: config.previousModule,
- failed: config.moduleStats.bad,
- passed: config.moduleStats.all - config.moduleStats.bad,
- total: config.moduleStats.all
- } );
- }
- config.previousModule = this.module;
- config.moduleStats = { all: 0, bad: 0 };
- runLoggingCallbacks( 'moduleStart', QUnit, {
- name: this.module
- } );
- }
-
- config.current = this;
- this.testEnvironment = extend({
- setup: function() {},
- teardown: function() {}
- }, this.moduleTestEnvironment);
- if (this.testEnvironmentArg) {
- extend(this.testEnvironment, this.testEnvironmentArg);
- }
-
- runLoggingCallbacks( 'testStart', QUnit, {
- name: this.testName,
- module: this.module
- });
-
- // allow utility functions to access the current test environment
- // TODO why??
- QUnit.current_testEnvironment = this.testEnvironment;
-
- try {
- if ( !config.pollution ) {
- saveGlobal();
- }
-
- this.testEnvironment.setup.call(this.testEnvironment);
- } catch(e) {
- QUnit.ok( false, "Setup failed on " + this.testName + ": " + e.message );
- }
- },
- run: function() {
- config.current = this;
- if ( this.async ) {
- QUnit.stop();
- }
-
- if ( config.notrycatch ) {
- this.callback.call(this.testEnvironment);
- return;
- }
- try {
- this.callback.call(this.testEnvironment);
- } catch(e) {
- fail("Test " + this.testName + " died, exception and test follows", e, this.callback);
- QUnit.ok( false, "Died on test #" + (this.assertions.length + 1) + ": " + e.message + " - " + QUnit.jsDump.parse(e) );
- // else next test will carry the responsibility
- saveGlobal();
-
- // Restart the tests if they're blocking
- if ( config.blocking ) {
- QUnit.start();
- }
- }
- },
- teardown: function() {
- config.current = this;
- try {
- this.testEnvironment.teardown.call(this.testEnvironment);
- checkPollution();
- } catch(e) {
- QUnit.ok( false, "Teardown failed on " + this.testName + ": " + e.message );
- }
- },
- finish: function() {
- config.current = this;
- if ( this.expected != null && this.expected != this.assertions.length ) {
- QUnit.ok( false, "Expected " + this.expected + " assertions, but " + this.assertions.length + " were run" );
- }
-
- var good = 0, bad = 0,
- tests = id("qunit-tests");
-
- config.stats.all += this.assertions.length;
- config.moduleStats.all += this.assertions.length;
-
- if ( tests ) {
- var ol = document.createElement("ol");
-
- for ( var i = 0; i < this.assertions.length; i++ ) {
- var assertion = this.assertions[i];
-
- var li = document.createElement("li");
- li.className = assertion.result ? "pass" : "fail";
- li.innerHTML = assertion.message || (assertion.result ? "okay" : "failed");
- ol.appendChild( li );
-
- if ( assertion.result ) {
- good++;
- } else {
- bad++;
- config.stats.bad++;
- config.moduleStats.bad++;
- }
- }
-
- // store result when possible
- if ( QUnit.config.reorder && defined.sessionStorage ) {
- if (bad) {
- sessionStorage.setItem("qunit-" + this.module + "-" + this.testName, bad);
- } else {
- sessionStorage.removeItem("qunit-" + this.module + "-" + this.testName);
- }
- }
-
- if (bad == 0) {
- ol.style.display = "none";
- }
-
- var b = document.createElement("strong");
- b.innerHTML = this.name + " <b class='counts'>(<b class='failed'>" + bad + "</b>, <b class='passed'>" + good + "</b>, " + this.assertions.length + ")</b>";
-
- var a = document.createElement("a");
- a.innerHTML = "Rerun";
- a.href = QUnit.url({ filter: getText([b]).replace(/\([^)]+\)$/, "").replace(/(^\s*|\s*$)/g, "") });
-
- addEvent(b, "click", function() {
- var next = b.nextSibling.nextSibling,
- display = next.style.display;
- next.style.display = display === "none" ? "block" : "none";
- });
-
- addEvent(b, "dblclick", function(e) {
- var target = e && e.target ? e.target : window.event.srcElement;
- if ( target.nodeName.toLowerCase() == "span" || target.nodeName.toLowerCase() == "b" ) {
- target = target.parentNode;
- }
- if ( window.location && target.nodeName.toLowerCase() === "strong" ) {
- window.location = QUnit.url({ filter: getText([target]).replace(/\([^)]+\)$/, "").replace(/(^\s*|\s*$)/g, "") });
- }
- });
-
- var li = id(this.id);
- li.className = bad ? "fail" : "pass";
- li.removeChild( li.firstChild );
- li.appendChild( b );
- li.appendChild( a );
- li.appendChild( ol );
-
- } else {
- for ( var i = 0; i < this.assertions.length; i++ ) {
- if ( !this.assertions[i].result ) {
- bad++;
- config.stats.bad++;
- config.moduleStats.bad++;
- }
- }
- }
-
- try {
- QUnit.reset();
- } catch(e) {
- fail("reset() failed, following Test " + this.testName + ", exception and reset fn follows", e, QUnit.reset);
- }
-
- runLoggingCallbacks( 'testDone', QUnit, {
- name: this.testName,
- module: this.module,
- failed: bad,
- passed: this.assertions.length - bad,
- total: this.assertions.length
- } );
- },
-
- queue: function() {
- var test = this;
- synchronize(function() {
- test.init();
- });
- function run() {
- // each of these can by async
- synchronize(function() {
- test.setup();
- });
- synchronize(function() {
- test.run();
- });
- synchronize(function() {
- test.teardown();
- });
- synchronize(function() {
- test.finish();
- });
- }
- // defer when previous test run passed, if storage is available
- var bad = QUnit.config.reorder && defined.sessionStorage && +sessionStorage.getItem("qunit-" + this.module + "-" + this.testName);
- if (bad) {
- run();
- } else {
- synchronize(run, true);
- };
- }
-
-};
-
-var QUnit = {
-
- // call on start of module test to prepend name to all tests
- module: function(name, testEnvironment) {
- config.currentModule = name;
- config.currentModuleTestEnviroment = testEnvironment;
- },
-
- asyncTest: function(testName, expected, callback) {
- if ( arguments.length === 2 ) {
- callback = expected;
- expected = null;
- }
-
- QUnit.test(testName, expected, callback, true);
- },
-
- test: function(testName, expected, callback, async) {
- var name = '<span class="test-name">' + testName + '</span>', testEnvironmentArg;
-
- if ( arguments.length === 2 ) {
- callback = expected;
- expected = null;
- }
- // is 2nd argument a testEnvironment?
- if ( expected && typeof expected === 'object') {
- testEnvironmentArg = expected;
- expected = null;
- }
-
- if ( config.currentModule ) {
- name = '<span class="module-name">' + config.currentModule + "</span>: " + name;
- }
-
- if ( !validTest(config.currentModule + ": " + testName) ) {
- return;
- }
-
- var test = new Test(name, testName, expected, testEnvironmentArg, async, callback);
- test.module = config.currentModule;
- test.moduleTestEnvironment = config.currentModuleTestEnviroment;
- test.queue();
- },
-
- /**
- * Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through.
- */
- expect: function(asserts) {
- config.current.expected = asserts;
- },
-
- /**
- * Asserts true.
- * @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" );
- */
- ok: function(a, msg) {
- a = !!a;
- var details = {
- result: a,
- message: msg
- };
- msg = escapeInnerText(msg);
- runLoggingCallbacks( 'log', QUnit, details );
- config.current.assertions.push({
- result: a,
- message: msg
- });
- },
-
- /**
- * Checks that the first two arguments are equal, with an optional message.
- * Prints out both actual and expected values.
- *
- * Prefered to ok( actual == expected, message )
- *
- * @example equal( format("Received {0} bytes.", 2), "Received 2 bytes." );
- *
- * @param Object actual
- * @param Object expected
- * @param String message (optional)
- */
- equal: function(actual, expected, message) {
- QUnit.push(expected == actual, actual, expected, message);
- },
-
- notEqual: function(actual, expected, message) {
- QUnit.push(expected != actual, actual, expected, message);
- },
-
- deepEqual: function(actual, expected, message) {
- QUnit.push(QUnit.equiv(actual, expected), actual, expected, message);
- },
-
- notDeepEqual: function(actual, expected, message) {
- QUnit.push(!QUnit.equiv(actual, expected), actual, expected, message);
- },
-
- strictEqual: function(actual, expected, message) {
- QUnit.push(expected === actual, actual, expected, message);
- },
-
- notStrictEqual: function(actual, expected, message) {
- QUnit.push(expected !== actual, actual, expected, message);
- },
-
- raises: function(block, expected, message) {
- var actual, ok = false;
-
- if (typeof expected === 'string') {
- message = expected;
- expected = null;
- }
-
- try {
- block();
- } catch (e) {
- actual = e;
- }
-
- if (actual) {
- // we don't want to validate thrown error
- if (!expected) {
- ok = true;
- // expected is a regexp
- } else if (QUnit.objectType(expected) === "regexp") {
- ok = expected.test(actual);
- // expected is a constructor
- } else if (actual instanceof expected) {
- ok = true;
- // expected is a validation function which returns true is validation passed
- } else if (expected.call({}, actual) === true) {
- ok = true;
- }
- }
-
- QUnit.ok(ok, message);
- },
-
- start: function(count) {
- config.semaphore -= count || 1;
- if (config.semaphore > 0) {
- // don't start until equal number of stop-calls
- return;
- }
- if (config.semaphore < 0) {
- // ignore if start is called more often then stop
- config.semaphore = 0;
- }
- // A slight delay, to avoid any current callbacks
- if ( defined.setTimeout ) {
- window.setTimeout(function() {
- if (config.semaphore > 0) {
- return;
- }
- if ( config.timeout ) {
- clearTimeout(config.timeout);
- }
-
- config.blocking = false;
- process(true);
- }, 13);
- } else {
- config.blocking = false;
- process(true);
- }
- },
-
- stop: function(count) {
- config.semaphore += count || 1;
- config.blocking = true;
-
- if ( config.testTimeout && defined.setTimeout ) {
- clearTimeout(config.timeout);
- config.timeout = window.setTimeout(function() {
- QUnit.ok( false, "Test timed out" );
- config.semaphore = 1;
- QUnit.start();
- }, config.testTimeout);
- }
- }
-};
-
-//We want access to the constructor's prototype
-(function() {
- function F(){};
- F.prototype = QUnit;
- QUnit = new F();
- //Make F QUnit's constructor so that we can add to the prototype later
- QUnit.constructor = F;
-})();
-
-// Backwards compatibility, deprecated
-QUnit.equals = QUnit.equal;
-QUnit.same = QUnit.deepEqual;
-
-// Maintain internal state
-var config = {
- // The queue of tests to run
- queue: [],
-
- // block until document ready
- blocking: true,
-
- // when enabled, show only failing tests
- // gets persisted through sessionStorage and can be changed in UI via checkbox
- hidepassed: false,
-
- // by default, run previously failed tests first
- // very useful in combination with "Hide passed tests" checked
- reorder: true,
-
- // by default, modify document.title when suite is done
- altertitle: true,
-
- urlConfig: ['noglobals', 'notrycatch'],
-
- //logging callback queues
- begin: [],
- done: [],
- log: [],
- testStart: [],
- testDone: [],
- moduleStart: [],
- moduleDone: []
-};
-
-// Load paramaters
-(function() {
- var location = window.location || { search: "", protocol: "file:" },
- params = location.search.slice( 1 ).split( "&" ),
- length = params.length,
- urlParams = {},
- current;
-
- if ( params[ 0 ] ) {
- for ( var i = 0; i < length; i++ ) {
- current = params[ i ].split( "=" );
- current[ 0 ] = decodeURIComponent( current[ 0 ] );
- // allow just a key to turn on a flag, e.g., test.html?noglobals
- current[ 1 ] = current[ 1 ] ? decodeURIComponent( current[ 1 ] ) : true;
- urlParams[ current[ 0 ] ] = current[ 1 ];
- }
- }
-
- QUnit.urlParams = urlParams;
- config.filter = urlParams.filter;
-
- // Figure out if we're running the tests from a server or not
- QUnit.isLocal = !!(location.protocol === 'file:');
-})();
-
-// Expose the API as global variables, unless an 'exports'
-// object exists, in that case we assume we're in CommonJS
-if ( typeof exports === "undefined" || typeof require === "undefined" ) {
- extend(window, QUnit);
- window.QUnit = QUnit;
-} else {
- extend(exports, QUnit);
- exports.QUnit = QUnit;
-}
-
-// define these after exposing globals to keep them in these QUnit namespace only
-extend(QUnit, {
- config: config,
-
- // Initialize the configuration options
- init: function() {
- extend(config, {
- stats: { all: 0, bad: 0 },
- moduleStats: { all: 0, bad: 0 },
- started: +new Date,
- updateRate: 1000,
- blocking: false,
- autostart: true,
- autorun: false,
- filter: "",
- queue: [],
- semaphore: 0
- });
-
- var tests = id( "qunit-tests" ),
- banner = id( "qunit-banner" ),
- result = id( "qunit-testresult" );
-
- if ( tests ) {
- tests.innerHTML = "";
- }
-
- if ( banner ) {
- banner.className = "";
- }
-
- if ( result ) {
- result.parentNode.removeChild( result );
- }
-
- if ( tests ) {
- result = document.createElement( "p" );
- result.id = "qunit-testresult";
- result.className = "result";
- tests.parentNode.insertBefore( result, tests );
- result.innerHTML = 'Running...<br/>&nbsp;';
- }
- },
-
- /**
- * Resets the test setup. Useful for tests that modify the DOM.
- *
- * If jQuery is available, uses jQuery's html(), otherwise just innerHTML.
- */
- reset: function() {
- if ( window.jQuery ) {
- jQuery( "#qunit-fixture" ).html( config.fixture );
- } else {
- var main = id( 'qunit-fixture' );
- if ( main ) {
- main.innerHTML = config.fixture;
- }
- }
- },
-
- /**
- * Trigger an event on an element.
- *
- * @example triggerEvent( document.body, "click" );
- *
- * @param DOMElement elem
- * @param String type
- */
- triggerEvent: function( elem, type, event ) {
- if ( document.createEvent ) {
- event = document.createEvent("MouseEvents");
- event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView,
- 0, 0, 0, 0, 0, false, false, false, false, 0, null);
- elem.dispatchEvent( event );
-
- } else if ( elem.fireEvent ) {
- elem.fireEvent("on"+type);
- }
- },
-
- // Safe object type checking
- is: function( type, obj ) {
- return QUnit.objectType( obj ) == type;
- },
-
- objectType: function( obj ) {
- if (typeof obj === "undefined") {
- return "undefined";
-
- // consider: typeof null === object
- }
- if (obj === null) {
- return "null";
- }
-
- var type = toString.call( obj ).match(/^\[object\s(.*)\]$/)[1] || '';
-
- switch (type) {
- case 'Number':
- if (isNaN(obj)) {
- return "nan";
- } else {
- return "number";
- }
- case 'String':
- case 'Boolean':
- case 'Array':
- case 'Date':
- case 'RegExp':
- case 'Function':
- return type.toLowerCase();
- }
- if (typeof obj === "object") {
- return "object";
- }
- return undefined;
- },
-
- push: function(result, actual, expected, message) {
- var details = {
- result: result,
- message: message,
- actual: actual,
- expected: expected
- };
-
- message = escapeInnerText(message) || (result ? "okay" : "failed");
- message = '<span class="test-message">' + message + "</span>";
- expected = escapeInnerText(QUnit.jsDump.parse(expected));
- actual = escapeInnerText(QUnit.jsDump.parse(actual));
- var output = message + '<table><tr class="test-expected"><th>Expected: </th><td><pre>' + expected + '</pre></td></tr>';
- if (actual != expected) {
- output += '<tr class="test-actual"><th>Result: </th><td><pre>' + actual + '</pre></td></tr>';
- output += '<tr class="test-diff"><th>Diff: </th><td><pre>' + QUnit.diff(expected, actual) +'</pre></td></tr>';
- }
- if (!result) {
- var source = sourceFromStacktrace();
- if (source) {
- details.source = source;
- output += '<tr class="test-source"><th>Source: </th><td><pre>' + escapeInnerText(source) + '</pre></td></tr>';
- }
- }
- output += "</table>";
-
- runLoggingCallbacks( 'log', QUnit, details );
-
- config.current.assertions.push({
- result: !!result,
- message: output
- });
- },
-
- url: function( params ) {
- params = extend( extend( {}, QUnit.urlParams ), params );
- var querystring = "?",
- key;
- for ( key in params ) {
- if ( !hasOwn.call( params, key ) ) {
- continue;
- }
- querystring += encodeURIComponent( key ) + "=" +
- encodeURIComponent( params[ key ] ) + "&";
- }
- return window.location.pathname + querystring.slice( 0, -1 );
- },
-
- extend: extend,
- id: id,
- addEvent: addEvent
-});
-
-//QUnit.constructor is set to the empty F() above so that we can add to it's prototype later
-//Doing this allows us to tell if the following methods have been overwritten on the actual
-//QUnit object, which is a deprecated way of using the callbacks.
-extend(QUnit.constructor.prototype, {
- // Logging callbacks; all receive a single argument with the listed properties
- // run test/logs.html for any related changes
- begin: registerLoggingCallback('begin'),
- // done: { failed, passed, total, runtime }
- done: registerLoggingCallback('done'),
- // log: { result, actual, expected, message }
- log: registerLoggingCallback('log'),
- // testStart: { name }
- testStart: registerLoggingCallback('testStart'),
- // testDone: { name, failed, passed, total }
- testDone: registerLoggingCallback('testDone'),
- // moduleStart: { name }
- moduleStart: registerLoggingCallback('moduleStart'),
- // moduleDone: { name, failed, passed, total }
- moduleDone: registerLoggingCallback('moduleDone')
-});
-
-if ( typeof document === "undefined" || document.readyState === "complete" ) {
- config.autorun = true;
-}
-
-QUnit.load = function() {
- runLoggingCallbacks( 'begin', QUnit, {} );
-
- // Initialize the config, saving the execution queue
- var oldconfig = extend({}, config);
- QUnit.init();
- extend(config, oldconfig);
-
- config.blocking = false;
-
- var urlConfigHtml = '', len = config.urlConfig.length;
- for ( var i = 0, val; i < len, val = config.urlConfig[i]; i++ ) {
- config[val] = QUnit.urlParams[val];
- urlConfigHtml += '<label><input name="' + val + '" type="checkbox"' + ( config[val] ? ' checked="checked"' : '' ) + '>' + val + '</label>';
- }
-
- var userAgent = id("qunit-userAgent");
- if ( userAgent ) {
- userAgent.innerHTML = navigator.userAgent;
- }
- var banner = id("qunit-header");
- if ( banner ) {
- banner.innerHTML = '<a href="' + QUnit.url({ filter: undefined }) + '"> ' + banner.innerHTML + '</a> ' + urlConfigHtml;
- addEvent( banner, "change", function( event ) {
- var params = {};
- params[ event.target.name ] = event.target.checked ? true : undefined;
- window.location = QUnit.url( params );
- });
- }
-
- var toolbar = id("qunit-testrunner-toolbar");
- if ( toolbar ) {
- var filter = document.createElement("input");
- filter.type = "checkbox";
- filter.id = "qunit-filter-pass";
- addEvent( filter, "click", function() {
- var ol = document.getElementById("qunit-tests");
- if ( filter.checked ) {
- ol.className = ol.className + " hidepass";
- } else {
- var tmp = " " + ol.className.replace( /[\n\t\r]/g, " " ) + " ";
- ol.className = tmp.replace(/ hidepass /, " ");
- }
- if ( defined.sessionStorage ) {
- if (filter.checked) {
- sessionStorage.setItem("qunit-filter-passed-tests", "true");
- } else {
- sessionStorage.removeItem("qunit-filter-passed-tests");
- }
- }
- });
- if ( config.hidepassed || defined.sessionStorage && sessionStorage.getItem("qunit-filter-passed-tests") ) {
- filter.checked = true;
- var ol = document.getElementById("qunit-tests");
- ol.className = ol.className + " hidepass";
- }
- toolbar.appendChild( filter );
-
- var label = document.createElement("label");
- label.setAttribute("for", "qunit-filter-pass");
- label.innerHTML = "Hide passed tests";
- toolbar.appendChild( label );
- }
-
- var main = id('qunit-fixture');
- if ( main ) {
- config.fixture = main.innerHTML;
- }
-
- if (config.autostart) {
- QUnit.start();
- }
-};
-
-addEvent(window, "load", QUnit.load);
-
-// addEvent(window, "error") gives us a useless event object
-window.onerror = function( message, file, line ) {
- if ( QUnit.config.current ) {
- ok( false, message + ", " + file + ":" + line );
- } else {
- test( "global failure", function() {
- ok( false, message + ", " + file + ":" + line );
- });
- }
-};
-
-function done() {
- config.autorun = true;
-