diff --git a/css/theme-minimal/jcf.css b/css/theme-minimal/jcf.css index 3105d53..a3f57e8 100755 --- a/css/theme-minimal/jcf.css +++ b/css/theme-minimal/jcf.css @@ -1,383 +1,383 @@ -/* radio */ -.jcf-radio { - vertical-align: middle; - display: inline-block; - position: relative; - overflow: hidden; - cursor: default; - background: #fff; - border: 1px solid #777; - border-radius: 9px; - margin: 0 3px 0 0; - height: 16px; - width: 16px; -} -.jcf-radio span{ - display:none; - position:absolute; - top:3px; - left:3px; - right:3px; - bottom:3px; - background:#777; - border-radius:100%; -} -.jcf-radio input[type="radio"] { - position: absolute; - height: 100%; - width: 100%; - border: 0; - margin: 0; - left: 0; - top: 0; -} -.jcf-radio.jcf-checked span {display:block;} - -/* checkbox */ -.jcf-checkbox { - vertical-align: middle; - display: inline-block; - position: relative; - overflow: hidden; - cursor: default; - background: #fff; - border: 1px solid #777; - margin: 0 3px 0 0; - height: 16px; - width: 16px; -} -.jcf-checkbox span{ - position:absolute; - display:none; - height:4px; - width:8px; - top:50%; - left:50%; - margin:-7px 0 0 -6px; - border:3px solid #777; - border-width:0 0 3px 3px; - -moz-transform: rotate(-45deg); - -ms-transform: rotate(-45deg); - -webkit-transform: rotate(-45deg); - transform: rotate(-45deg); - -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=0.7071067811865483, M12=0.7071067811865467, M21=-0.7071067811865467, M22=0.7071067811865483, SizingMethod='auto expand')"; -} -:root .jcf-checkbox span {margin:-4px 0 0 -5px;} -.jcf-checkbox input[type="checkbox"] { - position: absolute; - width: 100%; - height: 100%; - border: 0; - margin: 0; - left: 0; - top: 0; -} -.jcf-checkbox.jcf-checked span{display:block;} - -/* button */ -.jcf-button { - display: inline-block; - vertical-align: top; - position: relative; - overflow: hidden; - border: 1px solid #777; - background: #fff; - margin: 0 10px 10px 0; - padding: 5px 10px; -} -.jcf-button .jcf-real-element { - position: absolute; - min-height: 100%; - min-width: 100%; - outline: none; - opacity: 0; - padding: 0; - margin: 0; - border: 0; - bottom: 0; - right: 0; - left: 0; - top: 0; -} - -/* file */ -.jcf-file { - display: inline-block; - white-space: nowrap; - position: relative; - overflow: hidden; - background: #fff; -} -.jcf-file .jcf-real-element { - position: absolute; - font-size: 200px; - height: 200px; - margin: 0; - right: 0; - top: 0; -} -.jcf-file .jcf-fake-input { - display: inline-block; - text-overflow:ellipsis; - white-space: nowrap; - vertical-align: top; - overflow: hidden; - border: 1px solid #777; - padding: 0 8px; - font-size: 13px; - line-height: 28px; - height: 28px; - width: 125px; -} -.jcf-file .jcf-upload-button { - display: inline-block; - vertical-align: top; - white-space: nowrap; - overflow: hidden; - border: 1px solid #777; - margin: 0 0 0 -1px; - padding: 0 10px; - line-height: 28px; - height: 28px; -} - -/* scrollbars */ -.jcf-scrollable-wrapper { - box-sizing: content-box; - position: relative; -} -.jcf-scrollbar-vertical { - position: absolute; - cursor: default; - background: #e3e3e3; - width: 14px; - bottom: 0; - right: 0; - top: 0; -} -.jcf-scrollbar-vertical .jcf-scrollbar-dec, -.jcf-scrollbar-vertical .jcf-scrollbar-inc { - background: #bbb; - height: 14px; - width: 14px; - left: 0; - top: 0; -} -.jcf-scrollbar-vertical .jcf-scrollbar-inc { - top: auto; - bottom: 0; -} -.jcf-scrollbar-vertical .jcf-scrollbar-handle { - background: #888; - height: 1px; - width: 14px; -} -.jcf-scrollbar-horizontal { - position: absolute; - background: #e3e3e3; - right: auto; - top: auto; - left: 0; - bottom: 0; - width: 1px; - height: 14px; -} -.jcf-scrollbar-horizontal .jcf-scrollbar-dec, -.jcf-scrollbar-horizontal .jcf-scrollbar-inc { - display: inline-block; - vertical-align: top; - overflow: hidden; - background: #bbb; - height: 14px; - width: 14px; -} -.jcf-scrollbar-horizontal .jcf-scrollbar-inc { - left: auto; - right: 0; -} -.jcf-scrollbar-horizontal .jcf-scrollbar-slider { - display: inline-block; - position: relative; - height: 14px; -} -.jcf-scrollbar-horizontal .jcf-scrollbar-handle { - position: absolute; - background: #888; - height: 14px; -} -.jcf-scrollbar.jcf-inactive .jcf-scrollbar-handle { - visibility: hidden; -} -.jcf-scrollbar.jcf-inactive .jcf-scrollbar-dec, -.jcf-scrollbar.jcf-inactive .jcf-scrollbar-inc { - background: #e3e3e3; -} - -/* select */ -.jcf-select { - display: inline-block; - vertical-align: top; - position: relative; - border: 1px solid #777; - background: #fff; - margin: 0 0 12px; - min-width: 150px; - height: 26px; -} -.jcf-select select { - z-index: 1; - left: 0; - top: 0; -} -.jcf-select .jcf-select-text { - text-overflow:ellipsis; - white-space: nowrap; - overflow: hidden; - cursor: default; - display: block; - font-size: 13px; - line-height: 26px; - margin: 0 35px 0 8px; -} -.jcf-select .jcf-select-opener { - position: absolute; - text-align: center; - background: #aaa; - width: 26px; - bottom: 0; - right: 0; - top: 0; -} -body > .jcf-select-drop { - position: absolute; - margin: -1px 0 0; - z-index: 9999; -} -body > .jcf-select-drop.jcf-drop-flipped { - margin: 1px 0 0; -} -.jcf-select .jcf-select-drop { - position: absolute; - margin-top: 0px; - z-index: 9999; - top: 100%; - left: -1px; - right: -1px; -} -.jcf-select .jcf-drop-flipped { - bottom: 100%; - top: auto; -} -.jcf-select-drop .jcf-select-drop-content { - border: 1px solid #f00; -} - -/* multiple select styles */ -.jcf-list-box { - overflow: hidden; - display: inline-block; - border: 1px solid #b8c3c9; - min-width: 200px; - margin: 0 15px; -} -/* select options styles */ -.jcf-list { - display: inline-block; - vertical-align: top; - position: relative; - background: #fff; - line-height: 14px; - font-size: 12px; - width: 100%; -} -.jcf-list .jcf-list-content { - vertical-align: top; - display: inline-block; - overflow: auto; - width: 100%; -} -.jcf-list ul { - list-style: none; - padding: 0; - margin: 0; -} -.jcf-list ul li { - overflow: hidden; - display: block; -} -.jcf-list .jcf-overflow { - overflow: auto; -} -.jcf-list .jcf-option { - white-space: nowrap; - overflow: hidden; - cursor: default; - display: block; - padding: 5px 9px; - color: #656565; - height: 1%; -} -.jcf-list .jcf-disabled { - background: #fff !important; - color: #aaa !important; -} -.jcf-select-drop .jcf-hover, -.jcf-list-box .jcf-selected { - background: #e6e6e6; - color: #000; -} -.jcf-list .jcf-optgroup-caption { - white-space: nowrap; - font-weight: bold; - display: block; - padding: 5px 9px; - cursor: default; - color: #000; -} -.jcf-list .jcf-optgroup .jcf-option { - padding-left: 30px; -} - -/* other styles */ -.jcf-textarea { - border: 1px solid #b8c3c9; - box-sizing: content-box; - display: inline-block; - position: relative; -} -.jcf-textarea .jcf-scrollbar-horizontal { - display: none; - height: 0; -} -.jcf-textarea textarea { - padding: 8px 10px; - border: none; - margin: 0; -} -.jcf-textarea .jcf-resize { - position: absolute; - text-align: center; - cursor: se-resize; - background: #e3e3e3; - font-weight: bold; - line-height: 15px; - text-indent: 1px; - font-size: 12px; - height: 15px; - width: 14px; - bottom: 0; - right: 0; -} -.jcf-textarea .jcf-resize:before { - border: 1px solid #000; - border-width: 0 1px 1px 0; - display: block; - margin: 4px 0 0 3px; - width: 6px; - height: 6px; - content: ''; -} - -/* common styles */ -.jcf-disabled {background: #ddd !important;} +/* radio */ +.jcf-radio { + vertical-align: middle; + display: inline-block; + position: relative; + overflow: hidden; + cursor: default; + background: #fff; + border: 1px solid #777; + border-radius: 9px; + margin: 0 3px 0 0; + height: 16px; + width: 16px; +} +.jcf-radio span{ + display:none; + position:absolute; + top:3px; + left:3px; + right:3px; + bottom:3px; + background:#777; + border-radius:100%; +} +.jcf-radio input[type="radio"] { + position: absolute; + height: 100%; + width: 100%; + border: 0; + margin: 0; + left: 0; + top: 0; +} +.jcf-radio.jcf-checked span {display:block;} + +/* checkbox */ +.jcf-checkbox { + vertical-align: middle; + display: inline-block; + position: relative; + overflow: hidden; + cursor: default; + background: #fff; + border: 1px solid #777; + margin: 0 3px 0 0; + height: 16px; + width: 16px; +} +.jcf-checkbox span{ + position:absolute; + display:none; + height:4px; + width:8px; + top:50%; + left:50%; + margin:-7px 0 0 -6px; + border:3px solid #777; + border-width:0 0 3px 3px; + -moz-transform: rotate(-45deg); + -ms-transform: rotate(-45deg); + -webkit-transform: rotate(-45deg); + transform: rotate(-45deg); + -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=0.7071067811865483, M12=0.7071067811865467, M21=-0.7071067811865467, M22=0.7071067811865483, SizingMethod='auto expand')"; +} +:root .jcf-checkbox span {margin:-4px 0 0 -5px;} +.jcf-checkbox input[type="checkbox"] { + position: absolute; + width: 100%; + height: 100%; + border: 0; + margin: 0; + left: 0; + top: 0; +} +.jcf-checkbox.jcf-checked span{display:block;} + +/* button */ +.jcf-button { + display: inline-block; + vertical-align: top; + position: relative; + overflow: hidden; + border: 1px solid #777; + background: #fff; + margin: 0 10px 10px 0; + padding: 5px 10px; +} +.jcf-button .jcf-real-element { + position: absolute; + min-height: 100%; + min-width: 100%; + outline: none; + opacity: 0; + padding: 0; + margin: 0; + border: 0; + bottom: 0; + right: 0; + left: 0; + top: 0; +} + +/* file */ +.jcf-file { + display: inline-block; + white-space: nowrap; + position: relative; + overflow: hidden; + background: #fff; +} +.jcf-file .jcf-real-element { + position: absolute; + font-size: 200px; + height: 200px; + margin: 0; + right: 0; + top: 0; +} +.jcf-file .jcf-fake-input { + display: inline-block; + text-overflow:ellipsis; + white-space: nowrap; + vertical-align: top; + overflow: hidden; + border: 1px solid #777; + padding: 0 8px; + font-size: 13px; + line-height: 28px; + height: 28px; + width: 125px; +} +.jcf-file .jcf-upload-button { + display: inline-block; + vertical-align: top; + white-space: nowrap; + overflow: hidden; + border: 1px solid #777; + margin: 0 0 0 -1px; + padding: 0 10px; + line-height: 28px; + height: 28px; +} + +/* scrollbars */ +.jcf-scrollable-wrapper { + box-sizing: content-box; + position: relative; +} +.jcf-scrollbar-vertical { + position: absolute; + cursor: default; + background: #e3e3e3; + width: 14px; + bottom: 0; + right: 0; + top: 0; +} +.jcf-scrollbar-vertical .jcf-scrollbar-dec, +.jcf-scrollbar-vertical .jcf-scrollbar-inc { + background: #bbb; + height: 14px; + width: 14px; + left: 0; + top: 0; +} +.jcf-scrollbar-vertical .jcf-scrollbar-inc { + top: auto; + bottom: 0; +} +.jcf-scrollbar-vertical .jcf-scrollbar-handle { + background: #888; + height: 1px; + width: 14px; +} +.jcf-scrollbar-horizontal { + position: absolute; + background: #e3e3e3; + right: auto; + top: auto; + left: 0; + bottom: 0; + width: 1px; + height: 14px; +} +.jcf-scrollbar-horizontal .jcf-scrollbar-dec, +.jcf-scrollbar-horizontal .jcf-scrollbar-inc { + display: inline-block; + vertical-align: top; + overflow: hidden; + background: #bbb; + height: 14px; + width: 14px; +} +.jcf-scrollbar-horizontal .jcf-scrollbar-inc { + left: auto; + right: 0; +} +.jcf-scrollbar-horizontal .jcf-scrollbar-slider { + display: inline-block; + position: relative; + height: 14px; +} +.jcf-scrollbar-horizontal .jcf-scrollbar-handle { + position: absolute; + background: #888; + height: 14px; +} +.jcf-scrollbar.jcf-inactive .jcf-scrollbar-handle { + visibility: hidden; +} +.jcf-scrollbar.jcf-inactive .jcf-scrollbar-dec, +.jcf-scrollbar.jcf-inactive .jcf-scrollbar-inc { + background: #e3e3e3; +} + +/* select */ +.jcf-select { + display: inline-block; + vertical-align: top; + position: relative; + border: 1px solid #777; + background: #fff; + margin: 0 0 12px; + min-width: 150px; + height: 26px; +} +.jcf-select select { + z-index: 1; + left: 0; + top: 0; +} +.jcf-select .jcf-select-text { + text-overflow:ellipsis; + white-space: nowrap; + overflow: hidden; + cursor: default; + display: block; + font-size: 13px; + line-height: 26px; + margin: 0 35px 0 8px; +} +.jcf-select .jcf-select-opener { + position: absolute; + text-align: center; + background: #aaa; + width: 26px; + bottom: 0; + right: 0; + top: 0; +} +body > .jcf-select-drop { + position: absolute; + margin: -1px 0 0; + z-index: 9999; +} +body > .jcf-select-drop.jcf-drop-flipped { + margin: 1px 0 0; +} +.jcf-select .jcf-select-drop { + position: absolute; + margin-top: 0px; + z-index: 9999; + top: 100%; + left: -1px; + right: -1px; +} +.jcf-select .jcf-drop-flipped { + bottom: 100%; + top: auto; +} +.jcf-select-drop .jcf-select-drop-content { + border: 1px solid #f00; +} + +/* multiple select styles */ +.jcf-list-box { + overflow: hidden; + display: inline-block; + border: 1px solid #b8c3c9; + min-width: 200px; + margin: 0 15px; +} +/* select options styles */ +.jcf-list { + display: inline-block; + vertical-align: top; + position: relative; + background: #fff; + line-height: 14px; + font-size: 12px; + width: 100%; +} +.jcf-list .jcf-list-content { + vertical-align: top; + display: inline-block; + overflow: auto; + width: 100%; +} +.jcf-list ul { + list-style: none; + padding: 0; + margin: 0; +} +.jcf-list ul li { + overflow: hidden; + display: block; +} +.jcf-list .jcf-overflow { + overflow: auto; +} +.jcf-list .jcf-option { + white-space: nowrap; + overflow: hidden; + cursor: default; + display: block; + padding: 5px 9px; + color: #656565; + height: 1%; +} +.jcf-list .jcf-disabled { + background: #fff !important; + color: #aaa !important; +} +.jcf-select-drop .jcf-hover, +.jcf-list-box .jcf-selected { + background: #e6e6e6; + color: #000; +} +.jcf-list .jcf-optgroup-caption { + white-space: nowrap; + font-weight: bold; + display: block; + padding: 5px 9px; + cursor: default; + color: #000; +} +.jcf-list .jcf-optgroup .jcf-option { + padding-left: 30px; +} + +/* other styles */ +.jcf-textarea { + border: 1px solid #b8c3c9; + box-sizing: content-box; + display: inline-block; + position: relative; +} +.jcf-textarea .jcf-scrollbar-horizontal { + display: none; + height: 0; +} +.jcf-textarea textarea { + padding: 8px 10px; + border: none; + margin: 0; +} +.jcf-textarea .jcf-resize { + position: absolute; + text-align: center; + cursor: se-resize; + background: #e3e3e3; + font-weight: bold; + line-height: 15px; + text-indent: 1px; + font-size: 12px; + height: 15px; + width: 14px; + bottom: 0; + right: 0; +} +.jcf-textarea .jcf-resize:before { + border: 1px solid #000; + border-width: 0 1px 1px 0; + display: block; + margin: 4px 0 0 3px; + width: 6px; + height: 6px; + content: ''; +} + +/* common styles */ +.jcf-disabled {background: #ddd !important;} .jcf-focus, .jcf-focus * {border-color: #f00 !important;} \ No newline at end of file diff --git a/index.html b/index.html index 62929b5..eccd676 100755 --- a/index.html +++ b/index.html @@ -1,279 +1,279 @@ - - - - - - JavaScript Custom Forms - - - - - - - - - - - - - - - - - - - -
- -
-

JavaScript Custom Forms

-

This library allows crossbrowser form elements customization using CSS.

-

Supported elements are following: select, checkbox, radio, file input, textarea and scrollbars (and more coming)

- -
- -
-

<select>

-

Select module provides an ability to customize not only select area but also its dropdown. Multiple selects, keyboard navigation and custom scrollbars are supported in the option list.

-
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
-
- - -
-
-
- -
-

Checkboxes and radios

-

Focused and pressed states are also handled.

-
-
- - -
-
- - -
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
- - -
-
-
- -
-

File input

-

Simple file input customization. Custom browse button text, focus/pressed state, selected file extension class.

-
- - -
-
- - -
-
- - -
-
- -
-

Scrollbars

-

Scrollbars can be either vertical or horizontal. Nested scrollbars are supported. Can be applied on textarea.

-
-
- -

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum, officia, facilis, similique voluptates ut assumenda ea ex vero suscipit possimus nihil animi unde dolore in sint error quod consequatur modi!

-

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum, officia, facilis, similique voluptates ut assumenda ea ex vero suscipit possimus nihil animi unde dolore in sint error quod consequatur modi!

-
-
-
- -
-
- -
-

Browser support

-

The script was tested in the following browsers:

- -
- -
-

Usage

-

The script requires jQuery 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:

-
-<script src="js/jquery-1.11.1.js"></script>
-<script src="js/jcf.js"></script>
-<script src="js/jcf.select.js"></script>
-<script src="js/jcf.radio.js"></script>
-<script src="js/jcf.checkbox.js"></script>
-

When the page is loaded all you have to do is simply call the function:

-
-$(function() {
-	jcf.replaceAll();
-});
-
- -
-

License

-

This script is licensed under the MIT License

-

Copyright 2014 PSD2HTML.com

-
- -
- - + + + + + + JavaScript Custom Forms + + + + + + + + + + + + + + + + + + + +
+ +
+

JavaScript Custom Forms

+

This library allows crossbrowser form elements customization using CSS.

+

Supported elements are following: select, checkbox, radio, file input, textarea and scrollbars (and more coming)

+ +
+ +
+

<select>

+

Select module provides an ability to customize not only select area but also its dropdown. Multiple selects, keyboard navigation and custom scrollbars are supported in the option list.

+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+ + +
+
+
+ +
+

Checkboxes and radios

+

Focused and pressed states are also handled.

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ +
+

File input

+

Simple file input customization. Custom browse button text, focus/pressed state, selected file extension class.

+
+ + +
+
+ + +
+
+ + +
+
+ +
+

Scrollbars

+

Scrollbars can be either vertical or horizontal. Nested scrollbars are supported. Can be applied on textarea.

+
+
+ +

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum, officia, facilis, similique voluptates ut assumenda ea ex vero suscipit possimus nihil animi unde dolore in sint error quod consequatur modi!

+

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum, officia, facilis, similique voluptates ut assumenda ea ex vero suscipit possimus nihil animi unde dolore in sint error quod consequatur modi!

+
+
+
+ +
+
+ +
+

Browser support

+

The script was tested in the following browsers:

+ +
+ +
+

Usage

+

The script requires jQuery 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:

+
+<script src="js/jquery-1.11.1.js"></script>
+<script src="js/jcf.js"></script>
+<script src="js/jcf.select.js"></script>
+<script src="js/jcf.radio.js"></script>
+<script src="js/jcf.checkbox.js"></script>
+

When the page is loaded all you have to do is simply call the function:

+
+$(function() {
+	jcf.replaceAll();
+});
+
+ +
+

License

+

This script is licensed under the MIT License

+

Copyright 2014 PSD2HTML.com

+
+ +
+ + \ No newline at end of file diff --git a/js/jcf.checkbox.js b/js/jcf.checkbox.js index ea37bb1..19ce94d 100755 --- a/js/jcf.checkbox.js +++ b/js/jcf.checkbox.js @@ -1,167 +1,167 @@ -/*! - * JavaScript Custom Forms : Checkbox Module - * - * Copyright 2014 PSD2HTML (http://psd2html.com) - * Released under the MIT license (LICENSE.txt) - * - * Version: 1.0.2 - */ -;(function($, window) { - 'use strict'; - - jcf.addModule({ - name: 'Checkbox', - selector: 'input[type="checkbox"]', - options: { - wrapNative: true, - checkedClass: 'jcf-checked', - uncheckedClass: 'jcf-unchecked', - labelActiveClass: 'jcf-label-active', - fakeStructure: '' - }, - matchElement: function(element) { - return element.is(':checkbox'); - }, - init: function(options) { - this.initStructure(); - this.attachEvents(); - this.refresh(); - }, - initStructure: function() { - // prepare structure - this.doc = $(document); - this.realElement = $(this.options.element); - this.fakeElement = $(this.options.fakeStructure).insertAfter(this.realElement); - this.labelElement = this.getLabelFor(); - - if(this.options.wrapNative) { - // wrap native checkbox inside fake block - this.realElement.appendTo(this.fakeElement).css({ - position: 'absolute', - height: '100%', - width: '100%', - opacity: 0, - margin: 0 - }); - } else { - // just hide native checkbox - this.realElement.addClass(this.options.hiddenClass); - } - }, - attachEvents: function() { - // add event handlers - this.realElement.on({ - focus: this.onFocus, - click: this.onRealClick - }); - this.fakeElement.on('click', this.onFakeClick); - this.fakeElement.on('jcf-pointerdown', this.onPress); - }, - onRealClick: function(e) { - // just redraw fake element (setTimeout handles click that might be prevented) - var self = this; - this.savedEventObject = e; - setTimeout(function() { - self.refresh(); - }, 0); - }, - onFakeClick: function(e) { - // skip event if clicked on real element inside wrapper - if(this.options.wrapNative && this.realElement.is(e.target)) { - return; - } - - // toggle checked class - if(!this.realElement.is(':disabled')) { - delete this.savedEventObject; - this.stateChecked = this.realElement.prop('checked'); - this.realElement.prop('checked', !this.stateChecked); - this.fireNativeEvent(this.realElement, 'click'); - if(this.savedEventObject && this.savedEventObject.isDefaultPrevented()) { - this.realElement.prop('checked', this.stateChecked); - } else { - this.fireNativeEvent(this.realElement, 'change'); - } - delete this.savedEventObject; - } - }, - onFocus: function() { - if(!this.pressedFlag || !this.focusedFlag) { - this.focusedFlag = true; - this.fakeElement.addClass(this.options.focusClass); - this.realElement.on('blur', this.onBlur); - } - }, - onBlur: function() { - if(!this.pressedFlag) { - this.focusedFlag = false; - this.fakeElement.removeClass(this.options.focusClass); - this.realElement.off('blur', this.onBlur); - } - }, - onPress: function(e) { - if(!this.focusedFlag && e.pointerType === 'mouse') { - this.realElement.focus(); - } - this.pressedFlag = true; - this.fakeElement.addClass(this.options.pressedClass); - this.doc.on('jcf-pointerup', this.onRelease); - }, - onRelease: function(e) { - if(this.focusedFlag && e.pointerType === 'mouse') { - this.realElement.focus(); - } - this.pressedFlag = false; - this.fakeElement.removeClass(this.options.pressedClass); - this.doc.off('jcf-pointerup', this.onRelease); - }, - getLabelFor: function() { - var parentLabel = this.realElement.closest('label'), - elementId = this.realElement.prop('id'); - - if(!parentLabel.length && elementId) { - parentLabel = $('label[for="' + elementId + '"]'); - } - return parentLabel.length ? parentLabel : null; - }, - refresh: function() { - // redraw custom checkbox - var isChecked = this.realElement.is(':checked'), - isDisabled = this.realElement.is(':disabled'); - - this.fakeElement.toggleClass(this.options.checkedClass, isChecked) - .toggleClass(this.options.uncheckedClass, !isChecked) - .toggleClass(this.options.disabledClass, isDisabled); - - if(this.labelElement) { - this.labelElement.toggleClass(this.options.labelActiveClass, isChecked); - } - }, - destroy: function() { - // restore structure - if(this.options.wrapNative) { - this.realElement.insertBefore(this.fakeElement).css({ - position: '', - width: '', - height: '', - opacity: '', - margin: '' - }); - } else { - this.realElement.removeClass(this.options.hiddenClass); - } - - // removing element will also remove its event handlers - this.fakeElement.off('jcf-pointerdown', this.onPress); - this.fakeElement.remove(); - - // remove other event handlers - this.doc.off('jcf-pointerup', this.onRelease); - this.realElement.off({ - focus: this.onFocus, - click: this.onRealClick - }); - } - }); - +/*! + * JavaScript Custom Forms : Checkbox Module + * + * Copyright 2014 PSD2HTML (http://psd2html.com) + * Released under the MIT license (LICENSE.txt) + * + * Version: 1.0.2 + */ +;(function($, window) { + 'use strict'; + + jcf.addModule({ + name: 'Checkbox', + selector: 'input[type="checkbox"]', + options: { + wrapNative: true, + checkedClass: 'jcf-checked', + uncheckedClass: 'jcf-unchecked', + labelActiveClass: 'jcf-label-active', + fakeStructure: '' + }, + matchElement: function(element) { + return element.is(':checkbox'); + }, + init: function(options) { + this.initStructure(); + this.attachEvents(); + this.refresh(); + }, + initStructure: function() { + // prepare structure + this.doc = $(document); + this.realElement = $(this.options.element); + this.fakeElement = $(this.options.fakeStructure).insertAfter(this.realElement); + this.labelElement = this.getLabelFor(); + + if(this.options.wrapNative) { + // wrap native checkbox inside fake block + this.realElement.appendTo(this.fakeElement).css({ + position: 'absolute', + height: '100%', + width: '100%', + opacity: 0, + margin: 0 + }); + } else { + // just hide native checkbox + this.realElement.addClass(this.options.hiddenClass); + } + }, + attachEvents: function() { + // add event handlers + this.realElement.on({ + focus: this.onFocus, + click: this.onRealClick + }); + this.fakeElement.on('click', this.onFakeClick); + this.fakeElement.on('jcf-pointerdown', this.onPress); + }, + onRealClick: function(e) { + // just redraw fake element (setTimeout handles click that might be prevented) + var self = this; + this.savedEventObject = e; + setTimeout(function() { + self.refresh(); + }, 0); + }, + onFakeClick: function(e) { + // skip event if clicked on real element inside wrapper + if(this.options.wrapNative && this.realElement.is(e.target)) { + return; + } + + // toggle checked class + if(!this.realElement.is(':disabled')) { + delete this.savedEventObject; + this.stateChecked = this.realElement.prop('checked'); + this.realElement.prop('checked', !this.stateChecked); + this.fireNativeEvent(this.realElement, 'click'); + if(this.savedEventObject && this.savedEventObject.isDefaultPrevented()) { + this.realElement.prop('checked', this.stateChecked); + } else { + this.fireNativeEvent(this.realElement, 'change'); + } + delete this.savedEventObject; + } + }, + onFocus: function() { + if(!this.pressedFlag || !this.focusedFlag) { + this.focusedFlag = true; + this.fakeElement.addClass(this.options.focusClass); + this.realElement.on('blur', this.onBlur); + } + }, + onBlur: function() { + if(!this.pressedFlag) { + this.focusedFlag = false; + this.fakeElement.removeClass(this.options.focusClass); + this.realElement.off('blur', this.onBlur); + } + }, + onPress: function(e) { + if(!this.focusedFlag && e.pointerType === 'mouse') { + this.realElement.focus(); + } + this.pressedFlag = true; + this.fakeElement.addClass(this.options.pressedClass); + this.doc.on('jcf-pointerup', this.onRelease); + }, + onRelease: function(e) { + if(this.focusedFlag && e.pointerType === 'mouse') { + this.realElement.focus(); + } + this.pressedFlag = false; + this.fakeElement.removeClass(this.options.pressedClass); + this.doc.off('jcf-pointerup', this.onRelease); + }, + getLabelFor: function() { + var parentLabel = this.realElement.closest('label'), + elementId = this.realElement.prop('id'); + + if(!parentLabel.length && elementId) { + parentLabel = $('label[for="' + elementId + '"]'); + } + return parentLabel.length ? parentLabel : null; + }, + refresh: function() { + // redraw custom checkbox + var isChecked = this.realElement.is(':checked'), + isDisabled = this.realElement.is(':disabled'); + + this.fakeElement.toggleClass(this.options.checkedClass, isChecked) + .toggleClass(this.options.uncheckedClass, !isChecked) + .toggleClass(this.options.disabledClass, isDisabled); + + if(this.labelElement) { + this.labelElement.toggleClass(this.options.labelActiveClass, isChecked); + } + }, + destroy: function() { + // restore structure + if(this.options.wrapNative) { + this.realElement.insertBefore(this.fakeElement).css({ + position: '', + width: '', + height: '', + opacity: '', + margin: '' + }); + } else { + this.realElement.removeClass(this.options.hiddenClass); + } + + // removing element will also remove its event handlers + this.fakeElement.off('jcf-pointerdown', this.onPress); + this.fakeElement.remove(); + + // remove other event handlers + this.doc.off('jcf-pointerup', this.onRelease); + this.realElement.off({ + focus: this.onFocus, + click: this.onRealClick + }); + } + }); + }(jQuery, this)); \ No newline at end of file diff --git a/js/jcf.js b/js/jcf.js index 41f0ef2..e2f3ed4 100755 --- a/js/jcf.js +++ b/js/jcf.js @@ -1,423 +1,423 @@ -/*! - * JavaScript Custom Forms - * - * Copyright 2014 PSD2HTML (http://psd2html.com) - * Released under the MIT license (LICENSE.txt) - * - * Version: 1.0.2 - */ -;(function (root, factory) { - if (typeof define === 'function' && define.amd) { - define(['jquery'], factory); - } else if (typeof exports === 'object') { - module.exports = factory(require('jquery')); - } else { - root.jcf = factory(jQuery); - } -}(this, function ($) { - 'use strict'; - - // private variables - var customInstances = []; - - // default global options - var commonOptions = { - optionsKey: 'jcf', - dataKey: 'jcf-instance', - rtlClass: 'jcf-rtl', - focusClass: 'jcf-focus', - pressedClass: 'jcf-pressed', - disabledClass: 'jcf-disabled', - hiddenClass: 'jcf-hidden', - resetAppearanceClass: 'jcf-reset-appearance', - unselectableClass: 'jcf-unselectable' - }; - - // detect device type - var isTouchDevice = ('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch, - isWinPhoneDevice = /Windows Phone/.test(navigator.userAgent); - commonOptions.isMobileDevice = !!(isTouchDevice || isWinPhoneDevice); - - // create global stylesheet if custom forms are used - var createStyleSheet = function() { - var styleTag = $('