-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialog.js
75 lines (57 loc) · 2.04 KB
/
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
(function (window, $, Voltron, Duvet, Shamen) {
'use strict';
// set prototype to base component and assign
// Dialog constructor to the constructor prototype
Dialog.prototype = new Voltron({});
Dialog.prototype.constructor = Dialog;
// constructor
function Dialog (options) {
// optionally clone dialog $el
options.$el = options.clone ? $(options.$el).clone() :
$(options.$el);
// append to body
$('body').append(options.$el);
Voltron.call(this, options);
// create overlay instance
this.overlay = new Duvet(this.$el[0]);
// create a draggable instance
if (options.draggable) {
this.shamen = new Shamen(this.$el[0], {
// dialog header is the draghandle
dragHandle: '#title'
});
}
return this;
}
Dialog.prototype.init = function (options) {
// call super method
Voltron.prototype.init.call(this, options);
// position the dialog's root element absolutely
this.$el.css({ position: 'absolute' });
};
// defaults, e.g., width and height
Dialog.prototype.defaults = {};
// event listeners; this is processed by Voltron.prototype.bind
Dialog.prototype.events = {};
// process template for injection into DOM
Dialog.prototype.render = function () {};
// makes dialog visible in the UI
Dialog.prototype.show = function () {
// this will adjust z-index, set the display property,
// and position the dialog
this.overlay.position();
};
// makes dialog invisible in the UI
Dialog.prototype.hide = function () {};
Dialog.prototype.destroy = function () {
// clean up overlay
this.overlay.destroy();
// clean up draggable
if (this.shamen) {
this.shamen.destroy();
}
// call super class
Voltron.prototype.destroy.call(this);
};
window.Dialog = window.Dialog || Dialog;
})(window, jQuery, Voltron, Duvet, Shamen);