diff --git a/src/demo.js b/src/demo.js index b5610a1df..a6460f8cb 100644 --- a/src/demo.js +++ b/src/demo.js @@ -10,7 +10,7 @@ require(['config/require-config'], function() { container : '#gjs', height: '100%', //fromElement: true, - + /* components: [{ type: 'text', style:{ @@ -32,7 +32,8 @@ require(['config/require-config'], function() { type: 'textnode', content: " More text node --- ", }], - }], + }],*/ + components: '
a b b ic
ABC
i u test
', storageManager:{ autoload: 0, diff --git a/src/dom_components/model/ComponentImage.js b/src/dom_components/model/ComponentImage.js index b5ac60eec..faf3bb139 100644 --- a/src/dom_components/model/ComponentImage.js +++ b/src/dom_components/model/ComponentImage.js @@ -67,10 +67,7 @@ define(['./Component'], isComponent: function(el) { var result = ''; if(el.tagName == 'IMG'){ - result = { - type: 'image', - src: el.src - }; + result = {type: 'image'}; } return result; }, diff --git a/src/dom_components/model/Components.js b/src/dom_components/model/Components.js index 140d25ea0..a12ef5961 100644 --- a/src/dom_components/model/Components.js +++ b/src/dom_components/model/Components.js @@ -51,8 +51,6 @@ define([ 'backbone', 'require'], if(parsed.css && cssc){ var added = cssc.addCollection(parsed.css); } - - console.log('Parsed from add', models); } return Backbone.Collection.prototype.add.apply(this, [models, opt]); diff --git a/src/parser/model/ParserHtml.js b/src/parser/model/ParserHtml.js index 9efa7f66f..9caf6698d 100644 --- a/src/parser/model/ParserHtml.js +++ b/src/parser/model/ParserHtml.js @@ -68,8 +68,8 @@ define(function(require) { var attrsLen = attrs.length; var prevI = result.length - 1; var prevSib = result[prevI]; - var ct = this.compTypes; + if(ct){ var obj = ''; for (var cType in ct) { @@ -125,7 +125,13 @@ define(function(require) { } } - var prevIsText = prevSib && prevSib.type == 'text' && prevSib.tagName == TEXT_NODE; + var prevIsText = prevSib && prevSib.type == 'textnode'; + if(model.type == 'textnode'){ + if(prevIsText){ + prevSib.content += model.content; + continue; + } + } // Find text nodes /* if(model.type == 'textnode'){ @@ -156,6 +162,24 @@ define(function(require) { } }*/ + // If all components are texts and textnodes the parent should be text too + // otherwise I'm unable to edit texts + var comps = model.components; + if(!model.type && comps){ + var allTxt = 1; + for(var ci = 0; ci < comps.length; ci++){ + var comp = comps[ci]; + if(comp.type != 'text' && + comp.type != 'textnode' && + c.textTags.indexOf(comp.tagName) < 0 ){ + allTxt = 0; + break; + } + } + if(allTxt) + model.type = 'text'; + } + // If tagName is still empty and is not a textnode, do not push it if(!model.tagName && model.type != 'textnode') continue; diff --git a/test/specs/asset_manager/main.js b/test/specs/asset_manager/main.js index e4b42c2c5..573708589 100644 --- a/test/specs/asset_manager/main.js +++ b/test/specs/asset_manager/main.js @@ -139,4 +139,4 @@ define(['StorageManager','AssetManager', AssetsView.run(); FileUploader.run(); }); -}); \ No newline at end of file +}); diff --git a/test/specs/parser/model/ParserHtml.js b/test/specs/parser/model/ParserHtml.js index 4a8b647ac..52e692c4e 100644 --- a/test/specs/parser/model/ParserHtml.js +++ b/test/specs/parser/model/ParserHtml.js @@ -1,17 +1,19 @@ var path = 'Parser/'; -define([path + 'model/ParserHtml', path + 'model/ParserCss'], - function(ParserHtml, ParserCss) { +define([path + 'model/ParserHtml', path + 'model/ParserCss', 'DomComponents'], + function(ParserHtml, ParserCss, DomComponents) { return { run : function(){ - describe('ParserHtml', function() { + describe.only('ParserHtml', function() { var obj; beforeEach(function () { + var dom = new DomComponents(); obj = new ParserHtml({ textTags: ['br', 'b', 'i', 'u'], }); + obj.compTypes = dom.componentTypes; }); afterEach(function () { @@ -89,8 +91,10 @@ define([path + 'model/ParserHtml', path + 'model/ParserCss'], var result = { tagName: 'img', type: 'image', - src: './index.html', - attributes: { id: 'test1'}, + attributes: { + id: 'test1', + src: './index.html', + }, }; obj.parse(str).html.should.deep.equal(result); }); @@ -112,7 +116,44 @@ define([path + 'model/ParserHtml', path + 'model/ParserCss'], tagName: 'div', attributes: { id: 'test1'}, type: 'text', - content: '
test2
a b b i u test ', + components: [ + {tagName: 'br'}, + { + content: ' test2 ', + type: 'textnode', + tagName: '' + }, + {tagName: 'br'}, + { + content: ' a b ', + type: 'textnode', + tagName: '' + },{ + content: 'b', + type: 'text', + tagName: 'b' + },{ + content: ' ', + type: 'textnode', + tagName: '' + },{ + content: 'i', + tagName: 'i', + type: 'text' + },{ + content: ' ', + type: 'textnode', + tagName: '' + },{ + content: 'u', + tagName: 'u', + type: 'text' + },{ + content: ' test ', + type: 'textnode', + tagName: '' + } + ], }; obj.parse(str).html.should.deep.equal(result); }); @@ -253,4 +294,4 @@ define([path + 'model/ParserHtml', path + 'model/ParserCss'], } }; -}); \ No newline at end of file +});