ipage 1.0.1

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