Skip to content

Commit

Permalink
Artboard now is detected as a background.
Browse files Browse the repository at this point in the history
  • Loading branch information
ygev committed Apr 5, 2020
1 parent c55ded9 commit 8f39a35
Showing 1 changed file with 40 additions and 7 deletions.
47 changes: 40 additions & 7 deletions Cluse.sketchplugin/Contents/Sketch/cluse.js
@@ -1,24 +1,36 @@
var sketch = require('sketch/dom');
var async = require('sketch/async');
var Artboard = require('sketch/dom').Artboard
var DataSupplier = require('sketch/data-supplier');
var UI = require('sketch/ui');
var Settings = require('sketch/settings');

var initBgSketch, initFgSketch;

var initBgSketch, initFgSketch, bgType, txtSize;

function onLoad(webView) {
if (layerChecker()) {
var doc = sketch.getSelectedDocument();
var selection = doc.selectedLayers;
var bgSketch = selection.layers[0].style.fills[0].color;
var bgSketch;
var fgSketch;
var txtSize;

if (selection.layers[0].style.fills.length == 0) {
// bottom layer is an artboard
bgSketch = selection.layers[1].getParentArtboard().background.color;
bgType = "artboard";
}
else {
bgSketch = selection.layers[0].style.fills[0].color;
bgType = "shape";
}

if (selection.layers[1].text == undefined) {
// top layer is a shape
fgSketch = selection.layers[1].style.fills[0].color;
txtSize = "none";
}

else {
// top layer is text
fgSketch = selection.layers[1].style.textColor;
Expand All @@ -41,16 +53,37 @@ function onApply(options) {
var selection = doc.selectedLayers;

if (options.background != null) {
selection.layers[0].style.fills[0].color = options.background;
if (bgType == "artboard") {
selection.layers[1].getParentArtboard().background.color = options.background;
}
else if (bgType == "shape") {
selection.layers[0].style.fills[0].color = options.background;
}
}

if (options.foreground != null) {
selection.layers[1].style.textColor = options.foreground;
if (txtSize == "none"){
selection.layers[1].style.fills[0].color = options.foreground;
}
else {
selection.layers[1].style.textColor = options.foreground;
}
}

if (options.cancel) {
selection.layers[0].style.fills[0].color = initBgSketch;
selection.layers[1].style.textColor = initFgSketch;
if (txtSize == "none"){
selection.layers[1].style.fills[0].color = initFgSketch;
}
else {
selection.layers[1].style.textColor = initFgSketch;
}

if (bgType == "artboard") {
selection.layers[1].getParentArtboard().background.color = initBgSketch;
}
else if (bgType == "shape") {
selection.layers[0].style.fills[0].color = initBgSketch;
}
}
};

Expand Down

0 comments on commit 8f39a35

Please sign in to comment.