jquery_002.js 3.9 KB

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