Skip to content

Instantly share code, notes, and snippets.

@chandresh
Created January 9, 2012 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chandresh/1580495 to your computer and use it in GitHub Desktop.
Save chandresh/1580495 to your computer and use it in GitHub Desktop.
$(window).bind('mercury:ready', function() {
var link = $('#mercury_iframe').contents().find('#edit_link');
Mercury.saveURL = link.data('save-url');
link.hide();
});
$(window).bind('mercury:saved', function() {
window.location = window.location.href.replace(/\/editor\//i, '/');
});
@jejacks0n
Copy link

This is pulled directly from my mercury.js.. note that the saveURL is set to mercury/images, because in my scenario it's the only route that accepts posts. It should be noted that the onload function came after the railscast, and is inside your configuration (mercury.js).

  // The onload method is provided as a callback in case you want to override default Mercury Editor behavior.  It will
  // be called directly after the Mercury scripts have loaded, but before anything has been initialized.  It's a good
  // place to add or change functionality.
  onload: function() {
    Mercury.saveURL = '/mercury/images';
    Mercury.on('saved', function() {
      window.location.href = window.location.href.replace(/\/editor\//i, '/');
    });
  }

@chandresh
Copy link
Author

Thanks.. doing a quick test..

@chandresh
Copy link
Author

It seems to be working.. need to tweak it to make the railscasts version... will post that shortly.

@chandresh
Copy link
Author

This works!!

onload: function() {
//Mercury.PageEditor.prototype.iframeSrc = function(url) { return '/testing'; }
Mercury.on('ready', function() {
var link = $('#mercury_iframe').contents().find('#edit_link');
Mercury.saveURL = link.data('save-url');
link.hide();
});

Mercury.on('saved', function() {
  window.location.href = window.location.href.replace(/\/editor\//i, '/');
});

}

@cthree
Copy link

cthree commented Jan 9, 2012

Any chance you could post the whole, working mercury.js file? I'm still not getting a good result.

@chandresh
Copy link
Author

@cthree
Copy link

cthree commented Jan 9, 2012 via email

@chandresh
Copy link
Author

:)

@chandresh
Copy link
Author

For those who read this; please add to your Gemfile, as commented by cthree on main discussion of the issue:

gem 'mercury-rails', git: 'https://github.com/jejacks0n/mercury.git'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment