Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ var WWW = (function(undefined) {
$('#uuid').val(uuid);
}

function set_content(data, xhr) {
function set_content(data, xhr, id) {

if (xhr.getResponseHeader('etag') == null) {
try {
Expand All @@ -229,6 +229,18 @@ var WWW = (function(undefined) {
if (ct.startsWith("text/")) {
$('#content').val(data);
return;
} else if (ct.startsWith("image/")) {
var link = $('<a></a>')
.attr('href', 'https://ptpb.pw/' + id)
.attr('target', '_blank')
.attr('title', 'Opens in a new window');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating elements on the fly is ok, but when they contain several attributes like this that have the same value, I feel like copying from a pre-made <a> in #stash is better.


var img = $('<img></img>')
.attr('src', 'https://ptpb.pw/' + id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ehh. I'd rather re-use baseurl from API, instead of hard-coding it here.

.attr('height', '10%')
.attr('width', '30%');

alert_new().append(alert_title('image loaded', $(link).append(img)));
} else {
alert_new().append(alert_title('status', 'cowardly refusing to display C-T: ' + ct));
}
Expand Down Expand Up @@ -354,7 +366,7 @@ $(function() {

spinner.removeClass('hidden');
api.paste.get(id).done(function(data, status, xhr) {
app.set_content(data, xhr);
app.set_content(data, xhr, id);
spinner.addClass('hidden');
});

Expand Down