diff --git a/static/css/base.css b/static/css/base.css index 1dd9700..fa2c28a 100644 --- a/static/css/base.css +++ b/static/css/base.css @@ -7,7 +7,9 @@ --ui-gray-1-color: #C6C6C7; --ui-gray-3-color: #8E8E93; --red-0-color: #FF3B30; + --green-0-color: #06EC01; --special-0-color: #E70078; + --font-h1-size: 24px; --font-h2-size: 18px; --font-body-size: 18px; diff --git a/static/css/promo.css b/static/css/promo.css index 11e924a..7eb6111 100644 --- a/static/css/promo.css +++ b/static/css/promo.css @@ -1,3 +1,6 @@ +.action-icon-done { color: var(--green-0-color); } +.action-icon-error { color: var(--red-0-color); } + .gift-list { display: grid; grid-template-columns: 1fr 1fr; @@ -45,12 +48,18 @@ background: var(--ui-gray-m1-color); } -.cp-btn-cp-action:hover { background: var(--ui-gray-0-color); } +.cp-btn-cp-action:hover { + background: var(--ui-gray-0-color); + cursor: pointer; +} + .cp-btn-cp-action:active { background: var(--ui-gray-1-color); } -.cp-btn-cp-action > svg { +.icon-holder > svg { width: var(--ui-icon-size); height: var(--ui-icon-size); + /* Centering of icon, based on button size. */ + padding: 6px; } .gift-img { diff --git a/static/icons/check.svg b/static/icons/check.svg new file mode 100644 index 0000000..4621174 --- /dev/null +++ b/static/icons/check.svg @@ -0,0 +1,3 @@ + + + diff --git a/static/icons/x_mark.svg b/static/icons/x_mark.svg new file mode 100644 index 0000000..672d7af --- /dev/null +++ b/static/icons/x_mark.svg @@ -0,0 +1,3 @@ + + + diff --git a/static/js/promo.js b/static/js/promo.js new file mode 100644 index 0000000..c29b503 --- /dev/null +++ b/static/js/promo.js @@ -0,0 +1,101 @@ +function copyToClipboard(text, onSuccess = undefined, onFailure = undefined) { + navigator.clipboard + .writeText(text) + .then(() => { + if (onSuccess === undefined){ + console.log('clipboard success'); + return; + } + onSuccess(); + }) + .catch((e) => { + if (onFailure === undefined){ + console.log('clipboard failed\n' + e); + return; + } + onFailure(e); + }); +} + +function getFirstClassElement(root, class_name){ + let elements = root.getElementsByClassName(class_name); + if (elements.length != 1){ + return undefined; + } + return elements[0]; +} + +function attachCopyEvent(copy_button){ + let input = getFirstClassElement(copy_button, 'cp-btn-text-to-copy'); + if (input === undefined){ + console.error('Exactly one input required. Check HTML/CSS.'); + return false; + } + let text_to_copy = input.value; + + let action_copy = getFirstClassElement(copy_button, 'cp-btn-cp-action'); + if (action_copy === undefined){ + console.error('Exactly one copy button required. Check HTML/CSS.'); + return false; + } + + let icon_act = getFirstClassElement(action_copy, 'action-icon-act'); + if (icon_act === undefined){ + console.error('Exactly one act icon required. Check HTML/CSS.'); + return false; + } + + let icon_done = getFirstClassElement(action_copy, 'action-icon-done'); + if (icon_done === undefined){ + console.error('Exactly one done icon required. Check HTML/CSS.'); + return false; + } + + let icon_error = getFirstClassElement(action_copy, 'action-icon-error'); + if (icon_error === undefined){ + console.error('Exactly one error icon required. Check HTML/CSS.'); + return false; + } + + action_copy.addEventListener('click', function (){ + let show = (x) => { x.style.display = 'inline' }; + let hide = (x) => { x.style.display = 'none' }; + + let show_time_milliseconds = 3000; + copyToClipboard(text_to_copy, + function(){ + console.debug('Successfull copy.'); + + hide(icon_act); + show(icon_done); + + setTimeout(() => { + show(icon_act); + hide(icon_done); + }, show_time_milliseconds); + }, + function(){ + console.debug('Error during copy.'); + + hide(icon_act); + show(icon_error); + + setTimeout(() => { + show(icon_act); + hide(icon_error); + }, show_time_milliseconds); + } + ); + }); + + return true; +} + +function main(){ + var copy_buttons = document.getElementsByClassName('cp-btn'); + for (var i = 0; i < copy_buttons.length; i++){ + attachCopyEvent(copy_buttons[i]); + } +} + +document.addEventListener('DOMContentLoaded', main); diff --git a/templates/base.html b/templates/base.html index ab38550..729ed66 100644 --- a/templates/base.html +++ b/templates/base.html @@ -16,7 +16,11 @@ {% macro copybutton(texttocopy) -%} - + + {{ icons.clipboard }} + + + {%- endmacro %} @@ -106,4 +110,7 @@ {% endblock %} + + {% block page_just_before_end %} + {% endblock %} diff --git a/templates/promo.html b/templates/promo.html index 57831f3..2ac1830 100644 --- a/templates/promo.html +++ b/templates/promo.html @@ -34,3 +34,7 @@

Промокод на подарок

{% endblock %} + +{% block page_just_before_end %} + +{% endblock %}