File size: 29,664 Bytes
52ae39e |
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 |
$(document).ready(function () {
// An object is being moved in the canvas
canvas.on('object:moving', function (e) {
e.target.hasControls = false;
centerLines(e);
if (cropping) {
if (
canvas.getItemById('crop').isContainedWithinObject(cropobj)
) {
cropleft = canvas.getItemById('crop').get('left');
croptop = canvas.getItemById('crop').get('top');
cropscalex = canvas.getItemById('crop').get('scaleX');
cropscaley = canvas.getItemById('crop').get('scaleY');
}
crop(canvas.getItemById('cropped'));
} else if (
lockmovement &&
e.e.shiftKey &&
canvas.getActiveObject()
) {
if (canvasx < shiftx + 30 && canvasx > shiftx - 30) {
canvas.getActiveObject().set({ left: shiftx });
canvas.getActiveObject().lockMovementX = true;
canvas.getActiveObject().lockMovementY = false;
} else {
canvas.getActiveObject().set({ top: shifty });
canvas.getActiveObject().lockMovementX = false;
canvas.getActiveObject().lockMovementY = true;
}
} else if (canvas.getActiveObject() && !e.e.shiftKey) {
lockmovement = false;
canvas.getActiveObject().lockMovementX = false;
canvas.getActiveObject().lockMovementY = false;
}
});
// An object is being scaled in the canvas
canvas.on('object:scaling', function (e) {
e.target.hasControls = false;
centerLines(e);
if (cropping) {
if (
canvas.getItemById('crop').isContainedWithinObject(cropobj)
) {
cropleft = canvas.getItemById('crop').get('left');
croptop = canvas.getItemById('crop').get('top');
cropscalex = canvas.getItemById('crop').get('scaleX');
cropscaley = canvas.getItemById('crop').get('scaleY');
}
crop(canvas.getItemById('cropped'));
}
});
// An object is being resized in the canvas
canvas.on('object:resizing', function (e) {
e.target.hasControls = false;
centerLines(e);
if (cropping) {
if (
canvas.getItemById('crop').isContainedWithinObject(cropobj)
) {
cropleft = canvas.getItemById('crop').get('left');
croptop = canvas.getItemById('crop').get('top');
cropscalex = canvas.getItemById('crop').get('scaleX');
cropscaley = canvas.getItemById('crop').get('scaleY');
}
crop(canvas.getItemById('cropped'));
}
});
// An object is being rotated in the canvas
canvas.on('object:rotating', function (e) {
if (e.e.shiftKey) {
canvas.getActiveObject().snapAngle = 15;
} else {
canvas.getActiveObject().snapAngle = 0;
}
e.target.hasControls = false;
});
// An object has been modified in the canvas
canvas.on('object:modified', function (e) {
e.target.hasControls = true;
if (!editinggroup && !cropping) {
canvas.getActiveObject().lockMovementX = false;
canvas.getActiveObject().lockMovementY = false;
canvas.renderAll();
if (e.target.type == 'activeSelection') {
const tempselection = canvas.getActiveObject();
canvas.discardActiveObject();
e.target._objects.forEach(function (object) {
autoKeyframe(object, e, true);
});
reselect(tempselection);
} else {
autoKeyframe(e.target, e, false);
}
updatePanelValues();
save();
}
if (cropping) {
var obj = e.target;
checkCrop(obj);
}
});
// A selection has been updated in the canvas
canvas.on('selection:updated', function (e) {
updatePanel(true);
updatePanelValues();
updateSelection(e);
closeFilters();
});
// A selection has been made in the canvas
canvas.on('selection:created', function (e) {
shiftx = canvas.getActiveObject().get('left');
shifty = canvas.getActiveObject().get('top');
if (!editingpanel) {
updatePanel(true);
}
updateSelection(e);
canvas.renderAll();
closeFilters();
});
// A selection has been cleared in the canvas
canvas.on('selection:cleared', function (e) {
if (!editingpanel && !setting) {
updatePanel(false);
}
$('.layer-selected').removeClass('layer-selected');
if (cropping) {
crop(cropobj);
}
closeFilters();
});
function kFormatter(num) {
return Math.abs(num) > 999
? Math.sign(num) * (Math.abs(num) / 1000).toFixed(1) + 'k'
: Math.sign(num) * Math.abs(num);
}
// Zoom in/out of the canvas
canvas.on('mouse:wheel', function (opt) {
var delta = opt.e.deltaY;
var zoom = canvas.getZoom();
zoom *= 0.999 ** delta;
$('#zoom-level span').html(
kFormatter((zoom * 100).toFixed(0)) + '%'
);
if (zoom > 20) zoom = 20;
if (zoom < 0.01) zoom = 0.01;
canvas.zoomToPoint({ x: opt.e.offsetX, y: opt.e.offsetY }, zoom);
opt.e.preventDefault();
opt.e.stopPropagation();
});
// Start panning if space is down or hand tool is enabled
canvas.on('mouse:down', function (opt) {
var e = opt.e;
if (spaceDown || handtool) {
this.isDragging = true;
this.selection = false;
this.lastPosX = e.clientX;
this.lastPosY = e.clientY;
}
if (opt.target) {
opt.target.hasControls = true;
wip = false;
}
});
// Pan while dragging mouse
canvas.on('mouse:move', function (opt) {
var pointer = canvas.getPointer(opt.e);
canvasx = pointer.x;
canvasy = pointer.y;
if (this.isDragging) {
var e = opt.e;
var vpt = this.viewportTransform;
vpt[4] += e.clientX - this.lastPosX;
vpt[5] += e.clientY - this.lastPosY;
this.requestRenderAll();
this.lastPosX = e.clientX;
this.lastPosY = e.clientY;
}
});
// Stop panning
canvas.on('mouse:up', function (opt) {
this.setViewportTransform(this.viewportTransform);
this.isDragging = false;
this.selection = true;
line_h.opacity = 0;
line_v.opacity = 0;
});
// Detect mouse over canvas (for dragging objects from the library)
canvas.on('mouse:move', function (e) {
overCanvas = true;
if (
e.target &&
!canvas.getActiveObject() &&
draggingPanel &&
e.target.type == 'image'
) {
wip = true;
e.target.hasControls = false;
canvas.setActiveObject(e.target);
}
});
canvas.on('mouse:out', function (e) {
overCanvas = false;
if (wip) {
e.target.hasControls = true;
canvas.discardActiveObject();
wip = false;
canvas.renderAll();
}
});
// Double click on image to get into cropping mode
fabric.util.addListener(
canvas.upperCanvasEl,
'dblclick',
function (e) {
var target = canvas.findTarget(e);
if (target) {
if (target.type == 'image') {
cropImage(target);
}
}
}
);
// Key event handling
$(document)
.keyup(function (e) {
// Space bar (panning and playback)
if (
e.keyCode == 32 &&
!editinglayer &&
!editingproject &&
$(e.target)[0].tagName != 'INPUT'
) {
spacerelease = true;
spaceDown = false;
canvas.defaultCursor = 'default';
canvas.renderAll();
if (!spacehold) {
if (
!(
canvas.getActiveObject() &&
canvas.getActiveObject().isEditing
)
) {
if (paused) {
play();
} else {
pause();
}
}
} else {
if (!handtool) {
$('#hand-tool').removeClass('hand-active');
$('#hand-tool')
.find('img')
.attr('src', 'assets/hand-tool.svg');
}
}
spacehold = false;
}
// Delete object/keyframe
if (
(e.keyCode == 46 ||
e.key == 'Delete' ||
e.code == 'Delete' ||
e.key == 'Backspace') &&
!focus &&
!editinglayer
) {
if (
$('.show-properties').length > 0 ||
shiftkeys.length > 0
) {
deleteKeyframe();
} else {
deleteSelection();
}
}
// Shift key is up (stop locking horizontal/vertical object movement)
if (e.keyCode == 16) {
lockmovement = false;
shiftdown = false;
}
})
.keydown(function (e) {
// Space bar (panning and playback)
if (
e.keyCode == 32 &&
!editinglayer &&
!editingproject &&
$(e.target)[0].tagName != 'INPUT'
) {
spacerelease = false;
spaceDown = true;
canvas.defaultCursor = 'grab';
canvas.renderAll();
window.setTimeout(function () {
if (!spacerelease) {
spacehold = true;
if (!handtool) {
$('#hand-tool').addClass('hand-active');
$('#hand-tool')
.find('img')
.attr('src', 'assets/hand-tool-active.svg');
}
}
}, 1000);
}
// Redo
if (e.which === 90 && (e.ctrlKey || e.metaKey) && e.shiftKey) {
undoRedo(redo, undo, redoarr, undoarr);
}
// Undo
if (e.which === 90 && (e.ctrlKey || e.metaKey)) {
undoRedo(undo, redo, undoarr, redoarr);
}
// Duplicate object
if (e.which === 68 && (e.ctrlKey || e.metaKey)) {
e.preventDefault();
if (canvas.getActiveObject()) {
clipboard = canvas.getActiveObject();
copyObject();
}
}
// Shift key (Lock horizontal/vertical movement for objects)
if (e.shiftKey) {
shiftdown = true;
lockmovement = true;
if (canvas.getActiveObject()) {
shiftx = canvas.getActiveObject().get('left');
shifty = canvas.getActiveObject().get('top');
}
}
// Return (save layer name)
if (e.keyCode === 13 && editinglayer) {
saveLayerName();
}
// Return (save project name)
if (e.keyCode === 13 && editingproject) {
saveProjectName();
}
// Left arrow key (move object to the left)
if (e.keyCode === 37 && canvas.getActiveObject()) {
var obj = canvas.getActiveObject();
var step = 2;
// Bigger step if shift is down
if (e.shiftKey) {
step = 7;
}
obj.left = obj.left - step;
canvas.renderAll();
autoKeyframe(obj, { action: 'drag' }, false);
}
// Up arrow key (move object up)
if (e.keyCode === 38 && canvas.getActiveObject()) {
var obj = canvas.getActiveObject();
var step = 2;
// Bigger step if shift is down
if (e.shiftKey) {
step = 7;
}
obj.top = obj.top - step;
canvas.renderAll();
autoKeyframe(obj, { action: 'drag' }, false);
}
// Right arrow key (move object to the right)
if (e.keyCode === 39 && canvas.getActiveObject()) {
var obj = canvas.getActiveObject();
var step = 2;
// Bigger step if shift is down
if (e.shiftKey) {
step = 7;
}
obj.left = obj.left + step;
canvas.renderAll();
autoKeyframe(obj, { action: 'drag' }, false);
}
// Down arrow key (move object down)
if (e.keyCode === 40 && canvas.getActiveObject()) {
var obj = canvas.getActiveObject();
var step = 2;
// Bigger step if shift is down
if (e.shiftKey) {
step = 7;
}
obj.top = obj.top + step;
canvas.renderAll();
autoKeyframe(obj, { action: 'drag' }, false);
}
// Move object up layer list
if (
e.keyCode === 221 &&
canvas.getActiveObjects() &&
e.metaKey
) {
if (canvas.getActiveObjects().length == 1) {
var obj = canvas.getActiveObject();
$(".layer[data-object='" + obj.id + "']")
.prev()
.insertAfter($(".layer[data-object='" + obj.id + "']"));
$('#' + obj.id)
.prev()
.insertAfter($('#' + obj.id));
orderLayers();
} else {
canvas.getActiveObjects().forEach(function (obj) {
$(".layer[data-object='" + obj.id + "']")
.prev()
.insertAfter($(".layer[data-object='" + obj.id + "']"));
$('#' + obj.id)
.prev()
.insertAfter($('#' + obj.id));
orderLayers();
});
}
}
// Move object down layer list
if (
e.keyCode === 219 &&
canvas.getActiveObjects() &&
e.metaKey
) {
if (canvas.getActiveObjects().length == 1) {
var obj = canvas.getActiveObject();
$(".layer[data-object='" + obj.id + "']")
.next()
.insertBefore($(".layer[data-object='" + obj.id + "']"));
$('#' + obj.id)
.next()
.insertBefore($('#' + obj.id));
orderLayers();
} else {
canvas.getActiveObjects().forEach(function (obj) {
$(".layer[data-object='" + obj.id + "']")
.next()
.insertBefore(
$(".layer[data-object='" + obj.id + "']")
);
$('#' + obj.id)
.next()
.insertBefore($('#' + obj.id));
orderLayers();
});
}
}
// Move object top of layer list
if (
e.keyCode === 221 &&
canvas.getActiveObjects() &&
e.altKey
) {
if (canvas.getActiveObjects().length == 1) {
var obj = canvas.getActiveObject();
$('#layer-inner-list').prepend(
$(".layer[data-object='" + obj.id + "']")
);
$('#inner-timeline').prepend($('#' + obj.id));
orderLayers();
} else {
canvas.getActiveObjects().forEach(function (obj) {
$('#layer-inner-list').prepend(
$(".layer[data-object='" + obj.id + "']")
);
$('#inner-timeline').prepend($('#' + obj.id));
orderLayers();
});
}
}
// Move object bottom of layer list
if (e.keyCode === 219 && canvas.getActiveObject() && e.altKey) {
if (canvas.getActiveObjects().length == 1) {
var obj = canvas.getActiveObject();
$('#layer-inner-list').append(
$(".layer[data-object='" + obj.id + "']")
);
$('#inner-timeline').append($('#' + obj.id));
orderLayers();
} else {
canvas.getActiveObjects().forEach(function (obj) {
$('#layer-inner-list').append(
$(".layer[data-object='" + obj.id + "']")
);
$('#inner-timeline').append($('#' + obj.id));
orderLayers();
});
}
}
// Zoom in
if (e.keyCode === 187 && e.shiftKey) {
var zoom = canvas.getZoom() + 0.2;
if (zoom > 20) zoom = 20;
if (zoom < 0.01) zoom = 0.01;
canvas.setZoom(1);
canvas.renderAll();
var vpw = canvas.width / zoom;
var vph = canvas.height / zoom;
var x = artboard.left + artboard.width / 2 - vpw / 2;
var y = artboard.top + artboard.height / 2 - vph / 2;
canvas.absolutePan({ x: x, y: y });
canvas.setZoom(zoom);
canvas.renderAll();
$('#zoom-level span').html(
(canvas.getZoom() * 100).toFixed(0) + '%'
);
}
// Zoom out
if (e.keyCode === 189 && e.shiftKey) {
var zoom = canvas.getZoom() - 0.2;
if (zoom > 20) zoom = 20;
if (zoom < 0.01) zoom = 0.01;
canvas.setZoom(1);
canvas.renderAll();
var vpw = canvas.width / zoom;
var vph = canvas.height / zoom;
var x = artboard.left + artboard.width / 2 - vpw / 2;
var y = artboard.top + artboard.height / 2 - vph / 2;
canvas.absolutePan({ x: x, y: y });
canvas.setZoom(zoom);
canvas.renderAll();
$('#zoom-level span').html(
(canvas.getZoom() * 100).toFixed(0) + '%'
);
}
});
// Copy event
window.addEventListener('copy', function (e) {
// Copy selected object
if (
canvas.getActiveObject() &&
shiftkeys.length == 0 &&
!canvas.getActiveObject().isEditing
) {
var emptyInp = document.getElementById('emptyInput');
emptyInp.select();
emptyInp.focus();
setTimeout(function () {
document.execCommand('copy');
}, 0);
clipboard = canvas.getActiveObject();
cliptype = 'object';
// Copy selected keyframe(s)
} else if (
shiftkeys.length > 0 &&
!canvas.getActiveObject().isEditing
) {
var emptyInp = document.getElementById('emptyInput');
emptyInp.select();
emptyInp.focus();
setTimeout(function () {
document.execCommand('copy');
}, 0);
clipboard = [];
shiftkeys.forEach(function (keyframe) {
var drag = $(keyframe.keyframe);
var keyarr = $.grep(keyframes, function (e) {
return (
e.t == drag.attr('data-time') &&
e.id == drag.attr('data-object') &&
e.name == drag.attr('data-property')
);
});
clipboard.push(keyarr[0]);
});
cliptype = 'keyframe';
}
});
// Paste event
window.addEventListener('paste', function (e) {
var imgs = e.clipboardData.items;
if (imgs == undefined) return false;
// Paste object or keyframe(s)
if (imgs.length == 1 && e.clipboardData.getData('text') == ' ') {
copyObject();
// Paste external image (by uploading it)
} else {
for (var i = 0; i < imgs.length; i++) {
if (imgs[i].type.indexOf('image') == -1) continue;
var imgObj = imgs[i].getAsFile();
if (imgObj.size / 1024 / 1024 <= 10) {
createThumbnail(imgObj, 250).then(function (data) {
saveFile(
dataURItoBlob(data),
imgObj,
imgObj['type'].split('/')[0],
'temp',
true,
true
);
});
} else {
alert('Image is too big');
}
}
}
});
// Stop cropping when clicking on the blacked out properties panel
$(document).on('click', '#properties-overlay', function () {
if (cropping) {
canvas.discardActiveObject();
}
});
// Scroll horizontally through assets in the library
$(document).on('click', '.right-arrow', function () {
$(this).parent().animate({ scrollLeft: '+=1000' }, 500);
});
$(document).on('click', '.left-arrow', function () {
$(this).parent().animate({ scrollLeft: '-=1000' }, 500);
});
// Playback
$(document).on('click', '#play-button', function () {
if (paused) {
play();
} else {
pause();
}
});
// Detect when not clicking on certain elements
$(document).on('mousedown', function (e) {
// De-select keyframes
if (
!$('#keyframe-properties').is(e.target) &&
$('#keyframe-properties').has(e.target).length === 0 &&
!$('.keyframe').is(e.target) &&
$('.keyframe').has(e.target).length === 0
) {
$('#keyframe-properties').removeClass('show-properties');
$('.keyframe-selected').removeClass('keyframe-selected');
shiftkeys = [];
}
// Hide color picker
if (
!$('.object-color').is(e.target) &&
$('.object-color').has(e.target).length === 0 &&
!$('.pcr-app').is(e.target) &&
$('.prc-app').has(e.target).length === 0 &&
!$('.pcr-selection').is(e.target) &&
$('.pcr-selection').has(e.target).length === 0 &&
!$('.pcr-swatches').is(e.target) &&
$('.pcr-swatches').has(e.target).length === 0 &&
!$('.pcr-interaction').is(e.target) &&
$('.pcr-interaction').has(e.target).length === 0
) {
o_fill.hide();
}
// Hide zoom controls
if (
!$('#other-controls').is(e.target) &&
$('#other-controls').has(e.target).length === 0
) {
$('#zoom-options').addClass('zoom-hidden');
$('#zoom-level img').removeClass('zoom-open');
}
// Hide speed settings
if (
!$('#speed').is(e.target) &&
$('#speed').has(e.target).length === 0
) {
$('#speed-settings').removeClass('show-speed');
$('#speed-arrow').removeClass('arrow-on');
}
// Hide more menu
if (
!$('#more-tool').is(e.target) &&
$('#more-tool').has(e.target).length === 0 &&
!$('#more-over').is(e.target) &&
$('#more-over').has(e.target).length === 0
) {
hideMore();
}
});
// Detect focus on an input in the properties
$(document)
.on('focus', '.property-input', function () {
focus = true;
})
.on('focusout', function () {
focus = false;
});
// Toggle zoom dropdown
$(document).on('click', '#zoom-level', function () {
$('#zoom-options').toggleClass('zoom-hidden');
$('#zoom-level img').toggleClass('zoom-open');
});
// Skip to the beginning or end
$(document).on('click', '#skip-backward', function () {
animate(false, 0);
$('#seekbar').offset({
left:
offset_left +
$('#inner-timeline').offset().left +
currenttime / timelinetime,
});
});
$(document).on('click', '#skip-forward', function () {
animate(false, duration);
$('#seekbar').offset({
left:
offset_left +
$('#inner-timeline').offset().left +
currenttime / timelinetime,
});
});
// Change layer name
$(document).on('dblclick', '.layer-custom-name', function () {
$(this).prop('readonly', false);
$(this).addClass('name-active');
$(this).focus();
document.execCommand('selectAll', false, null);
editinglayer = true;
});
// Trigger file picker when clicking the upload button
$(document).on('click', '#upload-button', function () {
$('#upload-popup').addClass('upload-show');
});
$(document).on('click', '#upload-overlay', function () {
$('.upload-show').removeClass('upload-show');
});
$(document).on('click', '#upload-popup-close', function () {
$('.upload-show').removeClass('upload-show');
});
$(document).on('click', '#upload-drop-area', function () {
$('#filepick').click();
});
$(document).on('dragover', function (e) {
e.preventDefault();
e.stopPropagation();
});
$(document).on('dragover', '#upload-drop-area', function (e) {
e.preventDefault();
e.stopPropagation();
$('#upload-drop-area').addClass('dropping');
});
$(document).on('dragenter', '#upload-drop-area', function (e) {
e.preventDefault();
e.stopPropagation();
$('#upload-drop-area').addClass('dropping');
});
$(document).on('drop', function (e) {
e.preventDefault();
e.stopPropagation();
$('#upload-drop-area').removeClass('dropping');
handleUpload(e);
});
$(document).on('dragleave', function () {
$('#upload-drop-area').removeClass('dropping');
});
$(document).on('dragend', function () {
$('#upload-drop-area').removeClass('dropping');
});
// Upload or remove background audio
$(document).on('click', '#audio-upload-button', function () {
$('#filepick2').click();
});
// Sync scrolling for the timeline
syncScroll($('#layer-inner-list'), $('#timeline'));
syncScrollHoz($('#timeline'), $('#seekarea'));
// Initialize layer sorting
sortable('#layer-inner-list', {
customDragImage: (draggedElement, elementOffset, event) => {
return {
element: document.getElementById('nothing'),
posX: event.pageX - elementOffset.left,
posY: event.pageY - elementOffset.top,
};
},
})[0].addEventListener('sortstop', function (e) {
const id = $(e.detail.item).attr('data-object');
const previd = $(e.detail.item).prev().attr('data-object');
if ($('.sortable-dragging').length == 1) {
$('.sortable-dragging').remove();
if (previd == undefined) {
$('#inner-timeline').prepend($('#' + id));
} else {
$('#' + id).insertAfter($('#' + previd));
}
orderLayers();
}
});
// Initialize dropdown for keyframe easing
$('#easing select').niceSelect();
// Initialize properties panel
updatePanel(false);
// Initialize library
updateBrowser('shape-tool');
function initFilterSliders() {
var filters = [
'filter-brightness',
'filter-contrast',
'filter-saturation',
'filter-hue',
'filter-vibrance',
];
filters.forEach(function (filter) {
var selectme = document.getElementById(filter);
var slider = new RangeSlider(selectme, {
design: '2d',
theme: 'default',
handle: 'round',
popup: null,
showMinMaxLabels: false,
unit: '%',
min: -100,
max: 100,
value: 0,
step: 1,
onmove: function (x) {
if (canvas.getActiveObject()) {
var obj = canvas.getActiveObject();
if (filter == 'filter-brightness') {
if (obj.filters.find((i) => i.type == 'Brightness')) {
obj.filters.find(
(i) => i.type == 'Brightness'
).brightness = x / 100;
} else {
obj.filters.push(
new f.Brightness({ brightness: x / 100 })
);
}
} else if (filter == 'filter-contrast') {
if (obj.filters.find((i) => i.type == 'Contrast')) {
obj.filters.find(
(i) => i.type == 'Contrast'
).contrast = x / 100;
} else {
obj.filters.push(
new f.Contrast({ contrast: x / 100 })
);
}
} else if (filter == 'filter-saturation') {
if (obj.filters.find((i) => i.type == 'Saturation')) {
obj.filters.find(
(i) => i.type == 'Saturation'
).saturation = x / 100;
} else {
obj.filters.push(
new f.Saturation({ saturation: x / 100 })
);
}
} else if (filter == 'filter-vibrance') {
if (obj.filters.find((i) => i.type == 'Vibrance')) {
obj.filters.find(
(i) => i.type == 'Vibrance'
).vibrance = x / 100;
} else {
obj.filters.push(
new f.Vibrance({ vibrance: x / 100 })
);
}
} else if (filter == 'filter-hue') {
if (obj.filters.find((i) => i.type == 'HueRotation')) {
obj.filters.find(
(i) => i.type == 'HueRotation'
).rotation = x / 100;
} else {
obj.filters.push(
new f.HueRotation({ rotation: x / 100 })
);
}
}
obj.applyFilters();
canvas.renderAll();
}
},
onfinish: function (x) {
save();
},
});
sliders.push({ name: filter, slider: slider });
});
}
var selectchroma = document.getElementById('chroma-distance');
chromaslider = new RangeSlider(selectchroma, {
design: '2d',
theme: 'default',
handle: 'round',
popup: null,
showMinMaxLabels: false,
unit: '%',
min: 1,
max: 100,
value: 1,
step: 1,
onmove: function (x) {
if (canvas.getActiveObject()) {
var obj = canvas.getActiveObject();
if (obj.filters.find((x) => x.type == 'RemoveColor')) {
obj.filters.find((x) => x.type == 'RemoveColor').distance =
x / 100;
}
obj.applyFilters();
canvas.renderAll();
}
},
onfinish: function (x) {
save();
},
});
var selectnoise = document.getElementById('filter-noise');
noiseslider = new RangeSlider(selectnoise, {
design: '2d',
theme: 'default',
handle: 'round',
popup: null,
showMinMaxLabels: false,
unit: '%',
min: 0,
max: 1000,
value: 0,
step: 1,
onmove: function (x) {
if (canvas.getActiveObject()) {
var obj = canvas.getActiveObject();
if (obj.filters.find((x) => x.type == 'Noise')) {
obj.filters.find((x) => x.type == 'Noise').noise = x;
} else {
obj.filters.push(
new f.Noise({
noise: x,
})
);
}
obj.applyFilters();
canvas.renderAll();
}
},
onfinish: function (x) {
save();
},
});
var selectblur = document.getElementById('filter-blur');
blurslider = new RangeSlider(selectblur, {
design: '2d',
theme: 'default',
handle: 'round',
popup: null,
showMinMaxLabels: false,
unit: '%',
min: 0,
max: 100,
value: 0,
step: 1,
onmove: function (x) {
if (canvas.getActiveObject()) {
var obj = canvas.getActiveObject();
if (obj.filters.find((x) => x.type == 'Blur')) {
obj.filters.find((x) => x.type == 'Blur').blur = x / 100;
} else {
obj.filters.push(
new f.Blur({
blur: x / 100,
})
);
}
}
obj.applyFilters();
canvas.renderAll();
},
onfinish: function (x) {
save();
},
});
$('#filters-list').val('none');
$('#filters-list').niceSelect();
initFilterSliders();
});
|