filemanager.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. (function($)
  2. {
  3. $.Redactor.prototype.filemanager = function()
  4. {
  5. return {
  6. init: function()
  7. {
  8. if (!this.opts.fileManagerJson) return;
  9. this.modal.addCallback('file', this.filemanager.load);
  10. },
  11. load: function()
  12. {
  13. var $modal = this.modal.getModal();
  14. this.modal.createTabber($modal);
  15. this.modal.addTab(1, 'Upload', 'active');
  16. this.modal.addTab(2, 'Choose');
  17. $('#redactor-modal-file-upload-box').addClass('redactor-tab redactor-tab1');
  18. var $box = $('<div id="redactor-file-manager-box" style="overflow: auto; height: 300px;" class="redactor-tab redactor-tab2">').hide();
  19. $modal.append($box);
  20. $.ajax({
  21. dataType: "json",
  22. cache: false,
  23. url: this.opts.fileManagerJson,
  24. success: $.proxy(function(data)
  25. {
  26. var ul = $('<ul id="redactor-modal-list">');
  27. $.each(data, $.proxy(function(key, val)
  28. {
  29. var a = $('<a href="#" title="' + val.title + '" rel="' + val.link + '" class="redactor-file-manager-link">' + val.title + ' <span style="font-size: 11px; color: #888;">' + val.name + '</span> <span style="position: absolute; right: 10px; font-size: 11px; color: #888;">(' + val.size + ')</span></a>');
  30. var li = $('<li />');
  31. a.on('click', $.proxy(this.filemanager.insert, this));
  32. li.append(a);
  33. ul.append(li);
  34. }, this));
  35. $('#redactor-file-manager-box').append(ul);
  36. }, this)
  37. });
  38. },
  39. insert: function(e)
  40. {
  41. e.preventDefault();
  42. var $target = $(e.target).closest('.redactor-file-manager-link');
  43. this.file.insert('<a href="' + $target.attr('rel') + '">' + $target.attr('title') + '</a>');
  44. }
  45. };
  46. };
  47. })(jQuery);