1 define(function(require) {
6 var $ = require('libs/jquery'),
7 _ = require('libs/underscore'),
8 elementBase = require('plugins/core/edumed/elementBase'),
9 genericElement = require('modules/documentCanvas/canvas/genericElement'),
10 viewTemplate = require('libs/text!./view.html'),
11 tipTemplate = require('libs/text!./tip.html');
13 var AnswerElement = Object.create(genericElement);
14 _.extend(AnswerElement, {
16 genericElement.init.call(this);
17 this.tip = $(tipTemplate);
18 this.tip.text(this.wlxmlNode.getAttr('answer') || '');
19 this.tip.on('click', function(e) {
20 var doc = this.wlxmlNode.document,
21 textNode = this.wlxmlNode.contents()[0];
26 this.canvas.select(doc.createFragment(doc.CaretFragment, {node:textNode, offset: textNode.getText().length}));
27 this.canvas.showContextMenu(this, {x: e.clientX, y: e.clientY});
30 this.addWidget(this.tip);
32 onNodeAttrChange: function(event) {
33 if(event.meta.attr === 'answer') {
34 this.tip.text(event.meta.newVal || '');
39 var ReplaceExerciseElement = Object.create(elementBase);
40 _.extend(ReplaceExerciseElement, {
42 elementBase.init.call(this);
43 var view = $(_.template(viewTemplate)());
44 this._container().append(view);
47 this.elementsRegister.register(
48 {tag: 'span', klass: 'answer', prototype: AnswerElement}
51 this.createContainer(this.wlxmlNode.contents(), {
55 dom: view.find('.content')
58 this.addToContextMenu('core.markToReplace');
59 this.contextMenuActions[0].on('actionExecuted', function(ret) {
60 if(ret instanceof this.wlxmlNode.document.Fragment && ret.isValid()) {
61 this.canvas.select(ret);
64 this.addToContextMenu('core.editReplaceMark');
65 this.addToContextMenu('core.removeReplaceMark');
68 getVerticallyFirstTextElement: function() {
70 this.containers.some(function(container) {
71 toret = container.getVerticallyFirstTextElement();
78 return {tag: 'div', klass: 'exercise.replace', prototype: ReplaceExerciseElement};