'modules/documentCanvas/canvas/wlxmlListener',
'modules/documentCanvas/canvas/elementsRegister',
'modules/documentCanvas/canvas/genericElement',
-], function($, _, Backbone, logging, documentElement, keyboard, utils, wlxmlListener, ElementsRegister, genericElement) {
+'modules/documentCanvas/canvas/nullElement',
+], function($, _, Backbone, logging, documentElement, keyboard, utils, wlxmlListener, ElementsRegister, genericElement, nullElement) {
'use strict';
/* global document:false, window:false, Node:false, gettext */
var Canvas = function(wlxmlDocument, elements) {
- this.elementsRegister = new ElementsRegister(documentElement.DocumentNodeElement);
+ this.elementsRegister = new ElementsRegister(documentElement.DocumentNodeElement, nullElement);
elements = [
{tag: 'section', klass: null, prototype: genericElement},
},
contains: function(element) {
- return element.dom.parents().index(this.wrapper) !== -1;
+ return element && element.dom && element.dom.parents().index(this.wrapper) !== -1;
},
triggerSelectionChanged: function() {
} else {
element = e.canvas.createElement(params);
}
- e.dom[action](element.dom);
- e.refreshPath();
+ if(element.dom) {
+ e.dom[action](element.dom);
+ e.refreshPath();
+ }
return element;
};
} else {
element = this.canvas.createElement(params);
}
- this.dom.wrap('<div>');
- this.dom.parent().after(element.dom);
- this.dom.unwrap();
- this.refreshPath();
+ if(element.dom) {
+ this.dom.wrap('<div>');
+ this.dom.parent().after(element.dom);
+ this.dom.unwrap();
+ this.refreshPath();
+ }
return element;
},
before: function(params) {
} else {
element = this.canvas.createElement(params);
}
- this.dom.wrap('<div>');
- this.dom.parent().before(element.dom);
- this.dom.unwrap();
- this.refreshPath();
+ if(element.dom) {
+ this.dom.wrap('<div>');
+ this.dom.parent().before(element.dom);
+ this.dom.unwrap();
+ this.refreshPath();
+ }
return element;
},
wlxml = require('wlxml/wlxml');
-var ElementsRegister = function(BaseType) {
+var ElementsRegister = function(BaseType, NullType) {
this._register = {};
this.BaseType = BaseType;
+ this.NullType = NullType;
};
_.extend(ElementsRegister.prototype, {
},
register: function(params) {
params.klass = params.klass || '';
- params.prototype = params.prototype || Object.create({});
+ params.prototype = params.prototype || this.NullType;
this._register[params.tag] = this._register[params.tag] || {};
this._register[params.tag][params.klass] = this.createCanvasElementType(params.prototype);
.attr('wlxml-tag', this.wlxmlNode.getTagName());
this.setWlxmlClass(this.wlxmlNode.getClass());
this.wlxmlNode.contents().forEach(function(node) {
- this._container().append(this.canvas.createElement(node).dom);
+ var el = this.canvas.createElement(node);
+ if(el.dom) {
+ this._container().append(el.dom);
+ }
}.bind(this));
this.refresh();
},
return;
}
- var nodeIndex = event.meta.node.getIndex(),
+ var ptr = event.meta.node.prev(),
referenceElement, referenceAction, actionArg;
+
+ while(ptr && !(referenceElement = utils.getElementForElementRootNode(ptr))) {
+ ptr = ptr.prev();
+ }
- if(nodeIndex === 0) {
+ if(referenceElement) {
+ referenceAction = 'after';
+ } else {
referenceElement = this;
referenceAction = 'prepend';
- } else {
- referenceElement = this.children()[nodeIndex-1];
- referenceAction = 'after';
}
if(event.meta.move) {
/* Let's check if this node had its own canvas element and it's accessible. */
actionArg = utils.getElementForElementRootNode(event.meta.node);
- if(actionArg && actionArg.sameNode(referenceElement)) {
- referenceElement = this.children()[nodeIndex];
- }
}
if(!actionArg) {
actionArg = event.meta.node;
} else {
element = this.canvas.createElement(param);
}
- this._container().prepend(element.dom);
- this.refreshPath();
+ if(element.dom) {
+ this._container().prepend(element.dom);
+ this.refreshPath();
+ }
return element;
},
--- /dev/null
+define(function(require) {
+
+'use strict';
+var documentElement = require('./documentElement');
+
+
+var NullElement = Object.create(documentElement.DocumentNodeElement.prototype);
+
+NullElement.init = function() {
+ this.dom = null;
+ this.wlxmlNode.setData('canvasElement', undefined);
+};
+
+return NullElement;
+
+});
\ No newline at end of file