innova-market / jquery-swip

Automatically exported from code.google.com/p/jquery-swip
0 stars 0 forks source link

Additional Function for popupWindow - contributed code #24

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
// Added "rightHalf" feature -- good behavior for displaying reference 
materials in a persistent window.
    (function($){         
    $.fn.popupWindow = function(instanceSettings){

        return this.each(function(){

        $(this).click(function(){

        $.fn.popupWindow.defaultSettings = {
            centerBrowser:0, // center window over browser window? {1 (YES) or 0 (NO)}. overrides top and left
            centerScreen:0, // center window over entire screen? {1 (YES) or 0 (NO)}. overrides top and left
            rightHalf:0, // fill right half of entire screen (or 3/4 if width<1024) {1 (YES) or 0 (NO}. overrides top, left
            height:500, // sets the height in pixels of the window.
            left:0, // left position when the window appears.
            location:0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
            menubar:0, // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
            resizable:0, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
            scrollbars:0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
            status:0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
            width:500, // sets the width in pixels of the window.
            windowName:null, // name of window set from the name attribute of the element that invokes the click
            windowURL:null, // url used for the popup
            top:0, // top position when the window appears.
            toolbar:0 // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
        };

        settings = $.extend({}, $.fn.popupWindow.defaultSettings, instanceSettings || {});

        var windowFeatures =    
                                'toolbar=' + settings.toolbar +
                                ',scrollbars=' + settings.scrollbars +
                                ',status=' + settings.status + 
                                ',resizable=' + settings.resizable +
                                ',location=' + settings.location +
                                ',menuBar=' + settings.menubar;
        var windowSize = ',height=' + settings.height +
                                ',width=' + settings.width;

                settings.windowName = this.name || settings.windowName;
                settings.windowURL = this.href || settings.windowURL;
                var centeredY,centeredX, halfy, halfx, features;

                if (settings.rightHalf){
                    halfy = screen.availTop;
                    halfx = screen.availLeft+(screen.availWidth/2);
                    windowSize = ',height=' + (screen.availHeight) +
                                ',width=' + (screen.availWidth/2);
                  features = windowFeatures+windowSize+',left=' + halfx +',top=' + halfy;
                } else if(settings.centerBrowser){

                    if ($.browser.msie) {//hacked together for IE browsers
                        centeredY = (window.screenTop - 120) + ((((document.documentElement.clientHeight + 120)/2) - (settings.height/2)));
                        centeredX = window.screenLeft + ((((document.body.offsetWidth + 20)/2) - (settings.width/2)));
                    }else{
                        centeredY = window.screenY + (((window.outerHeight/2) - (settings.height/2)));
                        centeredX = window.screenX + (((window.outerWidth/2) - (settings.width/2)));
                    }
                    features = windowFeatures+windowSize+',left=' + centeredX +',top=' + centeredY;
                }else if(settings.centerScreen){
                    centeredY = (screen.height - settings.height)/2;
                    centeredX = (screen.width - settings.width)/2;
                    features = windowFeatures+windowSize+',left=' + centeredX +',top=' + centeredY;
                }else{
                    features = windowFeatures+windowSize+',left=' + settings.left +',top=' + settings.top;
                }
                window.open(settings.windowURL, settings.windowName, features).focus();
                return false;
            });

        }); 
    };
})(jQuery);
</script>
<script>
    $('a').popupWindow({ 
rightHalf:1 
});

Original issue reported on code.google.com by jake.wh...@gmail.com on 18 Aug 2010 at 9:58

GoogleCodeExporter commented 8 years ago
// fill right half of entire screen (or 3/4 if width<1024) {1 (YES) or 0 (NO}. 
overrides top, left

Comment is incorrect -- should read:

// fill right half of entire screen {1 (YES) or 0 (NO}. overrides top, left

Original comment by jake.wh...@gmail.com on 18 Aug 2010 at 10:00