medium-editor-rails icon indicating copy to clipboard operation
medium-editor-rails copied to clipboard

Incompatibility with Turbolinks

Open n-studio opened this issue 10 years ago • 5 comments

Hi! The bug is reproducible with: https://github.com/marjinal1st/medium-test

Changing page prevents the tooltip from being displayed.

Workaround:

<script>
  var editor = new MediumEditor('.editable');
  editor.options.elementsContainer = false;
  $('.editable').bind('input propertychange', function(){
    $("#post_" + $(this).attr("data-field-id")).val($(this).html());
  });
</script>

I still don't know if the workaround is clean enough and doesn't produce unwanted bugs.

n-studio avatar Oct 10 '14 16:10 n-studio

@n-studio @marjinal1st

Hi guys - I'm still having the turbo-links issue... I've tried the workaround above and the issue still seems to persist. Any fix as of yet?

MY WORKAROUND:

I simply used https://github.com/rails/turbolinks#opting-out-of-turbolinks to opt out of turbolinks for all links which lead to the editor. A really cheap workaround but it does at least do the trick.

bencoullie avatar Feb 11 '15 19:02 bencoullie

Sorry but I'm not using Turbolinks in my projects, so I don't really know how to fix it :disappointed:

marjinal1st avatar Feb 13 '15 18:02 marjinal1st

No problem, my workaround does the trick. I doubt your average user would even notice the odd pageload.

Thanks for taking the time to reply though.

bencoullie avatar May 19 '15 06:05 bencoullie

I'm currently using turbolinks 5.0.0-beta4 and the only thing you need to do is:

  • Remove Medium Editor before the page loads.
  • Re-attach on page load. So:
var all_medium_editors = null;

$(document).on('turbolinks:before-render', function(){
    if(all_medium_editors != null) {
        all_medium_editors.destroy()
    }
})

$(document).on('turbolinks:load', function(){
    all_medium_editors = new MediumEditor('.editable', {
        // options go here
    });
})

Hope it helps.

rubentrf avatar Apr 08 '16 14:04 rubentrf

@rubentrf I've added your solution as a Wiki page, here.

marjinal1st avatar Apr 08 '16 16:04 marjinal1st