|
71 | 71 | }); |
72 | 72 | }); |
73 | 73 |
|
| 74 | + window.addEventListener('unload', function() { |
| 75 | + _this.savePosition(); |
| 76 | + }); |
| 77 | + |
74 | 78 | this.restorePosition(); |
75 | 79 | }; |
76 | 80 |
|
|
119 | 123 | this.elem.classList.remove(Panel.FLOAT); |
120 | 124 | this.elem.classList.add(Panel.PEEK); |
121 | 125 | this.elem.style.display = 'none'; |
122 | | - localStorage.removeItem(this.id); // delete position |
123 | 126 | }; |
124 | 127 |
|
125 | 128 | Panel.prototype.toWindow = function() { |
|
159 | 162 | } |
160 | 163 | }); |
161 | 164 |
|
162 | | - localStorage.setItem(this.id, JSON.stringify({window: true})); |
163 | 165 | this.elem.style.display = 'none'; |
164 | 166 | this.elem.classList.remove(Panel.FLOAT); |
165 | 167 | this.elem.classList.remove(Panel.PEEK); |
|
168 | 170 | }; |
169 | 171 |
|
170 | 172 | Panel.prototype.reposition = function() { |
171 | | - if (!this.is(Panel.WINDOW)) { |
172 | | - var pos = getPosition(this.elem); |
173 | | - if (pos.width) { // is visible? |
174 | | - setPosition(this.elem, {right: pos.right, bottom: pos.bottom}); |
175 | | - localStorage.setItem(this.id, JSON.stringify({right: pos.right, bottom: pos.bottom})); |
176 | | - } |
| 173 | + var pos = getPosition(this.elem); |
| 174 | + if (pos.width) { // is visible? |
| 175 | + setPosition(this.elem, {right: pos.right, bottom: pos.bottom}); |
177 | 176 | } |
178 | 177 | }; |
179 | 178 |
|
|
184 | 183 | coords.bottom = Math.min(Math.max(coords.bottom, -0.2 * el.offsetHeight), height - el.offsetHeight); |
185 | 184 | }; |
186 | 185 |
|
| 186 | + Panel.prototype.savePosition = function() { |
| 187 | + var pos = getPosition(this.elem); |
| 188 | + if (this.is(Panel.WINDOW)) { |
| 189 | + localStorage.setItem(this.id, JSON.stringify({window: true})); |
| 190 | + } else if (pos.width) { |
| 191 | + localStorage.setItem(this.id, JSON.stringify({right: pos.right, bottom: pos.bottom})); |
| 192 | + } else { |
| 193 | + localStorage.removeItem(this.id); |
| 194 | + } |
| 195 | + }; |
| 196 | + |
187 | 197 | Panel.prototype.restorePosition = function() { |
188 | 198 | var pos = JSON.parse(localStorage.getItem(this.id)); |
189 | 199 | if (!pos) { |
|
213 | 223 | draggable(elem, { |
214 | 224 | rightEdge: true, |
215 | 225 | bottomEdge: true, |
216 | | - draggedClass: 'tracy-dragged', |
217 | | - stop: function() { |
218 | | - _this.savePosition(); |
219 | | - } |
| 226 | + draggedClass: 'tracy-dragged' |
220 | 227 | }); |
221 | 228 |
|
222 | 229 | [].forEach.call(elem.querySelectorAll('a'), function(a) { |
|
239 | 246 | right: getPosition(panel.elem).right + Math.round(Math.random() * 100) + 20, |
240 | 247 | bottom: getPosition(panel.elem).bottom + Math.round(Math.random() * 100) + 20 |
241 | 248 | }); |
242 | | - panel.reposition(); |
243 | 249 | } |
244 | 250 | } |
245 | 251 | e.preventDefault(); |
|
267 | 273 | }); |
268 | 274 | }); |
269 | 275 |
|
| 276 | + window.addEventListener('unload', function() { |
| 277 | + _this.savePosition(); |
| 278 | + }); |
| 279 | + |
270 | 280 | this.restorePosition(); |
271 | 281 | }; |
272 | 282 |
|
|
0 commit comments