Skip to content

Commit a5d44aa

Browse files
committed
v1.2.0 - destroy & selectText methods
1 parent 2da76e9 commit a5d44aa

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

CanvasInput.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* CanvasInput v1.1.6
2+
* CanvasInput v1.2.0
33
* http://goldfirestudios.com/blog/108/CanvasInput-HTML5-Canvas-Text-Input
44
*
55
* (c) 2013-2015, James Simpson of GoldFire Studios
@@ -978,6 +978,10 @@
978978
sw = self.shadowW,
979979
sh = self.shadowH;
980980

981+
if (!ctx) {
982+
return;
983+
}
984+
981985
// clear the canvas
982986
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
983987

@@ -1094,6 +1098,32 @@
10941098
});
10951099
},
10961100

1101+
/**
1102+
* Destroy this input and stop rendering it.
1103+
*/
1104+
destroy: function() {
1105+
var self = this;
1106+
1107+
// pull from the inputs array
1108+
var index = inputs.indexOf(self);
1109+
if (index) {
1110+
inputs.splice(index, 1);
1111+
}
1112+
1113+
// remove focus
1114+
if (self._hasFocus) {
1115+
self.blur();
1116+
}
1117+
1118+
// remove the hidden input box
1119+
document.body.removeChild(self._hiddenInput);
1120+
1121+
// remove off-DOM canvas
1122+
self._renderCanvas = null;
1123+
self._shadowCanvas = null;
1124+
self._renderCtx = null;
1125+
},
1126+
10971127
/**
10981128
* Draw the text box area with either an image or background color.
10991129
* @param {Function} fn Callback.

0 commit comments

Comments
 (0)