django / code.djangoproject.com

Configuration for Django's Trac instance (code.djangoproject.com)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Copy Button is Missing at the download page, CLI parts

cleverhare opened this issue · comments

At the Download Page of the website, there is no button to copy the code And the

Cons

  • It requires the user to select it, which is not accurate sometimes, and it requires extra effort
  • it will be even easier to use
  • User Experience will be better

How I approach solving the problem.

  • First of all I would head towards any of the icon providers like, feather icons, box icons or font awesome, or bootstrap icons
  • From there, I would paste the HTML, right at the command div black part,
  • Make sure its at the most right part of the black div
  • And Lastly, I will add addEventListener to the icon and within that function, I will write the code to clipboard.add to install the command contents on the clipboard, either by fetching the HTML text content of the code tag
  • Else will add a parent tag as input and fetch the value of it

How much time will it require ?

  • I am not sure when will I raise a PR but it would barely take 10 mins to do so

If the reviewer found it an worthy and useful issue, Do assign me to this. I would like to contribute to Django

This issue can be resolved through the following code:
HTML:

<div class="container">
 <div class="wrap">
   <div class="box">
     <p data-copy-text="">pip install Django==4.2</p>
   </div>
 </div>
</div>

CSS:

  font-size: 16px;
}
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  line-height: 1;
  border: 0;
}
html,
body {
  width: 100vw;
  min-width: 100vw;
  height: 100vh;
  min-height: 100vh;
}
body {
  background-color: #f5f5f4;
  font-family: 'Catamaran', sans-serif;
}
p {
  font-size: 1.25rem;
  line-height: 1.25;
}
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
}
.container .wrap {
  flex: 0 1 37.5rem;
  margin: 0.625rem;
}
.container .wrap .box {
  padding: 1.25rem;
  background-color: #fff;
  border: 0.0625rem solid #607d8b;
  border-radius: 0.1875rem;
}
.container .wrap .box:not(:last-child) {
  margin-bottom: 1.5625rem;
}
[data-copy-text] + i.material-icons {
  transition: all 0.25s ease-in-out;
  position: absolute;
  top: 0;
  right: 0;
  background-color: #f5f5f4;
  padding: 0.3125rem 0.625rem;
  color: #000;
  border-color: #607d8b;
  border-style: solid;
  border-top-right-radius: 0.1875rem;
  border-bottom-width: 0.0625rem;
  border-left-width: 0.0625rem;
  opacity: 0.3;
  cursor: pointer;
  z-index: 1;
}
[data-copy-text] + i.material-icons:hover,
[data-copy-text] + i.material-icons.active {
  background-color: #607d8b;
  opacity: 1;
  color: #fff;
}```
JavaScript:

'use strict';

document.addEventListener('DOMContentLoaded', function() {
copyText.init()
});

var copyText = {
init: function() {
if (document.querySelectorAll('[data-copy-text]').length) {
var cp = document.querySelectorAll('[data-copy-text]');

		for (var i = 0, l = cp.length; i < l; i++) {
			copyText.addCopy(cp[i]);
		}
	}
},
addCopy: function(el) {
	if (typeof el !== 'undifined') {
		var parent = el.parentNode;
		if (!parent.querySelectorAll('span.copy-btn').length && window.getSelection) {
			var cpBtn = document.createElement('I');

			parent.setAttribute('style', 'position:relative');
			parent.appendChild(cpBtn);

			cpBtn.classList.add('material-icons');
			cpBtn.textContent = 'content_copy';
    cpBtn.innerHTML = '&#xf0c5;';

			cpBtn.setAttribute('title', 'Copy Text');

			copyText.addCopyEvent(cpBtn, el);
		}
	}
},
addCopyEvent: function(btn, el) {
	var coppied = false;
	var timer = 0;

	function copyText() {
		function showCheckmark() {
			btn.textContent = 'check';
			btn.classList.add('active');
		}

		function hideCheckmark() {
			btn.classList.remove('active');
			btn.textContent = 'content_copy';
			timer = 0;
		}
		
		if (timer === 0) {
			if (window.getSelection) {
				var selection = window.getSelection();
				var range = document.createRange();
				range.selectNodeContents(el);
				selection.removeAllRanges();
				selection.addRange(range);

				try {
					document.execCommand('copy');
					coppied = true;
				} catch (err) {
					console.error(err);
				}

				selection.removeAllRanges();
			} else {
				console.error('your browser does not support copy');
			}

			if (coppied) {
				clearTimeout(timer);
				showCheckmark();
				timer = setTimeout(hideCheckmark, 2000);
			}
		}
	}

	if (typeof btn !== 'undifined' && typeof el !== 'undifined') {
		btn.addEventListener('click', copyText, false);
	}
},

}

**I hope the reviewer finds these code snippets useful for the improvement of their download page, So assign this to me I'll resolve it super fast. I want to contribute to Django.**

Before :

![image](https://user-images.githubusercontent.com/83120798/229566139-bc5d887c-db26-4f7a-b2dd-2230454d7209.png)


After :
![image](https://user-images.githubusercontent.com/83120798/229566297-7be1828f-1c3b-4d67-9950-8c1f3303c0e1.png)

@Chandrababu-Namani Great brother, can you attach some screenshot so that reviewer can review it super fast, and I would also hope this issue would get assigned to you brother

You also raised the issue at djangoproject.com, which is the correct repository.
django/djangoproject.com#1338

I think this issue should be closed and handled in djangoproject.com 👍