|
353 | 353 | <div id="new-comment" class="post-comment"> |
354 | 354 | <h2>New comment</h2> |
355 | 355 | <form autocomplete="off" method="post"> |
356 | | - <p><textarea name="comment" rows="8"></textarea><br><button type="button" data-preview="textarea[name=comment]">Preview</button></p> |
| 356 | + <p> |
| 357 | + <textarea name="comment" rows="8"></textarea><br> |
| 358 | + <button type="button" data-preview="textarea[name=comment]">Preview</button> |
| 359 | + </p> |
357 | 360 | <p><input type="submit" /></p> |
358 | 361 | </form> |
359 | 362 | </div> |
360 | 363 |
|
361 | | -<script> |
362 | | -var cleared = false; |
363 | | -[].forEach.call(document.querySelectorAll('img[data-attachment][data-src]'), function(img) { |
364 | | - var id = img.dataset.attachment; |
365 | | - var context = img.dataset.context || 'unknown'; |
366 | | - |
367 | | - // Clean up cache |
368 | | - if ( !cleared ) { |
369 | | - cleared = true; |
370 | | - for ( var name in localStorage ) { |
371 | | - if ( /^attachment_/.test(name) ) { |
372 | | - var time = Number(localStorage[name].substr(0, 13)); |
373 | | - if ( !time || isNaN(time) || time < Date.now() - 30*86400*1000 ) { |
374 | | - console.log('Purging', name); |
375 | | - delete localStorage[name]; |
376 | | - } |
377 | | - } |
378 | | - } |
379 | | - } |
380 | | - |
381 | | - // Load from cache |
382 | | - var uri = localStorage['attachment_' + id + '_' + context]; |
383 | | - if ( uri ) { |
384 | | - console.log(id, context, 'Using Data URI for localStorage'); |
385 | | - img.src = uri.substr(13); |
386 | | - } |
387 | | - |
388 | | - // Load live and store in cache, maybe |
389 | | - else { |
390 | | - console.log(id, context, 'Using live URL...'); |
391 | | - img.src = img.dataset.src; |
392 | | - img.onload = function(e) { |
393 | | - console.log(id, context, 'Image loaded, saving into localStorage...'); |
394 | | - |
395 | | - var canvas = document.createElement('canvas'); |
396 | | - canvas.width = img.width; |
397 | | - canvas.height = img.height; |
398 | | - var ctx = canvas.getContext('2d'); |
399 | | - ctx.drawImage(img, 0, 0); |
400 | | - var data = canvas.toDataURL('image/png'); |
401 | | - |
402 | | - try { |
403 | | - if ( data.length < 20000 ) { |
404 | | - localStorage['attachment_' + id + '_' + context] = String(Date.now()) + data; |
405 | | - console.log(id, context, 'Image saved: ' + Math.round(data.length/1024) + ' kb'); |
406 | | - } |
407 | | - else { |
408 | | - console.log(id, context, 'Image not saved: ' + Math.round(data.length/1024) + ' kb is too big'); |
409 | | - } |
410 | | - } |
411 | | - catch (ex) { |
412 | | - alert("Couldn't save image in localStorage. Full?"); |
413 | | - alert("Error:\n\n" + ex.message); |
414 | | - } |
415 | | - }; |
416 | | - } |
417 | | -}); |
418 | | -</script> |
419 | | - |
420 | 364 | <?php |
421 | 365 |
|
422 | 366 | if ( isset($_GET['debug']) ) { |
|
0 commit comments