'use strict';
var actions = require('./actions'),
- orderExerciseElement = require('./order/element');
+ gapsActions = require('./gaps/actions'),
+ orderExerciseElement = require('./order/element'),
+ gapsExerciseElement = require('./gaps/element');
return {
- actions: actions,
- canvasElements: [orderExerciseElement]
+ actions: actions.concat(gapsActions),
+ canvasElements: [orderExerciseElement, gapsExerciseElement]
};
});
\ No newline at end of file
--- /dev/null
+define(function(require) {
+
+'use strict';
+
+/* globals gettext */
+
+var _ = require('libs/underscore');
+
+
+var createGap = {
+ name: 'createGap',
+ params: {
+ fragment: {type: 'context', name: 'fragment'}
+ },
+ stateDefaults: {
+ icon: null,
+ label: gettext('Create a gap'),
+ execute: function(callback, params) {
+ var doc = params.fragment.document;
+
+ doc.transaction(function() {
+ var wrapper = params.fragment.startNode.parent().wrapText({
+ _with: {tagName: 'aside', attrs: {'class': 'gap'}},
+ offsetStart: params.fragment.startOffset,
+ offsetEnd: params.fragment.endOffset,
+ textNodeIdx: [params.fragment.startNode.getIndex(), params.fragment.endNode.getIndex()]
+ }),
+ last = _.last(wrapper.contents());
+
+ return doc.createFragment(doc.CaretFragment, {node: last, offset: last.getText().length});
+ }, {
+ metadata: {
+ description: gettext('Create a gap')
+ },
+ success: callback
+ });
+ }
+ },
+ getState: function(params) {
+ return {
+ allowed: params.fragment &&
+ params.fragment.isValid() &&
+ params.fragment instanceof params.fragment.TextRangeFragment &&
+ params.fragment.hasSiblingBoundries() &&
+ params.fragment.startNode.isInside('exercise.gap') &&
+ !params.fragment.startNode.isInside({tagName: 'aside', klass: 'gap'}),
+
+ description: gettext('Turn selection into a gap')
+ };
+ }
+};
+
+var removeGap = {
+ name: 'removeGap',
+ params: {
+ fragment: {type: 'context', name: 'fragment'}
+ },
+ stateDefaults: {
+ icon: null,
+ label: gettext('Remove a gap'),
+ execute: function(callback, params) {
+ var doc = params.fragment.document;
+
+ doc.transaction(function() {
+ var ret = params.fragment.node.getParent('gap').unwrapContent();
+
+ return doc.createFragment(doc.CaretFragment, {node:ret.element2, offset: ret.element2.getText().length});
+ }, {
+ metadata: {
+ description: gettext('Remove a gap')
+ },
+ success: callback
+ });
+ }
+ },
+ getState: function(params) {
+ return {
+ allowed: params.fragment &&
+ params.fragment.isValid() &&
+ params.fragment instanceof params.fragment.NodeFragment &&
+ params.fragment.node.isInside('exercise.gap') &&
+ params.fragment.node.isInside('gap'),
+
+ description: gettext('Remove a gap')
+ };
+ }
+};
+
+
+return [createGap, removeGap];
+
+});
\ No newline at end of file
--- /dev/null
+define(function(require) {
+
+'use strict';
+
+
+var $ = require('libs/jquery'),
+ _ = require('libs/underscore'),
+ documentElement = require('modules/documentCanvas/canvas/documentElement'),
+ viewTemplate = require('libs/text!./view.html');
+
+var OrderExerciceElement = Object.create(documentElement.DocumentNodeElement.prototype);
+_.extend(OrderExerciceElement, {
+ init: function() {
+ documentElement.DocumentNodeElement.prototype.init.call(this);
+ var view = $(_.template(viewTemplate)());
+ this._container().append(view);
+
+ this.createContainer(this.wlxmlNode.contents(), {
+ manages: function() {
+ return true;
+ },
+ dom: view.find('.content')
+ });
+
+ this.addToContextMenu('core.createGap');
+ this.contextMenuActions[0].on('actionExecuted', function(ret) {
+ if(ret instanceof this.wlxmlNode.document.Fragment && ret.isValid()) {
+ this.canvas.select(ret);
+ }
+ }.bind(this));
+ this.addToContextMenu('core.removeGap');
+ },
+ getVerticallyFirstTextElement: function() {
+ // doesnt container handle this?
+ var toret;
+ this.containers.some(function(container) {
+ toret = container.getVerticallyFirstTextElement();
+ return !!toret;
+ });
+ return toret;
+ }
+});
+
+return {tag: 'div', klass: 'exercise.gap', prototype: OrderExerciceElement};
+
+});
+
+
+
+
+
+