As a developer of sorts, of scripts, I know it can be confusing if and when to issue an update. Are the new features worth it? Are there perhaps new bugs? Is the update path seamless enough for earlier adopters? It's always tempting to not worry about some or any of that. One can always issue a future update. The most comfortable spot to be in as far as all that goes is pre-release. You can play with it, update it whenever you like, and tell folks about it, where it's available, the basics of use, but don't have to worry about bugs (other than on the coding side) or docs.
Getting closer to back on topic though, the Opera team has been pretty consistent over the years.
As far as the script in question goes, Opera was the odd man out. IE often needs its own browser specific methods. Firefox and almost all others can do it to standards. In this particular case, Opera couldn't do it like the "Fox" or IE, but apparently was closer to IE.
So, let's try my other idea. Force Opera to do it like the "Fox". Only let's try it with a twist, changing the order of:
Code:
el.selectionStart = el.selectionEnd = startPos + l;
to:
Code:
el.selectionEnd = el.selectionStart = startPos + l;
Here's the full code (other things have changed. You cannot simply plug in the above change to the previous version):
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 - 2010 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;
}
window.opera = typeof opera !== 'undefined'? opera : null;
editText = {
saveCurRng: (function(){return document.selection && !opera?
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 && !opera?
function(btag, etag){
this.el.focus();
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.selectionEnd = el.selectionStart = startPos + l;
}
};
})(),
controlsFront: function(el, cfg, area){
var t = el[cfg.controlInfo].split(cfg.controlDelimit);
if(window.opera && t.length === 1 && !/^<.*>$/.test(t[0])){
t = el.value.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);});
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: '><'
});
</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">
</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">
<input type="button" title=" :)" value=" :)">
</div>
</body>
</html>
I dunno if it will fix it for 10.5x, but when I shifted to the standard method in 10.10, it had the exact problem you described for 10.5x, then the change mentioned above (plus shifting to the standard method) fixed it, so it's worth a shot.
Bookmarks