/** jquery.onoff - v0.3.6 - 2014-06-23 * https://github.com/timmywil/jquery.onoff * Copyright (c) 2014 Timmy Willison; Licensed MIT */ (function(global, factory) { // AMD if (typeof define === 'function' && define.amd) { define([ 'jquery' ], factory); // CommonJS/Browserify } else if (typeof exports === 'object') { factory(require('jquery')); // Global } else { factory(global.jQuery); } }(this, function($) { 'use strict'; // Common properties to lift for touch or pointer events var list = 'over out down up move enter leave cancel'.split(' '); var hook = $.extend({}, $.event.mouseHooks); var events = {}; // Support pointer events in IE11+ if available if ( window.PointerEvent ) { $.each(list, function( i, name ) { // Add event name to events property and add fixHook $.event.fixHooks[ (events[name] = 'pointer' + name) ] = hook; }); } else { var mouseProps = hook.props; // Add touch properties for the touch hook hook.props = mouseProps.concat(['touches', 'changedTouches', 'targetTouches', 'altKey', 'ctrlKey', 'metaKey', 'shiftKey']); /** * Support: Android * Android sets pageX/Y to 0 for any touch event * Attach first touch's pageX/pageY and clientX/clientY if not set correctly */ hook.filter = function( event, originalEvent ) { var touch; var i = mouseProps.length; if ( !originalEvent.pageX && originalEvent.touches && (touch = originalEvent.touches[0]) ) { // Copy over all mouse properties while(i--) { event[mouseProps[i]] = touch[mouseProps[i]]; } } return event; }; $.each(list, function( i, name ) { // No equivalent touch events for over and out if (i < 2) { events[ name ] = 'mouse' + name; } else { var touch = 'touch' + (name === 'down' ? 'start' : name === 'up' ? 'end' : name); // Add fixHook $.event.fixHooks[ touch ] = hook; // Add event names to events property events[ name ] = touch + ' mouse' + name; } }); } $.pointertouch = events; var count = 1; var slice = Array.prototype.slice; /** * Create an OnOff object for a given element * @constructor * @param {Element} elem - Element to use pan and zoom * @param {Object} [options] - An object literal containing options * to override default options (See OnOff.defaults) */ function OnOff(elem, options) { // Allow instantiation without `new` keyword if (!(this instanceof OnOff)) { return new OnOff(elem, options); } // Sanity checks if (elem.nodeName.toLowerCase() !== 'input' || elem.type !== 'checkbox') { return $.error('OnOff should be called on checkboxes'); } // Don't remake var d = $.data(elem, OnOff.datakey); if (d) { return d; } // Extend default with given object literal // Each instance gets its own options this.options = options = $.extend({}, OnOff.defaults, options); this.elem = elem; this.$elem = $(elem).addClass(options.className); this.$doc = $(elem.ownerDocument || document); // Add guid to event namespace options.namespace += $.guid++; // Add an ID if none has been added if (!elem.id) { elem.id = 'onoffswitch' + count++; } // Enable this.enable(); // Save the instance $.data(elem, OnOff.datakey, this); } OnOff.datakey = '_onoff'; OnOff.defaults = { // The event namespace // Should always be non-empty // Used to bind jQuery events without collisions namespace: '.onoff', // The class added to the checkbox (see the CSS file) className: 'onoffswitch-checkbox' }; OnOff.prototype = { constructor: OnOff, /** * @returns {OnOff} Returns the instance */ instance: function() { return this; }, /** * Wrap the checkbox and add the label element */ wrap: function() { var elem = this.elem; var $elem = this.$elem; var options = this.options; // Get or create elem wrapper var $con = $elem.parent('.onoffswitch'); if (!$con.length) { $elem.wrap('
'); $con = $elem.parent() .addClass(elem.className.replace(options.className, '')); } this.$con = $con; // Get or create label var $label = $elem.next('label[for="' + elem.id + '"]'); if (!$label.length) { $label = $('