[enh] Implements 'paste online' helper.

This commit is contained in:
opi 2016-05-06 18:50:12 +02:00
parent 93243f432f
commit 34d775be73
2 changed files with 47 additions and 1 deletions

View file

@ -80,8 +80,11 @@ body {
} }
} }
.btn {
& + .btn {margin-left: 8px;}
}
button { button {
&:extend(.btn); &:extend(.btn all);
} }
.block { .block {
@ -404,6 +407,14 @@ label .list-group-item-text {
font-weight:normal; font-weight:normal;
} }
/* Paste buttons */
button[data-paste-content] {
&:extend(.btn all);
&:extend(.btn-default all);
& + pre {
margin-top: 10px;
}
}
/** Breadcrumb **/ /** Breadcrumb **/

View file

@ -199,6 +199,9 @@
store.set('slide', 'to'); store.set('slide', 'to');
} }
}); });
// Paste <pre> helper
c.prePaste();
// Run callback
callback(); callback();
// Force scrollTop on page load // Force scrollTop on page load
$('html, body').scrollTop(0); $('html, body').scrollTop(0);
@ -236,6 +239,9 @@
} }
} else { } else {
rendered.swap(function(){ rendered.swap(function(){
// Paste <pre> helper
c.prePaste();
// Run callback
callback(); callback();
// Force scrollTop on page load // Force scrollTop on page load
$('html, body').scrollTop(0); $('html, body').scrollTop(0);
@ -373,6 +379,35 @@
return data; return data;
}, },
// Paste <pre>
prePaste: function() {
var pasteButtons = $('button[data-paste-content]');
pasteButtons.on('click', function(){
// Get paste content element
var preElement = $($(this).data('paste-content'));
// Add pacman loader
$('#main').append('<div class="loader loader-content"></div>');
// Send to paste.yunohost.org
$.ajax({
type: "POST",
url: 'https://paste.yunohost.org/documents',
data: preElement[0].innerHTML,
})
.success(function(data, textStatus, jqXHR) {
window.open('https://paste.yunohost.org/' + data.key, '_blank');
})
.fail(function() {
c.flash('fail', y18n.t('paste_error'));
})
.always(function(){
// Remove pacman
$('div.loader').remove();
});
});
}
}); });
})(); })();