Well you would need two sets of controls, at least the way the script is written now. I believe I updated it a bit from its last published version, but that shouldn't make a difference to the multi-use functionality, though it may have. Anyways, here is a working version with two textareas:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
/* editText Script ©2009 John Davenport Scheuer
as first seen in http://www.dynamicdrive.com/forums/
username: jscheuer1 - This Notice Must Remain for Legal Use
*/
var editText = {
init: function(){return;}
};
(function(){
if(!document.getElementById){
return;
}
editText = {
saveCurRng: (function(){return document.selection?
function(el){this.el = el; el.focus(); this.curRng = document.selection.createRange();}:
function(el){this.el = el, this.curRng = typeof el.selectionStart === 'number'?
el.value.substring(el.selectionStart, el.selectionEnd) : null;}
})(),
insert: (function(){return document.selection?
function(btag, etag){
this.el.focus();
if(!window.opera){
document.selection.empty();
}
this.curRng.text = btag + this.curRng.text + etag;
this.el.blur();
this.el.focus();
}:function(btag, etag){
if (typeof this.el.selectionStart === 'number'){
var el = this.el, startPos = el.selectionStart, endPos = el.selectionEnd,
l = [btag, this.curRng, etag].join('').length; el.focus();
el.value = [el.value.substring(0, startPos), btag, this.curRng, etag,
el.value.substring(endPos, el.value.length)].join('');
el.selectionStart = el.selectionEnd = startPos + l;
}
};
})(),
controlsFront: function(el, cfg, area){
var t = el[cfg.controlInfo].split(cfg.controlDelimit);
if(cfg.controlDelimit === '><' && t.length === 2){
t[0] += '>';
t[1] = '<' + t[1];
}
else if(t.length === 1){
t.unshift('');
}
this.saveCurRng(area);
this.insert(t[0], t[1]);
},
addEvent: (function(){return window.addEventListener? function(el, ev, f){
el.addEventListener(ev, f, false);
}:window.attachEvent? function(el, ev, f){
el.attachEvent('on' + ev, f);
}:function(){return;};
})(),
init: function(cfg){
this.addEvent(window, 'load', function(){
var ctrls = document.getElementById(cfg.controls).getElementsByTagName(cfg.controlTag), i = 0,
area = document.getElementById(cfg.el);
editText.addEvent(area, 'change', function(){editText.saveCurRng(area);});
if(cfg.clearSelect){
editText.addEvent(document.getElementById(cfg.clearSelect), 'click', function(e){
area.value = area.value;
if(e && e.preventDefault){
e.preventDefault();
}
return false;
});
}
for(i; i < ctrls.length; ++i){
(function(el){
editText.addEvent(el, 'click', function(e){
editText.controlsFront(el, cfg, area);
if(e && e.preventDefault){
e.preventDefault();
}
return false;
});
})(ctrls[i]);
}
});
}
};
})();
editText.init({
el: 'myArea',
controls: 'myControls',
controlTag: 'input',
controlInfo: 'title',
controlDelimit: '><',
clearSelect: 'clearSelection'
});
editText.init({
el: 'myArea2',
controls: 'myControls2',
controlTag: 'input',
controlInfo: 'title',
controlDelimit: '><',
clearSelect: 'clearSelection'
});
</script>
</head>
<body>
<form action="#">
<div>
<textarea id="myArea" rows=5 cols=40>The Slow Pink Fox Jumped Over the Quick Green Dog.</textarea><br>
<input type="reset" value="Reset"> <input id="clearSelection" type="button" value="DeSelect">
</div>
</form>
<div id="myControls">
<input type="button" title="<b></b>" value="B">
<input type="button" title="<i></i>" value="I">
<input type="button" title="<br>" value="BR">
</div>
<form action="#">
<div>
<textarea id="myArea2" rows=5 cols=40>Nothing Here to Look at Folks, Move Along . . .</textarea><br>
<input type="reset" value="Reset"> <input id="clearSelection" type="button" value="DeSelect">
</div>
</form>
<div id="myControls2">
<input type="button" title="<b></b>" value="B">
<input type="button" title="<i></i>" value="I">
<input type="button" title="<br>" value="BR">
</div>
</body>
</html>
Also, using ][ as delimiters probably won't work the way you think. Only >< gets split and used. If you want square brackets around your tags (as would be useful on a bulletin board or other system that uses tags like that), you should use a neutral character for the delimiter, like - say an undescore (_). Then for example your title could be:
Code:
<input type="button" title="[b]_[/b]" value="B">
Though you could edit the script here (adding the highlighted):
Code:
controlsFront: function(el, cfg, area){
var t = el[cfg.controlInfo].split(cfg.controlDelimit);
if(cfg.controlDelimit === '><' && t.length === 2){
t[0] += '>';
t[1] = '<' + t[1];
}
else if(cfg.controlDelimit === '][' && t.length === 2){
t[0] += ']';
t[1] = '[' + t[1];
}
else if(t.length === 1){
t.unshift('');
}
this.saveCurRng(area);
this.insert(t[0], t[1]);
},
To allow for stuff like:
Code:
<input type="button" title="[b][/b]" value="B">
Bookmarks