cornerstone-source 0.1.1

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