From 5ca01bb0de5f40942caa94602a7271517543ace9 Mon Sep 17 00:00:00 2001 From: Borys Levytskyi Date: Thu, 2 Apr 2015 23:14:54 +0300 Subject: [PATCH] fixed html builder component --- .idea/workspace.xml | 148 ++++++++++++++------------------------------ components/html.js | 17 ++++- index.html | 4 +- 3 files changed, 61 insertions(+), 108 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index aa0c690..6525ba5 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -26,7 +26,7 @@ - + @@ -36,7 +36,7 @@ - + @@ -53,21 +53,21 @@ - + - - + + - + - - + + @@ -76,7 +76,7 @@ - + @@ -86,15 +86,9 @@ - + - - - - - - - + @@ -102,7 +96,7 @@ - + @@ -112,7 +106,7 @@ - + @@ -171,9 +165,9 @@ @@ -228,7 +222,6 @@ - @@ -289,26 +282,9 @@ - - - - - - - - - - + @@ -329,6 +305,14 @@ + + - - @@ -456,13 +432,7 @@ - - - - - - - + @@ -478,7 +448,6 @@ - @@ -509,13 +478,7 @@ - - - - - - - + @@ -531,7 +494,6 @@ - @@ -563,13 +525,7 @@ - - - - - - - + @@ -585,7 +541,6 @@ - @@ -625,7 +580,6 @@ - @@ -665,7 +619,6 @@ - @@ -705,7 +658,6 @@ - @@ -737,7 +689,6 @@ - @@ -768,7 +719,6 @@ - @@ -800,13 +750,7 @@ - - - - - - - + @@ -826,14 +770,6 @@ - - - - - - - - @@ -852,8 +788,16 @@ - - + + + + + + + + + + diff --git a/components/html.js b/components/html.js index 5d409cf..bf39d24 100644 --- a/components/html.js +++ b/components/html.js @@ -4,9 +4,20 @@ this.sb = []; } - HtmlBuilder.prototype.element = function(tagName, arg) { - var attrs = typeof arg == "object" ? arg : { html: arg}, - elementContent = attrs.html || ''; + HtmlBuilder.prototype.element = function(tagName, arg1, arg2) { + var attrs, elementContent; + + if(typeof arg1 == "object") { + attrs = arg1; + } + else if(typeof arg1 == "string") { + attrs = { html: arg1 }; + } + else { + attrs = {}; + } + + elementContent = attrs.html || arg2; this.sb.push('<' + tagName + ' ' + getAttributesStr(attrs) + ">"); diff --git a/index.html b/index.html index 3924c08..12bd57d 100644 --- a/index.html +++ b/index.html @@ -52,10 +52,9 @@ var view = new window.app.views.ExpressionView(expr); var hb = app.service('html').builder(); - hb.element('div', { class: 'result'}, view.getHtml()); + hb.element('div', { class: 'result', html: view.getHtml() }); outputDiv.appendChild(hb.toHtmlElement()); - cmdArgs.commandHandled = true; }); @@ -75,7 +74,6 @@ }}); - outputDiv.appendChild(hb.toHtmlElement()); cmdArgs.commandHandled = true; });