-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1575e90
commit adc4c3a
Showing
9 changed files
with
1,899 additions
and
583 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
{ | ||
"name": "adapt-sentenceOrdering", | ||
"version": "2.0.0", | ||
"framework": "^2.0.0", | ||
"authors": [ | ||
"Nayan Khedkar <[email protected]>" | ||
], | ||
"description": "A sentence Ordering question component.", | ||
"main": "/js/adapt-sentenceOrdering.js", | ||
"displayName" : "Sentence Ordering", | ||
"component" : "sentenceOrdering", | ||
"keywords": [ | ||
"adapt-plugin", | ||
"adapt-component" | ||
], | ||
"license": "GPLv3" | ||
} | ||
"name": "adapt-sentenceOrdering", | ||
"repository": "git://github.com/NayanKhedkar/adapt-sentenceOrdering.git", | ||
"framework": "^2.0.0", | ||
"version": "2.0.0", | ||
"authors": [ | ||
"Nayan Khedkar <[email protected]>" | ||
], | ||
"description": "A sentence Ordering question component.", | ||
"main": "/js/adapt-sentenceOrdering.js", | ||
"displayName": "Sentence Ordering", | ||
"component": "sentenceOrdering", | ||
"keywords": [ | ||
"adapt-plugin", | ||
"adapt-component" | ||
], | ||
"license": "GPLv3" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,190 +1,10 @@ | ||
define(function(require) { | ||
var QuestionView = require('coreViews/questionView'), | ||
Adapt = require('coreJS/adapt'), | ||
SortableLib = require('components/adapt-sentenceOrdering/js/sortable'); | ||
var SentenceOrdering = QuestionView.extend({ | ||
events: { | ||
}, | ||
setupQuestion: function() { | ||
this.listenTo(Adapt, 'device:resize', this.resizeItems, 200); | ||
this.setupRandomisation(); | ||
}, | ||
setupRandomisation: function() { | ||
if (this.model.get('_isRandom')) { | ||
this.model.set("_shuffleItems", _.shuffle(this.model.get("_items"))); | ||
} else { | ||
this.model.set("_shuffleItems", this.model.get("_items")); | ||
} | ||
}, | ||
var Adapt = require('core/js/adapt'); | ||
var SentenceOrderingModel = require('./sentenceOrderingModel'); | ||
var SentenceOrderingView = require('./sentenceOrderingView'); | ||
|
||
onQuestionRendered: function() { | ||
this.model.set('_sortableItems', this.$('#sortable').html()); | ||
this.setReadyStatus(); | ||
this.sortSentenceInitialize(); | ||
this.setHeight(); | ||
this.resizeItems(); | ||
if(!this.model.get('_isPrefixTitle'))this.$('.sentence-container').width('100%'); | ||
}, | ||
|
||
sortSentenceInitialize: function(event) { | ||
var self = this; | ||
if (event && event.preventDefault) { | ||
event.preventDefault(); | ||
} | ||
this.$("#sortable").sortable().on('sortable:activate', function(event, ui) { | ||
$(ui.item).css({ | ||
'z-index': '1000' | ||
}); | ||
}).on('sortable:deactivate', function(event, ui) { | ||
$(ui.item).css({ | ||
'z-index': '0' | ||
}); | ||
self.setDefaultHeight(); | ||
}).on('sortable:change', function(event, ui) { | ||
$("li.placeholder").css('height', ui.item.height() + 'px'); | ||
}); | ||
}, | ||
setDefaultHeight: function() { | ||
var sentenceOrderingContainers = this.$('.prefixTitle ,.sentenceSequence'); | ||
sentenceOrderingContainers.css({ | ||
'height': 'auto' | ||
}); | ||
this.setHeight(); | ||
}, | ||
setHeight: function() { | ||
var prefix = this.$('.prefixTitle'), | ||
sentence = this.$('.sentenceSequence'), | ||
prefixHeight, | ||
sentenceHeight; | ||
for (var i = 0, length = prefix.length; i < length; i++) { | ||
prefixHeight = prefix.eq(i).height(); | ||
sentenceHeight = sentence.eq(i).height(); | ||
if (!(prefixHeight === sentenceHeight)) { | ||
if (prefixHeight > sentenceHeight) { | ||
sentence.eq(i).css({ | ||
'height': prefixHeight | ||
}); | ||
} else { | ||
prefix.eq(i).css({ | ||
'height': sentenceHeight | ||
}); | ||
} | ||
} | ||
} | ||
}, | ||
resizeItems: function() { | ||
if (this.model.get("_shouldScale")) { | ||
var $el = this.$("#innerWrapper"), | ||
elHeight = $el.outerHeight(), | ||
elWidth = $el.outerWidth(), | ||
$wrapper = this.$('#scaleableWrapper'); | ||
|
||
function doResize(event, ui) { | ||
var scale, heightFactor; | ||
scale = Math.min( | ||
ui.size.width / elWidth, | ||
ui.size.height / elHeight | ||
); | ||
if (scale > 1) { | ||
scale = 1; | ||
} | ||
$el.css({ | ||
'-ms-transform': 'scale(' + scale + ')', | ||
'-moz-transform': 'scale(' + scale + ')', | ||
'-webkit-transform': 'scale(' + scale + ')', | ||
'-webkit-transform-style': 'preserve-3d', | ||
'-webkit-transform': 'scale3d(' + scale + ',' + scale + ',' + scale + ')', | ||
'transform': 'scale(' + scale + ')' | ||
}).attr('zoom', scale); | ||
$el.height(this.$('.sentence-container').height() * scale); | ||
} | ||
var starterData = { | ||
size: { | ||
width: $wrapper.width(), | ||
height: $wrapper.height() | ||
} | ||
}; | ||
doResize(null, starterData); | ||
} else { | ||
this.setDefaultHeight(); | ||
} | ||
}, | ||
disableQuestion: function() { | ||
this.$("#sortable").sortable('disable'); | ||
}, | ||
enableQuestion: function() { | ||
this.$("#sortable").sortable('enable'); | ||
}, | ||
canSubmit: function() { | ||
return true; | ||
}, | ||
onSubmitted: function() { | ||
var numberOfIncorrectAnswers = this.model.get('_numberOfIncorrectAnswers'); | ||
var attemptsLeft = this.model.get('_attemptsLeft'); | ||
if (attemptsLeft !== 0 && numberOfIncorrectAnswers > 0) | ||
this.$('.sentenceSequence').addClass('incorrect-resettable'); | ||
}, | ||
storeUserAnswer: function() { | ||
var listElements = this.$(".sentenceSequence"), | ||
userAnswer = []; | ||
_.each(listElements, function(item, index) { | ||
userAnswer.push({ | ||
'id': parseInt(item.id) | ||
}); | ||
}); | ||
this.model.set({ | ||
'_userAnswerListElement': listElements, | ||
'_userAnswer': userAnswer | ||
}); | ||
}, | ||
showCorrectAnswer: function() { | ||
var listElements = [], | ||
cloneElement = this.$("#sortable li").clone(); | ||
cloneElement.sort(function(firstEle, secondEle) { | ||
return parseInt(firstEle.id) - parseInt(secondEle.id); | ||
}).each(function() { | ||
listElements.push(this) | ||
}); | ||
this.$('#sortable').html(listElements); | ||
this.setDefaultHeight(); | ||
}, | ||
hideCorrectAnswer: function() { | ||
this.$('#sortable').html(this.model.get('_userAnswerListElement')); | ||
this.setDefaultHeight(); | ||
}, | ||
showMarking: function() { | ||
var listElements = this.model.get('_userAnswer'); | ||
_.each(listElements, function(item, index) { | ||
var $item = this.$('.sentenceSequence').eq(index); | ||
$item.addClass(item._isCorrect ? 'correct' : 'incorrect') | ||
}, this); | ||
}, | ||
resetQuestion: function() { | ||
this.model.set('_userAnswer', []); | ||
this.$('#sortable').html(this.model.get('_sortableItems')); | ||
}, | ||
isCorrect: function() { | ||
var listElements = this.model.get('_userAnswer'), | ||
items = this.model.get("_items"), | ||
numberOfCorrectAnswers = 0, | ||
numberOfIncorrectAnswers = 0, | ||
isCorrect; | ||
_.each(listElements, function(item, index) { | ||
isCorrect = _.contains(items[index].position, item.id); | ||
if (isCorrect) { | ||
numberOfCorrectAnswers++; | ||
item._isCorrect = true; | ||
} else { | ||
numberOfIncorrectAnswers++; | ||
} | ||
}, this); | ||
this.model.set('_numberOfCorrectAnswers', numberOfCorrectAnswers); | ||
this.model.set('_numberOfIncorrectAnswers', numberOfIncorrectAnswers); | ||
// Check if correct answers matches correct items and there are no incorrect selections | ||
var answeredCorrectly = (numberOfCorrectAnswers === items.length) && (numberOfIncorrectAnswers === 0); | ||
return answeredCorrectly; | ||
} | ||
return Adapt.register("sentenceOrdering", { | ||
view: SentenceOrderingView, | ||
model: SentenceOrderingModel | ||
}); | ||
Adapt.register("sentenceOrdering", SentenceOrdering); | ||
return SentenceOrdering; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
define(function(require) { | ||
var QuestionModel = require('core/js/models/questionModel'); | ||
|
||
var SentenceOrderingModel = QuestionModel.extend({ | ||
|
||
init: function() { | ||
QuestionModel.prototype.init.call(this); | ||
}, | ||
|
||
restoreUserAnswers: function() { | ||
if (!this.get("_isSubmitted")) return; | ||
var userAnswer = this.get("_userAnswer"); | ||
var itemArray = []; | ||
var items = _.sortBy(this.get("_items")); | ||
_.each(userAnswer, function(item, index) { | ||
itemArray[index] = items[item - 1]; | ||
}, this); | ||
this.set("_items", itemArray); | ||
this.setPrefixTitle(); | ||
this.setQuestionAsSubmitted(); | ||
this.markQuestion(); | ||
this.setScore(); | ||
this.setupFeedback(); | ||
}, | ||
|
||
setupRandomisation: function() { | ||
this.setPrefixTitle(); | ||
if (this.get('_isRandom') && this.get('_isEnabled')) { | ||
this.set("_items", _.shuffle(this.get("_items"))); | ||
} | ||
}, | ||
|
||
setPrefixTitle: function() { | ||
if (!this.get("_isPrefixTitle")) return; | ||
var items = _.sortBy(this.get('_items'), 'id'); | ||
this.set("_prefixTitles", _.pluck(items, 'prefixTitle')); | ||
}, | ||
|
||
// check if the user is allowed to submit the question | ||
canSubmit: function() { | ||
return true; | ||
|
||
}, | ||
|
||
// This is important for returning or showing the users answer | ||
// This should preserve the state of the users answers | ||
storeUserAnswer: function() { | ||
var userAnswer = []; | ||
var tempArray = []; | ||
var items = _.sortBy(this.get('_items'), 'id'); | ||
var userSortedList = this.get('_sentenceListJqueryObject').children(); | ||
this.set("userSortedList", userSortedList); | ||
_.each(userSortedList, function(item, index) { | ||
userAnswer.push(parseInt(item.dataset.itemid)); | ||
tempArray.push(items[parseInt(item.dataset.itemid) - 1]); | ||
}); | ||
this.set({ | ||
'_items': tempArray, | ||
'_userAnswer': userAnswer | ||
}); | ||
}, | ||
|
||
isCorrect: function() { | ||
var userAnswer = this.get('_userAnswer'), | ||
itemsSorted = _.sortBy(this.get("_items"), 'id'), | ||
items = this.get("_items"), | ||
numberOfCorrectAnswers = 0, | ||
numberOfIncorrectAnswers = 0, | ||
isItemOnCorrectPlace = []; | ||
_.each(userAnswer, function(item, index) { | ||
if (_.contains(itemsSorted[index].position, item)) { | ||
numberOfCorrectAnswers++; | ||
isItemOnCorrectPlace.push(true); | ||
} else { | ||
numberOfIncorrectAnswers++; | ||
isItemOnCorrectPlace.push(false); | ||
} | ||
}, this); | ||
this.set('isItemOnCorrectPlace', isItemOnCorrectPlace); | ||
this.set('_numberOfCorrectAnswers', numberOfCorrectAnswers); | ||
this.set('_numberOfIncorrectAnswers', numberOfIncorrectAnswers); | ||
// Check if correct answers matches correct items and there are no incorrect selections | ||
var answeredCorrectly = (numberOfCorrectAnswers === items.length) && (numberOfIncorrectAnswers === 0); | ||
return answeredCorrectly; | ||
}, | ||
|
||
// Sets the score based upon the questionWeight | ||
// Can be overwritten if the question needs to set the score in a different way | ||
setScore: function() { | ||
var questionWeight = this.get("_questionWeight"); | ||
var answeredCorrectly = this.get('_isCorrect'); | ||
var score = answeredCorrectly ? questionWeight : 0; | ||
this.set('_score', score); | ||
}, | ||
isPartlyCorrect: function() { | ||
return this.get('_numberOfCorrectAnswers') >= this.get('_items').length / 2; | ||
}, | ||
/*resetItems: function() { | ||
if(!this.get('_previousItems')) return; | ||
this.set('_items', this.get('_previousItems')); | ||
},*/ | ||
resetUserAnswer: function() { | ||
this.set({_userAnswer: []}); | ||
} | ||
}); | ||
|
||
return SentenceOrderingModel; | ||
|
||
}); |
Oops, something went wrong.