Skip to content

Commit

Permalink
Merge pull request #19 from deltanet/fw-v4
Browse files Browse the repository at this point in the history
Framework v4 changes
  • Loading branch information
dancgray authored Aug 29, 2019
2 parents a362455 + 120a9fe commit 938715d
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 225 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ The Enhanced Question attribute group contains values for **_isEnabled**, **_ove
## Limitations

This cannot be used when adapt-contrib-tutor is installed, as there are issues with adapt-contrib-trickle events.
This cannot be used when adapt-contrib-tutor is installed, as there are issues with adapt-contrib-trickle events, and multiple feedback popups will open.

----------------------------
**Version number:** 2.3.1
**Framework versions supported:** ^2.0.4
**Version number:** 3.0.0
**Framework versions supported:** 4+
**Author / maintainer:** DeltaNet with [contributors](https://github.com/deltanet/adapt-enhanced-question/graphs/contributors)
**Accessibility support:** Yes
**RTL support:** Yes
Expand Down
8 changes: 4 additions & 4 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "adapt-enhanced-question",
"version": "2.3.1",
"framework": "^2.0.4",
"version": "3.0.0",
"framework": ">=4",
"homepage": "https://github.com/deltanet/adapt-enhanced-question",
"issues": "https://github.com/deltanet/adapt-enhanced-question/issues",
"displayName" : "Enhanced Question",
"extension" : "enhanced question",
"description": "An extension that enables more options for a question",
"description": "An extension that enables question feedback to be shown inline, an image and title added to the popup, and also change the partly correct score.",
"main": "/js/adapt-enhanced-question.js",
"keywords": [
"adapt-plugin",
"adapt-extension"
],
"license": "GPL-3.0",
"license": "GPLv3",
"targetAttribute": "_enhancedQuestion"
}
229 changes: 111 additions & 118 deletions js/adapt-enhanced-question.js
Original file line number Diff line number Diff line change
@@ -1,145 +1,138 @@
define([
'coreJS/adapt',
'./inline-feedbackView'
],function(Adapt, InlineFeedbackView) {
'core/js/adapt',
'./inline-feedbackView',
'./popup-feedbackView'
],function(Adapt, InlineFeedbackView, PopupFeedbackView) {

var EnhancedQuestion = _.extend({

initialize: function() {
this.listenToOnce(Adapt, "app:dataReady", this.onDataReady);
this.listenToOnce(Adapt, "app:dataReady", this.onDataReady);

this.popupView = null;
this.isPopupOpen = false;
},

onDataReady: function() {
this.setupEventListeners();
this.setupListeners();
},

setupEventListeners: function() {
this.listenTo(Adapt, "componentView:postRender", this.onQuestionReady);
this.listenTo(Adapt, "questionView:showFeedback questionView:disabledFeedback", this.onShowFeedback);
setupListeners: function() {
this.listenTo(Adapt, "componentView:postRender", this.onQuestionReady);
this.listenTo(Adapt, "questionView:showFeedback questionView:disabledFeedback", this.onShowFeedback);
},

onShowFeedback: function(view) {
// Partly correct score change
if (view.model.get('_enhancedQuestion') && view.model.get('_enhancedQuestion')._isEnabled && view.model.get('_enhancedQuestion')._overidePartlyCorrect._isEnabled && view.model.get('_isAtLeastOneCorrectSelection') && !view.model.get('_isCorrect')) {
if (!view.model.get('_enhancedQuestion') || !view.model.get('_enhancedQuestion')._isEnabled) return;

view.model.set('_score', view.model.get('_enhancedQuestion')._overidePartlyCorrect._questionWeight);
view.model.set('_isCorrect', true);
// Partly correct score change
if (view.model.get('_enhancedQuestion')._overidePartlyCorrect._isEnabled && view.model.get('_isAtLeastOneCorrectSelection') && !view.model.get('_isCorrect')) {

$('.'+view.model.get('_id')).find('.buttons-marking-icon').removeClass('icon-cross');
$('.'+view.model.get('_id')).find('.buttons-marking-icon').addClass('icon-tick');
view.model.set('_score', view.model.get('_enhancedQuestion')._overidePartlyCorrect._questionWeight);
view.model.set('_isCorrect', true);

$('.'+view.model.get('_id')).find('.buttons-marking-icon').removeClass('icon-cross');
$('.'+view.model.get('_id')).find('.buttons-marking-icon').addClass('icon-tick');
}
// Custom notify elements
if (view.model.get('_enhancedQuestion') && view.model.get('_enhancedQuestion')._isEnabled && view.model.get('_canShowFeedback')) {
// Set alert title
var feedbackTitle = "";

/// Feedback title
if (view.model.get('_enhancedQuestion')._feedbackTitle._isEnabled) {
// Correct
if (view.model.get('_isCorrect')) {
feedbackTitle = view.model.get('_enhancedQuestion')._feedbackTitle.correct;
// Partly correct
} else if (view.model.get('_isAtLeastOneCorrectSelection')) {
// Check attempts
if (view.model.get('_attemptsLeft') === 0) {
feedbackTitle = view.model.get('_enhancedQuestion')._feedbackTitle.partlyCorrect;
} else {
feedbackTitle = view.model.get('_enhancedQuestion')._feedbackTitle.partlyCorrectNotFinal;
}
// Incorrect
} else {
// Check attempts
if (view.model.get('_attemptsLeft') === 0) {
feedbackTitle = view.model.get('_enhancedQuestion')._feedbackTitle.incorrect;
} else {
feedbackTitle = view.model.get('_enhancedQuestion')._feedbackTitle.incorrectNotFinal;
}
}

} else {
feedbackTitle = view.model.get("feedbackTitle");
}

// Check for feedback icon
if (view.model.get('_enhancedQuestion')._feedbackIcons._isEnabled) {
var feedbackIconTitle = "";
if (view.model.get('_isCorrect')) {
// Check for image alt tag
if(view.model.get('_enhancedQuestion')._feedbackIcons.correctAlt && !view.model.get('_enhancedQuestion')._feedbackIcons.correctAlt == "") {
feedbackIconTitle = "<div class=feedback-icon><img aria-label='"+view.model.get('_enhancedQuestion')._feedbackIcons.correctAlt+"' tabindex='0' src='"+view.model.get('_enhancedQuestion')._feedbackIcons._correctIcon+"'/></div>"+feedbackTitle;
} else {
feedbackIconTitle = "<div class=feedback-icon><img class='a11y-ignore' aria-hidden='true' tabindex='-1' src='"+view.model.get('_enhancedQuestion')._feedbackIcons._correctIcon+"'/></div>"+feedbackTitle;
}
} else if (view.model.get('_isAtLeastOneCorrectSelection')) {
// Check for image alt tag
if(view.model.get('_enhancedQuestion')._feedbackIcons.partlyCorrectAlt && !view.model.get('_enhancedQuestion')._feedbackIcons.partlyCorrectAlt == "") {
feedbackIconTitle = "<div class=feedback-icon><img aria-label='"+view.model.get('_enhancedQuestion')._feedbackIcons.partlyCorrectAlt+"' tabindex='0' src='"+view.model.get('_enhancedQuestion')._feedbackIcons._partlyCorrectIcon+"'/></div>"+feedbackTitle;
} else {
feedbackIconTitle = "<div class=feedback-icon><img class='a11y-ignore' aria-hidden='true' tabindex='-1' src='"+view.model.get('_enhancedQuestion')._feedbackIcons._partlyCorrectIcon+"'/></div>"+feedbackTitle;
}
} else {
// Check for image alt tag
if(view.model.get('_enhancedQuestion')._feedbackIcons.incorrectAlt && !view.model.get('_enhancedQuestion')._feedbackIcons.incorrectAlt == "") {
feedbackIconTitle = "<div class=feedback-icon><img aria-label='"+view.model.get('_enhancedQuestion')._feedbackIcons.incorrectAlt+"' tabindex='0' src='"+view.model.get('_enhancedQuestion')._feedbackIcons._incorrectIcon+"'/></div>"+feedbackTitle;
} else {
feedbackIconTitle = "<div class=feedback-icon><img class='a11y-ignore' aria-hidden='true' tabindex='-1' src='"+view.model.get('_enhancedQuestion')._feedbackIcons._incorrectIcon+"'/></div>"+feedbackTitle;
}
}
feedbackTitle = feedbackIconTitle;
}

var buttonText = (view.model.get('_enhancedQuestion').close) ? view.model.get('_enhancedQuestion').close : Adapt.course.get('_globals')._accessibility._ariaLabels.closePopup;

// Set up new notify object
var alertObject = {
title: feedbackTitle,
body: view.model.get("feedbackMessage"),
_prompts:[
{
promptText: buttonText
}
],
};

if (view.model.has('_isCorrect')) {
// Attach specific classes so that feedback can be styled.
if (view.model.get('_isCorrect')) {
alertObject._classes = 'correct';
} else {
if (view.model.has('_isAtLeastOneCorrectSelection')) {
// Partially correct feedback is an option.
alertObject._classes = view.model.get('_isAtLeastOneCorrectSelection')
? 'partially-correct'
: 'incorrect';
} else {
alertObject._classes = 'incorrect';
}
}
}

if (!view.model.get('_enhancedQuestion')._inlineFeedback._isEnabled) {
Adapt.trigger('notify:prompt', alertObject);
}

}
if (!view.model.get('_canShowFeedback') || this.isPopupOpen) return;

},
// Check for image
if (view.model.get('_enhancedQuestion')._feedbackIcons._isEnabled) {
if (view.model.get('_isCorrect')) {
view.model.set('image', view.model.get('_enhancedQuestion')._feedbackIcons._correctIcon);
view.model.set('alt', view.model.get('_enhancedQuestion')._feedbackIcons.correctAlt);

onQuestionReady: function(view) {
} else if (view.model.get('_isAtLeastOneCorrectSelection')) {
view.model.set('image', view.model.get('_enhancedQuestion')._feedbackIcons._partlyCorrectIcon);
view.model.set('alt', view.model.get('_enhancedQuestion')._feedbackIcons.partlyCorrectAlt);

if (view.model.get('_enhancedQuestion') && view.model.get('_enhancedQuestion')._isEnabled) {

// Add class to component
$('.'+view.model.get('_id')).addClass('enhanced-question-enabled');
} else {
view.model.set('image', view.model.get('_enhancedQuestion')._feedbackIcons._incorrectIcon);
view.model.set('alt', view.model.get('_enhancedQuestion')._feedbackIcons.incorrectAlt);
}
}

/// Inline feedback
if (view.model.get('_enhancedQuestion')._inlineFeedback._isEnabled && view.model.get('_canShowFeedback')) {
new InlineFeedbackView({model:view.model});
}
// Check for title
if (view.model.get('_enhancedQuestion')._feedbackTitle._isEnabled) {
// Correct
if (view.model.get('_isCorrect')) {
view.model.set('feedbackTitle', view.model.get('_enhancedQuestion')._feedbackTitle.correct);
// Partly correct
} else if (view.model.get('_isAtLeastOneCorrectSelection')) {
// Check attempts
if (view.model.get('_attemptsLeft') === 0) {
view.model.set('feedbackTitle', view.model.get('_enhancedQuestion')._feedbackTitle.partlyCorrect);
} else {
view.model.set('feedbackTitle', view.model.get('_enhancedQuestion')._feedbackTitle.partlyCorrectNotFinal);
}
// Incorrect
} else {
// Check attempts
if (view.model.get('_attemptsLeft') === 0) {
view.model.set('feedbackTitle', view.model.get('_enhancedQuestion')._feedbackTitle.incorrect);
} else {
view.model.set('feedbackTitle', view.model.get('_enhancedQuestion')._feedbackTitle.incorrectNotFinal);
}
}
} else {
view.model.set('feedbackTitle', view.model.get("feedbackTitle"));
}

Adapt.trigger('audio:stopAllChannels');

var classes = ' enhancedQuestion-popup';

// Attach specific classes so that feedback can be styled.
if (view.model.get('_isCorrect')) {
classes = ' enhancedQuestion-popup correct';
} else {
if (view.model.has('_isAtLeastOneCorrectSelection')) {
// Partially correct feedback is an option.
classes = view.model.get('_isAtLeastOneCorrectSelection')
? ' enhancedQuestion-popup partially-correct'
: ' enhancedQuestion-popup incorrect';
} else {
classes = ' enhancedQuestion-popup incorrect';
}
}

if (view.model.get('_enhancedQuestion')._inlineFeedback._isEnabled) {
this.inlineFeedbackView = new InlineFeedbackView({model:view.model});
this.listenToOnce(view.model, 'change:_isSubmitted', this.removeInlineFeedbackView, this);

} else {
this.isPopupOpen = true;

this.popupView = new PopupFeedbackView({
model: view.model
});

Adapt.trigger("notify:popup", {
_view: this.popupView,
_isCancellable: true,
_showCloseButton: false,
_closeOnBackdrop: true,
_classes: classes
});
this.listenToOnce(Adapt, 'popup:closed', this.onPopupClosed);
}
},

onPopupClosed: function() {
this.isPopupOpen = false;
},

removeInlineFeedbackView: function(model) {
this.inlineFeedbackView.remove();
$('.'+model.get('_id')).find('.inline-feedback').remove();
},

onQuestionReady: function(view) {
if (view.model.get('_enhancedQuestion') && view.model.get('_enhancedQuestion')._isEnabled) {
// Add class to component
$('.'+view.model.get('_id')).addClass('enhanced-question-enabled');
}
}

}, Backbone.Events);
Expand All @@ -148,4 +141,4 @@ define([

return EnhancedQuestion;

})
});
Loading

0 comments on commit 938715d

Please sign in to comment.