From d2d5043d0423e7b6fc3e04c44eb1ed0cd33a900c Mon Sep 17 00:00:00 2001 From: ray007 Date: Tue, 2 Feb 2016 11:35:43 +0100 Subject: [PATCH 1/2] add handler for css files --- lib/basket.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/basket.js b/lib/basket.js index 5abff79..26b6aa2 100644 --- a/lib/basket.js +++ b/lib/basket.js @@ -160,8 +160,16 @@ head.appendChild( script ); }; + var injectStyle = function( obj ) { + var style = document.createElement('style'); + style.type = 'text/css'; + style.text = obj.data; + head.appendChild( style ); + }; + var handlers = { - 'default': injectScript + 'default': injectScript, + 'css': injectStyle }; var execute = function( obj ) { From 40108d0eaf11feaa9e086c3fff74f272a3f10b59 Mon Sep 17 00:00:00 2001 From: Raimund Bauer Date: Fri, 27 Jul 2018 15:17:47 +0200 Subject: [PATCH 2/2] add sourceURL if not already present --- lib/basket.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/basket.js b/lib/basket.js index 26b6aa2..b4fe9e2 100644 --- a/lib/basket.js +++ b/lib/basket.js @@ -151,19 +151,33 @@ return promise; }; + var absUrl = function( u ) { + if (!/^(\.|\w+:)/.test(u)) + u = location.origin + location.pathname + u; + return u; + }; + var injectScript = function( obj ) { var script = document.createElement('script'); script.defer = true; // Have to use .text, since we support IE8, // which won't allow appending to a script - script.text = obj.data; + var content = obj.data; + if (!/\/\/[#@]\s+sourceURL=.*\s*$/.test(content)) { + content += '//# sourceURL=' + absUrl(obj.url); + } + script.text = content; head.appendChild( script ); }; var injectStyle = function( obj ) { var style = document.createElement('style'); style.type = 'text/css'; - style.text = obj.data; + var content = obj.data; + if (!/\/\*#\s+sourceURL=.*\s+\*\/\s*$/.test(content)) { + content += '/*# sourceURL=' + absUrl(obj.url) + ' */'; + } + style.textContent = content; head.appendChild( style ); };