how to make own custom widgets like facebook social plugins? - javascript

How do I make my own widget just like facebook? https://developers.facebook.com/docs/guides/web/#plugins
Basically it's a bit of javascript, css and html code, but how to do it?
Any example, tutorials?

I highly recommend Third Party Javascript (Manning) from the guys at Disqus for a great overview of everything. While it won't give you a magic bullet solution for your SDK/widget-making, it will help you bullet-proof things as you go. It's a great reference, if short/concise and the code is definitely not for JavaScript beginners.
As to how Facebook does it, while it's not fully descriptive of their iframe/widget approach, it shows how they do bullet-proof embedding in non-standard webpages: http://calendar.perfplanet.com/2011/the-art-and-craft-of-the-async-snippet/
For extra bonus points, combine that with http://www.phpied.com/non-onload-blocking-async-js/ and it should get rid of the loading spinner in all but iOS 6 if memory serves me well.
For even more advanced iframe fun, see https://github.com/benvinegar/seamless-talk and any other slides/posts at http://benv.ca/. (I think I'd like to meet Ben one day, given how much of his stuff I've been borrowing from lately, and he's a fellow Canadian to boot.)
Note that seamless iframes, as a native browser concept, are webkit-only and buggy at that: https://bugs.webkit.org/show_bug.cgi?id=99289 (On Firefox, dev. is stopped due to an 11-year old bug? https://bugzilla.mozilla.org/show_bug.cgi?id=631218) So for the foreseeable future, iframe customization will require JavaScript. :)

Look here for a tutorial on how to build your own widget using JSONP:
http://alexmarandon.com/articles/web_widget_jquery/
and here on how to make it secure:
http://wordpress.tv/2011/08/31/mike-adams-developing-secure-widgets-secure-iframe-communication-in-a-pre-postmessage-world/

