From 457e9d4d26a96491e325fc28e566bf5fc4c41660 Mon Sep 17 00:00:00 2001
From: Ziirish
Date: Mon, 25 Feb 2013 16:45:14 +0100
Subject: [PATCH] add: shorten url option using a local service
---
css/zerobin.css | 2 +-
js/zerobin.js | 32 ++++++++++++++++++++++++++++++--
tpl/page.html | 5 +++++
3 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/css/zerobin.css b/css/zerobin.css
index 29418263..a17821d1 100644
--- a/css/zerobin.css
+++ b/css/zerobin.css
@@ -164,7 +164,7 @@ position:relative;
top:2px;
}
-div#expiration, div#rawtextbutton, div#burnafterreadingoption, div#opendisc, div#syntaxcoloringoption {
+div#expiration, div#rawtextbutton, div#burnafterreadingoption, div#opendisc, div#syntaxcoloringoption, div#urlshorteneroption {
background-color:#414D5A;
padding:6px 8px;
margin:0px 5px 0px 0px;;
diff --git a/js/zerobin.js b/js/zerobin.js
index c6952420..3edbc514 100644
--- a/js/zerobin.js
+++ b/js/zerobin.js
@@ -317,6 +317,26 @@ function send_comment(parentid) {
});
}
+/**
+ * Shorten URL via a webservice
+ */
+function shortenUrl(url)
+{
+ // replace with your webservice URL
+ $.get ('/shortapi.php',
+ { url: url
+ /* shortener options */ }
+ )
+ .error(function() {
+ showError('Data could not be sent (webservice error).');
+ })
+ .success(function(data) {
+ var shorten = data;
+ $('div#shortenlink').html('Short URL is ' + shorten + ' (Hit CTRL+C to copy)');
+ $('div#shortenlink').show();
+ selectText('shorturl');
+ });
+}
/**
* Send a new paste to server
@@ -356,10 +376,11 @@ function send_data() {
var deleteUrl = scriptLocation() + "?pasteid=" + data.id + '&deletetoken=' + data.deletetoken;
showStatus('');
- $('div#pastelink').html('Your paste is ' + url + ' (Hit CTRL+C to copy)');
+ var hint = $('input#urlshortener').is(':checked') ? '' : ' (Hit CTRL+C to copy)';
+
+ $('div#pastelink').html('Your paste is ' + url + '' + hint);
$('div#deletelink').html('Delete link');
$('div#pasteresult').show();
- selectText('pasteurl'); // We pre-select the link so that the user only has to CTRL+C the link.
setElementText($('div#cleartext'), $('textarea#message').val());
urls2links($('div#cleartext'));
@@ -367,6 +388,11 @@ function send_data() {
// FIXME: Add option to remove syntax highlighting ?
if ($('input#syntaxcoloring').is(':checked')) applySyntaxColoring();
+ if ($('input#urlshortener').is(':checked'))
+ shortenUrl(url);
+ else
+ selectText('pasteurl'); // We pre-select the link so that the user only has to CTRL+C the link.
+
showStatus('');
}
else if (data.status==1) {
@@ -412,6 +438,7 @@ function stateNewPaste() {
$('div#burnafterreadingoption').show();
$('div#opendisc').show();
$('div#syntaxcoloringoption').show();
+ $('div#urlshorteneroption').show();
$('button#newbutton').show();
$('div#pasteresult').hide();
$('textarea#message').text('');
@@ -440,6 +467,7 @@ function stateExistingPaste() {
$('div#burnafterreadingoption').hide();
$('div#opendisc').hide();
$('div#syntaxcoloringoption').hide();
+ $('div#urlshorteneroption').hide();
$('button#newbutton').show();
$('div#pasteresult').hide();
$('textarea#message').hide();
diff --git a/tpl/page.html b/tpl/page.html
index 5499847f..74ef54d5 100644
--- a/tpl/page.html
+++ b/tpl/page.html
@@ -72,10 +72,15 @@ {$VERSION}
+
+
+
+