1
0
mirror of https://github.com/github/choosealicense.com synced 2024-12-22 21:00:10 +01:00

Merge pull request #301 from OmgImAlexis/gh-pages

Replaced zeroclipboard with clipboard.js
This commit is contained in:
Ben Balter 2015-10-25 16:42:35 -04:00
commit c85e54523b
30 changed files with 930 additions and 1510 deletions

5
.gitignore vendored
View File

@ -2,9 +2,8 @@
/_site /_site
/node_modules /node_modules
/.bundle /.bundle
assets/vendor/zeroclipboard/docs assets/vendor/clipboard/src
assets/vendor/zeroclipboard/src assets/vendor/clipboard/test
assets/vendor/zeroclipboard/test
assets/vendor/selectivizr/tests assets/vendor/selectivizr/tests
assets/vendor/qtip2/basic assets/vendor/qtip2/basic
/vendor /vendor

View File

@ -35,7 +35,7 @@ exclude:
- test - test
- tests - tests
- assets/vendor/selectivizr/tests - assets/vendor/selectivizr/tests
- assets/vendor/zeroclipboard/test - assets/vendor/clipboard/test
gems: gems:
- jekyll-sitemap - jekyll-sitemap

View File

@ -18,7 +18,7 @@
{% if page.collection == "licenses" or page.class == "license-types" %} {% if page.collection == "licenses" or page.class == "license-types" %}
<script src="/assets/vendor/jquery/jquery.min.js"></script> <script src="/assets/vendor/jquery/jquery.min.js"></script>
<script src="/assets/vendor/qtip2/jquery.qtip.min.js"></script> <script src="/assets/vendor/qtip2/jquery.qtip.min.js"></script>
<script src="/assets/vendor/zeroclipboard/ZeroClipboard.min.js"></script> <script src="/assets/vendor/clipboard/dist/clipboard.min.js"></script>
<script> <script>
window.annotations = {{ site.data.rules | jsonify }}; window.annotations = {{ site.data.rules | jsonify }};
</script> </script>

View File

@ -1,6 +1,6 @@
<div class="sidebar"> <div class="sidebar">
<a href="#" data-clipboard-target="license-text" data-proofer-ignore="true" class="js-clipboard-button button">Copy license text to clipboard</a> <a href="#" data-clipboard-target="#license-text" data-proofer-ignore="true" class="js-clipboard-button button">Copy license text to clipboard</a>
<div class="how-to-apply"> <div class="how-to-apply">
<h5>How to apply this license</h5> <h5>How to apply this license</h5>
<p> <p>

View File

@ -54,22 +54,16 @@ class Choosealicense
false false
# Initializes ZeroClipboard # Initializes Clipboard.js
initClipboard: -> initClipboard: ->
# Backup the clipboard button's original text. # Backup the clipboard button's original text.
$(".js-clipboard-button").data "clipboard-prompt", $(".js-clipboard-button").text() $(".js-clipboard-button").data "clipboard-prompt", $(".js-clipboard-button").text()
# Hook up copy to clipboard buttons # Hook up copy to clipboard buttons
clip = new ZeroClipboard $(".js-clipboard-button"), clip = new Clipboard ".js-clipboard-button"
moviePath: "/assets/vendor/zeroclipboard/ZeroClipboard.swf"
clip.on "mouseout", @clipboardMouseout clip.on "mouseout", @clipboardMouseout
clip.on "complete", @clipboardComplete clip.on "complete", @clipboardComplete
# Fallback if flash is not available
$(".js-clipboard-button").click (e) =>
target = "#" + $(e.target).data("clipboard-target")
@selectText $(target)[0]
# Callback to restore the clipboard button's original text # Callback to restore the clipboard button's original text
clipboardMouseout: (client, args) -> clipboardMouseout: (client, args) ->
@textContent = $(this).data("clipboard-prompt") @textContent = $(this).data("clipboard-prompt")

31
assets/vendor/clipboard/.bower.json vendored Normal file
View File

@ -0,0 +1,31 @@
{
"name": "clipboard",
"version": "1.4.3",
"description": "Modern copy to clipboard. No Flash. Just 2kb",
"license": "MIT",
"main": "dist/clipboard.js",
"ignore": [
"/.*/",
"/example/",
"/test/",
"/.*",
"/bower.json",
"/karma.conf.js"
],
"keywords": [
"clipboard",
"copy",
"cut"
],
"homepage": "https://github.com/zenorocha/clipboard.js",
"_release": "1.4.3",
"_resolution": {
"type": "version",
"tag": "v1.4.3",
"commit": "705e2dbefdf40911ee2fe266a514b982d3edd0b6"
},
"_source": "git://github.com/zenorocha/clipboard.js.git",
"_target": "~1.4.3",
"_originalSource": "clipboard",
"_direct": true
}

20
assets/vendor/clipboard/bower.json vendored Normal file
View File

@ -0,0 +1,20 @@
{
"name": "clipboard",
"version": "1.4.3",
"description": "Modern copy to clipboard. No Flash. Just 2kb",
"license": "MIT",
"main": "dist/clipboard.js",
"ignore": [
"/.*/",
"/example/",
"/test/",
"/.*",
"/bower.json",
"/karma.conf.js"
],
"keywords": [
"clipboard",
"copy",
"cut"
]
}

