Skip to content

Instantly share code, notes, and snippets.

@triptych
Created April 13, 2011 19:12
Show Gist options
  • Select an option

  • Save triptych/918184 to your computer and use it in GitHub Desktop.

Select an option

Save triptych/918184 to your computer and use it in GitHub Desktop.
renderUI: function(){
Y.log("IB: Panel: renderUI called");
var tgtNode = this.get("srcNode");
var frameId = this.get("frameId");
tgtNode.setStyles({
overflow:"hidden",
height: "0px",
opacity: 0
});
var ifr = Y.Node.create('<iframe id="'+frameId+'" src="javascript:0" name="ibframe" scrollbar="no" frameborder="no"></iframe>');
tgtNode.appendChild(ifr);
var ifrNode = Y.Node.getDOMNode(ifr);
var ifrNodeDoc = ifrNode.contentWindow.document;
var content = this.get("content");
// for Firefox
ifrNodeDoc.open().close();
this.set("innerFrameYUI",
YUI({
win:ifrNode.contentWindow,
doc:ifrNode.contentWindow.document
})
);
ifYUI = this.get('innerFrameYUI');
ifYUI.use('node','event', 'event-custom', function(theFrame){
//var rootEl = theFrame.one("body");
Y.log("in ifYUI.use");
Y.log("frameId:" + frameId);
//Y.log(content)
//rootEl.appendChild(content);
Y.namespace("ibiframe");
Y.ibiframe = {
rootEl: theFrame.one("body"),
headEl: theFrame.one("head"),
setFrame: function(val){
Y.log("IB: in ifYUI listening to ib:setframe");
// step 1 : if we have a string convert to a node
if(Y.Lang.isString(val)){
Y.log("it's a string - make it a Node");
val = Y.Node.create(val);
}
// step 2: insert the node
Y.ibiframe.rootEl.setContent("");
Y.ibiframe.rootEl.appendChild(val.cloneNode(true));// get around different origin policy chrome
// step 3: apply styles and js to head
Y.ibiframe.headEl.appendChild(val.one(".ib_stylesheet"));
var scriptSrc = val.one(".ib_script").get("src");
var module = theFrame.one(".ibmodule");
Y.Get.script(scriptSrc, {
onSuccess: function(o){
Y.log("Y.Get.script success!");
val.one(".ib_script").remove(); //kill this script node now that we have obtained its src value
//this is hacky but we dont have "load" events for CSS in FF and Safari :(
Y.later(100, o.data.module, function(){
Y.Global.fire("ib:setframedone", {
docHeight:this.get("offsetHeight") + 10 ,
docWidth: this.get("offsetWidth"),
frameId: frameId
});
});
},
onFailure: function(){
Y.log("Y.Get.script failure!")
},
win: ifrNode.contentWindow,
data: {
module: module
}
});
},
captureClicks: function(){
Y.log("captureClicks");
//Y.log(Y.ibiframe.rootEl.all("a"));
Y.ibiframe.rootEl.all("a").on("click",function(e){
e.preventDefault();
Y.log("ib:captureclicks click event");
Y.log(e.target.get("tagName"));
var tgtNode = e.target;
if(tgtNode.get("tagName") != "A"){
tgtNode = e.target.ancestor("a");
}
Y.log(tgtNode.get("href"));
})
},
bindings: function(){
//bindings
Y.log("IB: Y.ibiframe.bindings");
Y.Global.on("ib:setframe", Y.ibiframe.setFrame);
Y.on("domready", function(){
Y.log("IB: ibiframe bindings domready");
Y.ibiframe.captureClicks();
});
//capture clicks
Y.log(Y.ibiframe);
},
init: function(){
Y.log("Y.ibiframe.init called");
Y.ibiframe.bindings();
}
}
Y.ibiframe.init();
});
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment