Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
change to utils.removeClasses, changed callback naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordon Koo committed Aug 1, 2012
1 parent 8ba4005 commit 1ec5eea
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 133 deletions.
211 changes: 106 additions & 105 deletions js/exampletour.js
@@ -1,107 +1,108 @@
var tour = {
id: 'hello-hopscotch',
steps: [
{
title: 'Welcome to the Hopscotch Demo Page!',
content: 'Hey there! Welcome to the Hopscotch Demo Page! Please excuse our dust; this is still a work in progress. To proceed, click the next button below. (And as you do, watch the title of the page turn red!!!)',
targetId: 'subheading',
orientation: 'bottom',
arrowOffset: 30,
nextCallback: function() {
document.getElementById('pageTitle').style.color = '#f00';
}
},
{
title: 'Debug controls',
content: 'Here are the debug controls. They\'re pretty self-explanatory: start a tour, end a tour, clear the tour cookie (if you want the tour to forget what step you are on).',
targetId: 'debug',
orientation: 'left',
width: 320,
height: 480,
prevCallback: function() {
document.getElementById('pageTitle').style.color = '#000';
}
},
{
title: 'Mission district',
content: 'Some sort of sound heat map in the mission? Did you notice that this bubble isn\'t completely aligned with this image? That\'s because I\'m using xOffset and yOffset options, which are available if you need to make slight positioning adjustments! Hopscotch has never been more fun!',
targetId: 'mission',
orientation: 'top',
xOffset: 100,
arrowOffset: 100
},
{
title: 'Multi-page test',
content: 'Are you ready? We\'re going to try hopping to another page and then back!!! Where we\'re going, we won\'t need roads... (Please click this link.)',
targetId: 'secpagelink',
orientation: 'bottom',
showNextButton: false,
multiPage: true
},
{
title: 'Polar bears',
content: 'We made it!! Polar bears are very interesting creatures.',
targetId: 'polarbears',
orientation: 'right',
showPrevButton: false
},
{
title: 'Returning to the first page',
content: 'Time to go back home... Please click this link to return to the first page.',
targetId: 'firstpagelink',
orientation: 'bottom',
showNextButton: false,
showPrevButton: false,
multiPage: true // this indicates that next step will be on a different page
},
{
title: 'Cool wave',
content: 'This is a colorful wave. Here is the the <a href="http://imgur.com/s632o" target="_new">page</a> where I found it.',
targetId: 'wave',
orientation: 'bottom',
width: 500,
xOffset: -50,
arrowOffset: 400,
showPrevButton: false
},
{
title: 'Python decorator',
content: 'Whoa, did you notice that the page just scrolled? If you didn\'t, you aren\'t very observant. (Or you have a very tall monitor)',
targetId: 'python',
orientation: 'top',
xOffset: 200
}
],
animate: false,
//smoothScroll: false,
//showCloseButton: false,
showPrevButton: true,
showNextButton: true,
arrowWidth: 20,
scrollDuration: 500,
allNextCallback: function(step, idx) {
var newLi,
list = document.getElementById('my-list');
if (list) {
newLi = document.createElement('li');
newLi.innerHTML = 'going from step ' + (idx + 1) + ' to step ' + (idx+2) + '. (can use this callback for tracking)';
list.appendChild(newLi);
}
},
/* to be implemented:
doneCallback: function() {
},
*/
i18n: {
nextBtn: 'Forward',
prevBtn: 'Backward',
stepNums: [
'&#x4e00;',
'&#x4e8c;',
'&#x4e09;',
'&#x56db;',
'&#x4e94;',
'&#x516d;'
]
id: 'hello-hopscotch',
steps: [
{
title: 'Welcome to the Hopscotch Demo Page!',
content: 'Hey there! Welcome to the Hopscotch Demo Page! Please excuse our dust; this is still a work in progress. To proceed, click the next button below. (And as you do, watch the title of the page turn red!!!)',
targetId: 'subheading',
orientation: 'bottom',
arrowOffset: 30,
onNext: function() {
document.getElementById('pageTitle').style.color = '#f00';
}
};
},
{
title: 'Debug controls',
content: 'Here are the debug controls. They\'re pretty self-explanatory: start a tour, end a tour, clear the tour cookie (if you want the tour to forget what step you are on).',
targetId: 'debug',
orientation: 'left',
width: 320,
height: 480,
onPrev: function() {
document.getElementById('pageTitle').style.color = '#000';
}
},
{
title: 'Mission district',
content: 'Some sort of sound heat map in the mission? Did you notice that this bubble isn\'t completely aligned with this image? That\'s because I\'m using xOffset and yOffset options, which are available if you need to make slight positioning adjustments! Hopscotch has never been more fun!',
targetId: 'mission',
orientation: 'top',
xOffset: 100,
arrowOffset: 100
},
{
title: 'Multi-page test',
content: 'Are you ready? We\'re going to try hopping to another page and then back!!! Where we\'re going, we won\'t need roads... (Please click this link.)',
targetId: 'secpagelink',
orientation: 'bottom',
showNextButton: false,
multiPage: true
},
{
title: 'Polar bears',
content: 'We made it!! Polar bears are very interesting creatures.',
targetId: 'polarbears',
orientation: 'right',
showPrevButton: false
},
{
title: 'Returning to the first page',
content: 'Time to go back home... Please click this link to return to the first page.',
targetId: 'firstpagelink',
orientation: 'bottom',
showNextButton: false,
showPrevButton: false,
multiPage: true // this indicates that next step will be on a different page
},
{
title: 'Cool wave',
content: 'This is a colorful wave. Here is the the <a href="http://imgur.com/s632o" target="_new">page</a> where I found it.',
targetId: 'wave',
orientation: 'bottom',
width: 500,
xOffset: -50,
arrowOffset: 400,
showPrevButton: false
},
{
title: 'Python decorator',
content: 'Whoa, did you notice that the page just scrolled? If you didn\'t, you aren\'t very observant. (Or you have a very tall monitor)',
targetId: 'python',
orientation: 'top',
xOffset: 200
}
],
animate: false,
//smoothScroll: false,
//showCloseButton: false,
showPrevButton: true,
showNextButton: true,
arrowWidth: 20,
scrollDuration: 500,
cookieName: 'li_hs',
onNext: function(step, idx) {
var newLi,
list = document.getElementById('my-list');
if (list) {
newLi = document.createElement('li');
newLi.innerHTML = 'going from step ' + (idx + 1) + ' to step ' + (idx+2) + '. (can use this callback for tracking)';
list.appendChild(newLi);
}
},
/* to be implemented:
onDone: function() {
},
*/
i18n: {
nextBtn: 'Forward',
prevBtn: 'Backward',
stepNums: [
'&#x4e00;',
'&#x4e8c;',
'&#x4e09;',
'&#x56db;',
'&#x4e94;',
'&#x516d;'
]
}
};
79 changes: 51 additions & 28 deletions js/hopscotch.js
Expand Up @@ -57,6 +57,8 @@
* addClass
* ========
* Adds a class to a DOM element.
* Note: does not support adding multiple classes at once yet, unless
* you're using jQuery.
*/
addClass: function(domEl, classToAdd) {
var domClasses,
Expand All @@ -81,24 +83,39 @@
}
},

