UI plugins: Dynamically load CSS

Adds a CSS file <pluginName>.css to the plugin structure, which allows
developer to specify custom CSS to be loaded after their JS code.
This commit is contained in:
Brian Federle 2013-01-29 13:56:36 -08:00
parent bf2691c51a
commit 806105f9a1
2 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,2 @@
/* Put your CSS here */

View File

@ -1,4 +1,16 @@
(function($, cloudStack, require) {
var loadCSS = function(path) {
var $link = $('<link>');
$link.attr({
rel: 'stylesheet',
type: 'text/css',
href: path
});
$('head').append($link);
};
var pluginAPI = {
addSection: function(section) {
cloudStack.sections[section.id] = section;
@ -18,14 +30,18 @@
var basePath = 'plugins/' + pluginID + '/';
var pluginJS = basePath + pluginID + '.js';
var configJS = basePath + 'config.js';
var pluginCSS = basePath + pluginID + '.css';
require([pluginJS], function() {
require([configJS]);
loadCSS(pluginCSS);
// Execute plugin
cloudStack.plugins[pluginID]({
ui: pluginAPI
});
});
// Load CSS
});
}(jQuery, cloudStack, require));