-
Notifications
You must be signed in to change notification settings - Fork 8
/
jquery.dialog.extra.js
286 lines (248 loc) · 9.25 KB
/
jquery.dialog.extra.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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/**
* jQuery UI dialog extra v0.7
*
* Copyright 2011, Mark Prisyazhnyuk (nixmrak)
* Licensed under GPL Version 2 licenses.
*
*
* Usage:
* $.dialog({canMaximize:true, canMinimize:true})
*
* Idea based on: Extension of JQuery UI Dialog widget to add custom minimizing capabilities (by Ryan Curtis)
*
* 2012 PauloRB - Changed to put the minimized in the bottom of the screen
*/
(function($){
var def_options = {
'canMaximize' : false,
'canMinimize' : false
}
$.extend($.ui.dialog.prototype.options, def_options)
var _init = $.ui.dialog.prototype._init;
//Optional top margin for page, wont let a user move a dialog into this spot.
var topMargin = 0;
//Custom Dialog Init
$.ui.dialog.prototype._init = function() {
var self = this;
_init.apply(this, arguments);
uiDialogTitlebar = this.uiDialogTitlebar;
//we need two variables to preserve the original width and height so that can be restored.
//this.options.originalWidth = this.options.width;
//this.options.originalHeight = this.options.height;
this._savePosition()
//save a reference to the resizable handle so we can hide it when necessary.
this.resizeableHandle = this.uiDialog.resizable().find('.ui-resizable-se');
//Save the height of the titlebar for the minimize operation
this.titlebarHeight = parseInt(uiDialogTitlebar.css('height')) + parseInt(uiDialogTitlebar.css('padding-top')) + parseInt(uiDialogTitlebar.css('padding-bottom')) + parseInt(this.uiDialog.css('padding-top')) + parseInt(this.uiDialog.css('padding-bottom')) ;
//--------------------------------------------------------------------------------------------------------------
var uiDialogTitlebarMinimize = self.uiDialogTitlebarMinimize = $('<a href="#"></a>')
.addClass(
'dialog-minimize ui-dialog-titlebar-min ' +
'ui-corner-all'
)
.attr('role', 'button')
.hover(
function() {
uiDialogTitlebarMinimize.addClass('ui-state-hover');
},
function() {
uiDialogTitlebarMinimize.removeClass('ui-state-hover');
}
)
.focus(function() {
uiDialogTitlebarMinimize.addClass('ui-state-focus');
})
.blur(function() {
uiDialogTitlebarMinimize.removeClass('ui-state-focus');
})
.click(function(event) {
self.minimize();
return false;
})
.css({
position: 'absolute',
right: 24,
marginTop: -10,
top: '50%'
})
if(self.options.canMinimize) {
uiDialogTitlebarMinimize.appendTo(uiDialogTitlebar)
}
var uiDialogTitlebarMinimizeText = (self.uiDialogTitlebarMinimizeText = $('<span></span>'))
.addClass(
'ui-icon ' +
'ui-icon-minusthick'
)
.text('minimize')
.appendTo(uiDialogTitlebarMinimize)
//--------------------------------------------------------------------------------------------------------------
var uiDialogTitlebarRest = self.uiDialogTitlebarRest = $('<a href="#"></a>')
.addClass(
'dialog-restore ui-dialog-titlebar-rest ui-corner-all'
)
.attr('role', 'button')
.hover(
function() {
uiDialogTitlebarRest.addClass('ui-state-hover');
},
function() {
uiDialogTitlebarRest.removeClass('ui-state-hover');
}
)
.focus(function() {
uiDialogTitlebarRest.addClass('ui-state-focus');
})
.blur(function() {
uiDialogTitlebarRest.removeClass('ui-state-focus');
})
.click(function(event) {
self.restore();
return false;
})
.css({
position: 'absolute',
right: 24,
marginTop: -10,
top: '50%'
})
.appendTo(uiDialogTitlebar)
.hide()
var uiDialogTitlebarRestText = (self.uiDialogTitlebarRestText = $('<span></span>'))
.addClass('ui-icon ui-icon-newwin')
.text('minimize')
.appendTo(uiDialogTitlebarRest)
//restore the minimize button on close
this.uiDialog.bind('dialogbeforeclose', function(event, ui) {
self.uiDialogTitlebarRest.hide();
self.uiDialogTitlebarMinimize.show();
});
//--------------------------------------------------------------------------------------------------------------
var uiDialogTitlebarMaximize = self.uiDialogTitlebarMaximize = $('<a href="#"></a>')
.addClass(
'dialog-maximize ui-dialog-titlebar-max ui-corner-all'
)
.attr('role', 'button')
.hover(
function() {
uiDialogTitlebarMaximize.addClass('ui-state-hover');
},
function() {
uiDialogTitlebarMaximize.removeClass('ui-state-hover');
}
)
.focus(function() {
uiDialogTitlebarMaximize.addClass('ui-state-focus');
})
.blur(function() {
uiDialogTitlebarMaximize.removeClass('ui-state-focus');
})
.click(function(event) {
self.maximize();
return false;
})
.css({
position: 'absolute',
right: 45,
marginTop: -10,
top: '50%'
})
if(self.options.canMaximize) {
uiDialogTitlebarMaximize.appendTo(uiDialogTitlebar)
if(!self.options.canMinimize) {
uiDialogTitlebarMaximize.css({right:24})
}
}
var uiDialogTitlebarMaximizeText = (self.uiDialogTitlebarMaximizeText = $('<span></span>'))
.addClass('ui-icon ui-icon-arrow-4-diag')
.text('maximize')
.appendTo(uiDialogTitlebarMaximize)
//restore the minimize button on close
this.uiDialog.bind('dialogbeforeclose', function(event, ui) {
self.uiDialogTitlebarRest.hide();
self.uiDialogTitlebarMinimize.show();
self.uiDialogTitlebarMaximize.show();
});
//--------------------------------------------------------------------------------------------------------------
};
//Custom Dialog Functions
$.extend($.ui.dialog.prototype, {
_savePosition: function() {
this.options.originalWidth = this.options.width
this.options.originalHeight = this.options.height
this.options.originalLeft = this.uiDialog.offset().left
this.options.originalTop = this.uiDialog.offset().top
this.options.height = this.element.height()
},
_restorePosition: function() {
this.uiDialog.css({
left:this.options.originalLeft,
top:this.options.originalTop
})
},
_restoreSize: function() {
this.uiDialog.css({
height:this.options.originalHeight,
width:this.options.originalWidth
});
this.element.parent().height(this.options.height+this.titlebarHeight+11);
this.element.height(this.options.height);
},
_maximizedResizeHandler: function(event) {
var newHeight = $(window).height()-11;
var newWidth = $(window).width()-11;
event.data.dialogObject.uiDialog.css({top:1, left: 1, width:newWidth, height:newHeight});
},
restore: function() {
var self = this
self._makeResizable()
self._makeDraggable()
self.uiDialog.draggable('_generatePosition')
$(window).unbind('resize',self._maximizedResizeHandler)
if(this.options.currentState=='maximized') {
this._restorePosition()
}
this._restoreSize()
this.element.show();
this.resizeableHandle.show();
this.uiDialogTitlebarRest.hide();
this.uiDialogTitlebarMinimize.show();
this.uiDialogTitlebarMaximize.show();
this.options.currentState = 'normal'
},
minimize: function() {
var self = this
//Store the original height/width
this.uiDialog.resizable( 'destroy' )
this._savePosition()
this.uiDialog.animate({width: 200, height:this.titlebarHeight},200);
this.element.hide();
this.uiDialog.css("top", "");
this.uiDialog.css("bottom", "0");
this.uiDialogTitlebarMaximize.show();
this.uiDialogTitlebarMinimize.hide();
this.uiDialogTitlebarRest.show();
this.resizeableHandle.hide();
this.options.currentState = 'minimized'
},
maximize: function() {
//Store the original height/width
var self = this
if(this.options.currentState != 'minimized') {
this.uiDialog.resizable( 'destroy' )
}
this.uiDialog.draggable( 'destroy' )
this._savePosition();
var newHeight = $(window).height()-11;
var newWidth = $(window).width()-11;
self.uiDialog.animate({top:0, left: 1, width:newWidth, height:newHeight},200)
$(window).bind('resize', {dialogObject:self}, self._maximizedResizeHandler)
self.element.show();
self.element.css({width:'auto','height':newHeight-this.titlebarHeight-11 })
this.uiDialogTitlebarMaximize.hide();
this.uiDialogTitlebarMinimize.hide();
this.uiDialogTitlebarRest.show();
this.resizeableHandle.hide();
this.options.currentState = 'maximized'
}
});
})(jQuery);