-
Notifications
You must be signed in to change notification settings - Fork 0
/
quaid.dialog-1.0.js
74 lines (74 loc) · 2.47 KB
/
quaid.dialog-1.0.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Quaid.Dialog
*
* Creates a HTML dialog box.
*
* Essentially a lighter weight version of the jQuery UI Dialog
*
* Version: 1.03
* Updated: 25/09/2012
* Author: Chris Lienert
* Changes: BUG-FIX: Make the dialog modal overlay span the height of the document, not just the visible window
*
* Requires: jQuery 1.4.x or later
*/
jQuery(function ($) {
$.quaidDialog = function (element) {
this.element = element;
};
$.extend($.quaidDialog, {
prototype: {
_init: function () {//initialisation
var self = this;
self._overlay = $('<div class=\"dialog-overlay\"></div>').appendTo(document.body).hide(); //modal overlay. Style this to prevent access to elements behind the dialog
self._overlay.css("height", $(document).height() + "px"); //make the overlay span the height of the document
self.box = $("<div class=\"dialog\"></div>")//add the dialog
.append(self.element).appendTo(document.body)
.hide();
self._isOpen = false;
$(document).keypress(function (e) {
if (e.keyCode && e.keyCode == 27) {//esc
$.data(self.element, "quaidDialog").close(); //call dialog close
}
});
},
open: function (noOverlay) {
if (!this._isOpen) {
if (!noOverlay) {
this._overlay.show();
}
this.box.show();
this._isOpen = true;
}
},
close: function () {
if (this._isOpen) {
this._overlay.hide();
this.box.hide();
this._isOpen = false;
}
},
setPosition: function (location) {//set top/left position of the dialog
if (!location) {//ensure params are provided
return;
}
if (location.top) {//set top if provided ensuring it stays inside the client window
this.box.css({ top: Math.max(location.top, $(document).scrollTop() - $(document.body).offset().top) });
}
if (location.left) {//set left if provided
this.box.css({ left: location.left });
}
}
}
});
$.extend($.fn, {
quaidDialog: function () {//jQuery function
return this.each(function () {
//if no instance exists for the calling element(s), create a new one.
var instance = $.data(this, "quaidDialog");
(!instance &&
$.data(this, "quaidDialog", new $.quaidDialog(this))._init());
});
}
});
});