survivalkit 1.0.beta.11 → 1.0.beta.12

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