Double-click select add

This commit is contained in:
JoseluCross
2017-10-30 23:25:29 +01:00
parent e25666648d
commit b3b477fd53
4 changed files with 30 additions and 5 deletions

View File

@@ -117,4 +117,29 @@ function selectAll() {
}
}
getAjax();
}
}
//From https://stackoverflow.com/questions/35297919/javascript-select-all-text-inside-a-pre-code-block-on-double-click
window.onload = function(){
document.body.addEventListener('dblclick', function(e){
var target = e.target || e.srcElement;
if (target.className.indexOf("highlight") !== -1 || target.parentNode.className.indexOf("highlight") !== -1){
var range, selection;
if (document.body.createTextRange) {
range = document.body.createTextRange();
range.moveToElementText(target);
range.select();
} else if (window.getSelection) {
selection = window.getSelection();
range = document.createRange();
range.selectNodeContents(target);
selection.removeAllRanges();
selection.addRange(range);
}
e.stopPropagation();
}
});
};