joosy 0.1.0.RC3 → 0.1.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/.gitignore +0 -2
  2. data/Gemfile +2 -13
  3. data/Gemfile.lock +62 -80
  4. data/Guardfile +15 -21
  5. data/MIT-LICENSE +2 -2
  6. data/README.rdoc +3 -0
  7. data/app/helpers/joosy/sprockets_helper.rb +11 -23
  8. data/joosy.gemspec +3 -3
  9. data/lib/joosy/forms.rb +12 -2
  10. data/lib/joosy/rails/engine.rb +1 -9
  11. data/lib/joosy/rails/version.rb +2 -2
  12. data/lib/joosy-rails.rb +5 -0
  13. data/lib/rails/generators/joosy/application_generator.rb +3 -13
  14. data/lib/rails/generators/joosy/joosy_base.rb +2 -2
  15. data/lib/rails/generators/joosy/layout_generator.rb +1 -8
  16. data/lib/rails/generators/joosy/page_generator.rb +6 -21
  17. data/lib/rails/generators/joosy/preloader_generator.rb +7 -14
  18. data/lib/rails/generators/joosy/templates/app/layouts/application.js.coffee +0 -1
  19. data/lib/rails/generators/joosy/templates/app/layouts/template.js.coffee +1 -1
  20. data/lib/rails/generators/joosy/templates/app/pages/application.js.coffee +1 -1
  21. data/lib/rails/generators/joosy/templates/app/pages/template.js.coffee +3 -3
  22. data/lib/rails/generators/joosy/templates/app/routes.js.coffee +1 -7
  23. data/lib/rails/generators/joosy/templates/app/widgets/template.js.coffee +2 -2
  24. data/lib/rails/generators/joosy/templates/app.js.coffee +0 -3
  25. data/lib/rails/generators/joosy/templates/app_preloader.js.coffee.erb +12 -9
  26. data/lib/rails/generators/joosy/templates/preload.html.erb +6 -5
  27. data/lib/rails/generators/joosy/templates/preload.html.haml +5 -3
  28. data/lib/rails/generators/joosy/templates/preload.html.slim +21 -0
  29. data/lib/rails/generators/joosy/widget_generator.rb +1 -8
  30. data/spec/javascripts/helpers/spec_helper.js.coffee +0 -20
  31. data/spec/javascripts/joosy/core/modules/container_spec.js.coffee +27 -24
  32. data/spec/javascripts/joosy/core/modules/events_spec.js.coffee +18 -42
  33. data/spec/javascripts/joosy/core/modules/filters_spec.js.coffee +27 -27
  34. data/spec/javascripts/joosy/core/modules/log_spec.js.coffee +3 -3
  35. data/spec/javascripts/joosy/core/modules/module_spec.js.coffee +15 -6
  36. data/spec/javascripts/joosy/core/modules/time_manager_spec.js.coffee +7 -12
  37. data/spec/javascripts/joosy/core/modules/widget_manager_spec.js.coffee +17 -31
  38. data/tmp/javascripts/.gitignore +1 -0
  39. data/tmp/spec/javascripts/helpers/.gitignore +1 -0
  40. data/vendor/assets/javascripts/base64.js +135 -0
  41. data/vendor/assets/javascripts/joosy/core/application.js.coffee +26 -0
  42. data/vendor/assets/javascripts/joosy/core/form.js.coffee +87 -0
  43. data/vendor/assets/javascripts/joosy/core/joosy.js.coffee +62 -0
  44. data/vendor/assets/javascripts/joosy/core/layout.js.coffee +38 -0
  45. data/vendor/assets/javascripts/joosy/core/modules/container.js.coffee +51 -0
  46. data/vendor/assets/javascripts/joosy/core/modules/events.js.coffee +17 -0
  47. data/vendor/assets/javascripts/joosy/core/modules/filters.js.coffee +39 -0
  48. data/vendor/assets/javascripts/joosy/core/modules/log.js.coffee +12 -0
  49. data/vendor/assets/javascripts/joosy/core/modules/module.js.coffee +28 -0
  50. data/vendor/assets/javascripts/joosy/core/modules/time_manager.js.coffee +23 -0
  51. data/vendor/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee +45 -0
  52. data/vendor/assets/javascripts/joosy/core/page.js.coffee +136 -0
  53. data/vendor/assets/javascripts/joosy/core/resource/rest.js.coffee +69 -0
  54. data/vendor/assets/javascripts/joosy/core/resource/rest_collection.js.coffee +42 -0
  55. data/vendor/assets/javascripts/joosy/core/router.js.coffee +75 -0
  56. data/vendor/assets/javascripts/joosy/core/widget.js.coffee +35 -0
  57. data/vendor/assets/javascripts/joosy/preloader/development.js.coffee +27 -0
  58. data/vendor/assets/javascripts/joosy/preloader/production.js.coffee +84 -0
  59. data/{app → vendor}/assets/javascripts/joosy.js.coffee +0 -0
  60. data/vendor/assets/javascripts/jquery.form.js +963 -978
  61. data/vendor/assets/javascripts/sugar.js +1 -1
  62. metadata +48 -77
  63. data/.codoopts +0 -5
  64. data/README.md +0 -95
  65. data/app/assets/javascripts/joosy/core/application.js.coffee +0 -50
  66. data/app/assets/javascripts/joosy/core/form.js.coffee +0 -304
  67. data/app/assets/javascripts/joosy/core/helpers/view.js.coffee +0 -30
  68. data/app/assets/javascripts/joosy/core/joosy.js.coffee +0 -129
  69. data/app/assets/javascripts/joosy/core/layout.js.coffee +0 -162
  70. data/app/assets/javascripts/joosy/core/modules/container.js.coffee +0 -104
  71. data/app/assets/javascripts/joosy/core/modules/events.js.coffee +0 -123
  72. data/app/assets/javascripts/joosy/core/modules/filters.js.coffee +0 -67
  73. data/app/assets/javascripts/joosy/core/modules/log.js.coffee +0 -36
  74. data/app/assets/javascripts/joosy/core/modules/module.js.coffee +0 -105
  75. data/app/assets/javascripts/joosy/core/modules/renderer.js.coffee +0 -195
  76. data/app/assets/javascripts/joosy/core/modules/time_manager.js.coffee +0 -46
  77. data/app/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee +0 -84
  78. data/app/assets/javascripts/joosy/core/page.js.coffee +0 -375
  79. data/app/assets/javascripts/joosy/core/preloader.js.coffee +0 -13
  80. data/app/assets/javascripts/joosy/core/resource/collection.js.coffee +0 -174
  81. data/app/assets/javascripts/joosy/core/resource/generic.js.coffee +0 -254
  82. data/app/assets/javascripts/joosy/core/resource/rest.js.coffee +0 -197
  83. data/app/assets/javascripts/joosy/core/resource/rest_collection.js.coffee +0 -125
  84. data/app/assets/javascripts/joosy/core/router.js.coffee +0 -163
  85. data/app/assets/javascripts/joosy/core/templaters/rails_jst.js.coffee +0 -36
  86. data/app/assets/javascripts/joosy/core/widget.js.coffee +0 -80
  87. data/app/assets/javascripts/joosy/preloaders/caching.js.coffee +0 -169
  88. data/app/assets/javascripts/joosy/preloaders/inline.js.coffee +0 -56
  89. data/lib/joosy.rb +0 -9
  90. data/lib/rails/generators/joosy/resource_generator.rb +0 -29
  91. data/lib/rails/generators/joosy/templates/app/helpers/application.js.coffee +0 -4
  92. data/lib/rails/generators/joosy/templates/app/pages/welcome/index.js.coffee +0 -22
  93. data/lib/rails/generators/joosy/templates/app/resources/template.js.coffee +0 -2
  94. data/lib/rails/generators/joosy/templates/app/templates/layouts/application.jst.hamlc +0 -2
  95. data/lib/rails/generators/joosy/templates/app/templates/pages/welcome/index.jst.hamlc +0 -7
  96. data/spec/javascripts/joosy/core/application_spec.js.coffee +0 -40
  97. data/spec/javascripts/joosy/core/form_spec.js.coffee +0 -184
  98. data/spec/javascripts/joosy/core/joosy_spec.js.coffee +0 -72
  99. data/spec/javascripts/joosy/core/layout_spec.js.coffee +0 -50
  100. data/spec/javascripts/joosy/core/modules/renderer_spec.js.coffee +0 -185
  101. data/spec/javascripts/joosy/core/page_spec.js.coffee +0 -178
  102. data/spec/javascripts/joosy/core/resource/collection_spec.js.coffee +0 -84
  103. data/spec/javascripts/joosy/core/resource/generic_spec.js.coffee +0 -118
  104. data/spec/javascripts/joosy/core/resource/rest_collection_spec.js.coffee +0 -58
  105. data/spec/javascripts/joosy/core/resource/rest_spec.js.coffee +0 -129
  106. data/spec/javascripts/joosy/core/router_spec.js.coffee +0 -123
  107. data/spec/javascripts/joosy/core/templaters/rails_jst_spec.js.coffee +0 -25
  108. data/spec/javascripts/joosy/core/widget_spec.js.coffee +0 -40
  109. data/spec/javascripts/joosy/preloaders/caching_spec.js.coffee +0 -36
  110. data/spec/javascripts/joosy/preloaders/inline_spec.js.coffee +0 -16
  111. data/spec/javascripts/support/assets/coolface.jpg +0 -0
  112. data/spec/javascripts/support/assets/okay.jpg +0 -0
  113. data/spec/javascripts/support/assets/test.js +0 -1
  114. data/spec/javascripts/support/sinon-ie-1.3.1.js +0 -82
  115. data/vendor/assets/javascripts/metamorph.js +0 -409
