Home page Forum Wiki Mail Jabber Devel NIX-FILES

AltLUG Git

Git-repositories of Altai Linux User Group

Merge remote branch 'wwalser/recursionBug'
[qunit.git] / qunit / qunit.js
1 /**
2  * QUnit 1.1.0pre - A JavaScript Unit Testing Framework
3  *
4  * http://docs.jquery.com/QUnit
5  *
6  * Copyright (c) 2011 John Resig, Jörn Zaefferer
7  * Dual licensed under the MIT (MIT-LICENSE.txt)
8  * or GPL (GPL-LICENSE.txt) licenses.
9  */
10
11 (function(window) {
12
13 var defined = {
14         setTimeout: typeof window.setTimeout !== "undefined",
15         sessionStorage: (function() {
16                 try {
17                         return !!sessionStorage.getItem;
18                 } catch(e) {
19                         return false;
20                 }
21         })()
22 };
23
24 var     testId = 0,
25         toString = Object.prototype.toString,
26         hasOwn = Object.prototype.hasOwnProperty;
27
28 var Test = function(name, testName, expected, testEnvironmentArg, async, callback) {
29         this.name = name;
30         this.testName = testName;
31         this.expected = expected;
32         this.testEnvironmentArg = testEnvironmentArg;
33         this.async = async;
34         this.callback = callback;
35         this.assertions = [];
36 };
37 Test.prototype = {
38         init: function() {
39                 var tests = id("qunit-tests");
40                 if (tests) {
41                         var b = document.createElement("strong");
42                                 b.innerHTML = "Running " + this.name;
43                         var li = document.createElement("li");
44                                 li.appendChild( b );
45                                 li.className = "running";
46                                 li.id = this.id = "test-output" + testId++;
47                         tests.appendChild( li );
48                 }
49         },
50         setup: function() {
51                 if (this.module != config.previousModule) {
52                         if ( config.previousModule ) {
53                                 runLoggingCallbacks('moduleDone', QUnit, {
54                                         name: config.previousModule,
55                                         failed: config.moduleStats.bad,
56                                         passed: config.moduleStats.all - config.moduleStats.bad,
57                                         total: config.moduleStats.all
58                                 } );
59                         }
60                         config.previousModule = this.module;
61                         config.moduleStats = { all: 0, bad: 0 };
62                         runLoggingCallbacks( 'moduleStart', QUnit, {
63                                 name: this.module
64                         } );
65                 }
66
67                 config.current = this;
68                 this.testEnvironment = extend({
69                         setup: function() {},
70                         teardown: function() {}
71                 }, this.moduleTestEnvironment);
72                 if (this.testEnvironmentArg) {
73                         extend(this.testEnvironment, this.testEnvironmentArg);
74                 }
75
76                 runLoggingCallbacks( 'testStart', QUnit, {
77                         name: this.testName,
78                         module: this.module
79                 });
80
81                 // allow utility functions to access the current test environment
82                 // TODO why??
83                 QUnit.current_testEnvironment = this.testEnvironment;
84
85                 try {
86                         if ( !config.pollution ) {
87                                 saveGlobal();
88                         }
89
90                         this.testEnvironment.setup.call(this.testEnvironment);
91                 } catch(e) {
92                         QUnit.ok( false, "Setup failed on " + this.testName + ": " + e.message );
93                 }
94         },
95         run: function() {
96                 config.current = this;
97                 if ( this.async ) {
98                         QUnit.stop();
99                 }
100
101                 if ( config.notrycatch ) {
102                         this.callback.call(this.testEnvironment);
103                         return;
104                 }
105                 try {
106                         this.callback.call(this.testEnvironment);
107                 } catch(e) {
108                         fail("Test " + this.testName + " died, exception and test follows", e, this.callback);
109                         QUnit.ok( false, "Died on test #" + (this.assertions.length + 1) + ": " + e.message + " - " + QUnit.jsDump.parse(e) );
110                         // else next test will carry the responsibility
111                         saveGlobal();
112
113                         // Restart the tests if they're blocking
114                         if ( config.blocking ) {
115                                 start();
116                         }
117                 }
118         },
119         teardown: function() {
120                 config.current = this;
121                 try {
122                         this.testEnvironment.teardown.call(this.testEnvironment);
123                         checkPollution();
124                 } catch(e) {
125                         QUnit.ok( false, "Teardown failed on " + this.testName + ": " + e.message );
126                 }
127         },
128         finish: function() {
129                 config.current = this;
130                 if ( this.expected != null && this.expected != this.assertions.length ) {
131                         QUnit.ok( false, "Expected " + this.expected + " assertions, but " + this.assertions.length + " were run" );
132                 }
133
134                 var good = 0, bad = 0,
135                         tests = id("qunit-tests");
136
137                 config.stats.all += this.assertions.length;
138                 config.moduleStats.all += this.assertions.length;
139
140                 if ( tests ) {
141                         var ol = document.createElement("ol");
142
143                         for ( var i = 0; i < this.assertions.length; i++ ) {
144                                 var assertion = this.assertions[i];
145
146                                 var li = document.createElement("li");
147                                 li.className = assertion.result ? "pass" : "fail";
148                                 li.innerHTML = assertion.message || (assertion.result ? "okay" : "failed");
149                                 ol.appendChild( li );
150
151                                 if ( assertion.result ) {
152                                         good++;
153                                 } else {
154                                         bad++;
155                                         config.stats.bad++;
156                                         config.moduleStats.bad++;
157                                 }
158                         }
159
160                         // store result when possible
161                         if ( QUnit.config.reorder && defined.sessionStorage ) {
162                                 if (bad) {
163                                         sessionStorage.setItem("qunit-" + this.module + "-" + this.testName, bad);
164                                 } else {
165                                         sessionStorage.removeItem("qunit-" + this.module + "-" + this.testName);
166                                 }
167                         }
168
169                         if (bad == 0) {
170                                 ol.style.display = "none";
171                         }
172
173                         var b = document.createElement("strong");
174                         b.innerHTML = this.name + " <b class='counts'>(<b class='failed'>" + bad + "</b>, <b class='passed'>" + good + "</b>, " + this.assertions.length + ")</b>";
175
176                         var a = document.createElement("a");
177                         a.innerHTML = "Rerun";
178                         a.href = QUnit.url({ filter: getText([b]).replace(/\([^)]+\)$/, "").replace(/(^\s*|\s*$)/g, "") });
179
180                         addEvent(b, "click", function() {
181                                 var next = b.nextSibling.nextSibling,
182                                         display = next.style.display;
183                                 next.style.display = display === "none" ? "block" : "none";
184                         });
185
186                         addEvent(b, "dblclick", function(e) {
187                                 var target = e && e.target ? e.target : window.event.srcElement;
188                                 if ( target.nodeName.toLowerCase() == "span" || target.nodeName.toLowerCase() == "b" ) {
189                                         target = target.parentNode;
190                                 }
191                                 if ( window.location && target.nodeName.toLowerCase() === "strong" ) {
192                                         window.location = QUnit.url({ filter: getText([target]).replace(/\([^)]+\)$/, "").replace(/(^\s*|\s*$)/g, "") });
193                                 }
194                         });
195
196                         var li = id(this.id);
197                         li.className = bad ? "fail" : "pass";
198                         li.removeChild( li.firstChild );
199                         li.appendChild( b );
200                         li.appendChild( a );
201                         li.appendChild( ol );
202
203                 } else {
204                         for ( var i = 0; i < this.assertions.length; i++ ) {
205                                 if ( !this.assertions[i].result ) {
206                                         bad++;
207                                         config.stats.bad++;
208                                         config.moduleStats.bad++;
209                                 }
210                         }
211                 }
212
213                 try {
214                         QUnit.reset();
215                 } catch(e) {
216                         fail("reset() failed, following Test " + this.testName + ", exception and reset fn follows", e, QUnit.reset);
217                 }
218
219                 runLoggingCallbacks( 'testDone', QUnit, {
220                         name: this.testName,
221                         module: this.module,
222                         failed: bad,
223                         passed: this.assertions.length - bad,
224                         total: this.assertions.length
225                 } );
226         },
227
228         queue: function() {
229                 var test = this;
230                 synchronize(function() {
231                         test.init();
232                 });
233                 function run() {
234                         // each of these can by async
235                         synchronize(function() {
236                                 test.setup();
237                         });
238                         synchronize(function() {
239                                 test.run();
240                         });
241                         synchronize(function() {
242                                 test.teardown();
243                         });
244                         synchronize(function() {
245                                 test.finish();
246                         });
247                 }
248                 // defer when previous test run passed, if storage is available
249                 var bad = QUnit.config.reorder && defined.sessionStorage && +sessionStorage.getItem("qunit-" + this.module + "-" + this.testName);
250                 if (bad) {
251                         run();
252                 } else {
253                         synchronize(run, true);
254                 };
255         }
256
257 };
258
259 var QUnit = {
260
261         // call on start of module test to prepend name to all tests
262         module: function(name, testEnvironment) {
263                 config.currentModule = name;
264                 config.currentModuleTestEnviroment = testEnvironment;
265         },
266
267         asyncTest: function(testName, expected, callback) {
268                 if ( arguments.length === 2 ) {
269                         callback = expected;
270                         expected = null;
271                 }
272
273                 QUnit.test(testName, expected, callback, true);
274         },
275
276         test: function(testName, expected, callback, async) {
277                 var name = '<span class="test-name">' + testName + '</span>', testEnvironmentArg;
278
279                 if ( arguments.length === 2 ) {
280                         callback = expected;
281                         expected = null;
282                 }
283                 // is 2nd argument a testEnvironment?
284                 if ( expected && typeof expected === 'object') {
285                         testEnvironmentArg = expected;
286                         expected = null;
287                 }
288
289                 if ( config.currentModule ) {
290                         name = '<span class="module-name">' + config.currentModule + "</span>: " + name;
291                 }
292
293                 if ( !validTest(config.currentModule + ": " + testName) ) {
294                         return;
295                 }
296
297                 var test = new Test(name, testName, expected, testEnvironmentArg, async, callback);
298                 test.module = config.currentModule;
299                 test.moduleTestEnvironment = config.currentModuleTestEnviroment;
300                 test.queue();
301         },
302
303         /**
304          * Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through.
305          */
306         expect: function(asserts) {
307                 config.current.expected = asserts;
308         },
309
310         /**
311          * Asserts true.
312          * @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" );
313          */
314         ok: function(a, msg) {
315                 a = !!a;
316                 var details = {
317                         result: a,
318                         message: msg
319                 };
320                 msg = escapeInnerText(msg);
321                 runLoggingCallbacks( 'log', QUnit, details );
322                 config.current.assertions.push({
323                         result: a,
324                         message: msg
325                 });
326         },
327
328         /**
329          * Checks that the first two arguments are equal, with an optional message.
330          * Prints out both actual and expected values.
331          *
332          * Prefered to ok( actual == expected, message )
333          *
334          * @example equal( format("Received {0} bytes.", 2), "Received 2 bytes." );
335          *
336          * @param Object actual
337          * @param Object expected
338          * @param String message (optional)
339          */
340         equal: function(actual, expected, message) {
341                 QUnit.push(expected == actual, actual, expected, message);
342         },
343
344         notEqual: function(actual, expected, message) {
345                 QUnit.push(expected != actual, actual, expected, message);
346         },
347
348         deepEqual: function(actual, expected, message) {
349                 QUnit.push(QUnit.equiv(actual, expected), actual, expected, message);
350         },
351
352         notDeepEqual: function(actual, expected, message) {
353                 QUnit.push(!QUnit.equiv(actual, expected), actual, expected, message);
354         },
355
356         strictEqual: function(actual, expected, message) {
357                 QUnit.push(expected === actual, actual, expected, message);
358         },
359
360         notStrictEqual: function(actual, expected, message) {
361                 QUnit.push(expected !== actual, actual, expected, message);
362         },
363
364         raises: function(block, expected, message) {
365                 var actual, ok = false;
366
367                 if (typeof expected === 'string') {
368                         message = expected;
369                         expected = null;
370                 }
371
372                 try {
373                         block();
374                 } catch (e) {
375                         actual = e;
376                 }
377
378                 if (actual) {
379                         // we don't want to validate thrown error
380                         if (!expected) {
381                                 ok = true;
382                         // expected is a regexp
383                         } else if (QUnit.objectType(expected) === "regexp") {
384                                 ok = expected.test(actual);
385                         // expected is a constructor
386                         } else if (actual instanceof expected) {
387                                 ok = true;
388                         // expected is a validation function which returns true is validation passed
389                         } else if (expected.call({}, actual) === true) {
390                                 ok = true;
391                         }
392                 }
393
394                 QUnit.ok(ok, message);
395         },
396
397         start: function(count) {
398                 config.semaphore -= count || 1;
399                 if (config.semaphore > 0) {
400                         // don't start until equal number of stop-calls
401                         return;
402                 }
403                 if (config.semaphore < 0) {
404                         // ignore if start is called more often then stop
405                         config.semaphore = 0;
406                 }
407                 // A slight delay, to avoid any current callbacks
408                 if ( defined.setTimeout ) {
409                         window.setTimeout(function() {
410                                 if (config.semaphore > 0) {
411                                         return;
412                                 }
413                                 if ( config.timeout ) {
414                                         clearTimeout(config.timeout);
415                                 }
416
417                                 config.blocking = false;
418                                 process(true);
419                         }, 13);
420                 } else {
421                         config.blocking = false;
422                         process(true);
423                 }
424         },
425
426         stop: function(count) {
427                 config.semaphore += count || 1;
428                 config.blocking = true;
429
430                 if ( config.testTimeout && defined.setTimeout ) {
431                         clearTimeout(config.timeout);
432                         config.timeout = window.setTimeout(function() {
433                                 QUnit.ok( false, "Test timed out" );
434                                 config.semaphore = 1;
435                                 QUnit.start();
436                         }, config.testTimeout);
437                 }
438         }
439 };
440
441 //We want access to the constructor's prototype
442 (function() {
443         function F(){};
444         F.prototype = QUnit;
445         QUnit = new F();
446         //Make F QUnit's constructor so that we can add to the prototype later
447         QUnit.constructor = F;
448 })();
449
450 // Backwards compatibility, deprecated
451 QUnit.equals = QUnit.equal;
452 QUnit.same = QUnit.deepEqual;
453
454 // Maintain internal state
455 var config = {
456         // The queue of tests to run
457         queue: [],
458
459         // block until document ready
460         blocking: true,
461
462         // when enabled, show only failing tests
463         // gets persisted through sessionStorage and can be changed in UI via checkbox
464         hidepassed: false,
465
466         // by default, run previously failed tests first
467         // very useful in combination with "Hide passed tests" checked
468         reorder: true,
469
470         // by default, modify document.title when suite is done
471         altertitle: true,
472
473         urlConfig: ['noglobals', 'notrycatch'],
474
475         //logging callback queues
476         begin: [],
477         done: [],
478         log: [],
479         testStart: [],
480         testDone: [],
481         moduleStart: [],
482         moduleDone: []
483 };
484
485 // Load paramaters
486 (function() {
487         var location = window.location || { search: "", protocol: "file:" },
488                 params = location.search.slice( 1 ).split( "&" ),
489                 length = params.length,
490                 urlParams = {},
491                 current;
492
493         if ( params[ 0 ] ) {
494                 for ( var i = 0; i < length; i++ ) {
495                         current = params[ i ].split( "=" );
496                         current[ 0 ] = decodeURIComponent( current[ 0 ] );
497                         // allow just a key to turn on a flag, e.g., test.html?noglobals
498                         current[ 1 ] = current[ 1 ] ? decodeURIComponent( current[ 1 ] ) : true;
499                         urlParams[ current[ 0 ] ] = current[ 1 ];
500                 }
501         }
502
503         QUnit.urlParams = urlParams;
504         config.filter = urlParams.filter;
505
506         // Figure out if we're running the tests from a server or not
507         QUnit.isLocal = !!(location.protocol === 'file:');
508 })();
509
510 // Expose the API as global variables, unless an 'exports'
511 // object exists, in that case we assume we're in CommonJS
512 if ( typeof exports === "undefined" || typeof require === "undefined" ) {
513         extend(window, QUnit);
514         window.QUnit = QUnit;
515 } else {
516         extend(exports, QUnit);
517         exports.QUnit = QUnit;
518 }
519
520 // define these after exposing globals to keep them in these QUnit namespace only
521 extend(QUnit, {
522         config: config,
523
524         // Initialize the configuration options
525         init: function() {
526                 extend(config, {
527                         stats: { all: 0, bad: 0 },
528                         moduleStats: { all: 0, bad: 0 },
529                         started: +new Date,
530                         updateRate: 1000,
531                         blocking: false,
532                         autostart: true,
533                         autorun: false,
534                         filter: "",
535                         queue: [],
536                         semaphore: 0
537                 });
538
539                 var tests = id( "qunit-tests" ),
540                         banner = id( "qunit-banner" ),
541                         result = id( "qunit-testresult" );
542
543                 if ( tests ) {
544                         tests.innerHTML = "";
545                 }
546
547                 if ( banner ) {
548                         banner.className = "";
549                 }
550
551                 if ( result ) {
552                         result.parentNode.removeChild( result );
553                 }
554
555                 if ( tests ) {
556                         result = document.createElement( "p" );
557                         result.id = "qunit-testresult";
558                         result.className = "result";
559                         tests.parentNode.insertBefore( result, tests );
560                         result.innerHTML = 'Running...<br/>&nbsp;';
561                 }
562         },
563
564         /**
565          * Resets the test setup. Useful for tests that modify the DOM.
566          *
567          * If jQuery is available, uses jQuery's html(), otherwise just innerHTML.
568          */
569         reset: function() {
570                 if ( window.jQuery ) {
571                         jQuery( "#qunit-fixture" ).html( config.fixture );
572                 } else {
573                         var main = id( 'qunit-fixture' );
574                         if ( main ) {
575                                 main.innerHTML = config.fixture;
576                         }
577                 }
578         },
579
580         /**
581          * Trigger an event on an element.
582          *
583          * @example triggerEvent( document.body, "click" );
584          *
585          * @param DOMElement elem
586          * @param String type
587          */
588         triggerEvent: function( elem, type, event ) {
589                 if ( document.createEvent ) {
590                         event = document.createEvent("MouseEvents");
591                         event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView,
592                                 0, 0, 0, 0, 0, false, false, false, false, 0, null);
593                         elem.dispatchEvent( event );
594
595                 } else if ( elem.fireEvent ) {
596                         elem.fireEvent("on"+type);
597                 }
598         },
599
600         // Safe object type checking
601         is: function( type, obj ) {
602                 return QUnit.objectType( obj ) == type;
603         },
604
605         objectType: function( obj ) {
606                 if (typeof obj === "undefined") {
607                                 return "undefined";
608
609                 // consider: typeof null === object
610                 }
611                 if (obj === null) {
612                                 return "null";
613                 }
614
615                 var type = toString.call( obj ).match(/^\[object\s(.*)\]$/)[1] || '';
616
617                 switch (type) {
618                                 case 'Number':
619                                                 if (isNaN(obj)) {
620                                                                 return "nan";
621                                                 } else {
622                                                                 return "number";
623                                                 }
624                                 case 'String':
625                                 case 'Boolean':
626                                 case 'Array':
627                                 case 'Date':
628                                 case 'RegExp':
629                                 case 'Function':
630                                                 return type.toLowerCase();
631                 }
632                 if (typeof obj === "object") {
633                                 return "object";
634                 }
635                 return undefined;
636         },
637
638         push: function(result, actual, expected, message) {
639                 var details = {
640                         result: result,
641                         message: message,
642                         actual: actual,
643                         expected: expected
644                 };
645
646                 message = escapeInnerText(message) || (result ? "okay" : "failed");
647                 message = '<span class="test-message">' + message + "</span>";
648                 expected = escapeInnerText(QUnit.jsDump.parse(expected));
649                 actual = escapeInnerText(QUnit.jsDump.parse(actual));
650                 var output = message + '<table><tr class="test-expected"><th>Expected: </th><td><pre>' + expected + '</pre></td></tr>';
651                 if (actual != expected) {
652                         output += '<tr class="test-actual"><th>Result: </th><td><pre>' + actual + '</pre></td></tr>';
653                         output += '<tr class="test-diff"><th>Diff: </th><td><pre>' + QUnit.diff(expected, actual) +'</pre></td></tr>';
654                 }
655                 if (!result) {
656                         var source = sourceFromStacktrace();
657                         if (source) {
658                                 details.source = source;
659                                 output += '<tr class="test-source"><th>Source: </th><td><pre>' + escapeInnerText(source) + '</pre></td></tr>';
660                         }
661                 }
662                 output += "</table>";
663
664                 runLoggingCallbacks( 'log', QUnit, details );
665
666                 config.current.assertions.push({
667                         result: !!result,
668                         message: output
669                 });
670         },
671
672         url: function( params ) {
673                 params = extend( extend( {}, QUnit.urlParams ), params );
674                 var querystring = "?",
675                         key;
676                 for ( key in params ) {
677                         if ( !hasOwn.call( params, key ) ) {
678                                 continue;
679                         }
680                         querystring += encodeURIComponent( key ) + "=" +
681                                 encodeURIComponent( params[ key ] ) + "&";
682                 }
683                 return window.location.pathname + querystring.slice( 0, -1 );
684         },
685
686         extend: extend,
687         id: id,
688         addEvent: addEvent
689 });
690
691 //QUnit.constructor is set to the empty F() above so that we can add to it's prototype later
692 //Doing this allows us to tell if the following methods have been overwritten on the actual
693 //QUnit object, which is a deprecated way of using the callbacks.
694 extend(QUnit.constructor.prototype, {
695         // Logging callbacks; all receive a single argument with the listed properties
696         // run test/logs.html for any related changes
697         begin: registerLoggingCallback('begin'),
698         // done: { failed, passed, total, runtime }
699         done: registerLoggingCallback('done'),
700         // log: { result, actual, expected, message }
701         log: registerLoggingCallback('log'),
702         // testStart: { name }
703         testStart: registerLoggingCallback('testStart'),
704         // testDone: { name, failed, passed, total }
705         testDone: registerLoggingCallback('testDone'),
706         // moduleStart: { name }
707         moduleStart: registerLoggingCallback('moduleStart'),
708         // moduleDone: { name, failed, passed, total }
709         moduleDone: registerLoggingCallback('moduleDone')
710 });
711
712 if ( typeof document === "undefined" || document.readyState === "complete" ) {
713         config.autorun = true;
714 }
715
716 QUnit.load = function() {
717         runLoggingCallbacks( 'begin', QUnit, {} );
718
719         // Initialize the config, saving the execution queue
720         var oldconfig = extend({}, config);
721         QUnit.init();
722         extend(config, oldconfig);
723
724         config.blocking = false;
725
726         var urlConfigHtml = '', len = config.urlConfig.length;
727         for ( var i = 0, val; i < len, val = config.urlConfig[i]; i++ ) {
728                 config[val] = QUnit.urlParams[val];
729                 urlConfigHtml += '<label><input name="' + val + '" type="checkbox"' + ( config[val] ? ' checked="checked"' : '' ) + '>' + val + '</label>';
730         }
731
732         var userAgent = id("qunit-userAgent");
733         if ( userAgent ) {
734                 userAgent.innerHTML = navigator.userAgent;
735         }
736         var banner = id("qunit-header");
737         if ( banner ) {
738                 banner.innerHTML = '<a href="' + QUnit.url({ filter: undefined }) + '"> ' + banner.innerHTML + '</a> ' + urlConfigHtml;
739                 addEvent( banner, "change", function( event ) {
740                         var params = {};
741                         params[ event.target.name ] = event.target.checked ? true : undefined;
742                         window.location = QUnit.url( params );
743                 });
744         }
745
746         var toolbar = id("qunit-testrunner-toolbar");
747         if ( toolbar ) {
748                 var filter = document.createElement("input");
749                 filter.type = "checkbox";
750                 filter.id = "qunit-filter-pass";
751                 addEvent( filter, "click", function() {
752                         var ol = document.getElementById("qunit-tests");
753                         if ( filter.checked ) {
754                                 ol.className = ol.className + " hidepass";
755                         } else {
756                                 var tmp = " " + ol.className.replace( /[\n\t\r]/g, " " ) + " ";
757                                 ol.className = tmp.replace(/ hidepass /, " ");
758                         }
759                         if ( defined.sessionStorage ) {
760                                 if (filter.checked) {
761                                         sessionStorage.setItem("qunit-filter-passed-tests", "true");
762                                 } else {
763                                         sessionStorage.removeItem("qunit-filter-passed-tests");
764                                 }
765                         }
766                 });
767                 if ( config.hidepassed || defined.sessionStorage && sessionStorage.getItem("qunit-filter-passed-tests") ) {
768                         filter.checked = true;
769                         var ol = document.getElementById("qunit-tests");
770                         ol.className = ol.className + " hidepass";
771                 }
772                 toolbar.appendChild( filter );
773
774                 var label = document.createElement("label");
775                 label.setAttribute("for", "qunit-filter-pass");
776                 label.innerHTML = "Hide passed tests";
777                 toolbar.appendChild( label );
778         }
779
780         var main = id('qunit-fixture');
781         if ( main ) {
782                 config.fixture = main.innerHTML;
783         }
784
785         if (config.autostart) {
786                 QUnit.start();
787         }
788 };
789
790 addEvent(window, "load", QUnit.load);
791
792 function done() {
793         config.autorun = true;
794
795         // Log the last module results
796         if ( config.currentModule ) {
797                 runLoggingCallbacks( 'moduleDone', QUnit, {
798                         name: config.currentModule,
799                         failed: config.moduleStats.bad,
800                         passed: config.moduleStats.all - config.moduleStats.bad,
801                         total: config.moduleStats.all
802                 } );
803         }
804
805         var banner = id("qunit-banner"),
806                 tests = id("qunit-tests"),
807                 runtime = +new Date - config.started,
808                 passed = config.stats.all - config.stats.bad,
809                 html = [
810                         'Tests completed in ',
811                         runtime,
812                         ' milliseconds.<br/>',
813                         '<span class="passed">',
814                         passed,
815                         '</span> tests of <span class="total">',
816                         config.stats.all,
817                         '</span> passed, <span class="failed">',
818                         config.stats.bad,
819                         '</span> failed.'
820                 ].join('');
821
822         if ( banner ) {
823                 banner.className = (config.stats.bad ? "qunit-fail" : "qunit-pass");
824         }
825
826         if ( tests ) {
827                 id( "qunit-testresult" ).innerHTML = html;
828         }
829
830         if ( config.altertitle && typeof document !== "undefined" && document.title ) {
831                 // show ✖ for good, ✔ for bad suite result in title
832                 // use escape sequences in case file gets loaded with non-utf-8-charset
833                 document.title = [
834                         (config.stats.bad ? "\u2716" : "\u2714"),
835                         document.title.replace(/^[\u2714\u2716] /i, "")
836                 ].join(" ");
837         }
838
839         runLoggingCallbacks( 'done', QUnit, {
840                 failed: config.stats.bad,
841                 passed: passed,
842                 total: config.stats.all,
843                 runtime: runtime
844         } );
845 }
846
847 function validTest( name ) {
848         var filter = config.filter,
849                 run = false;
850
851         if ( !filter ) {
852                 return true;
853         }
854
855         var not = filter.charAt( 0 ) === "!";
856         if ( not ) {
857                 filter = filter.slice( 1 );
858         }
859
860         if ( name.indexOf( filter ) !== -1 ) {
861                 return !not;
862         }
863
864         if ( not ) {
865                 run = true;
866         }
867
868         return run;
869 }
870
871 // so far supports only Firefox, Chrome and Opera (buggy)
872 // could be extended in the future to use something like https://github.com/csnover/TraceKit
873 function sourceFromStacktrace() {
874         try {
875                 throw new Error();
876         } catch ( e ) {
877                 if (e.stacktrace) {
878                         // Opera
879                         return e.stacktrace.split("\n")[6];
880                 } else if (e.stack) {
881                         // Firefox, Chrome
882                         return e.stack.split("\n")[4];
883                 } else if (e.sourceURL) {
884                         // Safari, PhantomJS
885                         // TODO sourceURL points at the 'throw new Error' line above, useless
886                         //return e.sourceURL + ":" + e.line;
887                 }
888         }
889 }
890
891 function escapeInnerText(s) {
892         if (!s) {
893                 return "";
894         }
895         s = s + "";
896         return s.replace(/[\&<>]/g, function(s) {
897                 switch(s) {
898                         case "&": return "&amp;";
899                         case "<": return "&lt;";
900                         case ">": return "&gt;";
901                         default: return s;
902                 }
903         });
904 }
905
906 function synchronize( callback, last ) {
907         config.queue.push( callback );
908
909         if ( config.autorun && !config.blocking ) {
910                 process(last);
911         }
912 }
913
914 function process(last) {
915         var start = (new Date()).getTime();
916         config.depth = config.depth ? config.depth+1 : 1;
917
918         while ( config.queue.length && !config.blocking ) {
919                 if ( config.updateRate <= 0 || (((new Date()).getTime() - start) < config.updateRate) ) {
920                         config.queue.shift()();
921                 } else {
922                         window.setTimeout( function(){process(last)}, 13 );
923                         break;
924                 }
925         }
926         config.depth--;
927         if (last && !config.blocking && !config.queue.length && config.depth === 0) {
928                 done();
929         }
930 }
931
932 function saveGlobal() {
933         config.pollution = [];
934
935         if ( config.noglobals ) {
936                 for ( var key in window ) {
937                         if ( !hasOwn.call( window, key ) ) {
938                                 continue;
939                         }
940                         config.pollution.push( key );
941                 }
942         }
943 }
944
945 function checkPollution( name ) {
946         var old = config.pollution;
947         saveGlobal();
948
949         var newGlobals = diff( config.pollution, old );
950         if ( newGlobals.length > 0 ) {
951                 ok( false, "Introduced global variable(s): " + newGlobals.join(", ") );
952         }
953
954         var deletedGlobals = diff( old, config.pollution );
955         if ( deletedGlobals.length > 0 ) {
956                 ok( false, "Deleted global variable(s): " + deletedGlobals.join(", ") );
957         }
958 }
959
960 // returns a new Array with the elements that are in a but not in b
961 function diff( a, b ) {
962         var result = a.slice();
963         for ( var i = 0; i < result.length; i++ ) {
964                 for ( var j = 0; j < b.length; j++ ) {
965                         if ( result[i] === b[j] ) {
966                                 result.splice(i, 1);
967                                 i--;
968                                 break;
969                         }
970                 }
971         }
972         return result;
973 }
974
975 function fail(message, exception, callback) {
976         if ( typeof console !== "undefined" && console.error && console.warn ) {
977                 console.error(message);
978                 console.error(exception);
979                 console.warn(callback.toString());
980
981         } else if ( window.opera && opera.postError ) {
982                 opera.postError(message, exception, callback.toString);
983         }
984 }
985
986 function extend(a, b) {
987         for ( var prop in b ) {
988                 if ( b[prop] === undefined ) {
989                         delete a[prop];
990                 } else {
991                         a[prop] = b[prop];
992                 }
993         }
994
995         return a;
996 }
997
998 function addEvent(elem, type, fn) {
999         if ( elem.addEventListener ) {
1000                 elem.addEventListener( type, fn, false );
1001         } else if ( elem.attachEvent ) {
1002                 elem.attachEvent( "on" + type, fn );
1003         } else {
1004                 fn();
1005         }
1006 }
1007
1008 function id(name) {
1009         return !!(typeof document !== "undefined" && document && document.getElementById) &&
1010                 document.getElementById( name );
1011 }
1012
1013 function registerLoggingCallback(key){
1014         return function(callback){
1015                 config[key].push( callback );
1016         };
1017 }
1018
1019 // Supports deprecated method of completely overwriting logging callbacks
1020 function runLoggingCallbacks(key, scope, args) {
1021         //debugger;
1022         var callbacks;
1023         if ( QUnit.hasOwnProperty(key) ) {
1024                 QUnit[key].call(scope, args);
1025         } else {
1026                 callbacks = config[key];
1027                 for( var i = 0; i < callbacks.length; i++ ) {
1028                         callbacks[i].call( scope, args );
1029                 }
1030         }
1031 }
1032
1033 // Test for equality any JavaScript type.
1034 // Author: Philippe Rathé <prathe@gmail.com>
1035 QUnit.equiv = function () {
1036
1037         var innerEquiv; // the real equiv function
1038         var callers = []; // stack to decide between skip/abort functions
1039         var parents = []; // stack to avoiding loops from circular referencing
1040
1041         // Call the o related callback with the given arguments.
1042         function bindCallbacks(o, callbacks, args) {
1043                 var prop = QUnit.objectType(o);
1044                 if (prop) {
1045                         if (QUnit.objectType(callbacks[prop]) === "function") {
1046                                 return callbacks[prop].apply(callbacks, args);
1047                         } else {
1048                                 return callbacks[prop]; // or undefined
1049                         }
1050                 }
1051         }
1052
1053         var callbacks = function () {
1054
1055                 // for string, boolean, number and null
1056                 function useStrictEquality(b, a) {
1057                         if (b instanceof a.constructor || a instanceof b.constructor) {
1058                                 // to catch short annotaion VS 'new' annotation of a
1059                                 // declaration
1060                                 // e.g. var i = 1;
1061                                 // var j = new Number(1);
1062                                 return a == b;
1063                         } else {
1064                                 return a === b;
1065                         }
1066                 }
1067
1068                 return {
1069                         "string" : useStrictEquality,
1070                         "boolean" : useStrictEquality,
1071                         "number" : useStrictEquality,
1072                         "null" : useStrictEquality,
1073                         "undefined" : useStrictEquality,
1074
1075                         "nan" : function(b) {
1076                                 return isNaN(b);
1077                         },
1078
1079                         "date" : function(b, a) {
1080                                 return QUnit.objectType(b) === "date"
1081                                                 && a.valueOf() === b.valueOf();
1082                         },
1083
1084                         "regexp" : function(b, a) {
1085                                 return QUnit.objectType(b) === "regexp"
1086                                                 && a.source === b.source && // the regex itself
1087                                                 a.global === b.global && // and its modifers
1088                                                                                                         // (gmi) ...
1089                                                 a.ignoreCase === b.ignoreCase
1090                                                 && a.multiline === b.multiline;
1091                         },
1092
1093                         // - skip when the property is a method of an instance (OOP)
1094                         // - abort otherwise,
1095                         // initial === would have catch identical references anyway
1096                         "function" : function() {
1097                                 var caller = callers[callers.length - 1];
1098                                 return caller !== Object && typeof caller !== "undefined";
1099                         },
1100
1101                         "array" : function(b, a) {
1102                                 var i, j, loop;
1103                                 var len;
1104
1105                                 // b could be an object literal here
1106                                 if (!(QUnit.objectType(b) === "array")) {
1107                                         return false;
1108                                 }
1109
1110                                 len = a.length;
1111                                 if (len !== b.length) { // safe and faster
1112                                         return false;
1113                                 }
1114
1115                                 // track reference to avoid circular references
1116                                 parents.push(a);
1117                                 for (i = 0; i < len; i++) {
1118                                         loop = false;
1119                                         for (j = 0; j < parents.length; j++) {
1120                                                 if (parents[j] === a[i]) {
1121                                                         loop = true;// dont rewalk array
1122                                                 }
1123                                         }
1124                                         if (!loop && !innerEquiv(a[i], b[i])) {
1125                                                 parents.pop();
1126                                                 return false;
1127                                         }
1128                                 }
1129                                 parents.pop();
1130                                 return true;
1131                         },
1132
1133                         "object" : function(b, a) {
1134                                 var i, j, loop;
1135                                 var eq = true; // unless we can proove it
1136                                 var aProperties = [], bProperties = []; // collection of
1137                                                                                                                 // strings
1138
1139                                 // comparing constructors is more strict than using
1140                                 // instanceof
1141                                 if (a.constructor !== b.constructor) {
1142                                         return false;
1143                                 }
1144
1145                                 // stack constructor before traversing properties
1146                                 callers.push(a.constructor);
1147                                 // track reference to avoid circular references
1148                                 parents.push(a);
1149
1150                                 for (i in a) { // be strict: don't ensures hasOwnProperty
1151                                                                 // and go deep
1152                                         loop = false;
1153                                         for (j = 0; j < parents.length; j++) {
1154                                                 if (parents[j] === a[i])
1155                                                         loop = true; // don't go down the same path
1156                                                                                         // twice
1157                                         }
1158                                         aProperties.push(i); // collect a's properties
1159
1160                                         if (!loop && !innerEquiv(a[i], b[i])) {
1161                                                 eq = false;
1162                                                 break;
1163                                         }
1164                                 }
1165
1166                                 callers.pop(); // unstack, we are done
1167                                 parents.pop();
1168
1169                                 for (i in b) {
1170                                         bProperties.push(i); // collect b's properties
1171                                 }
1172
1173                                 // Ensures identical properties name
1174                                 return eq
1175                                                 && innerEquiv(aProperties.sort(), bProperties
1176                                                                 .sort());
1177                         }
1178                 };
1179         }();
1180
1181         innerEquiv = function() { // can take multiple arguments
1182                 var args = Array.prototype.slice.apply(arguments);
1183                 if (args.length < 2) {
1184                         return true; // end transition
1185                 }
1186
1187                 return (function(a, b) {
1188                         if (a === b) {
1189                                 return true; // catch the most you can
1190                         } else if (a === null || b === null || typeof a === "undefined"
1191                                         || typeof b === "undefined"
1192                                         || QUnit.objectType(a) !== QUnit.objectType(b)) {
1193                                 return false; // don't lose time with error prone cases
1194                         } else {
1195                                 return bindCallbacks(a, callbacks, [ b, a ]);
1196                         }
1197
1198                         // apply transition with (1..n) arguments
1199                 })(args[0], args[1])
1200                                 && arguments.callee.apply(this, args.splice(1,
1201                                                 args.length - 1));
1202         };
1203
1204         return innerEquiv;
1205
1206 }();
1207
1208 /**
1209  * jsDump Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com |
1210  * http://flesler.blogspot.com Licensed under BSD
1211  * (http://www.opensource.org/licenses/bsd-license.php) Date: 5/15/2008
1212  *
1213  * @projectDescription Advanced and extensible data dumping for Javascript.
1214  * @version 1.0.0
1215  * @author Ariel Flesler
1216  * @link {http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html}
1217  */
1218 QUnit.jsDump = (function() {
1219         function quote( str ) {
1220                 return '"' + str.toString().replace(/"/g, '\\"') + '"';
1221         };
1222         function literal( o ) {
1223                 return o + '';
1224         };
1225         function join( pre, arr, post ) {
1226                 var s = jsDump.separator(),
1227                         base = jsDump.indent(),
1228                         inner = jsDump.indent(1);
1229                 if ( arr.join )
1230                         arr = arr.join( ',' + s + inner );
1231                 if ( !arr )
1232                         return pre + post;
1233                 return [ pre, inner + arr, base + post ].join(s);
1234         };
1235         function array( arr, stack ) {
1236                 var i = arr.length, ret = Array(i);
1237                 this.up();
1238                 while ( i-- )
1239                         ret[i] = this.parse( arr[i] , undefined , stack);
1240                 this.down();
1241                 return join( '[', ret, ']' );
1242         };
1243
1244         var reName = /^function (\w+)/;
1245
1246         var jsDump = {
1247                 parse:function( obj, type, stack ) { //type is used mostly internally, you can fix a (custom)type in advance
1248                         stack = stack || [ ];
1249                         var parser = this.parsers[ type || this.typeOf(obj) ];
1250                         type = typeof parser;
1251                         var inStack = inArray(obj, stack);
1252                         if (inStack != -1) {
1253                                 return 'recursion('+(inStack - stack.length)+')';
1254                         }
1255                         //else
1256                         if (type == 'function')  {
1257                                         stack.push(obj);
1258                                         var res = parser.call( this, obj, stack );
1259                                         stack.pop();
1260                                         return res;
1261                         }
1262                         // else
1263                         return (type == 'string') ? parser : this.parsers.error;
1264                 },
1265                 typeOf:function( obj ) {
1266                         var type;
1267                         if ( obj === null ) {
1268                                 type = "null";
1269                         } else if (typeof obj === "undefined") {
1270                                 type = "undefined";
1271                         } else if (QUnit.is("RegExp", obj)) {
1272                                 type = "regexp";
1273                         } else if (QUnit.is("Date", obj)) {
1274                                 type = "date";
1275                         } else if (QUnit.is("Function", obj)) {
1276                                 type = "function";
1277                         } else if (typeof obj.setInterval !== undefined && typeof obj.document !== "undefined" && typeof obj.nodeType === "undefined") {
1278                                 type = "window";
1279                         } else if (obj.nodeType === 9) {
1280                                 type = "document";
1281                         } else if (obj.nodeType) {
1282                                 type = "node";
1283                         } else if (typeof obj === "object" && typeof obj.length === "number" && obj.length >= 0) {
1284                                 type = "array";
1285                         } else {
1286                                 type = typeof obj;
1287                         }
1288                         return type;
1289                 },
1290                 separator:function() {
1291                         return this.multiline ? this.HTML ? '<br />' : '\n' : this.HTML ? '&nbsp;' : ' ';
1292                 },
1293                 indent:function( extra ) {// extra can be a number, shortcut for increasing-calling-decreasing
1294                         if ( !this.multiline )
1295                                 return '';
1296                         var chr = this.indentChar;
1297                         if ( this.HTML )
1298                                 chr = chr.replace(/\t/g,'   ').replace(/ /g,'&nbsp;');
1299                         return Array( this._depth_ + (extra||0) ).join(chr);
1300                 },
1301                 up:function( a ) {
1302                         this._depth_ += a || 1;
1303                 },
1304                 down:function( a ) {
1305                         this._depth_ -= a || 1;
1306                 },
1307                 setParser:function( name, parser ) {
1308                         this.parsers[name] = parser;
1309                 },
1310                 // The next 3 are exposed so you can use them
1311                 quote:quote,
1312                 literal:literal,
1313                 join:join,
1314                 //
1315                 _depth_: 1,
1316                 // This is the list of parsers, to modify them, use jsDump.setParser
1317                 parsers:{
1318                         window: '[Window]',
1319                         document: '[Document]',
1320                         error:'[ERROR]', //when no parser is found, shouldn't happen
1321                         unknown: '[Unknown]',
1322                         'null':'null',
1323                         'undefined':'undefined',
1324                         'function':function( fn ) {
1325                                 var ret = 'function',
1326                                         name = 'name' in fn ? fn.name : (reName.exec(fn)||[])[1];//functions never have name in IE
1327                                 if ( name )
1328                                         ret += ' ' + name;
1329                                 ret += '(';
1330
1331                                 ret = [ ret, QUnit.jsDump.parse( fn, 'functionArgs' ), '){'].join('');
1332                                 return join( ret, QUnit.jsDump.parse(fn,'functionCode'), '}' );
1333                         },
1334                         array: array,
1335                         nodelist: array,
1336                         arguments: array,
1337                         object:function( map, stack ) {
1338                                 var ret = [ ];
1339                                 QUnit.jsDump.up();
1340                                 for ( var key in map ) {
1341                                     var val = map[key];
1342                                         ret.push( QUnit.jsDump.parse(key,'key') + ': ' + QUnit.jsDump.parse(val, undefined, stack));
1343                 }
1344                                 QUnit.jsDump.down();
1345                                 return join( '{', ret, '}' );
1346                         },
1347                         node:function( node ) {
1348                                 var open = QUnit.jsDump.HTML ? '&lt;' : '<',
1349                                         close = QUnit.jsDump.HTML ? '&gt;' : '>';
1350
1351                                 var tag = node.nodeName.toLowerCase(),
1352                                         ret = open + tag;
1353
1354                                 for ( var a in QUnit.jsDump.DOMAttrs ) {
1355                                         var val = node[QUnit.jsDump.DOMAttrs[a]];
1356                                         if ( val )
1357                                                 ret += ' ' + a + '=' + QUnit.jsDump.parse( val, 'attribute' );
1358                                 }
1359                                 return ret + close + open + '/' + tag + close;
1360                         },
1361                         functionArgs:function( fn ) {//function calls it internally, it's the arguments part of the function
1362                                 var l = fn.length;
1363                                 if ( !l ) return '';
1364
1365                                 var args = Array(l);
1366                                 while ( l-- )
1367                                         args[l] = String.fromCharCode(97+l);//97 is 'a'
1368                                 return ' ' + args.join(', ') + ' ';
1369                         },
1370                         key:quote, //object calls it internally, the key part of an item in a map
1371                         functionCode:'[code]', //function calls it internally, it's the content of the function
1372                         attribute:quote, //node calls it internally, it's an html attribute value
1373                         string:quote,
1374                         date:quote,
1375                         regexp:literal, //regex
1376                         number:literal,
1377                         'boolean':literal
1378                 },
1379                 DOMAttrs:{//attributes to dump from nodes, name=>realName
1380                         id:'id',
1381                         name:'name',
1382                         'class':'className'
1383                 },
1384                 HTML:false,//if true, entities are escaped ( <, >, \t, space and \n )
1385                 indentChar:'  ',//indentation unit
1386                 multiline:true //if true, items in a collection, are separated by a \n, else just a space.
1387         };
1388
1389         return jsDump;
1390 })();
1391
1392 // from Sizzle.js
1393 function getText( elems ) {
1394         var ret = "", elem;
1395
1396         for ( var i = 0; elems[i]; i++ ) {
1397                 elem = elems[i];
1398
1399                 // Get the text from text nodes and CDATA nodes
1400                 if ( elem.nodeType === 3 || elem.nodeType === 4 ) {
1401                         ret += elem.nodeValue;
1402
1403                 // Traverse everything else, except comment nodes
1404                 } else if ( elem.nodeType !== 8 ) {
1405                         ret += getText( elem.childNodes );
1406                 }
1407         }
1408
1409         return ret;
1410 };
1411
1412 //from jquery.js
1413 function inArray( elem, array ) {
1414         if ( array.indexOf ) {
1415                 return array.indexOf( elem );
1416         }
1417
1418         for ( var i = 0, length = array.length; i < length; i++ ) {
1419                 if ( array[ i ] === elem ) {
1420                         return i;
1421                 }
1422         }
1423
1424         return -1;
1425 }
1426
1427 /*
1428  * Javascript Diff Algorithm
1429  *  By John Resig (http://ejohn.org/)
1430  *  Modified by Chu Alan "sprite"
1431  *
1432  * Released under the MIT license.
1433  *
1434  * More Info:
1435  *  http://ejohn.org/projects/javascript-diff-algorithm/
1436  *
1437  * Usage: QUnit.diff(expected, actual)
1438  *
1439  * QUnit.diff("the quick brown fox jumped over", "the quick fox jumps over") == "the  quick <del>brown </del> fox <del>jumped </del><ins>jumps </ins> over"
1440  */
1441 QUnit.diff = (function() {
1442         function diff(o, n) {
1443                 var ns = {};
1444                 var os = {};
1445
1446                 for (var i = 0; i < n.length; i++) {
1447                         if (ns[n[i]] == null)
1448                                 ns[n[i]] = {
1449                                         rows: [],
1450                                         o: null
1451                                 };
1452                         ns[n[i]].rows.push(i);
1453                 }
1454
1455                 for (var i = 0; i < o.length; i++) {
1456                         if (os[o[i]] == null)
1457                                 os[o[i]] = {
1458                                         rows: [],
1459                                         n: null
1460                                 };
1461                         os[o[i]].rows.push(i);
1462                 }
1463
1464                 for (var i in ns) {
1465                         if ( !hasOwn.call( ns, i ) ) {
1466                                 continue;
1467                         }
1468                         if (ns[i].rows.length == 1 && typeof(os[i]) != "undefined" && os[i].rows.length == 1) {
1469                                 n[ns[i].rows[0]] = {
1470                                         text: n[ns[i].rows[0]],
1471                                         row: os[i].rows[0]
1472                                 };
1473                                 o[os[i].rows[0]] = {
1474                                         text: o[os[i].rows[0]],
1475                                         row: ns[i].rows[0]
1476                                 };
1477                         }
1478                 }
1479
1480                 for (var i = 0; i < n.length - 1; i++) {
1481                         if (n[i].text != null && n[i + 1].text == null && n[i].row + 1 < o.length && o[n[i].row + 1].text == null &&
1482                         n[i + 1] == o[n[i].row + 1]) {
1483                                 n[i + 1] = {
1484                                         text: n[i + 1],
1485                                         row: n[i].row + 1
1486                                 };
1487                                 o[n[i].row + 1] = {
1488                                         text: o[n[i].row + 1],
1489                                         row: i + 1
1490                                 };
1491                         }
1492                 }
1493
1494                 for (var i = n.length - 1; i > 0; i--) {
1495                         if (n[i].text != null && n[i - 1].text == null && n[i].row > 0 && o[n[i].row - 1].text == null &&
1496                         n[i - 1] == o[n[i].row - 1]) {
1497                                 n[i - 1] = {
1498                                         text: n[i - 1],
1499                                         row: n[i].row - 1
1500                                 };
1501                                 o[n[i].row - 1] = {
1502                                         text: o[n[i].row - 1],
1503                                         row: i - 1
1504                                 };
1505                         }
1506                 }
1507
1508                 return {
1509                         o: o,
1510                         n: n
1511                 };
1512         }
1513
1514         return function(o, n) {
1515                 o = o.replace(/\s+$/, '');
1516                 n = n.replace(/\s+$/, '');
1517                 var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/));
1518
1519                 var str = "";
1520
1521                 var oSpace = o.match(/\s+/g);
1522                 if (oSpace == null) {
1523                         oSpace = [" "];
1524                 }
1525                 else {
1526                         oSpace.push(" ");
1527                 }
1528                 var nSpace = n.match(/\s+/g);
1529                 if (nSpace == null) {
1530                         nSpace = [" "];
1531                 }
1532                 else {
1533                         nSpace.push(" ");
1534                 }
1535
1536                 if (out.n.length == 0) {
1537                         for (var i = 0; i < out.o.length; i++) {
1538                                 str += '<del>' + out.o[i] + oSpace[i] + "</del>";
1539                         }
1540                 }
1541                 else {
1542                         if (out.n[0].text == null) {
1543                                 for (n = 0; n < out.o.length && out.o[n].text == null; n++) {
1544                                         str += '<del>' + out.o[n] + oSpace[n] + "</del>";
1545                                 }
1546                         }
1547
1548                         for (var i = 0; i < out.n.length; i++) {
1549                                 if (out.n[i].text == null) {
1550                                         str += '<ins>' + out.n[i] + nSpace[i] + "</ins>";
1551                                 }
1552                                 else {
1553                                         var pre = "";
1554
1555                                         for (n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++) {
1556                                                 pre += '<del>' + out.o[n] + oSpace[n] + "</del>";
1557                                         }
1558                                         str += " " + out.n[i].text + nSpace[i] + pre;
1559                                 }
1560                         }
1561                 }
1562
1563                 return str;
1564         };
1565 })();
1566
1567 })(this);

Hosting is provided AltSPAHow to use Git
Please direct any questions on jabber alex.wolf@jabber.ru

Valid HTML 4.0 Transitional Valid CSS!

Designer Alexander Wolf