mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2025-01-19 16:52:59 +08:00
Adding onModulesLoaded
This commit is contained in:
parent
2cd5cf4498
commit
265f88c7d6
@ -91,6 +91,7 @@ class SimpleKeyboard {
|
||||
this.handleButtonMouseUp = this.handleButtonMouseUp.bind(this);
|
||||
this.handleButtonMouseDown = this.handleButtonMouseDown.bind(this);
|
||||
this.handleButtonHold = this.handleButtonHold.bind(this);
|
||||
this.onModulesLoaded = this.onModulesLoaded.bind(this);
|
||||
|
||||
/**
|
||||
* simple-keyboard uses a non-persistent internal input to keep track of the entered string (the variable `keyboard.input`).
|
||||
@ -542,6 +543,14 @@ class SimpleKeyboard {
|
||||
this.options.onRender();
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the callback function once all modules have been loaded
|
||||
*/
|
||||
onModulesLoaded(){
|
||||
if(typeof this.options.onModulesLoaded === "function")
|
||||
this.options.onModulesLoaded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register module
|
||||
*/
|
||||
@ -566,9 +575,13 @@ class SimpleKeyboard {
|
||||
this.keyboardPluginClasses = this.keyboardPluginClasses + ` ${classStr}`;
|
||||
}
|
||||
|
||||
this.render();
|
||||
module.init(this);
|
||||
});
|
||||
|
||||
this.keyboardPluginClasses = this.keyboardPluginClasses + ' modules-loaded';
|
||||
|
||||
this.render();
|
||||
this.onModulesLoaded();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -838,4 +838,27 @@ it('Keyboard handleButtonMouseDown will work', () => {
|
||||
keyboard.getButtonElement("q").onmousedown();
|
||||
document.onmouseup();
|
||||
|
||||
});
|
||||
|
||||
it('Keyboard onModulesLoaded will work', () => {
|
||||
testUtil.setDOM();
|
||||
|
||||
class myClass {
|
||||
init = (module) => {
|
||||
module.foo = "bar";
|
||||
};
|
||||
}
|
||||
|
||||
let foo;
|
||||
|
||||
let keyboard = new Keyboard({
|
||||
modules: [
|
||||
myClass
|
||||
],
|
||||
onModulesLoaded: () => {
|
||||
foo = "bar";
|
||||
}
|
||||
});
|
||||
|
||||
expect(foo).toBe("bar");
|
||||
});
|
Loading…
Reference in New Issue
Block a user