Home page Forum Wiki Mail Jabber Devel NIX-FILES

AltLUG Git

Git-repositories of Altai Linux User Group

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