mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1689240 - Move ScrollOffsets from aboutaddons.js to view-controller.js. r=rpl
Differential Revision: https://phabricator.services.mozilla.com/D104190
This commit is contained in:
parent
330da40a65
commit
6015ee0245
@ -4679,40 +4679,6 @@ function openAmoInTab(el) {
|
||||
windowRoot.ownerGlobal.openTrustedLinkIn(amoUrl, "tab");
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for saving and restoring the scroll offsets when a previously loaded
|
||||
* view is accessed again.
|
||||
*/
|
||||
var ScrollOffsets = {
|
||||
_key: null,
|
||||
_offsets: new Map(),
|
||||
canRestore: true,
|
||||
|
||||
setView(historyEntryId) {
|
||||
this._key = historyEntryId;
|
||||
this.canRestore = true;
|
||||
},
|
||||
|
||||
getPosition() {
|
||||
if (!this.canRestore) {
|
||||
return { top: 0, left: 0 };
|
||||
}
|
||||
let { scrollTop: top, scrollLeft: left } = document.documentElement;
|
||||
return { top, left };
|
||||
},
|
||||
|
||||
save() {
|
||||
if (this._key) {
|
||||
this._offsets.set(this._key, this.getPosition());
|
||||
}
|
||||
},
|
||||
|
||||
restore() {
|
||||
let { top = 0, left = 0 } = this._offsets.get(this._key) || {};
|
||||
window.scrollTo({ top, left, behavior: "auto" });
|
||||
},
|
||||
};
|
||||
|
||||
function sendEMPong(aSubject, aTopic, aData) {
|
||||
Services.obs.notifyObservers(window, "EM-pong");
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
/* import-globals-from ../../../content/customElements.js */
|
||||
/* import-globals-from aboutaddonsCommon.js */
|
||||
/* import-globals-from aboutaddons.js */
|
||||
/* exported loadView */
|
||||
|
||||
const { AddonManager } = ChromeUtils.import(
|
||||
@ -47,6 +46,40 @@ function loadView(viewId) {
|
||||
gViewController.loadView(viewId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for saving and restoring the scroll offsets when a previously loaded
|
||||
* view is accessed again.
|
||||
*/
|
||||
var ScrollOffsets = {
|
||||
_key: null,
|
||||
_offsets: new Map(),
|
||||
canRestore: true,
|
||||
|
||||
setView(historyEntryId) {
|
||||
this._key = historyEntryId;
|
||||
this.canRestore = true;
|
||||
},
|
||||
|
||||
getPosition() {
|
||||
if (!this.canRestore) {
|
||||
return { top: 0, left: 0 };
|
||||
}
|
||||
let { scrollTop: top, scrollLeft: left } = document.documentElement;
|
||||
return { top, left };
|
||||
},
|
||||
|
||||
save() {
|
||||
if (this._key) {
|
||||
this._offsets.set(this._key, this.getPosition());
|
||||
}
|
||||
},
|
||||
|
||||
restore() {
|
||||
let { top = 0, left = 0 } = this._offsets.get(this._key) || {};
|
||||
window.scrollTo({ top, left, behavior: "auto" });
|
||||
},
|
||||
};
|
||||
|
||||
var gViewController = {
|
||||
currentViewId: null,
|
||||
get defaultViewId() {
|
||||
|
Loading…
Reference in New Issue
Block a user