DmitrMakeev commited on
Commit
550239d
·
verified ·
1 Parent(s): e778b6e

Update builder.html

Browse files
Files changed (1) hide show
  1. builder.html +26 -20
builder.html CHANGED
@@ -8,15 +8,19 @@
8
  <link rel="stylesheet" href="https://unpkg.com/grapesjs/dist/css/grapes.min.css">
9
 
10
  <!-- Your Custom CSS -->
 
11
  <style>
12
  .container {
13
- position: relative;
 
14
  width: 100%;
15
- height: 100vh;
16
  }
17
- .draggable {
18
- position: absolute;
19
- cursor: move;
 
 
20
  }
21
  </style>
22
  </head>
@@ -36,17 +40,29 @@
36
  pluginsOpts: {}
37
  });
38
 
39
- // Example of adding a draggable button
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,18 +73,8 @@
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
 
 
8
  <link rel="stylesheet" href="https://unpkg.com/grapesjs/dist/css/grapes.min.css">
9
 
10
  <!-- Your Custom CSS -->
11
+ <!-- Your Custom CSS -->
12
  <style>
13
  .container {
14
+ display: flex;
15
+ justify-content: space-between;
16
  width: 100%;
17
+ height: 100px;
18
  }
19
+ .item {
20
+ flex: 1;
21
+ border: 1px solid #ccc;
22
+ padding: 10px;
23
+ text-align: center;
24
  }
25
  </style>
26
  </head>
 
40
  pluginsOpts: {}
41
  });
42
 
43
+ // Example of adding a horizontal block with three items
44
  const blockManager = editor.BlockManager;
45
+ blockManager.add('horizontal-block', {
46
+ label: 'Horizontal Block',
47
+ content: `
48
+ <div class="container">
49
+ <div class="item">Item 1</div>
50
+ <div class="item">Item 2</div>
51
+ <div class="item">Item 3</div>
52
+ </div>
53
+ `,
54
+ attributes: { class: 'gjs-block-section' }
55
+ });
56
+
57
+ // Example of adding a draggable button
58
  blockManager.add('draggable-button', {
59
  label: 'Draggable Button',
60
+ content: `<button class="draggable" draggable="true">Давай</button>`,
61
  attributes: { class: 'gjs-block-section' }
62
  });
63
 
64
  document.addEventListener('DOMContentLoaded', function() {
65
  var button = document.querySelector('.draggable');
 
66
  var offsetX = 0, offsetY = 0, isDragging = false;
67
 
68
  button.addEventListener('mousedown', function(e) {
 
73
 
74
  document.addEventListener('mousemove', function(e) {
75
  if (isDragging) {
76
+ button.style.left = (e.clientX - offsetX) + 'px';
77
+ button.style.top = (e.clientY - offsetY) + 'px';
 
 
 
 
 
 
 
 
 
 
78
  }
79
  });
80