Added code to read postMessage from CKan template in oder to set iFrame height after page loading
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@130454 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
420ee338f4
commit
cc169e6d6a
|
@ -161,12 +161,12 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
|
|||
updateSize();
|
||||
}
|
||||
});
|
||||
Window.enableScrolling(false);
|
||||
// Window.enableScrolling(false);
|
||||
rootPanel.add(loading);
|
||||
rootPanel.add(this);
|
||||
updateSize();
|
||||
|
||||
// listenForPostMessage();
|
||||
listenForPostMessage();
|
||||
// postMessage("Un messaggio");
|
||||
}
|
||||
|
||||
|
@ -257,11 +257,81 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
|
|||
int height = rootHeight - getTopPanelHeight();
|
||||
if (this.ckanFramePanel.getFrame() != null) {
|
||||
int newH = this.managementPanel != null &&this.managementPanel.getCurrentHeight() > 0? this.managementPanel.getOffsetHeight() + height : height;
|
||||
this.ckanFramePanel.getFrame().setHeight(newH + "px");
|
||||
// this.ckanFramePanel.getFrame().setHeight(newH + "px");
|
||||
}
|
||||
// workspace.setHeight(height+"px");
|
||||
}
|
||||
|
||||
/**
|
||||
* Post message.
|
||||
*
|
||||
* @param msg the msg
|
||||
*/
|
||||
protected native void postMessage(String msg) /*-{
|
||||
$wnd.postMessage(msg, "*");
|
||||
}-*/;
|
||||
|
||||
/**
|
||||
* Listen for post message.
|
||||
*/
|
||||
private final native void listenForPostMessage() /*-{
|
||||
var that = this;
|
||||
$wnd.addEventListener("message", function(msg) {
|
||||
console.log("read message...");
|
||||
that.@org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view.GCubeCkanDataCatalogPanel::onPostMessage(Ljava/lang/String;Ljava/lang/String;)(msg.data, msg.origin);
|
||||
});
|
||||
}-*/;
|
||||
|
||||
/**
|
||||
* On post message.
|
||||
*
|
||||
* @param data the data
|
||||
* @param origin the origin
|
||||
*/
|
||||
private void onPostMessage(String data, String origin) {
|
||||
GWT.log("Read data: "+data+", from origin: "+origin);
|
||||
GWT.log("Ckan base url: "+ckanAccessPoint.getBaseUrl());
|
||||
|
||||
if (ckanAccessPoint.getBaseUrl().indexOf(origin)>=0) {
|
||||
GWT.log("Data has been sent by ckan "+origin +", Is it the height?");
|
||||
// The data has been sent from your site
|
||||
// The data sent with postMessage is stored in event.data
|
||||
setIFrameHeight(data);
|
||||
} else {
|
||||
// The data hasn't been sent from your site!
|
||||
// Be careful! Do not use it.
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the i frame height.
|
||||
*
|
||||
* @param height the new i frame height
|
||||
*/
|
||||
private void setIFrameHeight(String height){
|
||||
String parsedHeight = null;
|
||||
if(height==null || height.isEmpty())
|
||||
return;
|
||||
|
||||
if(height.contains("px")){
|
||||
parsedHeight = height;
|
||||
}else{
|
||||
try{
|
||||
int intH = Integer.parseInt(height);
|
||||
parsedHeight = intH + " px";
|
||||
}catch(Exception e ){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(parsedHeight!=null){
|
||||
GWT.log("Setting new height for ckan iFrame: "+height);
|
||||
this.ckanFramePanel.getFrame().setHeight(height);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the base urlckan connector.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue