You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

67 lines
2.5 KiB

{% extends 'base.html' %}
{% load bootstrap5 %}
{% block content %}
<div class="container">
<div class="row my-5">
<div class="col-md-12">
<h1>Заполните данные статьи для продвижения в соц. сетях</h1>
<form
method="post"
enctype="application/x-www-form-urlencoded"
action="{% url 'create-article' %}"
class="form"
>
{% csrf_token %}
{% bootstrap_form new_article_form %}
{% buttons %}
<div class="row">
<div class="col">
<button
class="btn btn-primary"
type="submit"
disabled="disabled"
>
Продвинуть
</button>
</div>
<div id="vkShare" class="col"></div>
</div>
{% endbuttons %}
</form>
</div>
</div>
</div>
{% endblock content %}
{% block extra_scripts %}
<script type="text/javascript">
let submitBtn = null
const enableSubmitBtn = () => {
submitBtn.disabled = false
}
const appendShare = (e) => {
submitBtn.disabled = true
const articleLink = e.target.value;
const gen = {
url: articleLink
}
const buttonType = {
type: "custom",
text: '<img src="https://vk.com/images/share_32_2x.png" width="32" height="32" alt="share icon" />'
}
document.getElementById('vkShare').innerHTML = VK.Share.button(gen, buttonType)
const vkButtons = document.querySelectorAll('a[href^="//vk.com/"]')
vkButtons.forEach((vkBtn) => vkBtn.addEventListener('click', enableSubmitBtn))
}
const main = () => {
submitBtn = document.querySelector('button[type="submit"]')
const linkInput = document.querySelector('[name="link"]');
linkInput.addEventListener('input', appendShare)
linkInput.addEventListener('paste', appendShare)
}
window.addEventListener('DOMContentLoaded', main)
</script>
{% endblock %}