Facebook SDK inside Firefox (callback from content window to window) - facebook

I’m developing a Firefox addon and I would like to use facebook sdk in it. One of the features that I like to use is the callback that is triggered when a like button is pressed. In detail I mean this one:
FB.Event.subscribe('edge.create', function() {dump("like pressed"); });
Currently I’m doing it this way. I open a layer in the current window with an iframe. That iframe contains the facebook api + the features that I would like to use. My problem is that I can’t call my addons functions from the inside of that iframe. What I would like to do would be something like:
FB.Event.subscribe('edge.create', function() {fbClass.like(); });
In my mind I’ve one idea. I think to make it safe it would be ok to create an empty hidden div container in that iframe, attach an eventlistener to it and fill it with json. Then use firefox safe json loader to receive it.
Any other idea how I could accomplish that one without creating a security issue?
I tried porting the FB api to FF but it leaded into a waste of time. Sure I got some features work but it’s that complex to debug it and in case if the api changes I would have to do it again. So I think the iframe way would be a much better one.

I would suggest to you that use the Add-on SDK makes this task probably easier. You could add your code to the page using PageMod and from the content script calls your addon's function using postMessage. This also helps to you decoupled the content code from the addon code.

Related

Chrome Extension (Content Script) Caching CSS

I'm writing an extremely simple extension which applies some CSS to facebook's root, i.e: http://www.facebook.com/ only. When the user navigates to another page the CSS should not be applied, however it appears that the file is cached and applies to all other pages until a full refresh (F5, etc) is pressed, rendering the extension useless.
Would there be a simple solution to prevent caching for a particular page - or - some javascript to run such as window.reload? This may be a facebook particular issue.
The Google Chrome extension never cache css. Actually, Facebook use Ajax call to update its content. So most of the time you are on the same page with a different content.
The best way to have a local change is to use javascript script with "document_end" injection. You can use DOM events to detect changes.

Cross-domain navigation within Blogger without Javascript

The setup: I have a Blogger blog set up on a domain name as blog.mydomain.com. The main site site at mydomain.com is running Umbraco CMS.
The problem: I need to have the navigation from the CMS transported to Blogger somehow, so that making a change on the main website doesn't require the extra step of modifying the navigation inside Blogger.
Generating the navigation data on the CMS side in what ever format it needs to be (XML, unordered list, JSON, etc) is not a problem. The problem is getting the data from Umbraco to Blogger after it is generated.
I'm not yet willing to use Javascript, as this would seriously impair the website for users browsing without Javascript. (Too bad because AJAX would be a very workable solution.)
I've tossed around the idea of using an iFrame. How would this work for a navigation system including sub-menus? Creating and deleting multiple iframes is out of the picture, since I don't want to use Javascript. I could use one large iframe to allow for the sub-menus, but then it would cover content at the top of the content area, rendering it unclickable.
I'm thinking about how you could do this, but while I do - in this day-and-age javascript has become very common. Most users are going to have it, and those with it disabled really shouldn't be on the web. Is this the only reason you don't want to use javascript? Around 2% according to YDN have js disabled, and that's lower from other countries. As time goes on that 2% should get lower, I don't see that as an issue. However if you absolutely can't use javascript, I'll keep thinking. I might have an idea, I'll need to test it though.
It's not possible to use IFrame, cause of same origin policy. Both sites are on different domains, when user click menu item inside IFrame, there is no way to call parent window.
There are few ways how this can be done.
1) Javascript solution. Use json rpc, or another cross-domain calls. Load menu from your CMS and render it. Yes, this requires javsascript, but, seriously, show me the site, which does not use javascript.
2) Direct server communication.
Is it possible to perform http call from blogger ? If so, just perform http call to your CMS from Blogger, get data and render it.
3) Mixed flash/javascript solution. Flash can perform http call regardless of same origin policy. Get data with flash, use ExternalInterface to call Javascript function to render data.
There is no another way to do it. I suggest you to use javascript solution
You could build an HTML skeleton of empty ULs in Blogger (the max that you might need) to hold your navigation contents, and then link to an Umbraco-generated external stylesheet.
This stylesheet could fill those LIs with CSS generated content using the :before and :after pseudo-elements, and hiding unused LIs with CSS display: none.
An example of this is at: http://jsfiddle.net/5bXja/1/
This works in IE8+ so depending on your clients, this may-or-may-not be more widely supported than Javascript. Likely not. ;-)

What is the current proper way of creating Facebook Tab's with interaction?

