PDA

View Full Version : Repopulating the Link in HTMLEditor



digitalkaoz
28 Dec 2010, 1:56 AM
He folks,

not really a bug, but an improvement to the Link Helper in the HtmlEditor. Currently the Link Target wont be repopulated if you click the button with a link selected.

here is the fix to repopulate the link target:



/** HtmlEditor.js **/

createLink : function() {
var sel = false;
if (window.getSelection) {
sel = this.getWin().getSelection();
} else if (document.getSelection) {
sel = this.getDoc().getSelection();
}

var linkValue = this.defaultLinkValue;
if(sel && sel.getRangeAt(0).cloneContents().querySelector('a')){
linkValue = sel.getRangeAt(0).cloneContents().querySelector('a').getAttribute('href');
}

var url = prompt(this.createLinkText, linkValue);
if(url && url != 'http:/'+'/') {
if (sel) {
this.insertAtCursor('<a href="'+url+'">'+sel+'</a>');
} else if (document.selection) {
sel = this.getDoc().selection.createRange();
sel.pasteHTML('<a href="'+url+'">'+sel.text+'</a>');
} else this.relayCmd('createlink', url);
}
}