Permalink
Browse files

added check on idom$clone() to prevent use on cloned nodes or directl…

…y on linked nodes (inside another node) as either would be structurally problematic
  • Loading branch information...
1 parent 72d6f5a commit 4fd44a09641dfb3a003fe7823c7a995c8e228469 @idibidiart committed Apr 18, 2012
Showing with 42 additions and 1 deletion.
  1. +42 −1 idom.js
View
43 idom.js
@@ -976,6 +976,47 @@ Element.prototype.idom$ = Element.prototype.idom$ || function() {
Element.prototype.idom$clone = Element.prototype.idom$clone || function() {
+ var fullNid = this.getAttribute("idom-node-id");
+
+ if (fullNid.indexOf('@') != -1) {
+
+ var err = new Error;
+
+ err.message = "this method may only be used on the original non-cloned, non-linked node"
+
+ throw err.message + '\n' + err.stack;
+ }
+
+ if (!idomDOM.initDone) {
+
+ var err = new Error;
+
+ err.message = "you must run idom.init() from window.onload or $(document).ready before invoking .idom$ methods";
+
+ throw err.message + '\n' + err.stack;
+ }
+
+ var nid = this.getAttribute('idom-node-id').replace(new RegExp("([@])(.)+$", "g"), "");
+
+ if (!idomDOM.cache[nid]) {
+
+ // node was added after idom.init()
+ var err = new Error;
+
+ err.message = "node was not cached";
+
+ throw err.message + '\n' + err.stack;
+ }
+
+ if (fullNid.indexOf('@') != -1) {
+
+ var err = new Error;
+
+ err.message = "this method may only be used on the original non-cloned, non-linked node"
+
+ throw err.message + '\n' + err.stack;
+ }
+
if (!arguments.length) {
var err = new Error;
@@ -989,7 +1030,7 @@ Element.prototype.idom$clone = Element.prototype.idom$clone || function() {
var err = new Error;
- err.message = "the node must be populated before it may be cloned"
+ err.message = "the node must be populated before it can be cloned"
throw err.message + '\n' + err.stack;
}

0 comments on commit 4fd44a0

Please sign in to comment.