Skip to content

Instantly share code, notes, and snippets.

@caged
Created November 12, 2009 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caged/233265 to your computer and use it in GitHub Desktop.
Save caged/233265 to your computer and use it in GitHub Desktop.
diff --git a/public/javascripts/modules/facebooklist.js b/public/javascripts/modules/facebooklist.js
index 974675a..fba042a 100644
--- a/public/javascripts/modules/facebooklist.js
+++ b/public/javascripts/modules/facebooklist.js
@@ -4,7 +4,10 @@
*/
// Added key contstant for COMMA watching happiness
-Object.extend(Event, { KEY_COMMA: 188, KEY_SPACE: 32 });
+Object.extend(Event, {
+ KEY_COMMA: {code: 188, value:","},
+ KEY_SPACE: {code: 32, value:" "}
+});
var ResizableTextbox = Class.create({
initialize: function(element, options) {
@@ -42,7 +45,7 @@ var TextboxList = Class.create({
onBoxDispose: $empty,*/
resizable: {},
className: 'bit',
- separator: ',',
+ separator: Event.KEY_COMMA,
tabindex: null,
extrainputs: true,
startinput: true,
@@ -105,9 +108,9 @@ var TextboxList = Class.create({
},
update: function() {
- this.element.value = this.bits.values().join(this.options.get('separator'));
+ this.element.value = this.bits.values().join(this.options.get('separator').value);
if (!this.current_input.blank()){
- this.element.value += (this.element.value.blank() ? "" : this.options.get('separator')) + this.current_input;
+ this.element.value += (this.element.value.blank() ? "" : this.options.get('separator').value) + this.current_input;
}
return this;
},
@@ -434,19 +437,20 @@ var FacebookList = Class.create(TextboxList, {
}
}.bind(this));
input.observe('keyup',function(e) {
+ var code = this.options.get('separator').code;
+ var splitOn = this.options.get('separator').value;
switch(e.keyCode) {
- case Event.KEY_COMMA:
+ case code:
if(this.options.get('newValues')) {
new_value_el = this.current.retrieveData('input');
if (!new_value_el.value.endsWith('<')) {
keep_input = "";
- new_value_el.value = new_value_el.value.strip();
- if (new_value_el.value.indexOf(",") < (new_value_el.value.length - 1)){
- comma_pos = new_value_el.value.indexOf(",");
- keep_input = new_value_el.value.substr(comma_pos + 1);
- new_value_el.value = new_value_el.value.substr(0,comma_pos).escapeHTML().strip();
+ if (new_value_el.value.indexOf(splitOn) < (new_value_el.value.length - splitOn.length)){
+ separator_pos = new_value_el.value.indexOf(splitOn);
+ keep_input = new_value_el.value.substr(separator_pos + 1);
+ new_value_el.value = new_value_el.value.substr(0,separator_pos).escapeHTML().strip();
} else {
- new_value_el.value = new_value_el.value.gsub(",","").escapeHTML().strip();
+ new_value_el.value = new_value_el.value.gsub(splitOn,"").escapeHTML().strip();
}
if(!this.options.get("spaceReplace").blank()) new_value_el.value.gsub(" ", this.options.get("spaceReplace"));
if(!new_value_el.value.blank()) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment