Displaying layout tool current state
This commit is contained in:
parent
67fa502930
commit
5c473697d9
@ -11,6 +11,7 @@ Template.layoutButton.events({
|
|||||||
left: $button.offset().left + 'px'
|
left: $button.offset().left + 'px'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Open or close the layout chooser dialog
|
||||||
toggleDialog($dropdown);
|
toggleDialog($dropdown);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,43 +1,75 @@
|
|||||||
/**
|
Template.layoutChooser.onRendered(() => {
|
||||||
* Adds the 'hover' class to cells above and to the left of the current cell
|
const instance = Template.instance();
|
||||||
* This is used to "fill in" the grid that the user will change the layout to,
|
|
||||||
* if they click on a specific table cell.
|
|
||||||
*
|
|
||||||
* @param currentCell
|
|
||||||
*/
|
|
||||||
function highlightCells(currentCell) {
|
|
||||||
const cells = $('.layoutChooser table td');
|
|
||||||
cells.removeClass('hover');
|
|
||||||
|
|
||||||
currentCell = $(currentCell);
|
/**
|
||||||
const table = currentCell.parents('.layoutChooser table').get(0);
|
* Adds the 'hover' class to cells above and to the left of the current cell
|
||||||
const rowIndex = currentCell.closest('tr').index();
|
* This is used to "fill in" the grid that the user will change the layout to,
|
||||||
const columnIndex = currentCell.index();
|
* if they click on a specific table cell.
|
||||||
|
*
|
||||||
|
* @param currentCell
|
||||||
|
*/
|
||||||
|
instance.highlightCells = currentCell => {
|
||||||
|
const cells = $('.layoutChooser table td');
|
||||||
|
cells.removeClass('hover');
|
||||||
|
|
||||||
// Loop through the table row by row
|
currentCell = $(currentCell);
|
||||||
// and cell by cell to apply the highlighting
|
const table = currentCell.parents('.layoutChooser table').get(0);
|
||||||
for (var i = 0; i < table.rows.length; i++) {
|
const rowIndex = currentCell.closest('tr').index();
|
||||||
const row = table.rows[i];
|
const columnIndex = currentCell.index();
|
||||||
if (i <= rowIndex) {
|
|
||||||
for (var j = 0; j < row.cells.length; j++) {
|
// Loop through the table row by row
|
||||||
if (j <= columnIndex) {
|
// and cell by cell to apply the highlighting
|
||||||
const cell = row.cells[j];
|
for (var i = 0; i < table.rows.length; i++) {
|
||||||
cell.classList.add('hover');
|
const row = table.rows[i];
|
||||||
|
if (i <= rowIndex) {
|
||||||
|
for (var j = 0; j < row.cells.length; j++) {
|
||||||
|
if (j <= columnIndex) {
|
||||||
|
const cell = row.cells[j];
|
||||||
|
cell.classList.add('hover');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
// Refresh layout chooser highlighting based on current viewports state
|
||||||
|
instance.refreshHighlights = () => {
|
||||||
|
// Stop here if layoutManager is not defined yet
|
||||||
|
if (!window.layoutManager) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the layout rows and columns amount
|
||||||
|
const info = window.layoutManager.layoutProps;
|
||||||
|
|
||||||
|
// get the limiter cell
|
||||||
|
const cell = instance.$('tr').eq(info.rows - 1).children().eq(info.columns - 1);
|
||||||
|
|
||||||
|
// Highlight all cells before the limiter
|
||||||
|
instance.highlightCells(cell);
|
||||||
|
};
|
||||||
|
|
||||||
|
instance.autorun(() => {
|
||||||
|
// Run this computation every time the viewer layout is changed
|
||||||
|
Session.get('LayoutManagerUpdated');
|
||||||
|
|
||||||
|
instance.refreshHighlights();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
Template.layoutChooser.events({
|
Template.layoutChooser.events({
|
||||||
'touchstart .layoutChooser table td, mouseenter .layoutChooser table td'(evt) {
|
'touchstart .layoutChooser table td, mouseenter .layoutChooser table td'(event, instance) {
|
||||||
highlightCells(evt.currentTarget);
|
instance.highlightCells(event.currentTarget);
|
||||||
},
|
},
|
||||||
|
|
||||||
'click .layoutChooser table td'(evt) {
|
'mouseleave .layoutChooser'(event, instance) {
|
||||||
const currentCell = $(evt.currentTarget);
|
instance.refreshHighlights();
|
||||||
const rowIndex = currentCell.closest('tr').index();
|
},
|
||||||
const columnIndex = currentCell.index();
|
|
||||||
|
'click .layoutChooser table td'(event, instance) {
|
||||||
|
const $currentCell = $(event.currentTarget);
|
||||||
|
const rowIndex = $currentCell.closest('tr').index();
|
||||||
|
const columnIndex = $currentCell.index();
|
||||||
|
|
||||||
// Add 1 because the indices start from zero
|
// Add 1 because the indices start from zero
|
||||||
const layoutProps = {
|
const layoutProps = {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user