Skip to content

Commit

Permalink
fixed specs plugin to be recursive
Browse files Browse the repository at this point in the history
  • Loading branch information
hrescak committed Apr 16, 2015
1 parent ecbf334 commit b2cf5b3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
.DS_Store
Binary file removed MatejSketchPlugins.sketchplugin/.DS_Store
Binary file not shown.
@@ -1,46 +1,34 @@
var layerprefix = "specs";
var visibility = nil;

var onRun = function (context) {
var doc = context.document;
var layerprefix = "specs";
var pages = [doc pages];
var visibility = nil; // whether all specs will be toggled on or off (vs toggling each layer independently)

for (var a=0; a<pages.length();a++){
var page = pages[a];
var artboards = [page artboards];

if (artboards.length()) { // if this page has artboards...
for (var i=0; i<artboards.length(); i++) {
var artboard = artboards[i];
var layers = [artboard layers];

for (var j=0; j<layers.length();j++){
var layer = [layers objectAtIndex: j];
layername = [layer name];
if (layername.substr(0, layerprefix.length) == layerprefix){
// determine whether to toggle all specs on or off
if (visibility == nil) {
visibility = [layer isVisible] ? false : true;
}

[layer setIsVisible: visibility];
}
}
}
} else { // if this page doesn't have artboards...
var layers = [page layers];
var pageLoop = [pages objectEnumerator];
while (page = [pageLoop nextObject]) {
hideOrShowSpecs(page);
}
}

for (var j=0; j<layers.length();j++){
var layer = [layers objectAtIndex: j];
layername = [layer name];
if (layername.substr(0, layerprefix.length) == layerprefix){
// determine whether to toggle all specs on or off
if (visibility == nil) {
visibility = [layer isVisible] ? false : true;
}
function hideOrShowSpecs(layer){
//show or hide layer if it matches prefix
var layername = [layer name];
if (layername.substr(0, layerprefix.length) == layerprefix){
// determine whether to toggle all specs on or off
if (visibility == nil) {
visibility = [layer isVisible] ? false : true;
}
[layer setIsVisible: visibility];
}

[layer setIsVisible: visibility];
}
}
// iterate over children recursively if we can
if ([layer class] == "MSArtboardGroup" || [layer class] == "MSLayerGroup" || [layer class] == "MSPage"]{
var childLayers = [layer layers].array();
if (childLayers){
var loop = [childLayers objectEnumerator];
while (item = [loop nextObject]) {
hideOrShowSpecs(item);
}
}
}
}

0 comments on commit b2cf5b3

Please sign in to comment.