Skip to content

Commit 23b47e9

Browse files
author
amyg
committedApr 19, 2016
Added keyboard close/open signals
1 parent c75bb78 commit 23b47e9

10 files changed

+39
-17
lines changed
 

‎README.md

+10
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ Also, when the keyboard is shown, sometimes a resize event will be triggered.
6363

6464
Ideally you use a custom resize event, check for the static property `Fabrique.Plugins.InputField.KeyboardOpen` and don't resize when it's set to true.
6565

66+
### Using keyboard open/close signals
67+
Current version includes two event dispatchers that notify when a device keyboard is opened or closed.
68+
69+
You can add listeners which trigger events based on this feedback.
70+
71+
```javascript
72+
Fabrique.Plugins.InputField.onKeyboardClose.addOnce(function() {
73+
this.resizeBackgroundImage();
74+
});
75+
```
6676

6777
### Current Limitations
6878
- Updates are slow when typing fast (type slower you!!)

‎build/phaser-input.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ declare module Fabrique {
166166
class InputField extends Phaser.Plugin {
167167
static Zoomed: boolean;
168168
static KeyboardOpen: boolean;
169+
static onKeyboardOpen: Phaser.Signal;
170+
static onKeyboardClose: Phaser.Signal;
169171
constructor(game: Phaser.Game, parent: PIXI.DisplayObject);
170172
/**
171173
* Extends the GameObjectFactory prototype with the support of adding InputField. this allows us to add InputField methods to the game just like any other object:

‎build/phaser-input.js

+5-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎build/phaser-input.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎build/phaser-input.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎example/index.html

+8
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@
143143
password.resetText();
144144
age.resetText();
145145
});
146+
147+
Fabrique.Plugins.InputField.onKeyboardOpen.add(function () {
148+
console.error("keyboard open", Fabrique.Plugins.InputField.KeyboardOpen)
149+
});
150+
Fabrique.Plugins.InputField.onKeyboardClose.add(function () {
151+
console.error("keyboard close", Fabrique.Plugins.InputField.KeyboardOpen)
152+
});
153+
146154
}
147155
</script>
148156
</head>

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "phaser-input",
33
"author": "OrangeGames",
4-
"version": "1.1.2",
4+
"version": "1.1.3",
55
"description": "Adds input boxes to Phaser like CanvasInput, but also works for WebGL and Mobile, made for Phaser only.",
66
"contributors": [
77
{
@@ -28,6 +28,7 @@
2828
"grunt-contrib-watch": "^0.6.1",
2929
"grunt-typescript": "0.8.0",
3030
"phaser": "2.4.6",
31+
"phaser-nineslice": "^1.0.0",
3132
"typescript": "1.8.x"
3233
},
3334
"engines": {

‎ts/InputElement.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ module Fabrique {
9292

9393
let kbAppeared: boolean = false;
9494
let interval: number = setInterval((): void => {
95-
console.log(originalWidth, window.innerWidth, originalHeight, window.innerHeight)
95+
//console.log(originalWidth, window.innerWidth, originalHeight, window.innerHeight)
9696
if (originalWidth > window.innerWidth || originalHeight > window.innerHeight) {
9797
kbAppeared = true;
9898
}

‎ts/InputField.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,15 @@ module Fabrique {
130130

131131
this.game.input.onDown.add(this.checkDown, this);
132132
this.domElement.focusOut.add((): void => {
133+
133134
if (Plugins.InputField.KeyboardOpen) {
135+
134136
this.endFocus();
135137
if (this.inputOptions.zoom) {
136138
this.zoomOut();
137139
}
138140
}
139-
})
141+
});
140142
}
141143

142144
/**
@@ -219,6 +221,7 @@ module Fabrique {
219221

220222
if (!this.game.device.desktop) {
221223
Plugins.InputField.KeyboardOpen = false;
224+
Plugins.InputField.onKeyboardClose.dispatch();
222225
}
223226
}
224227

@@ -239,6 +242,7 @@ module Fabrique {
239242

240243
if (!this.game.device.desktop) {
241244
Plugins.InputField.KeyboardOpen = true;
245+
Plugins.InputField.onKeyboardOpen.dispatch();
242246
}
243247
}
244248

‎ts/Plugin.ts

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ module Fabrique {
1616
export class InputField extends Phaser.Plugin {
1717
public static Zoomed: boolean = false;
1818
public static KeyboardOpen: boolean = false;
19+
public static onKeyboardOpen: Phaser.Signal = new Phaser.Signal();
20+
public static onKeyboardClose: Phaser.Signal = new Phaser.Signal();
1921

2022
constructor(game:Phaser.Game, parent:PIXI.DisplayObject) {
2123
super(game, parent);

0 commit comments

Comments
 (0)
Please sign in to comment.