forked from sr258/h5p-advanced-blanks
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
copied library from source (not functional yet)
- Loading branch information
sr258
committed
Aug 9, 2017
1 parent
4a3d6a5
commit ebd1805
Showing
22 changed files
with
1,191 additions
and
33 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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module RactiveEventsKeys { | ||
// TODO can we just declare the keydownHandler once? using `this`? | ||
function makeKeyDefinition(code) { | ||
return (node, fire) => { | ||
function keydownHandler(event) { | ||
var which = event.which || event.keyCode; | ||
|
||
if (which === code) { | ||
event.preventDefault(); | ||
|
||
fire({ | ||
node, | ||
original: event | ||
}); | ||
} | ||
} | ||
|
||
node.addEventListener('keydown', keydownHandler, false); | ||
|
||
return { | ||
teardown() { | ||
node.removeEventListener('keydown', keydownHandler, false); | ||
} | ||
}; | ||
}; | ||
} | ||
|
||
export const enter = makeKeyDefinition(13); | ||
export const tab = makeKeyDefinition(9); | ||
export const escape = makeKeyDefinition(27); | ||
export const space = makeKeyDefinition(32); | ||
|
||
export const leftarrow = makeKeyDefinition(37); | ||
export const rightarrow = makeKeyDefinition(39); | ||
export const downarrow = makeKeyDefinition(40); | ||
export const uparrow = makeKeyDefinition(38); | ||
} |
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,65 @@ | ||
import { Message } from './message'; | ||
import { ClozeHighlight } from './cloze-highlight'; | ||
import { Settings } from './settings'; | ||
import { Evaluation } from './enums'; | ||
import { Levensthein } from './levenshtein'; | ||
|
||
export class Answer { | ||
alternatives: string[]; | ||
message: Message; | ||
appliesAlways: boolean; | ||
|
||
constructor(answers: string, reaction: string) { | ||
this.alternatives = answers.split(/[;|]/).map(s => s.trim()); | ||
this.message = new Message(reaction); | ||
if (answers.trim() === "") { | ||
this.appliesAlways = true; | ||
} else { | ||
this.appliesAlways = false; | ||
} | ||
} | ||
|
||
linkHighlightIdsToObjects = (highlightsBefore: ClozeHighlight[], highlightsAfter: ClozeHighlight[]) => { | ||
this.message.linkHighlights(highlightsBefore, highlightsAfter); | ||
} | ||
|
||
activateHighlights = () => { | ||
for (var highlightedObject of this.message.highlightedElements) { | ||
highlightedObject.isHighlighted = true; | ||
} | ||
} | ||
|
||
private getCleanedText(text: string) { | ||
var caseSensitivity = Settings.instance.caseSensivitity; | ||
|
||
if (caseSensitivity == false) | ||
return text.toLocaleLowerCase(); | ||
else | ||
return text; | ||
} | ||
|
||
public evaluateEnteredText(enteredText: string): Evaluation { | ||
var cleanedEnteredText = this.getCleanedText(enteredText); | ||
|
||
var acceptableTypoCount: number; | ||
if (Settings.instance.acceptTypos) | ||
acceptableTypoCount = Math.floor(enteredText.length / 10) + 1; | ||
else | ||
acceptableTypoCount = 0; | ||
|
||
var bestEvaluation: Evaluation = Evaluation.NoMatch; | ||
|
||
for (var alternative of this.alternatives) { | ||
var cleanedAlternative = this.getCleanedText(alternative); | ||
|
||
if (cleanedAlternative == cleanedEnteredText) | ||
return Evaluation.ExactMatch; | ||
|
||
var necessaryChanges = Levensthein.getEditDistance(cleanedEnteredText, cleanedAlternative); | ||
if (necessaryChanges <= acceptableTypoCount) | ||
bestEvaluation = Evaluation.CloseMatch; | ||
} | ||
|
||
return bestEvaluation; | ||
} | ||
} |
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,29 +1,33 @@ | ||
import * as $ from 'jquery'; | ||
|
||
declare var H5P: any; | ||
declare var H5PIntegration: any; | ||
import { H5PDataRepository } from './data-repository'; | ||
import { MindTheGapController } from './mind-the-gap-controller'; | ||
|
||
export default class AdvancedBlanks extends (H5P.EventDispatcher as { new(): any; }) { | ||
/** | ||
* @constructor | ||
* | ||
* @param {object} config | ||
* @param {string} contentId | ||
* @param {object} contentData | ||
*/ | ||
constructor(config: any, contentId: string, contentData: any = {}) { | ||
super(); | ||
this.element = document.createElement('div'); | ||
this.element.innerText = '-Advanced blanks content-'; | ||
} | ||
|
||
/** | ||
* Attach library to wrapper | ||
* | ||
* @param {jQuery} $wrapper | ||
*/ | ||
attach = function($wrapper: JQuery) { | ||
$wrapper.get(0).classList.add('h5p-advanced-blanks'); | ||
$wrapper.get(0).appendChild(this.element); | ||
} | ||
} | ||
/** | ||
* @constructor | ||
* | ||
* @param {object} config | ||
* @param {string} contentId | ||
* @param {object} contentData | ||
*/ | ||
constructor(config: any, contentId: string, contentData: any = {}) { | ||
super(); | ||
this.element = document.createElement('div'); | ||
this.element.innerText = '-Advanced blanks content-'; | ||
|
||
var repository = new H5PDataRepository(contentData); | ||
//Localization.initialize(AppClient); | ||
var app : MindTheGapController = new MindTheGapController(repository); | ||
app.initialize(); | ||
} | ||
|
||
/** | ||
* Attach library to wrapper | ||
* | ||
* @param {jQuery} $wrapper | ||
*/ | ||
attach = function($wrapper: JQuery) { | ||
$wrapper.get(0).classList.add('h5p-advanced-blanks'); | ||
$wrapper.get(0).appendChild(this.element); | ||
} | ||
} |
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,8 @@ | ||
export enum ClozeElementType { | ||
Gap, | ||
Highlight | ||
} | ||
|
||
export class ClozeElement { | ||
public type: ClozeElementType; | ||
} |
Oops, something went wrong.