imagemanager.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. (function($)
  2. {
  3. $.Redactor.prototype.imagemanager = function()
  4. {
  5. return {
  6. init: function()
  7. {
  8. if (!this.opts.imageManagerJson) return;
  9. this.modal.addCallback('image', this.imagemanager.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-image-droparea').addClass('redactor-tab redactor-tab1');
  18. var $box = $('<div id="redactor-image-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.imageManagerJson,
  24. success: $.proxy(function(data)
  25. {
  26. $.each(data, $.proxy(function(key, val)
  27. {
  28. // title
  29. var thumbtitle = '';
  30. if (typeof val.title !== 'undefined') thumbtitle = val.title;
  31. var img = $('<img src="' + val.thumb + '" rel="' + val.image + '" title="' + thumbtitle + '" style="width: 100px; height: 75px; cursor: pointer;" />');
  32. $('#redactor-image-manager-box').append(img);
  33. $(img).click($.proxy(this.imagemanager.insert, this));
  34. }, this));
  35. }, this)
  36. });
  37. },
  38. insert: function(e)
  39. {
  40. this.image.insert('<img src="' + $(e.target).attr('rel') + '" alt="' + $(e.target).attr('title') + '">');
  41. }
  42. };
  43. };
  44. })(jQuery);