$this.updatePageByCursorPosition($this.pageToSlider(e.pageX), true, true);
});
+ $("#slidercursor").on('mousedown', function (e) {
+ $this.dragCursor(e, false, false);
+ });
+
interact(document.getElementById("slidercursor")).draggable({
inertia: false,
onstart: function (event) {
return $this.dragCursor(event, true);
}
});
+
+
+ if (!Modernizr.ftouch) {
+ $("#slider").on('mouseenter mousemove', function (e) {
+ return $this.hover(e.pageX);
+ });
+
+ $("#slider").on('mouseleave', function () {
+ $("#slider").removeClass('hover');
+ });
+ }
+ },
+
+ hover: function (pageX) {
+ $("#slider").addClass('hover');
+ var page = this.getPageByX(this.pageToSlider(pageX));
+ this.updateThumb(page);
},
- dragCursor: function (e, end) {
+ dragCursor: function (e, end, move) {
+ if (move == undefined) {
+ move = true;
+ }
if (!end) {
$("#slider").addClass("drag");
} else {
$("#slider").removeClass("drag");
}
- this.updatePageByCursorPosition(this.pageToSlider(e.pageX), end, true);
+ if (move) {
+ this.updatePageByCursorPosition(this.pageToSlider(e.pageX), end, true);
+ }
},
pageToSlider: function (pageX) {
if (gotoPage == undefined) {
gotoPage = true;
}
+ var page = this.getPageByX(pos)
+
+ if (gotoPage) {
+ this.fluidbook.setCurrentPage(page);
+ }
+ if (updateCursor) {
+ this.updateCursorPosition(page);
+ }
+ return false;
+ },
+
+ getPageByX: function (pos) {
var page;
if (this.fluidbook.resize.orientation == 'portrait') {
page = Math.floor(pos / (this.sliderWidth / this.snapsCount)) + 1;
pageMin = 0;
}
- page = Math.min(this.fluidbook.datas.pages, Math.max(pageMin, page));
-
- if (gotoPage) {
- this.fluidbook.setCurrentPage(page);
- }
- if (updateCursor) {
- this.updateCursorPosition(page);
- }
- return false;
+ return Math.min(this.fluidbook.datas.pages, Math.max(pageMin, page));
},
resize: function (ww, hh, single) {
if (page == undefined) {
page = this.fluidbook.currentPage;
}
+
+ $("#slidercursor").css('left', this.getCursorXByPage(page));
+
+ if ($("#sliderthumb").is(':visible') && !$("#slider").hasClass('hover')) {
+ this.updateThumb(page);
+ }
+ },
+
+ getCursorXByPage: function (page) {
var left;
if (this.fluidbook.resize.orientation == 'portrait') {
left = this.snapsWidth * (page - 1);
var current = Math.floor(page / 2);
left = this.snapsWidth * current;
}
- var x = Math.max(0, Math.min(left, this.sliderWidth - this.cursorWidth));
- $("#slidercursor").css('left', x);
-
- if ($("#sliderthumb").is(':visible')) {
- this.updateThumb(page);
- $("#sliderthumb").css('left', x + (this.cursorWidth / 2) - ($("#sliderthumb").outerWidth() / 2));
- }
+ return Math.max(0, Math.min(left, this.sliderWidth - this.cursorWidth));
},
updateThumb: function (page) {
this.setThumb($("#sliderthumb .doubleThumb").find('.thumb.left'), left, !single);
this.setThumb($("#sliderthumb .doubleThumb").find('.thumb.right'), right, !single);
this.fluidbook.bookmarks.updateBookmarks();
+ $("#sliderthumb").css('left', this.getCursorXByPage(page) + (this.cursorWidth / 2) - ($("#sliderthumb").outerWidth() / 2));
},
setThumb: function (thumb, page, shade) {