-
-
Save shanlalit/119761 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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