JS 자동 적응 그림 창 인 스 턴 스


/************************************ *********************************/
var autoImg=function(argcs){/* , argcs['maxHeight']=> ,argcs['maxWidth']=> ,argcs['height']=> ,argcs['width']=> */
                var _maxHeight='';
                var _maxWidth='';
                var _newSize=[];

                if(argcs['maxHeight']){
                    _maxHeight=argcs['maxHeight'];
                    }
                if(argcs['maxWidth']){
                    _maxWidth=argcs['maxWidth'];
                    }
                if(!argcs['height']){
                    throw new Error('height ');
                    }
                if(!argcs['width']){
                    throw new Error('width ');
                    }
                if(argcs['height']>argcs['width']||argcs['height']==argcs['width']){//
                        if(argcs['height']>=_maxHeight){
                                _newSize['height']=_maxHeight;
                                _newSize['width']=(_maxHeight/argcs['height'])*argcs['width'];
                            }else{
                                _newSize['width']=argcs['width'];
                                _newSize['height']=argcs['height'];
                                }
                        return _newSize;
                    }
                if(argcs['width']>argcs['height']){//
                        if(argcs['width']>=_maxWidth){
                                _newSize['width']=_maxWidth;
                                _newSize['height']=(_maxWidth/argcs['width'])*argcs['height'];
                            }else{
                                _newSize['width']=argcs['width'];
                                _newSize['height']=argcs['height'];
                                }
                        return _newSize;
                    }               
                }

    var imgBox=function(imgSrc){            
            var winImg=new popBox({//
                ID:'imgBox',
                bgColor:'#a3c90e',
                width:906,
                moveHandle:false,
                closeButton:false,
                height:'auto',
                times:250,
                lock:true,
                content:'',
                shadow:true,
                position:'center',
                displayCallBack:function(){
                                       $('body').append('<img id="loading" src="/template/27/img/loading.gif"/>');
                    $('img[id=loading]').css('z-index',110000).css({position:'absolute',left:$(window).scrollLeft()+($(window).width())/2-($('img[id=loading]').width())/2-22,top:$(window).scrollTop()+($(window).height()/2-($('img[id=loading]').width())/2)});
                    /************ , **************/
                    var img=new Image();
                    var _imgWidth=0;
                    var _imgHeight=0;
                    img.src=imgSrc;// img
                                       // console.log(imgSrc);
                                        /************************* ***************************/
                    img.onload=function(){
                                               $('img[id=loading]').remove();
                        _imgWidth=img.width;
                        _imgHeight=img.height;
                        var argcs=[];
                        var winWidth=$(window).width();
                        argcs['maxHeight']=750;//
                        argcs['maxWidth']=900;//
                        argcs['height']=_imgHeight;
                        argcs['width']=_imgWidth;
                        var newWH=autoImg(argcs);//
                        /************ , ************/
                        $('#'+winImg.ID).css({width:newWH['width'],height:newWH['height'],top:parseInt($(document).scrollTop())+parseInt(($(window).height()-newWH['height'])/2),left:$(document).scrollLeft()+parseInt(winWidth/2)-parseInt(newWH['width']/2)});
                        $('#'+winImg.ID).html('<img src="'+img.src+'" width="'+newWH['width']+'" height="'+newWH['height']+'"/>');
                        /************ , **************/

                        $('#'+winImg.ID+'_bg').css('cursor','pointer').click(function(){
                            winImg.kill();
                            });
                        };
                                        /************************* ***************************/ 
                    },
                unDisplayCallBack:function(){

                    },
                killCallBack:function(){
                    }
                });
                winImg.dispaly();
    }
popBox 코드

