Philip Remer
posted this on March 17, 2011 15:54
(As of June 1st, 2011, the viral installer feature is no longer available)
The Viral Installer consists of code that allows users to customize and grab your widget from any website.
The code contains two key sections:
How do you get the Viral Installer code for your widget? Let's walk through a simple example with a widget setting.
10. The code will look similar to this:
<!-- Developer: you can configure your widget's values via Javascript.
Learn more at http://docs.widgetbox.com/developers/viral-installer/ -->
<form id="viral_installer_example_GetWidgetForm" style="display:none;">
<input type="hidden" name="appInstance.instanceName" value=""/>
<input type="hidden" name="appInstance.width" value=""/>
<input type="hidden" name="appInstance.height" value=""/>
<input type="hidden" name="MySetting" value=""/>
</form>
<script src='http://pub.widgetbox.com/GetWidgetButton/sourceId/<Unique ID Value>/ns/viral_installer_example'></script>
11. Let's explain the values the hidden field values.
appInstance.instanceName
- The "friendly name" a user can assign to a widget.
appInstance.width
- The width of the widget.
appInstance.height
- The height of the widget.
Note: If no values are provided for these three fields, the widget will be created using values associated with the widget's preview settings.
MySetting
- The value that maps to ${config.MySetting}
Note: If no value is provided for this field, the default value (if it exists) will be used.
12. Put the Viral Installer code onto the page you identified in Step 1.
13. Test the Viral Installer. We'll do this by temporarily adding values to each of the hidden form fields.
<!-- Developer: you can configure your widget's values via Javascript. Learn more at http://docs.widgetbox.com/developers/viral-installer/ -->
<form id="viral_installer_example_GetWidgetForm" style="display:none;">
<input type="hidden" name="appInstance.instanceName" value="Hello World Widget"/>
<input type="hidden" name="appInstance.width" value="200"/>
<input type="hidden" name="appInstance.height" value="200"/>
<input type="hidden" name="MySetting" value="Hello World!"/>
</form>
<script src='http://pub.widgetbox.com/GetWidgetButton/sourceId/<Unique ID Value>/ns/viral_installer_example'></script>
14. Save your page and load it in your favorite browser.
15. Click the Get Widget button. The same Get Widget Menu that you see on Widgetbox.com will appear over the page, configured with your new settings. Pick a site to install your new widget or just grab the widget code.
16. Take a look at your installed widget. The text MySetting: Hello World! should appear within.
17. What's next? Build an interface to feed values into the hidden form. What does does the interface need to look like? That's up to you! If you want a quick solution, you can un-hide the Viral Installer form and each of the form input fields.
18. Don't forget to come back to Widgetbox and submit your widget for consideration in our Gallery.