Created
May 6, 2022 14:15
-
-
Save c80609a/111dc243d289d9bdaeb2c1f01c8f6353 to your computer and use it in GitHub Desktop.
DelPhoto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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