1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-27 09:09:44 +02:00

scroll top tool

This commit is contained in:
Harvey Kandola 2016-10-05 17:12:47 -07:00
parent 3256292d41
commit 459469c1d4
5 changed files with 60 additions and 20 deletions

View file

@ -45,27 +45,29 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
didInsertElement() { didInsertElement() {
this.eventBus.subscribe('documentPageAdded', this, 'onDocumentPageAdded'); this.eventBus.subscribe('documentPageAdded', this, 'onDocumentPageAdded');
},
// let s = $(".document-structure");
// let pos = s.position();
//
// $(window).scroll(_.throttle(function() {
// let windowpos = $(window).scrollTop();
// if (windowpos - 200 >= pos.top) {
// s.addClass("stuck-toc");
// s.css('width', s.parent().width());
// } else {
// s.removeClass("stuck-toc");
// s.css('width', 'auto');
// }
// }, 50));
},
willDestroyElement() { willDestroyElement() {
this.eventBus.unsubscribe('documentPageAdded'); this.eventBus.unsubscribe('documentPageAdded');
this.destroyTooltips(); this.destroyTooltips();
}, },
// positionToc() {
// let s = $(".document-structure");
// let pos = s.position();
//
// $(window).scroll(_.throttle(function() {
// let windowpos = $(window).scrollTop();
// if (windowpos - 200 >= pos.top) {
// s.addClass("stuck-toc");
// s.css('width', s.parent().width());
// } else {
// s.removeClass("stuck-toc");
// s.css('width', 'auto');
// }
// }, 50));
// },
onDocumentPageAdded(pageId) { onDocumentPageAdded(pageId) {
this.send('onEntryClick', pageId); this.send('onEntryClick', pageId);
}, },

View file

@ -21,6 +21,7 @@ export default Ember.Component.extend(TooltipMixin, NotifierMixin, {
showViews: false, showViews: false,
showContributions: false, showContributions: false,
showSections: false, showSections: false,
showScrollTool: false,
didRender() { didRender() {
if (this.session.authenticated) { if (this.session.authenticated) {
@ -30,9 +31,20 @@ export default Ember.Component.extend(TooltipMixin, NotifierMixin, {
}, },
didInsertElement() { didInsertElement() {
let _this = this;
this.eventBus.subscribe('resized', this, 'positionTool'); this.eventBus.subscribe('resized', this, 'positionTool');
this.eventBus.subscribe('scrolled', this, 'positionTool'); this.eventBus.subscribe('scrolled', this, 'positionTool');
// new Waypoint({
// element: document.getElementById('zone-header'),
// handler: function(direction) {
// console.log(direction);
// if (direction === 'up') {
// $(".scroll-tool").addClass('hide');
// console.log("hiding");
// }
// },
// offset: 50
// });
}, },
willDestroyElement() { willDestroyElement() {
@ -40,14 +52,15 @@ export default Ember.Component.extend(TooltipMixin, NotifierMixin, {
}, },
positionTool() { positionTool() {
let s = $(".section-tool"); let s = $(".scroll-tool");
let pos = s.position();
let windowpos = $(window).scrollTop(); let windowpos = $(window).scrollTop();
if (windowpos - 200 >= pos.top) { if (windowpos >= 300) {
this.set('showScrollTool', true);
s.addClass("stuck-tool"); s.addClass("stuck-tool");
s.css('left', parseInt($(".zone-sidebar").css('width')) - 18 + 'px'); s.css('left', parseInt($(".zone-sidebar").css('width')) - 18 + 'px');
} else { } else {
this.set('showScrollTool', false);
s.removeClass("stuck-tool"); s.removeClass("stuck-tool");
} }
}, },
@ -101,6 +114,13 @@ export default Ember.Component.extend(TooltipMixin, NotifierMixin, {
onAddSection(section) { onAddSection(section) {
this.attrs.onAddSection(section); this.attrs.onAddSection(section);
},
scrollTop() {
this.set('showScrollTool', false);
$("html,body").animate({
scrollTop: 0
}, 500, "linear");
} }
} }
}); });

View file

@ -15,7 +15,7 @@ export default Ember.Service.extend(Ember.Evented, {
init() { init() {
let _this = this; let _this = this;
window.addEventListener("scroll", _.debounce(function() { window.addEventListener("scroll", _.throttle(function() {
_this.publish('scrolled', null); _this.publish('scrolled', null);
}, 100)); }, 100));

View file

@ -63,6 +63,18 @@
z-index: 999; z-index: 999;
} }
.scroll-tool {
position: absolute;
top: 150px;
right: -18px;
z-index: 888;
-webkit-animation: fadein 1s; /* Safari, Chrome and Opera > 12.1 */
-moz-animation: fadein 1s; /* Firefox < 16 */
-ms-animation: fadein 1s; /* Internet Explorer */
-o-animation: fadein 1s; /* Opera < 12.1 */
animation: fadein 1s;
}
.stuck-tool { .stuck-tool {
position: fixed !important; position: fixed !important;
top: 150px !important; top: 150px !important;

View file

@ -34,6 +34,12 @@
</div> </div>
{{/if}} {{/if}}
{{#if showScrollTool}}
<div {{action 'scrollTop'}} id="scroll-tool" class="round-button round-button-mono button-white scroll-tool" data-tooltip="Back to top" data-tooltip-position="top center">
<i class="material-icons color-gray">vertical_align_top</i>
</div>
{{/if}}
{{#if showToc}} {{#if showToc}}
{{document/document-sidebar-toc document=model folder=folder pages=pages page=page isEditor=isEditor {{document/document-sidebar-toc document=model folder=folder pages=pages page=page isEditor=isEditor
changePageSequence=(action 'onPageSequenceChange') changePageLevel=(action 'onPageLevelChange') changePageSequence=(action 'onPageSequenceChange') changePageLevel=(action 'onPageLevelChange')