rasputin 0.10.0 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -77,6 +77,10 @@ In your stylesheet asset manifest (app/assets/stylesheets/application.css) add t
77
77
  ChangeLog
78
78
  ----------
79
79
 
80
+ 0.10.1
81
+
82
+ * update with built in metamorph
83
+
80
84
  0.10.0
81
85
 
82
86
  * add sproutcore-routing
@@ -1,3 +1,3 @@
1
1
  module Rasputin
2
- VERSION = "0.10.0"
2
+ VERSION = "0.10.1"
3
3
  end
@@ -1,4 +1,3 @@
1
- //=require metamorph
2
1
 
3
2
  (function(exports) {
4
3
  // lib/handlebars/base.js
@@ -12569,6 +12568,333 @@ SC.CollectionView.CONTAINER_MAP = {
12569
12568
  SC.$ = jQuery;
12570
12569
 
12571
12570
 
12571
+ })({});
12572
+
12573
+ (function(exports) {
12574
+ // ==========================================================================
12575
+ // Project: metamorph
12576
+ // Copyright: ©2011 My Company Inc. All rights reserved.
12577
+ // ==========================================================================
12578
+
12579
+ (function(window) {
12580
+
12581
+ var K = function(){},
12582
+ guid = 0,
12583
+
12584
+ // Feature-detect the W3C range API
12585
+ supportsRange = ('createRange' in document);
12586
+
12587
+ // Constructor that supports either Metamorph('foo') or new
12588
+ // Metamorph('foo');
12589
+ //
12590
+ // Takes a string of HTML as the argument.
12591
+
12592
+ var Metamorph = function(html) {
12593
+ var self;
12594
+
12595
+ if (this instanceof Metamorph) {
12596
+ self = this;
12597
+ } else {
12598
+ self = new K;
12599
+ }
12600
+
12601
+ self.innerHTML = html;
12602
+ var myGuid = 'metamorph-'+(guid++);
12603
+ self.start = myGuid + '-start';
12604
+ self.end = myGuid + '-end';
12605
+
12606
+ return self;
12607
+ };
12608
+
12609
+ K.prototype = Metamorph.prototype;
12610
+
12611
+ var rangeFor, htmlFunc, removeFunc, outerHTMLFunc, appendToFunc, startTagFunc, endTagFunc;
12612
+
12613
+ // create the outer HTML for the current metamorph. this function will be
12614
+ // extended by the Internet Explorer version to work around a bug.
12615
+ outerHTMLFunc = function() {
12616
+ return this.startTag() + this.innerHTML + this.endTag();
12617
+ };
12618
+
12619
+ startTagFunc = function() {
12620
+ return "<script id='" + this.start + "' type='text/x-placeholder'></script>";
12621
+ };
12622
+
12623
+ endTagFunc = function() {
12624
+ return "<script id='" + this.end + "' type='text/x-placeholder'></script>";
12625
+ };
12626
+
12627
+ // If we have the W3C range API, this process is relatively straight forward.
12628
+ if (supportsRange) {
12629
+
12630
+ // Get a range for the current morph. Optionally include the starting and
12631
+ // ending placeholders.
12632
+ rangeFor = function(morph, outerToo) {
12633
+ var range = document.createRange();
12634
+ var before = document.getElementById(morph.start);
12635
+ var after = document.getElementById(morph.end);
12636
+
12637
+ if (outerToo) {
12638
+ range.setStartBefore(before);
12639
+ range.setEndAfter(after);
12640
+ } else {
12641
+ range.setStartAfter(before);
12642
+ range.setEndBefore(after);
12643
+ }
12644
+
12645
+ return range;
12646
+ };
12647
+
12648
+ htmlFunc = function(html, outerToo) {
12649
+ // get a range for the current metamorph object
12650
+ var range = rangeFor(this, outerToo);
12651
+
12652
+ // delete the contents of the range, which will be the
12653
+ // nodes between the starting and ending placeholder.
12654
+ range.deleteContents();
12655
+
12656
+ // create a new document fragment for the HTML
12657
+ var fragment = range.createContextualFragment(html);
12658
+
12659
+ // inser the fragment into the range
12660
+ range.insertNode(fragment);
12661
+ };
12662
+
12663
+ removeFunc = function() {
12664
+ // get a range for the current metamorph object including
12665
+ // the starting and ending placeholders.
12666
+ var range = rangeFor(this, true);
12667
+
12668
+ // delete the entire range.
12669
+ range.deleteContents();
12670
+ };
12671
+
12672
+ appendToFunc = function(node) {
12673
+ var range = document.createRange();
12674
+ range.setStart(node);
12675
+ range.collapse(false);
12676
+ var frag = range.createContextualFragment(this.outerHTML());
12677
+ node.appendChild(frag);
12678
+ };
12679
+ } else {
12680
+ /**
12681
+ * This code is mostly taken from jQuery, with one exception. In jQuery's case, we
12682
+ * have some HTML and we need to figure out how to convert it into some nodes.
12683
+ *
12684
+ * In this case, jQuery needs to scan the HTML looking for an opening tag and use
12685
+ * that as the key for the wrap map. In our case, we know the parent node, and
12686
+ * can use its type as the key for the wrap map.
12687
+ **/
12688
+ var wrapMap = {
12689
+ select: [ 1, "<select multiple='multiple'>", "</select>" ],
12690
+ fieldset: [ 1, "<fieldset>", "</fieldset>" ],
12691
+ table: [ 1, "<table>", "</table>" ],
12692
+ tbody: [ 2, "<table><tbody>", "</tbody></table>" ],
12693
+ tr: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
12694
+ colgroup: [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ],
12695
+ map: [ 1, "<map>", "</map>" ],
12696
+ _default: [ 0, "", "" ]
12697
+ };
12698
+
12699
+ /**
12700
+ * Given a parent node and some HTML, generate a set of nodes. Return the first
12701
+ * node, which will allow us to traverse the rest using nextSibling.
12702
+ *
12703
+ * We need to do this because innerHTML in IE does not really parse the nodes.
12704
+ **/
12705
+ function firstNodeFor(parentNode, html) {
12706
+ var arr = wrapMap[parentNode.tagName.toLowerCase()] || wrapMap._default;
12707
+ var depth = arr[0], start = arr[1], end = arr[2];
12708
+
12709
+ var element = document.createElement('div');
12710
+ element.innerHTML = start + html + end;
12711
+
12712
+ for (var i=0; i<=depth; i++) {
12713
+ element = element.firstChild;
12714
+ }
12715
+
12716
+ return element;
12717
+ }
12718
+
12719
+ /**
12720
+ * Internet Explorer does not allow setting innerHTML if the first element
12721
+ * is a "zero-scope" element. This problem can be worked around by making
12722
+ * the first node an invisible text node. We, like Modernizr, use &shy;
12723
+ **/
12724
+ var startTagFuncWithoutShy = startTagFunc;
12725
+
12726
+ startTagFunc = function() {
12727
+ return "&shy;" + startTagFuncWithoutShy.call(this);
12728
+ }
12729
+
12730
+ /**
12731
+ * In some cases, Internet Explorer can create an anonymous node in
12732
+ * the hierarchy with no tagName. You can create this scenario via:
12733
+ *
12734
+ * div = document.createElement("div");
12735
+ * div.innerHTML = "<table>&shy<script></script><tr><td>hi</td></tr></table>";
12736
+ * div.firstChild.firstChild.tagName //=> ""
12737
+ *
12738
+ * If our script markers are inside such a node, we need to find that
12739
+ * node and use *it* as the marker.
12740
+ **/
12741
+ var realNode = function(start) {
12742
+ while (start.parentNode.tagName == "") {
12743
+ start = start.parentNode;
12744
+ }
12745
+
12746
+ return start;
12747
+ };
12748
+
12749
+ /**
12750
+ * When automatically adding a tbody, Internet Explorer inserts the
12751
+ * tbody immediately before the first <tr>. Other browsers create it
12752
+ * before the first node, no matter what.
12753
+ *
12754
+ * This means the the following code:
12755
+ *
12756
+ * div = document.createElement("div");
12757
+ * div.innerHTML = "<table><script id='first'></script><tr><td>hi</td></tr><script id='last'></script></table>
12758
+ *
12759
+ * Generates the following DOM in IE:
12760
+ *
12761
+ * + div
12762
+ * + table
12763
+ * - script id='first'
12764
+ * + tbody
12765
+ * + tr
12766
+ * + td
12767
+ * - "hi"
12768
+ * - script id='last'
12769
+ *
12770
+ * Which means that the two script tags, even though they were
12771
+ * inserted at the same point in the hierarchy in the original
12772
+ * HTML, now have different parents.
12773
+ *
12774
+ * This code reparents the first script tag by making it the tbody's
12775
+ * first child.
12776
+ **/
12777
+ var fixParentage = function(start, end) {
12778
+ if (start.parentNode !== end.parentNode) {
12779
+ end.parentNode.insertBefore(start, end.parentNode.firstChild);
12780
+ }
12781
+ };
12782
+
12783
+ htmlFunc = function(html, outerToo) {
12784
+ // get the real starting node. see realNode for details.
12785
+ var start = realNode(document.getElementById(this.start));
12786
+ var end = document.getElementById(this.end);
12787
+ var parentNode = end.parentNode;
12788
+ var nextSibling, last;
12789
+
12790
+ // make sure that the start and end nodes share the same
12791
+ // parent. If not, fix it.
12792
+ fixParentage(start, end);
12793
+
12794
+ var node = start;
12795
+ if (!outerToo) { node = node.nextSibling; }
12796
+
12797
+ // remove all of the nodes after the starting placeholder and
12798
+ // before the ending placeholder.
12799
+ while (node) {
12800
+ nextSibling = node.nextSibling;
12801
+ last = node === end;
12802
+
12803
+ // if this is the last node, and we want to remove it as well,
12804
+ // set the `end` node to the next sibling. This is because
12805
+ // for the rest of the function, we insert the new nodes
12806
+ // before the end (note that insertBefore(node, null) is
12807
+ // the same as appendChild(node)).
12808
+ //
12809
+ // if we do not want to remove it, just break.
12810
+ if (last) {
12811
+ if (outerToo) { end = node.nextSibling; } else { break; }
12812
+ }
12813
+
12814
+ node.parentNode.removeChild(node);
12815
+
12816
+ // if this is the last node and we didn't break before
12817
+ // (because we wanted to remove the outer nodes), break
12818
+ // now.
12819
+ if (last) { break; }
12820
+
12821
+ node = nextSibling;
12822
+ }
12823
+
12824
+ // get the first node for the HTML string, even in cases like
12825
+ // tables and lists where a simple innerHTML on a div would
12826
+ // swallow some of the content.
12827
+ node = firstNodeFor(start.parentNode, html);
12828
+
12829
+ // copy the nodes for the HTML between the starting and ending
12830
+ // placeholder.
12831
+ while (node) {
12832
+ nextSibling = node.nextSibling;
12833
+ parentNode.insertBefore(node, end);
12834
+ node = nextSibling;
12835
+ }
12836
+ };
12837
+
12838
+ // remove the nodes in the DOM representing this metamorph.
12839
+ //
12840
+ // this includes the starting and ending placeholders.
12841
+ removeFunc = function() {
12842
+ var start = realNode(document.getElementById(this.start));
12843
+ var end = document.getElementById(this.end);
12844
+
12845
+ this.html('');
12846
+ start.parentNode.removeChild(start);
12847
+ end.parentNode.removeChild(end);
12848
+ };
12849
+
12850
+ appendToFunc = function(parentNode) {
12851
+ var node = firstNodeFor(parentNode, this.outerHTML());
12852
+
12853
+ while (node) {
12854
+ nextSibling = node.nextSibling;
12855
+ parentNode.appendChild(node);
12856
+ node = nextSibling;
12857
+ }
12858
+ };
12859
+ }
12860
+
12861
+ Metamorph.prototype.html = function(html) {
12862
+ this.checkRemoved();
12863
+ if (html === undefined) { return this.innerHTML; }
12864
+
12865
+ htmlFunc.call(this, html);
12866
+
12867
+ this.innerHTML = html;
12868
+ };
12869
+
12870
+ Metamorph.prototype.replaceWith = function(html) {
12871
+ this.checkRemoved();
12872
+ htmlFunc.call(this, html, true);
12873
+ };
12874
+
12875
+ Metamorph.prototype.remove = removeFunc;
12876
+ Metamorph.prototype.outerHTML = outerHTMLFunc;
12877
+ Metamorph.prototype.appendTo = appendToFunc;
12878
+ Metamorph.prototype.startTag = startTagFunc;
12879
+ Metamorph.prototype.endTag = endTagFunc;
12880
+
12881
+ Metamorph.prototype.isRemoved = function() {
12882
+ var before = document.getElementById(this.start);
12883
+ var after = document.getElementById(this.end);
12884
+
12885
+ return !before || !after;
12886
+ };
12887
+
12888
+ Metamorph.prototype.checkRemoved = function() {
12889
+ if (this.isRemoved()) {
12890
+ throw new Error("Cannot perform operations on a Metamorph that is not in the DOM.");
12891
+ }
12892
+ };
12893
+
12894
+ window.Metamorph = Metamorph;
12895
+ })(this);
12896
+
12897
+
12572
12898
  })({});
12573
12899
 
12574
12900
  (function(exports) {
@@ -13032,9 +13358,7 @@ SC.MetamorphView = SC.View.extend({
13032
13358
  var buffer = view.renderToBuffer();
13033
13359
 
13034
13360
  SC.run.schedule('render', this, function() {
13035
- // FIXME: patch metamorph
13036
- morph.html(buffer.string());
13037
- //morph.replaceWith(buffer.string());
13361
+ morph.replaceWith(buffer.string());
13038
13362
  view.transitionTo('inDOM');
13039
13363
  });
13040
13364
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rasputin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-12 00:00:00.000000000Z
12
+ date: 2011-10-13 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
16
- requirement: &70120614679120 !ruby/object:Gem::Requirement
16
+ requirement: &70284196816440 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70120614679120
24
+ version_requirements: *70284196816440
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: actionpack
27
- requirement: &70120614678620 !ruby/object:Gem::Requirement
27
+ requirement: &70284330270580 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.1.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70120614678620
35
+ version_requirements: *70284330270580
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sprockets
38
- requirement: &70120614678160 !ruby/object:Gem::Requirement
38
+ requirement: &70284330547400 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 2.0.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70120614678160
46
+ version_requirements: *70284330547400
47
47
  description: SproutCore 2.0 for the Rails asset pipeline.
48
48
  email:
49
49
  - paul@chavard.net
@@ -64,7 +64,6 @@ files:
64
64
  - lib/rasputin/version.rb
65
65
  - rasputin.gemspec
66
66
  - vendor/assets/javascripts/TransformJS.js
67
- - vendor/assets/javascripts/metamorph.js
68
67
  - vendor/assets/javascripts/sproutcore-datastore.js
69
68
  - vendor/assets/javascripts/sproutcore-i18n.js
70
69
  - vendor/assets/javascripts/sproutcore-routing.js
@@ -1,298 +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
13
- supportsRange = ('createRange' in document);
14
-
15
- // Constructor that supports either Metamorph('foo') or new
16
- // Metamorph('foo');
17
- //
18
- // Takes a string of HTML as the argument.
19
-
20
- var Metamorph = function(html) {
21
- var self;
22
-
23
- if (this instanceof Metamorph) {
24
- self = this;
25
- } else {
26
- self = new K();
27
- }
28
-
29
- self.innerHTML = html;
30
- var myGuid = 'metamorph-'+(guid++);
31
- self.start = myGuid + '-start';
32
- self.end = myGuid + '-end';
33
-
34
- return self;
35
- };
36
-
37
- K.prototype = Metamorph.prototype;
38
-
39
- var rangeFor, htmlFunc, removeFunc, outerHTMLFunc, appendToFunc, startTagFunc, endTagFunc;
40
-
41
- // create the outer HTML for the current metamorph. this function will be
42
- // extended by the Internet Explorer version to work around a bug.
43
- outerHTMLFunc = function() {
44
- return this.startTag() + this.innerHTML + this.endTag();
45
- };
46
-
47
- startTagFunc = function() {
48
- return "<script id='" + this.start + "' type='text/x-placeholder'></script>";
49
- };
50
-
51
- endTagFunc = function() {
52
- return "<script id='" + this.end + "' type='text/x-placeholder'></script>";
53
- };
54
-
55
- // If we have the W3C range API, this process is relatively straight forward.
56
- if (supportsRange) {
57
-
58
- // Get a range for the current morph. Optionally include the starting and
59
- // ending placeholders.
60
- rangeFor = function(morph, outerToo) {
61
- var range = document.createRange();
62
- var before = document.getElementById(morph.start);
63
- var after = document.getElementById(morph.end);
64
-
65
- if (outerToo) {
66
- range.setStartBefore(before);
67
- range.setEndAfter(after);
68
- } else {
69
- range.setStartAfter(before);
70
- range.setEndBefore(after);
71
- }
72
-
73
- return range;
74
- };
75
-
76
- htmlFunc = function(html) {
77
- // get a range for the current metamorph object
78
- var range = rangeFor(this);
79
-
80
- // delete the contents of the range, which will be the
81
- // nodes between the starting and ending placeholder.
82
- range.deleteContents();
83
-
84
- // create a new document fragment for the HTML
85
- var fragment = range.createContextualFragment(html);
86
-
87
- // inser the fragment into the range
88
- range.insertNode(fragment);
89
- };
90
-
91
- removeFunc = function() {
92
- // get a range for the current metamorph object including
93
- // the starting and ending placeholders.
94
- var range = rangeFor(this, true);
95
-
96
- // delete the entire range.
97
- range.deleteContents();
98
- };
99
-
100
- appendToFunc = function(node) {
101
- var range = document.createRange();
102
- range.setStart(node);
103
- range.collapse(false);
104
- var frag = range.createContextualFragment(this.outerHTML());
105
- node.appendChild(frag);
106
- };
107
- } else {
108
- /**
109
- * This code is mostly taken from jQuery, with one exception. In jQuery's case, we
110
- * have some HTML and we need to figure out how to convert it into some nodes.
111
- *
112
- * In this case, jQuery needs to scan the HTML looking for an opening tag and use
113
- * that as the key for the wrap map. In our case, we know the parent node, and
114
- * can use its type as the key for the wrap map.
115
- **/
116
- var wrapMap = {
117
- select: [ 1, "<select multiple='multiple'>", "</select>" ],
118
- fieldset: [ 1, "<fieldset>", "</fieldset>" ],
119
- table: [ 1, "<table>", "</table>" ],
120
- tbody: [ 2, "<table><tbody>", "</tbody></table>" ],
121
- tr: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
122
- colgroup: [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ],
123
- map: [ 1, "<map>", "</map>" ],
124
- _default: [ 0, "", "" ]
125
- };
126
-
127
- /**
128
- * Given a parent node and some HTML, generate a set of nodes. Return the first
129
- * node, which will allow us to traverse the rest using nextSibling.
130
- *
131
- * We need to do this because innerHTML in IE does not really parse the nodes.
132
- **/
133
- var firstNodeFor = function(parentNode, html) {
134
- var arr = wrapMap[parentNode.tagName.toLowerCase()] || wrapMap._default;
135
- var depth = arr[0], start = arr[1], end = arr[2];
136
-
137
- var element = document.createElement('div');
138
- element.innerHTML = start + html + end;
139
-
140
- for (var i=0; i<=depth; i++) {
141
- element = element.firstChild;
142
- }
143
-
144
- return element;
145
- };
146
-
147
- /**
148
- * Internet Explorer does not allow setting innerHTML if the first element
149
- * is a "zero-scope" element. This problem can be worked around by making
150
- * the first node an invisible text node. We, like Modernizr, use &shy;
151
- **/
152
- var startTagFuncWithoutShy = startTagFunc;
153
-
154
- startTagFunc = function() {
155
- return "&shy;" + startTagFuncWithoutShy.call(this);
156
- }
157
-
158
- /**
159
- * In some cases, Internet Explorer can create an anonymous node in
160
- * the hierarchy with no tagName. You can create this scenario via:
161
- *
162
- * div = document.createElement("div");
163
- * div.innerHTML = "<table>&shy<script></script><tr><td>hi</td></tr></table>";
164
- * div.firstChild.firstChild.tagName //=> ""
165
- *
166
- * If our script markers are inside such a node, we need to find that
167
- * node and use *it* as the marker.
168
- **/
169
- var realNode = function(start) {
170
- while (start.parentNode.tagName === "") {
171
- start = start.parentNode;
172
- }
173
-
174
- return start;
175
- };
176
-
177
- /**
178
- * When automatically adding a tbody, Internet Explorer inserts the
179
- * tbody immediately before the first <tr>. Other browsers create it
180
- * before the first node, no matter what.
181
- *
182
- * This means the the following code:
183
- *
184
- * div = document.createElement("div");
185
- * div.innerHTML = "<table><script id='first'></script><tr><td>hi</td></tr><script id='last'></script></table>
186
- *
187
- * Generates the following DOM in IE:
188
- *
189
- * + div
190
- * + table
191
- * - script id='first'
192
- * + tbody
193
- * + tr
194
- * + td
195
- * - "hi"
196
- * - script id='last'
197
- *
198
- * Which means that the two script tags, even though they were
199
- * inserted at the same point in the hierarchy in the original
200
- * HTML, now have different parents.
201
- *
202
- * This code reparents the first script tag by making it the tbody's
203
- * first child.
204
- **/
205
- var fixParentage = function(start, end) {
206
- if (start.parentNode !== end.parentNode) {
207
- end.parentNode.insertBefore(start, end.parentNode.firstChild);
208
- }
209
- };
210
-
211
- htmlFunc = function(html) {
212
- // get the real starting node. see realNode for details.
213
- var start = realNode(document.getElementById(this.start));
214
- var end = document.getElementById(this.end);
215
- var nextSibling;
216
-
217
- // make sure that the start and end nodes share the same
218
- // parent. If not, fix it.
219
- fixParentage(start, end);
220
-
221
- var node;
222
-
223
- // remove all of the nodes after the starting placeholder and
224
- // before the ending placeholder.
225
- node = start.nextSibling;
226
- while (node) {
227
- if (node === end) { break; }
228
- node.parentNode.removeChild(node);
229
- node = start.nextSibling;
230
- }
231
-
232
- // get the first node for the HTML string, even in cases like
233
- // tables and lists where a simple innerHTML on a div would
234
- // swallow some of the content.
235
- node = firstNodeFor(start.parentNode, html);
236
-
237
- // copy the nodes for the HTML between the starting and ending
238
- // placeholder.
239
- while (node) {
240
- nextSibling = node.nextSibling;
241
- end.parentNode.insertBefore(node, end);
242
- node = nextSibling;
243
- }
244
- };
245
-
246
- // remove the nodes in the DOM representing this metamorph.
247
- //
248
- // this includes the starting and ending placeholders.
249
- removeFunc = function() {
250
- var start = realNode(document.getElementById(this.start));
251
- var end = document.getElementById(this.end);
252
-
253
- this.html('');
254
- start.parentNode.removeChild(start);
255
- end.parentNode.removeChild(end);
256
- };
257
-
258
- appendToFunc = function(parentNode) {
259
- var node = firstNodeFor(parentNode, this.outerHTML());
260
-
261
- while (node) {
262
- nextSibling = node.nextSibling;
263
- parentNode.appendChild(node);
264
- node = nextSibling;
265
- }
266
- };
267
- }
268
-
269
- Metamorph.prototype.html = function(html) {
270
- this.checkRemoved();
271
- if (html === undefined) { return this.innerHTML; }
272
-
273
- htmlFunc.call(this, html);
274
-
275
- this.innerHTML = html;
276
- };
277
-
278
- Metamorph.prototype.remove = removeFunc;
279
- Metamorph.prototype.outerHTML = outerHTMLFunc;
280
- Metamorph.prototype.appendTo = appendToFunc;
281
- Metamorph.prototype.startTag = startTagFunc;
282
- Metamorph.prototype.endTag = endTagFunc;
283
-
284
- Metamorph.prototype.isRemoved = function() {
285
- var before = document.getElementById(this.start);
286
- var after = document.getElementById(this.end);
287
-
288
- return !before || !after;
289
- };
290
-
291
- Metamorph.prototype.checkRemoved = function() {
292
- if (this.isRemoved()) {
293
- throw new Error("Cannot perform operations on a Metamorph that is not in the DOM.");
294
- }
295
- };
296
-
297
- window.Metamorph = Metamorph;
298
- })(this);