Skip to content

Instantly share code, notes, and snippets.

@c80609a
Created May 6, 2022 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c80609a/111dc243d289d9bdaeb2c1f01c8f6353 to your computer and use it in GitHub Desktop.
Save c80609a/111dc243d289d9bdaeb2c1f01c8f6353 to your computer and use it in GitHub Desktop.
DelPhoto
// Handles click on the button "🞮" - delete photo
class DelPhoto {
constructor(html_node) {
this.$btn = $(html_node)
this.btn_id = this.$btn.attr("id")
this.$photo_div = $('#'+this.btn_id.split('photo_delete_').join('photo_'))
this.ajaxSuccess = this.ajaxSuccess.bind(this)
this.check()
this.init()
}
init() {
this.$btn[0].addEventListener("ajax:success", this.ajaxSuccess)
}
/**
*
* @param e {CustomEvent}
*/
ajaxSuccess({ detail: [data, status, xhr] }) {
console.log(data)
console.log(status)
console.log(xhr)
}
check() {
if (this.$photo_div.length === 0) {
throw Error(`У кнопки должен быть контейнер, содержащий фото, с атрибутом id="photo_${this.btn_id}"`)
}
}
static init() {
var $btns = $('.js-btn-photo_delete')
if ($btns.length == 0) return
let btn, i, len = $btns.length
for (i = 0; i < len; i++) {
btn = $btns[i]
new DelPhoto(btn)
}
}
}
window.DelPhoto = DelPhoto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment