Skip to content

Instantly share code, notes, and snippets.

@shanlalit
Forked from wycats/dialog.js
Created May 29, 2009 03:29
Show Gist options
  • Save shanlalit/119761 to your computer and use it in GitHub Desktop.
Save shanlalit/119761 to your computer and use it in GitHub Desktop.
// Creating a new dialog plugin
var dialog = new $.Widget("<div class='dialog'></div>");
dialog.insertInto = "body";
dialog.listen({
open: function() {
if(dialog.state == "closed") {
dialog.show(); // Triggers another event
dialog.state = "open";
}
},
close: function() {
if(dialog.state == "open") {
dialog.hide(); // Triggers another event
dialog.state = "closed";
}
}
});
// DOM Stuff
dialog.listen("default", {
show: function() {
dialog.el.show();
},
hide: function() {
dialog.el.hide();
},
initialize: function(dialog, contents) {
dialog.origin = dialog.el.parent();
dialog.append(contents).appendTo(dialog.insertInto);
}
})
/* Setup -- The specific setup is separated out from the implementation
so making special version of the dialog is simple (see below) */
var openButton = dialog.newType("open", "a.dialog");
openButton.live("click", function() {
dialog.open();
return false; // Should block bubbling
});
$("body").live("click", function() {
if(dialog.state == "open") dialog.close();
});
// Usage
$.get("someUrl", function(html) {
dialog.initialize(html);
});
/* OVERRIDE */
var openClicker = dialog.newType("open", "div.dialog");
openClicker.live("click", function() {
dialog.open();
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment