Skip to content

Commit

Permalink
Add "save image" button
Browse files Browse the repository at this point in the history
  • Loading branch information
ili3p committed Sep 24, 2016
1 parent f4de629 commit c651e0a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 10 additions & 0 deletions static/panes.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ function Pane(id) {
cloneButton.innerHTML = 'o';
cloneButton.title = 'disconnect';

var saveButton = document.createElement('a');
saveButton.innerHTML = '⤓';
saveButton.title = 'save';
saveButton.download = 'untitled_image.jpg';
saveButton.href = '';

var title = document.createElement('div');
title.className = 'title';

Expand All @@ -129,12 +135,14 @@ function Pane(id) {
this.grip = grip;
this.title = title;
this.content = content;
this.saveButton = saveButton;

el.appendChild(grip);
el.appendChild(bar);
el.appendChild(content);
bar.appendChild(closeButton);
bar.appendChild(cloneButton);
bar.appendChild(saveButton);
bar.appendChild(title);
body.appendChild(el);

Expand Down Expand Up @@ -188,6 +196,7 @@ function Pane(id) {
Pane.prototype = {
setTitle: function(title) {
this.title.innerHTML = title;
this.saveButton.download = title.replace(/\s+/g, '_') + '.jpg';
},

focus: function() {
Expand Down Expand Up @@ -481,6 +490,7 @@ ImagePane.prototype = extend(Object.create(Pane.prototype), {
// Hack around unexpected behavior. Setting .src resets .style (except 'position: absolute').
var oldCss = this.content.style.cssText;
this.content.src = content.src;
this.saveButton.href = content.src;
this.content.style.cssText = oldCss;
if (this.content.style.cssText != oldCss) {
this.content.style.cssText = oldCss;
Expand Down
12 changes: 10 additions & 2 deletions static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,19 @@ button {
cursor: pointer;
}

button:hover {
.bar a {
color: black;
text-decoration: none;
font-size: 12px;
line-height: 14px;
}

button:hover, a:hover {
font-weight: bold;
}

.bar button {

.bar button, .bar a {
background: transparent;
margin: 0 4px;
float: left;
Expand Down

0 comments on commit c651e0a

Please sign in to comment.