summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2016-05-28 11:42:09 +0200
committerYorhel <git@yorhel.nl>2016-05-28 11:42:09 +0200
commit9df7ea36431064c9a6db04b4a5a1444b9511e1be (patch)
tree02bc6554f2a4501956e8f1e95dfe5a1a1a1acb80
parentd8822b4f11cf8329f556baa2c39449674342afb6 (diff)
Add "copy" button to pastes
-rwxr-xr-xindex.cgi23
-rw-r--r--script.js18
2 files changed, 27 insertions, 14 deletions
diff --git a/index.cgi b/index.cgi
index bea8ef2..ca7bc09 100755
--- a/index.cgi
+++ b/index.cgi
@@ -24,6 +24,7 @@ my $codematch = qr/([a-z0-9]{5}|[a-zA-Z0-9\.-]{32})/;
TUWF::register(
qr// => \&home,
qr/mypastes/ => \&mypastes,
+ qr/copy\/$codematch/ => \&home,
qr/$codematch\.txt/ => \&raw,
qr/$codematch/ => \&paste,
);
@@ -98,12 +99,12 @@ sub upload {
sub home {
- my $self = shift;
+ my($self, $copy) = @_;
# upload form
if($self->reqMethod() ne 'POST') {
$self->htmlHeader('mypastes');
- $self->htmlUploadForm;
+ $self->htmlUploadForm($copy);
$self->htmlFooter;
return;
}
@@ -275,6 +276,8 @@ sub htmlHeader {
a href => '#', onclick => "return unpaste('/$$_')", 'unpaste';
txt ' ';
a href => "/$$_.txt", 'raw';
+ txt ' ';
+ a href => "/copy/$$_", 'copy';
} else {
/newpaste/ && a href => '/', 'new paste';
/mypastes/ && a href => '#', onclick => 'return mypastes()', 'my pastes';
@@ -297,7 +300,13 @@ sub htmlFooter {
sub htmlUploadForm {
- my $self = shift;
+ my($self, $copy) = @_;
+
+ my $r = $copy
+ ? $self->getpaste($copy, 'raw, wrap, parse_urls, syntax')
+ : { raw => '', wrap => 0, parse_urls => 1, syntax => 'nosyntax' };
+ return if !ref $r;
+
use utf8;
Tr;
td class => 'ff', '';
@@ -306,7 +315,7 @@ sub htmlUploadForm {
fieldset;
legend '▾ Contents';
- textarea name => 'f', id => 'f', '';
+ textarea name => 'f', id => 'f', $r->{raw};
br;
input type => 'submit', value => 'Submit', id => 'submit';
txt '-or- ';
@@ -317,17 +326,17 @@ sub htmlUploadForm {
fieldset;
legend '▾ Options';
a href => '#', id => 'formatsave', 'save as default';
- input type => 'checkbox', class => 'check', id => 'w', name => 'w', value => 1;
+ input type => 'checkbox', class => 'check', id => 'w', name => 'w', value => 1, $r->{wrap} ? (checked => 'checked') : ();
label for => 'w', ' allow line wrapping';
br;
- input type => 'checkbox', class => 'check', id => 'c', name => 'c', value => 1, checked => 'checked';
+ input type => 'checkbox', class => 'check', id => 'c', name => 'c', value => 1, $r->{parse_urls} ? (checked => 'checked') : ();
label for => 'c', ' make URLs clickable';
br;
input type => 'checkbox', class => 'check', id => 'l', name => 'l', value => 1;
label for => 'l', ' secure but ugly URL';
br;
i 'Syntax highlighting: ';
- input type => 'text', name => 's', id => 's', size => 10, value => 'nosyntax';
+ input type => 'text', name => 's', id => 's', size => 10, value => $r->{syntax};
i;
txt ' Popular: ';
b class => 'syntax';
diff --git a/script.js b/script.js
index c64ba81..748493f 100644
--- a/script.js
+++ b/script.js
@@ -120,19 +120,23 @@ if(x) {
return v;
}
};
+ var setclass = function() {
+ x.className = w.checked==v[0] && c.checked==v[1] && s.value==v[2] && l.checked==v[3] ? '' : 'notdef';
+ };
var v = def();
- w.checked = v[0];
- c.checked = v[1];
- s.value = v[2];
+ if(!byId('p').value) { // Don't apply some settings when copying another paste
+ w.checked = v[0];
+ c.checked = v[1];
+ s.value = v[2];
+ }
l.checked = v[3];
x.onclick = function() {
- x.className = '';
setCookie('formatdef', (w.checked ? '1' : '0')+','+(c.checked ? '1' : '0')+','+s.value+','+(l.checked ? '1' : '0'));
v = def();
+ setclass();
return false;
};
- w.onclick = c.onclick = l.onclick = s.onkeyup = s.onfocus = function() {
- x.className = w.checked==v[0] && c.checked==v[1] && s.value==v[2] && l.checked==v[3] ? '' : 'notdef';
- }
+ w.onclick = c.onclick = l.onclick = s.onkeyup = s.onfocus = setclass;
+ setclass();
}