fnp
/
fnpeditor.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
45c37b7
)
editor: canvas - context menu support
author
Aleksander Łukasz
<aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 1 Jul 2014 13:53:49 +0000
(15:53 +0200)
committer
Aleksander Łukasz
<aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 14 Aug 2014 14:26:13 +0000
(16:26 +0200)
src/editor/modules/documentCanvas/canvas/canvas.js
patch
|
blob
|
history
src/editor/modules/documentCanvas/canvas/documentElement.js
patch
|
blob
|
history
src/editor/modules/documentCanvas/documentCanvas.js
patch
|
blob
|
history
diff --git
a/src/editor/modules/documentCanvas/canvas/canvas.js
b/src/editor/modules/documentCanvas/canvas/canvas.js
index
0259452
..
d3376e3
100644
(file)
--- a/
src/editor/modules/documentCanvas/canvas/canvas.js
+++ b/
src/editor/modules/documentCanvas/canvas/canvas.js
@@
-3,6
+3,7
@@
define([
'libs/underscore',
'libs/backbone',
'fnpjs/logging/logging',
'libs/underscore',
'libs/backbone',
'fnpjs/logging/logging',
+'views/menu/menu',
'modules/documentCanvas/canvas/documentElement',
'modules/documentCanvas/canvas/keyboard',
'modules/documentCanvas/canvas/utils',
'modules/documentCanvas/canvas/documentElement',
'modules/documentCanvas/canvas/keyboard',
'modules/documentCanvas/canvas/utils',
@@
-14,8
+15,8
@@
define([
'modules/documentCanvas/canvas/selection',
'modules/documentCanvas/canvas/keyEvent',
'libs/text!./canvas.html'
'modules/documentCanvas/canvas/selection',
'modules/documentCanvas/canvas/keyEvent',
'libs/text!./canvas.html'
-], function($, _, Backbone, logging, documentElement, keyboard, utils, wlxmlListener, ElementsRegister, genericElement, nullElement, gutter, selection, keyEvent, canvasTemplate) {
-
+], function($, _, Backbone, logging,
Menu,
documentElement, keyboard, utils, wlxmlListener, ElementsRegister, genericElement, nullElement, gutter, selection, keyEvent, canvasTemplate) {
+
'use strict';
/* global document:false, window:false, Node:false, gettext */
'use strict';
/* global document:false, window:false, Node:false, gettext */
@@
-62,8
+63,9
@@
$.extend(TextHandler.prototype, {
});
});
-var Canvas = function(wlxmlDocument, elements, metadata) {
+var Canvas = function(wlxmlDocument, elements, metadata
, sandbox
) {
this.metadata = metadata || {};
this.metadata = metadata || {};
+ this.sandbox = sandbox;
this.elementsRegister = new ElementsRegister(documentElement.DocumentNodeElement, nullElement);
elements = [
this.elementsRegister = new ElementsRegister(documentElement.DocumentNodeElement, nullElement);
elements = [
@@
-147,7
+149,6
@@
$.extend(Canvas.prototype, Backbone.Events, {
this.rootWrapper.append(this.rootElement.dom);
},
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()) {
triggerKeyEvent: function(keyEvent, selection) {
selection = selection || this.getSelection();
if(selection && (selection.type === 'caret' || selection.type === 'textSelection') && selection.toDocumentFragment().isValid()) {
@@
-155,6
+156,10
@@
$.extend(Canvas.prototype, Backbone.Events, {
}
},
}
},
+ createAction: function(fqName, config) {
+ return this.sandbox.createAction(fqName, config);
+ },
+
setupEventHandling: function() {
var canvas = this;
setupEventHandling: function() {
var canvas = this;
@@
-196,6
+201,17
@@
$.extend(Canvas.prototype, Backbone.Events, {
}
});
}
});
+ this.rootWrapper.on('contextmenu', function(e) {
+ var el = canvas.getDocumentElement(e.target);
+
+ if(!el) {
+ return;
+ }
+
+ e.preventDefault();
+ this.showContextMenu(el, {x: e.clientX, y: e.clientY});
+ }.bind(this));
+
this.rootWrapper.on('paste', function(e) {
e.preventDefault();
this.rootWrapper.on('paste', function(e) {
e.preventDefault();
@@
-454,6
+470,18
@@
$.extend(Canvas.prototype, Backbone.Events, {
if(position.element) {
this._moveCaretToTextElement(position.element, position.offset);
}
if(position.element) {
this._moveCaretToTextElement(position.element, position.offset);
}
+ },
+ showContextMenu: function(element, coors) {
+ var menu = new Menu();
+
+ while(element) {
+ (element.contextMenuActions || []).forEach(menu.addAction.bind(menu));
+ element = element.parent();
+ }
+ if(menu.actions.length) {
+ menu.updateContextParam('fragment', this.getSelection().toDocumentFragment());
+ this.sandbox.showContextMenu(menu, {x: coors.x, y: coors.y});
+ }
}
});
}
});
@@
-585,8
+613,8
@@
$.extend(Cursor.prototype, {
});
return {
});
return {
- fromXMLDocument: function(wlxmlDocument, elements, metadata) {
- return new Canvas(wlxmlDocument, elements, metadata);
+ fromXMLDocument: function(wlxmlDocument, elements, metadata
, sandbox
) {
+ return new Canvas(wlxmlDocument, elements, metadata
, sandbox
);
}
};
}
};
diff --git
a/src/editor/modules/documentCanvas/canvas/documentElement.js
b/src/editor/modules/documentCanvas/canvas/documentElement.js
index
859a80b
..
adeaafe
100644
(file)
--- a/
src/editor/modules/documentCanvas/canvas/documentElement.js
+++ b/
src/editor/modules/documentCanvas/canvas/documentElement.js
@@
-95,6
+95,7
@@
$.extend(DocumentElement.prototype, {
var DocumentNodeElement = function(wlxmlNode, canvas) {
DocumentElement.call(this, wlxmlNode, canvas);
this.containers = [];
var DocumentNodeElement = function(wlxmlNode, canvas) {
DocumentElement.call(this, wlxmlNode, canvas);
this.containers = [];
+ this.contextMenuActions = [];
this.init(this.dom);
};
this.init(this.dom);
};
@@
-146,6
+147,9
@@
$.extend(DocumentNodeElement.prototype, {
this.containers.splice(idx, 1);
}
},
this.containers.splice(idx, 1);
}
},
+ addToContextMenu: function(actionFqName) {
+ this.contextMenuActions.push(this.canvas.createAction(actionFqName));
+ },
handle: function(event) {
var method = 'on' + event.type[0].toUpperCase() + event.type.substr(1),
target;
handle: function(event) {
var method = 'on' + event.type[0].toUpperCase() + event.type.substr(1),
target;
diff --git
a/src/editor/modules/documentCanvas/documentCanvas.js
b/src/editor/modules/documentCanvas/documentCanvas.js
index
a98fdb4
..
a440bb9
100644
(file)
--- a/
src/editor/modules/documentCanvas/documentCanvas.js
+++ b/
src/editor/modules/documentCanvas/documentCanvas.js
@@
-22,7
+22,7
@@
return function(sandbox) {
var canvas = canvas3.fromXMLDocument(null, canvasElements, {
user: sandbox.getConfig().user
var canvas = canvas3.fromXMLDocument(null, canvasElements, {
user: sandbox.getConfig().user
- });
+ }
, sandbox
);
var canvasWrapper = $(template);
var shownAlready = false;
var scrollbarPosition = 0,
var canvasWrapper = $(template);
var shownAlready = false;
var scrollbarPosition = 0,