Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added copy Button to the generated url #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 61 additions & 36 deletions Shortener/templates/shortener/home.html
Original file line number Diff line number Diff line change
@@ -1,47 +1,72 @@
{% load widget_tweaks %}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>UrlShortener</title>
<!--Include Bootstrap CSS-->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>UrlShortener</title>
<!--Include Bootstrap CSS-->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"
integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
</head>

<body>
<div class="container-fluid">
<h1 class="text-center">URL Shortner</h1>
<div class="row">
<form role="form" action="" method="post" class="col-md-8 col-md-offset-2">
{% csrf_token %}
<div class="form-group">
<label for="id_url">Long URL:</label>
{{ form.url|attr:"class:form-control input-lg"|attr:"placeholder:Example: https://www.youtube.com/watch?v=Y2VF8tmLFHw" }}
<p class="help-block text-right">Enter the lengthy URL you want to shorten.</p>
</div>
{% if error %}
<div class="text-center container">Enter the https:// or http:// in the starting of URL</div>
{% endif %}
<div class="form-group col-md-4 col-md-offset-4">
<label for="id_host">Service/Host:</label>
{{ form.host|attr:"class:form-control" }}
<p class="help-block text-center">Choose the service you want to use.</p>
</div>
<div class="form-group text-center col-md-12">
<button type="submit" class="btn btn-primary btn-lg">Submit</button>
</div>
</form>
</div>
<div class="row">
<div class="text-center col-md-6 col-md-offset-3">
<h2>{{ short_url }}</h2>
<div class="container-fluid">
<h1 class="text-center">URL Shortner</h1>
<div class="row">
<form role="form" action="" method="post" class="col-md-8 col-md-offset-2">
{% csrf_token %}
<div class="form-group">
<label for="id_url">Long URL:</label>
{{ form.url|attr:"class:form-control input-lg"|attr:"placeholder:Example: https://www.youtube.com/watch?v=Y2VF8tmLFHw" }}
<p class="help-block text-right">Enter the lengthy URL you want to shorten.</p>
</div>
{% if error %}
<div class="text-center container">Enter the https:// or http:// in the starting of URL</div>
{% endif %}
<div class="form-group col-md-4 col-md-offset-4">
<label for="id_host">Service/Host:</label>
{{ form.host|attr:"class:form-control" }}
<p class="help-block text-center">Choose the service you want to use.</p>
</div>
<div class="form-group text-center col-md-12">
<button type="submit" class="btn btn-primary btn-lg">Submit</button>
</div>
</form>
</div>
<div class="row">
<div class="text-center col-md-6 col-md-offset-3">

{% if short_url %}
<img src="http://chart.apis.google.com/chart?cht=qr&chl={{ short_url }}&chs=180x180" />
<div style="display:flex; align-items: center">
<input type="text" class="form-control form-control-lg" id="urlgen"
value="{{ short_url }}" readonly>
<h4><button style="margin-left: 10px;" onclick="copyText()" type="submit" class="btn btn-primary"><i
class="fa fa-copy"></i></button>
</h4>
</div>
<img src="http://chart.apis.google.com/chart?cht=qr&chl={{ short_url }}&chs=180x180" />
{% endif %}
</div>
</div>
</div>
</body>
</div>
</div>
<script>
function copyText() {
/* Get the text field */
var copyText = document.getElementById("urlgen");

/* Select the text field */
copyText.select();

/* Copy the text inside the text field */
document.execCommand("copy");

/* Alert the copied text */
alert("Copied the text: " + copyText.value);
}
</script>
</body>

</html>
</html>