Insert Sitecore Link Clears Out All Attributes

  • Twitter
  • LinkedIn

Insert Sitecore Link Clears Out All Attributes

Currently in Sitecore 6.6.0 (rev. 130214) . If you have a link with attributes like class or target in the

function scInsertSitecoreLink(sender, returnValue) {
  if (!returnValue) {
    return;
  }

    var d = scEditor.getSelection().getParentElement();
    var cssClass = d.getAttribute("class");
    var target = d.getAttribute("target");
    var title = d.getAttribute("title");
    var attributes = "";
    if (cssClass != "" && cssClass != null) {
        attributes = " class=\"" + cssClass + "\"";
    }
    if (target != "" && target != null) {
        attributes += " target=\"" + target + "\"";
    }
    if (title != "" && title != null) {
        attributes += " title=\"" + title + "\"";
    }

  if ($telerik.isFirefox && d.tagName == "A") {
    d.parentNode.removeChild(d);
  } else {
    scEditor.fire("Unlink");
  }

  var text = scEditor.getSelectionHtml();

  if (text == "" || text == null || ((text != null) && (text.length == 15) && (text.substring(2, 15).toLowerCase() == "

"))) { text = returnValue.text; } else { // if selected string is a full paragraph, we want to insert the link inside the paragraph, and not the other way around. var regex = /^[\s]*

(.+)<\/p>[\s]*$/i; var match = regex.exec(text); if (match && match.length >= 2) { scEditor.pasteHtml("

" + match[1] + "

", "DocumentManager"); return; } } scEditor.pasteHtml("" + text + "", "DocumentManager"); }

Simply put, the standard script grabs the original element to parse in the text for the link. You just piggy back on that to return any elements you want to go along with it. I am pulling through class, target, and title. Others could be added and appended to the attributes variable as needed.

Related Blogs

Latest Blogs