1 define(['libs/jquery-1.9.1.min'], function($) {
\r
5 var CanvasNode = function(desc) {
\r
6 if(desc instanceof $) {
\r
8 if(!this.dom.attr('id')) {
\r
9 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
12 var toBlock = ['div', 'document', 'section', 'header'];
\r
13 var htmlTag = _.contains(toBlock, desc.tag) ? 'div' : 'span';
\r
14 this.dom = $('<' + htmlTag + '>');
\r
15 this.dom.attr('wlxml-tag', desc.tag);
\r
17 this.dom.attr('wlxml-class', desc.klass);
\r
19 this.dom.text(desc.content);
\r
20 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
24 CanvasNode.prototype.getTag = function() {
\r
25 return this.dom.attr('wlxml-tag');
\r
28 CanvasNode.prototype.getClass = function() {
\r
29 return this.dom.attr('wlxml-class');
\r
32 CanvasNode.prototype.getId = function() {
\r
33 return this.dom.attr('id');
\r
36 CanvasNode.prototype.getContent = function() {
\r
37 return this.dom.text();
\r
40 CanvasNode.prototype.setContent = function(content) {
\r
41 this.dom.text(content);
\r
44 CanvasNode.prototype.isSame = function(other) {
\r
45 return this.dom.get(0).isSameNode(other.dom.get(0));
\r
49 create: function(desc) {
\r
50 return new CanvasNode(desc);
\r