Skip to content

Commit

Permalink
Slight fix to hashTags feature
Browse files Browse the repository at this point in the history
  • Loading branch information
IanLunn committed Jun 23, 2014
1 parent 73176bb commit d710f01
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 26 deletions.
12 changes: 7 additions & 5 deletions DOCUMENTATION.md
Expand Up @@ -690,13 +690,15 @@ Whether there should be a delay between a step animating out and the next animat

#### `reverseWhenNavigatingBackwards`

- Type: true/false
- Default: `false`
**Note**: not yet implemented.

~~- Type: true/false~~
~~- Default: `false`~~

Whether animations should be reversed when a user navigates backwards by clicking a previous button/swiping/pressing the left key.
~~Whether animations should be reversed when a user navigates backwards by clicking a previous button/swiping/pressing the left key.~~

- `true`: when navigating backwards, Sequence will animate the preceding step from its "animate-out" position to its "animate-in" position (creating a reversed animation).
- `false`: when navigating backwards, Sequence will animate the preceding step from its "start" position to its "animate-in" position (as it does when navigating forwards).
~~- `true`: when navigating backwards, Sequence will animate the preceding step from its "animate-out" position to its "animate-in" position (creating a reversed animation).~~
~~- `false`: when navigating backwards, Sequence will animate the preceding step from its "start" position to its "animate-in" position (as it does when navigating forwards).~~

#### `moveActiveStepToTop`

Expand Down
23 changes: 16 additions & 7 deletions scripts/sequence.js
Expand Up @@ -4,7 +4,7 @@
*
* @link https://github.com/IanLunn/Sequence
* @author IanLunn
* @version 2.0.0-alpha.2
* @version 2.0.0-alpha.3
* @license https://github.com/IanLunn/Sequence/blob/master/LICENSE
* @copyright IanLunn
*/
Expand Down Expand Up @@ -2337,6 +2337,9 @@ function defineSequence(imagesLoaded, Hammer) {
var correspondingStepId,
newHashTag;

// Does the browser support pushstate?
self.hasPushstate = !!(window.history && history.pushState);

// Get the current hashTag
newHashTag = location.hash.replace("#!", "");

Expand Down Expand Up @@ -2410,6 +2413,7 @@ function defineSequence(imagesLoaded, Hammer) {
*
* - hashTags are being used and this isn't the first run
* - hashTags are being used, this is the first run, and the first hash change is allowed in the options
* - the current step has a hashTag
*/
update: function() {

Expand All @@ -2424,13 +2428,18 @@ function defineSequence(imagesLoaded, Hammer) {
// Get the current hashTag
self.currentHashTag = self.stepHashTags[hashTagId];

// Add the hashTag to the URL
if (history.pushState) {
history.pushState(null, null, "#!" + self.currentHashTag);
}
else {
location.hash = "#!" + self.currentHashTag;
if(self.currentHashtag !== "") {

// Add the hashTag to the URL
if (self.hasPushstate === true) {
history.pushState(null, null, "#!" + self.currentHashTag);
}
else {
location.hash = "#!" + self.currentHashTag;
}
}


}
},

Expand Down
4 changes: 2 additions & 2 deletions scripts/sequence.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion scripts/sequence.min.map

Large diffs are not rendered by default.

21 changes: 15 additions & 6 deletions src/sequence.js
Expand Up @@ -2337,6 +2337,9 @@ function defineSequence(imagesLoaded, Hammer) {
var correspondingStepId,
newHashTag;

// Does the browser support pushstate?
self.hasPushstate = !!(window.history && history.pushState);

// Get the current hashTag
newHashTag = location.hash.replace("#!", "");

Expand Down Expand Up @@ -2410,6 +2413,7 @@ function defineSequence(imagesLoaded, Hammer) {
*
* - hashTags are being used and this isn't the first run
* - hashTags are being used, this is the first run, and the first hash change is allowed in the options
* - the current step has a hashTag
*/
update: function() {

Expand All @@ -2424,13 +2428,18 @@ function defineSequence(imagesLoaded, Hammer) {
// Get the current hashTag
self.currentHashTag = self.stepHashTags[hashTagId];

// Add the hashTag to the URL
if (history.pushState) {
history.pushState(null, null, "#!" + self.currentHashTag);
}
else {
location.hash = "#!" + self.currentHashTag;
if(self.currentHashtag !== "") {

// Add the hashTag to the URL
if (self.hasPushstate === true) {
history.pushState(null, null, "#!" + self.currentHashTag);
}
else {
location.hash = "#!" + self.currentHashTag;
}
}


}
},

Expand Down
6 changes: 3 additions & 3 deletions themes/test-theme/index.html
Expand Up @@ -24,13 +24,13 @@
<div id="sequence">
<div class="sequence-screen">
<ul class="sequence-canvas">
<li>
<li id="step1">
<div class="box box1">Box 1</div>
</li>
<li>
<li id="step2">
<div class="box box2">Box 2</div>
</li>
<li>
<li id="step3">
<div class="box box3">Box 3</div>
</li>
</ul>
Expand Down
4 changes: 3 additions & 1 deletion themes/test-theme/scripts/sequence-theme.test-theme.js
Expand Up @@ -24,7 +24,9 @@ var sequenceElement = document.getElementById("sequence");
var options = {
animateCanvas: false,
phaseThreshold: false,
reverseWhenNavigatingBackwards: true
reverseWhenNavigatingBackwards: true,
hashTags: true,
keyNavigation: true
}

var mySequence,
Expand Down
2 changes: 1 addition & 1 deletion themes/test-theme/scripts/sequence-theme.test-theme.min.js
Expand Up @@ -15,4 +15,4 @@
*
* Sequence.js and its dependencies are copyright (c) Ian Lunn 2014 unless otherwise stated.
*/
function init(){void 0===mySequence&&(mySequence=sequence(sequenceElement,options),mySequence.paused=function(){pauseButton.innerHTML="Unpause"},mySequence.unpaused=function(){pauseButton.innerHTML="Pause"})}var sequenceElement=document.getElementById("sequence"),options={animateCanvas:!1,phaseThreshold:!1,reverseWhenNavigatingBackwards:!0},mySequence,pauseButton=document.getElementById("pause"),initButton=document.getElementById("init"),destroyButton=document.getElementById("destroy");init(),initButton.addEventListener("click",function(){init()}),destroyButton.addEventListener("click",function(){void 0!==mySequence&&(mySequence.destroy(),mySequence=void 0)});
function init(){void 0===mySequence&&(mySequence=sequence(sequenceElement,options),mySequence.paused=function(){pauseButton.innerHTML="Unpause"},mySequence.unpaused=function(){pauseButton.innerHTML="Pause"})}var sequenceElement=document.getElementById("sequence"),options={animateCanvas:!1,phaseThreshold:!1,reverseWhenNavigatingBackwards:!0,hashTags:!0,keyNavigation:!0},mySequence,pauseButton=document.getElementById("pause"),initButton=document.getElementById("init"),destroyButton=document.getElementById("destroy");init(),initButton.addEventListener("click",function(){init()}),destroyButton.addEventListener("click",function(){void 0!==mySequence&&(mySequence.destroy(),mySequence=void 0)});

0 comments on commit d710f01

Please sign in to comment.