js/payone/core/sepa_input.js   A
last analyzed

Complexity

Total Complexity 7
Complexity/F 1.4

Size

Lines of Code 67
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
dl 0
loc 67
rs 10
c 1
b 0
f 0
cc 0
nc 1
mnd 1
bc 9
fnc 5
bpm 1.8
cpm 1.4
noi 2

4 Functions

Rating   Name   Duplication   Size   Complexity  
A sepa_input.js ➔ inputToUppaerCaseAndNumbers 0 6 1
A sepa_input.js ➔ getCaretPos 0 13 2
A sepa_input.js ➔ setCaretPos 0 14 2
A sepa_input.js ➔ inputToNumbers 0 6 1
1
/**
2
 *
3
 * NOTICE OF LICENSE
4
 *
5
 * This source file is subject to the GNU General Public License (GPL 3)
6
 * that is bundled with this package in the file LICENSE.txt
7
 *
8
 * DISCLAIMER
9
 *
10
 * Do not edit or add to this file if you wish to upgrade Payone_Core to newer
11
 * versions in the future. If you wish to customize Payone_Core for your
12
 * needs please refer to http://www.payone.de for more information.
13
 *
14
 * @category        Payone
15
 * @package         js
16
 * @subpackage      payone
17
 * @copyright       Copyright (c) 2012 <[email protected]> - www.noovias.com
18
 * @author          Matthias Walter <[email protected]>
19
 * @license         <http://www.gnu.org/licenses/> GNU General Public License (GPL 3)
20
 * @link            http://www.noovias.com
21
 */
22
23
/**
24
 *
25
 * @param input
26
 */
27
function inputToUpperCase(input) 
28
{
29
    var caretPosition = getCaretPos(input);
30
    input.value = input.value.toUpperCase().replace(/\s/g, '');
31
    setCaretPos(input, caretPosition);
32
}
33
34
/**
35
 *
36
 * @param input
37
 */
38
function inputToUppaerCaseAndNumbers(input) 
39
{
40
    var caretPosition = getCaretPos(input);
41
    input.value = input.value.toUpperCase().replace(/\W|[_]/g, '');
42
    setCaretPos(input, caretPosition);
43
}
44
45
/**
46
 *
47
 * @param input
48
 */
49
function inputToNumbers(input) 
50
{
51
    var caretPosition = getCaretPos(input);
52
    input.value = input.value.replace(/\D/g, '');
53
    setCaretPos(input, caretPosition);
54
}
55
56
/**
57
 *
58
 * @param oField
59
 * @returns {number}
60
 */
61
function getCaretPos(oField) 
62
{
63
    var iCaretPos = 0;
64
    if (Prototype.Browser.IE) {
0 ignored issues
show
Bug introduced by
The variable Prototype seems to be never declared. If this is a global, consider adding a /** global: Prototype */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
65
        var oSel = document.selection.createRange();
66
        oSel.moveStart('character', -oField.value.length);
67
        iCaretPos = oSel.text.length;
68
    } else {
69
        iCaretPos = oField.selectionEnd;
70
    }
71
72
    return iCaretPos;
73
}
74
75
/**
76
 *
77
 * @param oField
78
 * @param iCaretPos
79
 */
80
function setCaretPos(oField, iCaretPos) 
81
{
82
    if (Prototype.Browser.IE) {
0 ignored issues
show
Bug introduced by
The variable Prototype seems to be never declared. If this is a global, consider adding a /** global: Prototype */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
83
        var oSel = document.selection.createRange();
84
        oSel.moveStart('character', -oField.value.length);
85
        oSel.moveStart('character', iCaretPos);
86
        oSel.moveEnd('character', 0);
87
        oSel.select();
88
    } else {
89
        oField.selectionStart = iCaretPos;
90
        oField.selectionEnd = iCaretPos;
91
        oField.focus();
92
    }
93
}