28
assets/vendor/clipboard/contributing.md vendored Normal file
View File

@ -0,0 +1,28 @@
# Contributing guide
Want to contribute to Clipboard.js? Awesome!
There are many ways you can contribute, see below.
## Opening issues
Open an issue to report bugs or to propose new features.
- Reporting bugs: describe the bug as clearly as you can, including steps to reproduce, what happened and what you were expecting to happen. Also include browser version, OS and other related software's (npm, Node.js, etc) versions when applicable.
- Proposing features: explain the proposed feature, what it should do, why it is useful, how users should use it. Give us as much info as possible so it will be easier to discuss, access and implement the proposed feature. When you're unsure about a certain aspect of the feature, feel free to leave it open for others to discuss and find an appropriate solution.
## Proposing pull requests
Pull requests are very welcome. Note that if you are going to propose drastic changes, be sure to open an issue for discussion first, to make sure that your PR will be accepted before you spend effort coding it.
Fork the Clipboard.js repository, clone it locally and create a branch for your proposed bug fix or new feature. Avoid working directly on the master branch.
Implement your bug fix or feature, write tests to cover it and make sure all tests are passing (run a final `npm test` to make sure everything is correct). Then commit your changes, push your bug fix/feature branch to the origin (your forked repo) and open a pull request to the upstream (the repository you originally forked)'s master branch.
## Documentation
Documentation is extremely important and takes a fair deal of time and effort to write and keep updated. Please submit any and all improvements you can make to the repository's docs.
## Known issues
If you're using npm@3 you'll probably face some issues related to peerDependencies.
https://github.com/npm/npm/issues/9204

View File

