Browse files

MDL-7043: fix insert link functionality to allow linking to images again

Author: Matt Clarkson <mattc@catalyst.net.nz>
  • Loading branch information...
1 parent acd404e commit 4fb68891b0853ac7ea17f6a25589e354fc5127c0 mattc-catalyst committed Aug 6, 2007
Showing with 16 additions and 14 deletions.
  1. +16 −14 lib/editor/htmlarea/htmlarea.php
View
30 lib/editor/htmlarea/htmlarea.php
@@ -1526,21 +1526,23 @@ function (str, l1, l2, l3) {
}
var a = link;
if (!a) {
- // Since startContainer check does not work
- // very well in Moz use just insertHTML.
- var sel = editor._getSelection();
- var range = editor._createRange(sel);
- var strLink = '<a href="'+ param.f_href.trim() +'"';
- if ( param.f_title != "" ) {
- strLink += ' title="'+ param.f_title.trim() +'"';
- }
- if ( param.f_target != "" ) {
- strLink += ' target="'+ param.f_target.trim() +'"';
+ // Create a temporary unique link, insert it then find it and set the correct parameters
+ var tmpLink = 'http://www.moodle.org/'+Math.random();
+ var elm = editor._doc.execCommand("createlink",false,tmpLink);
+ var links=editor._doc.getElementsByTagName("a");
+ for(var i=0;i<links.length;i++){
+ var link=links[i];
+ if(link.href==tmpLink) {
+ link.href=param.f_href.trim();
+ if(param.f_target){
+ link.target=param.f_target.trim();
+ }
+ if(param.f_title){
+ link.title=param.f_title.trim();
+ }
+ break;
+ }
}
- strLink += '>';
- strLink += (!HTMLArea.is_ie) ? sel : range.text;
- strLink += '</a>';
- editor.insertHTML(strLink);
} else {
var href = param.f_href.trim();
editor.selectNodeContents(a);

0 comments on commit 4fb6889

Please sign in to comment.