moraes
6 Nov 2006, 3:47 AM
Hi.
I've made a port from Alex King's JS Quicktags to use with YUI.ext Toolbar. The result is here:
http://tipos.org/demos/quicktags/
It works very well on FF/Windows, but there is one problem on IE: when you select a text to apply a tag, it ignores document.selection.createRange(). Maybe it is related to how createDelegate() works. This is how buttons are added (this.b is an array of buttons definitions):
tb.addButton({className: this.b[i].id, text: this.b[i].text, click: this.insertTag.createDelegate(this, [i])});
And this is the IE part in the insertTag() function:
insertTag : function(i) {
//IE support
if (document.selection) {
this.f.focus();
sel = document.selection.createRange();
if (sel.text.length > 0) {
sel.text = this.b[i].tagStart + sel.text + this.b[i].tagEnd;
}
else {
if (!this.checkOpenTags(i) || this.b[i].tagEnd == '') {
sel.text = this.b[i].tagStart;
this.addTag(i);
}
else {
sel.text = this.b[i].tagEnd;
this.removeTag(i);
}
}
this.f.focus();
}
//MOZILLA/NETSCAPE support
...
Despite a text is selected in the textarea, sel.text.length is always 0. Any clues?
I've made a port from Alex King's JS Quicktags to use with YUI.ext Toolbar. The result is here:
http://tipos.org/demos/quicktags/
It works very well on FF/Windows, but there is one problem on IE: when you select a text to apply a tag, it ignores document.selection.createRange(). Maybe it is related to how createDelegate() works. This is how buttons are added (this.b is an array of buttons definitions):
tb.addButton({className: this.b[i].id, text: this.b[i].text, click: this.insertTag.createDelegate(this, [i])});
And this is the IE part in the insertTag() function:
insertTag : function(i) {
//IE support
if (document.selection) {
this.f.focus();
sel = document.selection.createRange();
if (sel.text.length > 0) {
sel.text = this.b[i].tagStart + sel.text + this.b[i].tagEnd;
}
else {
if (!this.checkOpenTags(i) || this.b[i].tagEnd == '') {
sel.text = this.b[i].tagStart;
this.addTag(i);
}
else {
sel.text = this.b[i].tagEnd;
this.removeTag(i);
}
}
this.f.focus();
}
//MOZILLA/NETSCAPE support
...
Despite a text is selected in the textarea, sel.text.length is always 0. Any clues?