PageRenderTime 24ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/prebuilt/extension/chrome/content/pdfplugin.js

http://firefox-mac-pdf.googlecode.com/
JavaScript | 75 lines | 42 code | 8 blank | 25 comment | 10 complexity | 14c4aab0fd2c8c0f79ede40352bd88ac MD5 | raw file
  1. /*
  2. * Copyright (c) 2008 Samuel Gross.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. * THE SOFTWARE.
  21. */
  22. (function() {
  23. var browser;
  24. var cmdFind;
  25. var cmdFindAgain;
  26. var cmdFindPrevious;
  27. var mimeTypes = {
  28. "application/pdf" : true,
  29. "text/pdf" : true
  30. };
  31. function init() {
  32. browser = document.getElementById('content');
  33. cmdFind = document.getElementById('cmd_find');
  34. cmdFindAgain = document.getElementById('cmd_findAgain');
  35. cmdFindPrevious = document.getElementById('cmd_findPrevious');
  36. // enable/disable find menu items correctly
  37. // this needs to be set before the plugin is loaded
  38. XULBrowserWindow.onStateChange =
  39. createStateChangeHandler(XULBrowserWindow.onStateChange);
  40. }
  41. function getPluginElement() {
  42. // Check if the page contains the plugin instance
  43. var doc = browser.contentWindow.document;
  44. var body = doc.body;
  45. if (!(body && body.tagName == 'BODY' && body.childNodes.length == 1)) {
  46. return null;
  47. }
  48. var embed = body.firstChild;
  49. if (!(embed && embed.tagName == 'EMBED' && mimeTypes[embed.type])) {
  50. return null;
  51. }
  52. return embed;
  53. }
  54. function createStateChangeHandler(o) {
  55. return function(aWebProgress, aRequest, aStateFlags, aStatus) {
  56. // remove the attribute to force a change if disabled is set
  57. document.getElementById('isImage').removeAttribute('disabled');
  58. o.call(this, aWebProgress, aRequest, aStateFlags, aStatus);
  59. if (getPluginElement()) {
  60. cmdFind.removeAttribute('disabled');
  61. cmdFindAgain.removeAttribute('disabled');
  62. cmdFindPrevious.removeAttribute('disabled');
  63. }
  64. }
  65. }
  66. addEventListener('load', init, false);
  67. })();