Skip to content

Commit 4129d39

Browse files
authored
Merge pull request #29 from ilija139/master
Add "save image" button
2 parents f4de629 + c651e0a commit 4129d39

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

static/panes.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ function Pane(id) {
117117
cloneButton.innerHTML = 'o';
118118
cloneButton.title = 'disconnect';
119119

120+
var saveButton = document.createElement('a');
121+
saveButton.innerHTML = '⤓';
122+
saveButton.title = 'save';
123+
saveButton.download = 'untitled_image.jpg';
124+
saveButton.href = '';
125+
120126
var title = document.createElement('div');
121127
title.className = 'title';
122128

@@ -129,12 +135,14 @@ function Pane(id) {
129135
this.grip = grip;
130136
this.title = title;
131137
this.content = content;
138+
this.saveButton = saveButton;
132139

133140
el.appendChild(grip);
134141
el.appendChild(bar);
135142
el.appendChild(content);
136143
bar.appendChild(closeButton);
137144
bar.appendChild(cloneButton);
145+
bar.appendChild(saveButton);
138146
bar.appendChild(title);
139147
body.appendChild(el);
140148

@@ -188,6 +196,7 @@ function Pane(id) {
188196
Pane.prototype = {
189197
setTitle: function(title) {
190198
this.title.innerHTML = title;
199+
this.saveButton.download = title.replace(/\s+/g, '_') + '.jpg';
191200
},
192201

193202
focus: function() {
@@ -481,6 +490,7 @@ ImagePane.prototype = extend(Object.create(Pane.prototype), {
481490
// Hack around unexpected behavior. Setting .src resets .style (except 'position: absolute').
482491
var oldCss = this.content.style.cssText;
483492
this.content.src = content.src;
493+
this.saveButton.href = content.src;
484494
this.content.style.cssText = oldCss;
485495
if (this.content.style.cssText != oldCss) {
486496
this.content.style.cssText = oldCss;

static/style.css

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,19 @@ button {
5656
cursor: pointer;
5757
}
5858

59-
button:hover {
59+
.bar a {
60+
color: black;
61+
text-decoration: none;
62+
font-size: 12px;
63+
line-height: 14px;
64+
}
65+
66+
button:hover, a:hover {
6067
font-weight: bold;
6168
}
6269

63-
.bar button {
70+
71+
.bar button, .bar a {
6472
background: transparent;
6573
margin: 0 4px;
6674
float: left;

0 commit comments

Comments
 (0)