2008-07-05 22:28:49 +02:00
|
|
|
var LSconfirmBox = new Class({
|
|
|
|
initialize: function(options) {
|
|
|
|
this._options = options;
|
2009-02-20 14:42:35 +01:00
|
|
|
this.labels = varLSdefault.LSjsConfig['LSconfirmBox_labels'];
|
|
|
|
if (!$type(this.labels)) {
|
|
|
|
this.labels = {
|
|
|
|
title: 'Confirmation',
|
|
|
|
text: 'You confirm your choice ?',
|
|
|
|
validate: 'Validate',
|
|
|
|
cancel: 'Cancel'
|
|
|
|
};
|
|
|
|
}
|
2008-07-05 22:28:49 +02:00
|
|
|
this.create();
|
|
|
|
this.display();
|
|
|
|
},
|
|
|
|
|
|
|
|
create: function() {
|
|
|
|
this.box = new Element('div');
|
|
|
|
this.box.setProperty('id','box-LSconfirmBox');
|
|
|
|
this.box.injectInside(document.body);
|
|
|
|
|
|
|
|
this.title = new Element('p');
|
|
|
|
this.title.setProperty('id','title-LSconfirmBox');
|
|
|
|
if (this._options.title) {
|
|
|
|
this.title.set('html',this._options.title);
|
|
|
|
}
|
|
|
|
else {
|
2009-02-20 14:42:35 +01:00
|
|
|
this.title.set('html',this.labels.title);
|
2008-07-05 22:28:49 +02:00
|
|
|
};
|
|
|
|
this.title.injectInside(this.box)
|
|
|
|
|
|
|
|
this.closeBtn = new Element('span');
|
|
|
|
this.closeBtn.setProperty('id','closeBtn-LSconfirmBox');
|
|
|
|
this.closeBtn.injectInside(this.box);
|
|
|
|
this.closeBtn.addEvent('click',this.cancel.bind(this));
|
|
|
|
|
|
|
|
this.text = new Element('p');
|
|
|
|
this.text.setProperty('id','text-LSconfirmBox');
|
|
|
|
if (this._options.text) {
|
|
|
|
this.text.set('html',this._options.text);
|
|
|
|
}
|
|
|
|
else {
|
2009-02-20 14:42:35 +01:00
|
|
|
this.text.set('html',this.labels.text);
|
2008-07-05 22:28:49 +02:00
|
|
|
}
|
|
|
|
this.text.injectInside(this.box);
|
|
|
|
|
|
|
|
this.btnsBox = new Element('p');
|
|
|
|
this.btnsBox.setProperty('id','btnsBox-LSconfirmBox');
|
|
|
|
this.btnsBox.injectInside(this.box);
|
|
|
|
|
|
|
|
this.confirmBtn = new Element('span');
|
|
|
|
this.confirmBtn.addClass('btn-LSconfirmBox');
|
2009-02-17 12:36:54 +01:00
|
|
|
if (this._options.validate_label) {
|
|
|
|
this.confirmBtn.set('html',this._options.validate_label);
|
|
|
|
}
|
|
|
|
else {
|
2009-02-20 14:42:35 +01:00
|
|
|
this.confirmBtn.set('html',this.labels.validate);
|
2009-02-17 12:36:54 +01:00
|
|
|
}
|
2008-07-05 22:28:49 +02:00
|
|
|
this.confirmBtn.injectInside(this.btnsBox);
|
|
|
|
this.confirmBtn.addEvent('click',this.confirm.bind(this));
|
|
|
|
|
|
|
|
this.cancelBtn = new Element('span');
|
|
|
|
this.cancelBtn.addClass('btn-LSconfirmBox');
|
2009-02-17 12:36:54 +01:00
|
|
|
if (this._options.cancel_label) {
|
|
|
|
this.cancelBtn.set('html',this._options.cancel_label);
|
|
|
|
}
|
|
|
|
else {
|
2009-02-20 14:42:35 +01:00
|
|
|
this.cancelBtn.set('html',this.labels.cancel);
|
2009-02-17 12:36:54 +01:00
|
|
|
}
|
2008-07-05 22:28:49 +02:00
|
|
|
this.cancelBtn.injectInside(this.btnsBox);
|
|
|
|
this.cancelBtn.addEvent('click',this.cancel.bind(this));
|
|
|
|
|
|
|
|
this._purge=0;
|
|
|
|
|
|
|
|
this.fx = {
|
2009-03-16 11:48:42 +01:00
|
|
|
open: new Fx.Morph(this.box, {duration: 500, fps: 30, transition: Fx.Transitions.Sine.easeOut, onComplete: this.displayContent.bind(this)}),
|
|
|
|
close: new Fx.Morph(this.box, {duration: 500, fps: 30, transition: Fx.Transitions.Sine.easeOut, onComplete: this.onClose.bind(this)})
|
2008-07-05 22:28:49 +02:00
|
|
|
};
|
2008-07-28 18:30:40 +02:00
|
|
|
this._scrolling=0;
|
2008-07-05 22:28:49 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
display: function() {
|
|
|
|
this.box.setStyle('display','block');
|
|
|
|
this.position(true);
|
|
|
|
window.addEvent('resize', this.position.bind(this));
|
2008-07-28 18:30:40 +02:00
|
|
|
window.addEvent('scroll', this.positionWhenScrolling.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
positionWhenScrolling: function(oldValue) {
|
|
|
|
if (this._scrolling==0||$type(oldValue)) {
|
|
|
|
this._scrolling = 1;
|
|
|
|
var current = window.getScrollTop().toInt();
|
|
|
|
if (oldValue == current) {
|
|
|
|
this.position();
|
|
|
|
this._scrolling=0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.positionWhenScrolling.delay(200,this,current);
|
|
|
|
}
|
|
|
|
}
|
2008-07-05 22:28:49 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
displayContent: function() {
|
|
|
|
[this.title, this.closeBtn, this.text, this.btnsBox].each(function(el) {
|
2009-03-16 11:48:42 +01:00
|
|
|
var fx = new Fx.Tween(el,{duration: 200, fps: 30});
|
2008-07-28 18:30:40 +02:00
|
|
|
fx.start('opacity',1);
|
2008-07-05 22:28:49 +02:00
|
|
|
},this);
|
|
|
|
},
|
|
|
|
|
|
|
|
hide: function() {
|
|
|
|
this.box.empty();
|
|
|
|
this.fx.close.start(this.getStartStyles());
|
|
|
|
window.removeEvent('resize', this.position.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
onClose: function() {
|
|
|
|
this.box.setStyle('display','none');
|
|
|
|
this.purge();
|
2008-09-25 17:15:33 +02:00
|
|
|
if (this._options.onClose) {
|
|
|
|
$try(this._options.onClose);
|
|
|
|
}
|
2008-07-05 22:28:49 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
purge: function() {
|
|
|
|
this._purge=1;
|
|
|
|
this.box.empty();
|
|
|
|
this.box.destroy();
|
|
|
|
delete this.fx;
|
|
|
|
},
|
|
|
|
|
|
|
|
getStartStyles: function() {
|
2009-02-20 14:42:35 +01:00
|
|
|
if ($type(this._options.startElement)) {
|
2008-07-05 22:28:49 +02:00
|
|
|
var startStyles = {
|
|
|
|
top: this._options.startElement.getCoordinates().top,
|
|
|
|
left: this._options.startElement.getCoordinates().left,
|
2009-02-20 14:42:35 +01:00
|
|
|
width: this._options.startElement.getWidth().toInt(),
|
2008-07-05 22:28:49 +02:00
|
|
|
opacity: 0
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var startStyles = {
|
|
|
|
top: '0px',
|
|
|
|
left: '0px',
|
|
|
|
width: '0px',
|
|
|
|
opacity: 0
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return startStyles;
|
|
|
|
},
|
|
|
|
|
|
|
|
getEndStyles: function() {
|
|
|
|
if (this._options.width) {
|
|
|
|
w = this._options.width;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
w = 300;
|
|
|
|
}
|
|
|
|
|
|
|
|
var endStyles = {
|
|
|
|
width: w.toInt()+'px',
|
|
|
|
top: ((window.getHeight()/2)-(this.box.getStyle('height').toInt()/2)-this.box.getStyle('border').toInt()+window.getScrollTop()).toInt(),
|
|
|
|
left: ((window.getWidth()/2)-(w/2)-this.box.getStyle('border').toInt()).toInt(),
|
|
|
|
opacity: 1
|
|
|
|
};
|
|
|
|
return endStyles;
|
|
|
|
},
|
|
|
|
|
|
|
|
position: function(start) {
|
|
|
|
if (this._purge==0) {
|
|
|
|
var endStyles = this.getEndStyles();
|
|
|
|
if (start) {
|
|
|
|
this.box.setStyles(this.getStartStyles());
|
|
|
|
}
|
|
|
|
this.fx.open.start(endStyles);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
confirm: function() {
|
2008-07-28 18:30:40 +02:00
|
|
|
this.hide();
|
2008-07-05 22:28:49 +02:00
|
|
|
if (this._options.onConfirm) {
|
2008-07-28 18:30:40 +02:00
|
|
|
$try(this._options.onConfirm);
|
2008-07-05 22:28:49 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
cancel: function() {
|
|
|
|
this.hide();
|
2008-09-25 17:15:33 +02:00
|
|
|
if (this._options.onCancel) {
|
|
|
|
$try(this._options.onCancel);
|
|
|
|
}
|
2008-07-05 22:28:49 +02:00
|
|
|
}
|
|
|
|
});
|