diff --git a/src/utils/ExtensionUtils.js b/src/utils/ExtensionUtils.js index b6773907ab6..aff98c03e7a 100644 --- a/src/utils/ExtensionUtils.js +++ b/src/utils/ExtensionUtils.js @@ -23,7 +23,7 @@ /*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */ -/*global define, $, brackets, less */ +/*global define, $, brackets, less, PathUtils */ /** * ExtensionUtils defines utility methods for implementing extensions. @@ -90,6 +90,16 @@ define(function (require, exports, module) { paths: [dir], rootpath: dir }; + + if (PathUtils.isAbsoluteUrl(url)) { + options.currentFileInfo = { + currentDirectory: dir, + entryPath: dir, + filename: url, + rootFilename: url, + rootpath: dir + }; + } } var parser = new less.Parser(options); @@ -151,7 +161,7 @@ define(function (require, exports, module) { * @return {!$.Promise} A promise object that is resolved with the contents of the requested file **/ function loadFile(module, path) { - var url = getModuleUrl(module, path), + var url = PathUtils.isAbsoluteUrl(path) ? path : getModuleUrl(module, path), promise = $.get(url); return promise; diff --git a/test/spec/ExtensionUtils-test.js b/test/spec/ExtensionUtils-test.js index c28a8823a4b..96a5026d7b8 100644 --- a/test/spec/ExtensionUtils-test.js +++ b/test/spec/ExtensionUtils-test.js @@ -111,8 +111,7 @@ define(function (require, exports, module) { waitsForFail(promise, "loadStyleSheet: " + path); }); }); - - // putting everything LESS related in 1 test so it runs faster + it("should attach LESS style sheets", function () { var promise, result; @@ -137,6 +136,35 @@ define(function (require, exports, module) { expect(testWindow.$.contains(testWindow.document, result)).toBeTruthy(); }); }); + + it("should attach LESS style sheets using absolute url", function () { + var promise, result; + + runs(function () { + var indexLocation = testWindow.location.origin + testWindow.location.pathname, + bracketsLocation = indexLocation.substring(0, indexLocation.length - "src/index.html".length), + basicLessLocation = bracketsLocation + "test/spec/ExtensionUtils-test-files/basic.less"; + + promise = loadStyleSheet(testWindow.document, basicLessLocation); + promise.done(function (style) { + result = style; + }); + + waitsForDone(promise); + }); + + runs(function () { + // convert all line endings to platform default + var windowText = FileUtils.translateLineEndings(testWindow.$(result).text()), + lessText = FileUtils.translateLineEndings(LESS_RESULT); + + // confirm style sheet contents + expect(windowText).toBe(lessText); + + // confirm style is attached to document + expect(testWindow.$.contains(testWindow.document, result)).toBeTruthy(); + }); + }); }); }); });