From: Aleksander Ɓukasz Date: Tue, 9 Jul 2013 10:32:24 +0000 (+0200) Subject: DocumentNodeElement wlxml class getting/setting X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/9c5db1c241bd7d0ff38354790dd9fbd43549cd4d?ds=sidebyside DocumentNodeElement wlxml class getting/setting --- diff --git a/modules/documentCanvas/canvas/canvas.test3.js b/modules/documentCanvas/canvas/canvas.test3.js index 253a97c..3c25cf5 100644 --- a/modules/documentCanvas/canvas/canvas.test3.js +++ b/modules/documentCanvas/canvas/canvas.test3.js @@ -46,7 +46,18 @@ describe('Canvas', function() { expect(c.doc().wlxmlTag).to.equal('section'); }); - describe('DocumentElement', function() { + describe('DocumentTextElement', function() { + it('can have its content set', function() { + var c = canvas.fromXML('
Alice
'), + root = c.doc(), + text = root.children()[0]; + + text.setText('a cat'); + expect(root.children()[0].getText()).to.equal('a cat'); + }); + }); + + describe('DocumentNodeElement', function() { it('knows index of its child', function() { var c = canvas.fromXML('
'), root = c.doc(), @@ -54,17 +65,26 @@ describe('Canvas', function() { expect(root.childIndex(child)).to.equal(1); }); - describe('DocumentTextElement can have its content set', function() { - var c = canvas.fromXML('
Alice
'), - root = c.doc(), - text = root.children()[0]; - - text.setText('a cat'); - expect(root.children()[0].getText()).to.equal('a cat'); + it('knows WLXML tag it renders', function(){ + var c = canvas.fromXML('
'), + section = c.doc(); + expect(section.getWlxmlTag()).to.equal('section', 'initial tag is section'); + section.setWlxmlTag('header'); + expect(section.getWlxmlTag()).to.equal('header', 'tag is changed to header'); + }); + + it('knows WLXML class of a WLXML tag it renders', function(){ + var c = canvas.fromXML('
'), + section = c.doc(); + expect(section.getWlxmlClass()).to.equal('some.class'); + section.setWlxmlClass('some.other.class'); + expect(section.getWlxmlClass()).to.equal('some.other.class'); }); }); }); + + describe('document representation api', function() { describe('document root element', function() { var c = canvas.fromXML('
'); diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index 0d08aab..e18f856 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -105,8 +105,17 @@ $.extend(DocumentNodeElement.prototype, { after: function(params) { manipulate(this, params, 'after'); }, + getWlxmlTag: function() { + return this.$element.attr('wlxml-tag'); + }, + setWlxmlTag: function(tag) { + this.$element.attr('wlxml-tag', tag); + }, + getWlxmlClass: function() { + return this.$element.attr('wlxml-class').replace('-', '.'); + }, setWlxmlClass: function(klass) { - this.$element.attr('class', klass); + this.$element.attr('wlxml-class', klass); }, is: function(what) { if(what === 'list' && _.contains(['list-items', 'list-items-enum'], this.$element.attr('wlxml-class')))