mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Some client side input validation
This commit is contained in:
@@ -18,14 +18,29 @@ const Startup = (() => {
|
|||||||
var height = Util.getValue('size-height' + splashPostfix);
|
var height = Util.getValue('size-height' + splashPostfix);
|
||||||
var selectedPalette = Util.getText('palette-button' + splashPostfix);
|
var selectedPalette = Util.getText('palette-button' + splashPostfix);
|
||||||
|
|
||||||
|
if (!(validator(width) && validator(height))) {
|
||||||
|
Util.setValue('size-width' + splashPostfix, 64);
|
||||||
|
Util.setValue('size-height' + splashPostfix, 64);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
newPixel(FileManager.defaultLPE(width,height));
|
newPixel(FileManager.defaultLPE(width,height));
|
||||||
resetInput();
|
resetInput();
|
||||||
|
|
||||||
|
|
||||||
//track google event
|
//track google event
|
||||||
if (typeof ga !== 'undefined')
|
if (typeof ga !== 'undefined')
|
||||||
ga('send', 'event', 'Pixel Editor New', selectedPalette, width+'/'+height); /*global ga*/
|
ga('send', 'event', 'Pixel Editor New', selectedPalette, width+'/'+height); /*global ga*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function validator(param) {
|
||||||
|
if (Number.isNaN(param) || param.includes('.')) return false
|
||||||
|
const num = parseInt(param)
|
||||||
|
if (param != num) return false
|
||||||
|
if (num && num > 0 && num <= 5000) return true
|
||||||
|
else return false
|
||||||
|
}
|
||||||
|
|
||||||
/** Creates a new, empty file
|
/** Creates a new, empty file
|
||||||
*
|
*
|
||||||
* @param {*} lpe If lpe != null, then the newPixel is being called from the open menu
|
* @param {*} lpe If lpe != null, then the newPixel is being called from the open menu
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
<h2>Size</h2>
|
<h2>Size</h2>
|
||||||
<div class="sp-np-entry">
|
<div class="sp-np-entry">
|
||||||
<input id="size-width-splash" value="{{#if width}}{{width}}{{else}}64{{/if}}" autocomplete="off" />{{svg "x.svg" width="16" height="16" class="dimentions-x"}}<input id="size-height-splash" value="{{#if height}}{{height}}{{else}}64{{/if}}" autocomplete="off" />
|
<input id="size-width-splash" value="{{#if width}}{{width}}{{else}}64{{/if}}" autocomplete="off" pattern="[0-9]" type="number"/>{{svg "x.svg" width="16" height="16" class="dimentions-x"}}<input id="size-height-splash" value="{{#if height}}{{height}}{{else}}64{{/if}}" autocomplete="off" pattern="[0-9]" type="number"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2>Palette</h2>
|
<h2>Palette</h2>
|
||||||
|
|||||||
Reference in New Issue
Block a user