CLIENT GUI Framework
[vnfsdk/refrepo.git] / portal-common / src / main / webapp / common / thirdparty / uniform / README.md
1 Uniform\r
2 =======\r
3 \r
4 Sexy form elements with jQuery. Now with HTML5 attributes!\r
5 \r
6 Version 2.1.1\r
7 \r
8 Works well with jQuery 1.6+, but we've received patches and heard that this works with jQuery 1.3.\r
9 \r
10 Licensed under the [MIT License](http://www.opensource.org/licenses/mit-license.php)\r
11 \r
12 \r
13 Installation\r
14 ------------\r
15 \r
16 Installation of Uniform is quite simple. First, make sure you have jQuery installed. Then you’ll want to link to the jquery.uniform.js file and uniform.default.css in the head area of your page.  Here's what your `<head>` tag contents should probably contain:\r
17 \r
18     <!-- Make sure your CSS file is listed before jQuery -->\r
19         <link rel="stylesheet" href="uniform.default.css" media="screen" />\r
20         <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>\r
21         <script src="jquery.uniform.js"></script>\r
22 \r
23 This relies upon a copy of jquery.uniform.js, uniform.default.css and the various images all being available on your webserver.\r
24 \r
25 \r
26 Basic usage\r
27 -----------\r
28 \r
29 Using Uniform is easy. Simply tell it what elements to style:\r
30 \r
31         // Style all <select> elements\r
32         $("select").uniform();\r
33 \r
34 To "uniform" all possible form elements, just do something like this.  Things that can't get styled appropriately will be skipped by Uniform.\r
35 \r
36         // Style everything\r
37         $("select, input, a.button, button").uniform();\r
38 \r
39 You can exclude elements too by using more jQuery selectors or methods:\r
40 \r
41         // Avoid styling some elements\r
42         $("select").not(".skip_these").uniform();  // Method 1\r
43         $('select[class!="skip_these"]').uniform();  // Method 2\r
44 \r
45 A complete set of tags in the HEAD section of your site can therefore look like this:\r
46 \r
47     <!-- Make sure your CSS file is listed before jQuery -->\r
48         <link rel="stylesheet" href="uniform.default.css" media="screen" />\r
49         <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>\r
50         <script src="jquery.uniform.js"></script>\r
51         <script type='text/javascript'>\r
52                 // On load, style typical form elements\r
53                 $(function () {\r
54                         $("select, input, button").uniform();\r
55                 });\r
56         </script>\r
57 \r
58 \r
59 Extra parameters\r
60 ----------------\r
61 \r
62 You can pass in extra parameters to control certain aspects of Uniform. To pass in parameters, use syntax like what is seen here.  This only changes the settings for the elements that are actually uniformed in this particular call.\r
63 \r
64     $("select").uniform({\r
65       param1: value,\r
66       param2: value,\r
67       param3: value\r
68     });\r
69 \r
70 There is a separate listing of global defaults.  You access them by using the `defaults` property.  *Note: This property name changed in v2.0.*\r
71 \r
72     $.uniform.defaults.checkedClass = "uniformCheckedClass";\r
73         $.uniform.defaults.fileBtnHtml = "Pick a file";\r
74 \r
75 Uniform v1.x had a bug where setting values in the call to `.uniform()` also potentially reset the defaults and redrew other uniformed objects with new settings.  As of version 2.0.0 the global defaults are now completely separate from the settings passed to every `.uniform()` call.  Extra parameters defined when instantiating Uniform are not global and can't be recalled from `$.uniform.defaults` later.\r
76 \r
77 ### activeClass (string)\r
78 \r
79 *Default:* "active"\r
80 \r
81 Sets the class given to elements when they are active (pressed).\r
82 \r
83     $("select").uniform({activeClass: 'myActiveClass'});\r
84 \r
85 ### autoHide (boolean)\r
86 \r
87 *Default:* true\r
88 \r
89 If this option is set to true, Uniform will hide the new elements if the existing elements are currently hidden using `display: none`.\r
90 \r
91 If you want to show a select or checkbox you'll need to show the new Uniform div instead of the child element.\r
92 \r
93 ### buttonClass (string)\r
94 \r
95 *Default:* "button"\r
96 \r
97 Sets the class given to a button that's been Uniformed\r
98 \r
99     $("input[type=button]").uniform({buttonClass: 'myBtnClass'});\r
100 \r
101 ### checkboxClass (string)\r
102 \r
103 *Default:* "checker"\r
104 \r
105 Sets the class given to the wrapper div for checkbox elements.\r
106 \r
107     $(":checkbox").uniform({checkboxClass: 'myCheckClass'});\r
108 \r
109 ### checkedClass (string)\r
110 \r
111 *Default:* "checked"\r
112 \r
113 Sets the class given to elements when they are checked (radios and checkboxes).\r
114 \r
115     $(":radio, :checkbox").uniform({checkedClass: 'myCheckedClass'});\r
116 \r
117 ### disabledClass (string)\r
118 \r
119 *Default:* "disabled"\r
120 \r
121 Sets the class given to elements when they are disabled.\r
122 \r
123     $("select").uniform({disabledClass: 'myDisabledClass'});\r
124 \r
125 ### eventNamespace (string)\r
126 \r
127 *Default:* ".uniform"\r
128 \r
129 Binds events using this namespace with jQuery.  Useful if you want to unbind them later.  Shouldn't probably need to be changed unless it conflicts with other code.\r
130 \r
131     $("select").uniform({eventNamespace: '.uniformEvents'});\r
132 \r
133 ### fileButtonClass (string)\r
134 \r
135 *Default:* "action"\r
136 \r
137 Sets the class given to div inside a file upload container that acts as the "Choose file" button.\r
138 \r
139     $(":file").uniform({fileButtonClass: 'myFileBtnClass'});\r
140 \r
141 ### fileButtonHtml (string)\r
142 \r
143 *Default:* "Choose File"\r
144 \r
145 Sets the text written on the action button inside a file upload input.\r
146 \r
147     $(":file").uniform({fileButtonHtml: 'Choose &hellip;'});\r
148 \r
149 ### fileClass (string)\r
150 \r
151 *Default:* "uploader"\r
152 \r
153 Sets the class given to the wrapper div for file upload elements.\r
154 \r
155     $(":file").uniform({fileClass: 'myFileClass'});\r
156 \r
157 ### fileDefaultHtml (string)\r
158 \r
159 *Default:* "No file selected"\r
160 \r
161 Sets the text written in the filename div of a file upload input when there is no file selected.\r
162 \r
163     $(":file").uniform({fileDefaultHtml: 'Select a file please'});\r
164 \r
165 ### filenameClass (string)\r
166 \r
167 *Default:* "filename"\r
168 \r
169 Sets the class given to div inside a file upload container that spits out the filename.\r
170 \r
171     $(":file").uniform({filenameClass: 'myFilenameClass'});\r
172 \r
173 ### focusClass (string)\r
174 \r
175 *Default:* "focus"\r
176 \r
177 Sets the class given to elements when they are focused.\r
178 \r
179     $("select").uniform({focusClass: 'myFocusClass'});\r
180 \r
181 ### hoverClass (string)\r
182 \r
183 *Default:* "hover"\r
184 \r
185 Sets the class given to elements when they are currently hovered.\r
186 \r
187     $("select").uniform({hoverClass: 'myHoverClass'});\r
188 \r
189 ### idPrefix (string)\r
190 \r
191 *Default:* "uniform"\r
192 \r
193 If useID is set to true, this string is prefixed to element ID’s and attached to the container div of each Uniformed element. If you have a checkbox with the ID of "remember-me" the container div would have the ID "uniform-remember-me".\r
194 \r
195     $("select").uniform({idPrefix: 'container'});\r
196 \r
197 ### inputAddTypeAsClass (boolean)\r
198 \r
199 *Default:* true\r
200 \r
201 When true, `<input>` elements will get a class applied that is equal to their "type" attribute.\r
202 \r
203     $("input").uniform({inputAddTypeAsClass: true});\r
204 \r
205 ### inputClass (string)\r
206 \r
207 *Default:* "uniform-input"\r
208 \r
209 Applies this class to all input elements when they get uniformed.\r
210 \r
211     $("input").uniform({inputClass: "inputElement"});\r
212 \r
213 ### radioClass (string)\r
214 \r
215 *Default:* "radio"\r
216 \r
217 Sets the class given to the wrapper div for radio elements.\r
218 \r
219     $(":radio").uniform({radioClass: 'myRadioClass'});\r
220 \r
221 ### resetDefaultHtml (string)\r
222 \r
223 *Default:* "Reset"\r
224 \r
225 This text is what's shown on form reset buttons.  It is very similar to submitDefaultHtml.\r
226 \r
227     $("input[type='reset']).uniform({resetDefaultHtml: "Clear"});\r
228 \r
229 ### resetSelector (boolean/string)\r
230 \r
231 *Default:* false\r
232 \r
233 This parameter allows you to use a jQuery-style selector to point to a "reset" button in your form if you have one. Use false if you have no "reset" button, or a selector string that points to the reset button if you have one.\r
234 \r
235     $("select").uniform({resetSelector: 'input[type="reset"]'});\r
236 \r
237 ### selectAutoWidth (boolean)\r
238 \r
239 *Default:* true\r
240 \r
241 If this option is set to true, Uniform will try to fit the select width to the actual content.  When false, it forces the selects to all be the width that was specified in the theme.\r
242 \r
243 When using auto widths, the size of the element is detected, then wrapped by Uniform and expanded to fit the wrapping.\r
244 \r
245 If you want to specify a size of a select element and then have Uniform wrap it appropriately, there will be some difficulty.  The size of the element needs to get detected and then will be changed by Uniform.  For this to happen, it is suggested you do one of these solutions when you have issues.\r
246 \r
247  * Set a custom inline width for the element (`<select style="width:XXpx">`)\r
248  * Use two css rules; `select { width: XXpx }` and `.selector select { width: 100% }`\r
249 \r
250 If the select is empty and later populated via JavaScript, you can do one the following:\r
251 \r
252  * Set a custom inline width for the element (`<select style="width:XXpx">`)\r
253  * Uniform the element after it was loaded with options\r
254  * Use `$('select').uniform.restore().uniform()` to reapply Uniform to the selects that change\r
255 \r
256 ### selectClass (string)\r
257 \r
258 *Default:* "selector"\r
259 \r
260 Sets the class given to the wrapper div for select elements, but not multiselects.\r
261 \r
262     $("select").uniform({selectClass: 'mySelectClass'});\r
263 \r
264 ### selectMultiClass (string)\r
265 \r
266 *Default:* "uniform-multiselect"\r
267 \r
268 Sets the class given to the wrapper div for select elements that are multiselects.\r
269 \r
270     $("select").uniform({selectMultiClass: 'myMultiSelectClass'});\r
271 \r
272 ### submitDefaultHtml (string)\r
273 \r
274 *Default:* "Submit"\r
275 \r
276 This text is what's shown on form submit buttons.  It is very similar to resetDefaultHtml.\r
277 \r
278     $("input[type='submit']).uniform({resetDefaultHtml: "Submit Form"});\r
279 \r
280 ### textareaClass (string)\r
281 \r
282 *Default:* "uniform"\r
283 \r
284 The class that is applied to textarea elements.\r
285 \r
286     $("textarea").uniform({textareaClass: "myTextareaClass"});\r
287 \r
288 ### useID (boolean)\r
289 \r
290 *Default:* true\r
291 \r
292 If true, sets an ID on the container div of each form element. The ID is a prefixed version of the same ID of the form element.\r
293 \r
294     $("select").uniform({useID: false});\r
295 \r
296 ### wrapperClass (string)\r
297 \r
298 *Default:* null\r
299 \r
300 When uniforming, the top level element that wraps the input is given this class.  When elements would not normally be given a wrapper element, this option will create a wrapper element anyway.  This can really help with running multiple themes on a single page.\r
301 \r
302     $('input.blue').uniform({wrapperClass: "blueTheme"});\r
303         $('input').uniform({wrapperClass: "defaultTheme"});\r
304 \r
305 \r
306 Additional Functions And Properties\r
307 -----------------------------------\r
308 \r
309 In addition to the parameters, there are a couple of other ways you can interact with Uniform.\r
310 \r
311 ### $.uniform.update([elem/selector string]);\r
312 \r
313 If you need to change values on the form dynamically you must tell Uniform to update that element’s style. Fortunately, it’s very simple. Just call this function, and Uniform will do the rest.\r
314 \r
315     $.uniform.update("#myUpdatedCheckbox");\r
316 \r
317 If you don't mind updating all Uniformed elements or just don’t specifically know which element to update, you can just leave out the parameter (see below) and Uniform will update all Uniformed elements on the page:\r
318 \r
319     $.uniform.update();\r
320 \r
321 ### $.uniform.restore([elem/selector string]);\r
322 \r
323 If you want to "un-uniform" something, simply call this function. It will remove the inline styles, extra dom elements, and event handlers, effectively restoring the element to it's previous state.\r
324 \r
325     $.uniform.restore("select");\r
326 \r
327 ### $.uniform.elements[]\r
328 \r
329 You can get an array of all the elements that have been Uniformed at any time using this public variable.  I don't advise changing the contents!\r
330 \r
331     var uniforms = $.uniform.elements;\r
332 \r
333 \r
334 Customizing CSS\r
335 ---------------\r
336 \r
337 To edit the CSS of Uniform it is highly recommended to not edit the theme files, but to override them using CSS. Make sure your CSS file comes after the Uniform theme css file in the HEAD section.\r
338 \r
339 It's common to want to resize the selects or other elements. The best way is to set the width property on the div element, span element and the form element itself. Resizing "select" lists is a bit tougher as you need to change the line height. I suggest looking at the _base theme's SCSS file to see where the various width and height variables are used.\r
340 \r
341 If you'd like to create your own theme, take a peek at theme-kit/README.md.  It's on [github](https://github.com/pixelmatrix/uniform) and included in the [theme kit](http://uniformjs.org/downloads/theme-kit.zip).\r
342 \r
343 \r
344 Tips & Tricks\r
345 -------------\r
346 \r
347 Uniform is supposed to be pretty simple, but there are a few things that can be tricky. Here are some tips that may make your experience simpler:\r
348 \r
349 * Remember to change the CSS classes in the theme if you change the parameters for elements’ classes. This can be tedious work, but if you don’t do it, it’s not going to look correct. Find and Replace is your friend.\r
350 \r
351 * Uniform cannot automatically sniff out dynamic value changes. If you make changes to elements in JavaScript or using a reset button of some kind, remember to call $.uniform.update(); to sync the changes with Uniform.  See [Issue #270](https://github.com/pixelmatrix/uniform/issues/270) for the little bit of code you will need.\r
352 \r
353 * Likewise, when you add elements to the DOM, perhaps via AJAX, and they need to get styled, you will need to use $('#newElement').uniform() on it so the styling is applied.\r
354 \r
355 * Uniform is disabled in IE6. It’s not possible to fix due to the way IE6 handles form elements. If you care about IE6 users, give it a quick look to make sure your "naked" form elements look alright in there.\r
356 \r
357 * There is a bug in Safari 5.1 that will cause the web rendering process to crash when you use custom fonts.  For more information, see [Issue #183](https://github.com/pixelmatrix/uniform/issues/183).\r
358 \r
359 * With IE 7-9, sometimes the "change" event doesn't get fired or doesn't get triggered at the right time.  When we detect a change, Uniform may submit its own "change" event on the element.  See [Issue #152](https://github.com/pixelmatrix/uniform/issues/152) and [Issue #238](https://github.com/pixelmatrix/uniform/issues/238).\r
360 \r
361 * With IE9, you may have problems with some fonts on your site.  See [Issue #226](https://github.com/pixelmatrix/uniform/issues/226) if you mysteriously see a blank page or blank form elements.  The fonts in Uniform have been arranged to work around this, but custom themes may not work properly.\r
362 \r
363 * If you have ideas, or bugs, please post them in [GitHub](https://github.com/pixelmatrix/uniform). We rely on our users' for improvement ideas and bug reports. Without your participation, Uniform will stay static.\r
364 \r
365 * If you are having problems with automatically sized select elements in Firefox, double check and ensure your CSS files are listed before jQuery, Uniform and your code that uniforms the form elements.  Also check the selectAutoWidth property's documentation.\r
366 \r
367 \r
368 Upgrading To 2.0 And Later\r
369 --------------------------\r
370 \r
371 Your sprite map will now support many new things and will need to be updated.  If you use custom backgrounds that are not in the sprite map, those will need updating as well.\r
372 \r
373 The uniform.options object was renamed to uniform.defaults since they are the default options.  Other properties were renamed to be consistent or have less ambiguous names, such as `fileBtnClass` becoming `fileButtonClass`.\r
374 \r
375 Previously, calls to update() would render all elements with the most recent set of options.  This has been fixed, but may change how your page looks.  Test to make sure things still render as expected.\r
376 \r
377 $.uniform.noSelect is no longer exposed and has been updated to version 1.0.3.\r
378 \r
379 $.uniform.restore() does not need to be global; you now can use $('#myId').uniform.restore() instead to just restore some elements.  Same thing for updates.\r
380 \r
381 The sprite changed a bit.  The caps for select lists were moved to the left-hand side.  Button theming was added and the file upload images were reordered to match the select list order.  See the theme-kit/README.md file for further reading on this topic.\r
382 \r
383 \r
384 Reporting Bugs\r
385 --------------\r
386 \r
387 It sure would be handy if you could create a test page to help illustrate bugs.  When you use the <a href="https://github.com/pixelmatrix/uniform/issues">GitHub Issue Tracker</a>, you could clone this [bug template gist](https://gist.github.com/4328659) or use [this jsfiddle](http://jsfiddle.net/fidian/JNCFP/) to help illustrate your point.\r
388 \r
389 Even if you don't do that, all sorts of feedback is welcome, but narrowing down your problem or providing an example would immediately help narrow down the problem quickly.\r