Remove the `ScrollTop` Mixin

This commit is contained in:
Robin Ward 2016-11-10 14:35:53 -05:00
parent 0904ad5537
commit a94f06ff78
20 changed files with 77 additions and 95 deletions

View File

@ -1,12 +1,11 @@
import BufferedContent from 'discourse/mixins/buffered-content'; import BufferedContent from 'discourse/mixins/buffered-content';
import ScrollTop from 'discourse/mixins/scroll-top';
import SiteSetting from 'admin/models/site-setting'; import SiteSetting from 'admin/models/site-setting';
import { propertyNotEqual } from 'discourse/lib/computed'; import { propertyNotEqual } from 'discourse/lib/computed';
import computed from 'ember-addons/ember-computed-decorators'; import computed from 'ember-addons/ember-computed-decorators';
const CustomTypes = ['bool', 'enum', 'list', 'url_list', 'host_list', 'category_list', 'value_list']; const CustomTypes = ['bool', 'enum', 'list', 'url_list', 'host_list', 'category_list', 'value_list'];
export default Ember.Component.extend(BufferedContent, ScrollTop, { export default Ember.Component.extend(BufferedContent, {
classNameBindings: [':row', ':setting', 'setting.overridden', 'typeClass'], classNameBindings: [':row', ':setting', 'setting.overridden', 'typeClass'],
content: Ember.computed.alias('setting'), content: Ember.computed.alias('setting'),
dirty: propertyNotEqual('buffered.value', 'setting.value'), dirty: propertyNotEqual('buffered.value', 'setting.value'),

View File

@ -1,4 +1,4 @@
<div class='current-badge span13'> {{#d-section class="current-badge span13"}}
<p>{{i18n 'admin.badges.none_selected'}}</p> <p>{{i18n 'admin.badges.none_selected'}}</p>
<div> <div>
@ -6,4 +6,4 @@
{{fa-icon "plus"}} {{i18n 'admin.badges.new'}} {{fa-icon "plus"}} {{i18n 'admin.badges.new'}}
{{/link-to}} {{/link-to}}
</div> </div>
</div> {{/d-section}}

View File

@ -1,4 +1,4 @@
<div class='current-badge span13'> {{#d-section class="current-badge span13"}}
<form class="form-horizontal"> <form class="form-horizontal">
<div> <div>
<label for="name">{{i18n 'admin.badges.name'}}</label> <label for="name">{{i18n 'admin.badges.name'}}</label>
@ -143,7 +143,7 @@
{{/unless}} {{/unless}}
</div> </div>
</form> </form>
</div> {{/d-section}}
{{#if grant_count}} {{#if grant_count}}
<div class="span13 current-badge-actions"> <div class="span13 current-badge-actions">

View File

@ -1,9 +1,9 @@
{{#if filteredContent}} {{#if filteredContent}}
<div class='form-horizontal settings'> {{#d-section class="form-horizontal settings"}}
{{#each filteredContent as |setting|}} {{#each filteredContent as |setting|}}
{{site-setting setting=setting saveAction="saveSetting"}} {{site-setting setting=setting saveAction="saveSetting"}}
{{/each}} {{/each}}
</div> {{/d-section}}
{{else}} {{else}}
<br/> <br/>
{{i18n 'admin.site_settings.no_results'}} {{i18n 'admin.site_settings.no_results'}}

View File

@ -1 +1,3 @@
{{outlet}} {{#d-section}}
{{outlet}}
{{/d-section}}

View File

@ -1,3 +0,0 @@
import ScrollTop from 'discourse/mixins/scroll-top';
export default Ember.View.extend(ScrollTop);

View File

@ -1,7 +0,0 @@
import ScrollTop from 'discourse/mixins/scroll-top';
export default Ember.View.extend(ScrollTop, {
_scrollOnModelChange: function() {
this._scrollTop();
}.observes('controller.model.id')
});

View File

@ -1 +0,0 @@
export default Ember.View.extend(Discourse.ScrollTop);

View File

@ -1,14 +1,9 @@
import DiscourseURL from 'discourse/lib/url'; import { scrollTop } from 'discourse/mixins/scroll-top';
// Can add a body class from within a component, also will scroll to the top automatically. // Can add a body class from within a component, also will scroll to the top automatically.
export default Ember.Component.extend({ export default Ember.Component.extend({
tagName: 'section', tagName: 'section',
_scrollTop() {
if (Ember.testing) { return; }
$(document).scrollTop(0);
},
didInsertElement() { didInsertElement() {
this._super(); this._super();
@ -26,8 +21,7 @@ export default Ember.Component.extend({
return; return;
} }
if (DiscourseURL.isJumpScheduled()) { return; } scrollTop();
Ember.run.scheduleOnce('afterRender', this, this._scrollTop);
}, },
willDestroyElement() { willDestroyElement() {

View File

@ -0,0 +1,24 @@
import isElementInViewport from "discourse/lib/is-element-in-viewport";
export default Ember.Component.extend({
didInsertElement() {
this._super();
const currentUser = this.currentUser;
if (!currentUser) { return; }
const path = this.get('path');
if (path === "faq" || path === "guidelines") {
$(window).on('load.faq resize.faq scroll.faq', () => {
const faqUnread = !currentUser.get('read_faq');
if (faqUnread && isElementInViewport($(".contents p").last())) {
this.sendAction();
}
});
}
},
willDestroyElement() {
this._super();
$(window).off('load.faq resize.faq scroll.faq');
}
});

View File

@ -6,6 +6,9 @@ export default Ember.Controller.extend({
showLoginButton: Em.computed.equal("model.path", "login"), showLoginButton: Em.computed.equal("model.path", "login"),
@computed('model.path')
bodyClass: path => `static-${path}`,
@computed("model.path") @computed("model.path")
showSignupButton() { showSignupButton() {
return this.get("model.path") === "login" && this.get('application.canSignUp'); return this.get("model.path") === "login" && this.get('application.canSignUp');

View File

@ -1,14 +1,24 @@
import DiscourseURL from 'discourse/lib/url'; import DiscourseURL from 'discourse/lib/url';
import { deprecated } from 'discourse/mixins/scroll-top';
const context = {
_scrollTop() {
if (Ember.testing) { return; }
$(document).scrollTop(0);
}
};
function scrollTop() { function scrollTop() {
if (DiscourseURL.isJumpScheduled()) { return; } if (DiscourseURL.isJumpScheduled()) { return; }
Ember.run.schedule('afterRender', function() { Ember.run.scheduleOnce('afterRender', context, context._scrollTop);
$(document).scrollTop(0);
});
} }
export default Ember.Mixin.create({ export default Ember.Mixin.create({
_scrollTop: scrollTop.on('didInsertElement') didInsertElement() {
deprecated('The `ScrollTop` mixin is deprecated. Replace it with a `{{d-section}}` component');
this._super();
scrollTop();
}
}); });
export { scrollTop }; export { scrollTop };

View File

@ -1,4 +1,5 @@
<div class='container'> {{#d-section bodyClass=bodyClass class="container"}}
{{#watch-read action="markFaqRead" path=model.path}}
<div class='contents clearfix body-page'> <div class='contents clearfix body-page'>
{{plugin-outlet "above-static"}} {{plugin-outlet "above-static"}}
{{{model.html}}} {{{model.html}}}
@ -11,4 +12,5 @@
{{d-button action="showLogin" class="btn-primary login-button" icon="user" label="log_in"}} {{d-button action="showLogin" class="btn-primary login-button" icon="user" label="log_in"}}
{{/if}} {{/if}}
</div> </div>
</div> {{/watch-read}}
{{/d-section}}

View File

@ -1,5 +1,5 @@
<div class="container{{if viewingSelf ' viewing-self'}}"> <div class="container {{if viewingSelf 'viewing-self'}}">
<section class='user-main'> {{#d-section class="user-main"}}
<section class="{{if collapsedInfo 'collapsed-info'}} about {{if hasProfileBackground 'has-background' 'no-background'}}" style={{model.profileBackground}}> <section class="{{if collapsedInfo 'collapsed-info'}} about {{if hasProfileBackground 'has-background' 'no-background'}}" style={{model.profileBackground}}>
{{#unless collapsedInfo}} {{#unless collapsedInfo}}
@ -186,5 +186,5 @@
</div> </div>
</div> </div>
</section> {{/d-section}}
</div> </div>

View File

@ -1,4 +1,4 @@
{{#d-section pageClass="user-activity" class="user-nagivation" scrollTop="false"}} {{#d-section pageClass="user-activity" class="user-navigation" scrollTop="false"}}
{{#mobile-nav class='activity-nav' desktopClass='action-list activity-list nav-stacked' currentPath=currentPath}} {{#mobile-nav class='activity-nav' desktopClass='action-list activity-list nav-stacked' currentPath=currentPath}}
<li class='no-glyph'> <li class='no-glyph'>
{{#link-to 'userActivity.index'}}{{i18n 'user.filters.all'}}{{/link-to}} {{#link-to 'userActivity.index'}}{{i18n 'user.filters.all'}}{{/link-to}}

View File

@ -1,40 +0,0 @@
import isElementInViewport from "discourse/lib/is-element-in-viewport";
import ScrollTop from 'discourse/mixins/scroll-top';
import { on } from 'ember-addons/ember-computed-decorators';
export default Ember.View.extend(ScrollTop, {
@on('didInsertElement')
_addBodyClass() {
const path = this.get('controller.model.path');
$('body').addClass(`static-${path}`);
},
@on('willDestroyElement')
_removeBodyClass() {
const path = this.get('controller.model.path');
$('body').removeClass(`static-${path}`);
},
@on('didInsertElement')
_checkRead() {
const currentUser = this.get('controller.currentUser');
if (currentUser) {
const path = this.get('controller.model.path');
if (path === "faq" || path === "guidelines") {
const controller = this.get('controller');
$(window).on('load.faq resize.faq scroll.faq', function() {
const faqUnread = !currentUser.get('read_faq');
if (faqUnread && isElementInViewport($(".contents p").last())) {
controller.send('markFaqRead');
}
});
}
}
},
@on('willDestroyElement')
_stopChecking() {
$(window).off('load.faq resize.faq scroll.faq');
}
});

View File

@ -1,4 +0,0 @@
import ScrollTop from 'discourse/mixins/scroll-top';
export default Ember.View.extend(ScrollTop, {
});

View File

@ -4,21 +4,25 @@ acceptance("Static");
test("Static Pages", () => { test("Static Pages", () => {
visit("/faq"); visit("/faq");
andThen(() => { andThen(() => {
ok($('body.static-faq').length, "has the body class");
ok(exists(".body-page"), "The content is present"); ok(exists(".body-page"), "The content is present");
}); });
visit("/guidelines"); visit("/guidelines");
andThen(() => { andThen(() => {
ok($('body.static-guidelines').length, "has the body class");
ok(exists(".body-page"), "The content is present"); ok(exists(".body-page"), "The content is present");
}); });
visit("/tos"); visit("/tos");
andThen(() => { andThen(() => {
ok($('body.static-tos').length, "has the body class");
ok(exists(".body-page"), "The content is present"); ok(exists(".body-page"), "The content is present");
}); });
visit("/privacy"); visit("/privacy");
andThen(() => { andThen(() => {
ok($('body.static-privacy').length, "has the body class");
ok(exists(".body-page"), "The content is present"); ok(exists(".body-page"), "The content is present");
}); });

View File

@ -28,5 +28,6 @@ test("Root URL - Viewing Self", () => {
andThen(() => { andThen(() => {
ok($('body.user-summary-page').length, "has the body class"); ok($('body.user-summary-page').length, "has the body class");
equal(currentPath(), 'user.summary', "it defaults to summary"); equal(currentPath(), 'user.summary', "it defaults to summary");
ok(exists('.container.viewing-self'), "has the viewing-self class");
}); });
}); });

View File

@ -65,9 +65,7 @@ export default function() {
this.get('/users/eviltrout.json', () => { this.get('/users/eviltrout.json', () => {
const json = fixturesByUrl['/users/eviltrout.json']; const json = fixturesByUrl['/users/eviltrout.json'];
if (loggedIn()) { json.user.can_edit = loggedIn();
json.user.can_edit = true;
}
return response(json); return response(json);
}); });