define([
'libs/jquery',
'libs/underscore',
+'fnpjs/logging/logging',
'./canvas/canvas',
-'libs/text!./template.html'], function($, _, canvas3, template) {
+'libs/text!./template.html'], function($, _, logging, canvas3, template) {
'use strict';
+
+var logger = logging.getLogger('documentCanvas');
+
return function(sandbox) {
var canvas = canvas3.fromXMLDocument(null);
canvas.setCurrentElement(node);
},
onAfterActionExecuted: function(action, ret) {
+ if(ret && ret instanceof canvas.wlxmlDocument.CaretFragment && ret.isValid()) {
+ logger.debug('The action returned a valid fragment');
+ canvas.setCurrentElement(ret.node, {caretTo: ret.offset});
+ return;
+ }
+ logger.debug('No valid fragment returned from the action');
+
(actionHandlers[action.getPluginName()] || []).forEach(function(handler) {
handler(canvas, action, ret);
});
dialog.on('execute', function(event) {
doc.transaction(function() {
- var span = params.fragment.startNode.parent().wrapText({
+ var span = action.params.fragment.startNode.parent().wrapText({
_with: {tagName: 'span', attrs: {'class': 'link'}},
offsetStart: params.fragment.startOffset,
offsetEnd: params.fragment.endOffset,
textNodeIdx: [params.fragment.startNode.getIndex(), params.fragment.endNode.getIndex()]
- });
+ }),
+ doc = params.fragment.document;
span.setAttr('href', event.formData.href);
event.success();
- return span;
+ return doc.createFragment(doc.CaretFragment, {node: span.contents()[0], offset:0});
}, {
metadata: {
description: action.getState().description
doc.transaction(function() {
link.setAttr('href', event.formData.href);
event.success();
+ return params.fragment;
}, {
metadata: {
description: action.getState().description
listParams.node1 = boundries.node1;
listParams.node2 = boundries.node2;
boundries.node1.document.transaction(function() {
- boundries.node1.document.createList(listParams);
+ var list = boundries.node1.document.createList(listParams),
+ item1 = list.object.getItem(0),
+ text = item1 ? item1.contents()[0] : undefined, //
+ doc = boundries.node1.document;
+
+ return doc.createFragment(doc.CaretFragment, {node: text, offset:0});
}, {
metadata: {
description: action.getState().description
var node = f instanceof f.CaretFragment ? f.node.parent() : f.getCommonParent(),
alreadyInTarget = node.isInside(createParams.to),
- toSwitch = node;
+ toSwitch = node,
+ textNodePath = (f.node || f.startNode).getPath();
if(!toSwitch.is(createParams.from)) {
toSwitch = toSwitch.getParent(createParams.from);
if(!_.isUndefined(createParams.to.klass)) {
toSwitch.setClass(createParams.to.klass);
}
+ return f.document.createFragment(f.CaretFragment, {node: f.document.getNodeByPath(textNodePath), offset: f.offset});
}, {
metadata: {
description: description
};
};
+var headerAction = createSwitchAction({name: 'switchToHeader', from: {tagName: 'div', klass: 'p'}, to: {tagName: 'header', klass: '', name: gettext('header')}}),
+ paragraphAction = createSwitchAction({name: 'switchToParagraph', from: {tagName: 'header'}, to: {tagName: 'div', klass: 'p', name: gettext('paragraf')}});
return {
- actions: [
- createSwitchAction({name: 'switchToHeader', from: {tagName: 'div', klass: 'p'}, to: {tagName: 'header', klass: '', name: gettext('header')}}),
- createSwitchAction({name: 'switchToParagraph', from: {tagName: 'header'}, to: {tagName: 'div', klass: 'p', name: gettext('paragraf')}})
- ]
+ actions: [headerAction, paragraphAction],
+ canvasActionHandler: {
+ handles: [headerAction, paragraphAction],
+ // handle: function(canvas, action, ret) {
+ // var params = {},
+ // f;
+ // if(ret && ret.node2) {
+ // f = ret.oldFragment;
+ // if(f && f instanceof f.CaretFragment) {
+ // params.caretTo = f.offset;
+ // }
+ // canvas.setCurrentElement(ret.node2, params);
+ // }
+ // }
+ }
};
});
\ No newline at end of file