diff --git a/app/mixins/scroll-tracker.js b/app/mixins/scroll-tracker.js deleted file mode 100644 index 51a2e0d8..00000000 --- a/app/mixins/scroll-tracker.js +++ /dev/null @@ -1,42 +0,0 @@ -import Mixin from '@ember/object/mixin'; -import { inject as service } from '@ember/service'; -import config from 'ember-api-docs/config/environment'; -import getOffset from 'ember-api-docs/utils/get-offset'; - -export default Mixin.create({ - scrollPositionReset: service(), - - actions: { - willTransition(transition) { - this.scrollPositionReset.scheduleReset(transition); - }, - - didTransition() { - this._super(); - if ( - typeof FastBoot === 'undefined' && - window.location.search === '?anchor=' - ) { - let elem = document.querySelector('#methods'); - - if (elem && elem.offsetHeight) { - const offsetToScroll = getOffset( - elem, - config.APP.scrollContainerSelector - ); - const scrollContainer = document.querySelector( - config.APP.scrollContainerSelector - ); - if (scrollContainer.scrollTo) { - scrollContainer.scrollTo(0, offsetToScroll - 10); - } else { - // fallback for IE11 - scrollContainer.scrollTop = offsetToScroll - 10; - } - return; - } - } - this.scrollPositionReset.doReset(); - }, - }, -}); diff --git a/app/routes/project-version/classes/class.js b/app/routes/project-version/classes/class.js index db930130..bf726d83 100644 --- a/app/routes/project-version/classes/class.js +++ b/app/routes/project-version/classes/class.js @@ -2,12 +2,12 @@ import { inject as service } from '@ember/service'; import { resolve, all } from 'rsvp'; import Route from '@ember/routing/route'; import { set } from '@ember/object'; -import ScrollTracker from 'ember-api-docs/mixins/scroll-tracker'; + import { pluralize } from 'ember-inflector'; import getFullVersion from 'ember-api-docs/utils/get-full-version'; import createExcerpt from 'ember-api-docs/utils/create-excerpt'; -export default class ClassRoute extends Route.extend(ScrollTracker) { +export default class ClassRoute extends Route { /** @type {import('@ember/routing/router-service').default} */ @service router; diff --git a/app/routes/project-version/functions/function.js b/app/routes/project-version/functions/function.js index f0dd7cac..dcdfb285 100644 --- a/app/routes/project-version/functions/function.js +++ b/app/routes/project-version/functions/function.js @@ -11,9 +11,6 @@ export default class FunctionRoute extends Route { @service metaStore; - @service - scrollPositionReset; - titleToken(model) { return model?.fn?.name; } @@ -63,8 +60,4 @@ export default class FunctionRoute extends Route { return fn.name === functionName; }); } - - activate() { - this.scrollPositionReset.doReset(); - } } diff --git a/app/routes/project-version/modules/module.js b/app/routes/project-version/modules/module.js index eb11468f..423b20c9 100644 --- a/app/routes/project-version/modules/module.js +++ b/app/routes/project-version/modules/module.js @@ -1,8 +1,7 @@ import ClassRoute from '../classes/class'; -import ScrollTracker from 'ember-api-docs/mixins/scroll-tracker'; import getFullVersion from 'ember-api-docs/utils/get-full-version'; -export default class ModuleRoute extends ClassRoute.extend(ScrollTracker) { +export default class ModuleRoute extends ClassRoute { async model(params) { const { project, project_version: compactVersion } = this.paramsFor('project-version'); diff --git a/app/routes/project-version/namespaces/namespace.js b/app/routes/project-version/namespaces/namespace.js index dc8e31d0..bd79fdf4 100644 --- a/app/routes/project-version/namespaces/namespace.js +++ b/app/routes/project-version/namespaces/namespace.js @@ -1,8 +1,7 @@ import ClassRoute from '../classes/class'; -import ScrollTracker from 'ember-api-docs/mixins/scroll-tracker'; import getFullVersion from 'ember-api-docs/utils/get-full-version'; -export default class NamespaceRoute extends ClassRoute.extend(ScrollTracker) { +export default class NamespaceRoute extends ClassRoute { templateName = 'project-version/classes/class'; async model(params) { diff --git a/app/routes/project.js b/app/routes/project.js index bcc5f143..76aca201 100644 --- a/app/routes/project.js +++ b/app/routes/project.js @@ -1,8 +1,7 @@ import Route from '@ember/routing/route'; -import ScrollTracker from 'ember-api-docs/mixins/scroll-tracker'; import { inject as service } from '@ember/service'; -export default class ProjectRoute extends Route.extend(ScrollTracker) { +export default class ProjectRoute extends Route { /** @type {import('@ember/routing/router-service').default} */ @service router; diff --git a/app/services/scroll-position-reset.js b/app/services/scroll-position-reset.js deleted file mode 100644 index de468b1b..00000000 --- a/app/services/scroll-position-reset.js +++ /dev/null @@ -1,72 +0,0 @@ -import Service from '@ember/service'; -import config from '../config/environment'; -import getOffset from '../utils/get-offset'; - -const { scrollContainerSelector } = config.APP; - -export default class ScrollPositionResetService extends Service { - constructor() { - super(...arguments); - this._shouldResetScroll = false; - } - handleScrollPosition() { - if ( - typeof FastBoot === 'undefined' && - window.location.search === '?anchor=' - ) { - let elem = document.querySelector('#methods'); - - if (elem && elem.offsetHeight) { - const offsetToScroll = getOffset( - elem, - config.APP.scrollContainerSelector - ); - document - .querySelector(config.APP.scrollContainerSelector) - .scrollTo(0, offsetToScroll - 10); - return; - } - } - this.doReset(); - } - - _isChangingTab(transition) { - //TODO: Use routeInfo for reliable behavior - const dynamicSlugLocation = 3; - - let fromRoutePathParts = transition.from.name.split('.'); - let toRoutePathParts = transition.to.name.split('.'); - - let fromSubPath = fromRoutePathParts - .splice(dynamicSlugLocation, fromRoutePathParts.length) - .join('.'); - let toSubPath = toRoutePathParts - .splice(dynamicSlugLocation, toRoutePathParts.length) - .join('.'); - - return ( - fromSubPath !== toSubPath && - fromRoutePathParts.join('.') === toRoutePathParts.join('.') - ); - } - - scheduleReset(transition) { - if (!this._isChangingTab(transition)) { - this._shouldResetScroll = true; - } - } - - doReset() { - if (this._shouldResetScroll) { - const selector = document.querySelector(scrollContainerSelector); - if (selector.scrollTo) { - selector.scrollTo(0, 0); - } else { - // fallback for IE11 - selector.scrollLeft = 0; - selector.scrollTop = 0; - } - this._shouldResetScroll = false; - } - } -} diff --git a/tests/unit/mixins/scroll-tracker-test.js b/tests/unit/mixins/scroll-tracker-test.js deleted file mode 100644 index 8459719e..00000000 --- a/tests/unit/mixins/scroll-tracker-test.js +++ /dev/null @@ -1,12 +0,0 @@ -import EmberObject from '@ember/object'; -import ScrollTrackerMixin from 'ember-api-docs/mixins/scroll-tracker'; -import { module, test } from 'qunit'; - -module('Unit | Mixin | scroll tracker', function () { - // Replace this with your real tests. - test('it works', function (assert) { - let ScrollTrackerObject = EmberObject.extend(ScrollTrackerMixin); - let subject = ScrollTrackerObject.create(); - assert.ok(subject); - }); -});