@oat-sa/tao-item-runner-qti
Version:
TAO QTI Item Runner modules
46 lines (40 loc) • 1.87 kB
JavaScript
define(['jquery', 'lodash', 'taoQtiItem/qtiItem/core/choices/Choice', 'taoQtiItem/qtiItem/helper/rendererConfig'], function ($, _, QtiChoice, rendererConfig) { 'use strict';
$ = $ && Object.prototype.hasOwnProperty.call($, 'default') ? $['default'] : $;
_ = _ && Object.prototype.hasOwnProperty.call(_, 'default') ? _['default'] : _;
QtiChoice = QtiChoice && Object.prototype.hasOwnProperty.call(QtiChoice, 'default') ? QtiChoice['default'] : QtiChoice;
rendererConfig = rendererConfig && Object.prototype.hasOwnProperty.call(rendererConfig, 'default') ? rendererConfig['default'] : rendererConfig;
var QtiTextVariableChoice = QtiChoice.extend({
init: function(serial, attributes, text) {
this._super(serial, attributes);
this.val(text || '');
},
is: function(qtiClass) {
return qtiClass === 'textVariableChoice' || this._super(qtiClass);
},
val: function(text) {
if (typeof text === 'undefined') {
return this.text;
} else {
if (typeof text === 'string') {
this.text = text;
$(document).trigger('choiceTextChange', {
choice: this,
text: text
});
} else {
throw 'text must be a string';
}
}
return this;
},
render: function() {
var args = rendererConfig.getOptionsFromArguments(arguments),
renderer = args.renderer || this.getRenderer(),
defaultData = {
body: this.text
};
return this._super(_.merge(defaultData, args.data), args.placeholder, args.subclass, renderer);
}
});
return QtiTextVariableChoice;
});