2020-10-19 19:59:54 +02:00
|
|
|
|
class CropEditor {
|
|
|
|
|
constructor(opt) {
|
|
|
|
|
this.opt = opt;
|
|
|
|
|
|
|
|
|
|
this.edit_crop_button = document.createElement("span");
|
2023-03-11 14:31:44 +01:00
|
|
|
|
this.edit_crop_button.className = "btn btn-light";
|
2020-10-19 19:59:54 +02:00
|
|
|
|
this.edit_crop_button.textContent = "Edit crop";
|
|
|
|
|
this.edit_crop_button.addEventListener('click', this.show.bind(this));
|
|
|
|
|
|
|
|
|
|
this.thumbnail_select = document.getElementById(opt.thumbnail_select_id);
|
|
|
|
|
this.thumbnail_select.addEventListener('change', this.toggleCropButton.bind(this));
|
|
|
|
|
this.thumbnail_select.parentNode.insertBefore(this.edit_crop_button, this.thumbnail_select.nextSibling);
|
|
|
|
|
|
|
|
|
|
this.toggleCropButton();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-23 12:42:02 +01:00
|
|
|
|
initDOM() {
|
2020-10-19 19:59:54 +02:00
|
|
|
|
this.container = document.createElement("div");
|
|
|
|
|
this.container.id = "crop_editor";
|
|
|
|
|
|
2020-11-23 12:42:02 +01:00
|
|
|
|
this.initPositionForm();
|
|
|
|
|
this.initImageContainer();
|
|
|
|
|
|
|
|
|
|
this.parent = document.getElementById(this.opt.editor_container_parent_id);
|
|
|
|
|
this.parent.appendChild(this.container);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initPositionForm() {
|
2020-11-23 12:22:05 +01:00
|
|
|
|
this.position = document.createElement("fieldset");
|
2020-10-19 19:59:54 +02:00
|
|
|
|
this.position.className = "crop_position";
|
|
|
|
|
this.container.appendChild(this.position);
|
|
|
|
|
|
|
|
|
|
let source_x_label = document.createTextNode("Source X:");
|
|
|
|
|
this.position.appendChild(source_x_label);
|
|
|
|
|
|
|
|
|
|
this.source_x = document.createElement("input");
|
2023-03-11 14:31:44 +01:00
|
|
|
|
this.source_x.className = 'form-control d-inline';
|
2020-11-29 17:28:52 +01:00
|
|
|
|
this.source_x.type = 'number';
|
|
|
|
|
this.source_x.addEventListener("change", this.positionBoundary.bind(this));
|
2020-10-19 19:59:54 +02:00
|
|
|
|
this.source_x.addEventListener("keyup", this.positionBoundary.bind(this));
|
|
|
|
|
this.position.appendChild(this.source_x);
|
|
|
|
|
|
|
|
|
|
let source_y_label = document.createTextNode("Source Y:");
|
|
|
|
|
this.position.appendChild(source_y_label);
|
|
|
|
|
|
|
|
|
|
this.source_y = document.createElement("input");
|
2023-03-11 14:31:44 +01:00
|
|
|
|
this.source_y.className = 'form-control d-inline';
|
2020-11-29 17:28:52 +01:00
|
|
|
|
this.source_y.type = 'number';
|
|
|
|
|
this.source_y.addEventListener("change", this.positionBoundary.bind(this));
|
2020-10-19 19:59:54 +02:00
|
|
|
|
this.source_y.addEventListener("keyup", this.positionBoundary.bind(this));
|
|
|
|
|
this.position.appendChild(this.source_y);
|
|
|
|
|
|
|
|
|
|
let crop_width_label = document.createTextNode("Crop width:");
|
|
|
|
|
this.position.appendChild(crop_width_label);
|
|
|
|
|
|
|
|
|
|
this.crop_width = document.createElement("input");
|
2023-03-11 14:31:44 +01:00
|
|
|
|
this.crop_width.className = 'form-control d-inline';
|
2020-11-29 17:28:52 +01:00
|
|
|
|
this.crop_width.type = 'number';
|
|
|
|
|
this.crop_width.addEventListener("change", this.positionBoundary.bind(this));
|
2020-10-19 19:59:54 +02:00
|
|
|
|
this.crop_width.addEventListener("keyup", this.positionBoundary.bind(this));
|
|
|
|
|
this.position.appendChild(this.crop_width);
|
|
|
|
|
|
|
|
|
|
let crop_height_label = document.createTextNode("Crop height:");
|
|
|
|
|
this.position.appendChild(crop_height_label);
|
|
|
|
|
|
|
|
|
|
this.crop_height = document.createElement("input");
|
2023-03-11 14:31:44 +01:00
|
|
|
|
this.crop_height.className = 'form-control d-inline';
|
2020-11-29 17:28:52 +01:00
|
|
|
|
this.crop_height.type = 'number';
|
|
|
|
|
this.crop_height.addEventListener("change", this.positionBoundary.bind(this));
|
2020-10-19 19:59:54 +02:00
|
|
|
|
this.crop_height.addEventListener("keyup", this.positionBoundary.bind(this));
|
|
|
|
|
this.position.appendChild(this.crop_height);
|
|
|
|
|
|
2020-12-17 13:05:24 +01:00
|
|
|
|
this.crop_constrain_label = document.createElement("label");
|
|
|
|
|
this.position.appendChild(this.crop_constrain_label);
|
|
|
|
|
|
|
|
|
|
this.crop_constrain = document.createElement("input");
|
|
|
|
|
this.crop_constrain.checked = true;
|
|
|
|
|
this.crop_constrain.type = 'checkbox';
|
|
|
|
|
this.crop_constrain_label.appendChild(this.crop_constrain);
|
|
|
|
|
|
|
|
|
|
this.crop_constrain_text = document.createTextNode('Constrain proportions');
|
|
|
|
|
this.crop_constrain_label.appendChild(this.crop_constrain_text);
|
|
|
|
|
|
2020-10-19 19:59:54 +02:00
|
|
|
|
this.save_button = document.createElement("span");
|
2023-03-11 14:31:44 +01:00
|
|
|
|
this.save_button.className = "btn btn-light";
|
2020-10-19 19:59:54 +02:00
|
|
|
|
this.save_button.textContent = "Save";
|
|
|
|
|
this.save_button.addEventListener('click', this.save.bind(this));
|
|
|
|
|
this.position.appendChild(this.save_button);
|
|
|
|
|
|
|
|
|
|
this.abort_button = document.createElement("span");
|
2023-03-11 14:31:44 +01:00
|
|
|
|
this.abort_button.className = "btn btn-danger";
|
2020-10-19 19:59:54 +02:00
|
|
|
|
this.abort_button.textContent = "Abort";
|
|
|
|
|
this.abort_button.addEventListener('click', this.hide.bind(this));
|
|
|
|
|
this.position.appendChild(this.abort_button);
|
2020-11-23 12:42:02 +01:00
|
|
|
|
}
|
2020-10-19 19:59:54 +02:00
|
|
|
|
|
2020-11-23 12:42:02 +01:00
|
|
|
|
initImageContainer() {
|
2020-10-19 19:59:54 +02:00
|
|
|
|
this.image_container = document.createElement("div");
|
|
|
|
|
this.image_container.className = "crop_image_container";
|
|
|
|
|
this.container.appendChild(this.image_container);
|
|
|
|
|
|
|
|
|
|
this.crop_boundary = document.createElement("div");
|
|
|
|
|
this.crop_boundary.id = "crop_boundary";
|
|
|
|
|
this.image_container.appendChild(this.crop_boundary);
|
|
|
|
|
|
|
|
|
|
this.original_image = document.createElement("img");
|
2020-11-23 12:35:42 +01:00
|
|
|
|
this.original_image.draggable = false;
|
2020-10-19 19:59:54 +02:00
|
|
|
|
this.original_image.id = "original_image";
|
|
|
|
|
this.original_image.src = this.opt.original_image_src;
|
|
|
|
|
this.image_container.appendChild(this.original_image);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-23 17:52:54 +01:00
|
|
|
|
setDefaultCrop(cropAspectRatio, cropMethod) {
|
|
|
|
|
let source = this.original_image;
|
|
|
|
|
let sourceAspectRatio = source.naturalWidth / source.naturalHeight;
|
|
|
|
|
|
|
|
|
|
// Cropping from the centre?
|
2020-12-17 11:56:38 +01:00
|
|
|
|
if (cropMethod === "c" || cropMethod === "s") {
|
2020-11-23 17:52:54 +01:00
|
|
|
|
// Crop vertically from the centre, using the entire width.
|
2020-11-24 11:33:16 +01:00
|
|
|
|
if (sourceAspectRatio <= cropAspectRatio) {
|
2020-11-23 17:52:54 +01:00
|
|
|
|
this.crop_width.value = source.naturalWidth;
|
|
|
|
|
this.crop_height.value = Math.ceil(source.naturalWidth / cropAspectRatio);
|
|
|
|
|
this.source_x.value = 0;
|
|
|
|
|
this.source_y.value = Math.ceil((source.naturalHeight - this.crop_height.value) / 2);
|
|
|
|
|
}
|
|
|
|
|
// Crop horizontally from the centre, using the entire height.
|
|
|
|
|
else {
|
|
|
|
|
this.crop_width.value = Math.ceil(cropAspectRatio * source.naturalHeight);
|
|
|
|
|
this.crop_height.value = source.naturalHeight;
|
|
|
|
|
this.source_x.value = Math.ceil((source.naturalWidth - this.crop_width.value) / 2);
|
|
|
|
|
this.source_y.value = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Cropping a top or bottom slice?
|
|
|
|
|
else {
|
|
|
|
|
// Can we actually take a top or bottom slice from the original image?
|
2020-11-24 11:33:16 +01:00
|
|
|
|
if (sourceAspectRatio <= cropAspectRatio) {
|
2020-11-23 17:52:54 +01:00
|
|
|
|
this.crop_width.value = source.naturalWidth;
|
2020-11-24 11:33:16 +01:00
|
|
|
|
this.crop_height.value = Math.floor(source.naturalWidth / cropAspectRatio);
|
2020-11-23 17:52:54 +01:00
|
|
|
|
this.source_x.value = "0";
|
|
|
|
|
this.source_y.value = cropMethod.indexOf("t") !== -1 ? "0" : source.naturalHeight - this.crop_height.value;
|
2016-09-01 23:13:23 +02:00
|
|
|
|
}
|
2020-11-23 17:52:54 +01:00
|
|
|
|
// Otherwise, take a vertical slice from the centre.
|
2016-09-01 23:13:23 +02:00
|
|
|
|
else {
|
2020-11-23 17:52:54 +01:00
|
|
|
|
this.crop_width.value = Math.floor(source.naturalHeight * cropAspectRatio);
|
|
|
|
|
this.crop_height.value = source.naturalHeight;
|
|
|
|
|
this.source_x.value = Math.floor((source.naturalWidth - this.crop_width.value) / 2);
|
|
|
|
|
this.source_y.value = "0";
|
2016-09-01 23:13:23 +02:00
|
|
|
|
}
|
2020-11-23 17:52:54 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setPositionFormValues() {
|
|
|
|
|
let current = this.thumbnail_select.options[this.thumbnail_select.selectedIndex].dataset;
|
|
|
|
|
|
|
|
|
|
if (typeof current.crop_region === "undefined") {
|
|
|
|
|
let aspectRatio = current.crop_width / current.crop_height;
|
|
|
|
|
this.setDefaultCrop(aspectRatio, current.crop_method);
|
2020-10-19 19:59:54 +02:00
|
|
|
|
} else {
|
|
|
|
|
let region = current.crop_region.split(',');
|
|
|
|
|
this.crop_width.value = region[0];
|
|
|
|
|
this.crop_height.value = region[1];
|
|
|
|
|
this.source_x.value = region[2];
|
|
|
|
|
this.source_y.value = region[3];
|
2016-09-01 23:13:23 +02:00
|
|
|
|
}
|
2020-11-29 17:28:52 +01:00
|
|
|
|
|
|
|
|
|
this.crop_width.min = 1;
|
|
|
|
|
this.crop_height.min = 1;
|
|
|
|
|
this.source_x.min = 0;
|
|
|
|
|
this.source_y.min = 0;
|
|
|
|
|
|
|
|
|
|
let source = this.original_image;
|
|
|
|
|
this.crop_width.max = source.naturalWidth;
|
|
|
|
|
this.crop_height.max = source.naturalHeight;
|
|
|
|
|
this.source_x.max = source.naturalWidth - 1;
|
|
|
|
|
this.source_y.max = source.naturalHeight - 1;
|
2020-12-17 13:05:24 +01:00
|
|
|
|
|
|
|
|
|
this.crop_constrain_text.textContent = `Constrain proportions (${current.crop_width} × ${current.crop_height})`;
|
2016-09-01 23:13:23 +02:00
|
|
|
|
}
|
2020-10-19 19:59:54 +02:00
|
|
|
|
|
|
|
|
|
showContainer() {
|
2020-11-23 12:35:20 +01:00
|
|
|
|
this.container.style.display = '';
|
2020-11-23 17:52:54 +01:00
|
|
|
|
this.setPositionFormValues();
|
2020-10-19 19:59:54 +02:00
|
|
|
|
this.positionBoundary();
|
2020-11-23 12:35:42 +01:00
|
|
|
|
this.addEvents();
|
2020-10-19 19:59:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
save() {
|
|
|
|
|
let current = this.thumbnail_select.options[this.thumbnail_select.selectedIndex].dataset;
|
|
|
|
|
let payload = {
|
|
|
|
|
thumb_width: current.crop_width,
|
|
|
|
|
thumb_height: current.crop_height,
|
|
|
|
|
crop_method: current.crop_method,
|
|
|
|
|
crop_width: this.crop_width.value,
|
|
|
|
|
crop_height: this.crop_height.value,
|
|
|
|
|
source_x: this.source_x.value,
|
|
|
|
|
source_y: this.source_y.value
|
|
|
|
|
};
|
|
|
|
|
let req = HttpRequest("post", this.opt.submitUrl + "?id=" + this.opt.asset_id + "&updatethumb",
|
|
|
|
|
"data=" + encodeURIComponent(JSON.stringify(payload)), function(response) {
|
|
|
|
|
this.opt.after_save(response);
|
|
|
|
|
this.hide();
|
|
|
|
|
}.bind(this));
|
2016-09-01 23:13:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-19 19:59:54 +02:00
|
|
|
|
show() {
|
|
|
|
|
if (typeof this.container === "undefined") {
|
2020-11-23 12:42:02 +01:00
|
|
|
|
this.initDOM();
|
2020-10-19 19:59:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Defer showing and positioning until image is loaded.
|
|
|
|
|
// !!! TODO: add a spinner in the mean time?
|
|
|
|
|
if (this.original_image.naturalWidth > 0) {
|
2016-09-01 23:13:23 +02:00
|
|
|
|
this.showContainer();
|
2020-10-19 19:59:54 +02:00
|
|
|
|
} else {
|
2020-11-23 12:42:02 +01:00
|
|
|
|
this.original_image.addEventListener("load", event => this.showContainer());
|
2020-10-19 19:59:54 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hide() {
|
|
|
|
|
this.container.style.display = "none";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addEvents(event) {
|
2020-11-23 20:36:46 +01:00
|
|
|
|
let cropTarget = this.image_container;
|
|
|
|
|
cropTarget.addEventListener('mousedown', this.cropSelectionStart.bind(this));
|
|
|
|
|
cropTarget.addEventListener('mousemove', this.cropSelection.bind(this));
|
|
|
|
|
cropTarget.addEventListener('mouseup', this.cropSelectionEnd.bind(this));
|
|
|
|
|
// cropTarget.addEventListener('mouseout', this.cropSelectionEnd.bind(this));
|
2020-11-23 12:35:42 +01:00
|
|
|
|
|
|
|
|
|
this.original_image.addEventListener('mousedown', event => {return false});
|
2020-11-23 18:13:38 +01:00
|
|
|
|
this.original_image.addEventListener('dragstart', event => {return false});
|
2020-11-23 20:36:46 +01:00
|
|
|
|
|
|
|
|
|
let moveTarget = this.crop_boundary;
|
|
|
|
|
moveTarget.addEventListener('mousedown', this.moveSelectionStart.bind(this));
|
|
|
|
|
moveTarget.addEventListener('mousemove', this.moveSelection.bind(this));
|
|
|
|
|
moveTarget.addEventListener('mouseup', this.moveSelectionEnd.bind(this));
|
2020-12-17 12:56:41 +01:00
|
|
|
|
|
|
|
|
|
window.addEventListener('resize', this.positionBoundary.bind(this));
|
2020-10-19 19:59:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-23 20:36:46 +01:00
|
|
|
|
cropSelectionStart(event) {
|
|
|
|
|
if (this.isMoving) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-12-06 18:21:29 +01:00
|
|
|
|
|
|
|
|
|
let dragStartX = event.x - this.image_container.offsetLeft;
|
|
|
|
|
let dragStartY = event.y - this.image_container.offsetTop;
|
|
|
|
|
|
|
|
|
|
if (dragStartX > this.original_image.clientWidth ||
|
|
|
|
|
dragStartY > this.original_image.clientHeight) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-23 12:35:42 +01:00
|
|
|
|
this.isDragging = true;
|
2020-12-06 18:21:29 +01:00
|
|
|
|
this.dragStartX = dragStartX;
|
|
|
|
|
this.dragStartY = dragStartY;
|
2020-10-19 19:59:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-23 20:36:46 +01:00
|
|
|
|
cropSelectionEnd(event) {
|
2020-11-23 12:35:42 +01:00
|
|
|
|
this.isDragging = false;
|
2020-11-23 20:36:46 +01:00
|
|
|
|
this.handleCropSelectionEvent(event);
|
2020-10-19 19:59:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-23 20:36:46 +01:00
|
|
|
|
cropSelection(event) {
|
|
|
|
|
this.handleCropSelectionEvent(event);
|
2020-11-23 18:13:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getScaleFactor() {
|
2020-11-23 19:00:42 +01:00
|
|
|
|
return this.original_image.naturalWidth / this.original_image.clientWidth;
|
2020-11-23 18:13:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-23 20:36:46 +01:00
|
|
|
|
handleCropSelectionEvent(event) {
|
2020-11-23 18:13:38 +01:00
|
|
|
|
if (!this.isDragging) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-23 19:00:42 +01:00
|
|
|
|
this.dragEndX = event.x - this.image_container.offsetLeft;
|
|
|
|
|
this.dragEndY = event.y - this.image_container.offsetTop;
|
2020-11-23 18:13:38 +01:00
|
|
|
|
|
|
|
|
|
let scaleFactor = this.getScaleFactor();
|
|
|
|
|
|
2020-11-23 19:00:42 +01:00
|
|
|
|
this.source_x.value = Math.ceil(Math.min(this.dragStartX, this.dragEndX) * scaleFactor);
|
|
|
|
|
this.source_y.value = Math.ceil(Math.min(this.dragStartY, this.dragEndY) * scaleFactor);
|
2020-11-23 20:20:37 +01:00
|
|
|
|
|
|
|
|
|
let width = Math.ceil(Math.abs(this.dragEndX - this.dragStartX) * scaleFactor);
|
|
|
|
|
this.crop_width.value = Math.min(width, this.original_image.naturalWidth - this.source_x.value);
|
|
|
|
|
|
|
|
|
|
let height = Math.ceil(Math.abs(this.dragEndY - this.dragStartY) * scaleFactor);
|
|
|
|
|
this.crop_height.value = Math.min(height, this.original_image.naturalHeight - this.source_y.value);
|
2020-11-23 18:13:38 +01:00
|
|
|
|
|
2020-12-17 13:05:24 +01:00
|
|
|
|
if (this.crop_constrain.checked) {
|
|
|
|
|
let current = this.thumbnail_select.options[this.thumbnail_select.selectedIndex].dataset;
|
|
|
|
|
|
|
|
|
|
let currentAspectRatio = parseInt(this.crop_width.value) / parseInt(this.crop_height.value);
|
|
|
|
|
let targetAspectRatio = current.crop_width / current.crop_height;
|
|
|
|
|
|
|
|
|
|
if (Math.abs(currentAspectRatio - targetAspectRatio) > 0.001) {
|
2020-12-30 12:56:17 +01:00
|
|
|
|
// Landscape?
|
2020-12-17 13:05:24 +01:00
|
|
|
|
if (targetAspectRatio > 1.0) {
|
2020-12-30 12:56:17 +01:00
|
|
|
|
let height = Math.ceil(this.crop_width.value / targetAspectRatio);
|
|
|
|
|
if (parseInt(this.source_y.value) + height > this.original_image.naturalHeight) {
|
|
|
|
|
height = this.original_image.naturalHeight - this.source_y.value;
|
|
|
|
|
}
|
|
|
|
|
this.crop_width.value = height * targetAspectRatio;
|
|
|
|
|
this.crop_height.value = height;
|
|
|
|
|
}
|
|
|
|
|
// Portrait?
|
|
|
|
|
else {
|
|
|
|
|
let width = Math.ceil(this.crop_height.value * targetAspectRatio);
|
|
|
|
|
if (parseInt(this.source_x.value) + width > this.original_image.naturalWidth) {
|
|
|
|
|
width = this.original_image.naturalWidth - this.source_x.value;
|
|
|
|
|
}
|
|
|
|
|
this.crop_width.value = width;
|
|
|
|
|
this.crop_height.value = width / targetAspectRatio;
|
2020-12-17 13:05:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-23 18:13:38 +01:00
|
|
|
|
this.positionBoundary();
|
2020-10-19 19:59:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-23 20:36:46 +01:00
|
|
|
|
handleCropMoveEvent(event) {
|
|
|
|
|
if (!this.isMoving) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.dragEndX = event.x - this.crop_boundary.offsetLeft;
|
|
|
|
|
this.dragEndY = event.y - this.crop_boundary.offsetTop;
|
|
|
|
|
|
|
|
|
|
let scaleFactor = this.getScaleFactor();
|
|
|
|
|
|
2020-11-23 20:46:13 +01:00
|
|
|
|
let x = parseInt(this.source_x.value) + Math.ceil((this.dragEndX - this.dragStartX) * scaleFactor);
|
|
|
|
|
if (x + parseInt(this.crop_width.value) > this.original_image.naturalWidth) {
|
|
|
|
|
x += this.original_image.naturalWidth - (x + parseInt(this.crop_width.value));
|
|
|
|
|
}
|
|
|
|
|
this.source_x.value = Math.max(x, 0);
|
2020-11-23 20:36:46 +01:00
|
|
|
|
|
2020-11-23 20:46:13 +01:00
|
|
|
|
let y = parseInt(this.source_y.value) + Math.ceil((this.dragEndY - this.dragStartY) * scaleFactor);
|
|
|
|
|
if (y + parseInt(this.crop_height.value) > this.original_image.naturalHeight) {
|
|
|
|
|
y += this.original_image.naturalHeight - (y + parseInt(this.crop_height.value));
|
|
|
|
|
}
|
|
|
|
|
this.source_y.value = Math.max(y, 0);
|
2020-11-23 20:36:46 +01:00
|
|
|
|
|
|
|
|
|
this.positionBoundary();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
moveSelectionStart(event) {
|
|
|
|
|
if (this.isDragging) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
this.isMoving = true;
|
|
|
|
|
this.dragStartX = event.x - this.crop_boundary.offsetLeft;
|
|
|
|
|
this.dragStartY = event.y - this.crop_boundary.offsetTop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
moveSelectionEnd(event) {
|
|
|
|
|
this.isMoving = false;
|
|
|
|
|
this.handleCropMoveEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
moveSelection(event) {
|
|
|
|
|
this.handleCropMoveEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-19 19:59:54 +02:00
|
|
|
|
toggleCropButton() {
|
|
|
|
|
let current = this.thumbnail_select.options[this.thumbnail_select.selectedIndex].dataset;
|
|
|
|
|
this.edit_crop_button.style.display = typeof current.crop_method === "undefined" ? "none" : "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
positionBoundary(event) {
|
2020-11-23 18:13:57 +01:00
|
|
|
|
let scaleFactor = this.getScaleFactor();
|
2020-11-23 19:00:42 +01:00
|
|
|
|
crop_boundary.style.left = parseInt(this.source_x.value) / scaleFactor + "px";
|
|
|
|
|
crop_boundary.style.top = parseInt(this.source_y.value) / scaleFactor + "px";
|
|
|
|
|
crop_boundary.style.width = parseInt(this.crop_width.value) / scaleFactor + "px";
|
|
|
|
|
crop_boundary.style.height = parseInt(this.crop_height.value) / scaleFactor + "px";
|
2016-09-01 23:13:23 +02:00
|
|
|
|
}
|
2020-11-23 12:22:05 +01:00
|
|
|
|
}
|