Last active
September 12, 2019 13:48
-
-
Save joonaspaakko/ad59e1f33ba953f622f6765b65b5854c to your computer and use it in GitHub Desktop.
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
var selection = app.selection[0]; | |
var zIndex = getStackingIndex( selection, true ); | |
$.writeln( zIndex ); | |
// Since the last parameter is set to false, this selectPageItem() mirrors the selection | |
// - If first item is selected when the script is run, the last one will be | |
// selected when the script is done. | |
selectPageItem( selection.parentPage, zIndex, false ); | |
// cssMode reverses the order → Frontmost item is the highest number. | |
function getStackingIndex( pageItem, cssMode ) { | |
var page = pageItem.parentPage; | |
var pageItems = page.allPageItems; | |
if ( cssMode ) pageItems = pageItems.reverse(); | |
var length = pageItems.length; | |
for ( var i=0; i < length; i++) { | |
var loopItem = pageItems[i]; | |
if ( pageItem === loopItem ) { | |
pageItem = i; | |
break; | |
} | |
} | |
return pageItem; | |
} | |
// cssMode reverses the order → Frontmost item is the highest number. | |
function selectPageItem( page, index, cssMode ) { | |
if ( cssMode ) { | |
var reversedItems = page.allPageItems.reverse(); | |
app.selection = reversedItems[ index ]; | |
} | |
else { | |
app.selection = page.allPageItems[ index ]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment