jejacks0n / mercury

Mercury Editor: The Rails WYSIWYG editor that allows embedding full page editing capabilities directly inline.
http://jejacks0n.github.com/mercury
Other
2.63k stars 531 forks source link

saveStyle option not used by page_editor? #36

Closed JeanMertz closed 12 years ago

JeanMertz commented 12 years ago

I tried setting the saveStyle option to 'form' to debug some weird behavior while saving Mercury data on a rails app running in production, but it seems like saveStyle is never passed in the pageEditor initialization.

At first I wanted to use the ?saveStyle=form option, but I couldn't, because I use sprockets and it doesn't allow for any params to be added to filenames, so instead I injected it directly in the default options block in mercury.js, like:

 var options = {
    // A path or url from which the javascripts and css should be loaded.
    src: '/assets',
    saveStyle: 'form',
    // A value defined in the packages above.  Development is used by default.  If you want to provide your own package
    // you can just define one before including this script.
    pack: 'development'
  };

but the content was never submitted as form data. In the end I uncommented line 156 in page_editor.js.coffee to make it work, any thoughts on this?

JeanMertz commented 12 years ago

I reinstalled the gem and used the install command, which gave me the mercury.html.erb layout file, which has all the options in there. So I guess this is where I can modify these settings.

The only thing I don't understand yet is how to use this layout? Should the layout be used for all the pages where I want to activate the editor? Or should the layout automatically be used by the gem? As it stands now, I don't see the file being used at all (the javascript snippet with the config vars isn't anywhere in the page source).

I noticed the layout being used in the MercuryController, which I guess is loaded only when using the routes method instead of the mercury_loader.js method. I use the latter because I'd like to keep the url's the same for both the viewing of the page and editing the page, to minimize the confusion for people. So I guess that means I'll see about including the layout in editing mode, and how that works.

I tried using a conditional to load the mercury layout when a user is signed_in layout Proc.new { |controller| signed_in? ? 'mercury' : 'application' }, only: :show, but that turned the editor in a never-ending loop loading the editor over and over again in each iframe

JeanMertz commented 12 years ago

I looked some more into this but it seems custom options aren't loaded when using the mercury_loader.js method.

This is what I found in the code:

// Instantiate the PageEditor, passing in the options that were provided to the loader.
new Mercury.PageEditor(null, {visible: true});

It says it loads the PageEditor using the supplied potions, but it simply passes in null and {visible: true}. I changed {visible: true} to options, which did the trick, but I am not sure if this is a bug, and if so, how you want to handle this.