Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

Standup 2/17/11: The awesome $.widget.bridge, Devise 1.1.6, Resetting a jQuery widget, Cookie-less sessions in Rails, CSS3 flexible box model

Ask for Help

“Is there any way to do cookie-less sessions in Rails?”

Josh Susser mentioned Rails used to support this (by encoding the session ID in all links like PHP can do) but no longer offers this feature and may try to fight your attempts to do it.

This pattern is discouraged because links which are shared with someone else through copy-and-paste would effectively log them in as that user. Very dangerous.

“Is there any way to take an element widgetized by a jQuery plugin and reinitialize everything (i.e. call the initializer again as if it’s an untouched element)?”

jQuery plugins ultimately do lower-level, destructive modifications to the DOM so, unless the plugin supports some kind of resetting, there’s no jQuery feature to do this directly. You can do a reset at the application layer through something like this:

var unmodified = $("#overlay").clone();

Interesting Things

  • Use jQuery UI’s $.widget.bridge to create new $.fn widget functions that wrap a more object-oriented Javascript function.

Here is an example:

var widget = function(options, element){ = "ACME Widget #42";
    this.options = options;
    this.element = element;

widget.prototype = {
    wizbang: function(){
        console.log("wizbang called!");
    _secret_sauce: function(){
        console.log("Protect me jQuery UI!")

$.widget.bridge("acme_widget", widget);
var widget = $("#victim").acme_widget();"acme_widget").name;       // => "ACME Widget #42"
widget.acme_widget("wizbang"); // => "wizbang called!"

widget.acme_widget("_secret_sauce"); // Just returns #victim, does not execute _secret_sauce.

For more information, see this blog post.

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *