OVIRT MANAGER用户界面插件的引导

一个典型的插件引导程式包括如下步骤:

获得插件的 pluginApi 实例

获得运行时插件配置对象

注册有关的事件处理函数

通知用户界面插件框架继续对插件进行初始化过程

下面的代码片段展示了实际运行过程中上面的步骤的实现:

  1. // Access plugin API using 'parent' due to this code being evaluated within the context of an iframe element.
  2. // As 'parent.pluginApi' is subject to Same-Origin Policy, this will only work when WebAdmin HTML page and plugin
  3. // host page are served from same origin. WebAdmin HTML page and plugin host page will always be on same origin
  4. // when using UI plugin infrastructure support to serve plugin resource files.
  5. var api = parent.pluginApi('MyPlugin');
  6. // Runtime configuration object associated with the plugin (or an empty object).
  7. var config = api.configObject();
  8. // Register event handler function(s) for later invocation by UI plugin infrastructure.
  9. api.register({
  10. // UiInit event handler function.
  11. UiInit: function() {
  12. // Handle UiInit event.
  13. window.alert('Favorite music band is ' + config.band);
  14. }
  15. });
  16. // Notify UI plugin infrastructure to proceed with plugin initialization.
  17. api.ready();