jQuery plugin - Bootstrap Modal

Install:

$ npm install jquery-plugin-bsmodal
or
$ yarn add jquery-plugin-bsmodal

Example:

Basic modal:

$('#basicBtn').bsModal({
  id: 'bsModal',
  title: 'Title',
  body: 'Modal body text......',
  onOpen: function () {
    console.log('Open');
  },
  onClose: function () {
    console.log('Close');
  },
  onOk: function () {
    console.log('OK');
  },
  onCancel: function () {
    console.log('Cancel');
  }
});

Confirm modal:

$('#confirmBtn').bsModal({
  id: 'bsModalConfirm',
  title: 'Title',
  body: 'Confirm......',
  confirm: true,
  onOpen: function () {
    console.log('Open');
  },
  onClose: function () {
    console.log('Close');
  },
  onOk: function () {
    console.log('OK');
  },
  onCancel: function () {
    console.log('Cancel');
  }
});

Crop image:

<button type="button" class="btn btn-primary" id="cropImageBtn">
  Try it
</button>

<div id="cropedImageBox" class="mt-3" style="display: none">
  <img id="cropedImage">
</div>
$('#cropImageBtn').bsModalCropper({
  id: 'bsModalCropper',
  title: 'Crop image',
  src: 'https://ycs77.github.io/jquery-plugin-bsModal/example-picture.jpg',

  // Cropper.js options
  cropper: {
    aspectRatio: 16 / 9
  },

  // On cropper
  onCropper: function (imgDataURL, imgBlob, uploadFile) {
    $('#cropedImageBox').show();
    $('#cropedImage').attr('src', imgDataURL);
  }
});

Limit cropped image max width and height:

<button type="button" class="btn btn-primary" id="cropLimitImageBtn">
  Try it
</button>

<div id="cropedLimitImageBox" class="mt-3" style="display: none">
  <img id="cropedLimitImage">
</div>

$('#cropLimitImageBtn').bsModalCropper({
  id: 'bsModalCropper',
  title: 'Crop image',
  src: 'example-picture.jpg',

  // Output image max size box
  maxWidth: 300,
  maxHeight: 300,

  // Cropper.js options
  cropper: {
    aspectRatio: 16 / 9
  },

  // On cropper
  onCropper: function (imgDataURL, imgBlob, uploadFile) {
    $('#cropedLimitImageBox').show();
    $('#cropedLimitImage').attr('src', imgDataURL);
  }
});

Upload image and crop image:

<label class="btn btn-primary" id="uploadImgBtn">
  <input type="file" name="upfile" id="upfile" class="d-none">
  Try it
</label>

<div id="cropedUploadImageBox" class="mt-3" style="display: none">
  <img id="cropedUploadImage">
</div>
$('#uploadImgBtn').bsModalCropper({
  id: 'bsModalCropper',
  title: 'Cropper image',

  // Cropper.js options
  cropper: {
    aspectRatio: 16 / 9
  },

  // On cropper
  onCropper: function (imgDataURL, imgBlob, uploadFile) {
    $('#cropedUploadImageBox').show();
    $('#cropedUploadImage').attr('src', imgDataURL);
  },

  // // Upload image
  // action: '/url', // Can set your Upload URL
  // success: function (data) {
  //   console.log(data);
  // },
  uploadConfig: {
    maxSize: Math.pow(1024, 2) * 5 // 5M
  },
  onUpload: function (uploadFile) {
    console.log(uploadFile);
  },
  onUploadError: function (error) {
    console.error(error);
  }
});