Skip to content

Instantly share code, notes, and snippets.

@mattparker
Created February 25, 2010 21:21
Show Gist options
  • Save mattparker/315048 to your computer and use it in GitHub Desktop.
Save mattparker/315048 to your computer and use it in GitHub Desktop.
initPanel:function(){
if( this.panel === '' )
{
YAHOO.util.Dom.removeClass( "detailPopupPanelContainer", "hidden");
this.panel = new YAHOO.widget.Panel( "detailPopupPanelContainer" ,
{close:true,
draggable:true,
underlay:"shadow",
xy: [100,75],
modal:false,
width:"800px"}
);
this.panel.render();
this.panel.hide();
var printNode = document.createElement( "a" );
printNode.innerHTML = "print";
YAHOO.util.Dom.addClass( printNode, "panel-print" );
YAHOO.util.Dom.insertBefore( printNode, YAHOO.util.Dom.getElementsByClassName( "container-close" , "a", "detailPopupPanelContainer" )[0] );
YAHOO.util.Event.addListener( printNode, "click", this.printPanel , this, true );
var maxNode = document.createElement( "a" );
maxNode.innerHTML = "max";
YAHOO.util.Dom.addClass( maxNode, "panel-maximise" );
YAHOO.util.Dom.addClass( maxNode, "panel-minmax-button" );
YAHOO.util.Dom.insertBefore( maxNode, YAHOO.util.Dom.getElementsByClassName( "container-close" , "a", "detailPopupPanelContainer" )[0] );
YAHOO.util.Event.addListener( maxNode, "click", this.toggleMaximiseRestorePanel , this, true );
}
},
toggleMaximiseRestorePanel:function(ev){
var Dom = YAHOO.util.Dom,
maxNode = Dom.getElementsByClassName( "panel-minmax-button", "a", "detailPopupPanelContainer" )[0];
// maximise
if( Dom.hasClass( maxNode, "panel-maximise" ) ){
this.maximisePanel(ev);
}
// restore
else if (Dom.hasClass( maxNode, "panel-restore" ) ){
this.restorePanel(ev);
}
},
maximisePanel: function(ev){
var Dom = YAHOO.util.Dom,
maxNode = Dom.getElementsByClassName( "panel-minmax-button", "a", "detailPopupPanelContainer" )[0],
p = this.panel;
// remember where it was
this._prevPanelPosition = { x: p.cfg.getProperty( "x" ), y: p.cfg.getProperty( "y" ),
w: p.cfg.getProperty( "width" ),
h: p.cfg.getProperty( "height" ) ?
p.cfg.getProperty( "height" ) :
Dom.getRegion( "detailPopupPanelContainer" ).height + "px" };
p.moveTo( 10, 40 );
p.cfg.setProperty( "width" , ( Dom.getDocumentWidth() - 20 )+ "px");
p.cfg.setProperty( "height" , Dom.getDocumentHeight() + "px" );
Dom.removeClass( maxNode, "panel-maximise" );
Dom.addClass( maxNode, "panel-restore" );
},
restorePanel: function(ev){
var Dom = YAHOO.util.Dom,
maxNode = Dom.getElementsByClassName( "panel-minmax-button", "a", "detailPopupPanelContainer" )[0],
p = this.panel;
var prev = this._prevPanelPosition;
p.moveTo( prev.x, prev.y );
p.cfg.setProperty( "width" , prev.w );
p.cfg.setProperty( "height" , prev.h );
YAHOO.util.Dom.setStyle( p.body, "height" , prev.h );
Dom.removeClass( maxNode, "panel-restore" );
Dom.addClass( maxNode, "panel-maximise" );
},
printPanel: function(ev){
var Dom = YAHOO.util.Dom,
maxNode = Dom.getElementsByClassName( "panel-minmax-button", "a", "detailPopupPanelContainer" )[0];
// maximise if necessary
if (Dom.hasClass( maxNode, "panel-maximise" ) ){
this.maximisePanel( ev );
}
window.print();
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment