-
Notifications
You must be signed in to change notification settings - Fork 383
/
gridsterPreview.component.js
42 lines (37 loc) · 1.28 KB
/
gridsterPreview.component.js
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
(function () {
'use strict';
angular.module('angular-gridster2').component('gridsterPreview', {
controller: GridsterPreviewController,
require: {
gridster: '^^gridster'
}
});
/** @ngInject */
function GridsterPreviewController($element) {
var vm = this;
vm.$onInit = function () {
vm.gridster.previewStyle = vm.previewStyle.bind(vm);
};
vm.$onDestroy = function () {
delete vm.gridster.previewStyle;
};
vm.previewStyle = function () {
if (!vm.gridster.movingItem) {
$element.css('display', 'none');
} else {
var margin = 0;
var curRowHeight = vm.gridster.curRowHeight;
var curColWidth = vm.gridster.curColWidth;
if (vm.gridster.$options.outerMargin) {
margin = vm.gridster.$options.margin;
}
$element.css('display', 'block');
$element.css('height', (vm.gridster.movingItem.rows * curRowHeight - margin) + 'px');
$element.css('width', (vm.gridster.movingItem.cols * curColWidth - margin) + 'px');
$element.css('top', (vm.gridster.movingItem.y * curRowHeight + margin) + 'px');
$element.css('left', (vm.gridster.movingItem.x * curColWidth + margin) + 'px');
$element.css('marginBottom', margin + 'px');
}
}
}
})();