Home page Forum Wiki Mail Jabber Devel NIX-FILES

AltLUG Git

Git-repositories of Altai Linux User Group

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