mirror of
https://github.com/lazylibrarian/LazyLibrarian.git
synced 2026-02-05 19:51:00 -05:00
So branching to new branch, and will merge my changes from itsmeg ontop will merge branch back to head once everyone happy its stable.
80 lines
1.6 KiB
JavaScript
80 lines
1.6 KiB
JavaScript
var Question = new Class( {
|
|
|
|
initialize : function(question, hint, answers) {
|
|
var self = this
|
|
|
|
self.question = question
|
|
self.hint = hint
|
|
self.answers = answers
|
|
|
|
self.createQuestion()
|
|
self.answers.each(function(answer) {
|
|
self.createAnswer(answer)
|
|
})
|
|
self.createMask()
|
|
|
|
},
|
|
|
|
createMask : function() {
|
|
var self = this
|
|
|
|
self.mask = new Element('div.mask').fade('hide').inject(document.body).fade('in');
|
|
},
|
|
|
|
createQuestion : function() {
|
|
|
|
this.container = new Element('div', {
|
|
'class' : 'question'
|
|
}).adopt(
|
|
new Element('div.title', {
|
|
'html': ('<h1>' + this.hint + '</h1>')
|
|
}),
|
|
new Element('h3', {
|
|
'html': this.question
|
|
})
|
|
).inject(document.body)
|
|
|
|
this.container.position( {
|
|
'position' : 'center'
|
|
});
|
|
|
|
},
|
|
|
|
createAnswer : function(options) {
|
|
var self = this
|
|
|
|
var answer = new Element('a', Object.merge(options, {
|
|
'class': 'answer button ' + (options['class'] || '') + (options['cancel'] ? ' grey cancel' : '')
|
|
})).inject(this.container)
|
|
|
|
if (options.cancel) {
|
|
answer.addEvent('click', self.close.bind(self))
|
|
}
|
|
else if (options.request) {
|
|
answer.addEvent('click', function(e){
|
|
e.stop();
|
|
new Request(Object.merge(options, {
|
|
'url': options.href,
|
|
'onComplete': function() {
|
|
(options.onComplete || function(){})()
|
|
self.close();
|
|
}
|
|
})).send();
|
|
});
|
|
}
|
|
},
|
|
|
|
close : function() {
|
|
var self = this;
|
|
self.mask.fade('out');
|
|
(function(){self.mask.destroy()}).delay(1000);
|
|
|
|
this.container.destroy();
|
|
},
|
|
|
|
toElement : function() {
|
|
return this.container
|
|
}
|
|
|
|
})
|