Commit 93ff4f52 authored by Nicolas Widart's avatar Nicolas Widart

Updating media module & publishing its assets & config files

parent 366d693b
<?php
return [
/*
|--------------------------------------------------------------------------
| Define which assets will be available through the asset manager
|--------------------------------------------------------------------------
| These assets are registered on the asset manager
*/
'media-partial-assets' => [
'jquery-ui.js' => ['module' => 'dashboard:vendor/jquery-ui/jquery-ui.min.js'],
'media-partial.js' => ['module' => 'media:js/media-partial.js'],
],
/*
|--------------------------------------------------------------------------
| Define which default assets will always be included in your pages
| through the asset pipeline
|--------------------------------------------------------------------------
*/
'media-partial-required-assets' => [
'js' => [
'jquery-ui.js',
'media-partial.js',
],
],
];
$( document ).ready(function() {
var $fileCount = $('.jsFileCount');
var sortableWrapper = $(".jsThumbnailImageWrapper");
var sortableSelection = sortableWrapper.not(".jsSingleThumbnailWrapper");
// This comes from new-file-link-single
if (typeof window.openMediaWindowSingle === 'undefined') {
window.mediaZone = '';
window.openMediaWindowSingle = function (event, zone) {
window.single = true;
window.old = false;
window.mediaZone = zone;
window.zoneWrapper = $(event.currentTarget).siblings('.jsThumbnailImageWrapper');
window.open(Asgard.mediaGridSelectUrl, '_blank', 'menubar=no,status=no,toolbar=no,scrollbars=yes,height=500,width=1000');
};
}
if (typeof window.includeMediaSingle === 'undefined') {
window.includeMediaSingle = function (mediaId, filePath, mediaType, mimetype) {
var mediaPlaceholder;
if (mediaType === 'image') {
mediaPlaceholder = '<img src="' + filePath + '" alt=""/>';
} else if (mediaType == 'video') {
mediaPlaceholder = '<video src="' + filePath + '" controls width="320"></video>';
} else if (mediaType == 'audio') {
mediaPlaceholder = '<audio controls><source src="' + filePath + '" type="' + mimetype + '"></audio>'
} else {
mediaPlaceholder = '<i class="fa fa-file" style="font-size: 50px;"></i>';
}
var html = '<figure data-id="'+ mediaId +'">' + mediaPlaceholder +
'<a class="jsRemoveSimpleLink" href="#" data-id="' + mediaId + '">' +
'<i class="fa fa-times-circle removeIcon"></i></a>' +
'<input type="hidden" name="medias_single['+ window.mediaZone +']" value="' + mediaId + '">' +
'</figure>';
window.zoneWrapper.append(html).fadeIn('slow', function() {
toggleButton($(this));
});
};
}
// This comes from new-file-link-multiple
if (typeof window.openMediaWindowMultiple === 'undefined') {
window.mediaZone = '';
window.openMediaWindowMultiple = function (event, zone) {
window.single = false;
window.old = false;
window.mediaZone = zone;
window.zoneWrapper = $(event.currentTarget).siblings('.jsThumbnailImageWrapper');
window.open(Asgard.mediaGridSelectUrl, '_blank', 'menubar=no,status=no,toolbar=no,scrollbars=yes,height=500,width=1000');
};
}
if (typeof window.includeMediaMultiple === 'undefined') {
window.includeMediaMultiple = function (mediaId, filePath, mediaType, mimetype) {
var mediaPlaceholder;
if (mediaType === 'image') {
mediaPlaceholder = '<img src="' + filePath + '" alt=""/>';
} else if (mediaType == 'video') {
mediaPlaceholder = '<video src="' + filePath + '" controls width="320"></video>';
} else if (mediaType == 'audio') {
mediaPlaceholder = '<audio controls><source src="' + filePath + '" type="' + mimetype + '"></audio>'
} else {
mediaPlaceholder = '<i class="fa fa-file" style="font-size: 50px;"></i>';
}
var html = '<figure data-id="' + mediaId + '">' + mediaPlaceholder +
'<a class="jsRemoveLink" href="#" data-id="' + mediaId + '">' +
'<i class="fa fa-times-circle removeIcon"></i>' +
'</a>' +
'<input type="hidden" name="medias_multi[' + window.mediaZone + '][files][]" value="' + mediaId + '">' +
'</figure>';
window.zoneWrapper.append(html).fadeIn();
window.zoneWrapper.trigger('sortupdate');
if ($fileCount.length > 0) {
var count = parseInt($fileCount.text());
$fileCount.text(count + 1);
}
};
}
// This comes from new-file-link-multiple
sortableWrapper.on('click', '.jsRemoveLink', function (e) {
e.preventDefault();
var pictureWrapper = $(this).parent();
var pictureSortable = pictureWrapper.parent();
pictureWrapper.fadeOut().remove();
pictureSortable.trigger('sortupdate');
if ($fileCount.length > 0) {
var count = parseInt($fileCount.text());
$fileCount.text(count - 1);
}
});
// This comes from new-file-link-multiple
sortableSelection.sortable({
items: "figure",
placeholder: 'ui-state-highlight',
cursor:'move',
helper: 'clone',
containment: 'parent',
forcePlaceholderSize: false,
forceHelperSize: true
});
sortableSelection.on('sortupdate', function(e, ui) {
var dataSortable = $(this).sortable('toArray', {attribute: 'data-id'});
$(this).find($('.orders')).val(dataSortable);
});
// This comes from new-file-link-single
sortableWrapper.off('click', '.jsRemoveSimpleLink');
sortableWrapper.on('click', '.jsRemoveSimpleLink', function (e) {
e.preventDefault();
$(e.delegateTarget).fadeOut('slow', function() {
toggleButton($(this));
}).html('');
});
function toggleButton(el) {
var browseButton = el.parent().find('.btn-browse');
browseButton.toggle();
}
});
\ No newline at end of file
ul.notifications-list li {
-webkit-animation-duration: .5s;
animation-duration: .5s;
}
.notificationsCounter {
-webkit-animation-duration: .5s;
animation-duration: .5s;
}
.notificationIcon {
......@@ -22,6 +20,39 @@ ul.notifications-list li {
right: 0px;
top: auto;
}
.btn-upload {
margin-bottom: 12px;
}
.jsThumbnailImageWrapper {
padding-top: 8px;
overflow-y: auto;
}
.jsThumbnailImageWrapper figure {
position: relative;
display: inline-block;
margin-right: 20px;
margin-bottom: 20px;
background-color: #fff;
border: 1px solid #eee;
padding: 3px;
border-radius: 3px;
vertical-align: bottom;
}
.jsThumbnailImageWrapper i.removeIcon {
position: absolute;
top: -10px;
right: -10px;
color: #f56954;
font-size: 2em;
background: white;
border-radius: 20px;
height: 25px;
}
figure.ui-state-highlight {
border: none;
width: 100px;
height: 0;
}
footer.main-footer a {
cursor: pointer;
}
......
{"version":3,"sources":["Asgard/notifications.less","asgard.css","footer.less","skins/blue.less","asgard.less"],"names":[],"mappings":"AAAA;EACE,gCAAA;EAAA,wBAAA;CCCD;ADCD;EACE,gCAAA;EAAA,wBAAA;CCCD;ADCD;EACE,gBAAA;CCCD;ADED;EACE,aAAA;EACA,2BAAA;EACA,mBAAA;EACA,WAAA;EACA,WAAA;CCAD;ADGD;EACE,mBAAA;EACA,cAAA;EACA,WAAA;EACA,UAAA;CCDD;ACrBD;EAEI,gBAAA;CDsBH;ACxBD;EAKI,iBAAA;CDsBH;AEzBD;;;EACE,oBAAA;CF6BD;AEzBD;EACE,eAAA;EACA,oBAAA;EACA,6BAAA;EACA,gBAAA;CF2BD;AG9BD;EACE,kBAAA;CHgCD;AG9BD;EACE,kBAAA;CHgCD;AG9BD;;EAEE,YAAA;EACA,iBAAA;EACA,UAAA;CHgCD;AG7BD;;EAEE,cAAA;CH+BD;AG3BD;EACE,gBAAA;CH6BD;AG3BD;EACE,kBAAA;EACA,iBAAA;CH6BD","file":"asgard.css","sourcesContent":["ul.notifications-list li {\n animation-duration: .5s;\n}\n.notificationsCounter {\n animation-duration: .5s;\n}\n.notificationIcon {\n font-size: 30px;\n}\n\n.removeNotification {\n z-index:999;\n font-size: 12px !important;\n position: absolute;\n top: -35px;\n right: 0px;\n}\n\n.navbar-nav > .messages-menu > .dropdown-menu > li .menu > li > a > h4 > small {\n position: absolute;\n bottom: -30px;\n right: 0px;\n top: auto;\n}\n","ul.notifications-list li {\n animation-duration: .5s;\n}\n.notificationsCounter {\n animation-duration: .5s;\n}\n.notificationIcon {\n font-size: 30px;\n}\n.removeNotification {\n z-index: 999;\n font-size: 12px !important;\n position: absolute;\n top: -35px;\n right: 0px;\n}\n.navbar-nav > .messages-menu > .dropdown-menu > li .menu > li > a > h4 > small {\n position: absolute;\n bottom: -30px;\n right: 0px;\n top: auto;\n}\nfooter.main-footer a {\n cursor: pointer;\n}\nfooter.main-footer p.text-muted {\n margin-bottom: 0;\n}\n.skin-blue .wrapper,\n.skin-blue .main-sidebar,\n.skin-blue .left-side {\n background: #202227;\n}\n.skin-blue .sidebar-menu > li.menu-title {\n color: #93AFBB;\n background: #25272d;\n padding: 10px 25px 10px 15px;\n font-size: 12px;\n}\n.sidebar-menu .append {\n margin-top: -44px;\n}\n.sidebar-menu .treeview-menu .append {\n margin-top: -30px;\n}\n.skin-blue .sidebar-menu .append:hover,\n.skin-blue .sidebar-menu > li.active > a.append {\n color: #fff;\n background: none;\n border: 0;\n}\n.sidebar-mini.sidebar-collapse .sidebar-menu a.append,\n.sidebar-mini.sidebar-collapse .sidebar-menu li.menu-title {\n display: none;\n}\n.checkbox label {\n padding-left: 0;\n}\n.checkbox label div {\n margin-right: 5px;\n margin-top: -2px;\n}\n","footer.main-footer {\n a {\n cursor: pointer;\n }\n p.text-muted {\n margin-bottom: 0;\n }\n}\n","@import \"blue/vars\";\n\n.skin-blue .wrapper, .skin-blue .main-sidebar, .skin-blue .left-side {\n background: #202227;\n}\n\n\n.skin-blue .sidebar-menu > li.menu-title {\n color: #93AFBB;\n background: lighten(@sidebar-light-bg, 2%);\n padding: 10px 25px 10px 15px;\n font-size: 12px;\n}\n","@import \"Asgard/vars\";\n@import \"Asgard/notifications\";\n@import \"mixins\";\n@import \"footer\";\n\n@import \"skins/blue.less\";\n\n// For the appended elements\n.sidebar-menu .append {\n margin-top: -44px;\n}\n.sidebar-menu .treeview-menu .append {\n margin-top: -30px;\n}\n.skin-blue .sidebar-menu .append:hover,\n.skin-blue .sidebar-menu > li.active > a.append {\n color: #fff;\n background: none;\n border: 0;\n}\n\n.sidebar-mini.sidebar-collapse .sidebar-menu a.append,\n.sidebar-mini.sidebar-collapse .sidebar-menu li.menu-title {\n display: none;\n}\n\n// Correctly aligning the checkbox labels\n.checkbox label {\n padding-left: 0;\n}\n.checkbox label div {\n margin-right: 5px;\n margin-top: -2px;\n}\n"],"sourceRoot":"/source/"}
\ No newline at end of file
{"version":3,"sources":["Asgard/notifications.less","asgard.css","Asgard/mediaModule.less","footer.less","skins/blue.less","asgard.less"],"names":[],"mappings":"AAAA;EACE,wBAAA;CCCD;ADCD;EACE,wBAAA;CCCD;ADCD;EACE,gBAAA;CCCD;ADED;EACE,aAAA;EACA,2BAAA;EACA,mBAAA;EACA,WAAA;EACA,WAAA;CCAD;ADGD;EACE,mBAAA;EACA,cAAA;EACA,WAAA;EACA,UAAA;CCDD;ACrBD;EACC,oBAAA;CDuBA;ACrBD;EACC,iBAAA;EACA,iBAAA;CDuBA;ACrBD;EACC,mBAAA;EACA,sBAAA;EACA,mBAAA;EACA,oBAAA;EACA,uBAAA;EACA,uBAAA;EACA,aAAA;EACA,mBAAA;EACA,uBAAA;CDuBA;ACrBD;EACC,mBAAA;EACA,WAAA;EACA,aAAA;EACA,eAAA;EACA,eAAA;EACA,kBAAA;EACA,oBAAA;EACA,aAAA;CDuBA;ACpBD;EACC,aAAA;EACA,aAAA;EACA,UAAA;CDsBA;AEtDD;EAEI,gBAAA;CFuDH;AEzDD;EAKI,iBAAA;CFuDH;AG1DD;;;EACE,oBAAA;CH8DD;AG1DD;EACE,eAAA;EACA,oBAAA;EACA,6BAAA;EACA,gBAAA;CH4DD;AI9DD;EACE,kBAAA;CJgED;AI9DD;EACE,kBAAA;CJgED;AI9DD;;EAEE,YAAA;EACA,iBAAA;EACA,UAAA;CJgED;AI7DD;;EAEE,cAAA;CJ+DD;AI3DD;EACE,gBAAA;CJ6DD;AI3DD;EACE,kBAAA;EACA,iBAAA;CJ6DD","file":"asgard.css","sourcesContent":["ul.notifications-list li {\n animation-duration: .5s;\n}\n.notificationsCounter {\n animation-duration: .5s;\n}\n.notificationIcon {\n font-size: 30px;\n}\n\n.removeNotification {\n z-index:999;\n font-size: 12px !important;\n position: absolute;\n top: -35px;\n right: 0px;\n}\n\n.navbar-nav > .messages-menu > .dropdown-menu > li .menu > li > a > h4 > small {\n position: absolute;\n bottom: -30px;\n right: 0px;\n top: auto;\n}\n","ul.notifications-list li {\n animation-duration: .5s;\n}\n.notificationsCounter {\n animation-duration: .5s;\n}\n.notificationIcon {\n font-size: 30px;\n}\n.removeNotification {\n z-index: 999;\n font-size: 12px !important;\n position: absolute;\n top: -35px;\n right: 0px;\n}\n.navbar-nav > .messages-menu > .dropdown-menu > li .menu > li > a > h4 > small {\n position: absolute;\n bottom: -30px;\n right: 0px;\n top: auto;\n}\n.btn-upload {\n margin-bottom: 12px;\n}\n.jsThumbnailImageWrapper {\n padding-top: 8px;\n overflow-y: auto;\n}\n.jsThumbnailImageWrapper figure {\n position: relative;\n display: inline-block;\n margin-right: 20px;\n margin-bottom: 20px;\n background-color: #fff;\n border: 1px solid #eee;\n padding: 3px;\n border-radius: 3px;\n vertical-align: bottom;\n}\n.jsThumbnailImageWrapper i.removeIcon {\n position: absolute;\n top: -10px;\n right: -10px;\n color: #f56954;\n font-size: 2em;\n background: white;\n border-radius: 20px;\n height: 25px;\n}\nfigure.ui-state-highlight {\n border: none;\n width: 100px;\n height: 0;\n}\nfooter.main-footer a {\n cursor: pointer;\n}\nfooter.main-footer p.text-muted {\n margin-bottom: 0;\n}\n.skin-blue .wrapper,\n.skin-blue .main-sidebar,\n.skin-blue .left-side {\n background: #202227;\n}\n.skin-blue .sidebar-menu > li.menu-title {\n color: #93AFBB;\n background: #25272d;\n padding: 10px 25px 10px 15px;\n font-size: 12px;\n}\n.sidebar-menu .append {\n margin-top: -44px;\n}\n.sidebar-menu .treeview-menu .append {\n margin-top: -30px;\n}\n.skin-blue .sidebar-menu .append:hover,\n.skin-blue .sidebar-menu > li.active > a.append {\n color: #fff;\n background: none;\n border: 0;\n}\n.sidebar-mini.sidebar-collapse .sidebar-menu a.append,\n.sidebar-mini.sidebar-collapse .sidebar-menu li.menu-title {\n display: none;\n}\n.checkbox label {\n padding-left: 0;\n}\n.checkbox label div {\n margin-right: 5px;\n margin-top: -2px;\n}\n",".btn-upload {\n\tmargin-bottom: 12px;\n}\n.jsThumbnailImageWrapper {\n\tpadding-top: 8px;\n\toverflow-y: auto;\n}\n.jsThumbnailImageWrapper figure {\n\tposition: relative;\n\tdisplay: inline-block;\n\tmargin-right: 20px;\n\tmargin-bottom: 20px;\n\tbackground-color: #fff;\n\tborder: 1px solid #eee;\n\tpadding: 3px;\n\tborder-radius: 3px;\n\tvertical-align: bottom;\n}\n.jsThumbnailImageWrapper i.removeIcon {\n\tposition: absolute;\n\ttop:-10px;\n\tright:-10px;\n\tcolor: #f56954;\n\tfont-size: 2em;\n\tbackground: white;\n\tborder-radius: 20px;\n\theight: 25px;\n}\n\nfigure.ui-state-highlight {\n\tborder: none;\n\twidth:100px;\n\theight: 0;\n}\n","footer.main-footer {\n a {\n cursor: pointer;\n }\n p.text-muted {\n margin-bottom: 0;\n }\n}\n","@import \"blue/vars\";\n\n.skin-blue .wrapper, .skin-blue .main-sidebar, .skin-blue .left-side {\n background: #202227;\n}\n\n\n.skin-blue .sidebar-menu > li.menu-title {\n color: #93AFBB;\n background: lighten(@sidebar-light-bg, 2%);\n padding: 10px 25px 10px 15px;\n font-size: 12px;\n}\n","@import \"Asgard/vars\";\n@import \"Asgard/notifications\";\n@import \"Asgard/mediaModule\";\n@import \"mixins\";\n@import \"footer\";\n\n@import \"skins/blue.less\";\n\n// For the appended elements\n.sidebar-menu .append {\n margin-top: -44px;\n}\n.sidebar-menu .treeview-menu .append {\n margin-top: -30px;\n}\n.skin-blue .sidebar-menu .append:hover,\n.skin-blue .sidebar-menu > li.active > a.append {\n color: #fff;\n background: none;\n border: 0;\n}\n\n.sidebar-mini.sidebar-collapse .sidebar-menu a.append,\n.sidebar-mini.sidebar-collapse .sidebar-menu li.menu-title {\n display: none;\n}\n\n// Correctly aligning the checkbox labels\n.checkbox label {\n padding-left: 0;\n}\n.checkbox label div {\n margin-right: 5px;\n margin-top: -2px;\n}\n"],"sourceRoot":"/source/"}
\ No newline at end of file
{
"name": "clipboard",
"version": "1.5.12",
"description": "Modern copy to clipboard. No Flash. Just 2kb",
"license": "MIT",
"main": "dist/clipboard.js",
"ignore": [
"/.*/",
"/demo/",
"/test/",
"/.*",
"/bower.json",
"/karma.conf.js",
"/src",
"/lib"
],
"keywords": [
"clipboard",
"copy",
"cut"
],
"homepage": "https://github.com/zenorocha/clipboard.js",
"_release": "1.5.12",
"_resolution": {
"type": "version",
"tag": "v1.5.12",
"commit": "eb7418b51bb3c963893d83954c5cfa4de3f7f527"
},
"_source": "https://github.com/zenorocha/clipboard.js.git",
"_target": "^1.5.12",
"_originalSource": "clipboard",
"_direct": true
}
\ No newline at end of file
{
"name": "clipboard",
"version": "1.5.12",
"description": "Modern copy to clipboard. No Flash. Just 2kb",
"license": "MIT",
"main": "dist/clipboard.js",
"ignore": [
"/.*/",
"/demo/",
"/test/",
"/.*",
"/bower.json",
"/karma.conf.js",
"/src",
"/lib"
],
"keywords": [
"clipboard",
"copy",
"cut"
]
}
# 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
This diff is collapsed.
/*!
* clipboard.js v1.5.12
* https://zenorocha.github.io/clipboard.js
*
* Licensed MIT © Zeno Rocha
*/
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.Clipboard=t()}}(function(){var t,e,n;return function t(e,n,o){function i(a,c){if(!n[a]){if(!e[a]){var s="function"==typeof require&&require;if(!c&&s)return s(a,!0);if(r)return r(a,!0);var l=new Error("Cannot find module '"+a+"'");throw l.code="MODULE_NOT_FOUND",l}var u=n[a]={exports:{}};e[a][0].call(u.exports,function(t){var n=e[a][1][t];return i(n?n:t)},u,u.exports,t,e,n,o)}return n[a].exports}for(var r="function"==typeof require&&require,a=0;a<o.length;a++)i(o[a]);return i}({1:[function(t,e,n){var o=t("matches-selector");e.exports=function(t,e,n){for(var i=n?t:t.parentNode;i&&i!==document;){if(o(i,e))return i;i=i.parentNode}}},{"matches-selector":5}],2:[function(t,e,n){function o(t,e,n,o,r){var a=i.apply(this,arguments);return t.addEventListener(n,a,r),{destroy:function(){t.removeEventListener(n,a,r)}}}function i(t,e,n,o){return function(n){n.delegateTarget=r(n.target,e,!0),n.delegateTarget&&o.call(t,n)}}var r=t("closest");e.exports=o},{closest:1}],3:[function(t,e,n){n.node=function(t){return void 0!==t&&t instanceof HTMLElement&&1===t.nodeType},n.nodeList=function(t){var e=Object.prototype.toString.call(t);return void 0!==t&&("[object NodeList]"===e||"[object HTMLCollection]"===e)&&"length"in t&&(0===t.length||n.node(t[0]))},n.string=function(t){return"string"==typeof t||t instanceof String},n.fn=function(t){var e=Object.prototype.toString.call(t);return"[object Function]"===e}},{}],4:[function(t,e,n){function o(t,e,n){if(!t&&!e&&!n)throw new Error("Missing required arguments");if(!c.string(e))throw new TypeError("Second argument must be a String");if(!c.fn(n))throw new TypeError("Third argument must be a Function");if(c.node(t))return i(t,e,n);if(c.nodeList(t))return r(t,e,n);if(c.string(t))return a(t,e,n);throw new TypeError("First argument must be a String, HTMLElement, HTMLCollection, or NodeList")}function i(t,e,n){return t.addEventListener(e,n),{destroy:function(){t.removeEventListener(e,n)}}}function r(t,e,n){return Array.prototype.forEach.call(t,function(t){t.addEventListener(e,n)}),{destroy:function(){Array.prototype.forEach.call(t,function(t){t.removeEventListener(e,n)})}}}function a(t,e,n){return s(document.body,t,e,n)}var c=t("./is"),s=t("delegate");e.exports=o},{"./is":3,delegate:2}],5:[function(t,e,n){function o(t,e){if(r)return r.call(t,e);for(var n=t.parentNode.querySelectorAll(e),o=0;o<n.length;++o)if(n[o]==t)return!0;return!1}var i=Element.prototype,r=i.matchesSelector||i.webkitMatchesSelector||i.mozMatchesSelector||i.msMatchesSelector||i.oMatchesSelector;e.exports=o},{}],6:[function(t,e,n){function o(t){var e;if("INPUT"===t.nodeName||"TEXTAREA"===t.nodeName)t.focus(),t.setSelectionRange(0,t.value.length),e=t.value;else{t.hasAttribute("contenteditable")&&t.focus();var n=window.getSelection(),o=document.createRange();o.selectNodeContents(t),n.removeAllRanges(),n.addRange(o),e=n.toString()}return e}e.exports=o},{}],7:[function(t,e,n){function o(){}o.prototype={on:function(t,e,n){var o=this.e||(this.e={});return(o[t]||(o[t]=[])).push({fn:e,ctx:n}),this},once:function(t,e,n){function o(){i.off(t,o),e.apply(n,arguments)}var i=this;return o._=e,this.on(t,o,n)},emit:function(t){var e=[].slice.call(arguments,1),n=((this.e||(this.e={}))[t]||[]).slice(),o=0,i=n.length;for(o;i>o;o++)n[o].fn.apply(n[o].ctx,e);return this},off:function(t,e){var n=this.e||(this.e={}),o=n[t],i=[];if(o&&e)for(var r=0,a=o.length;a>r;r++)o[r].fn!==e&&o[r].fn._!==e&&i.push(o[r]);return i.length?n[t]=i:delete n[t],this}},e.exports=o},{}],8:[function(e,n,o){!function(i,r){if("function"==typeof t&&t.amd)t(["module","select"],r);else if("undefined"!=typeof o)r(n,e("select"));else{var a={exports:{}};r(a,i.select),i.clipboardAction=a.exports}}(this,function(t,e){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var i=n(e),r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},a=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),c=function(){function t(e){o(this,t),this.resolveOptions(e),this.initSelection()}return t.prototype.resolveOptions=function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];this.action=e.action,this.emitter=e.emitter,this.target=e.target,this.text=e.text,this.trigger=e.trigger,this.selectedText=""},t.prototype.initSelection=function t(){this.text?this.selectFake():this.target&&this.selectTarget()},t.prototype.selectFake=function t(){var e=this,n="rtl"==document.documentElement.getAttribute("dir");this.removeFake(),this.fakeHandlerCallback=function(){return e.removeFake()},this.fakeHandler=document.body.addEventListener("click",this.fakeHandlerCallback)||!0,this.fakeElem=document.createElement("textarea"),this.fakeElem.style.fontSize="12pt",this.fakeElem.style.border="0",this.fakeElem.style.padding="0",this.fakeElem.style.margin="0",this.fakeElem.style.position="absolute",this.fakeElem.style[n?"right":"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=(0,i.default)(this.fakeElem),this.copyText()},t.prototype.removeFake=function t(){this.fakeHandler&&(document.body.removeEventListener("click",this.fakeHandlerCallback),this.fakeHandler=null,this.fakeHandlerCallback=null),this.fakeElem&&(document.body.removeChild(this.fakeElem),this.fakeElem=null)},t.prototype.selectTarget=function t(){this.selectedText=(0,i.default)(this.target),this.copyText()},t.prototype.copyText=function t(){var e=void 0;try{e=document.execCommand(this.action)}catch(n){e=!1}this.handleResult(e)},t.prototype.handleResult=function t(e){e?this.emitter.emit("success",{action:this.action,text:this.selectedText,trigger:this.trigger,clearSelection:this.clearSelection.bind(this)}):this.emitter.emit("error",{action:this.action,trigger:this.trigger,clearSelection:this.clearSelection.bind(this)})},t.prototype.clearSelection=function t(){this.target&&this.target.blur(),window.getSelection().removeAllRanges()},t.prototype.destroy=function t(){this.removeFake()},a(t,[{key:"action",set:function t(){var e=arguments.length<=0||void 0===arguments[0]?"copy":arguments[0];if(this._action=e,"copy"!==this._action&&"cut"!==this._action)throw new Error('Invalid "action" value, use either "copy" or "cut"')},get:function t(){return this._action}},{key:"target",set:function t(e){if(void 0!==e){if(!e||"object"!==("undefined"==typeof e?"undefined":r(e))||1!==e.nodeType)throw new Error('Invalid "target" value, use a valid Element');if("copy"===this.action&&e.hasAttribute("disabled"))throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');if("cut"===this.action&&(e.hasAttribute("readonly")||e.hasAttribute("disabled")))throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');this._target=e}},get:function t(){return this._target}}]),t}();t.exports=c})},{select:6}],9:[function(e,n,o){!function(i,r){if("function"==typeof t&&t.amd)t(["module","./clipboard-action","tiny-emitter","good-listener"],r);else if("undefined"!=typeof o)r(n,e("./clipboard-action"),e("tiny-emitter"),e("good-listener"));else{var a={exports:{}};r(a,i.clipboardAction,i.tinyEmitter,i.goodListener),i.clipboard=a.exports}}(this,function(t,e,n,o){"use strict";function i(t){return t&&t.__esModule?t:{"default":t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function c(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function s(t,e){var n="data-clipboard-"+t;if(e.hasAttribute(n))return e.getAttribute(n)}var l=i(e),u=i(n),f=i(o),d=function(t){function e(n,o){r(this,e);var i=a(this,t.call(this));return i.resolveOptions(o),i.listenClick(n),i}return c(e,t),e.prototype.resolveOptions=function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];this.action="function"==typeof e.action?e.action:this.defaultAction,this.target="function"==typeof e.target?e.target:this.defaultTarget,this.text="function"==typeof e.text?e.text:this.defaultText},e.prototype.listenClick=function t(e){var n=this;this.listener=(0,f.default)(e,"click",function(t){return n.onClick(t)})},e.prototype.onClick=function t(e){var n=e.delegateTarget||e.currentTarget;this.clipboardAction&&(this.clipboardAction=null),this.clipboardAction=new l.default({action:this.action(n),target:this.target(n),text:this.text(n),trigger:n,emitter:this})},e.prototype.defaultAction=function t(e){return s("action",e)},e.prototype.defaultTarget=function t(e){var n=s("target",e);return n?document.querySelector(n):void 0},e.prototype.defaultText=function t(e){return s("text",e)},e.prototype.destroy=function t(){this.listener.destroy(),this.clipboardAction&&(this.clipboardAction.destroy(),this.clipboardAction=null)},e}(u.default);t.exports=d})},{"./clipboard-action":8,"good-listener":4,"tiny-emitter":7}]},{},[9])(9)});
\ No newline at end of file
// Package metadata for Meteor.js.
Package.describe({
name: "zenorocha:clipboard",
summary: "Modern copy to clipboard. No Flash. Just 2kb.",
version: "1.5.12",
git: "https://github.com/zenorocha/clipboard.js"
});
Package.onUse(function(api) {
api.addFiles("dist/clipboard.js", "client");
});
{
"name": "clipboard",
"version": "1.5.12",
"description": "Modern copy to clipboard. No Flash. Just 2kb",
"repository": "zenorocha/clipboard.js",
"license": "MIT",
"main": "lib/clipboard.js",
"keywords": [
"clipboard",
"copy",
"cut"
],
"dependencies": {
"good-listener": "^1.1.6",
"select": "^1.0.6",
"tiny-emitter": "^1.0.0"
},
"devDependencies": {
"babel-cli": "^6.5.1",
"babel-core": "^6.5.2",
"babel-plugin-transform-es2015-modules-umd": "^6.5.0",
"babel-preset-es2015": "^6.5.0",
"babel-preset-es2015-loose": "^7.0.0",
"babelify": "^7.2.0",
"bannerify": "Vekat/bannerify#feature-option",
"browserify": "^13.0.0",
"chai": "^3.4.1",
"install": "^0.4.4",
"karma": "^0.13.10",
"karma-browserify": "^5.0.1",
"karma-chai": "^0.1.0",
"karma-mocha": "^0.2.0",
"karma-phantomjs-launcher": "^1.0.0",
"karma-sinon": "^1.0.4",
"mocha": "^2.3.3",
"phantomjs-prebuilt": "^2.1.4",
"sinon": "^1.17.2",
"uglify-js": "^2.4.24",
"watchify": "^3.4.0"
},
"scripts": {
"build": "npm run build-debug && npm run build-min",
"build-debug": "browserify src/clipboard.js -s Clipboard -t [babelify] -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 -t [babelify] -o dist/clipboard.js -v",
"test": "karma start --single-run",
"prepublish": "babel src --out-dir lib --loose all"
}
}
# 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 3kb gzipped.
<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 or load it from [a third-party CDN provider](https://github.com/zenorocha/clipboard.js/wiki/CDN-Providers).
```html
<script src="dist/clipboard.min.js"></script>
```
Now, you need to instantiate it by [passing a DOM selector](https://github.com/zenorocha/clipboard.js/blob/master/demo/constructor-selector.html#L18), [HTML element](https://github.com/zenorocha/clipboard.js/blob/master/demo/constructor-node.html#L16-L17), or [list of HTML elements](https://github.com/zenorocha/clipboard.js/blob/master/demo/constructor-nodelist.html#L18-L19).
```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, if you 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 Command+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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment