diff --git a/inc/SP/DataModel/CustomFieldData.class.php b/inc/SP/DataModel/CustomFieldData.class.php index f4f8fd30..42e26952 100644 --- a/inc/SP/DataModel/CustomFieldData.class.php +++ b/inc/SP/DataModel/CustomFieldData.class.php @@ -2,8 +2,8 @@ /** * sysPass * - * @author nuxsmin - * @link http://syspass.org + * @author nuxsmin + * @link http://syspass.org * @copyright 2012-2017, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. @@ -152,6 +152,14 @@ class CustomFieldData extends CustomFieldBaseData return Html::sanitize($this->value); } + /** + * @return string + */ + public function getSafeHtmlValue() + { + return htmlspecialchars($this->value, ENT_QUOTES); + } + /** * @return int */ diff --git a/inc/themes/material-blue/views/common/aux-customfields.inc b/inc/themes/material-blue/views/common/aux-customfields.inc index 823e4ec4..fe6834ad 100644 --- a/inc/themes/material-blue/views/common/aux-customfields.inc +++ b/inc/themes/material-blue/views/common/aux-customfields.inc @@ -31,7 +31,7 @@ foreach ($customFields as $index => $field):?> type="password" class="mdl-textfield__input mdl-color-text--indigo-400 passwordfield__no-pki " maxlength="500" - value="getCleanValue() !== '') ? '***' : $field->getCleanValue(); ?>" getDefinition()->isRequired() ? 'required' : ''; ?> > + value="getValue() !== '') ? '***' : $field->getSafeHtmlValue(); ?>" getDefinition()->isRequired() ? 'required' : ''; ?> > diff --git a/js/app-main.js b/js/app-main.js index f21f74ba..0d34331d 100644 --- a/js/app-main.js +++ b/js/app-main.js @@ -590,45 +590,45 @@ sysPass.Main = function () { var initializeClipboard = function () { log.info("initializeClipboard"); - if (!Clipboard.isSupported()) { + if (!clipboard.isSupported()) { log.warn(config.LANG[65]); return; } - var clipboard = new Clipboard(".clip-pass-button", { - async: function (trigger) { - var _this = this; + $("body").on("click", ".clip-pass-button", function () { + var json = appActions.account.copypass($(this)).done(function (json) { + sk.set(json.csrf); + }); - return appActions.account.copypass($(trigger)).then(function (json) { - sk.set(json.csrf); + clipboard.copy(json.responseJSON.data.accpass).then( + function () { + msg.ok(config.LANG[45]); + }, + function (err) { + msg.error(config.LANG[46]); + } + ); + }).on("click", ".dialog-clip-button", function () { + var $target = $(this.dataset.clipboardTarget); - _this.asyncText = json.data.accpass; - }); - } - }); - - clipboard.on("success", function (e) { - msg.ok(config.LANG[45]); - }).on("error", function (e) { - msg.error(config.LANG[46]); - }); - - // Portapapeles para claves visualizadas - var clipboardDialog = new Clipboard(".dialog-clip-button"); - - clipboardDialog.on("success", function (e) { - $(".dialog-text").removeClass("dialog-clip-copy"); - $(e.trigger.dataset.clipboardTarget).addClass("dialog-clip-copy"); - - e.clearSelection(); - }); - - var clipboardIcon = new Clipboard(".clip-pass-icon"); - - clipboardIcon.on("success", function (e) { - msg.ok(config.LANG[45]); - - e.clearSelection(); + clipboard.copy($target.text()).then( + function () { + $(".dialog-text").removeClass("dialog-clip-copy"); + $target.addClass("dialog-clip-copy"); + }, + function (err) { + msg.error(config.LANG[46]); + } + ); + }).on("click", ".clip-pass-icon", function () { + clipboard.copy(decodeEntities(this.dataset.clipboardText)).then( + function () { + msg.ok(config.LANG[45]); + }, + function (err) { + msg.error(config.LANG[46]); + } + ); }); }; @@ -770,6 +770,30 @@ sysPass.Main = function () { return image; }; + /** + * @author http://stackoverflow.com/users/24950/robert-k + * @link http://stackoverflow.com/questions/5796718/html-entity-decode + */ + var decodeEntities = (function () { + // this prevents any overhead from creating the object each time + var element = document.createElement("div"); + + function decodeHTMLEntities(str) { + if (str && typeof str === "string") { + // strip script/html tags + str = str.replace(/]*>([\S\s]*?)<\/script>/gmi, ""); + str = str.replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gmi, ""); + element.innerHTML = str; + str = element.textContent; + element.textContent = ""; + } + + return str; + } + + return decodeHTMLEntities; + })(); + // Objeto con métodos y propiedades protegidas var getProtected = function () { return $.extend({ diff --git a/js/app-main.min.js b/js/app-main.min.js index f1f88b90..30b67516 100644 --- a/js/app-main.min.js +++ b/js/app-main.min.js @@ -1,22 +1,23 @@ var $jscomp={scope:{}};$jscomp.defineProperty="function"==typeof Object.defineProperties?Object.defineProperty:function(a,g,f){if(f.get||f.set)throw new TypeError("ES3 does not support getters and setters.");a!=Array.prototype&&a!=Object.prototype&&(a[g]=f.value)};$jscomp.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global?global:a};$jscomp.global=$jscomp.getGlobal(this);$jscomp.SYMBOL_PREFIX="jscomp_symbol_"; $jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};$jscomp.symbolCounter_=0;$jscomp.Symbol=function(a){return $jscomp.SYMBOL_PREFIX+(a||"")+$jscomp.symbolCounter_++}; $jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var a=$jscomp.global.Symbol.iterator;a||(a=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));"function"!=typeof Array.prototype[a]&&$jscomp.defineProperty(Array.prototype,a,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}});$jscomp.initSymbolIterator=function(){}};$jscomp.arrayIterator=function(a){var g=0;return $jscomp.iteratorPrototype(function(){return g"+b.messages.join("
"));switch(a){case 0:h.ok(c);break;case 1:case 2:case 4:h.error(c);break;case 3:h.warn(c); -break;case 10:e.main.logout();break;case 100:h.ok(c);h.sticky(c);break;case 101:h.error(c);h.sticky(c);break;default:h.error(c)}}},html:{error:function(b){return'

Oops...
'+a.LANG[1]+"
"+b+"

"}}},x=function(b){k.info("getEnvironment");var l=window.location.pathname.split("/");a.APP_ROOT=window.location.protocol+"//"+window.location.host+function(){for(var b="",a=1;a<=l.length-2;a++)b+="/"+l[a];return b}();var c=m.getRequestOpts();c.url="/ajax/ajax_getEnvironment.php"; -c.method="get";c.async=!1;c.useLoading=!1;c.data={isAjax:1};m.getActionCall(c,function(c){a.LANG=c.lang;a.PK=c.pk;a.CHECK_UPDATES=c.check_updates;a.CRYPT.setPublicKey(c.pk);a.TIMEZONE=c.timezone;a.LOCALE=c.locale;a.DEBUG=c.debug;a.MAX_FILE_SIZE=parseInt(c.max_file_size);a.COOKIES_ENABLED=c.cookies_enabled;"function"===typeof b&&b()})},p={get:function(){k.info("sk:get");return $("#container").attr("data-sk")},set:function(b){k.info("sk:set");$("#container").attr("data-sk",b)}},y=function(){var b=$("#container"); -if(!b.hasClass("content-no-auto-resize")){var a=$("#content").height()+200;b.css("height",a)}},z=function(){$("html, body").animate({scrollTop:0},"slow")},A=function(a){for(var b=[],c,d=window.location.href.slice(window.location.href.indexOf("?")+1).split("&"),f=0;fa.MAX_FILE_SIZE)h.error(a.LANG[18]+"
"+q.name+" (Max: "+a.MAX_FILE_SIZE+")");else{var d;a:{d=q.name;for(var g=b.data("files-ext").toLowerCase().split(","),e=0;e<=g.length;e++)if(-1!==d.indexOf(g[e])){d=!0;break a}d=!1}d?f(c[l]):h.error(a.LANG[19]+ -"
"+q.name)}}},g=function(a){var b=$("#fileUploadForm");!1===a&&b.hide();a=b.find("input[type='file']");a.on("change",function(){"function"===typeof c.beforeSendAction&&c.beforeSendAction();d(this.files)});return a};window.File&&window.FileList&&window.FileReader?function(){k.info("fileUpload:init");var a=g(!1);b.on("dragover dragenter",function(a){k.info("fileUpload:drag");a.stopPropagation();a.preventDefault()});b.on("drop",function(a){k.info("fileUpload:drop");a.stopPropagation();a.preventDefault(); -"function"===typeof c.beforeSendAction&&c.beforeSendAction();d(a.originalEvent.dataTransfer.files)});b.on("click",function(){a.click()})}():g(!0);return c},D=function(a){k.info("checkPassLevel");g.passLength=a.val().length;v(zxcvbn(a.val()),a)},v=function(b,l){k.info("outputResult");var c=$(".passLevel-"+l.attr("id")),d=b.score;c.show();c.removeClass("weak good strong strongest");0===g.passLength?c.attr("title","").empty():g.passLengtha.secondary?a.calc=a.main/a.rel:a.maina.secondary&&(a.main*=a.factor,g(a));return a},e=function(){f.main=b;f.secondary=c;var e=g(f);a.css({width:e.main,height:e.calc});d.width= -e.main;d.height=e.calc},h=function(){f.main=c;f.secondary=b;var e=g(f);a.css({width:e.calc,height:e.main});d.width=e.calc;d.height=e.main};d.width>b?e():d.height>c&&(k.info("height"),h());return d},J=function(){return $.extend({log:k,config:function(){return a},appTheme:function(){return f},appActions:function(){return e},appTriggers:function(){return d},appRequests:function(){return m},evalAction:H,resizeImage:I},r)},K=function(){return{actions:function(){return e},triggers:function(){return d}, -theme:function(){return f},sk:p,msg:h,log:k,passToClip:0,passwordData:g,outputResult:v,checkboxDetect:E,checkPassLevel:D,encryptFormValue:u,fileUpload:C,redirect:t,scrollUp:z,setContentSize:y}};(function(){k.info("init");r=K();n=J();d=sysPass.Triggers(n);e=sysPass.Actions(n);m=sysPass.Requests(n);x(function(){""!==a.PK&&G();"function"===typeof sysPass.Theme&&(f=sysPass.Theme(n));!0===a.CHECK_UPDATES&&e.main.getUpdates();!1===a.COOKIES_ENABLED&&h.sticky(a.LANG[64]);F();w();B()})})();return r}; +$jscomp.iteratorPrototype=function(a){$jscomp.initSymbolIterator();a={next:a};a[$jscomp.global.Symbol.iterator]=function(){return this};return a};$jscomp.array=$jscomp.array||{};$jscomp.iteratorFromArray=function(a,g){$jscomp.initSymbolIterator();a instanceof String&&(a+="");var f=0,d={next:function(){if(f"+b.messages.join("
"));switch(a){case 0:k.ok(c);break;case 1:case 2:case 4:k.error(c);break;case 3:k.warn(c); +break;case 10:h.main.logout();break;case 100:k.ok(c);k.sticky(c);break;case 101:k.error(c);k.sticky(c);break;default:k.error(c)}}},html:{error:function(b){return'

Oops...
'+a.LANG[1]+"
"+b+"

"}}},x=function(b){l.info("getEnvironment");var e=window.location.pathname.split("/");a.APP_ROOT=window.location.protocol+"//"+window.location.host+function(){for(var b="",a=1;a<=e.length-2;a++)b+="/"+e[a];return b}();var c=m.getRequestOpts();c.url="/ajax/ajax_getEnvironment.php"; +c.method="get";c.async=!1;c.useLoading=!1;c.data={isAjax:1};m.getActionCall(c,function(e){a.LANG=e.lang;a.PK=e.pk;a.CHECK_UPDATES=e.check_updates;a.CRYPT.setPublicKey(e.pk);a.TIMEZONE=e.timezone;a.LOCALE=e.locale;a.DEBUG=e.debug;a.MAX_FILE_SIZE=parseInt(e.max_file_size);a.COOKIES_ENABLED=e.cookies_enabled;"function"===typeof b&&b()})},p={get:function(){l.info("sk:get");return $("#container").attr("data-sk")},set:function(a){l.info("sk:set");$("#container").attr("data-sk",a)}},y=function(){var a=$("#container"); +if(!a.hasClass("content-no-auto-resize")){var e=$("#content").height()+200;a.css("height",e)}},z=function(){$("html, body").animate({scrollTop:0},"slow")},A=function(a){for(var b=[],c,d=window.location.href.slice(window.location.href.indexOf("?")+1).split("&"),f=0;fa.MAX_FILE_SIZE)k.error(a.LANG[18]+"
"+q.name+" (Max: "+a.MAX_FILE_SIZE+")");else{var d;a:{d=q.name;for(var g=b.data("files-ext").toLowerCase().split(","),h=0;h<=g.length;h++)if(-1!==d.indexOf(g[h])){d=!0;break a}d=!1}d?f(e[c]):k.error(a.LANG[19]+ +"
"+q.name)}}},g=function(a){var b=$("#fileUploadForm");!1===a&&b.hide();a=b.find("input[type='file']");a.on("change",function(){"function"===typeof c.beforeSendAction&&c.beforeSendAction();d(this.files)});return a};window.File&&window.FileList&&window.FileReader?function(){l.info("fileUpload:init");var a=g(!1);b.on("dragover dragenter",function(a){l.info("fileUpload:drag");a.stopPropagation();a.preventDefault()});b.on("drop",function(a){l.info("fileUpload:drop");a.stopPropagation();a.preventDefault(); +"function"===typeof c.beforeSendAction&&c.beforeSendAction();d(a.originalEvent.dataTransfer.files)});b.on("click",function(){a.click()})}():g(!0);return c},D=function(a){l.info("checkPassLevel");g.passLength=a.val().length;v(zxcvbn(a.val()),a)},v=function(b,e){l.info("outputResult");var c=$(".passLevel-"+e.attr("id")),d=b.score;c.show();c.removeClass("weak good strong strongest");0===g.passLength?c.attr("title","").empty():g.passLengtha.secondary?a.calc=a.main/a.rel:a.maina.secondary&&(a.main*=a.factor,g(a));return a},h=function(){f.main=b;f.secondary=c;var e=g(f);a.css({width:e.main,height:e.calc});d.width=e.main;d.height=e.calc},k=function(){f.main=c;f.secondary=b;var e=g(f);a.css({width:e.calc,height:e.main});d.width=e.calc;d.height=e.main};d.width>b?h():d.height>c&&(l.info("height"),k());return d},F=function(){var a=document.createElement("div");return function(b){b&&"string"===typeof b&&(b=b.replace(/]*>([\S\s]*?)<\/script>/gmi, +""),b=b.replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gmi,""),a.innerHTML=b,b=a.textContent,a.textContent="");return b}}(),K=function(){return $.extend({log:l,config:function(){return a},appTheme:function(){return f},appActions:function(){return h},appTriggers:function(){return d},appRequests:function(){return m},evalAction:I,resizeImage:J},r)},L=function(){return{actions:function(){return h},triggers:function(){return d},theme:function(){return f},sk:p,msg:k,log:l,passToClip:0,passwordData:g,outputResult:v, +checkboxDetect:E,checkPassLevel:D,encryptFormValue:u,fileUpload:C,redirect:t,scrollUp:z,setContentSize:y}};(function(){l.info("init");r=L();n=K();d=sysPass.Triggers(n);h=sysPass.Actions(n);m=sysPass.Requests(n);x(function(){""!==a.PK&&H();"function"===typeof sysPass.Theme&&(f=sysPass.Theme(n));!0===a.CHECK_UPDATES&&h.main.getUpdates();!1===a.COOKIES_ENABLED&&k.sticky(a.LANG[64]);G();w();B()})})();return r}; diff --git a/js/app-triggers.js b/js/app-triggers.js index ae18339e..ff0b1bf1 100644 --- a/js/app-triggers.js +++ b/js/app-triggers.js @@ -183,7 +183,7 @@ sysPass.Triggers = function (Common) { main: function () { log.info("views:main"); - if (!Clipboard.isSupported()) { + if (!clipboard.isSupported()) { Common.msg.info(Common.config().LANG[65]); } diff --git a/js/app-triggers.min.js b/js/app-triggers.min.js index 04536611..0894af6d 100644 --- a/js/app-triggers.min.js +++ b/js/app-triggers.min.js @@ -2,7 +2,7 @@ var $jscomp={scope:{},findInternal:function(b,d,e){b instanceof String&&(b=Strin $jscomp.getGlobal=function(b){return"undefined"!=typeof window&&window===b?b:"undefined"!=typeof global?global:b};$jscomp.global=$jscomp.getGlobal(this);$jscomp.polyfill=function(b,d,e,a){if(d){e=$jscomp.global;b=b.split(".");for(a=0;aform").each(function(){var a=$(this);a.find("button.btn-clear").on("click",function(b){b.preventDefault();a.trigger("reset")})})},config:function(){d.info("views:config");var a=$("#drop-import-files");if(0 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.async = options.async; - - this.selectedText = ''; - } - }, { - key: 'initSelection', - value: function initSelection() { - if (this.text) { - this.selectFake(); - } else if (this.target) { - this.selectTarget(); - } - } - }, { - key: 'selectFake', - value: function selectFake() { - var _this = this; - - var isRTL = document.documentElement.getAttribute('dir') == 'rtl'; - - this.removeFake(); - - this.fakeHandlerCallback = function () { - return _this.removeFake(); - }; - this.fakeHandler = document.body.addEventListener('click', this.fakeHandlerCallback) || true; - - this.fakeElem = document.createElement('textarea'); - // Prevent zooming on iOS - this.fakeElem.style.fontSize = '12pt'; - // Reset box model - this.fakeElem.style.border = '0'; - this.fakeElem.style.padding = '0'; - this.fakeElem.style.margin = '0'; - // Move element out of screen horizontally - this.fakeElem.style.position = 'absolute'; - this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px'; - // Move element to the same position vertically - var yPosition = window.pageYOffset || document.documentElement.scrollTop; - this.fakeElem.style.top = yPosition + 'px'; - - this.fakeElem.setAttribute('readonly', ''); - this.fakeElem.value = this.text; - - document.body.appendChild(this.fakeElem); - - this.selectedText = (0, _select2.default)(this.fakeElem); - this.copyText(); - } - }, { - key: 'removeFake', - value: function removeFake() { - if (this.fakeHandler) { - document.body.removeEventListener('click', this.fakeHandlerCallback); - this.fakeHandler = null; - this.fakeHandlerCallback = null; - } - - if (this.fakeElem) { - document.body.removeChild(this.fakeElem); - this.fakeElem = null; - } - } - }, { - key: 'selectTarget', - value: function selectTarget() { - this.selectedText = (0, _select2.default)(this.target); - this.copyText(); - } - }, { - key: 'copyText', - value: function copyText() { - var succeeded = void 0; - - try { - succeeded = document.execCommand(this.action); - } catch (err) { - succeeded = false; - } - - this.handleResult(succeeded); - } - }, { - key: 'handleResult', - value: function handleResult(succeeded) { - this.emitter.emit(succeeded ? 'success' : 'error', { - action: this.action, - text: this.selectedText, - trigger: this.trigger, - clearSelection: this.clearSelection.bind(this) - }); - } - }, { - key: 'clearSelection', - value: function clearSelection() { - if (this.target) { - this.target.blur(); - } - - window.getSelection().removeAllRanges(); - } - }, { - key: 'destroy', - value: function destroy() { - this.removeFake(); - } - }, { - key: 'action', - set: function set() { - var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'copy'; - - this._action = action; - - if (this._action !== 'copy' && this._action !== 'cut') { - throw new Error('Invalid "action" value, use either "copy" or "cut"'); - } - }, - get: function get() { - return this._action; - } - }, { - key: 'target', - set: function set(target) { - if (target !== undefined) { - if (target && (typeof target === 'undefined' ? 'undefined' : _typeof(target)) === 'object' && target.nodeType === 1) { - if (this.action === 'copy' && target.hasAttribute('disabled')) { - throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute'); - } - - if (this.action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) { - throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes'); - } - - this._target = target; - } else { - throw new Error('Invalid "target" value, use a valid Element'); - } - } - }, - get: function get() { - return this._target; - } - }]); - - return ClipboardAction; - }(); - - module.exports = ClipboardAction; - }); - - }, {"select": 5}], 8: [function (require, module, exports) { - (function (global, factory) { - if (typeof define === "function" && define.amd) { - define(['module', './clipboard-action', 'tiny-emitter', 'good-listener'], factory); - } else if (typeof exports !== "undefined") { - factory(module, require('./clipboard-action'), require('tiny-emitter'), require('good-listener')); - } else { - var mod = { - exports: {} - }; - factory(mod, global.clipboardAction, global.tinyEmitter, global.goodListener); - global.clipboard = mod.exports; - } - })(this, function (module, _clipboardAction, _tinyEmitter, _goodListener) { - 'use strict'; - - var _clipboardAction2 = _interopRequireDefault(_clipboardAction); - - var _tinyEmitter2 = _interopRequireDefault(_tinyEmitter); - - var _goodListener2 = _interopRequireDefault(_goodListener); - - 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 _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 _possibleConstructorReturn(self, call) { - if (!self) { - throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - } - - return call && (typeof call === "object" || typeof call === "function") ? call : self; - } - - 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 Clipboard = function (_Emitter) { - _inherits(Clipboard, _Emitter); - - /** - * @param {String|HTMLElement|HTMLCollection|NodeList} trigger - * @param {Object} options - */ - function Clipboard(trigger, options) { - _classCallCheck(this, Clipboard); - - var _this = _possibleConstructorReturn(this, (Clipboard.__proto__ || Object.getPrototypeOf(Clipboard)).call(this)); - - _this.resolveOptions(options); - _this.listenClick(trigger); - return _this; - } - - /** - * Defines if attributes would be resolved using internal setter functions - * or custom functions that were passed in the constructor. - * @param {Object} options - */ - - - _createClass(Clipboard, [{ - key: 'resolveOptions', - value: 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; - this.async = options.async; - this.asyncText = ''; - } - }, { - key: 'listenClick', - value: function listenClick(trigger) { - var _this2 = this; - - this.listener = (0, _goodListener2.default)(trigger, 'click', function (e) { - return _this2.onClick(e); - }); - } - }, { - key: 'onClick', - value: function onClick(e) { - var trigger = e.delegateTarget || e.currentTarget; - - if (this.clipboardAction) { - this.clipboardAction = null; - } - - if (typeof this.async === "function") { - var _this = this; - - this.async(trigger).then(function () { - _this.clipboardAction = new _clipboardAction2.default({ - action: _this.action(trigger), - target: _this.target(trigger), - text: _this.asyncText, - trigger: trigger, - emitter: _this - }); - }); + else { + if (!tryBogusSelect) { + bogusSelect(); + triggerCopy(true); } else { - this.clipboardAction = new _clipboardAction2.default({ - action: this.action(trigger), - target: this.target(trigger), - text: this.text(trigger), - trigger: trigger, - emitter: this - }); + cleanup(); + throw new Error("Unable to copy. Perhaps it's not available in your browser?"); } } - }, { - key: 'defaultAction', - value: function defaultAction(trigger) { - return getAttributeValue('action', trigger); - } - }, { - key: 'defaultTarget', - value: function defaultTarget(trigger) { - var selector = getAttributeValue('target', trigger); - - if (selector) { - return document.querySelector(selector); - } - } - }, { - key: 'defaultText', - value: function defaultText(trigger) { - return getAttributeValue('text', trigger); - } - }, { - key: 'destroy', - value: function destroy() { - this.listener.destroy(); - - if (this.clipboardAction) { - this.clipboardAction.destroy(); - this.clipboardAction = null; - } - } - }], [{ - key: 'isSupported', - value: function isSupported() { - var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut']; - - var actions = typeof action === 'string' ? [action] : action; - var support = !!document.queryCommandSupported; - - actions.forEach(function (action) { - support = support && !!document.queryCommandSupported(action); - }); - - return support; - } - }]); - - return Clipboard; - }(_tinyEmitter2.default); - - /** - * Helper function to retrieve attribute value. - * @param {String} suffix - * @param {Element} element - */ - function getAttributeValue(suffix, element) { - var attribute = 'data-clipboard-' + suffix; - - if (!element.hasAttribute(attribute)) { - return; + } catch (e) { + cleanup(); + reject(e); } - - return element.getAttribute(attribute); } - module.exports = Clipboard; - }); + triggerCopy(false); - }, {"./clipboard-action": 7, "good-listener": 4, "tiny-emitter": 6}] - }, {}, [8])(8) -}); \ No newline at end of file + }); + }; + })(); + + clipboard.paste = (function () { + var _intercept = false; + var _resolve; + var _dataType; + + document.addEventListener("paste", function (e) { + if (_intercept) { + _intercept = false; + e.preventDefault(); + var resolve = _resolve; + _resolve = null; + resolve(e.clipboardData.getData(_dataType)); + } + }); + + return function (dataType) { + return new Promise(function (resolve, reject) { + _intercept = true; + _resolve = resolve; + _dataType = dataType || "text/plain"; + try { + if (!document.execCommand("paste")) { + _intercept = false; + reject(new Error("Unable to paste. Pasting only works in Internet Explorer at the moment.")); + } + } catch (e) { + _intercept = false; + reject(new Error(e)); + } + }); + }; + })(); + + // @author https://github.com/zenorocha + clipboard.isSupported = function isSupported() { + var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ["copy", "cut"]; + + var actions = typeof action === "string" ? [action] : action; + var support = !!document.queryCommandSupported; + + actions.forEach(function (action) { + support = support && !!document.queryCommandSupported(action); + }); + + return support; + }; + + // Handle IE behaviour. + if (typeof ClipboardEvent === "undefined" && + typeof window.clipboardData !== "undefined" && + typeof window.clipboardData.setData !== "undefined") { + + /*! promise-polyfill 2.0.1 */ + (function (a) { + function b(a, b) { + return function () { + a.apply(b, arguments) + } + } + + function c(a) { + if ("object" != typeof this)throw new TypeError("Promises must be constructed via new"); + if ("function" != typeof a)throw new TypeError("not a function"); + this._state = null, this._value = null, this._deferreds = [], i(a, b(e, this), b(f, this)) + } + + function d(a) { + var b = this; + return null === this._state ? void this._deferreds.push(a) : void j(function () { + var c = b._state ? a.onFulfilled : a.onRejected; + if (null === c)return void(b._state ? a.resolve : a.reject)(b._value); + var d; + try { + d = c(b._value) + } catch (e) { + return void a.reject(e) + } + a.resolve(d) + }) + } + + function e(a) { + try { + if (a === this)throw new TypeError("A promise cannot be resolved with itself."); + if (a && ("object" == typeof a || "function" == typeof a)) { + var c = a.then; + if ("function" == typeof c)return void i(b(c, a), b(e, this), b(f, this)) + } + this._state = !0, this._value = a, g.call(this) + } catch (d) { + f.call(this, d) + } + } + + function f(a) { + this._state = !1, this._value = a, g.call(this) + } + + function g() { + for (var a = 0, b = this._deferreds.length; b > a; a++)d.call(this, this._deferreds[a]); + this._deferreds = null + } + + function h(a, b, c, d) { + this.onFulfilled = "function" == typeof a ? a : null, this.onRejected = "function" == typeof b ? b : null, this.resolve = c, this.reject = d + } + + function i(a, b, c) { + var d = !1; + try { + a(function (a) { + d || (d = !0, b(a)) + }, function (a) { + d || (d = !0, c(a)) + }) + } catch (e) { + if (d)return; + d = !0, c(e) + } + } + + var j = c.immediateFn || "function" == typeof setImmediate && setImmediate || function (a) { + setTimeout(a, 1) + }, k = Array.isArray || function (a) { + return "[object Array]" === Object.prototype.toString.call(a) + }; + c.prototype["catch"] = function (a) { + return this.then(null, a) + }, c.prototype.then = function (a, b) { + var e = this; + return new c(function (c, f) { + d.call(e, new h(a, b, c, f)) + }) + }, c.all = function () { + var a = Array.prototype.slice.call(1 === arguments.length && k(arguments[0]) ? arguments[0] : arguments); + return new c(function (b, c) { + function d(f, g) { + try { + if (g && ("object" == typeof g || "function" == typeof g)) { + var h = g.then; + if ("function" == typeof h)return void h.call(g, function (a) { + d(f, a) + }, c) + } + a[f] = g, 0 === --e && b(a) + } catch (i) { + c(i) + } + } + + if (0 === a.length)return b([]); + for (var e = a.length, f = 0; f < a.length; f++)d(f, a[f]) + }) + }, c.resolve = function (a) { + return a && "object" == typeof a && a.constructor === c ? a : new c(function (b) { + b(a) + }) + }, c.reject = function (a) { + return new c(function (b, c) { + c(a) + }) + }, c.race = function (a) { + return new c(function (b, c) { + for (var d = 0, e = a.length; e > d; d++)a[d].then(b, c) + }) + }, "undefined" != typeof module && module.exports ? module.exports = c : a.Promise || (a.Promise = c) + })(this); + + clipboard.copy = function (data) { + return new Promise(function (resolve, reject) { + // IE supports string and URL types: https://msdn.microsoft.com/en-us/library/ms536744(v=vs.85).aspx + // We only support the string type for now. + if (typeof data !== "string" && !("text/plain" in data)) { + throw new Error("You must provide a text/plain type."); + } + + var strData = (typeof data === "string" ? data : data["text/plain"]); + var copySucceeded = window.clipboardData.setData("Text", strData); + if (copySucceeded) { + resolve(); + } else { + reject(new Error("Copying was rejected.")); + } + }); + }; + + clipboard.paste = function () { + return new Promise(function (resolve, reject) { + var strData = window.clipboardData.getData("Text"); + if (strData) { + resolve(strData); + } else { + // The user rejected the paste request. + reject(new Error("Pasting was rejected.")); + } + }); + }; + } + + return clipboard; +})); diff --git a/js/clipboard.min.js b/js/clipboard.min.js index d35ea87d..e04641b5 100644 --- a/js/clipboard.min.js +++ b/js/clipboard.min.js @@ -1,23 +1,9 @@ -var $jscomp={scope:{}};$jscomp.defineProperty="function"==typeof Object.defineProperties?Object.defineProperty:function(g,b,c){if(c.get||c.set)throw new TypeError("ES3 does not support getters and setters.");g!=Array.prototype&&g!=Object.prototype&&(g[b]=c.value)};$jscomp.getGlobal=function(g){return"undefined"!=typeof window&&window===g?g:"undefined"!=typeof global&&null!=global?global:g};$jscomp.global=$jscomp.getGlobal(this); -$jscomp.polyfill=function(g,b,c,f){if(b){c=$jscomp.global;g=g.split(".");for(f=0;fa;a++)e.call(this,this._deferreds[a]);this._deferreds=null}function n(a,b,c,d){this.onFulfilled="function"==typeof a?a:null;this.onRejected="function"==typeof b?b:null;this.resolve=c;this.reject=d}function m(a,b,c){var d=!1;try{a(function(a){d||(d=!0,b(a))},function(a){d||(d=!0,c(a))})}catch(l){d||(d= +!0,c(l))}}var p=b.immediateFn||"function"==typeof setImmediate&&setImmediate||function(a){setTimeout(a,1)},q=Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)};b.prototype["catch"]=function(a){return this.then(null,a)};b.prototype.then=function(a,c){var d=this;return new b(function(b,f){e.call(d,new n(a,c,b,f))})};b.all=function(){var a=Array.prototype.slice.call(1===arguments.length&&q(arguments[0])?arguments[0]:arguments);return new b(function(b,c){function d(e, +g){try{if(g&&("object"==typeof g||"function"==typeof g)){var h=g.then;if("function"==typeof h)return void h.call(g,function(a){d(e,a)},c)}a[e]=g;0===--f&&b(a)}catch(t){c(t)}}if(0===a.length)return b([]);for(var f=a.length,e=0;ed;d++)a[d].then(b,c)})}; +"undefined"!=typeof module&&module.exports?module.exports=b:c.Promise||(c.Promise=b)}(this),e.copy=function(c){return new Promise(function(d,b){if("string"!==typeof c&&!("text/plain"in c))throw Error("You must provide a text/plain type.");window.clipboardData.setData("Text","string"===typeof c?c:c["text/plain"])?d():b(Error("Copying was rejected."))})},e.paste=function(){return new Promise(function(c,d){var b=window.clipboardData.getData("Text");b?c(b):d(Error("Pasting was rejected."))})});return e});