@ -0,0 +1,587 @@
/*!
* clipboard.js v1.4.3
* https://zenorocha.github.io/clipboard.js
*
* Licensed MIT © Zeno Rocha
*/
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Clipboard = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var matches = require('matches-selector')
module.exports = function (element, selector, checkYoSelf) {
var parent = checkYoSelf ? element : element.parentNode
while (parent && parent !== document) {
if (matches(parent, selector)) return parent;
parent = parent.parentNode
}
}
},{"matches-selector":2}],2:[function(require,module,exports){
/**
* Element prototype.
*/
var proto = Element.prototype;
/**
* Vendor function.
*/
var vendor = proto.matchesSelector
|| proto.webkitMatchesSelector
|| proto.mozMatchesSelector
|| proto.msMatchesSelector
|| proto.oMatchesSelector;
/**
* Expose `match()`.
*/
module.exports = match;
/**
* Match `el` to `selector`.
*
* @param {Element} el
* @param {String} selector
* @return {Boolean}
* @api public
*/
function match(el, selector) {
if (vendor) return vendor.call(el, selector);
var nodes = el.parentNode.querySelectorAll(selector);
for (var i = 0; i < nodes.length; ++i) {
if (nodes[i] == el) return true;
}
return false;
}
},{}],3:[function(require,module,exports){
var closest = require('closest');
/**
* Delegate event `type` to `selector`
* and invoke `fn(e)`. A callback function
* is returned which may be passed to `.unbind()`.
*
* @param {Element} el
* @param {String} selector
* @param {String} type
* @param {Function} fn
* @param {Boolean} capture
* @return {Function}
*/
exports.bind = function(el, selector, type, fn, capture){
return el.addEventListener(type, function(e){
var target = e.target || e.srcElement;
e.delegateTarget = closest(target, selector, true, el);
if (e.delegateTarget) fn.call(el, e);
}, capture);
};
/**
* Unbind event `type`'s callback `fn`.
*
* @param {Element} el
* @param {String} type
* @param {Function} fn
* @param {Boolean} capture
*/
exports.unbind = function(el, type, fn, capture){
el.removeEventListener(type, fn, capture);
};
},{"closest":1}],4:[function(require,module,exports){
function select(element) {
var selection = window.getSelection();
if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
element.selectionStart = 0;
element.selectionEnd = element.value.length;
}
else {
var range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
}
return selection.toString();
}
module.exports = select;
},{}],5:[function(require,module,exports){
function E () {
// Keep this empty so it's easier to inherit from
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
}
E.prototype = {
on: function (name, callback, ctx) {
var e = this.e || (this.e = {});
(e[name] || (e[name] = [])).push({
fn: callback,
ctx: ctx
});
return this;
},
once: function (name, callback, ctx) {
var self = this;
function listener () {
self.off(name, listener);
callback.apply(ctx, arguments);
};
listener._ = callback
return this.on(name, listener, ctx);
},
emit: function (name) {
var data = [].slice.call(arguments, 1);
var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
var i = 0;
var len = evtArr.length;
for (i; i < len; i++) {
evtArr[i].fn.apply(evtArr[i].ctx, data);
}
return this;
},
off: function (name, callback) {
var e = this.e || (this.e = {});
var evts = e[name];
var liveEvents = [];
if (evts && callback) {
for (var i = 0, len = evts.length; i < len; i++) {
if (evts[i].fn !== callback && evts[i].fn._ !== callback)
liveEvents.push(evts[i]);
}
}
// Remove event from queue to prevent memory leak
// Suggested by https://github.com/lazd
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
(liveEvents.length)
? e[name] = liveEvents
: delete e[name];
return this;
}
};
module.exports = E;
},{}],6:[function(require,module,exports){
'use strict';
exports.__esModule = true;
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _select = require('select');
var _select2 = _interopRequireDefault(_select);
/**
* Inner class which performs selection from either `text` or `target`
* properties and then executes copy or cut operations.
*/
var ClipboardAction = (function () {
/**
* @param {Object} options
*/
function ClipboardAction(options) {
_classCallCheck(this, ClipboardAction);
this.resolveOptions(options);
this.initSelection();
}
/**
* Defines base properties passed from constructor.
* @param {Object} options
*/
ClipboardAction.prototype.resolveOptions = function resolveOptions() {
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
this.action = options.action;
this.emitter = options.emitter;
this.target = options.target;
this.text = options.text;
this.trigger = options.trigger;
this.selectedText = '';
};
/**
* Decides which selection strategy is going to be applied based
* on the existence of `text` and `target` properties.
*/
ClipboardAction.prototype.initSelection = function initSelection() {
if (this.text && this.target) {
throw new Error('Multiple attributes declared, use either "target" or "text"');
} else if (this.text) {
this.selectFake();
} else if (this.target) {
this.selectTarget();
} else {
throw new Error('Missing required attributes, use either "target" or "text"');
}
};
/**
* Creates a fake textarea element, sets its value from `text` property,
* and makes a selection on it.
*/
ClipboardAction.prototype.selectFake = function selectFake() {
var _this = this;
this.removeFake();
this.fakeHandler = document.body.addEventListener('click', function () {
return _this.removeFake();
});
this.fakeElem = document.createElement('textarea');
this.fakeElem.style.position = 'absolute';
this.fakeElem.style.left = '-9999px';
this.fakeElem.style.top = (window.pageYOffset || document.documentElement.scrollTop) + 'px';
this.fakeElem.setAttribute('readonly', '');
this.fakeElem.value = this.text;
document.body.appendChild(this.fakeElem);
this.selectedText = _select2['default'](this.fakeElem);
this.copyText();
};
/**
* Only removes the fake element after another click event, that way
* a user can hit `Ctrl+C` to copy because selection still exists.
*/
ClipboardAction.prototype.removeFake = function removeFake() {
if (this.fakeHandler) {
document.body.removeEventListener('click');
this.fakeHandler = null;
}
if (this.fakeElem) {
document.body.removeChild(this.fakeElem);
this.fakeElem = null;
}
};
/**
* Selects the content from element passed on `target` property.
*/
ClipboardAction.prototype.selectTarget = function selectTarget() {
this.selectedText = _select2['default'](this.target);
this.copyText();
};
/**
* Executes the copy operation based on the current selection.
*/
ClipboardAction.prototype.copyText = function copyText() {
var succeeded = undefined;
try {
succeeded = document.execCommand(this.action);
} catch (err) {
succeeded = false;
}
this.handleResult(succeeded);
};
/**
* Fires an event based on the copy operation result.
* @param {Boolean} succeeded
*/
ClipboardAction.prototype.handleResult = function handleResult(succeeded) {
if (succeeded) {
this.emitter.emit('success', {
action: this.action,
text: this.selectedText,
trigger: this.trigger,
clearSelection: this.clearSelection.bind(this)
});
} else {
this.emitter.emit('error', {
action: this.action,
trigger: this.trigger,
clearSelection: this.clearSelection.bind(this)
});
}
};
/**
* Removes current selection and focus from `target` element.
*/
ClipboardAction.prototype.clearSelection = function clearSelection() {
if (this.target) {
this.target.blur();
}
window.getSelection().removeAllRanges();
};
/**
* Sets the `action` to be performed which can be either 'copy' or 'cut'.
* @param {String} action
*/
/**
* Destroy lifecycle.
*/
ClipboardAction.prototype.destroy = function destroy() {
this.removeFake();
};
_createClass(ClipboardAction, [{
key: 'action',
set: function set() {
var action = arguments.length <= 0 || arguments[0] === undefined ? 'copy' : arguments[0];
this._action = action;
if (this._action !== 'copy' && this._action !== 'cut') {
throw new Error('Invalid "action" value, use either "copy" or "cut"');
}
},
/**
* Gets the `action` property.
* @return {String}
*/
get: function get() {
return this._action;
}
/**
* Sets the `target` property using an element
* that will be have its content copied.
* @param {Element} target
*/
}, {
key: 'target',
set: function set(target) {
if (target !== undefined) {
if (target && typeof target === 'object' && target.nodeType === 1) {
this._target = target;
} else {
throw new Error('Invalid "target" value, use a valid Element');
}
}
},
/**
* Gets the `target` property.
* @return {String|HTMLElement}
*/
get: function get() {
return this._target;
}
}]);
return ClipboardAction;
})();
exports['default'] = ClipboardAction;
module.exports = exports['default'];
},{"select":4}],7:[function(require,module,exports){
'use strict';
exports.__esModule = true;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var _clipboardAction = require('./clipboard-action');
var _clipboardAction2 = _interopRequireDefault(_clipboardAction);
var _delegate = require('delegate');
var _delegate2 = _interopRequireDefault(_delegate);
var _tinyEmitter = require('tiny-emitter');
var _tinyEmitter2 = _interopRequireDefault(_tinyEmitter);
/**
* Base class which takes a selector, delegates a click event to it,
* and instantiates a new `ClipboardAction` on each click.
*/
var Clipboard = (function (_Emitter) {
_inherits(Clipboard, _Emitter);
/**
* @param {String} selector
* @param {Object} options
*/
function Clipboard(selector, options) {
_classCallCheck(this, Clipboard);
_Emitter.call(this);
this.resolveOptions(options);
this.delegateClick(selector);
}
/**
* Helper function to retrieve attribute value.
* @param {String} suffix
* @param {Element} element
*/
/**
* Defines if attributes would be resolved using internal setter functions
* or custom functions that were passed in the constructor.
* @param {Object} options
*/
Clipboard.prototype.resolveOptions = function resolveOptions() {
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
this.action = typeof options.action === 'function' ? options.action : this.defaultAction;
this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;
this.text = typeof options.text === 'function' ? options.text : this.defaultText;
};
/**
* Delegates a click event on the passed selector.
* @param {String} selector
*/
Clipboard.prototype.delegateClick = function delegateClick(selector) {
var _this = this;
this.binding = _delegate2['default'].bind(document.body, selector, 'click', function (e) {
return _this.onClick(e);
});
};
/**
* Undelegates a click event on body.
* @param {String} selector
*/
Clipboard.prototype.undelegateClick = function undelegateClick() {
_delegate2['default'].unbind(document.body, 'click', this.binding);
};
/**
* Defines a new `ClipboardAction` on each click event.
* @param {Event} e
*/
Clipboard.prototype.onClick = function onClick(e) {
if (this.clipboardAction) {
this.clipboardAction = null;
}
this.clipboardAction = new _clipboardAction2['default']({
action: this.action(e.delegateTarget),
target: this.target(e.delegateTarget),
text: this.text(e.delegateTarget),
trigger: e.delegateTarget,
emitter: this
});
};
/**
* Default `action` lookup function.
* @param {Element} trigger
*/
Clipboard.prototype.defaultAction = function defaultAction(trigger) {
return getAttributeValue('action', trigger);
};
/**
* Default `target` lookup function.
* @param {Element} trigger
*/
Clipboard.prototype.defaultTarget = function defaultTarget(trigger) {
var selector = getAttributeValue('target', trigger);
if (selector) {
return document.querySelector(selector);
}
};
/**
* Default `text` lookup function.
* @param {Element} trigger
*/
Clipboard.prototype.defaultText = function defaultText(trigger) {
return getAttributeValue('text', trigger);
};
/**
* Destroy lifecycle.
*/
Clipboard.prototype.destroy = function destroy() {
this.undelegateClick();
if (this.clipboardAction) {
this.clipboardAction.destroy();
this.clipboardAction = null;
}
};
return Clipboard;
})(_tinyEmitter2['default']);
function getAttributeValue(suffix, element) {
var attribute = 'data-clipboard-' + suffix;
if (!element.hasAttribute(attribute)) {
return;
}
return element.getAttribute(attribute);
}
exports['default'] = Clipboard;
module.exports = exports['default'];
},{"./clipboard-action":6,"delegate":3,"tiny-emitter":5}]},{},[7])(7)
});

