linkitDialog.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * @file
  3. * Linkit ckeditor dialog helper.
  4. */
  5. (function ($) {
  6. // Abort if Drupal.linkit is not defined.
  7. if (typeof Drupal.linkit === 'undefined') {
  8. return ;
  9. }
  10. Drupal.linkit.registerDialogHelper('ckeditor', {
  11. init : function() {},
  12. /**
  13. * Prepare the dialog after init.
  14. */
  15. afterInit : function () {
  16. var editor = Drupal.settings.linkit.currentInstance.editor;
  17. var element = CKEDITOR.plugins.link.getSelectedLink(editor);
  18. // If we have selected a link element, lets populate the fields in the
  19. // modal with the values from that link element.
  20. if (element) {
  21. link = {
  22. path: element.data('cke-saved-href') || element.getAttribute('href') || '',
  23. attributes: {}
  24. },
  25. // Get all attributes that have fields in the modal.
  26. additionalAttributes = Drupal.linkit.additionalAttributes();
  27. for (var i = 0; i < additionalAttributes.length; i++) {
  28. link.attributes[additionalAttributes[i]] = element.getAttribute(additionalAttributes[i]);
  29. }
  30. // Populate the fields.
  31. Drupal.linkit.populateFields(link);
  32. }
  33. },
  34. /**
  35. * Insert the link into the editor.
  36. *
  37. * @param {Object} link
  38. * The link object.
  39. */
  40. insertLink : function(link) {
  41. var editor = Drupal.settings.linkit.currentInstance.editor;
  42. CKEDITOR.tools.callFunction(editor._.linkitFnNum, link, editor);
  43. }
  44. });
  45. })(jQuery);