2015-06-06 23:44:42 +02:00
|
|
|
$(function () {
|
|
|
|
var dragging
|
|
|
|
|
|
|
|
var lastx
|
|
|
|
var lasty
|
|
|
|
|
2015-06-07 00:20:47 +02:00
|
|
|
$(document).on('dblclick', '.dragresize', function (e) {
|
|
|
|
var target = $(e.target)
|
|
|
|
target.toggleClass('full')
|
|
|
|
if (target.hasClass('full')) {
|
|
|
|
target.addClass('dragged')
|
|
|
|
target.width(e.target.naturalWidth)
|
|
|
|
target.height(e.target.naturalHeight)
|
|
|
|
} else {
|
|
|
|
target.removeClass('dragged')
|
|
|
|
target.width('auto')
|
|
|
|
target.height('auto')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2015-06-06 23:44:42 +02:00
|
|
|
$(document).on('mousedown', '.dragresize', function(e) {
|
2015-06-07 00:20:47 +02:00
|
|
|
if (event.which != 1) {
|
|
|
|
return
|
|
|
|
}
|
2015-06-06 23:44:42 +02:00
|
|
|
dragging = $(e.target)
|
|
|
|
dragging.addClass('dragging')
|
|
|
|
lastx = e.pageX
|
|
|
|
lasty = e.pageY
|
|
|
|
})
|
|
|
|
|
|
|
|
$(document).on('mousemove', function (e) {
|
|
|
|
if (!dragging) {
|
|
|
|
return
|
|
|
|
}
|
2015-06-07 00:20:47 +02:00
|
|
|
|
|
|
|
e.preventDefault();
|
2015-06-06 23:44:42 +02:00
|
|
|
var newx = e.pageX - lastx
|
|
|
|
var newy = e.pageY - lasty
|
|
|
|
|
2015-06-07 00:20:47 +02:00
|
|
|
|
2015-06-06 23:44:42 +02:00
|
|
|
var width = dragging.width()
|
|
|
|
var height = dragging.height()
|
|
|
|
|
|
|
|
dragging.addClass('dragged')
|
|
|
|
|
|
|
|
if (Math.abs(newx) > Math.abs(newy)) {
|
|
|
|
dragging.width(width + newx)
|
|
|
|
dragging.height('auto')
|
|
|
|
} else {
|
|
|
|
dragging.height(height + newy)
|
|
|
|
dragging.width('auto')
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lastx = e.pageX
|
|
|
|
lasty = e.pageY
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
$(document).on('mouseup', function (e) {
|
|
|
|
if (!dragging) {
|
|
|
|
return
|
|
|
|
}
|
2015-06-07 00:20:47 +02:00
|
|
|
if (event.which != 1) {
|
|
|
|
return
|
|
|
|
}
|
2015-06-06 23:44:42 +02:00
|
|
|
dragging.removeClass('dragging')
|
|
|
|
dragging = undefined
|
|
|
|
});
|
|
|
|
})
|