in public/data/asset/data/draggable.js [23:149]
init: function (mainEl, chart, opt) {
opt = opt || {};
var chartResize = chart ? $.proxy(chart.resize, chart) : function () {};
if (opt.throttle) {
chartResize = throttle(chartResize, opt.throttle, true, false);
}
var mainEl = $(mainEl);
$('.draggable-control').remove();
var controlEl = $(
'<div class="draggable-control">DRAG<span class="draggable-label"></span></div>'
);
controlEl.css({
'position': 'absolute',
'border-radius': '30px',
'width': '60px',
'height': '60px',
'line-height': '60px',
'text-align': 'center',
'background': '#333',
'color': '#fff',
'cursor': 'pointer',
'font-size': '18px',
'box-shadow': '0 0 5px #333',
'-webkit-user-select': 'none',
'user-select': 'none'
});
var label = controlEl.find('.draggable-label');
label.css({
'display': 'block',
'position': 'absolute',
'color': '#000',
'font-size': '12px',
'text-align': 'center',
'left': 0,
'top': '65px',
'width': '60px',
'line-height': 1
});
mainEl.css({
'position': 'absolute',
'left': mainEl[0].offsetLeft + 'px',
'top': mainEl[0].offsetTop + 'px',
'width': mainEl[0].offsetWidth + 'px',
'height': mainEl[0].offsetHeight + 'px',
'border-style': 'solid',
'border-color': '#ddd',
'border-width': BORDER_WIDTH + 'px',
'padding': 0,
'margin': 0
});
mainEl.parent().append(controlEl);
var controlSize = controlEl[0].offsetWidth;
var boxSizing = mainEl.css('box-sizing');
var borderBoxBroder = boxSizing === 'border-box' ? 2 * BORDER_WIDTH : 0;
var mainContentWidth = opt.width || (mainEl.width() + borderBoxBroder);
var mainContentHeight = opt.height || (mainEl.height() + borderBoxBroder);
var mainOffset = mainEl.offset();
resize(
mainOffset.left + mainContentWidth + BORDER_WIDTH,
mainOffset.top + mainContentHeight + BORDER_WIDTH,
true
);
var dragging = false;
controlEl.on('mousedown', function () {
dragging = true;
});
$(document).on('mousemove', function (e) {
if (dragging) {
resize(e.pageX, e.pageY);
}
});
$(document).on('mouseup', function () {
dragging = false;
});
function resize(x, y, isInit) {
var mainOffset = mainEl.offset();
var mainPosition = mainEl.position();
var mainContentWidth = x - mainOffset.left - BORDER_WIDTH;
var mainContentHeight = y - mainOffset.top - BORDER_WIDTH;
if (isInit || !opt.lockX) {
controlEl.css(
'left',
(mainPosition.left + mainContentWidth + BORDER_WIDTH - controlSize / 2) + 'px'
);
mainEl.css(
'width',
(mainContentWidth + borderBoxBroder) + 'px'
);
}
if (isInit || !opt.lockY) {
controlEl.css(
'top',
(mainPosition.top + mainContentHeight + BORDER_WIDTH - controlSize / 2) + 'px'
);
mainEl.css(
'height',
(mainContentHeight + borderBoxBroder) + 'px'
);
}
label.text(Math.round(mainContentWidth) + ' x ' + Math.round(mainContentHeight));
chartResize();
}
}