Commits

Miki Tebeka  committed 4905b4c

JS works

  • Participants
  • Parent commits 63e193c

Comments (0)

Files changed (1)

File war/static/site.js

-function on_ready() {
+function on_shortened(short_url) {
+    var url = 'http://' + location.host + '/' + short_url;
+    $('#shortened').html('Shortened to <a href="' + url + '">' + url + '</a>');
 }
 
-$(document).ready(on_ready);
+function on_shorten () {
+    var url = $.trim($('#url').val());
+    if (url.length < 5) {
+        alert("This is not a valid url");
+        $('#url').focus();
+        return;
+    }
+
+    $.post('/shorten', {url: url}, on_shortened);
+}
+
+$(document).ready(function() {
+    $('#shorten').click(on_shorten);
+});