forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap-maxlength.d.ts
158 lines (150 loc) · 6.21 KB
/
bootstrap-maxlength.d.ts
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Type definitions for bootstrap-maxlength v1.7.0
// Project: https://github.com/mimo84/bootstrap-maxlength
// Definitions by: Dan Manastireanu <https://github.com/danmana>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../jquery/jquery.d.ts" />
declare module BootstrapMaxlength {
/**
* Possible options for the position of the counter. (passed to $.fn.css)
*/
interface PlacementOptions {
/**
* The top position of the counter (Number of pixels, or a px or percent string)
*/
top?: Number | string,
/**
* The right position of the counter (Number of pixels, or a px or percent string)
*/
right?: Number | string,
/**
* The bottom position of the counter (Number of pixels, or a px or percent string)
*/
bottom?: Number | string,
/**
* The left position of the counter (Number of pixels, or a px or percent string)
*/
left?: Number | string,
/**
* The positioning to use. For example 'relative', 'absolute'
*/
position?: string
}
/**
* Representation of the current input position
*/
interface PositionParam {
top: Number,
right: Number,
bottom: Number,
left: Number,
width: Number,
height: Number
}
export interface Options {
/**
* If true the threshold will be ignored and the remaining length indication will be always showing up while typing or on focus on the input
* @default false
*/
alwaysShow?: Boolean,
/**
* This is a number indicating how many chars are left to start displaying the indications
* @default 10
*/
threshold?: Number,
/**
* It's the class of the element with the indicator. By default is the bootstrap "label label-success" but can be changed to anything you'd like.
* @default 'label label-success'
*/
warningClass?: string,
/**
* It's the class the element gets when the limit is reached. Default is "label label-important label-danger" (to support Bootstrap 2 and 3).
* @default 'label label-important label-danger'
*/
limitReachedClass?: string,
/**
* Represents the separator between the number of typed chars and total number of available chars.
* @default ' / '
*/
separator?: string,
/**
* Is a string of text that can be outputted in front of the indicator.
* @default ''
*/
preText?: string,
/**
* Is a string outputted after the indicator.
* @default ''
*/
postText?: string,
/**
* If false, will display just the number of typed characters, e.g. will not display the max length.
* @default true
*/
showMaxLength?: Boolean,
/**
* If false, will display just the remaining length, e.g. will display remaining lenght instead of number of typed characters.
* @default true
*/
showCharsTyped?: Boolean,
/**
* Is a string, define where to output the counter.
* Options: bottom, left, top, right, bottom-right, top-right, top-left, bottom-left and centered-right
* @default 'bottom'
*/
placement?: string | PlacementOptions | ((currentInput: JQuery, maxLengthIndicator: JQuery, currentInputPosition: PositionParam) => void),
/**
* Appends the maxlength indicator badge to the parent of the input rather than to the body.
* @default false
*/
appendToParent?: boolean,
/**
* An alternative way to provide the message text.
* String example: 'You have typed %charsTyped% chars, %charsRemaining% of %charsTotal% remaining'.
* %charsTyped%, %charsRemaining% and %charsTotal% will be replaced by the actual values. This overrides the options separator, preText, postText and showMaxLength.
* Alternatively you may supply a function that the current text and max length and returns the string to be displayed.
* Function example: function(currentText, maxLength) { return '' + Math.ceil(currentText.length / 160) + ' SMS Message(s)'; }
* @default null
*/
message?: string | ((currentText : string, maxLength: Number) => string),
/**
* If true the input will count using utf8 bytesize/encoding. For example: the '£' character is counted as two characters.
* @default false
*/
utf8?: boolean,
/**
* Shows the badge as soon as it is added to the page, similar to alwaysShow
* @default false
*/
showOnReady?: boolean,
/**
* Count linebreak as 2 characters to match IE/Chrome textarea validation. As well as DB storage.
* @default true
*/
twoCharLinebreak?: boolean,
/**
* Allows a custom attribute to display indicator without triggering native maxlength behaviour.
* Ignored if value greater than a native maxlength attribute.
* 'overmax' class gets added when exceeded to allow user to implement form validation.
* @default null (use the maxlength attribute and browser functionality)
*/
customMaxAttribute?: string,
/**
* Will allow the input to be over the customMaxLength. Useful in soft max situations.
* @default false
*/
allowOverMax?: boolean,
/**
* If the browser doesn't support the maxlength attribute, attempt to type more than
* the indicated chars, will be prevented.
* @default false
*/
validate?: boolean
}
}
interface JQuery {
/** Apply the maxlength plugin on the selected elemens */
maxlength(options?: BootstrapMaxlength.Options): JQuery;
on(events: 'maxlength.shown', handler: (eventObject: JQueryEventObject, ...args: any[]) => any): JQuery;
on(events: 'maxlength.hidden', handler: (eventObject: JQueryEventObject, ...args: any[]) => any): JQuery;
trigger(eventType: 'maxlength.reposition', extraParameters?: any[]|Object): JQuery;
}