Skip to content

Commit

Permalink
Fixes #397 Fx.SmoothScroll - The effect wan't smooth at all, and some…
Browse files Browse the repository at this point in the history
… code cleanups

* Probably the previous commit fixed the real problem, but removed some lines of code that were never used.
* Removed Safari 2 code.
* Cleaned up the Tests
  • Loading branch information
Arian committed Sep 30, 2010
1 parent 2acb93e commit e6c5a62
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 95 deletions.
36 changes: 17 additions & 19 deletions Source/Fx/Fx.SmoothScroll.js
Expand Up @@ -28,34 +28,32 @@ provides: [Fx.SmoothScroll]
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){

var win = context.getWindow(),
location = win.location.href.match(/^[^#]*/)[0] + '#',
links = $$(this.options.links || this.doc.links);

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();
}
var el = document.id(anchor) || this.doc.getElement('a[name=' + anchor + ']');
if (!el) return;

event.preventDefault();
this.toElement(el).chain(function(){
this.fireEvent('scrolledTo', [link, el]);
}.bind(this));

}.bind(this));

return this;
}
});
97 changes: 21 additions & 76 deletions Tests/Fx/Fx.SmoothScroll.html
@@ -1,119 +1,64 @@
<p>All the links below should scroll smoothly to their sections.</p>

<a name="top" id="top"></a>

<a href="#A">A</a> |
<a href="#B">B</a> |
<a href="#C">C</a> |
<a href="#D">D</a> |
<a href="#E">E</a> |
<a href="#F">F</a> |
<a href="#G">G</a> |
<a href="#H">H</a> |
<a href="#J">J</a>


<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<a href="#H">H</a>


<div style="height: 300px"></div>
<a name="A" id="A"></a>
A
<a href="#top">Back to top</a>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>

<div style="height: 300px"></div>
<a name="B" id="B"></a>
B
<a href="#top">Back to top</a>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>

<div style="height: 300px"></div>
<a name="C" id="C"></a>
C
<a href="#top">Back to top</a>

<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<div style="height: 300px"></div>
<a name="D" id="D"></a>
D
<a href="#top">Back to top</a>

<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>

<div style="height: 300px"></div>
<a name="E" id="E"></a>
E
<a href="#top">Back to top</a>

<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<div style="height: 300px"></div>
<a name="F" id="F"></a>
F
<a href="#top">Back to top</a>

<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<div style="height: 300px"></div>
<a name="G" id="G"></a>
G
<a href="#top">Back to top</a>

<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<div style="height: 300px"></div>
<a name="H" id="H"></a>
H
<a href="#top">Back to top</a>

<div style="height: 300px"></div>


<script src="/depender/build?require=More/Fx.SmoothScroll"></script>
<script>

new Fx.SmoothScroll();

</script>

0 comments on commit e6c5a62

Please sign in to comment.