mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-07-08 17:34:26 +03:00
268 lines
6.3 KiB
JavaScript
268 lines
6.3 KiB
JavaScript
//MooTools More, <http://mootools.net/more>. Copyright (c) 2006-2008 Valerio Proietti, <http://mad4milk.net>, MIT Style License.
|
|
|
|
/*
|
|
Script: Fx.Slide.js
|
|
Effect to slide an element in and out of view.
|
|
|
|
License:
|
|
MIT-style license.
|
|
*/
|
|
|
|
Fx.Slide = new Class({
|
|
|
|
Extends: Fx,
|
|
|
|
options: {
|
|
mode: 'vertical'
|
|
},
|
|
|
|
initialize: function(element, options){
|
|
this.addEvent('complete', function(){
|
|
this.open = (this.wrapper['offset' + this.layout.capitalize()] != 0);
|
|
if (this.open && Browser.Engine.webkit419) this.element.dispose().inject(this.wrapper);
|
|
}, true);
|
|
this.element = this.subject = $(element);
|
|
this.parent(options);
|
|
var wrapper = this.element.retrieve('wrapper');
|
|
this.wrapper = wrapper || new Element('div', {
|
|
styles: $extend(this.element.getStyles('margin', 'position'), {'overflow': 'hidden'})
|
|
}).wraps(this.element);
|
|
this.element.store('wrapper', this.wrapper).setStyle('margin', 0);
|
|
this.now = [];
|
|
this.open = true;
|
|
},
|
|
|
|
vertical: function(){
|
|
this.margin = 'margin-top';
|
|
this.layout = 'height';
|
|
this.offset = this.element.offsetHeight;
|
|
},
|
|
|
|
horizontal: function(){
|
|
this.margin = 'margin-left';
|
|
this.layout = 'width';
|
|
this.offset = this.element.offsetWidth;
|
|
},
|
|
|
|
set: function(now){
|
|
this.element.setStyle(this.margin, now[0]);
|
|
this.wrapper.setStyle(this.layout, now[1]);
|
|
return this;
|
|
},
|
|
|
|
compute: function(from, to, delta){
|
|
var now = [];
|
|
var x = 2;
|
|
x.times(function(i){
|
|
now[i] = Fx.compute(from[i], to[i], delta);
|
|
});
|
|
return now;
|
|
},
|
|
|
|
start: function(how, mode){
|
|
if (!this.check(arguments.callee, how, mode)) return this;
|
|
this[mode || this.options.mode]();
|
|
var margin = this.element.getStyle(this.margin).toInt();
|
|
var layout = this.wrapper.getStyle(this.layout).toInt();
|
|
var caseIn = [[margin, layout], [0, this.offset]];
|
|
var caseOut = [[margin, layout], [-this.offset, 0]];
|
|
var start;
|
|
switch (how){
|
|
case 'in': start = caseIn; break;
|
|
case 'out': start = caseOut; break;
|
|
case 'toggle': start = (this.wrapper['offset' + this.layout.capitalize()] == 0) ? caseIn : caseOut;
|
|
}
|
|
return this.parent(start[0], start[1]);
|
|
},
|
|
|
|
slideIn: function(mode){
|
|
return this.start('in', mode);
|
|
},
|
|
|
|
slideOut: function(mode){
|
|
return this.start('out', mode);
|
|
},
|
|
|
|
hide: function(mode){
|
|
this[mode || this.options.mode]();
|
|
this.open = false;
|
|
return this.set([-this.offset, 0]);
|
|
},
|
|
|
|
show: function(mode){
|
|
this[mode || this.options.mode]();
|
|
this.open = true;
|
|
return this.set([0, this.offset]);
|
|
},
|
|
|
|
toggle: function(mode){
|
|
return this.start('toggle', mode);
|
|
}
|
|
|
|
});
|
|
|
|
Element.Properties.slide = {
|
|
|
|
set: function(options){
|
|
var slide = this.retrieve('slide');
|
|
if (slide) slide.cancel();
|
|
return this.eliminate('slide').store('slide:options', $extend({link: 'cancel'}, options));
|
|
},
|
|
|
|
get: function(options){
|
|
if (options || !this.retrieve('slide')){
|
|
if (options || !this.retrieve('slide:options')) this.set('slide', options);
|
|
this.store('slide', new Fx.Slide(this, this.retrieve('slide:options')));
|
|
}
|
|
return this.retrieve('slide');
|
|
}
|
|
|
|
};
|
|
|
|
Element.implement({
|
|
|
|
slide: function(how, mode){
|
|
how = how || 'toggle';
|
|
var slide = this.get('slide'), toggle;
|
|
switch (how){
|
|
case 'hide': slide.hide(mode); break;
|
|
case 'show': slide.show(mode); break;
|
|
case 'toggle':
|
|
var flag = this.retrieve('slide:flag', slide.open);
|
|
slide[(flag) ? 'slideOut' : 'slideIn'](mode);
|
|
this.store('slide:flag', !flag);
|
|
toggle = true;
|
|
break;
|
|
default: slide.start(how, mode);
|
|
}
|
|
if (!toggle) this.eliminate('slide:flag');
|
|
return this;
|
|
}
|
|
|
|
});
|
|
|
|
|
|
/*
|
|
Script: Fx.Scroll.js
|
|
Effect to smoothly scroll any element, including the window.
|
|
|
|
License:
|
|
MIT-style license.
|
|
*/
|
|
|
|
Fx.Scroll = new Class({
|
|
|
|
Extends: Fx,
|
|
|
|
options: {
|
|
offset: {'x': 0, 'y': 0},
|
|
wheelStops: true
|
|
},
|
|
|
|
initialize: function(element, options){
|
|
this.element = this.subject = $(element);
|
|
this.parent(options);
|
|
var cancel = this.cancel.bind(this, false);
|
|
|
|
if ($type(this.element) != 'element') this.element = $(this.element.getDocument().body);
|
|
|
|
var stopper = this.element;
|
|
|
|
if (this.options.wheelStops){
|
|
this.addEvent('start', function(){
|
|
stopper.addEvent('mousewheel', cancel);
|
|
}, true);
|
|
this.addEvent('complete', function(){
|
|
stopper.removeEvent('mousewheel', cancel);
|
|
}, true);
|
|
}
|
|
},
|
|
|
|
set: function(){
|
|
var now = Array.flatten(arguments);
|
|
this.element.scrollTo(now[0], now[1]);
|
|
},
|
|
|
|
compute: function(from, to, delta){
|
|
var now = [];
|
|
var x = 2;
|
|
x.times(function(i){
|
|
now.push(Fx.compute(from[i], to[i], delta));
|
|
});
|
|
return now;
|
|
},
|
|
|
|
start: function(x, y){
|
|
if (!this.check(arguments.callee, x, y)) return this;
|
|
var offsetSize = this.element.getSize(), scrollSize = this.element.getScrollSize();
|
|
var scroll = this.element.getScroll(), values = {x: x, y: y};
|
|
for (var z in values){
|
|
var max = scrollSize[z] - offsetSize[z];
|
|
if ($chk(values[z])) values[z] = ($type(values[z]) == 'number') ? values[z].limit(0, max) : max;
|
|
else values[z] = scroll[z];
|
|
values[z] += this.options.offset[z];
|
|
}
|
|
return this.parent([scroll.x, scroll.y], [values.x, values.y]);
|
|
},
|
|
|
|
toTop: function(){
|
|
return this.start(false, 0);
|
|
},
|
|
|
|
toLeft: function(){
|
|
return this.start(0, false);
|
|
},
|
|
|
|
toRight: function(){
|
|
return this.start('right', false);
|
|
},
|
|
|
|
toBottom: function(){
|
|
return this.start(false, 'bottom');
|
|
},
|
|
|
|
toElement: function(el){
|
|
var position = $(el).getPosition(this.element);
|
|
return this.start(position.x, position.y);
|
|
}
|
|
|
|
});
|
|
|
|
|
|
/*
|
|
Script: SmoothScroll.js
|
|
Class for creating a smooth scrolling effect to all internal links on the page.
|
|
|
|
License:
|
|
MIT-style license.
|
|
*/
|
|
|
|
var SmoothScroll = new Class({
|
|
|
|
Extends: Fx.Scroll,
|
|
|
|
initialize: function(options, context){
|
|
context = context || document;
|
|
var doc = context.getDocument(), win = context.getWindow();
|
|
this.parent(doc, options);
|
|
this.links = (this.options.links) ? $$(this.options.links) : $$(doc.links);
|
|
var location = win.location.href.match(/^[^#]*/)[0] + '#';
|
|
this.links.each(function(link){
|
|
if (link.href.indexOf(location) != 0) return;
|
|
var anchor = link.href.substr(location.length);
|
|
if (anchor && $(anchor)) this.useLink(link, anchor);
|
|
}, this);
|
|
if (!Browser.Engine.webkit419) this.addEvent('complete', function(){
|
|
win.location.hash = this.anchor;
|
|
}, true);
|
|
},
|
|
|
|
useLink: function(link, anchor){
|
|
link.addEvent('click', function(event){
|
|
this.anchor = anchor;
|
|
this.toElement(anchor);
|
|
event.stop();
|
|
}.bind(this));
|
|
}
|
|
|
|
}); |