forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
209 lines (154 loc) · 7.74 KB
/
popup.js
File metadata and controls
209 lines (154 loc) · 7.74 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
* $Revision$
* $Date$
*
* Copyright (C) 1999-2009 Jive Software. All rights reserved.
*
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
/*
* $ lightbox_me
* By: Buck Wilson
* Version : 2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function($) {
$.fn.lightbox_me = function(options) {
return this.each(function() {
var
opts = $.extend({}, $.fn.lightbox_me.defaults, options),
$overlay = $('<div class="' + opts.classPrefix + '_overlay"/>'),
$self = $(this),
$iframe = $('<iframe src="' + /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank' + '" style="z-index: ' + (opts.zIndex + 1) + '; display: none; border: none; margin: 0; padding: 0; position: absolute; width: 100%; height: 100%; top: 0; left: 0;"/>'),
ie6 = ($.browser.msie && $.browser.version < 7);
/*----------------------------------------------------
DOM Building
---------------------------------------------------- */
if (ie6) { $('body').append($iframe) } // iframe shim for ie6, to hide select elements
$('body').append($self).append($overlay);
/*----------------------------------------------------
CSS stuffs
---------------------------------------------------- */
// set css of the modal'd window
setSelfPosition();
$self.css({left: '50%', marginLeft: ($self.outerWidth() / 2) * -1, zIndex: (opts.zIndex + 3) });
// set css of the overlay
setOverlayHeight(); // pulled this into a function because it is called on window resize.
$overlay
.css({ position: 'absolute', width: '100%', top: 0, left: 0, right: 0, bottom: 0, zIndex: (opts.zIndex + 2), display: 'none' })
.css(opts.overlayCSS);
/*----------------------------------------------------
Animate it in.
---------------------------------------------------- */
$overlay.fadeIn(opts.overlaySpeed, function() {
$self[opts.appearEffect](opts.lightboxSpeed, function() { setOverlayHeight(); opts.onLoad()});
});
/*----------------------------------------------------
Bind Events
---------------------------------------------------- */
$(window).resize(setOverlayHeight)
.resize(setSelfPosition)
.scroll(setSelfPosition)
.keypress(observeEscapePress);
$self.find(opts.closeSelector).add($overlay).click(function() { closeLightbox(); return false; });
$self.bind('close', closeLightbox);
$self.bind('resize', setSelfPosition);
/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*----------------------------------------------------
Private Functions
---------------------------------------------------- */
/* Remove or hide all elements */
function closeLightbox() {
if (opts.destroyOnClose) {
$self.add($overlay).remove();
} else {
$self.add($overlay).hide();
}
$iframe.remove();
$(window).unbind('resize', setOverlayHeight);
$(window).unbind('resize', setSelfPosition);
opts.onClose();
}
/* Function to bind to the window to observe the escape key press */
function observeEscapePress(e) {
if(e.keyCode == 27 || (e.DOM_VK_ESCAPE == 27 && e.which==0)) closeLightbox();
}
/* Set the height of the overlay
: if the document height is taller than the window, then set the overlay height to the document height.
: otherwise, just set overlay height: 100%
*/
function setOverlayHeight() {
if ($(window).height() < $(document).height()) {
$overlay.css({height: $(document).height() + 'px'});
} else {
$overlay.css({height: '100%'});
if (ie6) {$('html,body').css('height','100%'); } // ie6 hack for height: 100%; TODO: handle this in IE7
}
}
/* Set the position of the modal'd window ($self)
: if $self is taller than the window, then make it absolutely positioned
: otherwise fixed
*/
function setSelfPosition() {
var s = $self[0].style;
if (($self.height() + 80 >= $(window).height()) && ($self.css('position') != 'absolute' || ie6)) {
var topOffset = $(document).scrollTop() + 40;
$self.css({position: 'absolute', top: topOffset + 'px', marginTop: 0})
if (ie6) {
s.removeExpression('top');
}
} else if ($self.height()+ 80 < $(window).height()) {
if (ie6) {
s.position = 'absolute';
if (opts.centered) {
s.setExpression('top', '(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (blah = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"')
s.marginTop = 0;
} else {
var top = (opts.modalCSS && opts.modalCSS.top) ? parseInt(opts.modalCSS.top) : 0;
s.setExpression('top', '((blah = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + '+top+') + "px"')
}
} else {
if (opts.centered) {
$self.css({ position: 'fixed', top: '50%', marginTop: ($self.outerHeight() / 2) * -1})
} else {
$self.css({ position: 'fixed'}).css(opts.modalCSS);
}
}
}
}
});
};
$.fn.lightbox_me.defaults = {
// animation
appearEffect: "fadeIn",
overlaySpeed: 300,
lightboxSpeed: "fast",
// close
closeSelector: ".close",
closeClick: true,
closeEsc: true,
// behavior
destroyOnClose: false,
// callbacks
onLoad: function() {},
onClose: function() {},
// style
classPrefix: 'lb',
zIndex: 999,
centered: false,
modalCSS: {top: '40px'},
overlayCSS: {background: 'black', opacity: .6}
}
})(jQuery);