I need to create an interactive Facebook Tab for a client, similar to this:
http://www.facebook.com/#!/knnktr.
The application has a number of slides, which are basically images that will scroll left/right as the visitor clicks on two arrows on either side of the displayed image.
I could do this in Flash, but I could also attempt doing this with JavaScript.
Now, I understand that Facebook's APIs often change, and iframe's are currently not an option.
What is the best/correct way to achieve this. Should I stick with the Static FBML? If we have an option to use JavaScript, we'll prefer that above Flash. The question is, does the Static FBML limit the ability to perform some JavaScript calls.
I need to respond to mouse clicks, and I also need to be able to make remote AJAX requests to our server.
If you're building a tab, FBML/FBJS are your only option. The official FB docs for FBJS are pretty good: http://developers.facebook.com/docs/fbjs/
A couple caveats about FBJS:
They rewrite your Javascript to only allow limited functionality. If you're used to a nice Javascript lib like jQuery you're out of luck.
You can't use external js includes, the Javascript must be in the same page
Take a look at the event, animate and AJAX sections in the docs. Taking a quick look at your example I don't see anything you couldn't do with FBJS.

Multiple "Like Button"s on a page

I have a page with 20 articles, and for each article, I have a Facebook Like Button, implemented using the tag.
Because of this, my site is greatly slowed down as Firefox makes a query in the background for each of the like button.
Is there anything I can do to reduce this load?
In my experience, all the extra IFRAMES are actually faster than using the JavaScript SDK, even though the Like icons are supposed to load asynchonously. I have a page with about 18 like buttons on it, and at least the IFRAME approach doesn't result in a perceived slowdown for users like the JS version does - the only downside is that the Like buttons "pop" into the page a little late in IFRAMES.
I assume you're using iframe to display your like buttons. Performance is the downside of using iframes. If you've got 20 iframes, then it's equivalent to loading 20 web pages (with 20 independent http requests). As browsers have connection limits per domain, it can take a while for this many iframes to load. This is especially true in older browsers, where connection limit is only 2 per domain, which means that only 2 iframes can load at a time. iframe can also have the negative side effect of blocking other downloads, which makes the problem even worse. You can read all about iframe performance problems here:
http://www.stevesouders.com/blog/2009/06/03/using-iframes-sparingly/
If possible, you may want to consider using xfbml like button instead of iframe. Unfortunately, this means that you'll need to load Facebook's JavaScript SDK, but with 20 like buttons, you should see an overall performance boost.
As an alternative, if you're not keen on the idea of xfbml, you could try a service like OpenLike: http://openlike.org/
From their docs:
A widget is created by first loading the OpenLike javascript and then calling OPENLIKE.Widget(). Multiple widgets can be embedded in the same page, each with different options.
I ended up going with something similar to this solution Lots of XFBML Facebook Like buttons are slow? with JQuery Sonar. It seems to do the trick for me. I'd prefer a single call that loads all the buttons but it's outside of my control.
If I had more time what I'd do is use the facebook API to get the count and make my own buttons (perhaps load the real button on hover if i wanted their functionality but iirc you can just call the "share" function directly). I don't currently have time to massage facebook that much so this is a sorta makeshift hack that I don't think has too many downsides and it seems to be used by a number of different sites.

Go to a new page, but still have GWT variables?

In GWT, I would like to do something like a form submission that takes me to a new page, with new style sheet and new static elements, and when I get there, be able to extract the values of GWT variables still in GWT. In other words, I want to do most of the form processing on the client side instead of sending it to a servlet to be processed and sent back. Is that possible? Would FormPanel allow me to do that? How do I access the contents of the form fields in GWT on the new page?
I'm not sure I'm getting the right picture here, but I see several possibilities:
Pass the variables in the url like example.com/myform#create/param1/param2 or any other format you want, then read it using the History class
Use something like this - create an iframe from GWT (maybe put it in Lightbox or something similar), populate it the way you want using the current state of the app, and when the user is finished, he'll just close the (Lightbox) frame and get back to the main application
You could also pass around data in a "hidden" way (no visible data in the url or even through POST) using the window.name hack - there's even a sample implementation for GWT to get you started
ATM, I prefer the second option, since it goes best with the whole no refresh, same page, one app, GWT thing :) That is, unless I'm getting the wrong picture and you want to do something else.
GWT is really meant to be used for the whole application, where "pages" are replaced by application state and URL fragments, and "form submission" is replaced by AJAX calls.
If you want to validate form fields, this can easily be done with regular JS or a library like jQuery.
I'm not sure it I get you right either, but for what I'm receiving, having a new page to process the form is not the optimal design. The reason been that you might have to write different GWT app for that which mean overheads, and creating new window (or tab) will move the user's attention away from where they are. Why not using another page WITHIN gwt to process the form with tab panel or hidden panel?