marjinal1st / medium-editor-rails

This project is not maintained anymore. If you'd like to maintain, I can transfer ownership. Contact me at marjinalist1@gmail.com
MIT License
120 stars 35 forks source link

Incompatibility with Turbolinks #5

Open n-studio opened 10 years ago

n-studio commented 10 years ago

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.

bencoullie commented 9 years ago

@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.

marjinal1st commented 9 years ago

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

bencoullie commented 9 years ago

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.

rubentrf commented 8 years ago

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

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.

marjinal1st commented 8 years ago

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