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 option to keep the label on the input until the input has a value #1058

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 26 additions & 6 deletions Source/Forms/OverText.js
Expand Up @@ -30,7 +30,7 @@ var OverText = new Class({

Implements: [Options, Events, Class.Occlude],

Binds: ['reposition', 'assert', 'focus', 'hide'],
Binds: ['reposition', 'assert', 'focus', 'hide' , 'keydown' ],

options: {/*
textOverride: null,
Expand All @@ -49,7 +49,8 @@ var OverText = new Class({
},
poll: false,
pollInterval: 250,
wrap: false
wrap: false,
showWhileEmpty: false
},

property: 'OverText',
Expand Down Expand Up @@ -86,7 +87,7 @@ var OverText = new Class({
},
html: value,
events: {
click: this.hide.pass(options.element == 'label', this)
click: this[this.options.showWhileEmpty ? 'assert' : 'hide'].pass(options.element == 'label', this)
}
}).inject(element, 'after');

Expand Down Expand Up @@ -121,6 +122,12 @@ var OverText = new Class({
blur: this.assert,
change: this.assert
});
if (this.options.showWhileEmpty) {
this.element.removeEvents({
keydown: this.keydown,
keyup: this.assert
});
}
window.removeEvent('resize', this.reposition);
this.hide(true, true);
return this;
Expand All @@ -132,10 +139,24 @@ var OverText = new Class({
blur: this.assert,
change: this.assert
});
if (this.options.showWhileEmpty) {
this.element.addEvents({
keydown: this.keydown,
keyup: this.assert
});
}
window.addEvent('resize', this.reposition);
this.reposition();
return this;
},

keydown: function(evt){
var key = evt.code;
// key code from zero to z, then anything above 185, which are symbols and such.. if its empty, we hide right away
if (((key >= 48 && key <= 90) || key > 185) && this.test()) {
this.hide();
}
},

wrap: function(){
if (this.options.element == 'label'){
Expand Down Expand Up @@ -172,7 +193,7 @@ var OverText = new Class({

focus: function(){
if (this.text && (!this.text.isDisplayed() || this.element.get('disabled'))) return this;
return this.hide();
return this.options.showWhileEmpty ? this.assert() : this.hide();
},

hide: function(suppressFocus, force){
Expand Down Expand Up @@ -253,5 +274,4 @@ Object.append(OverText, {
});
}

});

});