-define(['libs/jquery-1.9.1.min'], function($) {
+define([
+'libs/jquery-1.9.1.min',
+'libs/underscore-min',
+'modules/documentCanvas/classAttributes'
+], function($, _, classAttributes) {
'use strict';
+
+
var tagSelector = '[wlxml-tag]';
var CanvasNode = function(desc) {
this.dom.attr('wlxml-class', desc.klass);
if(desc.content)
this.dom.text(desc.content);
+ if(desc.meta) {
+ var c = this;
+ _.keys(desc.meta)
+ .filter(function(key) {return classAttributes.hasMetaAttr(c.getClass(), key);})
+ .forEach(function(key) {
+ c.dom.attr('wlxml-meta-'+key, desc.meta[key]);
+ });
+ }
this.dom.attr('id', 'xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}));
}
};
return this.dom.attr('wlxml-class');
};
+CanvasNode.prototype.setClass = function(klass) {
+ if(klass != this.getClass()) {
+ var c = this;
+ this.getMetaAttrs().forEach(function(attr) {
+ if(!classAttributes.hasMetaAttr(klass, attr.name))
+ c.dom.removeAttr('wlxml-meta-' + attr.name);
+ });
+ this.dom.attr('wlxml-class', klass);
+ }
+};
+
CanvasNode.prototype.getId = function() {
return this.dom.attr('id');
};
return this.getClass() && this.getClass().substr(0, klass.length) === klass;
};
+CanvasNode.prototype.getMetaAttr = function(attr) {
+ return this.dom.attr('wlxml-meta-'+attr);
+};
+
+CanvasNode.prototype.getMetaAttrs = function() {
+ var toret = [];
+ var metaAttrPrefix = 'wlxml-meta-';
+
+ var attrList = classAttributes.getMetaAttrsList(this.getClass());
+ var c = this;
+ attrList.all.forEach(function(attr) {
+ toret.push({name: attr.name, value: c.getMetaAttr(attr.name) || ''});
+ });
+
+
+ return toret;
+};
+
+CanvasNode.prototype.setMetaAttr = function(attr, value) {
+ this.dom.attr('wlxml-meta-'+attr, value);
+};
+
return {
create: function(desc) {
return new CanvasNode(desc);