-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathiron-cropper.html
87 lines (71 loc) · 1.87 KB
/
iron-cropper.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<script src="../cropperjs/dist/cropper.min.js"></script>
<link rel="import" href="../polymer/polymer.html">
<!--
`iron-cropper`
Polymer 1.0 element that wraps around Cropper.js
@demo demo/index.html
-->
<dom-module id="iron-cropper">
<link rel="import" type="css" href="../cropperjs/dist/cropper.min.css">
<template>
<style>
#wrapper {
display: block;
}
#image {
max-width: 100%;
}
</style>
<div>
<div id="wrapper">
<img id="image" src="[[src]]" on-load="render">
</div>
</div>
</template>
<script>
Polymer({
is: 'iron-cropper',
properties: {
/**
* The URL of the image to be cropped
*/
src: {
type: String,
reflectToAttribute: true
},
/**
* The options object as specified in https://github.com/fengyuanchen/cropperjs#options
*/
options: {
type: Object,
value: function () {
return { aspectRatio: 1 }
}
}
},
render: function () {
if (!window.Cropper) {
return console.error('Cropper has not been initialized');
}
if (this._cropper) {
this._cropper.destroy();
}
var options = Object.assign({}, this.options);
var wrapper = this.$.wrapper;
options._ready = options.ready;
options.ready = function (e) {
wrapper.removeAttribute('style');
if (options._ready) {
return options._ready(e);
}
};
wrapper.setAttribute('style', 'max-height: ' + this.$.image.offsetHeight + 'px');
if (!this._scoped) {
this._scoped = true;
this.scopeSubtree(wrapper, true);
}
this._cropper = new window.Cropper(this.$.image, options);
}
});
</script>
</dom-module>