styleDropdown.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. $( document ).ready(function() {
  2. setTimeout(() => {
  3. getBlocks();
  4. drawUi();
  5. console.log('ready');
  6. }, 2000);
  7. });
  8. let selectedBlock = '';
  9. let sBlockId;
  10. let lastSelectedBlock = '';
  11. let lBlockId = lastSelectedBlock.split('_')[1];
  12. let multipleBlocksSelected = false;
  13. let classList = [
  14. 'default',
  15. 'moment',
  16. 'temps',
  17. 'segment',
  18. 'sous_segment',
  19. 'liste',
  20. 'latour',
  21. 'éclairage'
  22. ];
  23. function getBlocks() {
  24. let sections = $('section[data-id="body"]');
  25. let index = 0;
  26. sections.each(function() {
  27. let content = $(this).find('> * > * > * > * > *');
  28. let newContent = [];
  29. content.each(function() {
  30. let block = $(this);
  31. if ($(block).prop('tagName') === "H4") {
  32. return;
  33. }
  34. index++;
  35. let taggedBlock = '';
  36. taggedBlock = `<div id="block_${index}" class="block" style="
  37. cursor: pointer;">`;
  38. taggedBlock += $(block).html();
  39. taggedBlock += '</div>';
  40. newContent.push(taggedBlock);
  41. $(this).empty();
  42. $(this).append(taggedBlock);
  43. $(this).click(function(e) {
  44. if (e.ctrl) {
  45. console.log("ctrl+click")
  46. blockGrouped($(this))
  47. } else {
  48. blockClicked($(this))
  49. }
  50. });
  51. //console.log(taggedBlock, index);
  52. });
  53. });
  54. }
  55. function drawUi() {
  56. let uiZone = `
  57. <div id="uiZone" style="
  58. display: flex;
  59. flex-direction: column;
  60. align-items: center;
  61. justify-content: space-around;
  62. background-color: white;
  63. position: fixed;
  64. top: 0;
  65. z-index: 1;
  66. width: 10vw;
  67. height: 7vw;
  68. ">
  69. </div>
  70. `;
  71. $('body').append(uiZone);
  72. let selectedDisplay = `
  73. <div id="selectedDisplay">
  74. Pas de block sélectionné
  75. </div>
  76. `;
  77. $('#uiZone').append(selectedDisplay);
  78. let styleDropdown = `
  79. <div id="dropdown" style="display:none;">
  80. <label for="classes">Style</label>
  81. <select name="classes" id="classes">
  82. </select>
  83. </div>
  84. `;
  85. $('#uiZone').append(styleDropdown);
  86. classList.forEach(function(el) {
  87. let option = `<option value="${el}">${el}</option>`;
  88. $('#dropdown #classes').append(option);
  89. })
  90. }
  91. function blockClicked(block) {
  92. let blockId = $(block).children().first().attr('id');
  93. let idNumber = parseInt(blockId.substr(blockId.indexOf("_") + 1));
  94. if (selectedBlock && selectedBlock != blockId) {
  95. $("#" + selectedBlock).toggleClass('selected');
  96. if (multipleBlocksSelected) {
  97. if ($('#' + selectedBlock).parent().is('[data-last-split-element]')) {
  98. $('#block_' + (sBlockId + 1)).toggleClass('selected');
  99. } else if ($('#' + selectedBlock).parent().is('[data-split-from]')) {
  100. $('#block_' + (sBlockId - 1)).toggleClass('selected');
  101. }
  102. }
  103. } else if ((selectedBlock && selectedBlock === blockId)) {
  104. $(block).children().toggleClass('selected');
  105. $('#dropdown').css('display', 'none');
  106. if (multipleBlocksSelected) {
  107. if ($('#' + selectedBlock).parent().is('[data-last-split-element]')) {
  108. $('#block_' + (sBlockId + 1)).toggleClass('selected');
  109. } else if ($('#' + selectedBlock).parent().is('[data-split-from]')) {
  110. $('#block_' + (sBlockId - 1)).toggleClass('selected');
  111. }
  112. }
  113. selectedBlock = '';
  114. $('#selectedDisplay').empty().append('Pas de block sélectionné');
  115. return;
  116. }
  117. $(block).children().first().toggleClass('selected');
  118. if ($('#' + blockId).attr('class') == 'block') {
  119. $('#' + blockId).addClass("default");
  120. }
  121. $('#selectedDisplay').empty().append('sélectionné<br>' + blockId);
  122. selectedBlock = blockId;
  123. sBlockId = parseInt(selectedBlock.split('_')[1]);
  124. if ($('#' + blockId).parent().is('[data-last-split-element]')) {
  125. $('#block_' + (idNumber + 1)).toggleClass('selected');
  126. if ($('#block_' + (idNumber + 1)).attr('class') == 'block') {
  127. $('#block_' + (idNumber + 1)).addClass("default");
  128. }
  129. $('#selectedDisplay').append(` -> block_${idNumber + 1}`);
  130. multipleBlocksSelected = true;
  131. } else if ($('#' + blockId).parent().is('[data-split-from]')) {
  132. $('#block_' + (idNumber - 1)).toggleClass('selected');
  133. if ($('#block_' + (idNumber - 1)).attr('class') == 'block') {
  134. $('#block_' + (idNumber - 1)).addClass("default");
  135. }
  136. $('#selectedDisplay').append(` -> block_${idNumber - 1}`);
  137. multipleBlocksSelected = true;
  138. }
  139. else {
  140. multipleBlocksSelected = false;
  141. }
  142. $('#dropdown').css('display', 'block');
  143. }
  144. function blockGrouped(block) {
  145. }
  146. function toggleStyle(style, id) {
  147. $('#' + id).toggleClass(style);
  148. }
  149. // data split from