From: Aleksander Ɓukasz Date: Fri, 22 Nov 2013 12:08:01 +0000 (+0100) Subject: integration wip: remove wlxml meta attributes code from documentCanvas module X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/25dc71d387b1ce0d0fbcdc6e24b462c1f1480ce8?hp=bf404a740c73d3aa8df7a44ef47012f33933e624 integration wip: remove wlxml meta attributes code from documentCanvas module --- diff --git a/src/editor/modules/documentCanvas/canvas/documentElement.js b/src/editor/modules/documentCanvas/canvas/documentElement.js index d624112..4951e6c 100644 --- a/src/editor/modules/documentCanvas/canvas/documentElement.js +++ b/src/editor/modules/documentCanvas/canvas/documentElement.js @@ -1,11 +1,10 @@ define([ 'libs/jquery', 'libs/underscore', -'modules/documentCanvas/classAttributes', 'modules/documentCanvas/canvas/utils', 'modules/documentCanvas/canvas/widgets', 'modules/documentCanvas/canvas/wlxmlManagers' -], function($, _, classAttributes, utils, widgets, wlxmlManagers) { +], function($, _, utils, widgets, wlxmlManagers) { 'use strict'; @@ -174,10 +173,6 @@ $.extend(DocumentNodeElement, { element.setWlxml({tag: wlxmlNode.getTagName(), klass: wlxmlNode.getClass()}); - _.keys(wlxmlNode.getMetaAttributes()).forEach(function(key) { - element.setWlxmlMetaAttr(key, params.meta[key]); - }); - wlxmlNode.contents().forEach((function(node) { container.append(DocumentElement.create(node).dom()); }).bind(this)); @@ -335,12 +330,6 @@ $.extend(DocumentNodeElement.prototype, { setWlxmlClass: function(klass) { if(klass === this.getWlxmlClass()) return; - - this.getWlxmlMetaAttrs().forEach(function(attr) { - if(!classAttributes.hasMetaAttr(klass, attr.name)) - this.dom().removeAttr('wlxml-meta-' + attr.name); - }, this); - if(klass) this._container().attr('wlxml-class', klass.replace(/\./g, '-')); else @@ -367,24 +356,6 @@ $.extend(DocumentNodeElement.prototype, { return true; return false; }, - - getWlxmlMetaAttr: function(attr) { - return this.dom().attr('wlxml-meta-'+attr); - }, - - getWlxmlMetaAttrs: function() { - var toret = []; - var attrList = classAttributes.getMetaAttrsList(this.getWlxmlClass()); - attrList.all.forEach(function(attr) { - toret.push({name: attr.name, value: this.getWlxmlMetaAttr(attr.name) || ''}); - }, this); - return toret; - }, - - setWlxmlMetaAttr: function(attr, value) { - this.dom().attr('wlxml-meta-'+attr, value); - }, - toggleLabel: function(toggle) { var displayCss = toggle ? 'inline-block' : 'none'; var label = this.dom().children('.canvas-widgets').find('.canvas-widget-label'); diff --git a/src/editor/modules/documentCanvas/classAttributes.js b/src/editor/modules/documentCanvas/classAttributes.js deleted file mode 100644 index 06c9485..0000000 --- a/src/editor/modules/documentCanvas/classAttributes.js +++ /dev/null @@ -1,64 +0,0 @@ -define([], function() { - -'use strict'; - -var wlxmlDict = { - 'uri': { - 'uri': 'string' - } -}; - -var hasMetaAttr = function(klass, attrName, dict) { - dict = dict || wlxmlDict; - if(!klass) - return false; - - var parts = klass.split('.'); - var partialClass = ''; - for(var i = 0; i < parts.length; i++) { - partialClass += (partialClass === '' ? '' : '.') + parts[i]; - if(dict[partialClass] && dict[partialClass][attrName]) - return true; - } - return false; -}; - -var getMetaAttrsList = function(klass, dict) { - dict = dict || wlxmlDict; - klass = klass || ''; - - var toret = {own: [], inheritedFrom: {}, all: []}; - var parts = klass.split('.'); - var partialClass = ''; - - var generate = function(klass) { - var toret = [], - desc = dict[klass]; - - if(!desc) - return toret; - - _.keys(desc).forEach(function(key) { - toret.push({name: key, type: desc[key]}); - }); - return toret; - }; - - toret.own = generate(klass); - for(var i = 0; i < parts.length; i++) { - partialClass += (partialClass === '' ? '' : '.') + parts[i]; - var list = generate(partialClass); - if(list.length > 0) { - toret.inheritedFrom[partialClass] = generate(partialClass); - toret.all = toret.all.concat(toret.inheritedFrom[partialClass]); - } - } - return toret; -}; - -return { - hasMetaAttr: hasMetaAttr, - getMetaAttrsList: getMetaAttrsList -}; - -}); \ No newline at end of file diff --git a/src/editor/modules/documentCanvas/tests/classAttributes.test.js b/src/editor/modules/documentCanvas/tests/classAttributes.test.js deleted file mode 100644 index 49e0be0..0000000 --- a/src/editor/modules/documentCanvas/tests/classAttributes.test.js +++ /dev/null @@ -1,58 +0,0 @@ -define([ -'libs/chai', -'modules/documentCanvas/classAttributes' -], function(chai, classAttributes) { - -var stubDict = { - 'klass': { - 'prop': 'string' - }, - 'klass.sub1': { - 'prop1': 'string' - }, - 'klass.sub1.sub2': { - 'prop2': 'string' - } -}; - -var assert = chai.assert; - -describe('Class attributes', function() { - it('class has own attribute', function() { - assert.ok(classAttributes.hasMetaAttr('klass.sub1.sub2', 'prop2', stubDict)); - }); - - it('class has attributes from parent classes', function() { - assert.ok(classAttributes.hasMetaAttr('klass.sub1.sub2', 'prop', stubDict)); - assert.ok(classAttributes.hasMetaAttr('klass.sub1.sub2', 'prop1', stubDict)); - }); - - it('list of class meta attributes', function() { - var attrList = classAttributes.getMetaAttrsList('klass.sub1.sub2', stubDict); - - assert.deepEqual(attrList.own, [{name: 'prop2', type: 'string'}]); - assert.deepEqual(attrList.inheritedFrom['klass.sub1'], [{name: 'prop1', type: 'string'}]); - assert.deepEqual(attrList.inheritedFrom.klass, [{name: 'prop', type: 'string'}]); - assert.deepEqual(attrList.all.sort(), [ - {name: 'prop', type: 'string'}, - {name: 'prop1', type: 'string'}, - {name: 'prop2', type: 'string'} - ].sort(), 'all values'); - }); - - it('class without meta attrs', function() { - var attrList = classAttributes.getMetaAttrsList('some.class', {}); - assert.deepEqual(attrList.own, [], 'empty own list'); - assert.deepEqual(attrList.inheritedFrom, {}, 'empty inherited dict'); - assert.deepEqual(attrList.all, [], 'empty all list'); - }); - - it('empty class', function() { - var attrList = classAttributes.getMetaAttrsList('', {}); - assert.deepEqual(attrList.own, [], 'empty own list'); - assert.deepEqual(attrList.inheritedFrom, {}, 'empty inherited dict'); - assert.deepEqual(attrList.all, [], 'empty all list'); - }); -}); - -}); \ No newline at end of file