File diff suppressed because one or more lines are too long

12
assets/vendor/clipboard/package.js vendored Normal file
View File

@ -0,0 +1,12 @@
// Package metadata for Meteor.js.
Package.describe({
name: "zenorocha:clipboard",
summary: "Modern copy to clipboard. No Flash. Just 2kb.",
version: "1.4.2",
git: "https://github.com/zenorocha/clipboard.js"
});
Package.onUse(function(api) {
api.addFiles("dist/clipboard.min.js", "client");
});

53
assets/vendor/clipboard/package.json vendored Normal file
View File

@ -0,0 +1,53 @@
{
"name": "clipboard",
"version": "1.4.3",
"description": "Modern copy to clipboard. No Flash. Just 2kb",
"repository": "zenorocha/clipboard.js",
"license": "MIT",
"main": "dist/clipboard.js",
"browser": "src/clipboard.js",
"browserify": {
"transform": [
[
"babelify",
{
"loose": "all"
}
]
]
},
"keywords": [
"clipboard",
"copy",
"cut"
],
"dependencies": {
"babelify": "^6.3.0",
"browserify": "^11.2.0",
"delegate": "^1.0.0",
"select": "^1.0.0",
"tiny-emitter": "^1.0.0"
},
"devDependencies": {
"karma": "^0.13.10",
"karma-browserify": "^4.4.0",
"karma-chai": "^0.1.0",
"karma-mocha": "^0.2.0",
"karma-phantomjs-launcher": "^0.2.1",
"karma-sinon": "^1.0.4",
"mocha": "^2.3.3",
"phantomjs-polyfill": "0.0.1",
"uglify-js": "^2.4.24",
"watchify": "^3.4.0",
"bannerify": "Vekat/bannerify#feature-option"
},
"scripts": {
"build": "npm run build-debug && npm run build-min",
"build-debug": "browserify src/clipboard.js -s Clipboard -p [bannerify --file .banner ] -o dist/clipboard.js",
"build-min": "uglifyjs dist/clipboard.js --comments '/!/' -m screw_ie8=true -c screw_ie8=true,unused=false -o dist/clipboard.min.js",
"build-watch": "watchify src/clipboard.js -s Clipboard -o dist/clipboard.js -v",
"test": "npm run test-browser && npm run test-server",
"test-browser": "karma start --single-run",
"test-server": "mocha test/module-systems.js"
}
}

