5 var console = window.console || {
log:
function () {} },
6 $alert = $(
'.docs-alert'),
7 $message = $alert.find(
'.message'),
8 showMessage =
function (message, type) {
9 $message.text(message);
12 $message.addClass(type);
17 setTimeout(
function () {
26 var $image = $(
'.img-container > img'),
29 $dataHeight = $(
'#dataHeight'),
30 $dataWidth = $(
'#dataWidth'),
31 $dataRotate = $(
'#dataRotate'),
34 preview:
'.img-preview',
35 crop:
function (data) {
36 $dataX.val(Math.round(data.x));
37 $dataY.val(Math.round(data.y));
38 $dataHeight.val(Math.round(data.height));
39 $dataWidth.val(Math.round(data.width));
40 $dataRotate.val(Math.round(data.rotate));
45 'build.cropper':
function (e) {
48 'built.cropper':
function (e) {
55 $(document.body).on(
'click',
'[data-method]',
function () {
56 var data = $(
this).data(),
61 data = $.extend({}, data);
63 if (typeof data.target !==
'undefined') {
64 $target = $(data.target);
66 if (typeof data.option ===
'undefined') {
68 data.option = JSON.parse($target.val());
70 console.log(e.message);
75 result = $image.cropper(data.method, data.option);
77 if (data.method ===
'getDataURL') {
78 $(
'#getDataURLModal').modal().find(
'.modal-body').html(
'<img src="' + result +
'">');
81 if ($.isPlainObject(result) && $target) {
83 $target.val(JSON.stringify(result));
85 console.log(e.message);
90 }).on(
'keydown',
function (e) {
95 $image.cropper(
'move', -1, 0);
100 $image.cropper(
'move', 0, -1);
105 $image.cropper(
'move', 1, 0);
110 $image.cropper(
'move', 0, 1);
118 var $inputImage = $(
'#inputImage'),
119 URL = window.URL || window.webkitURL,
123 $inputImage.change(
function () {
124 var files = this.files,
127 if (files && files.length) {
130 if (/^image\/\w+$/.test(file.type)) {
131 blobURL = URL.createObjectURL(file);
132 $image.one(
'built.cropper',
function () {
133 URL.revokeObjectURL(blobURL);
134 }).cropper(
'reset',
true).cropper(
'replace', blobURL);
137 showMessage(
'Please choose an image file.');
142 $inputImage.parent().remove();
147 $(
'.docs-options :checkbox').on(
'change',
function () {
150 options[$this.val()] = $this.prop(
'checked');
151 $image.cropper(
'destroy').cropper(options);
156 $(
'[data-toggle="tooltip"]').tooltip();