Skip to content

Commit

Permalink
JSGateway-1.2
Browse files Browse the repository at this point in the history
callbacks to modules functions
javascript funtions called on events
  • Loading branch information
mstandio committed Jul 30, 2011
1 parent 7cd35bb commit 0dcc82e
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 37 deletions.
2 changes: 1 addition & 1 deletion bin/_showcase/examplesviewer/resources/list.html
Expand Up @@ -95,7 +95,7 @@
<a class="L L2" href="javascript:change('05_modules/infobubble/03_enable.xml')">03_enable.xml</a><br/>
<a class="L L2" href="javascript:change('05_modules/infobubble/04_tween.xml')">04_tween.xml</a><br/>
<span class="L L1">jsgateway</span><br/>
<a class="L L2" href="javascript:change2('jsgateway/index.html','05_modules/jsgooglemap/01_complete.xml')">01_basic.xml</a><br/>
<a class="L L2" href="javascript:change2('jsgateway/index.html','05_modules/jsgateway/01_complete.xml')">01_complete.xml</a><br/>
<span class="L L1">jsgooglemap</span><br/>
<a class="L L2" href="javascript:change2('jsgooglemap/index.html','05_modules/jsgooglemap/01_complete.xml')">01_complete.xml</a><br/>
<span class="L L1">menuscroller</span><br/>
Expand Down
27 changes: 23 additions & 4 deletions bin/_showcase/jsgateway/index.html
Expand Up @@ -11,16 +11,35 @@
counter++;
}

// onEnter, onTransitionEnd and onMoveEnd are called from SaladoPlayer by default
function onEnter(panoramaId){
var box2 = document.getElementById('box2');
box2.value = 'panorama loaded: ' + panoramaId;
}
function onTransitionEnd(panoramaId){
var box2 = document.getElementById('box2');
box2.value = 'transition ended: ' + panoramaId;
}
function onMoveEnd(){
var box2 = document.getElementById('box2');
box2.value = 'move ended';
}

function handleClick(actionId){
document.getElementById('SaladoPlayer').runAction(actionId);
document.getElementById('SaladoPlayer').moveSaladoPlayerToView(50,50,NaN);

// exposed by default
document.getElementById('SaladoPlayer').runAction(actionId);

// exposed via asfunction
document.getElementById('SaladoPlayer').setActiveButtonBar('a', true);
document.getElementById('SaladoPlayer').moveSaladoPlayerToView(Math.ceil(100 * Math.random()), Math.ceil(100 * Math.random()), NaN);
}

</script>
<script type="text/javascript" src="../../embed/swfobject.js"></script>
<script type="text/javascript">
var flashvars = {};
flashvars.xml = "../../examples/05_modules/jsgateway/01_basic.xml"
flashvars.xml = "../../examples/05_modules/jsgateway/01_complete.xml"
flashvars.tilde="../../"
var params = {};
params.play = "true";
Expand All @@ -44,7 +63,7 @@
</div>
<div style="text-align:center; margin-top:10px;">
<u><a href="#" onClick="handleClick('javaScriptToSaladoPlayer');">Click here to execute action "javaScriptToSaladoPlayer"</a></u>
<form><input type="text" id="box" name="box" value=""/></form>
<form><input type="text" id="box" value=""/><input type="text2" id="box2" value=""/></form>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion bin/compiled_files.txt
Expand Up @@ -10,7 +10,7 @@ src/com/panozona/modules/dropdown/DropDown.as -> modules/DropDown-1.1.swf
src/com/panozona/modules/imagebutton/ImageButton.as -> modules/ImageButton-1.2.swf
src/com/panozona/modules/imagemap/ImageMap.as -> modules/ImageMap-1.2.swf
src/com/panozona/modules/infobubble/InfoBubble.as -> modules/InfoBubble-1.3.swf
src/com/panozona/modules/jsgateway/JSGateway.as -> modules/JSGateway-1.1.swf
src/com/panozona/modules/jsgateway/JSGateway.as -> modules/JSGateway-1.2.swf
src/com/panozona/modules/jsgooglemap/JSGoogleMap.as -> modules/JSGoogleMap-1.0.swf
src/com/panozona/modules/menuscroller/MenuScroller.as -> modules/MenuScroller-1.1.swf
src/com/panozona/modules/mousecursor/MouseCursor.as -> modules/MouseCursor-1.0.swf
Expand Down
28 changes: 0 additions & 28 deletions bin/examples/05_modules/jsgateway/01_basic.xml

This file was deleted.

50 changes: 50 additions & 0 deletions bin/examples/05_modules/jsgateway/01_complete.xml
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
By default JSGateway exposes to JavaScript function "runAction" that takes action id as parameter, and therefore
it enables executing actions via javascript. Another default behaviour is calling JavaScript functions named
onEnter, onTransitionEnd (both with argument of panorama id) and onMoveEnd whenever such events have place.
asfunction
callback points to function name that will be exposed to JavaScript. Pointing to specific functions requires
basic knowledge of SaladoPlayer source structure and is not analogical to regular syntax used in configuration.
jsfuncion
enables calling JavaScript functions via actions, arguments passed to JavaScript are hard-coded into configuration.
http://panozona.com/wiki/Module:JSGateway
-->
<SaladoPlayer>
<global debug="true">
<trace open="true"/>
</global>
<panoramas>
<panorama id="greenChecker" path="~panoramas/dz_green_check/green_check_f.xml">
<image id="gc_blueArrow" path="~hotspots/images/blue_arrow.png" mouse="onClick:loadBlueChecker"/>
</panorama>
<panorama id="blueChecker" path="~panoramas/dz_blue_check/blue_check_f.xml">
<image id="bc_greenArrow" path="~hotspots/images/green_arrow.png" mouse="onClick:loadGreenChecker"/>
</panorama>
</panoramas>
<modules>
<ButtonBar path="~modules/ButtonBar-1.2.swf">
<buttons path="~modules/images/buttonbar/buttons_40x40_black.png">
<extraButton name="a" action="saladoPlayerToJavascript"/>
</buttons>
</ButtonBar>
<JSGateway path="~modules/JSGateway-1.2.swf">
<jsfunctions>
<jsfunction id="js1" name="someJavaScriptFunction" text="hello"/>
</jsfunctions>
<asfunctions>
<asfunction name="moveSaladoPlayerToView" callback="saladoPlayer.manager.moveToView"/>
<asfunction name="setActiveButtonBar" callback="saladoPlayer.getModuleByName(ButtonBar).setActive"/>
</asfunctions>
</JSGateway>
</modules>
<actions>
<action id="loadBlueChecker" content="SaladoPlayer.loadPano(blueChecker)"/>
<action id="loadGreenChecker" content="SaladoPlayer.loadPano(greenChecker)"/>

<action id="saladoPlayerToJavascript" content="JSGateway.run(js1)"/>
<action id="javaScriptToSaladoPlayer" content="SaladoPlayer.print(got called from javascript)"/>
</actions>
</SaladoPlayer>
42 changes: 39 additions & 3 deletions src/com/panozona/modules/jsgateway/JSGateway.as
Expand Up @@ -32,13 +32,21 @@ package com.panozona.modules.jsgateway {
private var jsgatewayData:JSGatewayData;

public function JSGateway(){
super("JSGateway", "1.1", "http://panozona.com/wiki/Module:JSGateway");
super("JSGateway", "1.2", "http://panozona.com/wiki/Module:JSGateway");
moduleDescription.addFunctionDescription("run", String);
}

override protected function moduleReady(moduleData:ModuleData):void {
jsgatewayData = new JSGatewayData(moduleData, saladoPlayer);

visible = false;

if (!ExternalInterface.available) {
printError("ExternalInterface not avaible");
return;
}

jsgatewayData = new JSGatewayData(moduleData, saladoPlayer);

ExternalInterface.addCallback("runAction", saladoPlayer.manager.runAction);

for each (var asfunction:ASFunction in jsgatewayData.asfuncttions.getChildrenOfGivenClass(ASFunction)) {
Expand All @@ -48,6 +56,26 @@ package com.panozona.modules.jsgateway {
printWarning("Could not expose asfunction: " + asfunction.name +", " + e.message);
}
}

var panoramaEventClass:Class = ApplicationDomain.currentDomain.getDefinition("com.panozona.player.manager.events.PanoramaEvent") as Class;
saladoPlayer.manager.addEventListener(panoramaEventClass.PANORAMA_LOADED, onPanoramaLoaded, false, 0, true);
saladoPlayer.manager.addEventListener(panoramaEventClass.TRANSITION_ENDED, onTransitionEnded, false, 0, true);

var panoSaladoEventClass:Class = ApplicationDomain.currentDomain.getDefinition("com.panosalado.events.PanoSaladoEvent") as Class;
saladoPlayer.manager.addEventListener(panoSaladoEventClass.SWING_TO_COMPLETE, onMoveEnded, false, 0, true);
saladoPlayer.manager.addEventListener(panoSaladoEventClass.SWING_TO_CHILD_COMPLETE, onMoveEnded, false, 0, true);
}

private function onPanoramaLoaded(panoramaEvent:Object):void {
ExternalInterface.call("onEnter", saladoPlayer.manager.currentPanoramaData.id);
}

private function onTransitionEnded(panoramaEvent:Object):void {
ExternalInterface.call("onTransitionEnd", saladoPlayer.manager.currentPanoramaData.id);
}

private function onMoveEnded(panoSaladoEvent:Object):void {
ExternalInterface.call("onMoveEnd", saladoPlayer.manager.currentPanoramaData.id);
}

private function getReference(input:String):Object {
Expand All @@ -56,12 +84,20 @@ package com.panozona.modules.jsgateway {

private function getReferenceR(path:Array, currentIndex:int, inputObject:Object):Object {
if (currentIndex < path.length) {
return getReferenceR(path, currentIndex+1, inputObject[path[currentIndex]]);
return getReferenceR(path, currentIndex + 1, autocall(inputObject, path[currentIndex]));
}else {
return inputObject;
}
}

private function autocall(obj:Object, next:String):Object {
if (next.match(/^.+\(.*\)$/)) {
return (obj[next.match(/^.+(?=\()/)[0]] as Function).apply(this, ((next.match(/(?<=\()(.+)(?=\))/)[0]) as String).split(","));
}else {
return obj[next];
}
}

///////////////////////////////////////////////////////////////////////////////
// Exposed functions
///////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 0dcc82e

Please sign in to comment.