/**
* removeClass
* ===========
* Remove a class from a DOM element.
* Note: this one DOES support removing multiple classes.
*/
removeClass: function(domEl, classToRemove) {
var domClasses, i, len;
var domClasses,
classesToRemove,
currClass,
i,
j,
toRemoveLen,
domClassLen;

if (hasJquery) {
$(domEl).removeClass(classToRemove);
}
else {
classesToRemove = classToRemove.split(' ');
domClasses = domEl.className.split(' ');
for (i = 0, len = domClasses.length; i < len; ++i) {
if (domClasses[i] === classToRemove) {
break;
for (i = 0, toRemoveLen = classesToRemove.length; i < toRemoveLen; ++i) {
currClass = classesToRemove[i];
for (j = 0, domClassLen = domClasses.length; j < domClassLen; ++j) {
if (domClasses[j] === currClass) {
break;
}
}
if (j < len) {
domClasses.splice(j, 1); // remove class from list
}
}

if (i < len) {
domClasses.splice(i, 1); // remove class from list
domEl.className = domClasses.join(' ');
}
domEl.className = domClasses.join(' ');
}
},

Expand Down Expand Up @@ -280,6 +297,8 @@
bubbleWidth = utils.getPixelValue(step.width) || opt.bubbleWidth;
bubblePadding = utils.valOrDefault(step.padding, opt.bubblePadding);

utils.removeClass(el, 'bounce-down bounce-up bounce-left bounce-right');

// SET POSITION
boundingRect = targetEl.getBoundingClientRect();
if (step.orientation === 'top') {
Expand Down Expand Up @@ -505,8 +524,8 @@
}

// Set or clear new nav callbacks
prevBtnCallback = step.prevCallback;
nextBtnCallback = step.nextCallback;
prevBtnCallback = step.onPrev;
nextBtnCallback = step.onNext;

return this;
};
Expand Down Expand Up @@ -744,17 +763,6 @@
if (initOptions) {
this.configure(initOptions);
}

tourState = utils.getState('hopscotch.tour.next');
if (tourState) {
tourPair = tourState.split(':');
cookieTourId = tourPair[0]; // selecting tour is not supported by this framework.
cookieTourStep = parseInt(tourPair[1], 10);
if (tourPair.length > 2 && tourPair[2] === 'mp') {
// multipage... increment tour step by 1
++cookieTourStep;
}
}
};

