From ecb9cf542efaf79d4684e00af9f32abbcb592a3f Mon Sep 17 00:00:00 2001 From: Dan White Date: Fri, 6 May 2016 10:27:48 -0700 Subject: [PATCH 1/2] Add default JS resources Loads default scripts for all snippets. One use case is needing to load fonts through a service like Typekit where JS loading is the only option. --- bin/styleguide | 1 + templates/js/iframes.js | 10 ++++++++++ templates/js/snippetActions.js | 8 ++++++++ 3 files changed, 19 insertions(+) diff --git a/bin/styleguide b/bin/styleguide index 2e594e6..d6b44bc 100644 --- a/bin/styleguide +++ b/bin/styleguide @@ -21,6 +21,7 @@ var getMainConfig = function(folder) { projectUrl: '', projectLogo: '', + defaultJsResources: [], jsResources: [], viewportWidths: [320, 480, 768, 1024, 1200], diff --git a/templates/js/iframes.js b/templates/js/iframes.js index 596fbff..1743fa1 100644 --- a/templates/js/iframes.js +++ b/templates/js/iframes.js @@ -64,6 +64,16 @@ var iframesService = (function ($, snippetService) { }); }; + module.getDefaultJavaScripts = function (callback) { + getConfig(function (config) { + if (config.defaultJsResources) { + callback(config.defaultJsResources); + } else { + console.log('No default JavaScript files are defined in configuration to load into iframe.'); + } + }); + }; + module.getJavaScripts = function (callback) { getConfig(function (config) { if (config.jsResources) { diff --git a/templates/js/snippetActions.js b/templates/js/snippetActions.js index 90e0f21..29ca6da 100644 --- a/templates/js/snippetActions.js +++ b/templates/js/snippetActions.js @@ -91,6 +91,14 @@ var snippetActions = (function ($, snippetService, iframesService, editorService .find('script') .remove(); + iframesService.getDefaultJavaScripts(function (defaultJsResources) { + length = defaultJsResources.length; + + for (index = 0; index < length; index++) { + injectJavaScript(document.getElementById(frameId.attr('id')), defaultJsResources[index]); + } + }); + if (includeJs === true || includeJs === "true") { rawJsFrame = document.getElementById(frameId.attr('id')); From 26c0a74a5b816fbfd2db0418bbc40308242b026a Mon Sep 17 00:00:00 2001 From: Dan White Date: Fri, 6 May 2016 10:39:56 -0700 Subject: [PATCH 2/2] Add documentation for defaultJsResources --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c8f1b5b..ac710d9 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,7 @@ You can add project name, project logo or change settings modifying `config.txt` "projectName": "", //Project name "projectUrl": "", //Domain name of your project "projectLogo": "", //path to your project logo + "defaultJsResources": [], //Javascript resources that will load for all snippets automatically "jsResources": [], //Javascript resources that's going to be included into the snippets "viewportWidths": [ //Predefinded viewport breakpoints 480,