<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: times new roman,new york,times,serif; font-size: 12pt; color: #000000'>Hi guys,<br><br>I was thinking about improving JavaScript plugin API so that each time a plugin calls WebAdmin, the plugin name will be part of the call. This way, <em>PluginManager</em> (WebAdmin) can validate the call before doing any further actions, e.g. "plugin invocation must be allowed && plugin must be initialized". In other words, this is just to ensure consistent behavior for "plugin -> WebAdmin" calls.<br><br>Here's a draft of new JavaScript API in action: http://jsfiddle.net/tHk5n/ (see the code below the comment saying "ACTUAL TEST CODE")<br>(I took my inspiration from jQuery source code, even though I don't fully understand JavaScript prototype OOP concept, seems a bit weird to me.)<br><br><hr style="width: 100%; height: 2px;"><br>For comparison, here's some plugin code that uses current plugin API:<br><br><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">// Register our plugin object (containing event handler functions) into pluginApi.plugins</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">pluginApi.plugins['myPlugin'] = {</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;"> UiInit: function() {</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;"> pluginApi.ui.addMainTab('Custom Tab', 'custom-tab', 'http://www.example.com/');</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;"> }</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">};</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">// Tell WebAdmin that we are ready, we need the plugin name to identify this plugin</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">pluginApi.ready('myPlugin');</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><br><hr style="width: 100%; height: 2px;"><br>And here's an equivalent plugin code that uses new plugin API:<br><br><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">// Plugin API instance for our plugin</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">var myPlugin = pluginApi('myPlugin');</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">// Register our plugin object (containing event handler functions) into myPlugin</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">myPlugin.register({</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;"> UiInit: function() {</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;"> myPlugin.ui.addMainTab('Custom Tab', 'custom-tab', 'http://www.example.com/');</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;"> }</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">});</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">// Tell WebAdmin that we are ready, plugin name is already part of myPlugin</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">myPlugin.ready();</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">// Note: the above line is equivalent to: pluginApi('myPlugin').ready();</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><br><hr style="width: 100%; height: 2px;"><br>Let me know what you think.<br><br>Cheers,<br>Vojtech<br><br></div></body></html>