windowEvents.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // add the platform to the HTML tag
  2. setTimeout(function() {
  3. document.getElementsByTagName('html')[0].className = window.mist.platform;
  4. if (window.basePathHref) {
  5. var base = document.createElement('base');
  6. base.href = window.basePathHref;
  7. document.getElementsByTagName('head')[0].appendChild(base);
  8. }
  9. }, 200);
  10. $(window).on('blur', function(e) {
  11. $('body').addClass('app-blur');
  12. });
  13. $(window).on('focus', function(e) {
  14. $('body').removeClass('app-blur');
  15. });
  16. // make sure files can only be dropped in the browser webview
  17. $(window).on('dragenter', function(e) {
  18. LocalStore.set('selectedTab', 'browser');
  19. ipc.send('backendAction_focusMainWindow');
  20. });
  21. $(window).on('keydown', function(e) {
  22. // Select tab with index when number is 1-8
  23. if (e.metaKey && e.keyCode >= 49 && e.keyCode <= 56) {
  24. var index = parseInt(String.fromCharCode(e.keyCode), 10) - 1;
  25. Helpers.selectTabWithIndex(index);
  26. return;
  27. }
  28. // RELOAD current webview
  29. if (
  30. LocalStore.get('selectedTab') !== 'wallet' &&
  31. e.metaKey &&
  32. e.keyCode === 82
  33. ) {
  34. var webview = Helpers.getWebview(LocalStore.get('selectedTab'));
  35. if (webview) {
  36. webview.reloadIgnoringCache();
  37. }
  38. return;
  39. }
  40. // Select last tab on Ctrl + 9
  41. if (e.metaKey && e.keyCode === 57) {
  42. Helpers.selectLastTab();
  43. return;
  44. }
  45. // Ctrl + tab || Ctrl + shift + tab
  46. if (e.ctrlKey && e.keyCode === 9) {
  47. var tabOffset = e.shiftKey ? -1 : 1;
  48. Helpers.selectTabWithOffset(tabOffset);
  49. }
  50. });