jquery-cropper.common.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. 'use strict';
  11. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  12. var $ = _interopDefault(require('jquery'));
  13. var Cropper = _interopDefault(require('cropperjs'));
  14. if ($ && $.fn && Cropper) {
  15. var AnotherCropper = $.fn.cropper;
  16. var NAMESPACE = 'cropper';
  17. $.fn.cropper = function jQueryCropper(option) {
  18. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  19. args[_key - 1] = arguments[_key];
  20. }
  21. var result;
  22. this.each(function (i, element) {
  23. var $element = $(element);
  24. var isDestroy = option === 'destroy';
  25. var cropper = $element.data(NAMESPACE);
  26. if (!cropper) {
  27. if (isDestroy) {
  28. return;
  29. }
  30. var options = $.extend({}, $element.data(), $.isPlainObject(option) && option);
  31. cropper = new Cropper(element, options);
  32. $element.data(NAMESPACE, cropper);
  33. }
  34. if (typeof option === 'string') {
  35. var fn = cropper[option];
  36. if ($.isFunction(fn)) {
  37. result = fn.apply(cropper, args);
  38. if (result === cropper) {
  39. result = undefined;
  40. }
  41. if (isDestroy) {
  42. $element.removeData(NAMESPACE);
  43. }
  44. }
  45. }
  46. });
  47. return result !== undefined ? result : this;
  48. };
  49. $.fn.cropper.Constructor = Cropper;
  50. $.fn.cropper.setDefaults = Cropper.setDefaults;
  51. $.fn.cropper.noConflict = function noConflict() {
  52. $.fn.cropper = AnotherCropper;
  53. return this;
  54. };
  55. }