client_side_validations 3.1.5 → 3.2.0.beta.1

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