|
1
|
1 |
|
|
|
2 |
|
|
|
3 |
(function($){ |
|
|
4 |
$.fn.popupWindow = function(instanceSettings){ |
|
|
5 |
var myWin = null; |
|
|
6 |
return this.each(function(){ |
|
|
7 |
|
|
|
8 |
$(this).click(function(){ |
|
|
9 |
|
|
|
10 |
$.fn.popupWindow.defaultSettings = { |
|
|
11 |
centerBrowser:0, // center window over browser window? {1 (YES) or 0 (NO)}. overrides top and left |
|
|
12 |
centerScreen:0, // center window over entire screen? {1 (YES) or 0 (NO)}. overrides top and left |
|
|
13 |
height:500, // sets the height in pixels of the window. |
|
|
14 |
left:0, // left position when the window appears. |
|
|
15 |
location:0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}. |
|
|
16 |
menubar:0, // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}. |
|
|
17 |
resizable:0, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable. |
|
|
18 |
scrollbars:0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}. |
|
|
19 |
status:0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}. |
|
|
20 |
width:500, // sets the width in pixels of the window. |
|
|
21 |
windowName:null, // name of window set from the name attribute of the element that invokes the click |
|
|
22 |
windowURL:null, // url used for the popup |
|
|
23 |
top:0, // top position when the window appears. |
|
|
24 |
toolbar:0 // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}. |
|
|
25 |
}; |
|
|
26 |
|
|
|
27 |
settings = $.extend({}, $.fn.popupWindow.defaultSettings, instanceSettings || {}); |
|
|
28 |
|
|
|
29 |
var windowFeatures = 'height=' + settings.height + |
|
|
30 |
',width=' + settings.width + |
|
|
31 |
',toolbar=' + settings.toolbar + |
|
|
32 |
',scrollbars=' + settings.scrollbars + |
|
|
33 |
',status=' + settings.status + |
|
|
34 |
',resizable=' + settings.resizable + |
|
|
35 |
',location=' + settings.location + |
|
|
36 |
',menuBar=' + settings.menubar; |
|
|
37 |
|
|
|
38 |
settings.windowName = this.name || settings.windowName; |
|
|
39 |
settings.windowURL = this.href || settings.windowURL; |
|
|
40 |
var centeredY,centeredX; |
|
|
41 |
if(settings.centerBrowser){ |
|
|
42 |
|
|
|
43 |
if ($.browser.msie) {//hacked together for IE browsers |
|
|
44 |
centeredY = (window.screenTop - 120) + ((((document.documentElement.clientHeight + 120)/2) - (settings.height/2))); |
|
|
45 |
centeredX = window.screenLeft + ((((document.body.offsetWidth + 20)/2) - (settings.width/2))); |
|
|
46 |
}else{ |
|
|
47 |
centeredY = window.screenY + (((window.outerHeight/2) - (settings.height/2))); |
|
|
48 |
centeredX = window.screenX + (((window.outerWidth/2) - (settings.width/2))); |
|
|
49 |
} |
|
|
50 |
if (myWin == null || myWin.closed) { |
|
|
51 |
myWin = window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY); |
|
|
52 |
} |
|
|
53 |
}else if(settings.centerScreen){ |
|
|
54 |
centeredY = (screen.height - settings.height)/2; |
|
|
55 |
centeredX = (screen.width - settings.width)/2; |
|
|
56 |
if (myWin == null || myWin.closed) { |
|
|
57 |
myWin = window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY); |
|
|
58 |
} |
|
|
59 |
}else{ |
|
|
60 |
if (myWin == null || myWin.closed) { |
|
|
61 |
myWin = window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + settings.left +',top=' + settings.top); |
|
|
62 |
} |
|
|
63 |
} |
|
|
64 |
myWin.focus(); |
|
|
65 |
return false; |
|
|
66 |
}); |
|
|
67 |
|
|
|
68 |
}); |
|
|
69 |
}; |
|
|
70 |
})(jQuery); |