mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 13:31:18 +08:00
Clicking the #site-logo will refresh the latest list.
This commit is contained in:
@ -13,18 +13,6 @@ Discourse.URL = Em.Object.createWithMixins({
|
|||||||
// Used for matching a /more URL
|
// Used for matching a /more URL
|
||||||
MORE_REGEXP: /\/more$/,
|
MORE_REGEXP: /\/more$/,
|
||||||
|
|
||||||
/**
|
|
||||||
@private
|
|
||||||
|
|
||||||
Get a handle on the application's router. Note that currently it uses `__container__` which is not
|
|
||||||
advised but there is no other way to access the router.
|
|
||||||
|
|
||||||
@method router
|
|
||||||
**/
|
|
||||||
router: function() {
|
|
||||||
return Discourse.__container__.lookup('router:main');
|
|
||||||
}.property(),
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Browser aware replaceState. Will only be invoked if the browser supports it.
|
Browser aware replaceState. Will only be invoked if the browser supports it.
|
||||||
|
|
||||||
@ -70,11 +58,65 @@ Discourse.URL = Em.Object.createWithMixins({
|
|||||||
path = path.replace(rootURL, '');
|
path = path.replace(rootURL, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// TODO: Extract into rules we can inject into the URL handler
|
||||||
|
if (this.navigatedToHome(oldPath, path)) { return; }
|
||||||
|
if (this.navigatedToListMore(oldPath, path)) { return; }
|
||||||
|
if (this.navigatedToHome(oldPath, path)) { return; }
|
||||||
|
|
||||||
|
// Be wary of looking up the router. In this case, we have links in our
|
||||||
|
// HTML, say form compiled markdown posts, that need to be routed.
|
||||||
|
var router = this.get('router');
|
||||||
|
router.router.updateURL(path);
|
||||||
|
return router.handleURL(path);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Replaces the query parameters in the URL. Use no parameters to clear them.
|
||||||
|
|
||||||
|
@method replaceQueryParams
|
||||||
|
**/
|
||||||
|
queryParams: Em.computed.alias('router.location.queryParams'),
|
||||||
|
|
||||||
|
/**
|
||||||
|
Redirect to a URL.
|
||||||
|
This has been extracted so it can be tested.
|
||||||
|
|
||||||
|
@method redirectTo
|
||||||
|
**/
|
||||||
|
redirectTo: function(url) {
|
||||||
|
window.location = Discourse.getURL(url);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
@private
|
||||||
|
|
||||||
|
If we're viewing more topics, scroll to where we were previously.
|
||||||
|
|
||||||
|
@method navigatedToListMore
|
||||||
|
@param {String} oldPath the previous path we were on
|
||||||
|
@param {String} path the path we're navigating to
|
||||||
|
**/
|
||||||
|
navigatedToListMore: function(oldPath, path) {
|
||||||
|
// If we transition from a /more path, scroll to the top
|
||||||
|
if (this.MORE_REGEXP.exec(oldPath) && (oldPath.indexOf(path) === 0)) {
|
||||||
|
window.scrollTo(0, 0);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
@private
|
||||||
|
|
||||||
If the URL is in the topic form, /t/something/:topic_id/:post_number
|
If the URL is in the topic form, /t/something/:topic_id/:post_number
|
||||||
then we want to apply some special logic. If the post_number changes within the
|
then we want to apply some special logic. If the post_number changes within the
|
||||||
same topic, use replaceState and instruct our controller to load more posts.
|
same topic, use replaceState and instruct our controller to load more posts.
|
||||||
*/
|
|
||||||
|
@method navigatedToPost
|
||||||
|
@param {String} oldPath the previous path we were on
|
||||||
|
@param {String} path the path we're navigating to
|
||||||
|
**/
|
||||||
|
navigatedToPost: function(oldPath, path) {
|
||||||
|
|
||||||
var newMatches = this.TOPIC_REGEXP.exec(path),
|
var newMatches = this.TOPIC_REGEXP.exec(path),
|
||||||
newTopicId = newMatches ? newMatches[2] : null;
|
newTopicId = newMatches ? newMatches[2] : null;
|
||||||
|
|
||||||
@ -99,28 +141,33 @@ Discourse.URL = Em.Object.createWithMixins({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Abort routing, we have replaced our state.
|
// Abort routing, we have replaced our state.
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we transition from a /more path, scroll to the top
|
return false;
|
||||||
if (this.MORE_REGEXP.exec(oldPath) && (oldPath.indexOf(path) === 0)) {
|
|
||||||
window.scrollTo(0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Be wary of looking up the router. In this case, we have links in our
|
|
||||||
// HTML, say form compiled markdown posts, that need to be routed.
|
|
||||||
var router = this.get('router');
|
|
||||||
router.router.updateURL(path);
|
|
||||||
return router.handleURL(path);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Replaces the query parameters in the URL. Use no parameters to clear them.
|
@private
|
||||||
|
|
||||||
@method replaceQueryParams
|
Handle the custom case of routing to the root path from itself.
|
||||||
|
|
||||||
|
@param {String} oldPath the previous path we were on
|
||||||
|
@param {String} path the path we're navigating to
|
||||||
**/
|
**/
|
||||||
queryParams: Em.computed.alias('router.location.queryParams'),
|
navigatedToHome: function(oldPath, path) {
|
||||||
|
|
||||||
|
var defaultFilter = "/" + Discourse.ListController.filters[0];
|
||||||
|
|
||||||
|
if (path === "/" && (oldPath === "/" || oldPath === defaultFilter)) {
|
||||||
|
// Refresh our list
|
||||||
|
this.controllerFor('list').refresh();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@private
|
@private
|
||||||
@ -137,13 +184,27 @@ Discourse.URL = Em.Object.createWithMixins({
|
|||||||
/**
|
/**
|
||||||
@private
|
@private
|
||||||
|
|
||||||
Redirect to a URL.
|
Get a handle on the application's router. Note that currently it uses `__container__` which is not
|
||||||
This has been extracted so it can be tested.
|
advised but there is no other way to access the router.
|
||||||
|
|
||||||
@method redirectTo
|
@property router
|
||||||
**/
|
**/
|
||||||
redirectTo: function(url) {
|
router: function() {
|
||||||
window.location = Discourse.getURL(url);
|
return Discourse.__container__.lookup('router:main');
|
||||||
|
}.property(),
|
||||||
|
|
||||||
|
/**
|
||||||
|
@private
|
||||||
|
|
||||||
|
Get a controller. Note that currently it uses `__container__` which is not
|
||||||
|
advised but there is no other way to access the router.
|
||||||
|
|
||||||
|
@method controllerFor
|
||||||
|
@param {String} name the name of the controller
|
||||||
|
**/
|
||||||
|
controllerFor: function(name) {
|
||||||
|
return Discourse.__container__.lookup('controller:' + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -24,6 +24,19 @@ Discourse.ListController = Discourse.Controller.extend({
|
|||||||
});
|
});
|
||||||
}.property(),
|
}.property(),
|
||||||
|
|
||||||
|
/**
|
||||||
|
Refresh our current topic list
|
||||||
|
|
||||||
|
@method refresh
|
||||||
|
**/
|
||||||
|
refresh: function() {
|
||||||
|
var listTopicsController = this.get('controllers.listTopics');
|
||||||
|
listTopicsController.set('model.loaded', false);
|
||||||
|
this.load(this.get('filterMode')).then(function (topicList) {
|
||||||
|
listTopicsController.set('model', topicList);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Load a list based on a filter
|
Load a list based on a filter
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ Discourse.FilteredListRoute = Discourse.Route.extend({
|
|||||||
var listTopicsController = this.controllerFor('listTopics');
|
var listTopicsController = this.controllerFor('listTopics');
|
||||||
listController.set('filterMode', this.filter);
|
listController.set('filterMode', this.filter);
|
||||||
|
|
||||||
var listContent = listTopicsController.get('content');
|
var listContent = listTopicsController.get('model');
|
||||||
if (listContent) {
|
if (listContent) {
|
||||||
listContent.set('loaded', false);
|
listContent.set('loaded', false);
|
||||||
}
|
}
|
||||||
@ -39,7 +39,7 @@ Discourse.FilteredListRoute = Discourse.Route.extend({
|
|||||||
listController.load(this.filter).then(function(topicList) {
|
listController.load(this.filter).then(function(topicList) {
|
||||||
listController.set('category', null);
|
listController.set('category', null);
|
||||||
listController.set('canCreateTopic', topicList.get('can_create_topic'));
|
listController.set('canCreateTopic', topicList.get('can_create_topic'));
|
||||||
listTopicsController.set('content', topicList);
|
listTopicsController.set('model', topicList);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -31,7 +31,6 @@ task 'integration:create_fixtures' => :environment do
|
|||||||
|
|
||||||
File.write(filename, content)
|
File.write(filename, content)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ d.write('<style>#ember-testing-container { position: absolute; background: white
|
|||||||
Discourse.rootElement = '#ember-testing';
|
Discourse.rootElement = '#ember-testing';
|
||||||
Discourse.setupForTesting();
|
Discourse.setupForTesting();
|
||||||
Discourse.injectTestHelpers();
|
Discourse.injectTestHelpers();
|
||||||
|
Discourse.bindDOMEvents();
|
||||||
|
|
||||||
|
|
||||||
Discourse.Router.map(function() {
|
Discourse.Router.map(function() {
|
||||||
|
Reference in New Issue
Block a user