/
inputNumericHref.js
52 lines (39 loc) · 1.43 KB
/
inputNumericHref.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* This file is part of the QuidPHP package <https://quidphp.com>
* Author: Pierre-Philippe Emond <emondpph@gmail.com>
* License: https://github.com/quidphp/front/blob/master/LICENSE
*/
// inputNumericHref
// script with logic for an input containing a number which triggers a page change
Component.InputNumericHref = function(option)
{
// not empty
if(Vari.isEmpty(this))
return null;
// component
Component.InputNumeric.call(this,option);
Component.HrefReplaceChar.call(this);
// handlers
setHdlr(this,'inputNumericHref:getCurrent',function() {
return getAttr(this,"data-current",'int');
});
setHdlr(this,'inputNumericHref:setCurrent',function() {
setAttr(this,"data-current",value);
});
setHdlr(this,'inputNumeric:getValueRestore',function() {
return trigHdlr(this,'inputNumericHref:getCurrent');
});
setHdlr(this,'inputNumeric:shouldChange',function() {
const current = trigHdlr(this,'inputNumericHref:getCurrent');
const val = trigHdlr(this,'input:getValueInt');
return (val !== current);
});
// redirect
ael(this,'inputNumeric:change',function() {
const val = trigHdlr(this,'input:getValueInt');
const href = trigHdlr(this,'hrefReplaceChar:make',val);
if(Str.isNotEmpty(href))
trigHdlr(document,'history:href',href);
});
return this;
}