Sinatra::ZeroClipboard
Sinatra::ZeroClipboard is a sinatra plugin to access ZeroClipboard, a Flash-based cross-browser clipboard library. Accessing the clipboard from pure Javascript is still disabled on most browser due to security concerns, but sometimes needed in a project to improve user experience. This gem should mitigate this nuisance until better options are broadly available.
Requirements:
server-side:
- sinatra >= 1.4.2
client-side:
- Javascript & Flash-enabled Browser
Usage:
Add gem to your Gemfile
gem "sinatra-zero_clipboard"
Require the gem
require 'sinatra/zero_clipboard'
Register helper for asset routes
class SampleApplication < Sinatra::Base
# ...
register Sinatra::ZeroClipboard::Assets
# ...
end
Add asset links to HTML head
%html
%head
= zero_clipboard_assets
Add a button
%button{ id: "clip_button", data-clipboard-text: "Default text", data-clipboard-target: "text_to_copy" }
%span Copy to Clipboard
Add a target
%textarea{ id: "text_to_copy", rows: "3" cols: "40"} I'm getting copied, Yeah!
Add ZeroClipboard Javascript binding
var clip = new ZeroClipboard(document.getElementById("clip_button"), {
moviePath: "swf/ZeroClipboard.swf"
});
More Information
For more ZeroClipboard Javascript options look here