92 lines
13 KiB
JavaScript
92 lines
13 KiB
JavaScript
|
export class GridsterUtils {
|
||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||
|
static merge(obj1, obj2, properties) {
|
||
|
for (const p in obj2) {
|
||
|
if (obj2[p] !== void 0 && properties.hasOwnProperty(p)) {
|
||
|
if (typeof obj2[p] === 'object') {
|
||
|
// create an empty object for the property if obj1 does not already have one.
|
||
|
if (!(p in obj1)) {
|
||
|
obj1[p] = {};
|
||
|
}
|
||
|
obj1[p] = GridsterUtils.merge(obj1[p], obj2[p], properties[p]);
|
||
|
}
|
||
|
else {
|
||
|
obj1[p] = obj2[p];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return obj1;
|
||
|
}
|
||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||
|
static checkTouchEvent(e) {
|
||
|
if (e.clientX === undefined && e.touches) {
|
||
|
if (e.touches && e.touches.length) {
|
||
|
e.clientX = e.touches[0].clientX;
|
||
|
e.clientY = e.touches[0].clientY;
|
||
|
}
|
||
|
else if (e.changedTouches && e.changedTouches.length) {
|
||
|
e.clientX = e.changedTouches[0].clientX;
|
||
|
e.clientY = e.changedTouches[0].clientY;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
static checkContentClassForEvent(gridster, e) {
|
||
|
if (gridster.$options.draggable.ignoreContent) {
|
||
|
if (!GridsterUtils.checkDragHandleClass(e.target, e.currentTarget, gridster.$options.draggable.dragHandleClass, gridster.$options.draggable.ignoreContentClass)) {
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
if (GridsterUtils.checkContentClass(e.target, e.currentTarget, gridster.$options.draggable.ignoreContentClass)) {
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
static checkContentClassForEmptyCellClickEvent(gridster, e) {
|
||
|
return (GridsterUtils.checkContentClass(e.target, e.currentTarget, gridster.$options.draggable.ignoreContentClass) ||
|
||
|
GridsterUtils.checkContentClass(e.target, e.currentTarget, gridster.$options.draggable.dragHandleClass));
|
||
|
}
|
||
|
static checkDragHandleClass(target, current, dragHandleClass, ignoreContentClass) {
|
||
|
if (!target || target === current) {
|
||
|
return false;
|
||
|
}
|
||
|
if (target.hasAttribute('class')) {
|
||
|
const classnames = target.getAttribute('class').split(' ');
|
||
|
if (classnames.indexOf(dragHandleClass) > -1) {
|
||
|
return true;
|
||
|
}
|
||
|
if (classnames.indexOf(ignoreContentClass) > -1) {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
return GridsterUtils.checkDragHandleClass(target.parentNode, current, dragHandleClass, ignoreContentClass);
|
||
|
}
|
||
|
static checkContentClass(target, current, contentClass) {
|
||
|
if (!target || target === current) {
|
||
|
return false;
|
||
|
}
|
||
|
if (target.hasAttribute('class') &&
|
||
|
target.getAttribute('class').split(' ').indexOf(contentClass) > -1) {
|
||
|
return true;
|
||
|
}
|
||
|
else {
|
||
|
return GridsterUtils.checkContentClass(target.parentNode, current, contentClass);
|
||
|
}
|
||
|
}
|
||
|
static compareItems(a, b) {
|
||
|
if (a.y > b.y) {
|
||
|
return -1;
|
||
|
}
|
||
|
else if (a.y < b.y) {
|
||
|
return 1;
|
||
|
}
|
||
|
else if (a.x > b.x) {
|
||
|
return -1;
|
||
|
}
|
||
|
else {
|
||
|
return 1;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ3JpZHN0ZXJVdGlscy5zZXJ2aWNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vcHJvamVjdHMvYW5ndWxhci1ncmlkc3RlcjIvc3JjL2xpYi9ncmlkc3RlclV0aWxzLnNlcnZpY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsTUFBTSxPQUFPLGFBQWE7SUFDeEIsOERBQThEO0lBQzlELE1BQU0sQ0FBQyxLQUFL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