a-plus icon indicating copy to clipboard operation
a-plus copied to clipboard

Make `aplus:exercise-loaded` into a cancellable event

Open raphendyr opened this issue 5 years ago • 2 comments

The current event is send here https://github.com/apluslms/a-plus/blob/d10087a658dfffdcfa0d7626dad16016e41372dd/exercise/static/exercise/chapter.js#L65-L66

To support JavaScript plugins and to help removing data-aplus-ajax special variable, the event should be made cancellable. This means, the code should look something like

const event_data = {
	bubbles: true,
	cancelable: true,
	detail: {
		type: type,
	},
};
if (this.dom_element.dispatchEvent(
		new CustomEvent("aplus:exercise-loaded", event_data))
) {
	// aplus:exercise-loaded was not cancelled, proceed with the default action
	$.augmentSubmitButton($(".exercise-column"));
	this.dom_element.dispatchEvent(
		new CustomEvent("aplus:exercise-ready", event_data));
}

Todo:

  • [ ] make event cancellable
  • [ ] schedule deprecation of data-aplus-ajax (is documented in https://apluslms.github.io/protocols/aplus-material-v1/)
  • [ ] update the protocol documentation in https://apluslms.github.io/protocols/aplus-js-v1/

raphendyr avatar Aug 28 '20 08:08 raphendyr

Can you elaborate in which specific use cases would this be useful?

jkotimak avatar May 27 '25 10:05 jkotimak

Hey, fun. 5 year old technical "issue" without a clear user goal. I guess this could be just closed, if it didn't come up in past years...

I guess the origianl goal was to remove variable data-aplus-ajax.

From the linked doc page (which I have no idea if it's at all up to date):

data-aplus-ajax (pending deprecation). Stops A+ from binding to the submit event of the exercise form and adding group selection and so on. May be used when the course JavaScript takes care of that.

And I have no idea if that original idea to change the exercise API is a good or not.

raphendyr avatar May 27 '25 11:05 raphendyr