extender – HTMLInputElement [ 1167 views ]
Goal: give some additional function to the HTMLInputElement type
// 1. properties of the selected text (plus the original text as well)
TypeExtend(HTMLInputElement, 'selection', function() {
var d = this;
return {
position: this.selectionStart,
start: this.selectionStart,
end: this.selectionEnd,
length: this.selectionEnd - this.selectionStart,
text: this.value.substring(this.selectionStart, this.selectionEnd),
isAll: function(){var l = d.selectionEnd - d.selectionStart; return (l > 0 && d.value.length == l);}(),
_original: {
text: this.value,
length: this.value.length
}
};
});
the usage is very simple:
$('.myinputbox')[0].selection()
{
position : 0,
start : 0,
end : 4,
length : 4,
text : 'aaaa',
isAll : true,
_original : {
text: 'aaaa',
length: 6
}
}
in this case the inputbox value is 'aaaa' and all the text selected isAll == true
this extender working in ie as well.


