123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- (function (global, factory) {
- if (typeof define === "function" && define.amd) {
- define("/forms/image-cropping", ["jquery", "Site"], factory);
- } else if (typeof exports !== "undefined") {
- factory(require("jquery"), require("Site"));
- } else {
- var mod = {
- exports: {}
- };
- factory(global.jQuery, global.Site);
- global.formsImageCropping = mod.exports;
- }
- })(this, function (_jquery, _Site) {
- "use strict";
- _jquery = babelHelpers.interopRequireDefault(_jquery);
- (0, _jquery.default)(document).ready(function ($$$1) {
- (0, _Site.run)();
- }); // Example Cropper Simple
- // ----------------------
- (function () {
- (0, _jquery.default)("#simpleCropper img").cropper({
- preview: "#simpleCropperPreview >.img-preview",
- responsive: true
- });
- })(); // Example Cropper Full
- // --------------------
- (function () {
- var $exampleFullCropper = (0, _jquery.default)("#exampleFullCropper img"),
- $inputDataX = (0, _jquery.default)("#inputDataX"),
- $inputDataY = (0, _jquery.default)("#inputDataY"),
- $inputDataHeight = (0, _jquery.default)("#inputDataHeight"),
- $inputDataWidth = (0, _jquery.default)("#inputDataWidth");
- var options = {
- aspectRatio: 16 / 9,
- preview: "#exampleFullCropperPreview > .img-preview",
- responsive: true,
- crop: function crop() {
- var data = (0, _jquery.default)(this).data('cropper').getCropBoxData();
- $inputDataX.val(Math.round(data.left));
- $inputDataY.val(Math.round(data.top));
- $inputDataHeight.val(Math.round(data.height));
- $inputDataWidth.val(Math.round(data.width));
- }
- }; // set up cropper
- $exampleFullCropper.cropper(options); // set up method buttons
- (0, _jquery.default)(document).on("click", "[data-cropper-method]", function () {
- var data = (0, _jquery.default)(this).data(),
- method = (0, _jquery.default)(this).data('cropper-method'),
- result;
- if (method) {
- result = $exampleFullCropper.cropper(method, data.option);
- }
- if (method === 'getCroppedCanvas') {
- (0, _jquery.default)('#getDataURLModal').modal().find('.modal-body').html(result);
- }
- }); // deal wtih uploading
- var $inputImage = (0, _jquery.default)("#inputImage");
- if (window.FileReader) {
- $inputImage.change(function () {
- var fileReader = new FileReader(),
- files = this.files,
- file;
- if (!files.length) {
- return;
- }
- file = files[0];
- if (/^image\/\w+$/.test(file.type)) {
- fileReader.readAsDataURL(file);
- fileReader.onload = function () {
- $exampleFullCropper.cropper("reset", true).cropper("replace", this.result);
- $inputImage.val("");
- };
- } else {
- showMessage("Please choose an image file.");
- }
- });
- } else {
- $inputImage.addClass("hide");
- } // set data
- (0, _jquery.default)("#setCropperData").click(function () {
- var data = {
- left: parseInt($inputDataX.val()),
- top: parseInt($inputDataY.val()),
- width: parseInt($inputDataWidth.val()),
- height: parseInt($inputDataHeight.val())
- };
- $exampleFullCropper.cropper("setCropBoxData", data);
- });
- })();
- });
|