Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Commit

Permalink
feat: onLayout hook triggered on items being added/remove (#703)
Browse files Browse the repository at this point in the history
When implementing some custom, automatic layout that needs to
recalculate positions and/or sizes on items being added or removed
dynamically a hook like this one might be useful.
  • Loading branch information
rchl authored Apr 27, 2021
1 parent b6b0053 commit 94a1846
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ We divide tiles (cells) into groups on every page. Group object can have the fol
* (optional)
*/
groupMarginCss: '20px 40px',
/* custom function called on initial layout and when the items are added or removed dynamically.
* Can be used to adjust items size/position if implementing some dynamic layouts, for example.
* (optional)
*/
onLayout: function(page, group) {},

/* hidden: hide group (optional)
* can be boolean or function that return boolean
Expand Down
10 changes: 10 additions & 0 deletions scripts/controllers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ App.controller('Main', function ($scope, $timeout, $location, Api, tmhDynamicLoc
let activePage = null;
let cameraList = null;

for (const page of $scope.pages) {
for (const group of page.groups) {
if (group.onLayout) {
$scope.$watchCollection(
() => group.items,
() => group.onLayout(page, group));
}
}
}

const ghostCoordinates = [];
document.addEventListener('click', preventGhostClick, true);

Expand Down

0 comments on commit 94a1846

Please sign in to comment.