Skip to content

Commit

Permalink
Fix: Resolve minor JavaScript linting issues and hasOwnProperty warni…
Browse files Browse the repository at this point in the history
…ng (fixes #571) (#572)

* Fix minor JS linting issues

* Fix hasOwnProperty warning in img.lazyload.js
  • Loading branch information
swashbuck authored Aug 19, 2024
1 parent eb3f77d commit 63c3c61
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion js/fixes/img.lazyload.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function applyImgLoadingFix() {
Adapt.on('reactElement:preRender', event => {
if (event.name !== 'img') return;
const options = event.args[1] = event.args[1] || {};
if (options && options.hasOwnProperty('loading')) return;
if (options && Object.prototype.hasOwnProperty.call(options, 'loading')) return;
options.loading = 'eager';
});
}
4 changes: 2 additions & 2 deletions js/models/itemsComponentModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class ItemsComponentModel extends ComponentModel {
this.setUpItems();
this.listenTo(this.getChildren(), {
all: this.onAll,
'change': this.storeUserAnswer,
change: this.storeUserAnswer,
'change:_isActive': this.setVisitedStatus,
'change:_isVisited': this.checkCompletionStatus
});
Expand All @@ -27,7 +27,7 @@ export default class ItemsComponentModel extends ComponentModel {
this.getChildren().forEach(child => child.set('_isVisited', booleanArray[child.get('_index')]));
}

storeUserAnswer() {
storeUserAnswer() {
const items = this.getChildren().slice(0);
items.sort((a, b) => a.get('_index') - b.get('_index'));
const booleanArray = items.map(child => child.get('_isVisited'));
Expand Down
26 changes: 13 additions & 13 deletions js/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,19 +260,19 @@ class Router extends Backbone.Router {
let _parentId = parentModel.get('_id');
const built = buildTypes.map((_type, index) => {
const ModelClass = components.getModelClass({ _type });
const _id = `preview-${_type}`
const _id = `preview-${_type}`;
const builtModel = new ModelClass({
_type,
_id,
_parentId,
_isPreview: true
});
if (index) parentModel.getChildren().add(builtModel)
data.add(builtModel)
parentModel = builtModel
_parentId = _id
return builtModel
})
if (index) parentModel.getChildren().add(builtModel);
data.add(builtModel);
parentModel = builtModel;
_parentId = _id;
return builtModel;
});
// Clone the requested content to sanitise
model.deepClone((clone, orig) => {
// Make the cloned item available and unlocked
Expand All @@ -298,16 +298,16 @@ class Router extends Backbone.Router {
});
});
built.forEach(model => model.setupModel());
isContentObject = true
model = built[0]
model.setOnChildren({ _isPreview : true })
isContentObject = true;
model = built[0];
model.setOnChildren({ _isPreview: true });
}

const navigateToId = model.get('_id');

// Ensure that the router is rendering a contentobject
model = isContentObject ? model : model.findAncestor('contentobject');
id = model.get('_id');
id = navigateToId;

/**
* TODO:
Expand Down Expand Up @@ -351,7 +351,7 @@ class Router extends Backbone.Router {
}

async removePreviews() {
const previews = data.filter(model => model.get('_isPreview'))
const previews = data.filter(model => model.get('_isPreview'));
previews.forEach(model => data.remove(model));
}

Expand Down Expand Up @@ -582,7 +582,7 @@ class Router extends Backbone.Router {
}

onLanguageChange() {
this.updateLocation(null, null, null, null)
this.updateLocation(null, null, null, null);
}

}
Expand Down
2 changes: 1 addition & 1 deletion js/views/buttonsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export default class ButtonsView extends Backbone.View {
: isPartlyCorrect
? (ariaLabels.answeredPartlyCorrect ?? ariaLabels.answeredIncorrectly)
: ariaLabels.answeredIncorrectly;

if (!hasSpanAriaLabel) {
// Backward compability
$marking.attr('aria-label', correctnessAriaLabel);
Expand Down
2 changes: 1 addition & 1 deletion js/views/menuItemView.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class MenuItemView extends AdaptView {

attributes() {
return AdaptView.resultExtend('attributes', {
'role': 'listitem',
role: 'listitem',
'aria-labelledby': this.model.get('_id') + '-heading'
}, this);
}
Expand Down

0 comments on commit 63c3c61

Please sign in to comment.