Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
27 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
Binary file not shown.
64 changes: 26 additions & 38 deletions
64
MatejSketchPlugins.sketchplugin/Contents/Sketch/toggle-specs.cocoascript
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 |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} | ||
} |