├── .gitignore
├── LICENSE.txt
├── README.md
├── bower.json
├── css
├── demo.css
└── theme-minimal
│ └── jcf.css
├── dist
├── css
│ └── theme-minimal
│ │ └── jcf.css
└── js
│ ├── jcf.angular.js
│ ├── jcf.button.js
│ ├── jcf.checkbox.js
│ ├── jcf.common.js
│ ├── jcf.file.js
│ ├── jcf.js
│ ├── jcf.number.js
│ ├── jcf.radio.js
│ ├── jcf.range.js
│ ├── jcf.scrollable.js
│ ├── jcf.select.js
│ └── jcf.textarea.js
├── gulpfile.js
├── images
├── bg-body.jpg
├── test-icon1.png
├── test-icon2.png
├── test-icon3.png
└── test.png
├── index.html
├── js
├── .jscsrc
├── .jshintrc
├── ie.js
├── jcf.angular.js
├── jcf.button.js
├── jcf.checkbox.js
├── jcf.common.js
├── jcf.file.js
├── jcf.js
├── jcf.number.js
├── jcf.radio.js
├── jcf.range.js
├── jcf.scrollable.js
├── jcf.select.js
├── jcf.textarea.js
└── jquery.js
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright 2014, PSD2HTML (http://psd2html.com)
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # JCF - JavaScript Custom Forms
2 | This library allows crossbrowser customization of form elements using CSS.
3 |
4 | Check [live demo](http://psd2html.com/jcf).
5 |
6 | ## Browser support
7 | The script was tested in the following browsers:
8 |
9 | - Internet Explorer 8+
10 | - Firefox
11 | - Chrome
12 | - Safari
13 | - Opera
14 | - Windows 8+ Touch desktops
15 | - Windows Phone 8+
16 | - Android 4+
17 | - iOS7+
18 |
19 | ## Installation
20 |
21 | Install using [npm](http://npmjs.org/):
22 | `npm install jcf`
23 |
24 | Install using [Bower](http://bower.io/):
25 | `bower install jcf`
26 |
27 | CDN: this library is available at [cdnjs](https://cdnjs.com/)
28 |
29 | ## Usage
30 | The script requires [jQuery 1.7+](http://jquery.com/) to work properly. To add script in your page simply attach core file - `jcf.js` and some of modules you want to use for customization:
31 |
32 | ```html
33 |
34 |
35 |
36 |
37 |
38 | ```
39 |
40 | When the page is loaded all you have to do is simply call function:
41 |
42 | ```js
43 | $(function() {
44 | jcf.replaceAll();
45 | });
46 | ```
47 |
48 | Please note that JCF does not replace original form elements with own components. It just creates additional DOM nodes to support CSS styling. All DOM events are invoked on original elements and in most cases JCF could be easily turned on or off without affecting your existing event listeners.
49 |
50 | ## How to use JCF with AngularJS 1.x
51 |
52 | To use this script with Angular you still need to attach all scripts above (including jQuery) and also attach directive:
53 |
54 | ```js
55 |
56 | ```
57 |
58 | When the directive is connected as dependency in your app you can add `jcf` attribute to the form field and such element will be customized:
59 | ```html
60 |
61 |
64 |
65 |
66 |
67 | ```
68 |
69 | ## General API Information
70 |
71 | Global `jcf` object has several methods to control custom form elements on the page:
72 |
73 | `jcf.replaceAll( [context] )` - Replace elements on the whole page. Optional argument is context to use (can be CSS selector, or DOM/jQuery object). Add class `jcf-ignore` on the element to prevent its customization.
74 |
75 | `jcf.replace( elements [, moduleName] [, customOptions] )` - Replace certain element or multiple elements. Returns custom form element instance. The first argument is CSS selector, or DOM/jQuery object to be customized. Second argument is optional and used to specify module which should be used for customization. By default it is `false` which will result module to be auto detected. Third argument is module options which can be specified with object.
76 |
77 | `jcf.destroyAll( [context] )` - Destroy all custom form elements instances and restore original form elements. Optional argument is context to use (can be CSS selector, or DOM/jQuery object).
78 |
79 | `jcf.destroy( elements )` - Destroy certain element or multiple form elements. Should be applied to native form controls.
80 |
81 | `jcf.refreshAll( [context] )` - Redraw all custom form instances. Should be used when values of form elements are modified by other scripts. Optional argument is context to use (can be CSS selector, or DOM/jQuery object).
82 |
83 | `jcf.refresh( elements )` - Refresh certain element or multiple form elements.
84 |
85 | ## Getting the instance of customized form element
86 | In any time it's possible to get instance of customized form element. Use method `jcf.getInstance` to do this:
87 |
88 | ```javascript
89 | var countrySelect = document.getElementById('country-select');
90 | var customFormInstance = jcf.getInstance(countrySelect);
91 |
92 | customFormInstance.refresh();
93 | ```
94 |
95 | ## Setting Options
96 |
97 | There are two ways of specifying options for modules - override module defaults and specify options per element.
98 |
99 | ```javascript
100 | // set options for Checkbox module
101 | jcf.setOptions('Checkbox', {
102 | checkedClass: 'test',
103 | wrapNative: false
104 | });
105 |
106 | // replace all form elements with modified default options
107 | jcf.replaceAll();
108 | ```
109 |
110 | The second way is to specify options for certain element in HTML:
111 | ``` html
112 |
113 | ```
114 | *(Please be careful and use valid JSON)*
115 |
116 | ## Module Options
117 |
118 | Each module has options. Some of options are common between modules and some are unique. The most commonly used options in modules are listed below.
119 |
120 | ### Select
121 |
122 |
123 |
124 |
125 |
Option
126 |
Description
127 |
Data Type
128 |
Default
129 |
130 |
131 |
132 |
133 |
wrapNative
134 |
Wrap native select inside fake area, so that native dropdown will be shown
135 |
boolean
136 |
true
137 |
138 |
139 |
wrapNativeOnMobile
140 |
Show native dropdown on mobile devices even if wrapNative is false
141 |
boolean
142 |
true
143 |
144 |
145 |
fakeDropInBody
146 |
Active only when custom dropdown is used. Specifies where to append custom dropdown - in document root, or inside select area
147 |
boolean
148 |
true
149 |
150 |
151 |
useCustomScroll
152 |
Use custom scroll inside custom dropdown if Scrollable module present
153 |
boolean
154 |
true
155 |
156 |
157 |
flipDropToFit
158 |
Flip custom dropdown if it does not fit in viewport
159 |
boolean
160 |
true
161 |
162 |
163 |
maxVisibleItems
164 |
How many options should be visible in dropdown before scrollbar appears
165 |
number
166 |
10
167 |
168 |
169 |
170 |
171 | ### Checkbox
172 |
173 |
174 |
175 |
176 |
Option
177 |
Description
178 |
Data Type
179 |
Default
180 |
181 |
182 |
183 |
184 |
wrapNative
185 |
Wrap native checkbox inside fake area for better compatibility with event handlers attached by other scripts
186 |
boolean
187 |
true
188 |
189 |
190 |
checkedClass
191 |
Specify class which will be added to fake area when checkbox is checked
192 |
string
193 |
"jcf-checked"
194 |
195 |
196 |
labelActiveClass
197 |
Specify class which will be added to corresponding <label> when checkbox is checked
198 |
string
199 |
"jcf-label-active"
200 |
201 |
202 |
203 |
204 | ### Radio
205 |
206 |
207 |
208 |
209 |
Option
210 |
Description
211 |
Data Type
212 |
Default
213 |
214 |
215 |
216 |
217 |
wrapNative
218 |
Wrap native radio inside fake area for better compatibility with event handlers attached by other scripts
219 |
boolean
220 |
true
221 |
222 |
223 |
checkedClass
224 |
Specify class which will be added to fake area when radio is checked
225 |
string
226 |
"jcf-checked"
227 |
228 |
229 |
labelActiveClass
230 |
Specify class which will be added to corresponding <label> when radio is checked
231 |
string
232 |
"jcf-label-active"
233 |
234 |
235 |
236 |
237 | ### Number input
238 |
239 |
240 |
241 |
242 |
Option
243 |
Description
244 |
Data Type
245 |
Default
246 |
247 |
248 |
249 |
250 |
pressInterval
251 |
Specify the interval which will control how fast the value is changing while the buttons are pressed.
252 |
number
253 |
150
254 |
255 |
256 |
disabledClass
257 |
Specify class which will be added to arrow buttons when maximum or minimum number is reached
258 |
string
259 |
"jcf-disabled"
260 |
261 |
262 |
263 |
264 | ### Range input
265 |
266 |
267 |
268 |
269 |
Option
270 |
Description
271 |
Data Type
272 |
Default
273 |
274 |
275 |
276 |
277 |
orientation
278 |
Specify range input orientation: "horizontal" or "vertical"
279 |
string
280 |
horizontal
281 |
282 |
283 |
range
284 |
Show range indicator. By default indicator will be shown only for inputs with multiple handles. Possible values are: "min", "max", "all"
285 |
string
286 |
"auto"
287 |
288 |
289 |
minRange
290 |
Works only when multiple slider handles are used. Sets the minimum range value that can be selected between the two handles
291 |
number
292 |
0
293 |
294 |
295 |
dragHandleCenter
296 |
Enable this option to make the cursor stick to the center of the input handle
297 |
boolean
298 |
true
299 |
300 |
301 |
snapToMarks
302 |
Snap input handle to HTML5 datalist marks
303 |
boolean
304 |
true
305 |
306 |
307 |
snapRadius
308 |
Specify snapping radius in pixels
309 |
number
310 |
5
311 |
312 |
313 |
314 |
315 | ### File
316 |
317 |
318 |
319 |
320 |
Option
321 |
Description
322 |
Data Type
323 |
Default
324 |
325 |
326 |
327 |
328 |
buttonText
329 |
Specify default text for upload button (its better to specify this option from HTML for proper localization).
330 |
string
331 |
"Choose file"
332 |
333 |
334 |
placeholderText
335 |
Specify default text for input when no file is selected (its better to specify this option from HTML for proper localization)
336 |
string
337 |
"No file chosen"
338 |
339 |
340 |
341 |
342 | ### Scrollable
343 |
344 |
345 |
346 |
347 |
Option
348 |
Description
349 |
Data Type
350 |
Default
351 |
352 |
353 |
354 |
355 |
handleResize
356 |
Handle resize events so that scrollable area will be responsive
357 |
boolean
358 |
true
359 |
360 |
361 |
alwaysShowScrollbars
362 |
Always show scrollbars event if they cant scroll anything
363 |
boolean
364 |
false
365 |
366 |
367 |
alwaysPreventMouseWheel
368 |
Always prevent mouse wheel scrolling when its used over scrollable element. This way page wont be scrolled even if scrollable area is at the scrolled to the top/bottom.