Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit d2b5cf7

Browse files
committed
Merge pull request #1017 from adobe/jason-sanjose/ext-load-css
loadStyleSheet proposal for extensions
2 parents 8cdc155 + 8ab5e3a commit d2b5cf7

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

src/brackets.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ define(function (require, exports, module) {
8383
require("debug/DebugCommandHandlers");
8484
require("view/ViewCommandHandlers");
8585
require("search/FindInFiles");
86+
require("utils/ExtensionUtils");
8687

8788
function _callBracketsReadyHandler(handler) {
8889
try {

src/utils/ExtensionUtils.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*
22+
*/
23+
24+
25+
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
26+
/*global define, $ */
27+
28+
/**
29+
* ExtensionUtils defines utility methods for implementing extensions.
30+
*/
31+
define(function (require, exports, module) {
32+
'use strict';
33+
34+
/**
35+
* Loads a style sheet relative to the extension module.
36+
*
37+
* @param {!module} module Module provided by RequireJS
38+
* @param {!string} path Relative path from the extension folder to a CSS file
39+
* @return {!$.Promise} A promise object that is resolved if the CSS file can be loaded.
40+
*/
41+
function loadStyleSheet(module, path) {
42+
var url = encodeURI(module.uri.replace("main.js", "") + path),
43+
result = new $.Deferred();
44+
45+
// Make a request for the same file in order to record success or failure.
46+
// The link element's onload and onerror events are not consistently supported.
47+
$.get(url).done(function () {
48+
var $link = $("<link/>");
49+
50+
$link.attr({
51+
type: "text/css",
52+
rel: "stylesheet",
53+
href: url
54+
});
55+
56+
$("head").append($link[0]);
57+
58+
result.resolve();
59+
}).fail(function (err) {
60+
result.reject(err);
61+
});
62+
63+
return result;
64+
}
65+
66+
exports.loadStyleSheet = loadStyleSheet;
67+
});

0 commit comments

Comments
 (0)