Skip to content

Commit 4805207

Browse files
AndVikVinavasuro
authored andcommitted
fixed scroll bugs reported in issues xbsoftware#107 xbsoftware#96 xbsoftware#82
1 parent b816e52 commit 4805207

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

Gruntfile.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
module.exports = function(grunt){
22
grunt.initConfig({
3-
pkg: grunt.file.readJSON('bower.json'),
4-
concat:{
5-
options: {
6-
separator: ';'
7-
},
8-
dist:{
9-
src:['src/*.js', 'lib/kineticjs/kinetic.min.js', 'lib/jquery.scrollTo/jquery.scrollTo.min.js'],
10-
dest: '<%= pkg.name %>.js'
11-
}
12-
},
3+
pkg: grunt.file.readJSON('package.json'),
134
uglify: {
145
main: {
156
files: {
16-
'<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>']
7+
'<%= pkg.name %>.min.js': './src/<%= pkg.name %>.js'
178
}
189
}
1910
},
@@ -39,9 +30,8 @@ module.exports = function(grunt){
3930

4031
grunt.loadNpmTasks('grunt-contrib-uglify');
4132
grunt.loadNpmTasks('grunt-contrib-jshint');
42-
grunt.loadNpmTasks('grunt-contrib-concat');
4333
grunt.loadNpmTasks('grunt-contrib-cssmin');
4434

45-
grunt.registerTask("default", ["concat", "uglify", "cssmin"])
35+
grunt.registerTask("default", ["uglify", "cssmin"])
4636

4737
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
},
2424
"homepage": "https://github.com/xbsoftware/enjoyhint",
2525
"devDependencies": {
26-
"grunt-contrib-concat": "^0.5.1",
26+
"grunt": "^0.4.5",
2727
"grunt-contrib-cssmin": "^0.11.0",
2828
"grunt-contrib-jshint": "^0.11.2",
2929
"grunt-contrib-uglify": "^0.9.1"
3030
},
3131
"dependencies": {
32-
"grunt": "^0.4.5",
32+
"jquery": "~2.1.3",
3333
"jquery.scrollto": "^2.1.2",
3434
"kinetic": "^5.2.0"
3535
}

src/enjoyhint.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var EnjoyHint = function(configs) {
3030
var data = [];
3131
var current_step = 0;
3232

33-
$body = $(body);
33+
var $body = $(body);
3434

3535
/********************* PRIVATE METHODS ***************************************/
3636

@@ -76,6 +76,14 @@ var EnjoyHint = function(configs) {
7676
$skipBtn.text(BTN_SKIP_TEXT);
7777
};
7878

79+
function hideCurrentHint(){
80+
$body.enjoyhint('render_circle', []);
81+
$('#enjoyhint_label').remove();
82+
$('#enjoyhint_arrpw_line').remove();
83+
$body.enjoyhint('hide_next');
84+
$body.enjoyhint('hide_skip');
85+
};
86+
7987
var stepAction = function() {
8088
if (!(data && data[current_step])) {
8189
$body.enjoyhint("hide");
@@ -127,11 +135,10 @@ var EnjoyHint = function(configs) {
127135
that.clear();
128136
}, 250);
129137

130-
//$(document.body).scrollTop(step_data.selector, step_data.scrollAnimationSpeed || 250, {offset: -100});
131-
var elemToScroll = document.querySelector(step_data.selector);
132-
if (elemToScroll) {
133-
let { x, y } = elemToScroll.getClientRects();
134-
window.scrollTo(x, y);
138+
var isHintInViewport = $(step_data.selector).get(0).getBoundingClientRect();
139+
if(isHintInViewport.top < 0 || isHintInViewport.bottom > (window.innerHeight || document.documentElement.clientHeight)){
140+
hideCurrentHint();
141+
$(document.body).scrollTo(step_data.selector, step_data.scrollAnimationSpeed || 250, {offset: -200});
135142
}
136143

137144
setTimeout(function() {

0 commit comments

Comments
 (0)