mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-08 08:28:15 -04:00
Make classNames used by classesPersister private
Both the remove and replace methods rely on it having parity with the $els array property so it is a good idea to stop it, and $els, being changable by other code. As noted in: https://github.com/alphagov/notifications-admin/pull/4155#discussion_r804639058
This commit is contained in:
@@ -14,19 +14,22 @@
|
|||||||
// Methods to ensure the DOM fragment is clean of classes added by JS before diffing
|
// Methods to ensure the DOM fragment is clean of classes added by JS before diffing
|
||||||
// and that they are replaced afterwards.
|
// and that they are replaced afterwards.
|
||||||
var classesPersister = {
|
var classesPersister = {
|
||||||
classNames: [],
|
_classNames: [],
|
||||||
$els: [],
|
_$els: [],
|
||||||
|
addClassName: function (className) {
|
||||||
|
this._classNames.push(className);
|
||||||
|
},
|
||||||
remove: function () {
|
remove: function () {
|
||||||
this.classNames.forEach(className => {
|
this._classNames.forEach(className => {
|
||||||
var $elsWithClassName = $('.' + className).removeClass(className);
|
var $elsWithClassName = $('.' + className).removeClass(className);
|
||||||
|
|
||||||
// store elements for that className at the same index
|
// store elements for that className at the same index
|
||||||
this.$els.push($elsWithClassName);
|
this._$els.push($elsWithClassName);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
replace: function () {
|
replace: function () {
|
||||||
this.classNames.forEach((className, index) => {
|
this._classNames.forEach((className, index) => {
|
||||||
var $el = this.$els[index];
|
var $el = this._$els[index];
|
||||||
|
|
||||||
if (global.document.body.contains($el.get(0))) {
|
if (global.document.body.contains($el.get(0))) {
|
||||||
$el.addClass(className);
|
$el.addClass(className);
|
||||||
@@ -101,7 +104,7 @@
|
|||||||
if ($contents.data('classesToPersist') !== undefined) {
|
if ($contents.data('classesToPersist') !== undefined) {
|
||||||
$contents.data('classesToPersist')
|
$contents.data('classesToPersist')
|
||||||
.split(' ')
|
.split(' ')
|
||||||
.forEach(className => classesPersister.classNames.push(className));
|
.forEach(className => classesPersister.addClassName(className));
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(
|
setTimeout(
|
||||||
|
|||||||
Reference in New Issue
Block a user