Question.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. function Question(questionData, imageUrl) {
  2. this.questionData = questionData;
  3. this.questionData["imageUrl"] = imageUrl;
  4. this.questionData["answerArray"] = function () {
  5. return this["answer"].split("");
  6. };
  7. this.questionData["keyboardArray"] = function () {
  8. var originchars = this["answer"].split("");
  9. var defaultstring = this["keyboard"] + this["answer"];
  10. var that = this;
  11. this["keyboard"].split("").forEach(function(value) {
  12. if ( that["answer"].indexOf(value) < 0 && originchars.length < 24) {
  13. originchars.push(value);
  14. }
  15. });
  16. //fill the keyboard with charactor lib
  17. for ( index in controller.charactors ) {
  18. if ( originchars.length < 24 ) {
  19. var value = controller.charactors[index];
  20. if ( defaultstring.indexOf( value ) < 0 ) {
  21. originchars.push(value);
  22. }
  23. } else {
  24. break;
  25. }
  26. }
  27. var returnArray = [];
  28. shuffleArray(originchars).forEach(function(value,index){
  29. returnArray.push({'index':index,'value':value});
  30. });
  31. return returnArray;
  32. };
  33. this.questionUI = "";
  34. this.update = function () {
  35. var compiledTemplate = Mustache.compile(document.getElementById("questionTmpl").text);
  36. this.questionUI = compiledTemplate(this.questionData);
  37. }
  38. }