couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject svn commit: r1583561 - /couchdb/site/script/smooth.js
Date Tue, 01 Apr 2014 08:00:06 GMT
Author: kxepal
Date: Tue Apr  1 08:00:05 2014
New Revision: 1583561

URL: http://svn.apache.org/r1583561
Log:
Fix code style for smooth.js

Modified:
    couchdb/site/script/smooth.js

Modified: couchdb/site/script/smooth.js
URL: http://svn.apache.org/viewvc/couchdb/site/script/smooth.js?rev=1583561&r1=1583560&r2=1583561&view=diff
==============================================================================
--- couchdb/site/script/smooth.js (original)
+++ couchdb/site/script/smooth.js Tue Apr  1 08:00:05 2014
@@ -4,95 +4,128 @@
  *
  *  For details, please check the website : http://dezinerfolio.com/
  *
-/*--------------------------------------------------------------------------*/
+ *--------------------------------------------------------------------------*/
+
+/*jshint boss: true */
+/*jslint plusplus: true */
+
+
+var Scroller = (function () {
+    "use strict";
+
+    var onclickHandler = function () {
+        Scroller.end(this);
+        var l = this.hash.substr(1),
+            a = document.getElementsByTagName('a'),
+            i;
+        for (i = 0; i < a.length; i++) {
+            if (a[i].id === l) {
+                clearInterval(Scroller.interval);
+                Scroller.interval = setInterval(
+                    'Scroller.scroll(' + Scroller.gy(a[i]) + ')',
+                    10
+                );
+            }
+        }
+    };
+
+    return {
+        // control the speed of the scroller.
+        // don't change it here directly, please use Scroller.speed=50;
+        speed: 10,
+
+        // returns the Y position of the div
+        gy: function (d) {
+            var gy = d.offsetTop;
+            while (d = d.offsetParent) {
+                gy += d.offsetTop;
+            }
+            return gy;
+        },
+
+        // returns the current scroll position
+        scrollTop: function () {
+            var body = document.body,
+                d = document.documentElement;
+            if (body && body.scrollTop) {
+                return body.scrollTop;
+            }
+            if (d && d.scrollTop) {
+                return d.scrollTop;
+            }
+            if (window.pageYOffset) {
+                return window.pageYOffset;
+            }
+            return 0;
+        },
+
+        // attach an event for an element
+        // (element, type, function)
+        add: function (event, body, d) {
+            if (event.addEventListener) {
+                return event.addEventListener(body, d, false);
+            }
+            if (event.attachEvent) {
+                return event.attachEvent('on' + body, d);
+            }
+            return null;
+        },
+
+        // kill an event of an element
+        end: function (e) {
+            if (e.preventDefault && e.stopPropagation) {
+                e.preventDefault();
+                e.stopPropagation();
+            } else if (window.event) {
+                window.event.cancelBubble = true;
+                window.event.returnValue = false;
+            }
+        },
+
+        // move the scroll bar to the particular div.
+        scroll: function (d) {
+            var a = Scroller.scrollTop();
+            if (d > a) { // going down
+                a += Math.ceil((d - a) / Scroller.speed);
+            } else {     // going up
+                a = a + (d - a) / Scroller.speed;
+            }
+            window.scrollTo(0, a);
+            if (a === d || Scroller.offsetTop === a) {
+                clearInterval(Scroller.interval);
+            }
+            Scroller.offsetTop = a;
+        },
+
+        // initializer that adds the renderer to the onload function of
+        // the window
+        init: function () {
+            Scroller.add(window, 'load', Scroller.render);
+        },
+
+        // this method extracts all the anchors and validates then as #
+        // and attaches the events.
+        render: function () {
+            Scroller.end(this);
+            var a = document.getElementsByTagName('a');
+            for (var i = 0; i < a.length; i++) {
+                var l = a[i],
+                    has_hash = l.href && l.href.indexOf('#') !== -1,
+                    is_cur_loc = l.pathname === location.pathname;
+                is_cur_loc |= '/' + l.pathname === location.pathname;
+                if (has_hash && is_cur_loc) {
+                    Scroller.add(l, 'click', Scroller.end);
+                    l.onclick = onclickHandler;
+                }
+            }
+        }
+    };
+
+}());
 
-Scroller = {
-	// control the speed of the scroller.
-	// dont change it here directly, please use Scroller.speed=50;
-	speed:10,
-
-	// returns the Y position of the div
-	gy: function (d) {
-		gy = d.offsetTop
-		if (d.offsetParent) while (d = d.offsetParent) gy += d.offsetTop
-		return gy
-	},
-
-	// returns the current scroll position
-	scrollTop: function (){
-		body=document.body
-	    d=document.documentElement
-	    if (body && body.scrollTop) return body.scrollTop
-	    if (d && d.scrollTop) return d.scrollTop
-	    if (window.pageYOffset) return window.pageYOffset
-	    return 0
-	},
-
-	// attach an event for an element
-	// (element, type, function)
-	add: function(event, body, d) {
-	    if (event.addEventListener) return event.addEventListener(body, d,false)
-	    if (event.attachEvent) return event.attachEvent('on'+body, d)
-	},
-
-	// kill an event of an element
-	end: function(e){
-		if (window.event) {
-			window.event.cancelBubble = true
-			window.event.returnValue = false
-      		return;
-    	}
-	    if (e.preventDefault && e.stopPropagation) {
-	      e.preventDefault()
-	      e.stopPropagation()
-	    }
-	},
-
-	// move the scroll bar to the particular div.
-	scroll: function(d){
-		i = window.innerHeight || document.documentElement.clientHeight;
-		h=document.body.scrollHeight;
-		a = Scroller.scrollTop()
-		if(d>a) // going down
-			a+=Math.ceil((d-a)/Scroller.speed)
-		else // going up
-			a = a+(d-a)/Scroller.speed;
-		window.scrollTo(0,a)
-	  	if(a==d || Scroller.offsetTop==a)clearInterval(Scroller.interval)
-	  	Scroller.offsetTop=a
-	},
-	// initializer that adds the renderer to the onload function of the window
-	init: function(){
-		Scroller.add(window,'load', Scroller.render)
-	},
-
-	// this method extracts all the anchors and validates then as # and attaches the events.
-	render: function(){
-		a = document.getElementsByTagName('a');
-		Scroller.end(this);
-		window.onscroll
-	    for (i=0;i<a.length;i++) {
-	      l = a[i];
-	      if(l.href && l.href.indexOf('#') != -1 && ((l.pathname==location.pathname)
|| ('/'+l.pathname==location.pathname)) ){
-	      	Scroller.add(l,'click',Scroller.end)
-	      		l.onclick = function(){
-	      			Scroller.end(this);
-		        	l=this.hash.substr(1);
-		        	 a = document.getElementsByTagName('a');
-				     for (i=0;i<a.length;i++) {
-				     	if(a[i].id == l){
-				     		clearInterval(Scroller.interval);
-				     		Scroller.interval=setInterval('Scroller.scroll('+Scroller.gy(a[i])+')',10);
-						}
-					}
-				}
-	      	}
-		}
-	}
-}
 // invoke the initializer of the scroller
 Scroller.init();
 
 /*------------------------------------------------------------
- *						END OF CODE
-/*-----------------------------------------------------------*/
+ *                      END OF CODE
+ *-----------------------------------------------------------*/



Mime
View raw message