From d400c9c94da2515432ecd7b4e3224a23462b6687 Mon Sep 17 00:00:00 2001 From: Koen Bok Date: Fri, 12 Dec 2014 14:48:17 +0100 Subject: [PATCH] Add beta Utils.globalLayers --- framer/Utils.coffee | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/framer/Utils.coffee b/framer/Utils.coffee index 3e06c4622..2bd94da46 100644 --- a/framer/Utils.coffee +++ b/framer/Utils.coffee @@ -565,3 +565,24 @@ Utils.convertPoint = (input, layerA, layerB) -> _.extend exports, Utils + +Utils.globalLayers = (importedLayers) -> + + # Beta. Not sure if we should push this but it's nice to have. + # Use this to make all layers in an imported set available on + # on the top level, so without the "importedLayers" prefix. + + for layerName, layer of importedLayers + + # Replace all whitespace in layer names + layerName = layerName.replace(/\s/g,"") + + # Check if there are global variables with the same name + if window.hasOwnProperty(layerName) and not window.Framer._globalWarningGiven + print "Warning: Cannot make layer '#{layerName}' a global, an variable with that name already exists" + else + window[layerName] = layer + + window.Framer._globalWarningGiven = true + +