183
assets/vendor/clipboard/readme.md vendored Normal file
View File

@ -0,0 +1,183 @@
# clipboard.js
[![Build Status](http://img.shields.io/travis/zenorocha/clipboard.js/master.svg?style=flat)](https://travis-ci.org/zenorocha/clipboard.js)
![Killing Flash](https://img.shields.io/badge/killing-flash-brightgreen.svg?style=flat)
> Modern copy to clipboard. No Flash. Just 2kb
<a href="http://clipboardjs.com/"><img width="728" src="https://cloud.githubusercontent.com/assets/398893/9983535/5ab0a950-5fb4-11e5-9602-e73c0b661883.jpg" alt="Demo"></a>
## Why
Copying text to the clipboard shouldn't be hard. It shouldn't require dozens of steps to configure or hundreds of KBs to load. But most of all, it shouldn't depend on Flash or any bloated framework.
That's why clipboard.js exists.
## Install
You can get it on npm.
```
npm install clipboard --save
```
Or bower, too.
```
bower install clipboard --save
```
If you're not into package management, just [download a ZIP](https://github.com/zenorocha/clipboard.js/archive/master.zip) file.
## Setup
First, include the script located on the `dist` folder.
```html
<script src="dist/clipboard.min.js"></script>
```
Or load it from a CDN.
```html
<script src="https://cdn.rawgit.com/zenorocha/clipboard.js/master/dist/clipboard.min.js"></script>
```
Now, you need to instantiate it using a DOM selector. This selector corresponds to the trigger element(s), for example `<button class="btn">`.
```js
new Clipboard('.btn');
```
Internally, we need to fetch all elements that matches with your selector and attach event listeners for each one. But guess what? If you have hundreds of matches, this operation can consume a lot of memory.
For this reason we use [event delegation](http://stackoverflow.com/questions/1687296/what-is-dom-event-delegation) which replaces multiple event listeners with just a single listener. After all, [#perfmatters](https://twitter.com/hashtag/perfmatters).
# Usage
We're living a _declarative renaissance_, that's why we decided to take advantage of [HTML5 data attributes](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_data_attributes) for better usability.
### Copy text from another element
A pretty common use case is to copy content from another element. You can do that by adding a `data-clipboard-target` attribute in your trigger element.
The value you include on this attribute needs to match another's element selector.
<a href="http://clipboardjs.com/#example-target"><img width="473" alt="example-2" src="https://cloud.githubusercontent.com/assets/398893/9983467/a4946aaa-5fb1-11e5-9780-f09fcd7ca6c8.png"></a>
```html
<!-- Target -->
<input id="foo" value="https://github.com/zenorocha/clipboard.js.git">
<!-- Trigger -->
<button class="btn" data-clipboard-target="#foo">
<img src="assets/clippy.svg" alt="Copy to clipboard">
</button>
```
### Cut text from another element
Additionally, you can define a `data-clipboard-action` attribute to specify if you want to either `copy` or `cut` content.
If you omit this attribute, `copy` will be used by default.
<a href="http://clipboardjs.com/#example-action"><img width="473" alt="example-3" src="https://cloud.githubusercontent.com/assets/398893/10000358/7df57b9c-6050-11e5-9cd1-fbc51d2fd0a7.png"></a>
```html
<!-- Target -->
<textarea id="bar">Mussum ipsum cacilds...</textarea>
<!-- Trigger -->
<button class="btn" data-clipboard-action="cut" data-clipboard-target="#bar">
Cut to clipboard
</button>
```
As you may expect, the `cut` action only works on `<input>` or `<textarea>` elements.
### Copy text from attribute
Truth is, you don't even need another element to copy its content from. You can just include a `data-clipboard-text` attribute in your trigger element.
<a href="http://clipboardjs.com/#example-text"><img width="147" alt="example-1" src="https://cloud.githubusercontent.com/assets/398893/10000347/6e16cf8c-6050-11e5-9883-1c5681f9ec45.png"></a>
```html
<!-- Trigger -->
<button class="btn" data-clipboard-text="Just because you can doesn't mean you should — clipboard.js">
Copy to clipboard
</button>
```
## Events
There are cases where you'd like to show some user feedback or capture what has been selected after a copy/cut operation.
That's why we fire custom events such as `success` and `error` for you to listen and implement your custom logic.
```js
var clipboard = new Clipboard('.btn');
clipboard.on('success', function(e) {
console.info('Action:', e.action);
console.info('Text:', e.text);
console.info('Trigger:', e.trigger);
e.clearSelection();
});
clipboard.on('error', function(e) {
console.error('Action:', e.action);
console.error('Trigger:', e.trigger);
});
```
For a live demonstration, open this [site](http://clipboardjs.com/) and just your console :)
## Advanced Options
If you don't want to modify your HTML, there's a pretty handy imperative API for you to use. All you need to do is declare a function, do your thing, and return a value.
For instance, if you want to dynamically set a `target`, you'll need to return a Node.
```js
new Clipboard('.btn', {
target: function(trigger) {
return trigger.nextElementSibling;
}
});
```
If you want to dynamically set a `text`, you'll return a String.
```js
new Clipboard('.btn', {
text: function(trigger) {
return trigger.getAttribute('aria-label');
}
});
```
Also, with are working with single page apps, you may want to manage the lifecycle of the DOM more precisely. Here's how you clean up the events and objects that we create.
```js
var clipboard = new Clipboard('.btn');
clipboard.destroy();
```
## Browser Support
This library relies on both [Selection](https://developer.mozilla.org/en-US/docs/Web/API/Selection) and [execCommand](https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand) APIs. The second one is supported in the following browsers.
| <img src="http://clipboardjs.com/assets/images/chrome.png" width="48px" height="48px" alt="Chrome logo"> | <img src="http://clipboardjs.com/assets/images/firefox.png" width="48px" height="48px" alt="Firefox logo"> | <img src="http://clipboardjs.com/assets/images/ie.png" width="48px" height="48px" alt="Internet Explorer logo"> | <img src="http://clipboardjs.com/assets/images/opera.png" width="48px" height="48px" alt="Opera logo"> | <img src="http://clipboardjs.com/assets/images/safari.png" width="48px" height="48px" alt="Safari logo"> |
|:---:|:---:|:---:|:---:|:---:|
| 42+ ✔ | 41+ ✔ | 9+ ✔ | 29+ ✔ | Nope ✘ |
Although copy/cut operations with [execCommand](https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand) aren't supported on Safari yet (including mobile), it gracefully degrades because [Selection](https://developer.mozilla.org/en-US/docs/Web/API/Selection) is supported.
That means you can show a tooltip saying `Copied!` when `success` event is called and `Press Ctrl+C to copy` when `error` event is called because the text is already selected.
For a live demonstration, open this [site](http://clipboardjs.com) on Safari.
## License
[MIT License](http://zenorocha.mit-license.org/) © Zeno Rocha

View File

@ -1,46 +0,0 @@
{
"name": "zeroclipboard",
"description": "The ZeroClipboard library provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie and a JavaScript interface.",
"version": "1.3.2",
"main": [
"./ZeroClipboard.js",
"./ZeroClipboard.swf"
],
"keywords": [
"flash",
"clipboard",
"copy",
"cut",
"paste",
"zclip",
"clip",
"clippy"
],
"license": "https://github.com/zeroclipboard/zeroclipboard/blob/master/LICENSE",
"authors": [
{
"name": "Jon Rohan",
"url": "http://jonrohan.me/"
},
{
"name": "James M. Greene",
"email": "james.m.greene@gmail.com",
"url": "http://jamesgreene.net/"
}
],
"homepage": "http://zeroclipboard.org/",
"repository": {
"type": "git",
"url": "https://github.com/zeroclipboard/zeroclipboard.git"
},
"location": "git://github.com/zeroclipboard/zeroclipboard.git",
"_release": "1.3.2",
"_resolution": {
"type": "version",
"tag": "v1.3.2",
"commit": "028ce9abf2f2960fd79e0fae13b3446924be0e8c"
},
"_source": "git://github.com/zeroclipboard/zeroclipboard.git",
"_target": "~1.3.2",
"_originalSource": "zeroclipboard"
}

View File

@ -1,3 +0,0 @@
node_modules
npm-debug.log
bin/*

View File

@ -1,13 +0,0 @@
{
"boss": true,
"browser": true,
"camelcase": true,
"eqeqeq": true,
"eqnull": true,
"es3": true,
"es5": false,
"indent": 2,
"multistr": true,
"strict": false,
"trailing": true
}

View File

@ -1,3 +0,0 @@
docs/
test/
.DS_Store

View File

@ -1,5 +0,0 @@
language: node_js
node_js:
- "0.10"
before_script:
- npm install -g grunt-cli

View File

@ -1,25 +0,0 @@
Contributing
==============
If you find an issue, submitting a pull request is always better than a bug report! Please fork and submit your code fixes.
If you want to build some new features, we have a [roadmap.md](docs/roadmap.md) of features we want. You can add features you want there, or just code the feature and send a pull request.
### Cloning
$ git clone https://github.com/zeroclipboard/zeroclipboard.git
$ cd zeroclipboard/
$ npm install -g grunt-cli
$ npm install
$ grunt
### Developing
$ npm install
$ grunt
### Testing
$ grunt test

View File

@ -1,176 +0,0 @@
/*jshint -W106 */
/*jshint node:true */
module.exports = function(grunt) {
'use strict';
// Metadata
var pkg = grunt.file.readJSON('package.json');
// Shared configuration
var localPort = 7320; // "ZERO"
// Project configuration.
grunt.initConfig({
// Task configuration
jshint: {
options: {
jshintrc: '.jshintrc'
},
Gruntfile: ['Gruntfile.js'],
js: ['src/javascript/ZeroClipboard/**/*.js'],
test: {
options: {
jshintrc: 'test/.jshintrc'
},
src: ['test/*.js']
}
},
clean: {
src: ['ZeroClipboard.*'],
meta: ['bower.json', 'composer.json', 'LICENSE']
},
concat: {
options: {
stripBanners: true,
process: {
data: pkg
}
},
js: {
src: [
'src/meta/source-banner.tmpl',
'src/javascript/start.js',
'src/javascript/ZeroClipboard/state.js',
'src/javascript/ZeroClipboard/utils.js',
'src/javascript/ZeroClipboard/flash.js',
'src/javascript/ZeroClipboard/client.js',
'src/javascript/ZeroClipboard/core.js',
'src/javascript/ZeroClipboard/dom.js',
'src/javascript/ZeroClipboard/event.js',
'src/javascript/ZeroClipboard/deprecated.js',
'src/javascript/end.js'
],
dest: 'ZeroClipboard.js'
}
},
uglify: {
options: {
preserveComments: 'some',
report: 'min'
},
js: {
options: {
beautify: {
beautify: true,
// `indent_level` requires jshint -W106
indent_level: 2
},
mangle: false,
compress: false
},
src: ['ZeroClipboard.js'],
dest: 'ZeroClipboard.js'
},
minjs: {
src: ['ZeroClipboard.js'],
dest: 'ZeroClipboard.min.js'
}
},
mxmlc: {
options: {
rawConfig: '-static-link-runtime-shared-libraries=true'
},
swf: {
files: {
'ZeroClipboard.swf': ['src/flash/ZeroClipboard.as']
}
}
},
template: {
options: {
data: pkg
},
bower: {
files: {
'bower.json': ['src/meta/bower.json.tmpl']
}
},
composer: {
files: {
'composer.json': ['src/meta/composer.json.tmpl']
}
},
LICENSE: {
files: {
'LICENSE': ['src/meta/LICENSE.tmpl']
}
}
},
chmod: {
options: {
mode: '444'
},
src: ['ZeroClipboard.*'],
meta: ['bower.json', 'composer.json', 'LICENSE']
},
connect: {
server: {
options: {
port: localPort
}
}
},
qunit: {
file: ['test/**/*.js.html'],
http: {
options: {
urls: grunt.file.expand(['test/**/*.js.html']).map(function(testPage) {
return 'http://localhost:' + localPort + '/' + testPage + '?noglobals=true';
})
}
}
},
watch: {
options: {
spawn: false
},
Gruntfile: {
files: '<%= jshint.Gruntfile %>',
tasks: ['jshint:Gruntfile']
},
js: {
files: '<%= jshint.js %>',
tasks: ['jshint:js', 'unittest']
},
test: {
files: '<%= jshint.test %>',
tasks: ['jshint:test', 'unittest']
}
}
});
// These plugins provide necessary tasks
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-mxmlc');
grunt.loadNpmTasks('grunt-template');
grunt.loadNpmTasks('grunt-chmod');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-watch');
//
// Task aliases and chains
//
grunt.registerTask('unittest', ['connect', 'qunit']);
grunt.registerTask('test', ['jshint', 'clean:src', 'concat', 'mxmlc', 'chmod:src', 'unittest']);
grunt.registerTask('travis', ['test']);
// Default task
grunt.registerTask('default', ['jshint', 'clean', 'concat', 'uglify', 'mxmlc', 'template', 'chmod', 'unittest']);
};

View File

@ -1,8 +0,0 @@
The MIT License (MIT)
Copyright (c) 2014 Jon Rohan, James M. Greene
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -1,71 +0,0 @@
# ZeroClipboard
The ZeroClipboard library provides an easy way to copy text to the clipboard using an invisible [Adobe Flash](http://en.wikipedia.org/wiki/Adobe_Flash) movie and a [JavaScript](http://en.wikipedia.org/wiki/JavaScript) interface. The "Zero" signifies that the library is invisible and the user interface is left entirely up to you.
## Simple Example
``` html
<html>
<body>
<button id="copy-button" data-clipboard-text="Copy Me!" title="Click to copy me.">Copy to Clipboard</button>
<script src="ZeroClipboard.js"></script>
<script src="main.js"></script>
</body>
</html>
```
``` js
// main.js
var client = new ZeroClipboard( document.getElementById("copy-button"), {
moviePath: "/path/to/ZeroClipboard.swf"
} );
client.on( "load", function(client) {
// alert( "movie is loaded" );
client.on( "complete", function(client, args) {
// `this` is the element that was clicked
this.style.display = "none";
alert("Copied text to clipboard: " + args.text );
} );
} );
```
See the [instructions](docs/instructions.md) for more advanced options in using the library on your site.
Here is a working [test page](http://zeroclipboard.org/#demo) where you can try out ZeroClipboard in your browser.
## Testing ZeroClipboard Locally
To test the page [demo page](http://zeroclipboard.org/#demo) locally, clone the [website repo](https://github.com/zeroclipboard/zeroclipboard.org).
## Support
This library is fully compatible with Flash Player 10, which requires that the clipboard copy operation be initiated by a user click event inside the Flash movie. This is achieved by automatically floating the invisible movie on top of a [DOM](http://en.wikipedia.org/wiki/Document_Object_Model) element of your choice. Standard mouse events are even propagated out to your DOM element, so you can still have rollover and mouse down effects.
Works in IE7+ and all of the evergreen browsers.
## Contributing
see [CONTRIBUTING.md](CONTRIBUTING.md)
## Releases
Starting with version [1.1.7](https://github.com/zeroclipboard/zeroclipboard/releases/tag/v1.1.7), ZeroClipboard uses [semantic versioning](http://semver.org/).
see [releases](https://github.com/zeroclipboard/zeroclipboard/releases)
## Roadmap
see [roadmap.md](docs/roadmap.md)
## Last Build
[![Build Status](https://secure.travis-ci.org/zeroclipboard/zeroclipboard.png?branch=master)](https://travis-ci.org/zeroclipboard/zeroclipboard)

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -1,12 +0,0 @@
{
"name": "zeroclipboard",
"description": "The ZeroClipboard library provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie and a JavaScript interface.",
"version": "1.3.2",
"main": ["./ZeroClipboard.js", "./ZeroClipboard.swf"],
"keywords": ["flash","clipboard","copy","cut","paste","zclip","clip","clippy"],
"license": "https://github.com/zeroclipboard/zeroclipboard/blob/master/LICENSE",
"authors": [{"name":"Jon Rohan","url":"http://jonrohan.me/"},{"name":"James M. Greene","email":"james.m.greene@gmail.com","url":"http://jamesgreene.net/"}],
"homepage": "http://zeroclipboard.org/",
"repository": {"type":"git","url":"https://github.com/zeroclipboard/zeroclipboard.git"},
"location": "git://github.com/zeroclipboard/zeroclipboard.git"
}

View File

@ -1,14 +0,0 @@
{
"name": "zeroclipboard/zeroclipboard",
"description": "The ZeroClipboard library provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie and a JavaScript interface.",
"version": "1.3.2",
"type": "library",
"keywords": ["flash","clipboard","copy","cut","paste","zclip","clip","clippy"],
"license": "MIT",
"authors": [{"name":"Jon Rohan","homepage":"http://jonrohan.me/","role":"Developer"},{"name":"James M. Greene","email":"james.m.greene@gmail.com","homepage":"http://jamesgreene.net/","role":"Developer"}],
"homepage": "http://zeroclipboard.org/",
"support": {
"source": "https://github.com/zeroclipboard/zeroclipboard.git",
"issues": "https://github.com/zeroclipboard/zeroclipboard/issues"
}
}

View File

@ -1,31 +0,0 @@
/**
* Module exports.
*/
exports = module.exports = setup;
/**
* Module dependencies.
*/
var http = require('http');
var send = require('send');
var root = __dirname;
var swf = '/ZeroClipboard.swf';
function setup () {
return http.createServer(onReq);
}
function onReq (req, res) {
send(req, swf)
.root(root)
.on('error', onError)
.pipe(res);
}
function onError (err) {
res.statusCode = err.status || 500;
res.end(err.message);
}

View File

@ -1,68 +0,0 @@
{
"name": "zeroclipboard",
"title": "ZeroClipboard",
"version": "1.3.2",
"description": "The ZeroClipboard library provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie and a JavaScript interface.",
"keywords": [
"flash",
"clipboard",
"copy",
"cut",
"paste",
"zclip",
"clip",
"clippy"
],
"homepage": "http://zeroclipboard.org/",
"licenses": [
{
"type": "MIT",
"url": "https://github.com/zeroclipboard/zeroclipboard/blob/master/LICENSE"
}
],
"contributors": [
{
"name": "Jon Rohan",
"url": "http://jonrohan.me/"
},
{
"name": "James M. Greene",
"email": "james.m.greene@gmail.com",
"url": "http://jamesgreene.net/"
}
],
"repository": {
"type": "git",
"url": "https://github.com/zeroclipboard/zeroclipboard.git"
},
"bugs": {
"url": "https://github.com/zeroclipboard/zeroclipboard/issues"
},
"dependencies": {
"send": "0"
},
"devDependencies": {
"qunitjs": "~1.12.0",
"qunit-composite": "~1.0.1",
"grunt": "~0.4.2",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-jshint": "~0.7.2",
"grunt-contrib-connect": "~0.5.0",
"grunt-contrib-qunit": "~0.3.0",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-uglify": "~0.2.7",
"grunt-chmod": "~1.0.3",
"grunt-mxmlc": "~0.2.0",
"grunt-template": "~0.2.1",
"grunt-contrib-watch": "~0.5.3"
},
"main": "./ZeroClipboard.js",
"component": {
"scripts": {
"zeroclipboard": "ZeroClipboard.js"
}
},
"scripts": {
"test": "grunt travis --verbose"
}
}

View File

@ -9,11 +9,11 @@
"main": "index.html", "main": "index.html",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"zeroclipboard": "~1.3.2",
"jquery": "~1.11.0", "jquery": "~1.11.0",
"html5shiv": "~3.7.0", "html5shiv": "~3.7.0",
"selectivizr": "~1.0.2", "selectivizr": "~1.0.2",
"qtip2": "~2.2.0", "qtip2": "~2.2.0",
"normalize-css": "~3.0.0" "normalize-css": "~3.0.0",
"clipboard": "~1.4.3"
} }
} }