javascript - Angular close modal dialog when pressing escape in Chrome and Safari -


i have following directive attached element closes sharepoint 2013 modal dialog when user presses esc key.

    app.directive("closedialog", function() {     return {         link: function(scope, element, attrs) {             document.onkeypress = function(e) {                 var dialog = sp.ui.modaldialog.get_childdialog();                 if(dialog || dialog != null) {                     sp.ui.modaldialog.commonmodaldialogclose(sp.ui.dialogresult.cancel, null);                 }                 scope.$apply();             };         }     }; }); 

it works in ie , firefox, not in chrome or safari. suggestions?

i forgot update answer. $document answer.

app.directive("closedialog", function($document) {     function closemodaldialog(scope) {         var dialog = sp.ui.modaldialog.get_childdialog();         if(dialog != null) {             sp.ui.modaldialog.commonmodaldialogclose(sp.ui.dialogresult.cancel, null);         }         scope.$apply();     }     return {         link: function(scope, element, attrs) {             $document.on("keydown", function(e) {                 closemodaldialog(scope);             });         }     }; }); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -