1 define(function(require) {
5 var $ = require('libs/jquery'),
6 _ = require('libs/underscore'),
7 documentElement = require('./documentElement'),
8 CommentsView = require('./comments/comments');
11 var DocumentNodeElement = documentElement.DocumentNodeElement;
13 var generic = Object.create(DocumentNodeElement.prototype);
17 DocumentNodeElement.prototype.init.call(this);
19 .attr('wlxml-tag', this.wlxmlNode.getTagName())
20 .attr('wlxml-class', this.wlxmlNode.getClass().replace(/\./g, '-'));
22 this.container = this.createContainer(this.wlxmlNode.contents(), {
23 manages: function(node) { return !node.isInside('comment'); },
24 dom: this._container()
27 this.commentsView = new CommentsView(this.wlxmlNode, this.canvas.metadata.user);
28 this.addToGutter(this.commentsView);
29 this.commentTip = $('<div class="comment-tip"><i class="icon-comment"></i></div>');
30 this.addWidget(this.commentTip);
32 if(!this.wlxmlNode.hasChild({klass: 'comment'})) {
33 this.commentTip.hide();
40 if(this.wlxmlNode.getTagName() === 'span' || this.wlxmlNode.getTagName() === 'aside') {
41 if(this.containsBlock()) {
42 this.displayAsBlock();
47 this.displayAsBlock();
51 getFirst: function(e1, e2) {
52 return this.container.getFirst(e1, e2);
55 containsBlock: function() {
56 return this.container.containsBlock();
59 children: function() {
60 return this.container.children();
63 getVerticallyFirstTextElement: function(params) {
64 return this.container.getVerticallyFirstTextElement(params);
67 onNodeAdded: function(event) {
68 if(event.meta.node.is('comment')) {
69 this.commentTip.show();
70 this.commentsView.render();
74 onNodeDetached: function(event) {
75 var isComment = event.meta.node.is('comment');
76 if(event.meta.node.sameNode(this)) {
77 // defacto jestesmy rootem?
80 if(isComment && !this.wlxmlNode.hasChild({klass: 'comment'})) {
81 this.commentTip.hide();
83 this.commentsView.render();
87 onNodeTextChange: function(event) {
88 var node = event.meta.node;
90 /* TODO: This handling of changes to the comments should probably be implemented via separate,
91 non-rendering comments element */
92 if(node.parent() && node.parent().is('comment') && this.wlxmlNode.sameNode(node.parent().parent())) {
93 this.commentsView.render();
97 onStateChange: function(changes) {
98 var isSpan = this.wlxmlNode.getTagName() === 'span';
99 if(_.isBoolean(changes.exposed) && !isSpan) {
100 this._container().toggleClass('highlighted-element', changes.exposed);
102 if(_.isBoolean(changes.active) && !isSpan) {
103 this._container().toggleClass('current-node-element', changes.active);