Created
December 16, 2019 16:37
-
-
Save anmolj7/8109e4999cecbd8d2023c0bd1a4e7279 to your computer and use it in GitHub Desktop.
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
<html> | |
<head> | |
<title>Task for GCI</title> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> | |
<style> | |
input{ | |
border: none; | |
background-color: lightblue; | |
} | |
body{ | |
background-color: lightblue; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Some Random TV Series I love.</h1> | |
<p>P.S: Not in any particular order.</p> | |
<div id="tv_list"></div> | |
<script> | |
//Building thte list. | |
var list = [ | |
'Scorpion', | |
'The Arrow', | |
'Suits', | |
'Breaking Bad', | |
'One Punch Man', | |
'The Big Bang Theory', | |
'The Boys', | |
'The 100', | |
'Lucifer' //I loved this guy in the crossover, Crisis on Inifite earths. | |
]; | |
function make_list(list){ | |
var html_list = document.createElement('ul'); | |
for(var i=0; i<list.length; i++){ | |
var list_element = document.createElement('li'); | |
var text = document.createElement('input'); | |
//Setting the attributes. | |
text.setAttribute("type", "text"); | |
text.setAttribute("value", list[i]); | |
text.onclick = function(event){ | |
if(event.ctrlKey){ | |
this.select(); | |
} | |
} | |
text.setAttribute("readonly", "readonly") | |
list_element.appendChild(text); | |
//Adding it to html list. | |
html_list.appendChild(list_element); | |
} | |
return html_list | |
} | |
//Adding it to the tv_list id | |
document.getElementById("tv_list").appendChild(make_list(list)); | |
function select_all(){ | |
var $input_selection = $('#tv_list'); | |
var selection = window.getSelection(); | |
var range = document.createRange(); | |
range.setStartBefore($input_selection.first()[0]); | |
range.setEndAfter($input_selection.last()[0]); | |
selection.removeAllRanges(); | |
selection.addRange(range); | |
} | |
//Binding select all to ctrl+a | |
$(window).bind('keydown', function(event){ | |
switch(String.fromCharCode(event.which | event.keyCode).toLowerCase()){ | |
case 'a': | |
event.preventDefault(); | |
select_all(); | |
break; | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment