Class for creating a smooth scrolling effect to all internal links on the page.
<1.2compat>
Extends: Fx.Scroll,
initialize: function(options, context){
context = context || document;
this.doc = context.getDocument();
var win = context.getWindow();
this.parent(this.doc, options);
this.links = $$(this.options.links || this.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) this.useLink(link, anchor);
}, this);
if (!(Browser.safari && Browser.version == 2)){
this.addEvent('complete', function(){
win.location.hash = this.anchor;
}, true);
}
},
useLink: function(link, anchor){
var el;
link.addEvent('click', function(event){
if (el !== false && !el) el = document.id(anchor) || this.doc.getElement('a[name=' + anchor + ']');
if (el){
event.preventDefault();
this.anchor = anchor;
this.toElement(el).chain(function(){
this.fireEvent('scrolledTo', [link, el]);
}.bind(this));
link.blur();
}
}.bind(this));
}
});