From 7b8928886bf101b0cf4a8cc2d2dd2e576ec1c8d8 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Mon, 28 Sep 2015 20:27:43 +0100 Subject: [PATCH] Add tw.utils.tagToCssSelector() helper method --- core/modules/utils/utils.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/modules/utils/utils.js b/core/modules/utils/utils.js index 1e08837a5..f7f8340a7 100644 --- a/core/modules/utils/utils.js +++ b/core/modules/utils/utils.js @@ -633,4 +633,16 @@ exports.makeDataUri = function(text,type) { return parts.join(""); }; +/* +Useful for finding out the fully escaped CSS selector equivalent to a given tag. For example: + +$tw.utils.tagToCssSelector("$:/tags/Stylesheet") --> tc-tagged-\%24\%3A\%2Ftags\%2FStylesheet +*/ +exports.tagToCssSelector = function(tagName) { + return "tc-tagged-" + encodeURIComponent(tagName).replace(/[!"#$%&'()*+,\-./:;<=>?@[\\\]^`{\|}~,]/mg,function(c) { + return "\\" + c; + }); +}; + + })(); \ No newline at end of file