You can do this with the Facebook Javascript SDK (see https://developers.facebook.com/docs/reference/javascript/). You need to understand the Graph API (see https://developers.facebook.com/docs/reference/api/) which you can query from the Javascript SDK. Throughout Facebook's documentation there's tonnes of example code. Have fun!

Related

Which javaScript framework for cross-domain?

I am building a web service that will make heavy use of cross-domain GET and POST data, and then update some lightbox or similar windows on the client.
Is there one JavaScript framework that is better at this, or more importantly, a framework which I should avoid?
I want to be able to put controls in the boxes. Really sexy boxes would be nice. These will be updated without page reloads.
Framework needs to be really good at the cross-domain stuff. I need good error trapping and process confirmation so that I can show the user that his connections are active.
I can use more than one framework if necessary. The bandwidth might be justified if one framework was really good at cross-domain and another was really good at windows/boxes.
Thanks,
EDIT: With regard to which frameworks to avoid, I am thinking in terms of gotchas.
I would suggest using jQuery as it's probably one of the most widespread (if not "the") javascript frameworks. There are numerous jQuery addons for sexy boxes (you just have to google), you can have it to work cross-domain
As for which frameworks to avoid: the ones that don't have an active developer community behind them, just see how often releases and fixes are released.
My favourite Javascript Framework is YUI 2.
It has a very good documentation, is actively developed since about 3 years by a big company (YAHOO). The widgets provided with the library are well structured and can be easily configured. Moreover I had never the need to rely on any 3rd party plugin (except once I needed an accorion widget), all what I need comes with the YUI or what is also very important: it can be done with what the library offers. That is something I really appreciate. I used it in all my projects since 2008 and I never got disappointed.
The packages which are especially interesting for you:
The Connection Manager: http://developer.yahoo.com/yui/connection/
and the Overlay Component: http://developer.yahoo.com/yui/container/overlay/index.html
Another alternative is Dojo (documentation found here).
Biggest problems I've had with Dojo:
Big changes across versions
Relatively mediocre documentation
In its defense, I will say that Dojo's xhrPost and xhrGet commands are pretty solid, if that's all you're using the framework to do.
One of its libraries, Dijit, also has some neat looking widgets - only some of which work as advertised (i.e. "out of the box").
Nevertheless, it's far better than writing your own cross-browser JavaScript.
Good luck!
I would say JSONP from jQuery, but lately I've seen this video from Google for cross domain calls.
For the cross-domain part I would recommend easyXDM.
Demos of this can be viewed here, I'm guessing this example is fitting for your application
I recommend jQuery, it's probably the most popular one out there.

How to begin working with GwtQuery?

I've dived into the GWT world a couple of months ago and find it quite interesting.
I'm currently developing a web application which is to be used internally and so we need to resize the browser window, which can only be done by JSNI. After hitting some problems
regarding the JSNI I was advised to look into jquery and I found that it's counterpart in GWT is GwtQuery. I've tried looking on the project page and googling for tutorials but I can't seem to find a clear beginners tutorial on how to use GwtQuery on GWT but I keep find references to how it's very similar to jquery.
I think it's important to state that I'm not a js developer but rather a java developer who likes the idea of GWT and I just need to use GWTQuery in a very small part of my application.
Thanks in advance for any leads or links.
Ittai
GwtQuery also goes by the name GQuery, so maybe you find more if you search for that.
At Google I/O 2009 the creator of GQuery gave a speech about GQuery, you can find the video and slides here, maybe it helps.
Here you have a presentation I gave about gquery.
The getting started guide in the project site could be useful as well.
The gquery mailing list is a good place to ask questions to developers and users.
Here I found good article with small and simple examples:
GWTQuery – jQuery in GWT

Best Technologies for AJAX Web Development

I have some experience in AJAX development, mostly on .NET and MooTools. However, I want to learn more and see what others out there thought about the various other options available. I am looking more for advice about the front end. The back end, I will most probably be coding it in .NET using c# and WCF services.
Please feel free to provide me as much information as you can. Also, I would appreciate any links to resources.
List of Options (feel free to add)
Write my own Javascript
Use a framework like MooTools, JQuery, etc. Which one is better?
Use Google Web Toolkit. Am I tying myself to the limitations of GWT? Or are there not limitations?
ASP.NET AJAX
WPF (Will this run on non-IE browsers?)
Flash (it'll be a pain to learn action script)
Thanks
Jaspreet
Writing your own Javascript often means reinventing the wheel when it comes to trying to attain cross-browser compatibility. Frameworks such as jQuery and MooTools take care of much of that grunt work for you.
Personally, I would suggest picking a Javascript framework or using GWT, but really it's just a matter of personal preference at that point, much like choosing a programming language. Pick that one that is best for your purposes, or that you're most familiar with.
I'd go with jQuery.
jQuery will be bundled with the next version of Visual Studio. Google uses jQuery. jQuery has the largest user-base of any of the frameworks out there.. And speaking of not re-inventing the wheel: jQuery also has the largest plugin-repository of any of the frameworks out there.. Including its own official UI library which is in constant development.
.. And if you're a fan of books; there's 3-4 books about the framework out currently.
Oh, yeah! Check out Douglas Crockford's website for great vanilla JavaScript tips and tricks.
Just my two cents :)
jQuery
prototype
MooTools
dojo
GWT
ExtJS
Those will all have you working with very solid code, which is usually the best way to improve your own skills. And don't forget all their extensions/plugins.
I would recommend jQuery. It's more extensible and light-weight than most other JavaScript libraries I've seen (and you can have it Google-cached with the AJAX APIs).
For Flash-based AJAX web apps, Flex is a better solution.
Since this is a fairly subjective question I will put in my 2 cents.
I've developed using the Dojo toolkit and found it very well rounded. However, if you don't do a custom build on your library it slows everything down. It has a steeper learning curve than other frameworks, but seems to sit pretty close to heart of Javascript.
But this isn't an advertisement for dojo. I'm working on a Ajax web app currently and my goal is to try and avoid using a framework. Why? A few reasons.
The biggest reason is complete control over the code. Not that I don't trust toolkits, I just like my custom code. I don't have any code that I don't use, and all of my abstractions are custom made for my purposes. At times I am in fact reinventing the wheel*, but its always a bit different because it's purpose built.
The other big reason is the amount of knowledge I gain. I'm confident that I could pick up any framework much faster, because of not using one for a project. I understand so much more than I did previously. Before It was more like a voodoo mystery box, and now even frameworks make more sense to me.
The fact of the matter is if you do any non-trivial javascript you will end up with a framework (or a mess). In reality it may not be the fastest way to write web apps, but it isn't all that hard with a little practice. You can be amazed at what creative things you can come up with that didn't exist before.
*Reinventing the wheel is a terrible analogy that we all use. We reinvent wheels all the time. First made of stone, then lighter wood, tires, etc... My truck doesn't have the same wheels as my sedan.
Like other responders I prefer to use frameworks, but my favorite is dojo -- clean and well-designed architecture, good books (my favorite being Matthew Russel's), and a particularly impressive approach to using browser extensions (such as Google Gears or Microsoft Silverlight) if the user has them installed, while falling back gracefully (e.g. to Ajax-interfaced server-side storage) if no suitable browser extensions (or sufficiently advanced browsers, with HTML5 support) are present.
Dojo is, currently, slightly less popular than jquery (e.g., [jquery ajax] has 8.4 million hits on Google Search, vs 4.3 million for [dojo ajax]), but that's still way popular enough to ensure it won't go away any time soon;-).
You must check ExtJS.
Most libraries I've seen have usable core but lack the widget/control library that will blend-in with each other. Sure you can get a vast number of controls for jQuery, but do you have the time to find out which ones have intended functionality and tweak their visual appearance to match the rest of controls? ExtJS gives you just that. Core is core. It works and it works great. But the vast selection of compatible and functionality rich controls is the main driver that will make your life easier.
I've used ExtJS with Asp.Net and WCF services and it was a really nice experience overall. You will need some time to get to know ExtJS component model to extend it even further (as you would need to do the same with other libs), but when you do, you start loving it even more.
One more thing: since MS ships jQuery with MVC it doesn't mean it's the best. It only means it's one of the best (and much better than Microsoft's in-house Ajax) but with the most relaxed open source license.
Edit: Now that Silverlight 3 has shipped it became apparent it will shake things a bit with its offline support and rich graphics support. As well as standalone desktop like web apps. Definitely something to consider...
Please note that WPF has nothing to do with ajax.
AJAX = Asynchronous javascript and xml
WPF = a windows-only UI display technology. The only option there for in-browser use is to create an Xbap. The more-suited-for-the-web counterpart is silverlight (say, like flash but from microsoft), so perhaps you should look into that as well... it's like using flash, but with familiar MS technologies.
Concerning your question about which framework to use in case of ajax: I prefer jQuery. It's short syntax and chaining allow you to reach your goals very fast in an intuitive way.
Also, GWT is a Java framework that also renders stuff on the client, as far as i know. So you would have the limitation of Java as backend language...
GWT has made considerable leaps and bounds over the past 7 months. The mutiple GWT widget libraries have received a good deal of attention, and Google's work on the library has been impressive. Going GWT limits you to:
Using GWT widgets
Possibly becoming a GWT widget developer
The benefits include:
Coding in Java
Debugging in Java
Skipping the parts of JavaScript that make you pull your hair out
GWT is the step past AJAX. It buries the HTML / JavaScript so that you don't need to deal with it, but also provides access in case you do want to deal with it.
Overall, you will spend less time trying to get small things working, and more time adding awesome to your application.
there is also prototype.js
Try the Yahoo! User Interface Library (YUI)
Pick a library to learn, then pick up the others--but I don't think I'd reinvent the wheel.
I picked MooTools and have picked up jQuery/Prototype since. (Picked Mootools because their site, at the time, was the only one that validated, figured clean html meant clean javascript).
Side note about MooTools:
An often overlooked feature of MooTools is the download builder. You can download just enough of the framework source to get your AJAX working, and nothing else.
There's the BBC's open source javascript library called Glow

