/************************************************/ /* IPB3 Javascript */ /* -------------------------------------------- */ /* ips.hoverCard.js - Delayed pop-up menu */ /* (c) IPS, Inc 2010 */ /* -------------------------------------------- */ /* Author: Matt Mecham */ /************************************************/ /* ===================================================================================================== */ /* IPB3 Hover card manager */ IPBoard.prototype.hoverCardRegister = { mainStore: $H(), initialize: function( key, options ) { var store = $H(); /* Insert into main store */ if ( ! ipb.hoverCardRegister.mainStore.get( key ) ) { ipb.hoverCardRegister.mainStore.set( key, options ); } $$('._hovertrigger').each( function( elem ) { try { _key = $(elem).readAttribute( "hovercard-ref" ); if ( key == _key ) { $(elem).addClassName( '___hover___' + key ); store.set( 'key', key ); /* remove trigger class to prevent re-iteration later */ $(elem).removeClassName('_hovertrigger'); $(elem).addClassName('_hoversetup'); } } catch( err ) { Debug.error( err ); } } ); /* Set up cards */ store.each( function( elem ) { new ipb.hoverCard( '___hover___' + elem.value, options ); } ); }, /* Post ajax update 'cos new content added via ajax won't be set up */ postAjaxInit: function() { ipb.hoverCardRegister.mainStore.each( function( elem ) { ipb.hoverCardRegister.initialize( elem.key, elem.value ); } ); } }; IPBoard.prototype.hoverCard = Class.create( { /** * options.ajaxUrl: Pass a complete ajax URL in. * options.ajaxCacheExpire: Number of seconds to store the ajax cache. 0 to not cache * options.type : Balloon* or pane * options.position : Auto, topLeft, bottomLeft*, topRight, bottomRight */ /*------------------------------*/ /* Constructor */ initialize: function( className, options ) { this.id = className; this.timer = {}, this.card = false, this.ajaxCache = {}, this.popupActive = {}, this.openId = false; this.curEvent = false; this.options = Object.extend( { type: 'balloon', position: 'bottomLeft', w: '500px', openOnClick: false, openOnHover: true, ajaxUrl: false, delay: 800, ajaxCacheExpire: 0, black: false, getId: false, setIdParam: 'id', callback: false }, arguments[1] ); this.init(); }, init: function() { this.debugWrite( "hoverCard.init()" ); /* Scoping issues #ftl */ var _hc = this; document.observe( 'mousemove', _hc.mMove.bindAsEventListener( _hc ) ); /* Set up elements */ $$('.' + this.id ).each( function( elem ) { elem.identify(); try { Event.stopObserving( $( elem.id ), 'mouseout' ); Event.stopObserving( $( elem.id ), 'mouseover' ); /* title attributes murder the pop-up effect */ $( elem.id ).writeAttribute( 'title', '' ); if ( $( elem.id ).down('a') ) { $( elem.id ).down('a').writeAttribute( 'title', '' ); } if( $( elem.id ).down('img') ) { $( elem.id ).down('img').writeAttribute( 'title', '' ); $( elem.id ).down('img').writeAttribute( 'alt', '' ); } } catch (aBall){} $( elem.id ).observe( 'contextmenu' , _hc.mContext.bindAsEventListener( _hc, elem.id ) ); $( elem.id ).observe( 'click' , _hc.mClick.bindAsEventListener( _hc, elem.id ) ); $( elem.id ).observe( 'mouseover' , _hc.mOver.bindAsEventListener( _hc, elem.id ) ); $( elem.id ).observe( 'mouseout' , _hc.mOut.bindAsEventListener( _hc, elem.id ) ); } ); }, /** * Mouse Move */ mMove: function(e) { /* IE loses reference to event, so we need to copy it instead of use original reference */ var _newEvent = {}; for( var i in e ) { _newEvent[i] = e[i]; } this.curEvent = _newEvent; }, /** * ITEM CLICK */ mClick: function(e, id) { if ( ! this.options.openOnClick ) { this.close(id); } else { if ( $(id).tagName.toLowerCase() == 'input' && $(id).type.toLowerCase() == 'checkbox' ) { /* If this is a checkbox, and we're choosing to show on click then we probably only * want to show the card if we're clicking 'true' */ if ( $(id).checked !== true ) { return true; } } this.show(id); } }, /** * ITEM Context menu */ mContext: function(e, id) { this.close(id); }, /** * ITEM MOUSEOVER */ mOver: function(e, id) { Event.stop(e); if ( this.overPopUp(id) === true ) { return false; } if ( this.options.openOnHover !== true ) { return false; } this.debugWrite( "mover - setting time OVER " + id ); if ( ! Object.isUndefined( this.timer[id + '_out'] ) ) { clearTimeout( this.timer[id + '_out'] ); } /* Set timer */ this.timer[id + '_over'] = setTimeout( this.show.bind(this, id), this.options.delay ); }, /* * ITEM MOUSEOUT */ mOut: function(e, id) { Event.stop(e); if ( this.overPopUp(id) === true ) { return false; } /* Pop up class dominates the mouseover class */ Event.stopObserving( $( id ), 'mouseover' ); $( id ).observe( 'mouseover' , this.mOver.bindAsEventListener( this, id ) ); /* Clear any time out */ if ( ! Object.isUndefined( this.timer[id + '_over'] ) ) { clearTimeout( this.timer[id + '_over'] ); } /* Set timer */ this.debugWrite( "Mout - setting time OUT " + id ); this.timer[id + '_out'] = setTimeout( this.close.bind(this, id), 800 ); }, /* * SHOW POP UP */ show: function(id) { var popup = 'pu__' + this.id + '_popup'; /* Clear any time out */ if ( ! Object.isUndefined( this.timer[id + '_out'] ) ) { clearTimeout( this.timer[id + '_out'] ); } if ( ! Object.isUndefined( this.card ) && this.card !== false ) { this.card.kill(); this.card = false; } /* If we have an old popup from a previous class method, kill it 'cos this.card won't be populated */ if ( $(popup) ) { $(popup).remove(); } /* Set this as open */ this.openId = id; var content = false; if ( this.options.ajaxUrl ) { content = "