⚠️ Author Warning ⚠️
I added this wrapper to give access to the zclip Jquery plugin. Nevertheless I can not recommend Zclip. A better solution is to use the zeroclipboard-rails.
Zclip::Rails
Adds easy copytoclipboard functionality to your html-elements this is done by including the Jquery zClip libary to Rails 3.x.
Installation
Add this line to your application's Gemfile:
gem 'zclip-rails'
And then execute:
$ bundle
Add this line to your application.js:
//= require zclip
Usage
Add an element (button, input, div, span etc.) somewhere in your .erb template e.g.:
<button type="button" id="copy-some-txt">example</button>
Add this in some required js file of your app:
$('#copy-some-txt').zclip({
copy: "this is the text to copy"
});
Supply custom callback functions
$('#copy-some-txt').zclip({
copy: "this is the text to copy",
beforeCopy: function() {
alert("I am going to copy some text to your clipboard");
},
afterCopy: function() {
alert("done");
}
});
Settings
Settings |
||
---|---|---|
Variable |
Default Value |
Available Values |
copy * | null | any string, or any javascript expression or function that returns a string |
afterCopy | null | specify a function to call after text is copied. (your afterCopy function will overwrite the default alert box.) |
beforeCopy | null | specify a function to call before text is copied. |
clickAfter | true | true false |
setHandCursor | true | true false |
setCSSEffects | true | true false |
* required |
Notes
Proper CSS effects
zClip is a flash overlay, so it must provide the target element with "hover" and "active" classes to simulate native :hover and :active states. Be sure to write your CSS as follows for best results:
a:hover, a.hover {...}
a:active, a.active {...}
$('a.copy').zclip('show'); // enable zClip on the selected element
$('a.copy').zclip('hide'); // hide zClip on the selected element
$('a.copy').zclip('remove'); // remove zClip from the selected element
Requirements
- jquery
- Rails 3.x
Browsersupport
The Zero Clipboard Library has been tested on the following browsers / platforms:
Browser | Windows XP SP3 | Windows Vista | Mac OS X Leopard |
Internet Exploder | 7.0 | 7.0 | - |
Firefox | 3.0 | 3.0 | 3.0 |
Safari | - | - | 3.0 |
Google Chrome | 1.0 | 1.0 | - |
Adobe Flash Flash Player versions 9 and 10 are supported.
TODO
- Write a gem tests
Credits
-
Thanks to Joseph Huckaby for writing the zeroclipboard libary.
-
Thanks to steamdev.com for writing the jQuery wrapper.
-
Thanks to all the contributers to this Project.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request