Skip to content

Instantly share code, notes, and snippets.

@EtienneLem
Created June 19, 2013 17:35
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 EtienneLem/5816208 to your computer and use it in GitHub Desktop.
Save EtienneLem/5816208 to your computer and use it in GitHub Desktop.
The best way to code bookmarlets (with Rails)
def javascript_content(file_name)
Rails.application.assets[file_name].source.html_safe
end
class Bookmarklet
constructor: ->
alert('test')
# Initialization
bookmarklet = new Bookmarklet
<a href="javascript:<%= javascript_content('bookmarklet.js') %>">Bookmarklet</a>
@EtienneLem
Copy link
Author

Also: Live Bookmarklet!

<a href="javascript:(function(){
  if (!window.Bookmarklet) {
    var script = document.createElement('script');
        script.src = '<%= asset_url('bookmarklet.js') %>';

    document.getElementsByTagName('head')[0].appendChild(script);
  } else {
    window.Bookmarklet.toggle()
  }
})();">Bookmarklet</a>

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