/**
Expand All @@ -779,6 +787,18 @@
}
this.configure(tmpOpt);

// Get existing tour state, if it exists.
tourState = utils.getState(opt.cookieName);
if (tourState) {
tourPair = tourState.split(':');
cookieTourId = tourPair[0]; // selecting tour is not supported by this framework.
cookieTourStep = parseInt(tourPair[1], 10);
if (tourPair.length > 2 && tourPair[2] === 'mp') {
// multipage... increment tour step by 1
++cookieTourStep;
}
}

// Initialize whether to show or hide nav buttons
bubble = getBubble();
bubble.showPrevButton(opt.showPrevButton, true);
Expand Down Expand Up @@ -847,7 +867,7 @@
if (step.multiPage) {
cookieVal += ':mp';
}
utils.setState('hopscotch.tour.next', cookieVal, 7);
utils.setState(opt.cookieName, cookieVal, 1);
};

this.prevStep = function() {
Expand All @@ -857,8 +877,8 @@
};

this.nextStep = function() {
if (opt.allNextCallback) {
opt.allNextCallback(getCurrStep(), currStepNum);
if (opt.onNext) {
opt.onNext(getCurrStep(), currStepNum);
}
if (currStepNum < currTour.steps.length-1) {
this.showStep(++currStepNum);
Expand All @@ -876,7 +896,7 @@
bubble.hide();
currStepNum = cookieTourStep = 0;
if (clearCookie) {
utils.clearState('hopscotch.tour.next');
utils.clearState(opt.cookieName);
}
this.isActive = false;
};
Expand Down Expand Up @@ -904,6 +924,8 @@
* and the targetEl) Need to provide the option
* to set this here in case developer wants to
* use own CSS. Defaults to 20.
* cookieName: String - Name for the cookie key. Defaults to
* 'hopscotch.tour.state'.
* allNextCallback: Function - A callback to be invoked after every click on
* a "Next" button.
*
Expand Down Expand Up @@ -931,7 +953,8 @@
opt.bubbleWidth = utils.valOrDefault(opt.bubbleWidth, 280);
opt.bubblePadding = utils.valOrDefault(opt.bubblePadding, 10);
opt.arrowWidth = utils.valOrDefault(opt.arrowWidth, 20);
opt.allNextCallback = utils.valOrDefault(opt.allNextCallback, null);
opt.onNext = utils.valOrDefault(opt.onNext, null);
opt.cookieName = utils.valOrDefault(opt.cookieName, 'hopscotch.tour.state');

if (options) {
utils.extend(HopscotchI18N, options.i18n);
Expand All @@ -955,7 +978,7 @@
// =====
// REMOVE THIS LATER!!!
this.clearCookie = function() {
utils.clearState('hopscotch.tour.next');
utils.clearState(opt.cookieName);
};
};

Expand Down
1 change: 1 addition & 0 deletions secondpage.html
Expand Up @@ -4,6 +4,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Second Test Page</title>
<link href="css/hopscotch.less" rel="stylesheet/less"></link>
<link href="css/bounce.less" rel="stylesheet/less"></link>
<script src="js/less-1.3.0.min.js"></script>
</head>
<body>
Expand Down

0 comments on commit 1ec5eea

Please sign in to comment.