Socket
Socket
Sign inDemoInstall

phaser-input

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

phaser-input - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

9

build/phaser-input.d.ts

@@ -16,2 +16,5 @@ declare module Fabrique {

type?: InputType;
maxLength?: number;
min?: string;
max?: string;
}

@@ -21,2 +24,3 @@ enum InputType {

password = 1,
number = 2,
}

@@ -36,2 +40,3 @@ class InputField extends Phaser.Sprite {

private id;
private inputOptions;
constructor(game: Phaser.Game, x: number, y: number, inputOptions?: InputOptions);

@@ -90,2 +95,6 @@ /**

destroy(): void;
/**
* Resets the text to an empty value
*/
resetText(): void;
}

@@ -92,0 +101,0 @@ }

39

build/phaser-input.js
/*!
* phaser-input - version 0.1.3
* phaser-input - version 0.1.4
* Adds input boxes to Phaser like CanvasInput, but also works for WebGL and Mobile, made for Phaser only.
*
* OrangeGames
* Build at 23-02-2016
* Build at 26-02-2016
* Released under MIT License

@@ -20,2 +20,3 @@ */

InputType[InputType["password"] = 1] = "password";
InputType[InputType["number"] = 2] = "number";
})(Fabrique.InputType || (Fabrique.InputType = {}));

@@ -41,2 +42,3 @@ var InputType = Fabrique.InputType;

this.cnt = 0;
this.inputOptions = inputOptions;
this.padding = inputOptions.padding || 0;

@@ -140,8 +142,12 @@ this.createBox(inputOptions);

input.value = this.value;
if (this.type === InputType.password) {
input.type = 'password';
input.type = InputType[this.type];
if (this.inputOptions.maxLength && (this.type === InputType.text || this.type === InputType.password)) {
input.maxLength = this.inputOptions.maxLength;
}
else {
input.type = 'text';
if (this.inputOptions.min && this.type === InputType.number) {
input.min = this.inputOptions.min;
}
if (this.inputOptions.min && this.type === InputType.number) {
input.max = this.inputOptions.max;
}
if (created) {

@@ -204,2 +210,14 @@ document.body.appendChild(input);

}
else if (this.type === InputType.number) {
var val = parseInt(this.value);
if (val < parseInt(this.inputOptions.min)) {
text = this.inputOptions.min;
}
else if (val > parseInt(this.inputOptions.max)) {
text = this.inputOptions.max;
}
else {
text = this.value;
}
}
else {

@@ -225,2 +243,11 @@ text = this.value;

};
/**
* Resets the text to an empty value
*/
InputField.prototype.resetText = function () {
this.value = "";
document.getElementById(this.id).value = this.value;
this.updateText();
this.endFocus();
};
return InputField;

@@ -227,0 +254,0 @@ })(Phaser.Sprite);

6