Introductory JavaScript programming task for an expert developer

What would be a good mini-project to get intimate with JavaScript, as an advanced 'introduction' to the language? I want to actually code an application in JS, not hook up bits of it to enhance a web application.
A lot of stuff you could learn by doing an RSS reader on a page. Google shows what can be done. The whole lection concentrates on javascript, network access, security restrictions and medium data mangeling.
If you have the ability to do any sort of backend programming than AJAX is really neat to do. You can get a lot of good effects with less efforts. A good thing to build on up.
I would argue that if you're really an advanced programmer then the exercises above would not really give you any insight into the language as they are just variations on things you probably have already done. Javascript's strongest suit is it's LISP style ability to grow. Write something AI(ish) that creates new functions. Most people don't utilize the language in this way, but, its ability to augment its own classes on the fly is, I would argue, it's most unusual and most powerful feature.
Although not a project, watch the Douglas Crockford videos at YUI theater.
The biggest web based Javascript projects are going to deal with the DOM. Do some nifty stuff with JQuery. Make a table with rows that highlight when you hover. Make them update themselves through AJAX and JSON when you click on them.
If you're really looking for something magical and usefull write a scrollable table with fixed headers and footers for IE8.
If you want to stay away from the WEB use the JDK 1.6 and run Javascript code in that. You could do TONS with that.
Whenever I'm trying to get familiar with a language, I will work on Project Euler problems with it.
I would implement a simple game like sokoban first.
The second application would be an AJAX-based multiuser chat application, first fetching other people's responses by polling, later with AJAX push.
Interesting question.
Really you could do any sort of application. In order to make sure you're using the latest and greatest stuff, I'd try making a simple CRUD style application using DHTML and AJAX. Perhaps a contacts list or calendar. If you're feeling really energetic, you could write the back-end in JavaScript as well.
Unless you want to get really friendly with the DOM and browser compatibility, I'd learn Javascript through the mask of one of the nice frameworks like Jquery or Prototype.
The Holy Grail - a WYSIWYG editor. They wouldn't need to complete it, but just seeing their plan of attack would be interesting. Plays right into patterns and OO.
I suggest you create a Google Gadget. You can create one for free and perhaps make something useful out of it. If you don't have a Google account, sign up for one. Then add the Google Gadget Editor to begin writing your code.
With the gadget, you'll be able to mess with JavaScript, JSON, CSS, etc. Furthermore, you'll be able to store the file on Google's server so you can work on it from any computer.
I created a simple RSS reader and wrote JavaScript to get the feed (using Google's API) then dealing with that JavaScript object because it came back as JSON. I then developed some JavaScript to hide/show div tags.
It was a good starter project for me to learn JavaScript.
Get JavaScript the Good Parts by Douglas Crockford. Also check out his web site: http://www.crockford.com
Key reason: just because JavaScript looks like C/C++/Java/C# doesn't mean it actually is like them. Things are significantly different. I suggest reading his book to get a grasp of those differences.
Otherwise, I would look at the JQuery web site. JavaScript is cool and all, but a good framework will save you from a lot of the pitfalls and make you much more productive faster.
try making an advanced AJAX application like for example try to recreate the google calander.
How about a firefox plugin to monitor StackOverflow? It could use RSS to monitor feeds and let you know when new questions are asked with your tags.
It could also be grown as your js skills progress.
Write yet another javascript framework, but focused specially in something, ie game programming.

How to convince my fellow .NET developers that learning jQuery will be beneficial

I have a few .NET developers who only want to use the MS AJAX Toolkit and think JavaScript (and any JS Library) is evil. I tried to explain that if you treat client-side development like a grown-up language you can build maintainable code ... but I assume that the classic ASP days have left a mark on these guys. Anyone have a suggestion to help convince this type of developer that learning jQuery will actually benefit them in the long run as the industry is trending back to "lets get close to the metal again" w/ MVC for example?
Tell them microsoft endorses jquery and that it's shipping with MVC
If they don't realize that jQuery is the bee's knees - they're living under a rock - tell them about all of the people that are using jQuery (Google, Dell, MLB, Bank of America.....the rest of a good list is in the middle of the jQuery home page) - or just tell them that every time they go to their Netflix account they are using jQuery or if they visit the president's web site (which could backfire I guess.... ;)
Emphasize that learning a 'technology' that is becoming that ubiquitous can only help your career.
Point them to this article by Scott Guthrie.
Quick quote from the article explains all:
I'm excited today to announce that
Microsoft will be shipping jQuery with
Visual Studio going forward. We will
distribute the jQuery JavaScript
library as-is, and will not be forking
or changing the source from the main
jQuery branch. The files will
continue to use and ship under the
existing jQuery MIT license.
Ask if they like server-round-trips. (To make them understand that client-side-stuff is necessary.)
Ask if they want to write code that works in 3 different places at the same time? (To make them understand the need for a library that almost erases browser differences.)
Show them a list of who's using jQuery.
If they fancy elegant code, they will get what you're saying. Otherwise I think they'll be really hard to convince.
Implement something that has value for your organisation/clients using jQuery to prove that it works well in your context - even better if it's something that would be difficult to implement, more complex or take longer in the MS AJAX Toolkit.
Developers often find practical examples of running code in a context that applies to them more persuasive than general endorsements or lists of who else is using it (every practical technology can come up with a good list of users).
And if your developers don't like JavaScript, perhaps you should ask them what they think the AJAX Toolkit is running on the client side. The AJAX Toolkit is a JavaScript library on the client side - just one that's designed to be easily integrated into ASP.NET.
Getting up to speed on the dominant tool in a given area is always a good idea. JQuery is the dominant JS library. For some anecdotal evidence, take a look at the tags here on StackOverflow:
JQuery: 1809 items
asp.net-ajax: 272 items
ajaxtoolkit: 54 items
Tell them they can do more with less - and understanding jQuery/javascript will help them understand AJAX.NET even more. It's a big huge leaky abstraction in my books - since switching to jQuery it made web programming more fun and I could build way cooler apps.

Categories