You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bf...@apache.org on 2014/01/27 21:39:58 UTC

git commit: updated refs/heads/master to b7d6495

Updated Branches:
  refs/heads/master 0502d2f37 -> b7d649589


Plugin API: Support multiple JS includes per plugin

For any plugin/module, allow including additional JS dependencies via
new plugin syntax.

To include JS files, instead of passing a function directly, pass an
array with the first element being a sub-list of the includes:

cloudStack.plugin.myPlugin = [
    ['file1', 'file2', 'fileN' ...], // These will be loaded before
                                     // plugin is executed
    function(plugin) { // The plugin entry point
        ...
    }
];

-- Where each item represents a JS file relative to the plugin folder
   and without the .js extension. Sub-folders are also supported, i.e.,
   'subfolder/file1'


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/b7d64958
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/b7d64958
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/b7d64958

Branch: refs/heads/master
Commit: b7d64958924c7d9445b195b595f7bc00555de2d5
Parents: 0502d2f
Author: Brian Federle <br...@citrix.com>
Authored: Mon Jan 27 12:33:46 2014 -0800
Committer: Brian Federle <br...@citrix.com>
Committed: Mon Jan 27 12:39:36 2014 -0800

----------------------------------------------------------------------
 ui/scripts/plugins.js | 49 ++++++++++++++++++++++++++++++++++------------
 1 file changed, 37 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b7d64958/ui/scripts/plugins.js
----------------------------------------------------------------------
diff --git a/ui/scripts/plugins.js b/ui/scripts/plugins.js
index afeae7c..82d9242 100644
--- a/ui/scripts/plugins.js
+++ b/ui/scripts/plugins.js
@@ -98,15 +98,37 @@
                     }
 
                     // Execute module
-                    cloudStack[type][id](
-                        $.extend(true, {}, cloudStack.pluginAPI, {
-                            pluginAPI: {
-                                extend: function(api) {
-                                    cloudStack.pluginAPI[id] = api;
+                    var target = cloudStack[type][id];
+
+                    if ($.isArray(target)) { // Load additional JS includes
+                        pluginTotal += target[0].length;
+                        require(
+                            $(target[0]).map(function(index, val) {
+                                return basePath + val;
+                            }).toArray(),
+                            function() {
+                                loadedPlugins = loadedPlugins + target[0].length;
+                                target[1](
+                                    $.extend(true, {}, cloudStack.pluginAPI, {
+                                        pluginAPI: {
+                                            extend: function(api) {
+                                                cloudStack.pluginAPI[id] = api;
+                                            }
+                                        }
+                                    })
+                                );
+                            });
+                    } else {
+                        target(
+                            $.extend(true, {}, cloudStack.pluginAPI, {
+                                pluginAPI: {
+                                    extend: function(api) {
+                                        cloudStack.pluginAPI[id] = api;
+                                    }
                                 }
-                            }
-                        })
-                    );
+                            })
+                        );
+                    }
 
                     if (pluginDictionary) {
                         // Callback for extending the dictionary with new entries
@@ -133,13 +155,16 @@
 
                     loadedPlugins = loadedPlugins + 1;
 
-                    if (loadedPlugins === pluginTotal) {
-                        $(window).trigger('cloudStack.pluginReady');
-                    }
-
                     loadCSS(css);
                 });
             }
         );
     });
+
+    var loadTimer = setInterval(function() {
+        if (loadedPlugins === pluginTotal) {
+            clearInterval(loadTimer);
+            $(window).trigger('cloudStack.pluginReady');
+        }
+    }, 100);
 }(jQuery, cloudStack, require));