javascript - Preserve text selection in contenteditable while interacting with jQuery UI Dialog and text input -


i have jquery dialog making links in contenteditable span. problem clicking button open dialog causes selection lost, text input inside dialog causes selection lost.

i can fix button -moz-user-select:none; -webkit-user-select:none doesn't work in chrome.

i can fix input wrapping in iframe, that's messy , clicking anywhere else kills selection, example, dragging dialog around.

i've seen solution @ how preserve text selection when opening jquery dialog, doesn't work in many browsers in contenteditable element, real inputs.

is there nice solution problem?

you save , restore selection using simple functions such following when dialog opened , closed. not familiar enough jquery dialogs know mechanism hooking dialog opening , closing. first, saveselection, returns range or textrange object should store in variable later pass restoreselection:

function saveselection() {     if (window.getselection) {         sel = window.getselection();         if (sel.getrangeat && sel.rangecount) {             return sel.getrangeat(0);         }     } else if (document.selection && document.selection.createrange) {         return document.selection.createrange();     }     return null; }  function restoreselection(range) {     if (range) {         if (window.getselection) {             sel = window.getselection();             sel.removeallranges();             sel.addrange(range);         } else if (document.selection && range.select) {             range.select();         }     } } 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -