-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Use JS module loader instead of requirejs when available
- Loading branch information
1 parent
2d540b3
commit a677d80
Showing
6 changed files
with
158 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
return [ | ||
'dependencies' => ['core', 'backend'], | ||
'imports' => [ | ||
'@fluidtypo3/flux/' => 'EXT:flux/Resources/Public/JavaScript/', | ||
] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* This file is part of the FluidTYPO3/Flux project under GPLv2 or later. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.md file that was distributed with this source code. | ||
*/ | ||
define(['jquery'], function ($) { | ||
function isVisibleSection(element) { | ||
var classes = element.classList; | ||
return element.nodeType === Node.ELEMENT_NODE && classes.contains('t3js-flex-section') && !classes.contains('t3js-flex-section-deleted'); | ||
} | ||
|
||
function getSectionColPosInput(section) { | ||
return section.querySelector('.flux-flex-colPos-input'); | ||
} | ||
|
||
function getSectionColPosText(section) { | ||
return section.querySelector('.flux-flex-colPos-text'); | ||
} | ||
|
||
function determineCurrentlyTakenColPos(container) { | ||
return Array.prototype.reduce.call(container.childNodes, function (acc, containerChild) { | ||
if (isVisibleSection(containerChild)) { | ||
var value = getSectionColPosInput(containerChild).value; | ||
if (value !== '') { | ||
acc.push(parseInt(value)); | ||
} | ||
} | ||
return acc; | ||
}, []); | ||
} | ||
|
||
function determineFreeColPos(minColPos, maxColPos, takenColPos) { | ||
for (var colPos = minColPos; colPos <= maxColPos; colPos++) { | ||
if (takenColPos.indexOf(colPos) === -1) { | ||
return colPos; | ||
} | ||
} | ||
} | ||
|
||
function handleAddedSection(section, container) { | ||
var input = getSectionColPosInput(section); | ||
if (input === null || input.value !== '') { | ||
return; | ||
} | ||
var minColPos = parseInt(input.dataset.minValue); | ||
var maxColPos = parseInt(input.dataset.maxValue); | ||
var takenColPos = []; | ||
if (input.dataset.takenValues !== '') { | ||
takenColPos = input.dataset.takenValues.split(',').map(function (colPosStr) { return parseInt(colPosStr); }); | ||
} | ||
takenColPos = takenColPos.concat(determineCurrentlyTakenColPos(container)); | ||
|
||
var colPos = determineFreeColPos(minColPos, maxColPos, takenColPos); | ||
input.value = colPos; | ||
|
||
var label = getSectionColPosText(section); | ||
label.innerText = colPos; | ||
} | ||
|
||
function handleMutation(mutationList) { | ||
mutationList.forEach(function (mutation) { | ||
Array.prototype.forEach.call(mutation.addedNodes, function (addedElement) { | ||
if (!isVisibleSection(addedElement)) { | ||
return; | ||
} | ||
handleAddedSection(addedElement, mutation.target); | ||
}); | ||
}); | ||
} | ||
|
||
function init() { | ||
var targetNodes = document.querySelectorAll('.t3-flex-container'); | ||
var observer = new MutationObserver(handleMutation); | ||
Array.prototype.forEach.call(targetNodes, function (targetNode) { | ||
observer.observe(targetNode, { childList: true, characterData: false }); | ||
}); | ||
} | ||
|
||
$(function () { | ||
init(); | ||
}); | ||
|
||
return {}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters