Skip to content
This repository has been archived by the owner on Mar 23, 2019. It is now read-only.

Commit

Permalink
Make source Bindable. Update source value by checking the iframe in j…
Browse files Browse the repository at this point in the history
…avascript. Feature is subject to browser cross-domain restrictions.
  • Loading branch information
bithooked committed Jan 8, 2012
1 parent 2568578 commit 1c9ad0e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
28 changes: 26 additions & 2 deletions library/src/com/google/code/flexiframe/IFrame.as
Expand Up @@ -28,7 +28,7 @@ package com.google.code.flexiframe
import flash.geom.Point;
import flash.utils.Dictionary;
import flash.utils.getQualifiedClassName;

import mx.controls.ToolTip;
import mx.core.Application;
import mx.core.Container;
Expand Down Expand Up @@ -519,7 +519,14 @@ package com.google.code.flexiframe
logger.debug("frame id {0} calling queued function {1}", _frameId, queuedCall.functionName);
this.callIFrameFunction(queuedCall.functionName, queuedCall.args, queuedCall.callback);
}
dispatchEvent(new Event("frameLoad"));

var newSource:String = getBrowserSource();
if (newSource && newSource != "" && newSource != source) {
_source = newSource;
dispatchEvent(new Event("browserSourceChanged"));
}

dispatchEvent(new Event("frameLoad"));

invalidateDisplayList();
}
Expand Down Expand Up @@ -597,6 +604,7 @@ package com.google.code.flexiframe
if (source)
{
_source=source;
dispatchEvent(new Event("browserSourceChanged"));

// mark unloaded now so calls in this frame will be queued
_frameLoaded=false;
Expand All @@ -610,6 +618,7 @@ package com.google.code.flexiframe
/**
* Return url of frame contents
*/
[Bindable (event="browserSourceChanged")]
public function get source():String
{
return _source;
Expand Down Expand Up @@ -1217,6 +1226,7 @@ package com.google.code.flexiframe
ExternalInterface.call(IFrameExternalCalls.INSERT_FUNCTION_PRINT_IFRAME);
ExternalInterface.call(IFrameExternalCalls.INSERT_FUNCTION_HISTORY_BACK);
ExternalInterface.call(IFrameExternalCalls.INSERT_FUNCTION_HISTORY_FORWARD);
ExternalInterface.call(IFrameExternalCalls.INSERT_FUNCTION_GET_SOURCE);

// Resolve the SWF embed object id in the DOM.
ExternalInterface.call(IFrameExternalCalls.INSERT_FUNCTION_ASK_FOR_EMBED_OBJECT_ID);
Expand Down Expand Up @@ -1341,6 +1351,20 @@ package com.google.code.flexiframe
}
return new Number(0);
}

/**
* Get the browser source.
*/
protected function getBrowserSource():String
{
logger.info("Get browser source.");
var result:Object = ExternalInterface.call(IFrameExternalCalls.FUNCTION_GET_SOURCE, _iframeId);
if (result != null)
{
return result as String;
}
return "";
}

/**
* Setup the Browser resize event listener.
Expand Down
23 changes: 23 additions & 0 deletions library/src/com/google/code/flexiframe/IFrameExternalCalls.as
Expand Up @@ -528,6 +528,29 @@ package com.google.code.flexiframe
"}" +
"}" +
"}";



/**
* The name of the JavaScript function that hides a Div.
*/
public static var FUNCTION_GET_SOURCE:String = "getSource";


/**
* The Javascript code to call to insert the function that returns the IFrame's source.
*/
public static var INSERT_FUNCTION_GET_SOURCE:String =
"document.insertScript = function () " +
"{ " +
"if (document." + FUNCTION_GET_SOURCE + "==null) " +
"{ " +
FUNCTION_GET_SOURCE + " = function(iframeID) " +
"{ " +
"return document.getElementById(iframeID).contentDocument.URL; " +
"} " +
"} " +
"}";

}
}

0 comments on commit 1c9ad0e

Please sign in to comment.