jquery-cropper.esm.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*!
  2. * jQuery Cropper v1.0.1
  3. * https://fengyuanchen.github.io/jquery-cropper
  4. *
  5. * Copyright 2018-present Chen Fengyuan
  6. * Released under the MIT license
  7. *
  8. * Date: 2019-10-19T08:48:33.062Z
  9. */
  10. import $ from 'jquery';
  11. import Cropper from 'cropperjs';
  12. if ($ && $.fn && Cropper) {
  13. var AnotherCropper = $.fn.cropper;
  14. var NAMESPACE = 'cropper';
  15. $.fn.cropper = function jQueryCropper(option) {
  16. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  17. args[_key - 1] = arguments[_key];
  18. }
  19. var result;
  20. this.each(function (i, element) {
  21. var $element = $(element);
  22. var isDestroy = option === 'destroy';
  23. var cropper = $element.data(NAMESPACE);
  24. if (!cropper) {
  25. if (isDestroy) {
  26. return;
  27. }
  28. var options = $.extend({}, $element.data(), $.isPlainObject(option) && option);
  29. cropper = new Cropper(element, options);
  30. $element.data(NAMESPACE, cropper);
  31. }
  32. if (typeof option === 'string') {
  33. var fn = cropper[option];
  34. if ($.isFunction(fn)) {
  35. result = fn.apply(cropper, args);
  36. if (result === cropper) {
  37. result = undefined;
  38. }
  39. if (isDestroy) {
  40. $element.removeData(NAMESPACE);
  41. }
  42. }
  43. }
  44. });
  45. return result !== undefined ? result : this;
  46. };
  47. $.fn.cropper.Constructor = Cropper;
  48. $.fn.cropper.setDefaults = Cropper.setDefaults;
  49. $.fn.cropper.noConflict = function noConflict() {
  50. $.fn.cropper = AnotherCropper;
  51. return this;
  52. };
  53. }