image_upload.js 834 B

12345678910111213141516171819202122232425262728
  1. /* vim: set expandtab sw=4 ts=4 sts=4: */
  2. /**
  3. * Image upload transformations plugin js
  4. *
  5. * @package PhpMyAdmin
  6. */
  7. AJAX.registerOnload('transformations/image_upload.js', function () {
  8. // Change thumbnail when image file is selected
  9. // through file upload dialog
  10. $('input.image-upload').on('change', function (event) {
  11. if (this.files && this.files[0]) {
  12. var reader = new FileReader();
  13. var $input = $(this);
  14. reader.onload = function (e) {
  15. $input.prevAll('img').attr('src', e.target.result);
  16. };
  17. reader.readAsDataURL(this.files[0]);
  18. }
  19. });
  20. });
  21. /**
  22. * Unbind all event handlers before tearing down a page
  23. */
  24. AJAX.registerTeardown('transformations/image_upload.js', function () {
  25. $('input.image-upload').off('change');
  26. });