PluginLoader.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * @license
  3. * Copyright (C) 2012 KO GmbH <copyright@kogmbh.com>
  4. *
  5. * @licstart
  6. * The JavaScript code in this page is free software: you can redistribute it
  7. * and/or modify it under the terms of the GNU Affero General Public License
  8. * (GNU AGPL) as published by the Free Software Foundation, either version 3 of
  9. * the License, or (at your option) any later version. The code is distributed
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU AGPL for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this code. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. * As additional permission under GNU AGPL version 3 section 7, you
  17. * may distribute non-source (e.g., minimized or compacted) forms of
  18. * that code without the copy of the GNU GPL normally required by
  19. * section 4, provided you include this license notice and a URL
  20. * through which recipients can access the Corresponding Source.
  21. *
  22. * As a special exception to the AGPL, any HTML file which merely makes function
  23. * calls to this code, and for that purpose includes it by reference shall be
  24. * deemed a separate work for copyright law purposes. In addition, the copyright
  25. * holders of this code give you permission to combine this code with free
  26. * software libraries that are released under the GNU LGPL. You may copy and
  27. * distribute such a system following the terms of the GNU AGPL for this code
  28. * and the LGPL for the libraries. If you modify this code, you may extend this
  29. * exception to your version of the code, but you are not obligated to do so.
  30. * If you do not wish to do so, delete this exception statement from your
  31. * version.
  32. *
  33. * This license applies to this entire compilation.
  34. * @licend
  35. * @source: http://viewerjs.org/
  36. * @source: http://github.com/kogmbh/ViewerJS
  37. */
  38. /*global document, window, Viewer, ODFViewerPlugin, PDFViewerPlugin*/
  39. var viewer;
  40. function loadPlugin(pluginName, callback) {
  41. "use strict";
  42. var script, style;
  43. // Load script
  44. script = document.createElement('script');
  45. script.async = false;
  46. script.onload = callback;
  47. script.src = pluginName + '.js';
  48. script.type = 'text/javascript';
  49. document.getElementsByTagName('head')[0].appendChild(script);
  50. }
  51. function loadDocument(documentUrl) {
  52. "use strict";
  53. if (documentUrl) {
  54. var extension = documentUrl.split('.').pop(),
  55. Plugin;
  56. extension = extension.toLowerCase();
  57. switch (extension) {
  58. case 'odt':
  59. case 'odp':
  60. case 'ods':
  61. case 'fodt':
  62. loadPlugin('./ODFViewerPlugin', function () {
  63. Plugin = ODFViewerPlugin;
  64. });
  65. break;
  66. case 'pdf':
  67. loadPlugin('./PDFViewerPlugin', function () {
  68. Plugin = PDFViewerPlugin;
  69. });
  70. break;
  71. }
  72. window.onload = function () {
  73. if (Plugin) {
  74. viewer = new Viewer(new Plugin());
  75. }
  76. };
  77. }
  78. }