1 define(['libs/jquery-1.9.1.min'], function($) {
\r
6 var tagSelector = '[wlxml-tag]';
\r
8 var CanvasNode = function(desc) {
\r
9 if(desc instanceof $) {
\r
11 if(!this.dom.attr('id')) {
\r
12 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
15 var toBlock = ['div', 'document', 'section', 'header'];
\r
16 var htmlTag = _.contains(toBlock, desc.tag) ? 'div' : 'span';
\r
17 this.dom = $('<' + htmlTag + '>');
\r
18 this.dom.attr('wlxml-tag', desc.tag);
\r
20 this.dom.attr('wlxml-class', desc.klass);
\r
22 this.dom.text(desc.content);
\r
23 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
27 CanvasNode.prototype.getTag = function() {
\r
28 return this.dom.attr('wlxml-tag');
\r
31 CanvasNode.prototype.getClass = function() {
\r
32 return this.dom.attr('wlxml-class');
\r
35 CanvasNode.prototype.getId = function() {
\r
36 return this.dom.attr('id');
\r
39 CanvasNode.prototype.getContent = function() {
\r
40 return this.dom.text();
\r
43 CanvasNode.prototype.setContent = function(content) {
\r
44 this.dom.text(content);
\r
47 CanvasNode.prototype.isSame = function(other) {
\r
48 return (other instanceof CanvasNode) && this.dom.get(0).isSameNode(other.dom.get(0));
\r
51 CanvasNode.prototype.children = function() {
\r
53 this.dom.children(tagSelector).each(function() {
\r
54 list.push(new CanvasNode($(this)));
\r
60 CanvasNode.prototype.parent = function() {
\r
61 var node = this.dom.parent(tagSelector);
\r
63 return new CanvasNode(node);
\r
67 CanvasNode.prototype.parents = function() {
\r
69 this.dom.parents(tagSelector).each(function() {
\r
70 list.push(new CanvasNode($(this)));
\r
77 create: function(desc) {
\r
78 return new CanvasNode(desc);
\r