FIX: Don't scroll to top if there's an anchor present.
This commit is contained in:
parent
4c867c5796
commit
62ef81d895
|
@ -6,8 +6,15 @@
|
||||||
@namespace Discourse
|
@namespace Discourse
|
||||||
@module Discourse
|
@module Discourse
|
||||||
**/
|
**/
|
||||||
|
|
||||||
Discourse.StaticController = Em.ObjectController.extend({
|
Discourse.StaticController = Em.ObjectController.extend({
|
||||||
showLoginButton: Em.computed.equal('path', 'login')
|
showLoginButton: Em.computed.equal('path', 'login'),
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
markFaqRead: function() {
|
||||||
|
Discourse.ajax("/users/read-faq", { method: "POST" });
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Discourse.StaticController.reopenClass({
|
Discourse.StaticController.reopenClass({
|
||||||
|
|
|
@ -6,11 +6,18 @@
|
||||||
@namespace Discourse
|
@namespace Discourse
|
||||||
@module Discourse
|
@module Discourse
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
var jumpScheduled = false;
|
||||||
|
|
||||||
Discourse.URL = Em.Object.createWithMixins({
|
Discourse.URL = Em.Object.createWithMixins({
|
||||||
|
|
||||||
// Used for matching a topic
|
// Used for matching a topic
|
||||||
TOPIC_REGEXP: /\/t\/([^\/]+)\/(\d+)\/?(\d+)?/,
|
TOPIC_REGEXP: /\/t\/([^\/]+)\/(\d+)\/?(\d+)?/,
|
||||||
|
|
||||||
|
isJumpScheduled: function() {
|
||||||
|
return jumpScheduled;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Jumps to a particular post in the stream
|
Jumps to a particular post in the stream
|
||||||
**/
|
**/
|
||||||
|
@ -89,7 +96,7 @@ Discourse.URL = Em.Object.createWithMixins({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scroll to the same page, differnt anchor
|
// Scroll to the same page, different anchor
|
||||||
if (path.indexOf('#') === 0) {
|
if (path.indexOf('#') === 0) {
|
||||||
var $elem = $(path);
|
var $elem = $(path);
|
||||||
if ($elem.length > 0) {
|
if ($elem.length > 0) {
|
||||||
|
@ -301,10 +308,13 @@ Discourse.URL = Em.Object.createWithMixins({
|
||||||
var transition = router.handleURL(path);
|
var transition = router.handleURL(path);
|
||||||
transition.promise.then(function() {
|
transition.promise.then(function() {
|
||||||
if (elementId) {
|
if (elementId) {
|
||||||
|
|
||||||
|
jumpScheduled = true;
|
||||||
Em.run.next('afterRender', function() {
|
Em.run.next('afterRender', function() {
|
||||||
var offset = $('#' + elementId).offset();
|
var offset = $('#' + elementId).offset();
|
||||||
if (offset && offset.top) {
|
if (offset && offset.top) {
|
||||||
$('html, body').scrollTop(offset.top - $('header').height() - 10);
|
$('html, body').scrollTop(offset.top - $('header').height() - 10);
|
||||||
|
jumpScheduled = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,8 @@
|
||||||
/**
|
|
||||||
This mixin will cause a view to scroll the viewport to the top once it has been inserted
|
|
||||||
|
|
||||||
@class Discourse.ScrollTop
|
|
||||||
@extends Ember.Mixin
|
|
||||||
@namespace Discourse
|
|
||||||
@module Discourse
|
|
||||||
**/
|
|
||||||
Discourse.ScrollTop = Em.Mixin.create({
|
Discourse.ScrollTop = Em.Mixin.create({
|
||||||
_scrollTop: function() {
|
_scrollTop: function() {
|
||||||
|
if (Discourse.URL.isJumpScheduled()) { return; }
|
||||||
Em.run.schedule('afterRender', function() {
|
Em.run.schedule('afterRender', function() {
|
||||||
$(document).scrollTop(0);
|
$(document).scrollTop(0);
|
||||||
});
|
});
|
||||||
}.on('didInsertElement')
|
}.on('didInsertElement')
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,21 @@
|
||||||
|
var readFaq = false;
|
||||||
|
|
||||||
export default Discourse.View.extend({
|
export default Ember.View.extend(Discourse.ScrollTop, {
|
||||||
didInsertElement: function() {
|
_checkRead: function() {
|
||||||
var path = this.get('controller.model.path');
|
var path = this.get('controller.model.path');
|
||||||
if(path === "faq" || path === "guidelines"){
|
if(path === "faq" || path === "guidelines"){
|
||||||
var $window = $(window);
|
var $window = $(window),
|
||||||
|
controller = this.get('controller');
|
||||||
$window.on('scroll.faq', function(){
|
$window.on('scroll.faq', function(){
|
||||||
if($window.scrollTop() + $window.height() > $(document).height() - 10) {
|
if(!readFaq && ($window.scrollTop() + $window.height() > $(document).height() - 10)) {
|
||||||
if(!this._notifiedBottom){
|
readFaq = true;
|
||||||
this._notifiedBottom = true;
|
controller.send('markFaqRead');
|
||||||
Discourse.ajax("/users/read-faq", {
|
|
||||||
method: "POST"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
}.on('didInsertElement'),
|
||||||
willDestroyElement: function(){
|
|
||||||
|
_stopChecking: function(){
|
||||||
$(window).off('scroll.faq');
|
$(window).off('scroll.faq');
|
||||||
}
|
}.on('willDestroyElement')
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue