Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Patch for issue #2 Shouldn't alter location.hash if no default target…

… id set
  • Loading branch information...
commit 7dcd0380fa00787d044c209816fd538e472af9f8 1 parent b605f94
Rich Trott authored May 30, 2012
2  LightningTouch.js
@@ -166,7 +166,7 @@
166 166
             }
167 167
         }
168 168
 
169  
-        if (!location.hash) {
  169
+        if ((!location.hash) && (defaultTargetId!=='')) {
170 170
             location.hash = '#/' + defaultTargetId;
171 171
         }
172 172
         showContent(location.hash.substring(2), [defaultTargetId]);
2  demo/LightningTouch-1.0.1.min.js → demo/LightningTouch-1.0.2.min.js
... ...
@@ -1 +1 @@
1  
-(function(){var i=[],n=[],d=[],b,a,f,e,g,j,k,l,c,h,m;k=[];l=function(){k.splice(0,2)};c=function(o,p){k.push(o,p);window.setTimeout(l,2500)};h=function(q){var p,o,r;for(p=0;p<k.length;p+=2){o=k[p];r=k[p+1];if(Math.abs(q.clientX-o)<25&&Math.abs(q.clientY-r)<25){q.stopPropagation();q.preventDefault()}}};document.addEventListener("click",h,true);a=function(o,p){this.element=o;this.handler=p;o.addEventListener("touchstart",this,false);o.addEventListener("click",this,false)};a.prototype.handleEvent=function(o){switch(o.type){case"touchstart":this.onTouchStart(o);break;case"touchmove":this.onTouchMove(o);break;case"touchend":this.onClick(o);break;case"click":this.onClick(o);break}};a.prototype.onTouchStart=function(o){o.stopPropagation();this.element.addEventListener("touchend",this,false);document.body.addEventListener("touchmove",this,false);this.startX=o.touches[0].clientX;this.startY=o.touches[0].clientY};a.prototype.onTouchMove=function(o){if(Math.abs(o.touches[0].clientX-this.startX)>10||Math.abs(o.touches[0].clientY-this.startY)>10){this.reset()}};a.prototype.onClick=function(o){o.stopPropagation();this.reset();this.handler(o);if(o.type==="touchend"){c(this.startX,this.startY)}};a.prototype.reset=function(){this.element.removeEventListener("touchend",this,false);document.body.removeEventListener("touchmove",this,false)};f=function(q,p){var o=d.indexOf(p);if(o<0){o=d.length;d.push(p)}n[o]=q};e=function(p,q,o){o=o||location.pathname+location.hash;f(p,o);history.replaceState(p,q,o)};g=function(q){var p=q?location.pathname+"#/"+q:location.pathname+location.hash,o=d.indexOf(p);return o<0?undefined:n[o]};j=function(p,o){if(p.indexOf(o)<0){p.push(o)}return p};m=function(){var p,o;b=document.body.getAttribute("data-default-target-id")||"";function q(r,t){var v,u,s;u=document.getElementById(r)||document.getElementById(b);if(u){for(s=0;s<t.length;s+=1){v=document.getElementById(t[s]);if(v){v.setAttribute("style","display:none")}}u.setAttribute("style","display:block")}}if(!location.hash){location.hash="#/"+b}q(location.hash.substring(2),[b]);if(!(history instanceof Object&&history.replaceState instanceof Function)){return}this.touchHandler=function(v){var s,x,r,u,w,t;s=this.element.getAttribute("data-target-id");x=document.getElementById(s);if(x!==null){v.preventDefault();r=document.getElementById(location.hash.substr(2));u=r?r.getAttribute("id"):b;q(s,[u]);w=g();t=(w&&w.hasOwnProperty("hide"))?j(w.hide,s):[s];e({show:u,hide:t},"");location.hash="#/"+s;w=g();t=(w&&w.hasOwnProperty("hide"))?j(w.hide,u):[u];e({show:s,hide:t},"")}};p=document.getElementsByTagName("a");for(o=0;o<p.length;o+=1){if(p[o].getAttribute("data-target-id")!==null){i.push(new a(p[o],this.touchHandler))}}this.popHandler=function(t){var u,r,s;u=g();if(u){q(u.show,u.hide)}if(t.state){for(o=0;o<t.state.hide.length;o+=1){r=g(t.state.hide[o]);if(r){s=j(r.hide,t.state.show);f({show:t.state.hide[o],hide:s},location.pathname+"#/"+t.state.hide[o])}}q(t.state.show,t.state.hide)}};window.addEventListener("popstate",this.popHandler,false)};document.addEventListener("DOMContentLoaded",m,false)}());
  1
+(function(){var i=[],n=[],d=[],b,a,f,e,g,j,k,l,c,h,m;k=[];l=function(){k.splice(0,2)};c=function(o,p){k.push(o,p);window.setTimeout(l,2500)};h=function(q){var p,o,r;for(p=0;p<k.length;p+=2){o=k[p];r=k[p+1];if(Math.abs(q.clientX-o)<25&&Math.abs(q.clientY-r)<25){q.stopPropagation();q.preventDefault()}}};document.addEventListener("click",h,true);a=function(o,p){this.element=o;this.handler=p;o.addEventListener("touchstart",this,false);o.addEventListener("click",this,false)};a.prototype.handleEvent=function(o){switch(o.type){case"touchstart":this.onTouchStart(o);break;case"touchmove":this.onTouchMove(o);break;case"touchend":this.onClick(o);break;case"click":this.onClick(o);break}};a.prototype.onTouchStart=function(o){o.stopPropagation();this.element.addEventListener("touchend",this,false);document.body.addEventListener("touchmove",this,false);this.startX=o.touches[0].clientX;this.startY=o.touches[0].clientY};a.prototype.onTouchMove=function(o){if(Math.abs(o.touches[0].clientX-this.startX)>10||Math.abs(o.touches[0].clientY-this.startY)>10){this.reset()}};a.prototype.onClick=function(o){o.stopPropagation();this.reset();this.handler(o);if(o.type==="touchend"){c(this.startX,this.startY)}};a.prototype.reset=function(){this.element.removeEventListener("touchend",this,false);document.body.removeEventListener("touchmove",this,false)};f=function(q,p){var o=d.indexOf(p);if(o<0){o=d.length;d.push(p)}n[o]=q};e=function(p,q,o){o=o||location.pathname+location.hash;f(p,o);history.replaceState(p,q,o)};g=function(q){var p=q?location.pathname+"#/"+q:location.pathname+location.hash,o=d.indexOf(p);return o<0?undefined:n[o]};j=function(p,o){if(p.indexOf(o)<0){p.push(o)}return p};m=function(){var p,o;b=document.body.getAttribute("data-default-target-id")||"";function q(r,t){var v,u,s;u=document.getElementById(r)||document.getElementById(b);if(u){for(s=0;s<t.length;s+=1){v=document.getElementById(t[s]);if(v){v.setAttribute("style","display:none")}}u.setAttribute("style","display:block")}}if((!location.hash)&&(b!=="")){location.hash="#/"+b}q(location.hash.substring(2),[b]);if(!(history instanceof Object&&history.replaceState instanceof Function)){return}this.touchHandler=function(v){var s,x,r,u,w,t;s=this.element.getAttribute("data-target-id");x=document.getElementById(s);if(x!==null){v.preventDefault();r=document.getElementById(location.hash.substr(2));u=r?r.getAttribute("id"):b;q(s,[u]);w=g();t=(w&&w.hasOwnProperty("hide"))?j(w.hide,s):[s];e({show:u,hide:t},"");location.hash="#/"+s;w=g();t=(w&&w.hasOwnProperty("hide"))?j(w.hide,u):[u];e({show:s,hide:t},"")}};p=document.getElementsByTagName("a");for(o=0;o<p.length;o+=1){if(p[o].getAttribute("data-target-id")!==null){i.push(new a(p[o],this.touchHandler))}}this.popHandler=function(t){var u,r,s;u=g();if(u){q(u.show,u.hide)}if(t.state){for(o=0;o<t.state.hide.length;o+=1){r=g(t.state.hide[o]);if(r){s=j(r.hide,t.state.show);f({show:t.state.hide[o],hide:s},location.pathname+"#/"+t.state.hide[o])}}q(t.state.show,t.state.hide)}};window.addEventListener("popstate",this.popHandler,false)};document.addEventListener("DOMContentLoaded",m,false)}());
4  demo/index.html
... ...
@@ -1,7 +1,7 @@
1 1
 <!DOCTYPE html>
2 2
 <title>Lightning Touch Demos</title>
3 3
 <meta name="viewport" content="width=device-width">
4  
-<script src="LightningTouch-1.0.1.min.js"></script>
  4
+<script src="LightningTouch-1.0.2.min.js"></script>
5 5
 
6 6
 <!-- 
7 7
     Function for onclick() handling so it can be compared to Lightning Touch.
@@ -53,4 +53,4 @@
53 53
             <a href="#" onclick="swap('onclick-main','less-awesome'); return false;">Tap to reset onclick listener.</a>
54 54
 
55 55
         </div>
56  
-    </section>
  56
+    </section>
9  tests/no_default_hash.html
... ...
@@ -0,0 +1,9 @@
  1
+<!DOCTYPE html>
  2
+<title>Lightning Touch Test</title>
  3
+<meta name="viewport" content="width=device-width">
  4
+<script src="../LightningTouch.js"></script>
  5
+
  6
+<body>
  7
+    <p>There should be no hash inserted in the URL on this page.</p>
  8
+</body>
  9
+        

0 notes on commit 7dcd038

Please sign in to comment.
Something went wrong with that request. Please try again.