-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
27 lines (21 loc) · 873 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module.exports = function (config) {
self = this;
// Insert a new url
$(".btn-insert").on("click", function() {
var longUrl = $("#long-url").val().trim();
self.link("insert", { "data": longUrl }, function(err, url) {
if (err) { return alert("ERROR: " + JSON.stringify(err)); }
console.log(longUrl.length);
alert("Copy this code: " + url + "\n" +
"This will redirect you to your long url: " +
(longUrl.length > 20 ? longUrl.substring(0, 10) + "..." + longUrl.substring(longUrl.length - 5) : longUrl));
});
});
// Go to url
$(".btn-get").on("click", function() {
var urlCode = $("#short-url").val().trim();
self.link("get", { "data": urlCode }, function(err, url) {
window.location = url;
});
});
}