From 981c92f949a8414df8239f3b8ed78df9879b16fc Mon Sep 17 00:00:00 2001 From: Cheng Chen Date: Sun, 10 Apr 2011 06:57:09 -0700 Subject: [PATCH 1/6] Add comments, and possibly missing semicolon --- lib/jquery.flip_fields.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/jquery.flip_fields.js b/lib/jquery.flip_fields.js index d22ff7d..ce829c6 100644 --- a/lib/jquery.flip_fields.js +++ b/lib/jquery.flip_fields.js @@ -1,18 +1,38 @@ (function($) { + //key code for Carriage Return var ENTER_KEY = 13; + //key code for Escape var ESC_KEY = 27; + /** + * flipFields definition + * @param options Configuration for customize the plugin + */ $.fn.flipFields = function(options) { options = options || {}; + //alias of THIS context var flipFields = this; flipFields.data('currentlyFlipped', false); flipFields.each(function() { + //alias of jQuery representation for current DOM element var flipField = $(this); + //if the DOM is eligible to use this plugin + /*Not eligible if the element is not an element of type text or associated data named isflipField is evaluated to be True + *the second evaluation can prevent one would be 'isflipField' field from processing multiple times + */ if (flipField.attr('type') != "text" || flipField.data('isflipField')) return; - + //temp variable to hold the original value var originalValue = flipField.val(); + //hide the element to give space for a that acts as render of that input element flipField.hide(); + //create the with the value of the input element, and add css style to it var span = $("").text(flipField.val()).addClass(options.spanClass); + //hook 'click' event handler to the element span.click(function(e) { + /////////////////////////// + //if there is another Flip Field in edit state currently, blur it at first + //set currentlyFlipped to the current iterated(Closure Is Used Here), save the current value to variable originalValue + //hide the , show the element, and focus on it + ////////////////////////// if (flipFields.data('currentlyFlipped')) { flipFields.data('currentlyFlipped').blur(); } @@ -42,12 +62,13 @@ e.preventDefault(); } }; - + /*hook 'onblur' and 'onkeypress' handler to the current iterated element*/ flipField.blur(onBlur); flipField.keypress(onKeyPress); - + flipField.before(span); - flipField.data('isflipField', true) + //mark current iterated element as a 'flipField' + flipField.data('isflipField', true); }); }; From 6d12d948c37e67e90ce1b2819c4cf838394783df Mon Sep 17 00:00:00 2001 From: Cheng Chen Date: Sun, 10 Apr 2011 06:58:33 -0700 Subject: [PATCH 2/6] Edited lib/jquery.flip_fields.js via GitHub --- lib/jquery.flip_fields.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/jquery.flip_fields.js b/lib/jquery.flip_fields.js index ce829c6..3f875df 100644 --- a/lib/jquery.flip_fields.js +++ b/lib/jquery.flip_fields.js @@ -28,11 +28,12 @@ var span = $("").text(flipField.val()).addClass(options.spanClass); //hook 'click' event handler to the element span.click(function(e) { - /////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////////// //if there is another Flip Field in edit state currently, blur it at first - //set currentlyFlipped to the current iterated(Closure Is Used Here), save the current value to variable originalValue + //set currentlyFlipped to the current iterated(Closure Is Used Here) + //save the current value to variable originalValue //hide the , show the element, and focus on it - ////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////// if (flipFields.data('currentlyFlipped')) { flipFields.data('currentlyFlipped').blur(); } From cb2d81c9f8aaffaabba278e49581d8424df0cd35 Mon Sep 17 00:00:00 2001 From: Cheng Chen Date: Sun, 10 Apr 2011 06:59:38 -0700 Subject: [PATCH 3/6] Edited lib/jquery.flip_fields.js via GitHub --- lib/jquery.flip_fields.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jquery.flip_fields.js b/lib/jquery.flip_fields.js index 3f875df..9fec0e5 100644 --- a/lib/jquery.flip_fields.js +++ b/lib/jquery.flip_fields.js @@ -5,7 +5,7 @@ var ESC_KEY = 27; /** * flipFields definition - * @param options Configuration for customize the plugin + * @param options Configuration for customizing this plugin */ $.fn.flipFields = function(options) { options = options || {}; From c9d9667f980528b0ebfc766d7f9c17bcb51960b2 Mon Sep 17 00:00:00 2001 From: Cheng Chen Date: Sun, 10 Apr 2011 07:03:16 -0700 Subject: [PATCH 4/6] Edited lib/jquery.flip_fields.js via GitHub --- lib/jquery.flip_fields.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/jquery.flip_fields.js b/lib/jquery.flip_fields.js index 9fec0e5..ab478bd 100644 --- a/lib/jquery.flip_fields.js +++ b/lib/jquery.flip_fields.js @@ -15,14 +15,13 @@ flipFields.each(function() { //alias of jQuery representation for current DOM element var flipField = $(this); - //if the DOM is eligible to use this plugin /*Not eligible if the element is not an element of type text or associated data named isflipField is evaluated to be True - *the second evaluation can prevent one would be 'isflipField' field from processing multiple times + *the second evaluation can prevent one would-be 'isflipField' field from processing multiple times */ if (flipField.attr('type') != "text" || flipField.data('isflipField')) return; //temp variable to hold the original value var originalValue = flipField.val(); - //hide the element to give space for a that acts as render of that input element + //hide the element to give space for a that acts as render of the element flipField.hide(); //create the with the value of the input element, and add css style to it var span = $("").text(flipField.val()).addClass(options.spanClass); From 1c807f98289f83c3417dd5224b49a0d8735dd1a9 Mon Sep 17 00:00:00 2001 From: Cheng Chen Date: Sun, 10 Apr 2011 07:03:54 -0700 Subject: [PATCH 5/6] Edited lib/jquery.flip_fields.js via GitHub --- lib/jquery.flip_fields.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jquery.flip_fields.js b/lib/jquery.flip_fields.js index ab478bd..b112844 100644 --- a/lib/jquery.flip_fields.js +++ b/lib/jquery.flip_fields.js @@ -19,7 +19,7 @@ *the second evaluation can prevent one would-be 'isflipField' field from processing multiple times */ if (flipField.attr('type') != "text" || flipField.data('isflipField')) return; - //temp variable to hold the original value + //variable to hold the original value var originalValue = flipField.val(); //hide the element to give space for a that acts as render of the element flipField.hide(); From 73e6cf5df6a8e7845d699211ef84d65b136a2d69 Mon Sep 17 00:00:00 2001 From: Cheng Chen Date: Sun, 10 Apr 2011 07:08:13 -0700 Subject: [PATCH 6/6] Edited lib/jquery.flip_fields.js via GitHub --- lib/jquery.flip_fields.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jquery.flip_fields.js b/lib/jquery.flip_fields.js index b112844..4e9afd2 100644 --- a/lib/jquery.flip_fields.js +++ b/lib/jquery.flip_fields.js @@ -29,7 +29,7 @@ span.click(function(e) { ////////////////////////////////////////////////////////////////////////////////////////////// //if there is another Flip Field in edit state currently, blur it at first - //set currentlyFlipped to the current iterated(Closure Is Used Here) + //set currentlyFlipped to the current iterated element (Closure Is Used Here) //save the current value to variable originalValue //hide the , show the element, and focus on it ///////////////////////////////////////////////////////////////////////////////////////////////