build/phaser-input.min.js
/*!
* phaser-input - version 0.1.3
* phaser-input - version 0.1.4
* Adds input boxes to Phaser like CanvasInput, but also works for WebGL and Mobile, made for Phaser only.
*
* OrangeGames
* Build at 23-02-2016
* Build at 26-02-2016
* Released under MIT License
*/
var __extends=this&&this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);a.prototype=null===b?Object.create(b):(c.prototype=b.prototype,new c)},Fabrique;!function(a){!function(a){a[a.text=0]="text",a[a.password=1]="password"}(a.InputType||(a.InputType={}));var b=a.InputType,c=function(a){function c(c,d,e,f){void 0===f&&(f={}),a.call(this,c,d,e),this.placeHolder=null,this.box=null,this.focus=!1,this.type=b.text,this.value="",this.id="phaser-input-"+(1e4*Math.random()|0).toString(),this.blink=!0,this.cnt=0,this.padding=f.padding||0,this.createBox(f),f.placeHolder&&f.placeHolder.length>0&&(this.placeHolder=new Phaser.Text(c,this.padding,this.padding,f.placeHolder,{font:f.font||"14px Arial",fontWeight:f.fontWeight||"normal",fill:f.placeHolderColor||"#bfbebd"}),this.addChild(this.placeHolder)),this.cursor=new Phaser.Text(c,this.padding,this.padding-2,"|",{font:f.font||"14px Arial",fontWeight:f.fontWeight||"normal",fill:f.cursorColor||"#000000"}),this.cursor.visible=!1,this.addChild(this.cursor),this.text=new Phaser.Text(c,this.padding,this.padding,"",{font:f.font||"14px Arial",fontWeight:f.fontWeight||"normal",fill:f.fill||"#000000"}),this.addChild(this.text),f.type&&(this.type=f.type),this.inputEnabled=!0,this.input.useHandCursor=!0,this.game.input.onDown.add(this.checkDown,this),this.createDomElement()}return __extends(c,a),c.prototype.createBox=function(a){var b=a.backgroundColor?parseInt(a.backgroundColor.slice(1),16):16777215,c=a.borderRadius||0,d=a.borderColor?parseInt(a.borderColor.slice(1),16):9803157,e=void 0!==a.fillAlpha?a.fillAlpha:1,f=a.height||14;a.font&&(f=Math.max(parseInt(a.font.substr(0,a.font.indexOf("px")),10),f)),f=2*this.padding+f;var g=a.width||150;g=2*this.padding+g,this.box=new Phaser.Graphics(this.game,0,0),this.box.beginFill(b,e).lineStyle(a.borderWidth||1,d,e),c>0?this.box.drawRoundedRect(0,0,g,f,c):this.box.drawRect(0,0,g,f),this.setTexture(this.box.generateTexture())},c.prototype.checkDown=function(a){this.input.checkPointerOver(a)?(this.focus=!0,null!==this.placeHolder&&(this.placeHolder.visible=!1),this.startFocus()):this.focus===!0&&this.endFocus()},c.prototype.createDomElement=function(){var a=this,c=document.getElementById(this.id),d=!1;null===c&&(c=document.createElement("input"),d=!0),c.id=this.id,c.style.position="absolute",c.style.top=(-100).toString()+"px",c.style.left=(-100).toString()+"px",c.value=this.value,this.type===b.password?c.type="password":c.type="text",d&&document.body.appendChild(c),this.callback=function(){return a.keyListener()},document.addEventListener("keyup",this.callback)},c.prototype.removeDomElement=function(){var a=document.getElementById(this.id);document.body.removeChild(a),document.removeEventListener("keyup",this.callback)},c.prototype.update=function(){if(this.focus){if(30!==this.cnt)return this.cnt++;this.cursor.visible=this.blink,this.blink=!this.blink,this.cnt=0}},c.prototype.endFocus=function(){this.focus=!1,0===this.value.length&&null!==this.placeHolder&&(this.placeHolder.visible=!0),this.cursor.visible=!1},c.prototype.startFocus=function(){var a=document.getElementById(this.id);this.game.device.desktop?setTimeout(function(){a.focus()},0):a.focus()},c.prototype.updateText=function(){var a="";if(this.type===b.password)for(var c=0;c<this.value.length;c++)a+="*";else a=this.value;this.text.setText(a),this.cursor.x=this.text.width+this.padding},c.prototype.keyListener=function(){this.value=document.getElementById(this.id).value,this.updateText()},c.prototype.destroy=function(){this.removeDomElement(),a.prototype.destroy.call(this)},c}(Phaser.Sprite);a.InputField=c}(Fabrique||(Fabrique={}));var Fabrique;!function(a){var b;!function(b){var c=function(b){function c(a,c){b.call(this,a,c),this.addInputFieldFactory()}return __extends(c,b),c.prototype.addInputFieldFactory=function(){Phaser.GameObjectFactory.prototype.inputField=function(b,c,d,e){void 0===e&&(e=this.world);var f=new a.InputField(this.game,b,c,d);return e.add(f)},Phaser.GameObjectCreator.prototype.inputField=function(b,c,d){return new a.InputField(this.game,b,c,d)}},c}(Phaser.Plugin);b.InputField=c}(b=a.Plugins||(a.Plugins={}))}(Fabrique||(Fabrique={}));
var __extends=this&&this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);a.prototype=null===b?Object.create(b):(c.prototype=b.prototype,new c)},Fabrique;!function(a){!function(a){a[a.text=0]="text",a[a.password=1]="password",a[a.number=2]="number"}(a.InputType||(a.InputType={}));var b=a.InputType,c=function(a){function c(c,d,e,f){void 0===f&&(f={}),a.call(this,c,d,e),this.placeHolder=null,this.box=null,this.focus=!1,this.type=b.text,this.value="",this.id="phaser-input-"+(1e4*Math.random()|0).toString(),this.blink=!0,this.cnt=0,this.inputOptions=f,this.padding=f.padding||0,this.createBox(f),f.placeHolder&&f.placeHolder.length>0&&(this.placeHolder=new Phaser.Text(c,this.padding,this.padding,f.placeHolder,{font:f.font||"14px Arial",fontWeight:f.fontWeight||"normal",fill:f.placeHolderColor||"#bfbebd"}),this.addChild(this.placeHolder)),this.cursor=new Phaser.Text(c,this.padding,this.padding-2,"|",{font:f.font||"14px Arial",fontWeight:f.fontWeight||"normal",fill:f.cursorColor||"#000000"}),this.cursor.visible=!1,this.addChild(this.cursor),this.text=new Phaser.Text(c,this.padding,this.padding,"",{font:f.font||"14px Arial",fontWeight:f.fontWeight||"normal",fill:f.fill||"#000000"}),this.addChild(this.text),f.type&&(this.type=f.type),this.inputEnabled=!0,this.input.useHandCursor=!0,this.game.input.onDown.add(this.checkDown,this),this.createDomElement()}return __extends(c,a),c.prototype.createBox=function(a){var b=a.backgroundColor?parseInt(a.backgroundColor.slice(1),16):16777215,c=a.borderRadius||0,d=a.borderColor?parseInt(a.borderColor.slice(1),16):9803157,e=void 0!==a.fillAlpha?a.fillAlpha:1,f=a.height||14;a.font&&(f=Math.max(parseInt(a.font.substr(0,a.font.indexOf("px")),10),f)),f=2*this.padding+f;var g=a.width||150;g=2*this.padding+g,this.box=new Phaser.Graphics(this.game,0,0),this.box.beginFill(b,e).lineStyle(a.borderWidth||1,d,e),c>0?this.box.drawRoundedRect(0,0,g,f,c):this.box.drawRect(0,0,g,f),this.setTexture(this.box.generateTexture())},c.prototype.checkDown=function(a){this.input.checkPointerOver(a)?(this.focus=!0,null!==this.placeHolder&&(this.placeHolder.visible=!1),this.startFocus()):this.focus===!0&&this.endFocus()},c.prototype.createDomElement=function(){var a=this,c=document.getElementById(this.id),d=!1;null===c&&(c=document.createElement("input"),d=!0),c.id=this.id,c.style.position="absolute",c.style.top=(-100).toString()+"px",c.style.left=(-100).toString()+"px",c.value=this.value,c.type=b[this.type],!this.inputOptions.maxLength||this.type!==b.text&&this.type!==b.password||(c.maxLength=this.inputOptions.maxLength),this.inputOptions.min&&this.type===b.number&&(c.min=this.inputOptions.min),this.inputOptions.min&&this.type===b.number&&(c.max=this.inputOptions.max),d&&document.body.appendChild(c),this.callback=function(){return a.keyListener()},document.addEventListener("keyup",this.callback)},c.prototype.removeDomElement=function(){var a=document.getElementById(this.id);document.body.removeChild(a),document.removeEventListener("keyup",this.callback)},c.prototype.update=function(){if(this.focus){if(30!==this.cnt)return this.cnt++;this.cursor.visible=this.blink,this.blink=!this.blink,this.cnt=0}},c.prototype.endFocus=function(){this.focus=!1,0===this.value.length&&null!==this.placeHolder&&(this.placeHolder.visible=!0),this.cursor.visible=!1},c.prototype.startFocus=function(){var a=document.getElementById(this.id);this.game.device.desktop?setTimeout(function(){a.focus()},0):a.focus()},c.prototype.updateText=function(){var a="";if(this.type===b.password)for(var c=0;c<this.value.length;c++)a+="*";else if(this.type===b.number){var d=parseInt(this.value);a=d<parseInt(this.inputOptions.min)?this.inputOptions.min:d>parseInt(this.inputOptions.max)?this.inputOptions.max:this.value}else a=this.value;this.text.setText(a),this.cursor.x=this.text.width+this.padding},c.prototype.keyListener=function(){this.value=document.getElementById(this.id).value,this.updateText()},c.prototype.destroy=function(){this.removeDomElement(),a.prototype.destroy.call(this)},c.prototype.resetText=function(){this.value="",document.getElementById(this.id).value=this.value,this.updateText(),this.endFocus()},c}(Phaser.Sprite);a.InputField=c}(Fabrique||(Fabrique={}));var Fabrique;!function(a){var b;!function(b){var c=function(b){function c(a,c){b.call(this,a,c),this.addInputFieldFactory()}return __extends(c,b),c.prototype.addInputFieldFactory=function(){Phaser.GameObjectFactory.prototype.inputField=function(b,c,d,e){void 0===e&&(e=this.world);var f=new a.InputField(this.game,b,c,d);return e.add(f)},Phaser.GameObjectCreator.prototype.inputField=function(b,c,d){return new a.InputField(this.game,b,c,d)}},c}(Phaser.Plugin);b.InputField=c}(b=a.Plugins||(a.Plugins={}))}(Fabrique||(Fabrique={}));
{
"name": "phaser-input",
"author": "OrangeGames",
"version": "0.1.3",
"version": "0.1.4",
"description": "Adds input boxes to Phaser like CanvasInput, but also works for WebGL and Mobile, made for Phaser only.",

@@ -6,0 +6,0 @@ "contributors": [

@@ -69,6 +69,9 @@ Phaser Input

- **placeHolderColor**: string (#000 by default) The color of the placeholder text
- **type**: InputType (text by default) Either text or password
- **type**: InputType (text by default) Either text, password or numeric
- **backgroundColor**: string (#fff by default) The background color of the input box
- **cursorColor**: string (#000 by default) The color of the blinking cursor
- **font**: string (14px Arial by default) The font that is used for the input box, covers the input text, placeholder and cursor
- **maxLength**: number (none by default) The maximum amount of characters allowed, not for number input fields
- **min**: string (none by default) The minimum number for the input field, only for number input fields
- **max**: string (none by default) The maximum number for the input field, only for number input fields

@@ -88,2 +91,7 @@ Browser Support

---------
### 0.1.4
* You can now reset text
* Only nummeric input now also possible as type
* You can now specify a max length (text/password) or min/max (number)
### 0.1.3

@@ -90,0 +98,0 @@ * Fixed an issue where input wouldn't appear on Desktop Firefox and Safari

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc