|
1 | 1 | <!DOCTYPE HTML> |
2 | 2 | <!-- |
3 | 3 | /* |
4 | | - * JavaScript Load Image Demo 1.2.1 |
| 4 | + * JavaScript Load Image Demo 1.2.3 |
5 | 5 | * https://github.com/blueimp/JavaScript-Load-Image |
6 | 6 | * |
7 | 7 | * Copyright 2011, Sebastian Tschan |
@@ -70,27 +70,39 @@ <h2>Result</h2> |
70 | 70 | </div> |
71 | 71 | </div> |
72 | 72 | <script src="load-image.min.js"></script> |
73 | | -<!-- jQuery and Bootstrap JS are not required, but included for the demo --> |
| 73 | +<!-- jQuery is not required, but included for the demo --> |
74 | 74 | <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> |
75 | | -<script src="http://blueimp.github.com/cdn/js/bootstrap.min.js"></script> |
76 | 75 | <script> |
77 | | -/*global jQuery, window, document */ |
| 76 | +/*global jQuery, window, document, HTMLCanvasElement */ |
78 | 77 | (function ($) { |
79 | 78 | 'use strict'; |
80 | 79 | var result = $('#result'), |
81 | 80 | load = function (e) { |
82 | 81 | e = e.originalEvent; |
83 | 82 | e.preventDefault(); |
84 | | - window.loadImage( |
85 | | - (e.dataTransfer || e.target).files[0], |
86 | | - function (img) { |
87 | | - result.children().replaceWith(img); |
88 | | - }, |
89 | | - { |
90 | | - maxWidth: result.children().outerWidth(), |
91 | | - canvas: true |
92 | | - } |
93 | | - ); |
| 83 | + if (!window.loadImage( |
| 84 | + (e.dataTransfer || e.target).files[0], |
| 85 | + function (img) { |
| 86 | + if (!(img.src || img instanceof HTMLCanvasElement)) { |
| 87 | + img = $( |
| 88 | + '<span class="label label-important">Error</span>' + |
| 89 | + ' <span>Loading image file failed</span>' |
| 90 | + ); |
| 91 | + } |
| 92 | + result.children().replaceWith(img); |
| 93 | + }, |
| 94 | + { |
| 95 | + maxWidth: result.children().outerWidth(), |
| 96 | + canvas: true |
| 97 | + } |
| 98 | + )) { |
| 99 | + result.children().replaceWith( |
| 100 | + $( |
| 101 | + '<span class="label label-important">Error</span>' + |
| 102 | + ' <span>Your browser does not support the URL or FileReader API.</span>' |
| 103 | + ) |
| 104 | + ); |
| 105 | + } |
94 | 106 | }; |
95 | 107 | $(document) |
96 | 108 | .on('dragover', function (e) { |
|
0 commit comments