-define(['libs/jquery-1.9.1.min'], function($) {\r
-\r
-'use strict';\r
-\r
-\r
-var tagSelector = '[wlxml-tag]';\r
-\r
-var CanvasNode = function(desc) {\r
- if(desc instanceof $) {\r
- this.dom = desc;\r
- if(!this.dom.attr('id')) {\r
- 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);}));\r
- }\r
- } else {\r
- var toBlock = ['div', 'document', 'section', 'header'];\r
- var htmlTag = _.contains(toBlock, desc.tag) ? 'div' : 'span';\r
- this.dom = $('<' + htmlTag + '>');\r
- this.dom.attr('wlxml-tag', desc.tag);\r
- if(desc.klass)\r
- this.dom.attr('wlxml-class', desc.klass);\r
- if(desc.content)\r
- this.dom.text(desc.content);\r
- 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);}));\r
- }\r
-};\r
-\r
-CanvasNode.prototype.getTag = function() {\r
- return this.dom.attr('wlxml-tag');\r
-}\r
-\r
-CanvasNode.prototype.getClass = function() {\r
- return this.dom.attr('wlxml-class');\r
-}\r
-\r
-CanvasNode.prototype.getId = function() {\r
- return this.dom.attr('id');\r
-}\r
-\r
-CanvasNode.prototype.getContent = function() {\r
- return this.dom.text();\r
-}\r
-\r
-CanvasNode.prototype.setContent = function(content) {\r
- this.dom.text(content);\r
-}\r
-\r
-CanvasNode.prototype.isSame = function(other) {\r
- return (other instanceof CanvasNode) && this.dom.get(0) === other.dom.get(0);\r
-}\r
-\r
-CanvasNode.prototype.children = function() {\r
- var list = [];\r
- this.dom.children(tagSelector).each(function() {\r
- list.push(new CanvasNode($(this)));\r
- });\r
- return $(list);\r
-};\r
-\r
-\r
-CanvasNode.prototype.parent = function() {\r
- var node = this.dom.parent(tagSelector);\r
- if(node.length)\r
- return new CanvasNode(node);\r
- return null;\r
-};\r
-\r
-CanvasNode.prototype.parents = function() {\r
- var list = [];\r
- this.dom.parents(tagSelector).each(function() {\r
- list.push(new CanvasNode($(this)));\r
- });\r
- return $(list);\r
-};\r
-\r
-\r
-CanvasNode.prototype.isOfClass = function(klass) {\r
- return this.getClass() && this.getClass().substr(0, klass.length) === klass;\r
-}\r
-\r
-return {\r
- create: function(desc) {\r
- return new CanvasNode(desc);\r
- }\r
-\r
-}\r
- \r
-\r
+define(['libs/jquery-1.9.1.min', 'libs/underscore-min'], function($, _) {
+
+'use strict';
+
+
+var tagSelector = '[wlxml-tag]';
+
+var CanvasNode = function(desc) {
+ if(desc instanceof $) {
+ this.dom = desc;
+ if(!this.dom.attr('id')) {
+ 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);}));
+ }
+ } else {
+ var toBlock = ['div', 'document', 'section', 'header'];
+ var htmlTag = _.contains(toBlock, desc.tag) ? 'div' : 'span';
+ this.dom = $('<' + htmlTag + '>');
+ this.dom.attr('wlxml-tag', desc.tag);
+ if(desc.klass)
+ this.dom.attr('wlxml-class', desc.klass);
+ if(desc.content)
+ this.dom.text(desc.content);
+ if(desc.meta) {
+ var c = this;
+ _.keys(desc.meta).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);}));
+ }
+};
+
+CanvasNode.prototype.getTag = function() {
+ return this.dom.attr('wlxml-tag');
+};
+
+CanvasNode.prototype.getClass = function() {
+ return this.dom.attr('wlxml-class');
+};
+
+CanvasNode.prototype.getId = function() {
+ return this.dom.attr('id');
+};
+
+CanvasNode.prototype.getContent = function() {
+ return this.dom.text();
+};
+
+CanvasNode.prototype.setContent = function(content) {
+ this.dom.text(content);
+};
+
+CanvasNode.prototype.isSame = function(other) {
+ return (other instanceof CanvasNode) && this.dom.get(0) === other.dom.get(0);
+};
+
+CanvasNode.prototype.children = function() {
+ var list = [];
+ this.dom.children(tagSelector).each(function() {
+ list.push(new CanvasNode($(this)));
+ });
+ return $(list);
+};
+
+
+CanvasNode.prototype.parent = function() {
+ var node = this.dom.parent(tagSelector);
+ if(node.length)
+ return new CanvasNode(node);
+ return null;
+};
+
+CanvasNode.prototype.parents = function() {
+ var list = [];
+ this.dom.parents(tagSelector).each(function() {
+ list.push(new CanvasNode($(this)));
+ });
+ return $(list);
+};
+
+
+CanvasNode.prototype.isOfClass = function(klass) {
+ 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 attrs = this.dom.get(0).attributes;
+ for(var i = 0; i < attrs.length; i++) {
+ var attr = attrs[i];
+ if(attr.name.substr(0, metaAttrPrefix.length) === metaAttrPrefix) {
+ toret.push({name: attr.name.substr(metaAttrPrefix.length), value: attr.value});
+ }
+ }
+ return toret;
+}
+
+CanvasNode.prototype.setMetaAttr = function(attr, value) {
+ this.dom.attr('wlxml-meta-'+attr, value);
+}
+
+return {
+ create: function(desc) {
+ return new CanvasNode(desc);
+ }
+
+};
+
+