wp/wp-includes/js/clipboard.js
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     1 /*!
     1 /*!
     2  * clipboard.js v2.0.10
     2  * clipboard.js v2.0.11
     3  * https://clipboardjs.com/
     3  * https://clipboardjs.com/
     4  *
     4  *
     5  * Licensed MIT © Zeno Rocha
     5  * Licensed MIT © Zeno Rocha
     6  */
     6  */
     7 (function webpackUniversalModuleDefinition(root, factory) {
     7 (function webpackUniversalModuleDefinition(root, factory) {
    93 ;// CONCATENATED MODULE: ./src/actions/copy.js
    93 ;// CONCATENATED MODULE: ./src/actions/copy.js
    94 
    94 
    95 
    95 
    96 
    96 
    97 /**
    97 /**
       
    98  * Create fake copy action wrapper using a fake element.
       
    99  * @param {String} target
       
   100  * @param {Object} options
       
   101  * @return {String}
       
   102  */
       
   103 
       
   104 var fakeCopyAction = function fakeCopyAction(value, options) {
       
   105   var fakeElement = createFakeElement(value);
       
   106   options.container.appendChild(fakeElement);
       
   107   var selectedText = select_default()(fakeElement);
       
   108   command('copy');
       
   109   fakeElement.remove();
       
   110   return selectedText;
       
   111 };
       
   112 /**
    98  * Copy action wrapper.
   113  * Copy action wrapper.
    99  * @param {String|HTMLElement} target
   114  * @param {String|HTMLElement} target
   100  * @param {Object} options
   115  * @param {Object} options
   101  * @return {String}
   116  * @return {String}
   102  */
   117  */
       
   118 
   103 
   119 
   104 var ClipboardActionCopy = function ClipboardActionCopy(target) {
   120 var ClipboardActionCopy = function ClipboardActionCopy(target) {
   105   var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
   121   var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
   106     container: document.body
   122     container: document.body
   107   };
   123   };
   108   var selectedText = '';
   124   var selectedText = '';
   109 
   125 
   110   if (typeof target === 'string') {
   126   if (typeof target === 'string') {
   111     var fakeElement = createFakeElement(target);
   127     selectedText = fakeCopyAction(target, options);
   112     options.container.appendChild(fakeElement);
   128   } else if (target instanceof HTMLInputElement && !['text', 'search', 'url', 'tel', 'password'].includes(target === null || target === void 0 ? void 0 : target.type)) {
   113     selectedText = select_default()(fakeElement);
   129     // If input type doesn't support `setSelectionRange`. Simulate it. https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange
   114     command('copy');
   130     selectedText = fakeCopyAction(target.value, options);
   115     fakeElement.remove();
       
   116   } else {
   131   } else {
   117     selectedText = select_default()(target);
   132     selectedText = select_default()(target);
   118     command('copy');
   133     command('copy');
   119   }
   134   }
   120 
   135 
   302         clearSelection: function clearSelection() {
   317         clearSelection: function clearSelection() {
   303           if (trigger) {
   318           if (trigger) {
   304             trigger.focus();
   319             trigger.focus();
   305           }
   320           }
   306 
   321 
   307           document.activeElement.blur();
       
   308           window.getSelection().removeAllRanges();
   322           window.getSelection().removeAllRanges();
   309         }
   323         }
   310       });
   324       });
   311     }
   325     }
   312     /**
   326     /**