From be77f753e77c17868dd4954fecaf9c0c716c8f33 Mon Sep 17 00:00:00 2001 From: chylex <info@chylex.com> Date: Sun, 25 Sep 2016 02:34:19 +0200 Subject: [PATCH] Add a global function to easily add custom styles in plugins --- Resources/Scripts/plugins.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Resources/Scripts/plugins.js b/Resources/Scripts/plugins.js index bdb83c05..187563eb 100644 --- a/Resources/Scripts/plugins.js +++ b/Resources/Scripts/plugins.js @@ -34,4 +34,21 @@ } }); }; + + // + // Block: Setup a function to add/remove custom CSS. + // + window.TDPF_createCustomStyle = function(pluginObject){ + var element = document.createElement("style"); + element.id = "plugin-"+pluginObject.$id+"-"+Math.random().toString(36).substring(2, 7); + document.head.appendChild(element); + + var obj = { + insert: (rule) => element.sheet.insertRule(rule, 0), + remove: () => $(element).remove() + }; + + obj.element = element; + return obj; + }; })($TDP); \ No newline at end of file