Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#885 closed enhancement (wontfix)

More possibilities in createLink function

Reported by: henrik.andersen@… Owned by: gogo
Priority: normal Milestone: Version 1.0
Component: Xinha Core Version:
Severity: normal Keywords:
Cc:

Description

Add more possibilities to createLink function, so that people can make their own link popup and dont have to change htmlarea.js and more functionality can be added to the link popup in the future.

Added class and accessKey

NEW CODE FOR HTMLAREA.JS:

HTMLArea.prototype._createLink = function(link)
{

var editor = this;
var outparam = null;
if ( typeof link == "undefined" )
{

link = this.getParentElement();
if ( link )
{

while (link && !/a$/i.test(link.tagName))
{

link = link.parentNode;

}

}

}
if ( !link )
{

var sel = editor._getSelection();
var range = editor._createRange(sel);
var compare = 0;
if ( HTMLArea.is_ie )
{

if ( sel.type == "Control" )
{

compare = range.length;

}
else
{

compare = range.compareEndPoints("StartToEnd?", range);

}

}
else
{

compare = range.compareBoundaryPoints(range.START_TO_END, range);

}
if ( compare === 0 )
{

alert(HTMLArea._lc("You need to select some text before creating a link"));
return;

}
outparam =
{

f_href : ,
f_title :
,
f_target : ,
f_class :
,

f_key : ,

f_usetarget : editor.config.makeLinkShowsTarget

};

}
else
{

outparam =
{

f_href : HTMLArea.is_ie ? editor.stripBaseURL(link.href) : link.getAttribute("href"),
f_title : link.title,
f_target : link.target,
f_class : link.className,

f_key : link.accessKey,

f_usetarget : editor.config.makeLinkShowsTarget

};

}
this._popupDialog(

editor.config.URIs.link,
function(param)
{

if ( !param )
{

return false;

}
var a = link;
if ( !a )
{

try
{

var tmp = HTMLArea.uniq('http://www.example.com/Link');
editor._doc.execCommand('createlink', false, tmp);

Fix them up
var anchors = editor._doc.getElementsByTagName('a');
for(var i = 0; i < anchors.length; i++)
{

var anchor = anchors[i];
if(anchor.href == tmp)
{

Found one.
if (!a) a = anchor;
anchor.href = param.f_href;
if (param.f_target) anchor.target = param.f_target;
if (param.f_title) anchor.title = param.f_title;
if (param.f_class) anchor.className = param.f_class;
if (param.f_key) anchor.accessKey = param.f_key;

}

}

} catch(ex) {}

}
else
{

var href = param.f_href.trim();
editor.selectNodeContents(a);
if ( href === )
{

editor._doc.execCommand("unlink", false, null);
editor.updateToolbar();
return false;

}
else
{

a.href = href;

}

}
if ( ! ( a && a.tagName.toLowerCase() == 'a' ) )
{

return false;

}
a.target = param.f_target.trim();
a.title = param.f_title.trim();
a.className = param.f_class;
a.accessKey = param.f_key;
editor.selectNodeContents(a);
editor.updateToolbar();

},
outparam);

};

Change History (5)

comment:1 Changed 13 years ago by ray

Could you 1. explain what this change does 2. provide this as a patch

comment:2 Changed 13 years ago by ray

Could you 1. explain what this change does 2. provide this as a patch?

comment:3 Changed 13 years ago by henrik.andersen@…

See my reply on this ticket

http://xinha.python-hosting.com/ticket/884

comment:4 Changed 13 years ago by ray

  • Resolution set to wontfix
  • Status changed from new to closed

_createLink() moved to external file popups/link.js

Everybody who would like to extend link.html can chanke the function as they wish. No need for a central change here

comment:5 Changed 13 years ago by gogo

Just to remind people that they shouldn't edit any of the core Xinha stuff anyway, including files in popups, unless they want to make it harder to upgrade.

A plugin, or even just some javascript code in your own file, can easily override (redefine) any Xinha function it requires (ie the ticket opener could easily have stuck that whole _createImage method definition in thier own file after loading htmlarea.js and it would have worked as they wanted, with no modification to htmlarea.js required).

Note: See TracTickets for help on using tickets.