abc4c9ee21966e51361d27efacffb2564aa0c776fa6bddee2d53b365e8e3d722636a1bfdd6bbed8314d0dabe1ed670b80e0daf0bb2323e30ec7a10467227f1 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /// <reference lib="dom"/>
  2. type Action = 'cut' | 'copy';
  3. type Response = 'success' | 'error';
  4. type Options = {
  5. text?: string;
  6. action?: Action;
  7. target?: Element;
  8. container?: Element;
  9. };
  10. /**
  11. * Base class which takes one or more elements, adds event listeners to them,
  12. * and instantiates a new `ClipboardAction` on each click.
  13. */
  14. declare class ClipboardJS {
  15. constructor(
  16. selector: string | Element | NodeListOf<Element>,
  17. options?: ClipboardJS.Options
  18. );
  19. /**
  20. * Subscribes to events that indicate the result of a copy/cut operation.
  21. * @param type Event type ('success' or 'error').
  22. * @param handler Callback function.
  23. */
  24. on(type: Response, handler: (e: ClipboardJS.Event) => void): this;
  25. on(type: string, handler: (...args: any[]) => void): this;
  26. /**
  27. * Clears all event bindings.
  28. */
  29. destroy(): void;
  30. /**
  31. * Checks if clipboard.js is supported
  32. */
  33. static isSupported(): boolean;
  34. }
  35. declare namespace ClipboardJS {
  36. interface Options {
  37. /**
  38. * Overwrites default command ('cut' or 'copy').
  39. * @param elem Current element
  40. */
  41. action?(elem: Element): Action;
  42. /**
  43. * Overwrites default target input element.
  44. * @param elem Current element
  45. * @returns <input> element to use.
  46. */
  47. target?(elem: Element): Element;
  48. /**
  49. * Returns the explicit text to copy.
  50. * @param elem Current element
  51. * @returns Text to be copied.
  52. */
  53. text?(elem: Element): string;
  54. /**
  55. * For use in Bootstrap Modals or with any
  56. * other library that changes the focus
  57. * you'll want to set the focused element
  58. * as the container value.
  59. */
  60. container?: Element;
  61. }
  62. interface Event {
  63. action: string;
  64. text: string;
  65. trigger: Element;
  66. clearSelection(): void;
  67. }
  68. }
  69. export = ClipboardJS;
  70. export as namespace ClipboardJS;