Your IP : 216.73.216.229


Current Path : /home/jeromecohp/www/aesecure/third/bootstrap-checkbox/js/
Upload File :
Current File : /home/jeromecohp/www/aesecure/third/bootstrap-checkbox/js/bootstrap-checkbox.js

// @file : /third/bootstrap-checkbox/js/bootstrap-checkbox.js
// @version : 2.0.2
// @author : AVONTURE Christophe - christophe@aesecure.com
// @copyright : (C) 2013-2015 - Christophe Avonture - all right reserved.
// @url : http://www.aesecure.com/
// @package : 2015-02-14 13:37:51
// @license : This program is a commercial software.  You CAN'T redistribute it and/or modify it.
// Source code is the property of Christophe Avonture and can't be reused, in whole or in part, in any programs.
'use strict';
(function(factory){
if(typeof define=='function' && define.amd){
define(['jquery'], factory);}
else if(typeof exports=='object'){
module.exports=factory(require('jquery'));}
else {
factory(jQuery);}})(function($){
function Checkboxpicker(element, options){
this.element=element;
this.$element=$(element);
this.options=$.extend({}, $.fn.checkboxpicker.defaults, options, this.$element.data());
if(this.$element.closest('label').length){
console.warn(this.options.warningMessage);
return;}
this.$group=$('<div class="btn-group">');
this.$buttons=$('<a><a>').addClass('btn');var reverse=this.options.reverse || this.options.reverse==='';
this.$off=this.$buttons.eq(reverse?1:0);
this.$on=this.$buttons.eq(reverse?0:1);
this.init();}
Checkboxpicker.prototype={
init: function(){
this.$element.hide();
if(this.options.offLabel){
this.$off.html(this.options.offLabel);}
if(this.options.onLabel){
this.$on.html(this.options.onLabel);}
if(this.options.offIconClass){
this.$off.prepend('<span class="' + this.options.offIconClass + '">');}
if(this.options.onIconClass){
this.$on.prepend('<span class="' + this.options.onIconClass + '">');}
if(this.element.checked){
this.$on.addClass('active ' + this.options.onClass);
this.$off.addClass(this.options.defaultClass);}
else {
this.$off.addClass('active ' + this.options.offClass);
this.$on.addClass(this.options.defaultClass);}
if(this.options.style){
this.$group.addClass(this.options.style);}
if(this.element.title){
this.$group.attr('title', this.element.title);}
else {
if(this.options.offTitle){
this.$off.attr('title', this.options.offTitle);}
if(this.options.onTitle){
this.$on.attr('title', this.options.onTitle);}}
this.$group.keydown(this.keydown.bind(this));
this.$group.on('click','a:not(.active)', this.click.bind(this));
this.$element.change(this.toggle_checked.bind(this));
if(this.element.id){
$('label[for="' + this.element.id + '"]').click(this.focus.bind(this));}
$(this.element.form).on('reset', this.reset.bind(this));
this.$group.append(this.$buttons).insertAfter(this.element);
if(this.element.disabled){
this.$buttons.addClass('disabled');
if(this.options.disabledCursor){
this.$group.css('cursor', this.options.disabledCursor);}}
else {
this.$group.attr('tabindex', this.element.tabIndex);
if(this.element.autofocus){
this.focus();}}},
toggle_checked: function(){
this.$buttons.toggleClass('active ' + this.options.defaultClass);
this.$off.toggleClass(this.options.offClass);
this.$on.toggleClass(this.options.onClass);},
toggle_disabled: function(){
this.$buttons.toggleClass('disabled');
if(this.element.disabled){
this.$group.attr('tabindex', this.element.tabIndex);
this.$group.css('cursor','');}
else {
this.$group.removeAttr('tabindex');
if(this.options.disabledCursor){
this.$group.css('cursor', this.options.disabledCursor);}}},
focus: function(){
this.$group.focus();},
click: function(){
this.change(!this.element.checked);},
change: function(value){
this.element.checked=value;
this.$element.change();},
keydown: function(event){
if(this.options.toggleKeyCodes.indexOf(event.keyCode) !=-1){
event.preventDefault();
this.click();}
else if(event.keyCode==13){
$(this.element.form).submit();}},
reset: function(){
if((this.element.defaultChecked && this.$off.hasClass('active')) || (!this.element.defaultChecked && this.$on.hasClass('active'))){
this.change(this.element.defaultChecked);}}};var oldPropHooks=$.extend({}, $.propHooks);
$.extend($.propHooks, {
checked: {
set: function(elem, value){
var data=$.data(elem,'bs.checkbox');
if(data && elem.checked !=value){
data.change(value);}
if(oldPropHooks.checked && oldPropHooks.checked.set){
oldPropHooks.checked.set(elem, value);}}},
disabled: {
set: function(elem, value){
var data=$.data(elem,'bs.checkbox');
if(data && elem.disabled !=value){
data.toggle_disabled();}
if(oldPropHooks.disabled && oldPropHooks.disabled.set){
oldPropHooks.disabled.set(elem, value);}}}});
$.fn.checkboxpicker=function(options, elements){
var $elements;
if(this instanceof $){
$elements=this;}
else if(typeof options=='string'){
$elements=$(options);}
else {
$elements=$(elements);}
return $elements.each(function(){
var data=$.data(this,'bs.checkbox');
if(!data){
data=new Checkboxpicker(this, options);
$.data(this,'bs.checkbox', data);}});};
$.fn.checkboxpicker.defaults={
style: false,
defaultClass: 'btn-default',
disabledCursor: 'not-allowed',
offClass: 'btn-danger',
onClass: 'btn-success',
offLabel: 'No',
onLabel: 'Yes',
offTitle: false,
onTitle: false,
toggleKeyCodes: [13, 32],
warningMessage: 'Please do not use Bootstrap-checkbox element in label element.'
};
return $.fn.checkboxpicker;});