+ getDocumentElement: function(htmlElement) {
+ /* globals HTMLElement, Text */
+ if(!htmlElement || !(htmlElement instanceof HTMLElement || htmlElement instanceof Text)) {
+ return null;
+ }
+ var $element = $(htmlElement);
+ if(htmlElement.nodeType === Node.ELEMENT_NODE && $element.attr('document-node-element') !== undefined) {
+ return $element.data('canvas-element');
+ }
+
+ if(htmlElement.nodeType === Node.TEXT_NODE && $element.parent().attr('document-text-element') !== undefined) {
+ $element = $element.parent();
+ }
+
+ if($element.attr('document-text-element') !== undefined || (htmlElement.nodeType === Node.TEXT_NODE && $element.parent().attr('document-text-element') !== undefined)) {
+ //return DocumentTextElement.fromHTMLElement(htmlElement, canvas);
+ return $element.data('canvas-element');
+ }
+
+ /* experimental */
+ if($element.parent().data('canvas-element')) {
+ return $element.parent().data('canvas-element');
+ }
+ },
+
+ reloadRoot: function() {
+ if(this.rootElement) {
+ this.rootElement.detach();
+ }
+ this.rootElement = this.createElement(this.wlxmlDocument.root);
+ this.rootWrapper.append(this.rootElement.dom);
+ },
+
+ triggerKeyEvent: function(keyEvent, selection) {
+ selection = selection || this.getSelection();
+ if(selection && (
+ (selection.type === 'caret' || selection.type === 'textSelection') && selection.toDocumentFragment().isValid()
+ || selection.type == 'nodeSelection')) {
+ keyboard.handleKeyEvent(keyEvent, selection);
+ }
+ },
+
+ createAction: function(fqName, config) {
+ return this.sandbox.createAction(fqName, config);
+ },
+
+ setupEventHandling: function() {
+ var canvas = this;
+
+ /* globals document */
+ $(document.body).on('keydown', function(e) {
+ canvas.triggerKeyEvent(keyEvent.fromNativeEvent(e));
+ });
+
+ this.rootWrapper.on('mouseup', function() {
+ canvas.triggerSelectionChanged();
+ });
+
+ var mouseDown;
+ this.rootWrapper.on('mousedown', '[document-node-element], [document-text-element]', function(e) {
+ mouseDown = e.target;
+ canvas.rootWrapper.find('[contenteditable]').attr('contenteditable', null);
+ });