Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add/edit comments, and add possibly missing semicolon. #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions lib/jquery.flip_fields.js
Original file line number Diff line number Diff line change
@@ -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 customizing this 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);
/*Not eligible if the element is not an <input> 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;

//variable to hold the original value
var originalValue = flipField.val();
//hide the element to give space for a <span> that acts as render of the <input> element
flipField.hide();
//create the <span> with the value of the input element, and add css style to it
var span = $("<span></span>").text(flipField.val()).addClass(options.spanClass);
//hook 'click' event handler to the <span> 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 <input> element (Closure Is Used Here)
//save the current value to variable originalValue
//hide the <span>, show the <input> element, and focus on it
///////////////////////////////////////////////////////////////////////////////////////////////
if (flipFields.data('currentlyFlipped')) {
flipFields.data('currentlyFlipped').blur();
}
Expand Down Expand Up @@ -42,12 +62,13 @@
e.preventDefault();
}
};

/*hook 'onblur' and 'onkeypress' handler to the current iterated <input> element*/
flipField.blur(onBlur);
flipField.keypress(onKeyPress);

flipField.before(span);
flipField.data('isflipField', true)
//mark current iterated <input> element as a 'flipField'
flipField.data('isflipField', true);

});
};
Expand Down