From 0b1c8a50dd1c68a5ac6bd10d15b3710206a6de3f Mon Sep 17 00:00:00 2001 From: Jim A Kinsman Date: Sun, 27 Jan 2013 20:44:42 -0600 Subject: [PATCH 1/3] Added beforeFreeze abort option to * abort editing (using esc key would be a common implementation) Stored old data in data-oldvalue="foobar" --- jquery.editable.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/jquery.editable.js b/jquery.editable.js index 8b5a0cc..3b0ae63 100644 --- a/jquery.editable.js +++ b/jquery.editable.js @@ -1,6 +1,6 @@ /* * - * jQuery Editables 1.0.1 + * jQuery Editables 1.0.1 (jimk branch) * * Date: Aug 11 2012 * Source: www.tectual.com.au, www.arashkarimzadeh.com @@ -9,6 +9,9 @@ * Copyright (c) 2012 Tectual Pty. Ltd. * http://www.opensource.org/licenses/mit-license.php * + * 27-Jan-2013 JimK: Added beforeFreeze abort option to + * abort editing (using esc key would be a common implementation) + * Stored old data in data-oldvalue="foobar" */ (function($){ @@ -24,9 +27,16 @@ $.fn.editables = function(options){ var $this = $(this); var fn = function(ev){ var t = $($this.data('for')); - if(opts.beforeFreeze.call(t, $this, ev)==false) return; + var bf = opts.beforeFreeze.call(t, $this, ev); + if(bf==false) return; t.hide(); $this.show(); + if (bf === 'abort'){ + if (t.data('oldvalue') !== undefined){ + t.val(t.data('oldvalue')); + } + return; //do not call onFreeze, because we aborted freeze + } t.trigger('onFreeze'); }; var evs= {}; @@ -38,6 +48,7 @@ $.fn.editables = function(options){ if(opts.beforeEdit.call($this, t, ev)==false) return; $this.hide(); t.show().focus(); + t.data('oldvalue', t.val()); $this.trigger('onEdit'); } var evs = {}; From 294cf6ac1122cce87db35652659749e4be98deaf Mon Sep 17 00:00:00 2001 From: Jim A Kinsman Date: Sun, 27 Jan 2013 22:08:01 -0600 Subject: [PATCH 2/3] Added feature to pop up editing box programmatically .editables('edit') will show the editor and ('freeze') will freeze it (useful for tiny images to edit on click --- jquery.editable.js | 67 +++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/jquery.editable.js b/jquery.editable.js index 3b0ae63..854c8ad 100644 --- a/jquery.editable.js +++ b/jquery.editable.js @@ -5,17 +5,27 @@ * Date: Aug 11 2012 * Source: www.tectual.com.au, www.arashkarimzadeh.com * Author: Arash Karimzadeh (arash@tectual.com.au) + * Contributors: Jim Kinsman (relipse@gmail.com) + * * * Copyright (c) 2012 Tectual Pty. Ltd. * http://www.opensource.org/licenses/mit-license.php * - * 27-Jan-2013 JimK: Added beforeFreeze abort option to - * abort editing (using esc key would be a common implementation) - * Stored old data in data-oldvalue="foobar" */ (function($){ -$.fn.editables = function(options){ +$.fn.editables = function(options, arg2){ + + //if we already have an existing editable plugin, go ahead and call a method + //@see this.methods = { ... + if (typeof(options) == 'string'){ + $('[data-type=editable]', this).each(function(){ + if (typeof(this.methods[options]) == 'function'){ + this.methods[options].call(arg2); + } + }); + return; + } var opts = $.extend( {}, $.fn.editables.options, options ); @@ -25,32 +35,37 @@ $.fn.editables = function(options){ $('[data-type=editable]', this).each( function(){ var $this = $(this); - var fn = function(ev){ - var t = $($this.data('for')); - var bf = opts.beforeFreeze.call(t, $this, ev); - if(bf==false) return; - t.hide(); - $this.show(); - if (bf === 'abort'){ - if (t.data('oldvalue') !== undefined){ - t.val(t.data('oldvalue')); - } - return; //do not call onFreeze, because we aborted freeze - } - t.trigger('onFreeze'); + this.methods = { + freeze : function(ev) { + var t = $($this.data('for')); + var bf = opts.beforeFreeze.call(t, $this, ev); + if(bf==false) return; + t.hide(); + $this.show(); + if (bf === 'abort'){ + if (t.data('oldvalue') !== undefined){ + t.val(t.data('oldvalue')); + } + return; //do not call onFreeze, because we aborted freeze + } + t.trigger('onFreeze'); + }, + edit : function(ev){ + var t = $($this.data('for')); + if(opts.beforeEdit.call($this, t, ev)==false) return; + $this.hide(); + t.show().focus(); + t.data('oldvalue', t.val()); + $this.trigger('onEdit'); + } }; + + var fn = this.methods.freeze; var evs= {}; $.each( opts.freezeOn, function(){ evs[this] = fn; } ); $($this.data('for')).hide().bind('onFreeze', opts.onFreeze).bind(evs); - var fn = function(ev){ - var t = $($this.data('for')); - if(opts.beforeEdit.call($this, t, ev)==false) return; - $this.hide(); - t.show().focus(); - t.data('oldvalue', t.val()); - $this.trigger('onEdit'); - } + var fn = this.methods.edit; var evs = {}; $.each( opts.editOn, function(){ evs[this] = fn; } ); $this.bind('onEdit', opts.onEdit).bind(evs); @@ -68,5 +83,3 @@ $.fn.editables.options = { } })(jQuery); - - From 728e49008a0b4b0144eaf11d05124b840775e5a3 Mon Sep 17 00:00:00 2001 From: Jim A Kinsman Date: Mon, 28 Jan 2013 14:39:56 -0600 Subject: [PATCH 3/3] do not call onFreeze if value never changed --- jquery.editable.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/jquery.editable.js b/jquery.editable.js index 854c8ad..3cfbbee 100644 --- a/jquery.editable.js +++ b/jquery.editable.js @@ -1,13 +1,12 @@ /* * - * jQuery Editables 1.0.1 (jimk branch) + * jQuery Editables 1.0.1.3 (jimk branch) * * Date: Aug 11 2012 * Source: www.tectual.com.au, www.arashkarimzadeh.com * Author: Arash Karimzadeh (arash@tectual.com.au) * Contributors: Jim Kinsman (relipse@gmail.com) * - * * Copyright (c) 2012 Tectual Pty. Ltd. * http://www.opensource.org/licenses/mit-license.php * @@ -42,11 +41,15 @@ $.fn.editables = function(options, arg2){ if(bf==false) return; t.hide(); $this.show(); + if (bf === 'abort'){ if (t.data('oldvalue') !== undefined){ t.val(t.data('oldvalue')); } return; //do not call onFreeze, because we aborted freeze + }else if (t.data('oldvalue') == t.val()){ + //value never changed + return; } t.trigger('onFreeze'); },