6 var footnoteExecute = {
7 selecting: function(params) {
8 var parent = params.fragment.startNode.parent();
9 return parent.wrapText({
10 _with: {tagName: 'aside', attrs: {'class': 'footnote'}},
11 offsetStart: params.fragment.startOffset,
12 offsetEnd: params.fragment.endOffset,
13 textNodeIdx: [params.fragment.startNode.getIndex(), params.fragment.endNode.getIndex()]
16 afterCursor: function(params) {
17 var node = params.fragment.node,
19 node.document.transaction(function() {
20 asideNode = node.divideWithElementNode({tagName: 'aside', attrs:{'class': 'footnote'}}, {offset: params.fragment.offset});
21 asideNode.append({text: ''});
25 afterNode: function(params) {
26 var node = params.fragment.node,
28 node.document.transaction(function() {
29 asideNode = node.after({tagName: 'aside', attrs:{'class': 'footnote'}}, {offset: params.fragment.offset});
30 asideNode.append({text: ''});
36 var footnoteAction = {
39 fragment: {type: 'context', name: 'fragment'}
44 getState: function(params) {
45 if(!params.fragment || !params.fragment.isValid()) {
46 return {allowed: false};
48 if(params.fragment instanceof params.fragment.TextRangeFragment && params.fragment.hasSiblingBoundaries()) {
51 description: gettext('Create footnote from selection'),
52 execute: footnoteExecute.selecting
55 if(params.fragment instanceof params.fragment.CaretFragment) {
58 description: gettext('Insert footnote after cursor'),
59 execute: footnoteExecute.afterCursor
62 if(params.fragment instanceof params.fragment.NodeFragment) {
63 if(params.fragment.node.isRoot()) {
66 description: gettext('Cannot insert footnote after root node')
71 description: gettext('Insert footnote after node'),
72 execute: footnoteExecute.afterNode
81 actions: [footnoteAction],