// , jQuery UI
var popBox=function(settings){// settings=[]
        //alert(typeof settings['width']);
        //alert(settings['displayCallBack']);
        /************************ *****************************/
        /******************* *****************/
        var _shadow=true;// true/false
        var _closeButton=false;// false/dom
        var _killButton=false;//kill false/dom
        var _moveHandle=false;// false/dom
        var _width=650;// ,
        var _bgColor='#FFF';//
        var _height='auto';//
        var _content=' ';//
        var _position='center';/* topLeft,topCenter,topRight,center,bottomLeft,bottomRight,bottomCenter*/
        var _lock=true;//
        var _times=500;// ,
        var _displayCallBack=function(){//dispaly
                alert('display');
            }
        var _unDisplayCallBack=function(){//unDispaly
                alert('unDisplay');
            }
        var _beforeKillCallBack=function(){
                alert('beforeKill');
            }//kill
        var _killCallBack=function(){//kill
                alert('kill');
            }
        /******************* *****************/
        if(settings['closeButton']!==undefined){
            //alert('shadow');
            _closeButton=settings['closeButton'];
            }   
        if(settings['killButton']!==undefined){
            //alert('shadow');
            _killButton=settings['killButton'];
            }
        if(settings['moveHandle']!==undefined){
            //alert('shadow');
            _moveHandle=settings['moveHandle'];
            }               
        /****************** ********************/
        /**settings['shadow']!=' ' && settings['shadow']!=undefined*/
        if(settings['shadow']!==undefined){
            //alert('shadow');
            _shadow=settings['shadow'];
            }
        if(settings['bgColor']!==undefined){
            //alert('shadow');
            _bgColor=settings['bgColor'];
            }
        if( settings['width']!==undefined){
            _width=settings['width'];
            }
        if( settings['height']!==undefined){
            _height=settings['height'];
            }
        if(settings['content']!==undefined){
            _content=settings['content'];
            }
        if(settings['position']!==undefined){
            _position=settings['position'];
            }
        if( settings['times']!==undefined){
            _times=settings['times'];
            }
        if(settings['lock']!==undefined){
            _lock=settings['lock'];
            }
        if(settings['displayCallBack']!=undefined){
            //alert('here');
            _displayCallBack=settings['displayCallBack'];
            }       
        if( settings['unDisplayCallBack']!==undefined){
            _unDisplayCallBack=settings['unDisplayCallBack'];
            }   
        if( settings['beforeKillCallBack']!==undefined){
            _beforeKillCallBack=settings['beforeKillCallBack'];
            }
        if( settings['killCallBack']!==undefined){
            _killCallBack=settings['killCallBack'];
            }

        //alert(settings['shadow']);
        //alert(_shadow);
        /************************ ******************************/

        

        /********************* ********************/   
        var _this=this;             
        var _baseZindex=10000;
        var _domWidth=$(document).width();
        var _domHeight=$(document).height();
        /******************** *******************/

        
        /******************** **********************/
        var _getZindex=function(){/* z-index-> div ID popBox DOM, , z-index= + +1, z-index= + +2*/
                var _len=$('body').children('div').length;
                var _countDiv=0;
                var _divObj=$('body').children('div');
                var _reg=/^popBox_/;//
                for(var i=0;i<_len;i++){
                    if(_reg.test(_divObj.eq(i).attr('ID'))){
                            _countDiv+=1;
                        }
                    }
                return _countDiv;//
            }
        var _getWinZindex=function(){// z-index
                var _winZindex=_baseZindex+_getZindex()+2;
                return _winZindex;
            }
        var _geWinBgZindex=function(){// z-index
                var _winBgZindex=_baseZindex+_getZindex()+1;
                return _winBgZindex;                
            }
        var _renderBg=function(){//   www.jb51.net
                var _winBgZindex=_geWinBgZindex();
                //alert($(document).height());
                $('body').append('<div id="'+_this.ID+'_bg"></div>');// body
                $('#'+_this.ID+'_bg').addClass('popBox_bg').css({height:_domHeight,width:_domWidth,opcity:0}).css('z-index',_winBgZindex).fadeTo(_times,0.7);
            }
        var _creatWin=function(){//
                $('body').append('<div id="'+_this.ID+'"></div>');
                _renderContent(_content);//
                _initWin();//
            }
        var _initWin=function(){//
                var _winZindex=_getWinZindex();
                var _transHeight=0;
                if(_height=='auto'){
                    _transHeight='auto';
                    }else{
                        _transHeight=parseInt(_height)+'px';
                        }
                $('#'+_this.ID).css({width:parseInt(_width)+'px',height:_transHeight,position:'absolute',opticity:1.0,background:_bgColor}).css('z-index',_winZindex);
                if(_lock==false){
                    if(_moveHandle!==undefined&&_moveHandle!==false&&_moveHandle!==' '){
                        $('#'+_this.ID).children(_moveHandle).css('cursor','move');
                        //alert(_moveHandle);
                        //alert($('#'+_this.ID).children(_moveHandle).html());
                        }
                    }
                _locationWin();//
            }
        var _locationWin=function(){/* topLeft,topCenter,topRight,centerLeft,center,centerRight,bottomLeft,bottomCenter,bottomRight*/
            var _windowHeight=parseInt($(window).height());
            var _windowWidth=parseInt($(window).width());
            //alert(_windowWidth+_height);  
            var _left=(_windowWidth-parseInt(_width))/2;
            var _top=parseInt($(document).scrollTop())+parseInt(($(window).height()-$('#'+_this.ID).height())/2);
            $('#'+_this.ID).css({top:_top+'px',left:_left+'px'});
            }
        var _renderContent=function(content){//
                $('#'+_this.ID).append(content);
            }
        var bindEvent=function(){//
            if(_this.status!=='kill'&&_this.status!=='init'){
                        if(_closeButton!==undefined&&_closeButton!==' '&&_closeButton!==false){
                            $('#'+_this.ID+' '+_closeButton).css('cursor','pointer').live('click',function(e){
                            _this.unDisplay();
                            });                         
                        }// (close)
                        if(_killButton!==undefined&&_killButton!==' '&&_killButton!==false){
                            $('#'+_this.ID+' '+_killButton).css('cursor','pointer').live('click',function(e){
                            _this.kill();
                            });                         
                        }// (kill)
                    }
                if(_lock==false){
                    $('#'+_this.ID).draggable({cancel:''});
                    }
            }       
        /********************* *****************/

        
        /********************** ******************/
        this.status='init';// init-> ,display->display ,undisplay->undisplay ,kill->kill
        this.ID='';
        var _ID=settings['ID'];
        if(_ID==' '||(typeof _ID)==undefined){
            throw new Error('ID ');
            }else{
                this.ID='popBox_'+_ID;
                }
        this.display=function(){// , init kill
            //alert(_this.status);
            if(_this.status=='init'||_this.status=='kill'){
                    _creatWin();//
                    //$('#'+_this.ID).css('height',_domHeight);
                    if(_shadow==true){//
                        /*alert(_shadow);*/
                        _renderBg();
                        }
                    _this.status='display';
                    _displayCallBack();
                }else{
                    $('#'+_this.ID).fadeIn(_times);
                    if(_shadow==true){
                        $('#'+_this.ID+'_bg').fadeIn(_times);
                        }
                    _this.status='display';
                    }
            //alert(typeof _displayCallBack);
            //alert(_this.status);
            bindEvent();
            }
        this.kill=function(){//
            //alert(_this.status);
            //alert(_this.status);
            if(_this.status=='kill'||_this.status=='init'){
                //alert(_this.status);
                throw new Error(' , kill');
            }
            if(_beforeKillCallBack!=undefined){
                    _beforeKillCallBack();
                    }
            $('#'+_this.ID).remove();
            if(_shadow==true){
                $('#'+_this.ID+'_bg').remove();
                }
            _this.status='kill';
            if(_killCallBack!=undefined){
                    _killCallBack();
                    }
            }
        this.unDisplay=function(){//
            if(_this.status=='init'||_this.status=='kill'){
                throw new Error(' , undisplay');
                }
            if(_unDisplayCallBack!=undefined){
                _unDisplayCallBack();
                }
            $('#'+_this.ID).fadeOut(_times);
            $('#'+_this.ID+'_bg').fadeOut(_times);
            _this.status='undisplay';       
            }
        /********************** ******************/

        
    }//popBox

var errorBox=function(errorMsg){
        //alert(typeof errorBox);
            //alert(errorBox.length);
            var errorObj=new popBox({
            ID:'errorObj',
            bgColor:'#FFF',
            width:300,
            moveHandle:false,
            closeButton:false,
            height:'auto',
            times:200,
            lock:true,
            content:$('#errorBoxContent').html(),
            shadow:true,
            position:'center',
            displayCallBack:function(){ 
                    $('#'+errorObj.ID).find('.errorMessage').html();
                    $('#'+errorObj.ID).find('.errorMessage').html(errorMsg);
                    $('#'+errorObj.ID).find('.errorConfirm input').click(function(){
                        //alert('here');
                        errorObj.kill();
                        });
                },
            unDisplayCallBack:function(){
                throw new Error(' , Kill');// Kill,
                },
            killCallBack:function(){
                //errorBox=null;
                }
            });
        errorObj.dispaly(); 
    }//

좋은 웹페이지 즐겨찾기