The image link button always inserts a reference-style link with the URL at the bottom of the content, instead of having a checkbox for an "Inline" URL or not, which the regular link inserter has.

Doesn't look hard to add. I would make a patch, but I'm already using the Drupal 7 patch.

Comments

fretje’s picture

It wasn't hard indeed, just had to copy over some code from the link section :)
Although I'm not familiar with creating patches, so here are the functions in which I made changes:

/*******************************************************************************
* IMAGE
******************************************************************************/

/**
 * Displays a dialog where the user can add an inline image. The reference is
 * added to the reference section of the BUE. The IMCE dialog is integrated
 * if IMCE is enabled.
 */
markdownEditor.image = function () {
  var t = markdownEditor.t;
  var tag = Cactus.DOM.tag;
  var createForm = markdownEditor.dialog.createForm;

  // Default values for form fields.
  var hrefValue = "";
  var referenceValue = "";
  var titleValue = "";
  var textValue = BUE.active.getSelection();
  var inlineValue = null;

  // Creating the form for the dialog.
  var form = createForm(
    { label : t("Short Desc."), mandatory : true, attributes : { name : "text", value : textValue } },
    { label : t("Long Desc."), attributes : { name : "title", value : titleValue } },
    { label : t("Reference"), attributes : { name : "reference", value : referenceValue } },
    { label : t("URL"), mandatory : true, attributes : { name : "href", value : hrefValue } },
    { label : t("Inline"), attributes : { name : "inline", type : "checkbox", checked: "checked", value: inlineValue } }
  );

  // Create an onsubmit handler and various buttons.
  var submitFunction = markdownEditor.image._process.bind(null, form, "Images");
  var mDialog = markdownEditor.dialog;
  mDialog.setOnsubmit(form, submitFunction);
  mDialog.addIMCELink(form.elements.href.parentNode, form.elements.href);
  mDialog.addCancelButton(form);
  mDialog.addSubmitButton(form, submitFunction);
  mDialog.addHelpButton(form, "image");

  // Open the dialog and display the form.
  mDialog.open(t("Insert image"), "image");
  mDialog.getContent().appendChild(form);
  mDialog.focusFirst();
};

/**
 * Handles submissions for adding images.
 *
 * @param form
 *   The form element of the dialog.
 */
markdownEditor.image._process = function (form) {
  var Reference = markdownEditor.Reference;
  var t = markdownEditor.t;

  var referenceType = "Images";
  var text = form.elements.text.value;
  var reference = form.elements.reference.value || text;
  var href = form.elements.href.value;
  var title = form.elements.title.value;
  var inline = form.elements.inline.checked || false;

  // Validate input.
  markdownEditor.dialog.clearErrors();
  var valid = true;
  if (!text) {
    markdownEditor.dialog.addError(t("Text is a required field."));
    valid = false;
  }
  if (!href) {
    markdownEditor.dialog.addError(t("URL is a required field."));
    valid = false;
  }
  if (!valid) {
    return;
  }

  if (inline) {
    // Insert inline link after caret position
    var replaceString = "![" + text + "](" + href + ( title ? ' "' + title + '"' : '' ) + ")";
    markdownEditor.selection.replaceAll(replaceString);
    BUE.dialog.close();
  }
  else {
    // The text added at the caret position.
    var textString = text ? "![" + text + "][" + reference + "]" : "![" + reference + "]";
    // The reference to add to the reference section.
    var ref = new Reference(referenceType, reference, href + (title ? ' "' + title + '"' : ""));
    markdownEditor.references._callback(textString, ref);
  }
};

I hope someone will be so kind to create a patch out of that ;-)
I did it on the 7.x-1.x-dev version, but I think the changes for the 6.x version are the same.

frjo’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Active » Fixed

Committed to 7-dev.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.