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

Please take a look at my push request #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
Thumbs.db
54 changes: 50 additions & 4 deletions js/jquery.NobleCount.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,24 +282,68 @@
event_internals(t_obj, char_area, c_settings, max_char, true);

// then attach the events -- seem to work better than keypress
$(t_obj).keydown(function(e) {
$(t_obj).bind('keydown.noblecount', function(e) {
event_internals(t_obj, char_area, c_settings, max_char, false);

// to block text entry, return false
if (check_block_negative(e, t_obj, c_settings, max_char) == false) {
trim_input(t_obj, char_area, c_settings, max_char);
return false;
}
}
});

$(t_obj).keyup(function(e) {
$(t_obj).bind('keyup.noblecount', function(e) {
event_internals(t_obj, char_area, c_settings, max_char, false);

// to block text entry, return false
if (check_block_negative(e, t_obj, c_settings, max_char) == false) {
return false;
}
}
});

$(t_obj).bind('paste.noblecount', function(e) {
event_internals(t_obj, char_area, c_settings, max_char, false);

// You need a slight pause
setTimeout(function() {
if (check_block_negative(e, t_obj, c_settings, max_char) == false) {
trim_input(t_obj, char_area, c_settings, max_char);
return false;
}
}, 5);
});
}

/**********************************************************************************

FUNCTION
check_block_negative

DESCRIPTION
determines whether or not text entry within t_obj should be prevented

PRE
e EXISTS
t_obj VALID
c_settings and max_char initialized / calculated

POST
if t_obj text entry should be prevented FALSE is returned
otherwise TRUE returned

TODO
improve selection detection and permissible behaviors experience
ALSO
doesnt CURRENTLY block from the pasting of large chunks of text that
exceed max_char

**********************************************************************************/

function trim_input(t_obj, char_area, c_settings, max_char){
var content = $(t_obj).val();
$(t_obj).val(content.substr(0, max_char));
event_internals(t_obj, char_area, c_settings, max_char, false);
}


/**********************************************************************************
Expand Down Expand Up @@ -348,6 +392,8 @@

// block text entry
return false;
} else if ((find_remaining(t_obj, max_char) < 1) && e.type == "paste") {
return false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion js/jquery.NobleCount.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.