@@ -1,82 +0,0 @@
1
- /**
2
- * Sinon.JS 1.3.1, 2012/01/04
3
- *
4
- * @author Christian Johansen (christian@cjohansen.no)
5
- *
6
- * (The BSD License)
7
- *
8
- * Copyright (c) 2010-2011, Christian Johansen, christian@cjohansen.no
9
- * All rights reserved.
10
- *
11
- * Redistribution and use in source and binary forms, with or without modification,
12
- * are permitted provided that the following conditions are met:
13
- *
14
- * * Redistributions of source code must retain the above copyright notice,
15
- * this list of conditions and the following disclaimer.
16
- * * Redistributions in binary form must reproduce the above copyright notice,
17
- * this list of conditions and the following disclaimer in the documentation
18
- * and/or other materials provided with the distribution.
19
- * * Neither the name of Christian Johansen nor the names of his contributors
20
- * may be used to endorse or promote products derived from this software
21
- * without specific prior written permission.
22
- *
23
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
27
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
- */
34
-
35
- "use strict";
36
- /*global sinon, setTimeout, setInterval, clearTimeout, clearInterval, Date*/
37
- /**
38
- * Helps IE run the fake timers. By defining global functions, IE allows
39
- * them to be overwritten at a later point. If these are not defined like
40
- * this, overwriting them will result in anything from an exception to browser
41
- * crash.
42
- *
43
- * If you don't require fake timers to work in IE, don't include this file.
44
- *
45
- * @author Christian Johansen (christian@cjohansen.no)
46
- * @license BSD
47
- *
48
- * Copyright (c) 2010-2011 Christian Johansen
49
- */
50
- function setTimeout() {}
51
- function clearTimeout() {}
52
- function setInterval() {}
53
- function clearInterval() {}
54
- function Date() {}
55
-
56
- // Reassign the original functions. Now their writable attribute
57
- // should be true. Hackish, I know, but it works.
58
- setTimeout = sinon.timers.setTimeout;
59
- clearTimeout = sinon.timers.clearTimeout;
60
- setInterval = sinon.timers.setInterval;
61
- clearInterval = sinon.timers.clearInterval;
62
- Date = sinon.timers.Date;
63
-
64
- /*global sinon*/
65
- /**
66
- * Helps IE run the fake XMLHttpRequest. By defining global functions, IE allows
67
- * them to be overwritten at a later point. If these are not defined like
68
- * this, overwriting them will result in anything from an exception to browser
69
- * crash.
70
- *
71
- * If you don't require fake XHR to work in IE, don't include this file.
72
- *
73
- * @author Christian Johansen (christian@cjohansen.no)
74
- * @license BSD
75
- *
76
- * Copyright (c) 2010-2011 Christian Johansen
77
- */
78
- function XMLHttpRequest() {}
79
-
80
- // Reassign the original function. Now its writable attribute
81
- // should be true. Hackish, I know, but it works.
82
- XMLHttpRequest = sinon.xhr.XMLHttpRequest || undefined;
@@ -1,409 +0,0 @@
1
- // ==========================================================================
2
- // Project: metamorph
3
- // Copyright: ©2011 My Company Inc. All rights reserved.
4
- // ==========================================================================
5
-
6
- (function(window) {
7
-
8
- var K = function(){},
9
- guid = 0,
10
- document = window.document,
11
-
12
- // Feature-detect the W3C range API, the extended check is for IE9 which only partially supports ranges
13
- supportsRange = ('createRange' in document) && (typeof Range !== 'undefined') && Range.prototype.createContextualFragment,
14
-
15
- // Internet Explorer prior to 9 does not allow setting innerHTML if the first element
16
- // is a "zero-scope" element. This problem can be worked around by making
17
- // the first node an invisible text node. We, like Modernizr, use ­
18
- needsShy = (function(){
19
- var testEl = document.createElement('div');
20
- testEl.innerHTML = "<div></div>";
21
- testEl.firstChild.innerHTML = "<script></script>";
22
- return testEl.firstChild.innerHTML === '';
23
- })();
24
-
25
- // Constructor that supports either Metamorph('foo') or new
26
- // Metamorph('foo');
27
- //
28
- // Takes a string of HTML as the argument.
29
-
30
- var Metamorph = function(html) {
31
- var self;
32
-
33
- if (this instanceof Metamorph) {
34
- self = this;
35
- } else {
36
- self = new K();
37
- }
38
-
39
- self.innerHTML = html;
40
- var myGuid = 'metamorph-'+(guid++);
41
- self.start = myGuid + '-start';
42
- self.end = myGuid + '-end';
43
-
44
- return self;
45
- };
46
-
47
- K.prototype = Metamorph.prototype;
48
-
49
- var rangeFor, htmlFunc, removeFunc, outerHTMLFunc, appendToFunc, afterFunc, prependFunc, startTagFunc, endTagFunc;
50
-
51
- outerHTMLFunc = function() {
52
- return this.startTag() + this.innerHTML + this.endTag();
53
- };
54
-
55
- startTagFunc = function() {
56
- return "<script id='" + this.start + "' type='text/x-placeholder'></script>";
57
- };
58
-
59
- endTagFunc = function() {
60
- return "<script id='" + this.end + "' type='text/x-placeholder'></script>";
61
- };
62
-
63
- // If we have the W3C range API, this process is relatively straight forward.
64
- if (supportsRange) {
65
-
66
- // IE 9 supports ranges but doesn't define createContextualFragment
67
- if (!Range.prototype.createContextualFragment) {
68
- Range.prototype.createContextualFragment = function(html) {
69
- var frag = document.createDocumentFragment(),
70
- div = document.createElement("div");
71
- frag.appendChild(div);
72
- div.outerHTML = html;
73
- return frag;
74
- };
75
- }
76
-
77
- // Get a range for the current morph. Optionally include the starting and
78
- // ending placeholders.
79
- rangeFor = function(morph, outerToo) {
80
- var range = document.createRange();
81
- var before = document.getElementById(morph.start);
82
- var after = document.getElementById(morph.end);
83
-
84
- if (outerToo) {
85
- range.setStartBefore(before);
86
- range.setEndAfter(after);
87
- } else {
88
- range.setStartAfter(before);
89
- range.setEndBefore(after);
90
- }
91
-
92
- return range;
93
- };
94
-
95
- htmlFunc = function(html, outerToo) {
96
- // get a range for the current metamorph object
97
- var range = rangeFor(this, outerToo);
98
-
99
- // delete the contents of the range, which will be the
100
- // nodes between the starting and ending placeholder.
101
- range.deleteContents();
102
-
103
- // create a new document fragment for the HTML
104
- var fragment = range.createContextualFragment(html);
105
-
106
- // insert the fragment into the range
107
- range.insertNode(fragment);
108
- };
109
-
110
- removeFunc = function() {
111
- // get a range for the current metamorph object including
112
- // the starting and ending placeholders.
113
- var range = rangeFor(this, true);
114
-
115
- // delete the entire range.
116
- range.deleteContents();
117
- };
118
-
119
- appendToFunc = function(node) {
120
- var range = document.createRange();
121
- range.setStart(node);
122
- range.collapse(false);
123
- var frag = range.createContextualFragment(this.outerHTML());
124
- node.appendChild(frag);
125
- };
126
-
127
- afterFunc = function(html) {
128
- var range = document.createRange();
129
- var after = document.getElementById(this.end);
130
-
131
- range.setStartAfter(after);
132
- range.setEndAfter(after);
133
-
134
- var fragment = range.createContextualFragment(html);
135
- range.insertNode(fragment);
136
- };
137
-
138
- prependFunc = function(html) {
139
- var range = document.createRange();
140
- var start = document.getElementById(this.start);
141
-
142
- range.setStartAfter(start);
143
- range.setEndAfter(start);
144
-
145
- var fragment = range.createContextualFragment(html);
146
- range.insertNode(fragment);
147
- };
148
-
149
- } else {
150
- /**
151
- * This code is mostly taken from jQuery, with one exception. In jQuery's case, we
152
- * have some HTML and we need to figure out how to convert it into some nodes.
153
- *
154
- * In this case, jQuery needs to scan the HTML looking for an opening tag and use
155
- * that as the key for the wrap map. In our case, we know the parent node, and
156
- * can use its type as the key for the wrap map.
157
- **/
158
- var wrapMap = {
159
- select: [ 1, "<select multiple='multiple'>", "</select>" ],
160
- fieldset: [ 1, "<fieldset>", "</fieldset>" ],
161
- table: [ 1, "<table>", "</table>" ],
162
- tbody: [ 2, "<table><tbody>", "</tbody></table>" ],
163
- tr: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
164
- colgroup: [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ],
165
- map: [ 1, "<map>", "</map>" ],
166
- _default: [ 0, "", "" ]
167
- };
168
-
169
- /**
170
- * Given a parent node and some HTML, generate a set of nodes. Return the first
171
- * node, which will allow us to traverse the rest using nextSibling.
172
- *
173
- * We need to do this because innerHTML in IE does not really parse the nodes.
174
- **/
175
- var firstNodeFor = function(parentNode, html) {
176
- var arr = wrapMap[parentNode.tagName.toLowerCase()] || wrapMap._default;
177
- var depth = arr[0], start = arr[1], end = arr[2];
178
-
179
- if (needsShy) { html = '&shy;'+html; }
180
-
181
- var element = document.createElement('div');
182
- element.innerHTML = start + html + end;
183
-
184
- for (var i=0; i<=depth; i++) {
185
- element = element.firstChild;
186
- }
187
-
188
- // Look for &shy; to remove it.
189
- if (needsShy) {
190
- var shyElement = element;
191
-
192
- // Sometimes we get nameless elements with the shy inside
193
- while (shyElement.nodeType === 1 && !shyElement.nodeName && shyElement.childNodes.length === 1) {
194
- shyElement = shyElement.firstChild;
195
- }
196
-
197
- // At this point it's the actual unicode character.
198
- if (shyElement.nodeType === 3 && shyElement.nodeValue.charAt(0) === "\u00AD") {
199
- shyElement.nodeValue = shyElement.nodeValue.slice(1);
200
- }
201
- }
202
-
203
- return element;
204
- };
205
-
206
- /**
207
- * In some cases, Internet Explorer can create an anonymous node in
208
- * the hierarchy with no tagName. You can create this scenario via:
209
- *
210
- * div = document.createElement("div");
211
- * div.innerHTML = "<table>&shy<script></script><tr><td>hi</td></tr></table>";
212
- * div.firstChild.firstChild.tagName //=> ""
213
- *
214
- * If our script markers are inside such a node, we need to find that
215
- * node and use *it* as the marker.
216
- **/
217
- var realNode = function(start) {
218
- while (start.parentNode.tagName === "") {
219
- start = start.parentNode;
220
- }
221
-
222
- return start;
223
- };
224
-
225
- /**
226
- * When automatically adding a tbody, Internet Explorer inserts the
227
- * tbody immediately before the first <tr>. Other browsers create it
228
- * before the first node, no matter what.
229
- *
230
- * This means the the following code:
231
- *
232
- * div = document.createElement("div");
233
- * div.innerHTML = "<table><script id='first'></script><tr><td>hi</td></tr><script id='last'></script></table>
234
- *
235
- * Generates the following DOM in IE:
236
- *
237
- * + div
238
- * + table
239
- * - script id='first'
240
- * + tbody
241
- * + tr
242
- * + td
243
- * - "hi"
244
- * - script id='last'
245
- *
246
- * Which means that the two script tags, even though they were
247
- * inserted at the same point in the hierarchy in the original
248
- * HTML, now have different parents.
249
- *
250
- * This code reparents the first script tag by making it the tbody's
251
- * first child.
252
- **/
253
- var fixParentage = function(start, end) {
254
- if (start.parentNode !== end.parentNode) {
255
- end.parentNode.insertBefore(start, end.parentNode.firstChild);
256
- }
257
- };
258
-
259
- htmlFunc = function(html, outerToo) {
260
- // get the real starting node. see realNode for details.
261
- var start = realNode(document.getElementById(this.start));
262
- var end = document.getElementById(this.end);
263
- var parentNode = end.parentNode;
264
- var node, nextSibling, last;
265
-
266
- // make sure that the start and end nodes share the same
267
- // parent. If not, fix it.
268
- fixParentage(start, end);
269
-
270
- // remove all of the nodes after the starting placeholder and
271
- // before the ending placeholder.
272
- node = start.nextSibling;
273
- while (node) {
274
- nextSibling = node.nextSibling;
275
- last = node === end;
276
-
277
- // if this is the last node, and we want to remove it as well,
278
- // set the `end` node to the next sibling. This is because
279
- // for the rest of the function, we insert the new nodes
280
- // before the end (note that insertBefore(node, null) is
281
- // the same as appendChild(node)).
282
- //
283
- // if we do not want to remove it, just break.
284
- if (last) {
285
- if (outerToo) { end = node.nextSibling; } else { break; }
286
- }
287
-
288
- node.parentNode.removeChild(node);
289
-
290
- // if this is the last node and we didn't break before
291
- // (because we wanted to remove the outer nodes), break
292
- // now.
293
- if (last) { break; }
294
-
295
- node = nextSibling;
296
- }
297
-
298
- // get the first node for the HTML string, even in cases like
299
- // tables and lists where a simple innerHTML on a div would
300
- // swallow some of the content.
301
- node = firstNodeFor(start.parentNode, html);
302
-
303
- // copy the nodes for the HTML between the starting and ending
304
- // placeholder.
305
- while (node) {
306
- nextSibling = node.nextSibling;
307
- parentNode.insertBefore(node, end);
308
- node = nextSibling;
309
- }
310
- };
311
-
312
- // remove the nodes in the DOM representing this metamorph.
313
- //
314
- // this includes the starting and ending placeholders.
315
- removeFunc = function() {
316
- var start = realNode(document.getElementById(this.start));
317
- var end = document.getElementById(this.end);
318
-
319
- this.html('');
320
- start.parentNode.removeChild(start);
321
- end.parentNode.removeChild(end);
322
- };
323
-
324
- appendToFunc = function(parentNode) {
325
- var node = firstNodeFor(parentNode, this.outerHTML());
326
-
327
- while (node) {
328
- nextSibling = node.nextSibling;
329
- parentNode.appendChild(node);
330
- node = nextSibling;
331
- }
332
- };
333
-
334
- afterFunc = function(html) {
335
- // get the real starting node. see realNode for details.
336
- var end = document.getElementById(this.end);
337
- var parentNode = end.parentNode;
338
- var nextSibling;
339
- var node;
340
-
341
- // get the first node for the HTML string, even in cases like
342
- // tables and lists where a simple innerHTML on a div would
343
- // swallow some of the content.
344
- node = firstNodeFor(parentNode, html);
345
-
346
- // copy the nodes for the HTML between the starting and ending
347
- // placeholder.
348
- while (node) {
349
- nextSibling = node.nextSibling;
350
- parentNode.insertBefore(node, end.nextSibling);
351
- node = nextSibling;
352
- }
353
- };
354
-
355
- prependFunc = function(html) {
356
- var start = document.getElementById(this.start);
357
- var parentNode = start.parentNode;
358
- var nextSibling;
359
- var node;
360
-
361
- node = firstNodeFor(parentNode, html);
362
- var insertBefore = start.nextSibling;
363
-
364
- while (node) {
365
- nextSibling = node.nextSibling;
366
- parentNode.insertBefore(node, insertBefore);
367
- node = nextSibling;
368
- }
369
- }
370
- }
371
-
372
- Metamorph.prototype.html = function(html) {
373
- this.checkRemoved();
374
- if (html === undefined) { return this.innerHTML; }
375
-
376
- htmlFunc.call(this, html);
377
-
378
- this.innerHTML = html;
379
- };
380
-
381
- Metamorph.prototype.replaceWith = function(html) {
382
- this.checkRemoved();
383
- htmlFunc.call(this, html, true);
384
- };
385
-
386
- Metamorph.prototype.remove = removeFunc;
387
- Metamorph.prototype.outerHTML = outerHTMLFunc;
388
- Metamorph.prototype.appendTo = appendToFunc;
389
- Metamorph.prototype.after = afterFunc;
390
- Metamorph.prototype.prepend = prependFunc;
391
- Metamorph.prototype.startTag = startTagFunc;
392
- Metamorph.prototype.endTag = endTagFunc;
393
-
394
- Metamorph.prototype.isRemoved = function() {
395
- var before = document.getElementById(this.start);
396
- var after = document.getElementById(this.end);
397
-
398
- return !before || !after;
399
- };
400
-
401
- Metamorph.prototype.checkRemoved = function() {
402
- if (this.isRemoved()) {
403
- throw new Error("Cannot perform operations on a Metamorph that is not in the DOM.");
404
- }
405
- };
406
-
407
- window.Metamorph = Metamorph;
408
- })(this);
409
-