Added section in channel settings to update description and thumbnail.
This commit is contained in:
parent
4001ad2f13
commit
370a08cb03
8 changed files with 271 additions and 17 deletions
|
|
@ -41,6 +41,7 @@ class chanInfo{
|
|||
//Create description prompt
|
||||
this.descriptionInput = document.createElement("textarea");
|
||||
this.descriptionInput.id = "channel-info-description-prompt";
|
||||
this.descriptionInput.value = this.description.textContent;
|
||||
|
||||
//Setup Input Event Handlers
|
||||
this.setupInput();
|
||||
|
|
@ -58,50 +59,71 @@ class chanInfo{
|
|||
this.thumbnailInput.style.display = enabled ? "" : "none";
|
||||
|
||||
if(enabled){
|
||||
//focus thumbnail input
|
||||
this.thumbnailInput.focus();
|
||||
|
||||
//Remove interactive class from thumby
|
||||
this.thumbnail.classList.remove('interactive');
|
||||
}else{
|
||||
//add interactive class to thumby
|
||||
this.thumbnail.classList.add('interactive');
|
||||
}
|
||||
}
|
||||
|
||||
submitThumbnail(event){
|
||||
async submitThumbnail(event){
|
||||
//If we hit didnt hit enter or escape
|
||||
if(!(event.key == "Enter" || event.key == "Escape") && event.key != null){
|
||||
//bail!
|
||||
return;
|
||||
//Only returns w/ content after this point
|
||||
}else if(event.key == "Escape" && event.key != null){
|
||||
//Toggle prompt
|
||||
this.toggleThumbnailPrompt(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//Send update off to server and wait for response
|
||||
const data = await utils.ajax.setChannelThumbnail(this.channel, this.thumbnailInput.value);
|
||||
|
||||
//Set new image from updated thumby
|
||||
this.thumbnail.src = data.thumbnail;
|
||||
|
||||
//Toggle prompt
|
||||
this.toggleThumbnailPrompt(false);
|
||||
|
||||
//Only returns after this point
|
||||
if(event.key != "Enter" && event.key != null){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
toggleDescriptionPrompt(enabled){
|
||||
if(enabled){
|
||||
this.description.replaceWith(this.descriptionInput);
|
||||
this.descriptionInput.focus()
|
||||
}else{
|
||||
this.descriptionInput.replaceWith(this.description);
|
||||
}
|
||||
}
|
||||
|
||||
submitDescription(event){
|
||||
async submitDescription(event){
|
||||
//If we hit didnt hit enter (without shift) or escape
|
||||
if(!((event.key == "Enter" && !event.shiftKey) || event.key == "Escape") && event.key != null){
|
||||
//bail!
|
||||
return;
|
||||
}else if(event.key == "Escape" && event.key != null){
|
||||
//Toggle prompt
|
||||
this.toggleDescriptionPrompt(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//Stop newline from being processed
|
||||
event.preventDefault();
|
||||
|
||||
//Set Description
|
||||
const data = await utils.ajax.setChannelDescription(this.channel, this.descriptionInput.value);
|
||||
|
||||
//Unescape entities from server-side sanatization and safely put the newly made un-safe text inside of the element via .textContent.
|
||||
//Ensuring sanatized content displays proper, and that any unsanatized content that some how made it through is still safe.
|
||||
this.description.textContent = utils.unescapeEntities(data.description);
|
||||
|
||||
//Toggle prompt
|
||||
this.toggleDescriptionPrompt(false);
|
||||
|
||||
//Only returns after this point
|
||||
if(event.key != "Enter" && !event.shiftKey && event.key != null){
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue