Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use links in Medium Editor?

I've been trying out the excellent Medium Editor. The problem that I've been having is that I can't seem to get links to "work".

At the simplest, here's some HTML/JS to use to demonstrate the problem:

HTML:

<html>
<head>
  <script src="//cdn.jsdelivr.net/medium-editor/latest/js/medium-editor.min.js"></script>
  <link rel="stylesheet" href="//cdn.jsdelivr.net/medium-editor/latest/css/medium-editor.min.css" type="text/css" media="screen" charset="utf-8">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/medium-editor/latest/css/themes/beagle.min.css" type="text/css">
</head>
<body>
  <div class='editable'>
    Hello world.  <a href="http://www.google.com">link</a>
  </div>
</body>
</html>

Javascript:

var editor = new MediumEditor('.editable');

This fiddle demonstrates the problem (using the code above).

  • If you hover on the link, a popup appears.
  • If you click the link, nothing happens.
  • If you click the popup, a form appears where you can edit the link.

It seems to me that clicking the link should take me wherever the link's href is targeting. The only way to use the link is to right click and either open in a new tab or new window -- which I don't want to ask my users to do.

I feel like I must be missing something simple in the configuration (either the Anchor Preview Options or the Anchor Form Options). Unfortunately, I'm not seeing it.

In my actual application, I'm not using jQuery, but I am using angularjs. If a strictly Medium Editor answer doesn't exist, I can fall back to using basic JS or anything that angularjs provides.

like image 360
mgilson Avatar asked Dec 08 '15 19:12

mgilson


People also ask

Can you put links on Medium?

External linksAffiliate links are allowed on Medium, however, according to Medium's rules any affiliate links or outside payment received for writing a story MUST be disclosed somewhere in the story.

What links are not allowed on Medium?

Ads, Promotions, and MarketingImages functioning as third-party ads are not allowed. Inline images or embeds that link out and function as banner ads for third-party brands are not allowed. You must disclose affiliate links.

How do friend links work on Medium?

You can share a Friend Link with anyone. As long as they have that link, they'll have free access. And people can share it with other people too — it doesn't just have to come from you. They will need to receive the link from you, however — only the author can see the Friend Link when viewing their stories.


1 Answers

I've found how to bind event.

Here is full event list https://github.com/yabwe/medium-editor/blob/master/CUSTOM-EVENTS.md

Try to change your code to

var editor = new MediumEditor('.editable')
    .subscribe("editableClick", function(e){if (e.target.href) {window.open(e.target.href)}})

https://jsfiddle.net/fhr18gm1/

like image 165
Valijon Avatar answered Oct 09 '22 04:10

Valijon