definedlinks.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. (function($)
  2. {
  3. $.Redactor.prototype.definedlinks = function()
  4. {
  5. return {
  6. init: function()
  7. {
  8. if (!this.opts.definedLinks) return;
  9. this.modal.addCallback('link', $.proxy(this.definedlinks.load, this));
  10. },
  11. load: function()
  12. {
  13. var $select = $('<select id="redactor-defined-links" />');
  14. $('#redactor-modal-link-insert').prepend($select);
  15. this.definedlinks.storage = {};
  16. $.getJSON(this.opts.definedLinks, $.proxy(function(data)
  17. {
  18. $.each(data, $.proxy(function(key, val)
  19. {
  20. this.definedlinks.storage[key] = val;
  21. $select.append($('<option>').val(key).html(val.name));
  22. }, this));
  23. $select.on('change', $.proxy(this.definedlinks.select, this));
  24. }, this));
  25. },
  26. select: function(e)
  27. {
  28. var key = $(e.target).val();
  29. var name = '', url = '';
  30. if (key !== 0)
  31. {
  32. name = this.definedlinks.storage[key].name;
  33. url = this.definedlinks.storage[key].url;
  34. }
  35. $('#redactor-link-url').val(url);
  36. var $el = $('#redactor-link-url-text');
  37. if ($el.val() === '') $el.val(name);
  38. }
  39. };
  40. };
  41. })(jQuery);