From b1591a2e140bcb6d88fcb835ce4addb3a43aac1e Mon Sep 17 00:00:00 2001 From: Justin Cataldo Date: Wed, 4 Jan 2012 09:33:00 -0500 Subject: [PATCH 1/4] Add channelUrl option for xd communication using fragment --- README.md | 3 ++- ig-min.js | 26 +------------------------- ig.js | 6 +++--- 3 files changed, 6 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index c35051e..6d666ba 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,8 @@ SDK Usage Examples IG.init({ client_id: YOUR_CLIENT_ID, check_status: true, // check and load active session - cookie: true // persist a session via cookie + cookie: true, // persist a session via cookie + channelUrl: http:///channel.html }); // client side access_token flow (implicit) diff --git a/ig-min.js b/ig-min.js index d2ec866..09616c4 100644 --- a/ig-min.js +++ b/ig-min.js @@ -1,25 +1 @@ -if(!window.IG){window.IG={_client_id:null,_session:null,_userStatus:"unknown",_logging:false,_domain:{https_com:"https://instagram.com/",api:"http://api.instagram.com/"},getDomain:function(a){switch(a){case "https_com":return IG._domain.https_com;case "api":return IG._domain.api}},provide:function(a,d){return IG.copy(IG.create(a),d)},copy:function(a,d){for(var b in d)if(d.hasOwnProperty(b))if(typeof a[b]==="undefined")a[b]=d[b];return a},create:function(a,d){var b=window.IG,e=a?a.split("."):[],f= -e.length,g;for(g=0;g';a.root.innerHTML='';b=true;window.setTimeout(function(){a.root.innerHTML= -f},0)}else{var g=document.createElement("iframe");g.id=a.id;g.name=a.name;g.onload=IG.Content._callbacks[d];g.scrolling="no";g.style.border="none";g.style.overflow="hidden";if(a.title)g.title=a.title;if(a.className)g.className=a.className;if(a.height)g.height=a.height;if(a.width)g.width=a.width;a.root.appendChild(g);b=true;g.src=a.url}}});IG.provide("JSON",{stringify:function(a){return window.Prototype&&Object.toJSON?Object.toJSON(a):JSON.stringify(a)},parse:function(a){return JSON.parse(a)},flatten:function(a){var d= -{},b;for(b in a)if(a.hasOwnProperty(b)){var e=a[b];if(typeof e==="string"&&b!==null)d[b]=e;else if(e!==null&&e!==undefined)d[b]=IG.JSON.stringify(e)}return d}});IG.provide("EventProvider",{subscribers:function(){if(!this._subscribersMap)this._subscribersMap={};return this._subscribersMap},subscribe:function(a,d){IG.log("Subscription to: "+a);var b=this.subscribers();if(b[a])b[a].push(d);else b[a]=[d]},unsubscribe:function(a,d){var b=this.subscribers()[a];IG.Array.forEach(b,function(e,f){if(e===d)b[f]= -null})},monitor:function(a,d){if(!d()){var b=this,e=function(){d.apply(d,arguments)&&b.unsubscribe(a,e)};this.subscribe(a,e)}},clear:function(a){delete this.subscribers()[a]},fire:function(){var a=Array.prototype.slice.call(arguments),d=a.shift();IG.log("Fire for: "+d);IG.Array.forEach(this.subscribers()[d],function(b){b&&b.apply(this,a)})}});IG.provide("Event",IG.EventProvider);IG.provide("XD",{_origin:null,_transport:null,_callbacks:{},init:function(){if(IG.XD._origin)IG.log('XD.init called with "XD._origin" already set. Returning.'); -else if(window.addEventListener&&!window.attachEvent&&window.postMessage){IG.log('Using "postmessage" as XD transport.');IG.XD._origin=window.location.protocol+"//"+window.location.host+"/"+IG.guid();IG.XD.PostMessage.init();IG.XD._transport="postmessage"}else{IG.log('Using "fragment" as XD transport.');IG.XD._transport="fragment";IG.XD.Fragment._channelUrl=window.location.toString()}},resolveRelation:function(a){var d=a.split("."),b=window,e,f;f=0;for(num_relations=d.length;f0)return"javascript:false;//";var b=IG.getDomain("https_com")+"oauth/xd_proxy/#",e=IG.guid();if(IG.XD._transport==="fragment"){b=IG.XD.Fragment._channelUrl;var f=b.indexOf("#");if(f> -0)b=b.substr(0,f);b+=(b.indexOf("?")<0?"?":"&")+IG.XD.Fragment._magic+"#?=&"}IG.XD._callbacks[e]=a;return b+IG.QS.encode({cb:e,origin:IG.XD._origin,relation:d||"opener",transport:IG.XD._transport})},recv:function(a){if(typeof a==="string")a=IG.QS.decode(a);var d=IG.XD._callbacks[a.cb];delete IG.XD._callbacks[a.cb];d&&d(a)},PostMessage:{init:function(){var a=IG.XD.PostMessage.onMessage;window.addEventListener?window.addEventListener("message",a,false):window.attachEvent("onmessage",a)},onMessage:function(a){IG.XD.recv(a.data)}}, -Fragment:{_magic:"ig_xd_fragment",checkAndDispatch:function(){var a=window.location.toString(),d=a.substr(a.indexOf("#")+1);if(a.indexOf(IG.XD.Fragment._magic)>0){IG.init=function(){};document.documentElement.style.display="none";IG.XD.resolveRelation(IG.QS.decode(d).relation).IG.XD.recv(d)}}}});IG.XD.Fragment.checkAndDispatch();IG.provide("",{ui:function(a,d){var b=IG.UIServer.prepareCall(a,d);if(b){var e=IG.UIServer[b.params.display];e?e(b):IG.log('"display" must be "popup"')}else IG.log('"prepareCall" failed to return options')}}); -IG.provide("UIServer",{Methods:{},_active:{},_defaultCb:{},prepareCall:function(a,d){var b=a.method.toLowerCase(),e=IG.UIServer.Methods[b];b=IG.guid();IG.copy(a,{client_id:IG._client_id,access_token:IG._session&&IG._session.access_token||undefined});a.display=IG.UIServer.getDisplayMode(e,a);b={callback:d,id:b,size:e.size||{},url:e.url,params:a};if(e.transform){b=e.transform(b);if(!b){IG.log('Call to "transform" in "prepareCall" failed to return options');return}}e=IG.UIServer.getXdRelation(b.params.display); -b.params.redirect_uri=IG.UIServer._xdResult(b.callback,b.id,e,true);b.params=IG.JSON.flatten(b.params);if(e=IG.QS.encode(b.params))b.url+="?"+e;return b},getDisplayMode:function(a,d){if(d.display==="hidden")return"hidden";return"popup"},getXdRelation:function(a){if(a==="popup")return"opener"},popup:function(a){var d=typeof window.screenX!=="undefined"?window.screenX:window.screenLeft,b=typeof window.screenY!=="undefined"?window.screenY:window.screenTop,e=typeof window.outerHeight!=="undefined"?window.outerHeight: -document.documentElement.clientHeight-22,f=a.size.width,g=a.size.height;d=parseInt((d<0?window.screen.width+d:d)+((typeof window.outerWidth!=="undefined"?window.outerWidth:document.documentElement.clientWidth)-f)/2,10);b=parseInt(b+(e-g)/2.5,10);f="width="+f+",height="+g+",left="+d+",top="+b+",scrollbars=1,location=1,toolbar=0";IG.log("opening popup: "+a.id);IG.UIServer._active[a.id]=window.open(a.url,a.id,f)},hidden:function(a){a.className="IG_UI_Hidden";a.root=IG.Content.appendHidden("");IG.UIServer._insertIframe(a)}, -_insertIframe:function(a){IG.UIServer._active[a.id]=false;IG.Content.insertIframe({url:a.url,root:a.root,className:a.className,width:a.size.width,height:a.size.height,onload:function(d){if(IG.UIServer._active.hasOwnProperty(a.id))IG.UIServer._active[a.id]=d}})},_xdRedirectUriHandler:function(a,d,b,e){if(e)IG.UIServer._defaultCb[d]=a;return IG.XD.handler(function(f){IG.UIServer._xdRecv(f,a)},b)+"&frame="+d},_xdRecv:function(a,d){var b=IG.UIServer._active[a.frame];try{b.close&&b.close()}catch(e){}delete IG.UIServer._active[a.frame]; -delete IG.UIServer._defaultCb[a.frame];d(a)},_xdResult:function(a,d,b,e){return IG.UIServer._xdRedirectUriHandler(function(f){a&&f.result&&a(IG.JSON.parse(f.result))},d,b,e)}});IG.provide("",{getLoginStatus:function(a,d){if(IG._client_id){if(a)if(!d&&IG.Auth._loadState==="loaded"){a({status:IG._userStatus,session:IG._session});return}else IG.Event.subscribe("IG.loginStatus",a);if(!(!d&&IG.Auth._loadState==="loading")){IG.Auth._loadState="loading";IG.ui({method:"auth.status",display:"hidden"},function(b){IG.Auth._loadState= -"loaded";IG.Event.fire("IG.loginStatus",b);IG.Event.clear("IG.loginStatus")})}}else IG.log("IG.getLoginStatus() called before calling IG.init().")},login:function(a,d){IG.ui(IG.copy({display:"popup",method:"authorize"},d||{}),a)},logout:function(){IG.Auth.setSession()}});IG.provide("Auth",{setSession:function(a,d){var b=!IG._session&&a,e=IG._session&&!a,f=b||e||IG._session&&a&&IG._session.access_token!==a.access_token,g=d!==IG._userStatus,h={session:a,status:d};IG._session=a;IG._userStatus=d;f&&IG.Cookie.getEnabled()&& -IG.Cookie.set(a);g&&IG.Event.fire("auth.statusChange",h);b&&IG.Event.fire("auth.login",h);e&&IG.Event.fire("auth.logout",h);f&&IG.Event.fire("auth.sessionChange",h);return h},xdHandler:function(a,d,b,e,f,g){return IG.UIServer._xdRedirectUriHandler(IG.Auth.xdResponseWrapper(a,f,g),d,b,e)},xdResponseWrapper:function(a,d,b){return function(e){try{b=IG.JSON.parse(e.session||null);b.scope=IG.JSON.parse(e.scope||null)}catch(f){}if(b)d="connected";var g=IG.Auth.setSession(b||null,d),h=["code","error","error_reason", -"error_description"];e&&IG.Array.forEach(h,function(i){g[i]=e[i]||null});a&&a(g)}}});IG.provide("UIServer.Methods",{authorize:{size:{width:627,height:326},url:IG.getDomain("https_com")+"oauth/authorize/",transform:function(a){if(IG._client_id){if(IG._session){var d=false;IG.Array.forEach(a.params.scope,function(b){if(IG._session.scope.indexOf(b)===-1)d=true});if(!d){IG.log("IG.login() called when user is already connected.");if(a.callback){a.callback({status:IG._userStatus,session:IG._session});return}}}a.callback= -IG.Auth.xdResponseWrapper(a.callback);if(a.params.scope)a.params.scope=a.params.scope.join(" ");IG.copy(a.params,{response_type:"token"});return a}else IG.log("IG.login() called before claling IG.init().")}},"auth.status":{url:IG.getDomain("https_com")+"oauth/login_status/",transform:function(a){var d=a.callback;delete a.callback;IG.copy(a.params,{no_session:IG.Auth.xdHandler(d,a.id,"parent",false,"notConnected"),no_user:IG.Auth.xdHandler(d,a.id,"parent",false,"unknown"),ok_session:IG.Auth.xdHandler(d, -a.id,"parent",false,"connected")});return a}}});IG.provide("Cookie",{_domain:null,_enabled:false,setEnabled:function(a){IG.Cookie._enabled=a},getEnabled:function(){return IG.Cookie._enabled},load:function(){var a=document.cookie.match("\\bigs_"+IG._client_id+'="([^;]*)\\b'),d;if(a){d=IG.QS.decode(a[1]);if(d.expires)d.expires=parseInt(d.expires,10);IG.Cookie._domain=d.base_domain}return d},setRaw:function(a,d,b){document.cookie="igs_"+IG._client_id+'="'+a+'"'+(a&&d===0?"":"; expires="+(new Date(d* -1E3)).toGMTString())+"; path=/"+(b?"; domain=."+b:"");IG.Cookie._domain=b},set:function(a){a?IG.Cookie.setRaw(IG.QS.encode(a),a.expires,a.base_domain):IG.Cookie.clear()},clear:function(){IG.Cookie.setRaw("",0,IG.Cookie._domain)}});IG.provide("",{init:function(a){a=IG.copy(a||{},{logging:false,check_status:true});IG._client_id=a.client_id;IG._logging=a.logging||typeof a.logging==="undefined"&&window.location.toString().indexOf("ig_debug=1")>0;IG.XD.init();if(IG._client_id){IG.Cookie.setEnabled(a.cookie); -a.session=a.session||a.cookie&&IG.Cookie.load();IG.Auth.setSession(a.session);a.check_status&&IG.getLoginStatus()}}});window.setTimeout(function(){if(window.igAsyncInit&&!window.igAsyncInit.hasRun){window.igAsyncInit.hasRun=true;igAsyncInit()}},0)}; \ No newline at end of file +window.IG||(window.IG={_client_id:null,_session:null,_userStatus:"unknown",_logging:!1,_domain:{https_com:"https://instagram.com/",api:"http://api.instagram.com/"},getDomain:function(a){switch(a){case"https_com":return IG._domain.https_com;case"api":return IG._domain.api}},provide:function(a,b){return IG.copy(IG.create(a),b)},copy:function(a,b){var c;for(c in b)b.hasOwnProperty(c)&&typeof a[c]=="undefined"&&(a[c]=b[c]);return a},create:function(a,b){var c=window.IG,d=a?a.split("."):[],e=d.length,f;for(f=0;f";a.root.innerHTML='',c=!0,window.setTimeout(function(){a.root.innerHTML=e},0)}else{var f=document.createElement("iframe");f.id=a.id,f.name=a.name,f.onload=IG.Content._callbacks[b],f.scrolling="no",f.style.border="none",f.style.overflow="hidden",a.title&&(f.title=a.title),a.className&&(f.className=a.className),a.height&&(f.height=a.height),a.width&&(f.width=a.width),a.root.appendChild(f),c=!0,f.src=a.url}}}),IG.provide("JSON",{stringify:function(a){return window.Prototype&&Object.toJSON?Object.toJSON(a):JSON.stringify(a)},parse:function(a){return JSON.parse(a)},flatten:function(a){var b={},c;for(c in a)if(a.hasOwnProperty(c)){var d=a[c];typeof d=="string"&&c!==null?b[c]=d:d!==null&&d!==undefined&&(b[c]=IG.JSON.stringify(d))}return b}}),IG.provide("EventProvider",{subscribers:function(){return this._subscribersMap||(this._subscribersMap={}),this._subscribersMap},subscribe:function(a,b){IG.log("Subscription to: "+a);var c=this.subscribers();c[a]?c[a].push(b):c[a]=[b]},unsubscribe:function(a,b){var c=this.subscribers()[a];IG.Array.forEach(c,function(a,d){a===b&&(c[d]=null)})},monitor:function(a,b){if(!b()){var c=this,d=function(){b.apply(b,arguments)&&c.unsubscribe(a,d)};this.subscribe(a,d)}},clear:function(a){delete this.subscribers()[a]},fire:function(){var a=Array.prototype.slice.call(arguments),b=a.shift();IG.log("Fire for: "+b),IG.Array.forEach(this.subscribers()[b],function(b){b&&b.apply(this,a)})}}),IG.provide("Event",IG.EventProvider),IG.provide("XD",{_origin:null,_transport:null,_callbacks:{},init:function(a){if(IG.XD._origin){IG.log('XD.init called with "XD._origin" already set. Returning.');return}window.addEventListener&&!window.attachEvent&&window.postMessage?(IG.log('Using "postmessage" as XD transport.'),IG.XD._origin=window.location.protocol+"//"+window.location.host+"/"+IG.guid(),IG.XD.PostMessage.init(),IG.XD._transport="postmessage"):(IG.log('Using "fragment" as XD transport.'),IG.XD._transport="fragment",IG.XD.Fragment._channelUrl=a||window.location.toString())},resolveRelation:function(a){var b=a.split("."),c=window,d,e;for(e=0,num_relations=b.length;e0)return"javascript:false;//";var c=IG.getDomain("https_com")+"oauth/xd_proxy/#",d=IG.guid();if(IG.XD._transport==="fragment"){c=IG.XD.Fragment._channelUrl;var e=c.indexOf("#");e>0&&(c=c.substr(0,e)),c+=(c.indexOf("?")<0?"?":"&")+IG.XD.Fragment._magic+"#?=&"}return IG.XD._callbacks[d]=a,c+IG.QS.encode({cb:d,origin:IG.XD._origin,relation:b||"opener",transport:IG.XD._transport})},recv:function(a){typeof a=="string"&&(a=IG.QS.decode(a));var b=IG.XD._callbacks[a.cb];delete IG.XD._callbacks[a.cb],b&&b(a)},PostMessage:{init:function(){var a=IG.XD.PostMessage.onMessage;window.addEventListener?window.addEventListener("message",a,!1):window.attachEvent("onmessage",a)},onMessage:function(a){IG.XD.recv(a.data)}},Fragment:{_magic:"ig_xd_fragment",checkAndDispatch:function(){var a=window.location.toString(),b=a.substr(a.indexOf("#")+1),c=a.indexOf(IG.XD.Fragment._magic);c>0&&(IG.init=function(){},document.documentElement.style.display="none",IG.XD.resolveRelation(IG.QS.decode(b).relation).IG.XD.recv(b))}}}),IG.XD.Fragment.checkAndDispatch(),IG.provide("",{ui:function(a,b){var c=IG.UIServer.prepareCall(a,b);if(!c){IG.log('"prepareCall" failed to return options');return}var d=c.params.display,e=IG.UIServer[d];if(!e){IG.log('"display" must be "popup"');return}e(c)}}),IG.provide("UIServer",{Methods:{},_active:{},_defaultCb:{},prepareCall:function(a,b){var c=a.method.toLowerCase(),d=IG.UIServer.Methods[c],e=IG.guid();IG.copy(a,{client_id:IG._client_id,access_token:IG._session&&IG._session.access_token||undefined}),a.display=IG.UIServer.getDisplayMode(d,a);var f={callback:b,id:e,size:d.size||{},url:d.url,params:a};if(d.transform){f=d.transform(f);if(!f){IG.log('Call to "transform" in "prepareCall" failed to return options');return}}var g=IG.UIServer.getXdRelation(f.params.display);f.params.redirect_uri=IG.UIServer._xdResult(f.callback,f.id,g,!0),f.params=IG.JSON.flatten(f.params);var h=IG.QS.encode(f.params);return h&&(f.url+="?"+h),f},getDisplayMode:function(a,b){return b.display==="hidden"?"hidden":"popup"},getXdRelation:function(a){if(a==="popup")return"opener"},popup:function(a){var b=typeof window.screenX!="undefined"?window.screenX:window.screenLeft,c=typeof window.screenY!="undefined"?window.screenY:window.screenTop,d=typeof window.outerWidth!="undefined"?window.outerWidth:document.documentElement.clientWidth,e=typeof window.outerHeight!="undefined"?window.outerHeight:document.documentElement.clientHeight-22,f=a.size.width,g=a.size.height,h=b<0?window.screen.width+b:b,i=parseInt(h+(d-f)/2,10),j=parseInt(c+(e-g)/2.5,10),k="width="+f+",height="+g+",left="+i+",top="+j+",scrollbars=1,location=1,toolbar=0";IG.log("opening popup: "+a.id),IG.UIServer._active[a.id]=window.open(a.url,a.id,k)},hidden:function(a){a.className="IG_UI_Hidden",a.root=IG.Content.appendHidden(""),IG.UIServer._insertIframe(a)},_insertIframe:function(a){IG.UIServer._active[a.id]=!1;var b=function(b){IG.UIServer._active.hasOwnProperty(a.id)&&(IG.UIServer._active[a.id]=b)};IG.Content.insertIframe({url:a.url,root:a.root,className:a.className,width:a.size.width,height:a.size.height,onload:b})},_xdRedirectUriHandler:function(a,b,c,d){return d&&(IG.UIServer._defaultCb[b]=a),IG.XD.handler(function(b){IG.UIServer._xdRecv(b,a)},c)+"&frame="+b},_xdRecv:function(a,b){var c=IG.UIServer._active[a.frame];try{c.close&&c.close()}catch(d){}delete IG.UIServer._active[a.frame],delete IG.UIServer._defaultCb[a.frame],b(a)},_xdResult:function(a,b,c,d){return IG.UIServer._xdRedirectUriHandler(function(b){a&&b.result&&a(IG.JSON.parse(b.result))},b,c,d)}}),IG.provide("",{getLoginStatus:function(a,b){if(!IG._client_id){IG.log("IG.getLoginStatus() called before calling IG.init().");return}if(a){if(!b&&IG.Auth._loadState==="loaded"){a({status:IG._userStatus,session:IG._session});return}IG.Event.subscribe("IG.loginStatus",a)}if(!b&&IG.Auth._loadState==="loading")return;IG.Auth._loadState="loading";var c=function(a){IG.Auth._loadState="loaded",IG.Event.fire("IG.loginStatus",a),IG.Event.clear("IG.loginStatus")};IG.ui({method:"auth.status",display:"hidden"},c)},login:function(a,b){IG.ui(IG.copy({display:"popup",method:"authorize"},b||{}),a)},logout:function(a){IG.Auth.setSession()}}),IG.provide("Auth",{setSession:function(a,b){var c=!IG._session&&a,d=IG._session&&!a,e=c||d||IG._session&&a&&IG._session.access_token!==a.access_token,f=b!==IG._userStatus,g={session:a,status:b};return IG._session=a,IG._userStatus=b,e&&IG.Cookie.getEnabled()&&IG.Cookie.set(a),f&&IG.Event.fire("auth.statusChange",g),c&&IG.Event.fire("auth.login",g),d&&IG.Event.fire("auth.logout",g),e&&IG.Event.fire("auth.sessionChange",g),g},xdHandler:function(a,b,c,d,e,f){return IG.UIServer._xdRedirectUriHandler(IG.Auth.xdResponseWrapper(a,e,f),b,c,d)},xdResponseWrapper:function(a,b,c){return function(d){try{c=IG.JSON.parse(d.session||null),c.scope=IG.JSON.parse(d.scope||null)}catch(e){}c&&(b="connected");var f=IG.Auth.setSession(c||null,b),g=["code","error","error_reason","error_description"];d&&IG.Array.forEach(g,function(a){f[a]=d[a]||null}),a&&a(f)}}}),IG.provide("UIServer.Methods",{authorize:{size:{width:627,height:326},url:IG.getDomain("https_com")+"oauth/authorize/",transform:function(a){if(!IG._client_id){IG.log("IG.login() called before claling IG.init().");return}if(IG._session){var b=!1;IG.Array.forEach(a.params.scope,function(a){IG._session.scope.indexOf(a)===-1&&(b=!0)});if(!b){IG.log("IG.login() called when user is already connected.");if(a.callback){a.callback({status:IG._userStatus,session:IG._session});return}}}return a.callback=IG.Auth.xdResponseWrapper(a.callback),a.params.scope&&(a.params.scope=a.params.scope.join(" ")),IG.copy(a.params,{response_type:"token"}),a}},"auth.status":{url:IG.getDomain("https_com")+"oauth/login_status/",transform:function(a){var b=a.callback,c=a.id;return delete a.callback,IG.copy(a.params,{no_session:IG.Auth.xdHandler(b,a.id,"parent",!1,"notConnected"),no_user:IG.Auth.xdHandler(b,a.id,"parent",!1,"unknown"),ok_session:IG.Auth.xdHandler(b,a.id,"parent",!1,"connected")}),a}}}),IG.provide("Cookie",{_domain:null,_enabled:!1,setEnabled:function(a){IG.Cookie._enabled=a},getEnabled:function(){return IG.Cookie._enabled},load:function(){var a=document.cookie.match("\\bigs_"+IG._client_id+'="([^;]*)\\b'),b;return a&&(b=IG.QS.decode(a[1]),b.expires&&(b.expires=parseInt(b.expires,10)),IG.Cookie._domain=b.base_domain),b},setRaw:function(a,b,c){document.cookie="igs_"+IG._client_id+'="'+a+'"'+(a&&b===0?"":"; expires="+(new Date(b*1e3)).toGMTString())+"; path=/"+(c?"; domain=."+c:""),IG.Cookie._domain=c},set:function(a){a?IG.Cookie.setRaw(IG.QS.encode(a),a.expires,a.base_domain):IG.Cookie.clear()},clear:function(){IG.Cookie.setRaw("",0,IG.Cookie._domain)}}),IG.provide("",{init:function(a){a=IG.copy(a||{},{logging:!1,check_status:!0}),IG._client_id=a.client_id,IG._logging=a.logging||typeof a.logging=="undefined"&&window.location.toString().indexOf("ig_debug=1")>0,IG.XD.init(a.channelUrl),IG._client_id&&(IG.Cookie.setEnabled(a.cookie),a.session=a.session||a.cookie&&IG.Cookie.load(),IG.Auth.setSession(a.session),a.check_status&&IG.getLoginStatus())}}),window.setTimeout(function(){window.igAsyncInit&&!window.igAsyncInit.hasRun&&(window.igAsyncInit.hasRun=!0,igAsyncInit())},0)); \ No newline at end of file diff --git a/ig.js b/ig.js index b486064..09a0949 100644 --- a/ig.js +++ b/ig.js @@ -315,7 +315,7 @@ if (!window.IG) { _origin: null, _transport: null, _callbacks: {}, - init: function () { + init: function (channelUrl) { if (IG.XD._origin) { IG.log('XD.init called with "XD._origin" already set. Returning.'); return; @@ -329,7 +329,7 @@ if (!window.IG) { } else { IG.log('Using "fragment" as XD transport.'); IG.XD._transport = 'fragment'; - IG.XD.Fragment._channelUrl = window.location.toString(); + IG.XD.Fragment._channelUrl = channelUrl || window.location.toString(); } }, resolveRelation: function (relation) { @@ -777,7 +777,7 @@ if (!window.IG) { IG._client_id = settings.client_id; IG._logging = settings.logging || (typeof settings.logging === 'undefined' && window.location.toString().indexOf('ig_debug=1') > 0); - IG.XD.init(); + IG.XD.init(settings.channelUrl); if (IG._client_id) { IG.Cookie.setEnabled(settings.cookie); From c4c7e8740f89b422427053983b84ae1539629f42 Mon Sep 17 00:00:00 2001 From: Justin Cataldo Date: Fri, 13 Jan 2012 09:56:51 -0500 Subject: [PATCH 2/4] update readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d666ba..d430917 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ SDK Usage Examples client_id: YOUR_CLIENT_ID, check_status: true, // check and load active session cookie: true, // persist a session via cookie - channelUrl: http:///channel.html + channelUrl: http:///channel.html // Note: You have to set your website in the client settings to match this url }); // client side access_token flow (implicit) @@ -41,6 +41,7 @@ SDK Usage Examples } }, {response_type: 'code', scope: ['comments', 'likes']}); + Contributing ------------ In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project. From 51b055417b317584a4dc258f2141e6fef287e2cd Mon Sep 17 00:00:00 2001 From: Justin Cataldo Date: Fri, 13 Jan 2012 10:03:26 -0500 Subject: [PATCH 3/4] update readme --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d430917..6ecc91f 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ SDK Usage Examples client_id: YOUR_CLIENT_ID, check_status: true, // check and load active session cookie: true, // persist a session via cookie - channelUrl: http:///channel.html // Note: You have to set your website in the client settings to match this url + channelUrl: http:///channel.html // You have to set your website in the client settings to match this url }); // client side access_token flow (implicit) @@ -41,6 +41,14 @@ SDK Usage Examples } }, {response_type: 'code', scope: ['comments', 'likes']}); +Channel File Example +------------------ +The channel file helps addresses issues with cross domain communication in certain browsers. + +Include the sdk in your channel.html file. + +