JAVASCRIPT   55
jquery popup js
Guest on 12th August 2022 12:32:22 AM


  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.  
  22. (function ($) {
  23.  
  24.         popupWindow = function (object, instanceSettings, beforeCallback, afterCallback) {
  25.                 beforeCallback = typeof beforeCallback !== 'undefined' ? beforeCallback : null;
  26.                 afterCallback = typeof afterCallback !== 'undefined' ? afterCallback : null;
  27.        
  28.                 if (typeof object == 'string') {
  29.                         object = jQuery(object);
  30.                 }
  31.                 if (!(object instanceof jQuery)) {
  32.                         return false;
  33.                 }
  34.                 var settings = jQuery.extend({}, jqueryPopup.defaultSettings, instanceSettings || {});
  35.                 object.handler = jQuery(object).bind(settings.event, function() {
  36.                        
  37.                         if (beforeCallback) {
  38.                                 beforeCallback();
  39.                         }
  40.                        
  41.                         var windowFeatures =    'height=' + settings.height +
  42.                                                                         ',width=' + settings.width +
  43.                                                                         ',toolbar=' + settings.toolbar +
  44.                                                                         ',scrollbars=' + settings.scrollbars +
  45.                                                                         ',status=' + settings.status +
  46.                                                                         ',resizable=' + settings.resizable +
  47.                                                                         ',location=' + settings.location +
  48.                                                                         ',menuBar=' + settings.menubar;
  49.                
  50.                         settings.windowName = settings.windowName || jQuery(this).attr('name');
  51.                         var href = jQuery(this).attr('href');
  52.                         if (!settings.windowURL && !(href == '#') && !(href == '')) {
  53.                                 settings.windowURL = jQuery(this).attr('href');
  54.                         }
  55.                        
  56.                         var centeredY,centeredX;
  57.                        
  58.                         var win = null;
  59.                         if (settings.centerBrowser) {
  60.                                 if (typeof window.screenY == 'undefined') {// not defined for old IE versions
  61.                                         centeredY = (window.screenTop - 120) + ((((document.documentElement.clientHeight + 120)/2) - (settings.height/2)));
  62.                                         centeredX = window.screenLeft + ((((document.body.offsetWidth + 20)/2) - (settings.width/2)));
  63.                                 } else {
  64.                                         centeredY = window.screenY + (((window.outerHeight/2) - (settings.height/2)));
  65.                                         centeredX = window.screenX + (((window.outerWidth/2) - (settings.width/2)));
  66.                                 }
  67.                                 win = window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY);
  68.                         } else if (settings.centerScreen) {
  69.                                 centeredY = (screen.height - settings.height)/2;
  70.                                 centeredX = (screen.width - settings.width)/2;
  71.                                 win = window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY);
  72.                         } else {
  73.                                 win = window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + settings.left +',top=' + settings.top);
  74.                         }
  75.                         if (win != null) {
  76.                                 win.focus();
  77.                                 if (settings.data) {
  78.                                         win.document.write(settings.data);
  79.                                 }
  80.                         }
  81.                        
  82.                         if (afterCallback) {
  83.                                 afterCallback();
  84.                         }
  85.                 });
  86.                 return settings;
  87.         };
  88.  
  89.         popdownWindow = function(object, event) {
  90.                 if (typeof event == 'undefined') {
  91.                         event = 'click';
  92.                 }
  93.                 object = jQuery(object);
  94.                 if (!(object instanceof jQuery)) {
  95.                         return false;
  96.                 }
  97.                 object.unbind(event, object.handler);
  98.         };
  99.  
  100. })(jQueryUrvanovSyntaxHighlighter);

Raw Paste

Login or Register to edit or fork this paste. It's free.