JavaScript: Key event doesn't fire if selected text is just removed -


i applying handlers events keypress, keyup , keydown occuring on textarea. works every case except if select text , press backspace. particular assigned function won't called. if press backspace once more on textarea, function called. here code:

function myfunc(f) {     console.log("fired"); // logged when select , remove     var h = f.target || f.srcelement || this;     myfunc2(f); // doesn't called when select , remove } function myfunc2(e) {     var $elem = $(e);     // important stuff };  $textarea.addeventlistener("keyup", myfunc); $textarea.addeventlistener("keydown", myfunc); $textarea.addeventlistener("keypress", myfunc); myfunc({ target: $textarea }); // <-- call explicitly manage stuff 

the complete code

function elasticize(a) {     var b = "overflow" + ("overflowy" in document.getelementsbytagname("script")[0].style ? "y" : ""),         e = function (h, g, j) {             if (g.addeventlistener) {                 (var f = 0; f < h.length; f++) {                     g.addeventlistener(h[f], j, 0)                 }             } else {                 if (g.attachevent) {                     (var f = 0; f < h.length; f++) {                         g.attachevent("on" + h[f], j)                     }                 }             }         };     (var c = 0; c < a.length; c++) {         a[c].style[b] = "hidden";         a[c].__originalrows = a[c].rows;         var d = function (f) {             var h = f.target || f.srcelement || this,                 g = h.scrolltop;                 window.resizebody(h);             h.scrolltop = 1;             while (h.scrolltop > 0) {                 var j = h.clientheight,                     = true;                 h.rows++;                 if (h.clientheight == j) {                     if (h.style[b]) {                         h.style[b] = ""                     }                     h.scrolltop = g;                     return                 }                 h.scrolltop = 1             }             if (!i) {                 while (h.scrolltop == 0 && h.rows > h.__originalrows) {                     h.rows--;                     h.scrolltop = 1                 }                 if (h.scrolltop > 0) {                     h.rows++                 }             }             if (!h.style[b]) {                 h.style[b] = "hidden"             }         };         e(["keypress", "paste", "cut", "keyup", "keydown"], a[c], d);         d({             target: a[c]         })     } }; window.resizebody = function(e) {     $footer = $(e).parent(),     $body = $footer.siblings("div.body"),     footerheight = $footer.height();  $body.css("margin-bottom", footerheight + "px").height( function() {     return window.bodyheight - footerheight; }); }; 

i got solution. problem function being called before height of footer changed. need either use web api namely settimeout or call function in end of parent function. recommend doing settimeout delay of 0 milliseconds so, important function called when rest of code executed.

settimeout(myfunc2, 0); 

conclusion: there nothing wrong javascript events. have make sure order of functions being called correct.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -