2011-06-21 17:19:10 +08:00
|
|
|
var Overlay = new Class({
|
2019-01-19 23:32:40 +08:00
|
|
|
Implements: [Options, Events],
|
|
|
|
initialize: function( id, options ) {
|
|
|
|
this.setOptions( options );
|
2011-06-21 17:19:10 +08:00
|
|
|
|
2019-01-19 23:32:40 +08:00
|
|
|
this.mask = new Mask( document.body, {'maskMargins': false, 'class': 'overlayMask'} );
|
2011-06-21 17:19:10 +08:00
|
|
|
|
2019-01-19 23:32:40 +08:00
|
|
|
this.id = id?id:'overlay';
|
|
|
|
if ( typeOf(this.id) == 'string' ) {
|
|
|
|
if ( $(this.id) ) {
|
|
|
|
this.element = $(this.id);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.element = this.id;
|
|
|
|
this.id = this.element.get('id');
|
|
|
|
}
|
|
|
|
if ( !this.element ) {
|
|
|
|
this.element = new Element( 'div', {'id': this.id, 'class': 'overlay', 'styles': {'display': 'none'}} );
|
|
|
|
if ( this.options.title || this.options.buttons ) {
|
|
|
|
var overlayHeader = new Element( 'div', {'class': 'overlayHeader'} );
|
|
|
|
if ( this.options.title ) {
|
|
|
|
var overlayTitle = new Element( 'div', {'class': 'overlayTitle', 'text': this.options.title} );
|
|
|
|
overlayHeader.grab( overlayTitle );
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( this.options.buttons ) {
|
|
|
|
var overlayToolbar = new Element( 'div', {'class': 'overlayToolbar'} );
|
|
|
|
this.options.buttons.each(
|
|
|
|
function( button ) {
|
|
|
|
var overlayButton = new Element( 'button', {'text': button.text} );
|
|
|
|
if ( button.id ) {
|
|
|
|
overlayButton.setProperty( 'id', button.id );
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( button.events ) {
|
|
|
|
overlayButton.set( 'events', events );
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
2019-01-19 23:32:40 +08:00
|
|
|
overlayToolbar.grab( overlayButton );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
overlayHeader.grab( overlayTitle );
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
2019-01-19 23:32:40 +08:00
|
|
|
this.element.grab( overlayHeader );
|
|
|
|
var overlayBody = new Element( 'div', {'class': 'overlayBody'} );
|
|
|
|
var overlayContent = new Element( 'div', {'class': 'overlayContent'} );
|
|
|
|
overlayContent.grab( this.options.content );
|
|
|
|
overlayBody.grab( overlayContent );
|
|
|
|
this.element.grab( overlayBody );
|
|
|
|
}
|
|
|
|
this.target = document.id(this.options.target) || document.id(document.body);
|
|
|
|
this.element.inject( this.target );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
show: function() {
|
|
|
|
this.mask.show();
|
|
|
|
$(window).addEvent( 'resize', this.update.bind(this) );
|
|
|
|
$(window).addEvent( 'scroll', this.update.bind(this) );
|
|
|
|
this.element.tween( 'opacity', [0, 1.0] );
|
|
|
|
this.element.show();
|
|
|
|
this.element.position();
|
|
|
|
this.mask.position();
|
|
|
|
},
|
|
|
|
hideComplete: function() {
|
|
|
|
$(window).removeEvent( 'resize', this.update.bind(this) );
|
|
|
|
$(window).removeEvent( 'scroll', this.update.bind(this) );
|
|
|
|
this.element.hide();
|
|
|
|
this.mask.hide();
|
|
|
|
},
|
|
|
|
hide: function() {
|
|
|
|
new Fx.Tween( this.element, {duration: 400, transition: Fx.Transitions.Sine, onComplete: this.hideComplete.bind(this)} ).start( 'opacity', 1.0, 0 );
|
|
|
|
},
|
|
|
|
update: function() {
|
|
|
|
this.element.position();
|
|
|
|
this.mask.position();
|
|
|
|
},
|
|
|
|
showAnimation: function() {
|
|
|
|
showOverlay();
|
2017-03-18 15:00:51 +08:00
|
|
|
|
2019-01-19 23:32:40 +08:00
|
|
|
//console.log( "Showing overlay loading" );
|
|
|
|
if ( !this.loading ) {
|
|
|
|
this.loading = new Element( 'div', {'id': 'loading'+this.key, 'styles': {'display': 'none'}} );
|
|
|
|
this.loading.grab( this.loadingImage );
|
|
|
|
document.body.grab( this.loading );
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
2019-01-19 23:32:40 +08:00
|
|
|
updateOverlayLoading();
|
|
|
|
this.loading.setStyle( 'display', 'block' );
|
|
|
|
$(window).addEvent( 'resize', this.update.bind(this) );
|
|
|
|
$(window).addEvent( 'scroll', this.update.bind(this) );
|
|
|
|
},
|
|
|
|
hideAnimation: function() {
|
|
|
|
$(window).removeEvent( 'resize', this.update.bind(this) );
|
|
|
|
$(window).removeEvent( 'scroll', this.update.bind(this) );
|
|
|
|
if ( this.loading ) {
|
|
|
|
this.loading.setStyle( 'display', 'none' );
|
|
|
|
}
|
|
|
|
}
|
2011-06-21 17:19:10 +08:00
|
|
|
});
|
|
|
|
|
2019-01-19 23:32:40 +08:00
|
|
|
function setupOverlays() {
|
|
|
|
try {
|
2011-06-21 17:19:10 +08:00
|
|
|
$$('.overlay').each(
|
2019-01-19 23:32:40 +08:00
|
|
|
function( overlay ) {
|
|
|
|
overlay.element = new Overlay( overlay.get('id') );
|
|
|
|
overlay.getElements('.overlayCloser').each(
|
|
|
|
function( closer ) {
|
|
|
|
closer.addEvent( 'click', function() {
|
|
|
|
overlay.element.hide();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
overlay.overlayShow = function() {
|
|
|
|
overlay.element.show();
|
|
|
|
};
|
|
|
|
overlay.overlayHide = function() {
|
|
|
|
overlay.element.hide();
|
|
|
|
};
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
);
|
2019-01-19 23:32:40 +08:00
|
|
|
} catch ( e ) {
|
|
|
|
alert( e );
|
|
|
|
}
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
window.addEvent( 'domready', setupOverlays );
|