bootstrap.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Input History
  2. //
  3. // Douglas Thrift
  4. //
  5. // bootstrap.js
  6. /* ***** BEGIN LICENSE BLOCK *****
  7. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  8. *
  9. * The contents of this file are subject to the Mozilla Public License Version
  10. * 1.1 (the "License"); you may not use this file except in compliance with
  11. * the License. You may obtain a copy of the License at
  12. * http://www.mozilla.org/MPL/
  13. *
  14. * Software distributed under the License is distributed on an "AS IS" basis,
  15. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  16. * for the specific language governing rights and limitations under the
  17. * License.
  18. *
  19. * The Original Code is Input History.
  20. *
  21. * The Initial Developer of the Original Code is
  22. * Douglas Thrift <douglas@douglasthrift.net>.
  23. * Portions created by the Initial Developer are Copyright (C) 2011
  24. * the Initial Developer. All Rights Reserved.
  25. *
  26. * Contributor(s):
  27. *
  28. * Alternatively, the contents of this file may be used under the terms of
  29. * either the GNU General Public License Version 2 or later (the "GPL"), or
  30. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  31. * in which case the provisions of the GPL or the LGPL are applicable instead
  32. * of those above. If you wish to allow use of your version of this file only
  33. * under the terms of either the GPL or the LGPL, and not to allow others to
  34. * use your version of this file under the terms of the MPL, indicate your
  35. * decision by deleting the provisions above and replace them with the notice
  36. * and other provisions required by the GPL or the LGPL. If you do not delete
  37. * the provisions above, a recipient may use your version of this file under
  38. * the terms of any one of the MPL, the GPL or the LGPL.
  39. *
  40. * ***** END LICENSE BLOCK ***** */
  41. Components.utils.import("resource:///modules/imServices.jsm");
  42. function generatorFromArray(array)
  43. {
  44. for (var index = 0; index != array.length; ++index)
  45. yield array[index];
  46. }
  47. function generatorFromEnumerator(enumerator)
  48. {
  49. while (enumerator.hasMoreElements())
  50. yield enumerator.getNext();
  51. }
  52. let observer = {
  53. observe: function(subject, topic, data)
  54. {
  55. if (topic != "conversation-loaded")
  56. return;
  57. this.addArrowListener(subject);
  58. },
  59. addArrowListener: function(browser)
  60. {
  61. var binding = browser.ownerDocument.getBindingParent(browser);
  62. if (!binding || !("editor" in binding) || !binding.editor)
  63. return;
  64. binding.editor.addEventListener("keypress", this.onKeyPress, true);
  65. },
  66. removeArrowListener: function(browser)
  67. {
  68. var binding = browser.ownerDocument.getBindingParent(browser);
  69. if (!binding || !("editor" in binding) || !binding.editor)
  70. return;
  71. binding.editor.removeEventListener("keypress", this.onKeyPress, true);
  72. },
  73. onKeyPress: function(event)
  74. {
  75. if (!event.ctrlKey || ((event.keyCode != event.DOM_VK_UP) && (event.keyCode != event.DOM_VK_DOWN)) || event.altKey || event.metaKey || event.shiftKey)
  76. return;
  77. event.preventDefault();
  78. Services.console.logStringMessage(event);
  79. },
  80. };
  81. function startup(data, reason)
  82. {
  83. for each (let window in generatorFromEnumerator(Services.wm.getEnumerator("Messenger:convs")))
  84. for each (let tabconversation in generatorFromArray(window.document.getElementsByTagName("tabconversation")))
  85. for each (let browser in tabconversation.browsers)
  86. observer.addArrowListener(browser);
  87. Services.obs.addObserver(observer, "conversation-loaded", false);
  88. }
  89. function shutdown(data, reason)
  90. {
  91. Services.obs.removeObserver(observer, "conversation-loaded");
  92. for each (let window in generatorFromEnumerator(Services.wm.getEnumerator("Messenger:convs")))
  93. for each (let tabconversation in generatorFromArray(window.document.getElementsByTagName("tabconversation")))
  94. for each (let browser in tabconversation.browsers)
  95. observer.removeArrowListener(browser);
  96. }
  97. function install(data, reason) {}
  98. function uninstall(data, reason) {}
  99. // vim: expandtab