Skip to content

Commit

Permalink
New: Add click event trigger (solves: adaptlearning#106) (adaptlearni…
Browse files Browse the repository at this point in the history
…ng#107)

* Add event trigger to JSX
* Moved trigger to view
  • Loading branch information
joe-replin authored May 26, 2023
1 parent 28b3873 commit 0d27f68
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions js/ResourcesView.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ export default class ResourcesView extends Backbone.View {
}

initialize() {
this.onResourceItemClicked = this.onResourceItemClicked.bind(this);

this.listenTo(Adapt, 'remove', this.remove);
this.render();
}

render() {
const data = {
...this,
model: this.model.toJSON(),
resources: this.model.get('_resources')
};
Expand All @@ -29,4 +32,10 @@ export default class ResourcesView extends Backbone.View {
return this;
}

onResourceItemClicked(e) {
const index = $(e.currentTarget).attr('data-index');
const resourceItemData = this.model.get('_resourcesItems')[index];
Adapt.trigger('resources:itemClicked', resourceItemData);
}

}
1 change: 1 addition & 0 deletions templates/resources.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export default function Resources (props) {
{resources.map(({ title, description, _link, _type, _isGlobal, filename, _forceDownload }, index) =>
<templates.resourcesItem {...props}
key={index}
_index={index}
title={title}
description={description}
_link={_link}
Expand Down
6 changes: 5 additions & 1 deletion templates/resourcesItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ export default function ResourcesItem (props) {
_isGlobal,
_link,
_type,
_index,
description,
filename,
selectedFilter,
title
title,
onResourceItemClicked
} = props;

/**
Expand Down Expand Up @@ -39,7 +41,9 @@ export default function ResourcesItem (props) {

<a href={_link} className="resources__item-btn drawer__item-btn"
data-type={_type}
data-index={_index}
download={resourcesForceDownload(filename, _forceDownload) && filename }
onClick={onResourceItemClicked}
target="_blank"
rel="noreferrer"
aria-label={title}>
Expand Down

0 comments on commit 0d27f68

Please sign in to comment.