quicklook.googledocs.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. (function(root, factory) {
  2. if (typeof define === 'function' && define.amd) {
  3. define(['elfinder'], factory);
  4. } else if (typeof exports !== 'undefined') {
  5. module.exports = factory(require('elfinder'));
  6. } else {
  7. factory(root.elFinder);
  8. }
  9. }(this, function(elFinder) {
  10. "use strict";
  11. try {
  12. if (! elFinder.prototype.commands.quicklook.plugins) {
  13. elFinder.prototype.commands.quicklook.plugins = [];
  14. }
  15. elFinder.prototype.commands.quicklook.plugins.push(function(ql) {
  16. var fm = ql.fm,
  17. preview = ql.preview;
  18. preview.on('update', function(e) {
  19. var win = ql.window,
  20. file = e.file, node, loading;
  21. if (file.mime.indexOf('application/vnd.google-apps.') === 0) {
  22. if (file.url == '1') {
  23. preview.hide();
  24. $('<div class="elfinder-quicklook-info-data"><button class="elfinder-info-button">'+fm.i18n('getLink')+'</button></div>').appendTo(ql.info.find('.elfinder-quicklook-info'))
  25. .on('click', function() {
  26. $(this).html('<span class="elfinder-spinner">');
  27. fm.request({
  28. data : {cmd : 'url', target : file.hash},
  29. preventDefault : true
  30. })
  31. .always(function() {
  32. preview.show();
  33. $(this).html('');
  34. })
  35. .done(function(data) {
  36. var rfile = fm.file(file.hash);
  37. ql.value.url = rfile.url = data.url || '';
  38. if (ql.value.url) {
  39. preview.trigger($.Event('update', {file : ql.value}));
  40. }
  41. });
  42. });
  43. }
  44. if (file.url !== '' && file.url != '1') {
  45. e.stopImmediatePropagation();
  46. loading = $('<div class="elfinder-quicklook-info-data"><span class="elfinder-spinner-text">'+fm.i18n('nowLoading')+'</span><span class="elfinder-spinner"/></div>').appendTo(ql.info.find('.elfinder-quicklook-info'));
  47. node = $('<iframe class="elfinder-quicklook-preview-iframe"/>')
  48. .css('background-color', 'transparent')
  49. .on('load', function() {
  50. ql.hideinfo();
  51. loading.remove();
  52. node.css('background-color', '#fff');
  53. })
  54. .on('error', function() {
  55. loading.remove();
  56. node.remove();
  57. })
  58. .appendTo(preview)
  59. .attr('src', fm.url(file.hash));
  60. preview.one('change', function() {
  61. loading.remove();
  62. node.off('load').remove();
  63. });
  64. }
  65. }
  66. });
  67. });
  68. } catch(e) {}
  69. }));