wysihtml5 override link dialogue behaviour
Asked Answered
I

1

7

I want to be able to add arbitrary text as link hrefs using wysihtml5. For example: I want to generate this <a href="[~55~]">link</a>

I have worked out how to do this -- here's a simplified example of what I'm doing:

editor = new wysihtml5.Editor("text_area_content", {toolbar: "wysihtml5-toolbar"})  
editor.composer.commands.exec("createLink", { href: "[~"+55+"~]" })

The problem I now have is that, after creating a link, when this link is selected in the editor, the dialog box shows the link as "http://current_url/[~55~]". I want it to show just "[~55~]".

I have tried to bind a new event to links within the editor, but I couldn't work out how to do that (since they are in an iframe).

How can I get the wysihtml5 link dialog to show the link address without displaying the current url?

Ideology answered 7/2, 2014 at 15:45 Comment(0)
T
4

In wysihtml5/src/toolbar/dialog.js a method _interpolate is called on the link which takes the link's attributes and displays them in the dialog. So whatever is in the href="..." is displayed in the input element of the dialog.

Example from the inline documentation:

https://github.com/xing/wysihtml5/blob/master/src/toolbar/dialog.js

<!-- original link -->
    <a href="http://www.google.com" target="_blank">foo</a>

<!-- dialog: -->
    <input type="text" data-wysihtml5-dialog-field="href" value="">
    <input type="text" data-wysihtml5-dialog-field="target" value="">

<!-- after calling _interpolate() the dialog will look like this -->
    <input type="text" data-wysihtml5-dialog-field="href" value="http://www.google.com">
    <input type="text" data-wysihtml5-dialog-field="target" value="_blank">

So if you can extend the method _interpolate in your application you could check when the attribute name is href and then just display the relative part (without the server name).

Travancore answered 12/2, 2014 at 11:8 Comment(3)
Thanks for you answer. It would be super helpful if you could provide an example of how to do something like this.Ideology
Thanks for pointing me in the right direction. A small example for how one might override this default behaviour would still be much appreciated if you could...Ideology
I'll award the bounty for a helpful answer... still an example would make this a really good answer.Ideology

© 2022 - 2024 — McMap. All rights reserved.