Sha256: f3377ee5a9f540af23b74fc12c5ff22840c7b241dca15bfbd37c362e388333fb

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

/**
 * @file checkbox plugin for jquery-jeditable
 * @author Mika Tuupola, Nicolas CARPi
 * @home https://github.com/NicolasCARPi/jquery_jeditable
 * @licence MIT (see LICENCE file)
 * @name PluginCheckbox
 */
'use strict';
(function ($) {
	$.editable.addInputType('checkbox', {
		element : function(settings, original) {
			var input = $('<input type="checkbox">');
			$(this).append(input);

			$(input).bind('click', function() {
				if ($(input).val() === 'on') {
					$(input).val('off');
					$(input).removeAttr('checked');
				} else {
					$(input).val('on');
					$(input).attr('checked', 'checked');
				}
			});

			return(input);
		},

		content : function(string, settings, original) {

			var checked = (string === 'yes') ? 'on' : 'off';
			var input = $(':input:first', this);

			if (checked === 'on') {
				$(input).attr('checked', checked);
			} else {
				$(input).removeAttr('checked');
			}

			var value = $(input).is(':checked') ? 'on' : 'off';
			$(input).val(value);
		},

		submit: function (settings, original) {
			var value;
			var input = $(':input:first', this);
			if (input.is(':checked')) {
				value = '1';
			} else {
				value = '0';
			}
			$('input', this).val(value);
		}
	});
})(jQuery);

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
on_the_spot-1.1.5 app/assets/javascripts/jquery.jeditable.checkbox.js
on_the_spot-1.1.4 app/assets/javascripts/jquery.jeditable.checkbox.js