app/assets/javascripts/jquery.jeditable.checkbox.js in on_the_spot-1.1.3 vs app/assets/javascripts/jquery.jeditable.checkbox.js in on_the_spot-1.1.4
- old
+ new
@@ -1,26 +1,54 @@
-/**********************************************************************
- * Custom input types for the jquery.jeditable plugin
- * By Richard Davies <Richard__at__richarddavies.us>, 2009
- * By Peter Savichev (proton) <psavichev@gmail.com>, 2011
- *********************************************************************/
+/**
+ * @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);
-// Create a custom input type for checkboxes
-$.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');
+ }
+ });
- $(input).change(function() {
- var value = $(input).is(":checked") ? 1 : 0;
+ 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);
- });
- return(input);
- },
- content : function(string, settings, original) {
- var checked = (string == "true") ? 1 : 0;
- var input = $(':input:first', this);
- if(checked) $(input).attr("checked", "checked");
- else $(input).removeAttr("checked");
- $(input).val(checked);
- }
-});
\ No newline at end of file
+ },
+
+ 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);