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
|
var View = wp.media.View,
$ = jQuery,
SiteIconPreview;
/**
* wp.media.view.SiteIconPreview
*
* Shows a preview of the Site Icon as a favicon and app icon while cropping.
*
* @memberOf wp.media.view
*
* @class
* @augments wp.media.View
* @augments wp.Backbone.View
* @augments Backbone.View
*/
SiteIconPreview = View.extend(/** @lends wp.media.view.SiteIconPreview.prototype */{
className: 'site-icon-preview-crop-modal',
template: wp.template( 'site-icon-preview-crop' ),
ready: function() {
this.controller.imgSelect.setOptions({
onInit: this.updatePreview,
onSelectChange: this.updatePreview
});
},
prepare: function() {
return {
url: this.options.attachment.get( 'url' )
};
},
updatePreview: function( img, coords ) {
var rx = 64 / coords.width,
ry = 64 / coords.height,
preview_rx = 24 / coords.width,
preview_ry = 24 / coords.height;
$( '#preview-app-icon' ).css({
width: Math.round(rx * this.imageWidth ) + 'px',
height: Math.round(ry * this.imageHeight ) + 'px',
marginLeft: '-' + Math.round(rx * coords.x1) + 'px',
marginTop: '-' + Math.round(ry * coords.y1) + 'px'
});
$( '#preview-favicon' ).css({
width: Math.round( preview_rx * this.imageWidth ) + 'px',
height: Math.round( preview_ry * this.imageHeight ) + 'px',
marginLeft: '-' + Math.round( preview_rx * coords.x1 ) + 'px',
marginTop: '-' + Math.floor( preview_ry* coords.y1 ) + 'px'
});
}
});
module.exports = SiteIconPreview;
|