Tuesday, January 1, 2008

prototype.js sortables text selection

Just a quick note; if you encounter an issue with text selecting when you're trying to drag objects in IE; I use the following code to 'fix' it.
Be warned, it disables the text selection for the whole browser window, so you have to conditionally renable it when you want it.

Event.observe(window,'load',function(e){
if(Prototype.Browser.IE)
{
$$('input, select, textarea')
.invoke('observe','blur',function(e){
disableIETextSelection();
})
.invoke('observe','click',function(e){
enableIETextSelection();
})
.invoke('observe','focus',function(e){
enableIETextSelection();
});

disableIETextSelection();
}
});

function disableIETextSelection()
{
document.body.ondrag = function () { return false; };
document.body.onselectstart = function () { return false; };
}
function enableIETextSelection()
{
document.body.ondrag = null;
document.body.onselectstart = null;
}

No comments: