Update builder.html
Browse files- builder.html +20 -4
builder.html
CHANGED
@@ -8,7 +8,12 @@
|
|
8 |
<link rel="stylesheet" href="https://unpkg.com/grapesjs/dist/css/grapes.min.css">
|
9 |
|
10 |
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
12 |
.draggable {
|
13 |
position: absolute;
|
14 |
cursor: move;
|
@@ -35,12 +40,13 @@
|
|
35 |
const blockManager = editor.BlockManager;
|
36 |
blockManager.add('draggable-button', {
|
37 |
label: 'Draggable Button',
|
38 |
-
content: `<button class="draggable" draggable="true">Давай</button>`,
|
39 |
attributes: { class: 'gjs-block-section' }
|
40 |
});
|
41 |
|
42 |
document.addEventListener('DOMContentLoaded', function() {
|
43 |
var button = document.querySelector('.draggable');
|
|
|
44 |
var offsetX = 0, offsetY = 0, isDragging = false;
|
45 |
|
46 |
button.addEventListener('mousedown', function(e) {
|
@@ -51,8 +57,18 @@
|
|
51 |
|
52 |
document.addEventListener('mousemove', function(e) {
|
53 |
if (isDragging) {
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
}
|
57 |
});
|
58 |
|
|
|
8 |
<link rel="stylesheet" href="https://unpkg.com/grapesjs/dist/css/grapes.min.css">
|
9 |
|
10 |
|
11 |
+
<style>
|
12 |
+
.container {
|
13 |
+
position: relative;
|
14 |
+
width: 100%;
|
15 |
+
height: 100vh;
|
16 |
+
}
|
17 |
.draggable {
|
18 |
position: absolute;
|
19 |
cursor: move;
|
|
|
40 |
const blockManager = editor.BlockManager;
|
41 |
blockManager.add('draggable-button', {
|
42 |
label: 'Draggable Button',
|
43 |
+
content: `<div class="container"><button class="draggable" draggable="true">Давай</button></div>`,
|
44 |
attributes: { class: 'gjs-block-section' }
|
45 |
});
|
46 |
|
47 |
document.addEventListener('DOMContentLoaded', function() {
|
48 |
var button = document.querySelector('.draggable');
|
49 |
+
var container = document.querySelector('.container');
|
50 |
var offsetX = 0, offsetY = 0, isDragging = false;
|
51 |
|
52 |
button.addEventListener('mousedown', function(e) {
|
|
|
57 |
|
58 |
document.addEventListener('mousemove', function(e) {
|
59 |
if (isDragging) {
|
60 |
+
var newLeft = e.clientX - offsetX;
|
61 |
+
var newTop = e.clientY - offsetY;
|
62 |
+
if (newLeft < 0) newLeft = 0;
|
63 |
+
if (newTop < 0) newTop = 0;
|
64 |
+
if (newLeft + button.offsetWidth > container.offsetWidth) {
|
65 |
+
newLeft = container.offsetWidth - button.offsetWidth;
|
66 |
+
}
|
67 |
+
if (newTop + button.offsetHeight > container.offsetHeight) {
|
68 |
+
newTop = container.offsetHeight - button.offsetHeight;
|
69 |
+
}
|
70 |
+
button.style.left = newLeft + 'px';
|
71 |
+
button.style.top = newTop + 'px';
|
72 |
}
|
73 |
});
|
74 |
|