Lalit (owner)

Fork Of

Revisions

gist: 119761 Download_button fork
public
Public Clone URL: git://gist.github.com/119761.git
Embed All Files: show embed
dialog.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// 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;
});