[ANN] RevLetObject javascript include.

Andre Garzia andre at andregarzia.com
Fri Oct 30 14:03:48 EDT 2009


Hello Folks,

It is with immense happiness that I announce the immediate availability of
RevLetObject. As many here know, instantiating revlets is a tricky thing and
I bet most people here just copy & paste from the test.html generated by Rev
IDE into their own page. If you want to load more than one revlet or want to
do it at runtime, then, using those ugly HTML constructs will be a tad hard.
Right now, loading a revlet looks like this, pardon me for the huge quote,
but I want to make a point, just scroll down:

------------------------------------------------------------------------------------------------------------------------------------------------------

<object classid="CLSID:B2EC94AF-4716-4300-824A-3314BF23664A" width=566
height=396>
 <param name="src" value="redcube.revlet"/>
<param name="stack" value="Untitled 1"/>
 <param name="requestedName" value=""/>
<param name="instanceID" value=""/>
 <embed type="application/x-revolution"
src="redcube.revlet"
 width=566 height=396
stack="Untitled 1"
requestedName=""
 instanceID=""
></embed>
</object>

</div>
<div id="noplugin" style="display:none">
<a href="http://revweb.runrev.com"><img src="
http://www.runrev.com/revweb/images/revweb-noplugin.gif" border=0></a>
</div>
<!-- Revlet embedding code finishes above this line -->

</p>

<!-- This script determines if the plugin is installed, and if so shows the
'plugin' DIV, otherwise it shows the 'noplugn' DIV -->
<script type="text/javascript">
var agt=navigator.userAgent.toLowerCase();
var ie  = (agt.indexOf("msie") != -1);
var ns  = (navigator.appName.indexOf("Netscape") != -1);
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
var mac = (agt.indexOf("mac")!=-1);
if(ie && win){ pluginlist =
detectIE("RunRev.RevWebPluginCtrl.1","Revolution"); }
if (ns || !win){ nse = ""; for(var i=0;i<navigator.mimeTypes.length;i++) nse
+= navigator.mimeTypes[i].type.toLowerCase(); pluginlist =
detectNS("application/x-revolution","Revolution"); }
function detectIE(ClassID,name) { result = false; document.write('<SCRIPT
LANGUAGE=VBScript>\n on error resume next \n result =
IsObject(CreateObject("' + ClassID + '"))\</SCRIPT\>\n'); if (result) return
name+','; else return ''; }
function detectNS(ClassID,name) { n = ""; if (nse.indexOf(ClassID) != -1) if
(navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+","; return n;
}
pluginlist += navigator.javaEnabled() ? "Java," : "";
if (pluginlist.length > 0) pluginlist =
pluginlist.substring(0,pluginlist.length-1);
var plugin = document.getElementById("plugin");
var noplugin = document.getElementById("noplugin");
plugin.style.display = "none";
noplugin.style.display = "none";
if(pluginlist.indexOf("Revolution")!=-1){ plugin.style.display = "block";
}else{ noplugin.style.display = "block"; }
</script>
<!-- Plugin detection script finishes above this line -->

---------------------------------------------------------------------------------------------------------------------------------------------------------------------


With revletobject.js it looks like:

  revletobject.load({
    width: 360,
    height: 290,
    src: "demo.revlet",
    stack: "demo",
    instanceID: "1",
    id: "params",
    params: {
      test: "this is a test",
      color: "blue"}
    }
  );

Yes, that simple! It uses a JSON as parameter, and the key/value pairs are
pretty straight forward. RevLetObject also provides a pluginloaded()
function that will return true or false depending on the availability of the
plugin. So you can wrap it all like:

<div id="params">No plugin.</div>
<script type="text/javascript">
if (revletobject.pluginloaded()) {
  revletobject.load({
    width: 360,
    height: 290,
    src: "demo.revlet",
    stack: "demo",
    instanceID: "1",
    id: "params",
    params: {
      test: "this is a test",
      color: "blue"}
    }
  );
}
</script>

This will check if the plugin is loaded, if so it will replace the div with
id "params" with the revlet as specified by the id key on the load call...

You can see a demo at:

    http://andregarzia.com/revletobject/demo.html

or get it from

    http://hg.andregarzia.com/revletobject

There is a wiki available at:

    http://hg.andregarzia.com/revletobject/wiki/Home

I also show some nice revlet javascript interaction on that demo.

By the way, this is released on the terms of MIT license.

Cheers and have fun!
Andre



-- 
http://www.andregarzia.com All We Do Is Code.



More information about the use-livecode mailing list