mirror of https://github.com/apache/cloudstack.git
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:
parent
bf2691c51a
commit
806105f9a1
|
|
@ -0,0 +1,2 @@
|
|||
/* Put your CSS here */
|
||||
|
||||
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Reference in New Issue