The Basic Idea
There are several problems with embeding plugins. First of all you need a Ph.D. to figure out, if your user already has the plugin and what version she is using. Then it needs quite some HTML code to embed your multimedia, not just because Internet Explorer (for Windows) and Navigator compatible browser have a different model. And at the end you want a solution that is also accessible and works for users not having the plugin, or who are not able to install the plugin.
"plugin.js" provides some useful functions as static methods of the Plugin object to detect and embed plugins.
And a named Array (Object) providing information about the most important plugins: Acrobat, QuickTime, Director, 'Windows Media', Flash, Java, Real, VLC
Plugin exists in Mozilla and provides access to the native xpconnect object via Plugin.prototype. So the framework just extends the Plugin object for Mozilla, but will create a Plugin object for other browser, that functions as a namespace for the library.
Example 1 (Video)
Embed a video, depending on what the user has installed:
<div id="video"><a href="myVideo.mp4" onclick="return startVideo('video', 320, 240, 'myVideo.mp4', 'myVideo.wmv');" title="Klick to start video"><img src="myVideoPreview.jpg" width="320" height="240" alt="Preview image for video; Klick to start video." longdesc="myVideoDescription.html" /></a></div>
Example 2 (Flash)
Embed a flash file. SEE DEMO!
You may download and use this script under the Terms of an MIT-style license.
PLUGIN FRAMEWORK, Version 0.3
17.12.2005: Version 0.1
Testing and Bugs
This is currently version 0.3. That means it may contain bugs, and hasn't been tested on all platforms (still in use). It will/should never work on IE4, NS4. DivX and VLC support are experimental.
Please use the demo pages to give it a quick try:
If you would like to add support for another plugin you should extend Plugin.PLUGINS and check for Plugin.embed.
function Plugin.isInstalled(String name)
Returns if plugin with identifier name is installed.
Return true | false
Returns version string (if available) if plugin with identifier name is installed.
Returns an Array of valid plugin identifier names, if that plugins are installed and able to play the specified mimeType. This works diffenrently on Internet Explorer (PC) and Navigator compatible browsers. For IE we provide a fixed list of supportedMimeTypes (Plugin.PLUGINS) and can't say for sure that the installed plugin can play the mimeType.
Returns an Array of valid plugin identifier names, if that plugins are installed and able to play a file with the specified suffix. See getPluginsForMimeTypes for futher explanations.
Plugin.embed(pluginName, options, target)
Writes the proper embed or object tags for the specified plugin. This functions doesn't check, if the plugin is installed. With target you may specify an HTML element (id or referenz) that should contain the plugin code. Options will be used to specify the parameters (attributes) for the embeding code.
Returns structured information about the plugin with identifier name. Returns all attributes derived from Plugin.PLUGINS plus "name", "isInstalled" and "version".
And a named Array (Object) providing information about the most important plugins: Acrobat, QuickTime, Director, 'Windows Media', Flash, Java, RealPlayer, VLC.
Each element can contain:
description ... a short human readable description
Apple published a script that was an inspiration for me to do it better.