1var H5P = window.H5P = window.H5P || {}; 2 3/** 4 * The external event dispatcher. Others, outside of H5P may register and 5 * listen for H5P Events here. 6 * 7 * @type {H5P.EventDispatcher} 8 */ 9H5P.externalDispatcher = new H5P.EventDispatcher(); 10 11// EventDispatcher extensions 12 13/** 14 * Helper function for triggering xAPI added to the EventDispatcher. 15 * 16 * @param {string} verb 17 * The short id of the verb we want to trigger 18 * @param {Oject} [extra] 19 * Extra properties for the xAPI statement 20 */ 21H5P.EventDispatcher.prototype.triggerXAPI = function (verb, extra) { 22 this.trigger(this.createXAPIEventTemplate(verb, extra)); 23}; 24 25/** 26 * Helper function to create event templates added to the EventDispatcher. 27 * 28 * Will in the future be used to add representations of the questions to the 29 * statements. 30 * 31 * @param {string} verb 32 * Verb id in short form 33 * @param {Object} [extra] 34 * Extra values to be added to the statement 35 * @returns {H5P.XAPIEvent} 36 * Instance 37 */ 38H5P.EventDispatcher.prototype.createXAPIEventTemplate = function (verb, extra) { 39 var event = new H5P.XAPIEvent(); 40 41 event.setActor(); 42 event.setVerb(verb); 43 if (extra !== undefined) { 44 for (var i in extra) { 45 event.data.statement[i] = extra[i]; 46 } 47 } 48 if (!('object' in event.data.statement)) { 49 event.setObject(this); 50 } 51 if (!('context' in event.data.statement)) { 52 event.setContext(this); 53 } 54 return event; 55}; 56 57/** 58 * Helper function to create xAPI completed events 59 * 60 * DEPRECATED - USE triggerXAPIScored instead 61 * 62 * @deprecated 63 * since 1.5, use triggerXAPIScored instead. 64 * @param {number} score 65 * Will be set as the 'raw' value of the score object 66 * @param {number} maxScore 67 * will be set as the "max" value of the score object 68 * @param {boolean} success 69 * will be set as the "success" value of the result object 70 */ 71H5P.EventDispatcher.prototype.triggerXAPICompleted = function (score, maxScore, success) { 72 this.triggerXAPIScored(score, maxScore, 'completed', true, success); 73}; 74 75/** 76 * Helper function to create scored xAPI events 77 * 78 * @param {number} score 79 * Will be set as the 'raw' value of the score object 80 * @param {number} maxScore 81 * Will be set as the "max" value of the score object 82 * @param {string} verb 83 * Short form of adl verb 84 * @param {boolean} completion 85 * Is this a statement from a completed activity? 86 * @param {boolean} success 87 * Is this a statement from an activity that was done successfully? 88 */ 89H5P.EventDispatcher.prototype.triggerXAPIScored = function (score, maxScore, verb, completion, success) { 90 var event = this.createXAPIEventTemplate(verb); 91 event.setScoredResult(score, maxScore, this, completion, success); 92 this.trigger(event); 93}; 94 95H5P.EventDispatcher.prototype.setActivityStarted = function () { 96 if (this.activityStartTime === undefined) { 97 // Don't trigger xAPI events in the editor 98 if (this.contentId !== undefined && 99 H5PIntegration.contents !== undefined && 100 H5PIntegration.contents['cid-' + this.contentId] !== undefined) { 101 this.triggerXAPI('attempted'); 102 } 103 this.activityStartTime = Date.now(); 104 } 105}; 106 107/** 108 * Internal H5P function listening for xAPI completed events and stores scores 109 * 110 * @param {H5P.XAPIEvent} event 111 */ 112H5P.xAPICompletedListener = function (event) { 113 if ((event.getVerb() === 'completed' || event.getVerb() === 'answered') && !event.getVerifiedStatementValue(['context', 'contextActivities', 'parent'])) { 114 var score = event.getScore(); 115 var maxScore = event.getMaxScore(); 116 var contentId = event.getVerifiedStatementValue(['object', 'definition', 'extensions', 'http://h5p.org/x-api/h5p-local-content-id']); 117 H5P.setFinished(contentId, score, maxScore); 118 } 119};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.