diff --git a/elements/x-design-host/x-design-host.html b/elements/x-design-host/x-design-host.html new file mode 100644 index 00000000..f8745133 --- /dev/null +++ b/elements/x-design-host/x-design-host.html @@ -0,0 +1,169 @@ + + + \ No newline at end of file diff --git a/elements/x-designable/x-designable.html b/elements/x-designable/x-designable.html index ce5776a7..5fb13c4b 100644 --- a/elements/x-designable/x-designable.html +++ b/elements/x-designable/x-designable.html @@ -1,4 +1,5 @@ + @@ -29,6 +30,8 @@ ready: function() { this.meta = document.createElement('x-meta'); + this.makeDesignHost(); + this.appendChild(this.designHost); }, // communication @@ -46,6 +49,11 @@ }, // commands + addElement: function(element) { + this.designHost.appendChild(element); + this.decorateElement(element); + }, + deleteElement: function() { var e = this.selected; if (e && e !== this) { @@ -91,7 +99,6 @@ }, update: function() { - this.marshalNodeReferences(this); }, // @@ -166,7 +173,7 @@ s.webkitTransition = null; // designer is absolutely positioned, ad-hoc s.position = 'absolute'; - if (element.parentNode !== this) { + if (element.parentNode !== this.designHost) { s.left = s.top = s.position = ''; } var self = this; @@ -211,7 +218,7 @@ target.removeAttribute(name); } if (path) { - target.bind(name, new PathObserver(this, path)); + target.bind(name, new PathObserver(this.designHost.model, path)); } }, @@ -311,8 +318,11 @@ }, findContainer: function(element, container) { + if (container === this) { + container = this.designHost; + } while (container) { - if (container === this || element !== container && container.meta && container.meta.isContainer) { + if (container === this.designHost || element !== container && container.meta && container.meta.isContainer) { return container; } container = container.parentNode; @@ -338,7 +348,7 @@ // nominal target elt = target; // find top level parent - while (elt && elt.parentNode !== this) { + while (elt && elt.parentNode !== this.designHost) { elt = elt.parentNode; } } @@ -372,51 +382,17 @@ editorElements: {input: 1, select: 1, textarea: 1}, loadHtml: function(html) { - // TODO(sorvell): what should we bind to? for right now, we bind - // to 'this', but we should bind to some element that we're designing... - var template = document.createElement('template'); - template.bindingDelegate = this.syntax; - template.innerHTML = html; - this.sanitizeContent(template.content); this.innerHTML = ''; - // make imports go... - this.loadElementImports(template.content, function() { - this.appendChild(template.createInstance(this)); - executeScriptsInScope(this); - this.meta.ensureMeta(this); - this.update(); + this.makeDesignHost(); + this.designHost.loadHtml(html, function() { + this.appendChild(this.designHost); this.notify(); }.bind(this)); }, - sanitizeContent: function(element) { - // remove imports so that we don't have to keep track of them - var imports = element.querySelectorAll('link[rel=import]').array(); - imports.forEach(function(i) { - i.remove(); - }); - }, - - loadElementImports: function(element, callback) { - var pending = 1; - var receive = function() { - pending--; - checkDone(); - } - var checkDone = function() { - if (pending == 0 && callback) { - callback(); - } - }; - var n$ = element.querySelectorAll('*'); - for (var i=0, l=n$.length, n, m; (i