Sha256: 48f47f080de9e895924eb7202a51c482aa49d4eeb77697d90dd4396de34f4c4c

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

define([
	'jquery',
	'ui/button',
	'jqueryui'
],
function( jQuery, Button ) {
	'use strict';

	var idCounter = 0;

	/**
	 * ToggleButton control. Extends the Button component type to provide an
	 * easy way to create buttons that can transition between "checked" and
	 * "unchecked" states.
	 *
	 * @class
	 * @name ToggleButton
	 * @extends {Button}
	 */
	var ToggleButton = Button.extend({

		_checked: false,

		/**
		 * Sets the state of the toggleButton and updates its visual display
		 * accordingly.
		 *
		 * @param {boolean} toggled Whether the button is to be set to the
		 *                          "toggled/checked" state.
		 */
		setState: function( toggled ) {
			// It is very common to set the button state on every
			// selection change even if the state hasn't changed.
			// Profiling showed that this is very inefficient.
			if (this._checked === toggled) {
				return;
			}
			this._checked = toggled;
			if (toggled) {
				this.element.addClass("aloha-button-active");
			} else {
				this.element.removeClass("aloha-button-active");
			}
		},

		getState: function() {
			return this._checked;
		},

		_onClick: function() {
			this.setState( ! this._checked );
			this.click();
		}
	});

	return ToggleButton;
});

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
gnuside-aloha-rails-0.23.3 vendor/assets/javascripts/aloha/plugins/common/ui/lib/toggleButton.js
locomotive-aloha-rails-0.23.2.2 vendor/assets/javascripts/aloha/plugins/common/ui/lib/toggleButton.js
locomotive-aloha-rails-0.23.2.1 vendor/assets/javascripts/aloha/plugins/common/ui/lib/toggleButton.js