@lijuhong1981/jsgif 1.0.9 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +17 -5
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -467,10 +467,11 @@ function GifPlayer(options = {}) {
|
|
|
467
467
|
if (typeof options.onFrameChanged === 'function') {
|
|
468
468
|
options.onFrameChanged(currentFrameIndex, frame);
|
|
469
469
|
}
|
|
470
|
+
return frame;
|
|
470
471
|
}
|
|
471
472
|
|
|
472
473
|
function doFrame() {
|
|
473
|
-
drawCurrentFrame();
|
|
474
|
+
const frame = drawCurrentFrame();
|
|
474
475
|
setTimeout(function () {
|
|
475
476
|
if (!isPlaying)
|
|
476
477
|
return;
|
|
@@ -506,7 +507,7 @@ function GifPlayer(options = {}) {
|
|
|
506
507
|
return player;
|
|
507
508
|
}
|
|
508
509
|
|
|
509
|
-
function loadData(data) {
|
|
510
|
+
function loadData(data, onLoad, onError) {
|
|
510
511
|
Check.defined('data', data);
|
|
511
512
|
|
|
512
513
|
return new Promise(function (resolve, reject) {
|
|
@@ -521,21 +522,32 @@ function GifPlayer(options = {}) {
|
|
|
521
522
|
stopGif();
|
|
522
523
|
if (options.autoPlay)
|
|
523
524
|
playGif();
|
|
525
|
+
if (typeof onLoad === 'function')
|
|
526
|
+
onLoad(player);
|
|
524
527
|
resolve(player);
|
|
525
528
|
} catch (error) {
|
|
529
|
+
if (typeof onError === 'function')
|
|
530
|
+
onError(error);
|
|
526
531
|
reject(error);
|
|
527
532
|
}
|
|
528
533
|
});
|
|
529
534
|
}
|
|
530
535
|
|
|
531
536
|
// 用xhr请求本地文件
|
|
532
|
-
function loadUrl(url, requestOptions) {
|
|
537
|
+
function loadUrl(url, requestOptions, onLoad, onError) {
|
|
533
538
|
Check.typeOf.string('url', url);
|
|
534
539
|
|
|
535
540
|
return new Promise(function (resolve, reject) {
|
|
541
|
+
|
|
542
|
+
function rejectError() {
|
|
543
|
+
if (typeof onError === 'function')
|
|
544
|
+
onError(error);
|
|
545
|
+
reject(error);
|
|
546
|
+
}
|
|
547
|
+
|
|
536
548
|
fetchArrayBuffer(url, requestOptions).then(function (arraybuffer) {
|
|
537
|
-
loadData(arraybuffer).then(resolve).catch(
|
|
538
|
-
}).catch(
|
|
549
|
+
loadData(arraybuffer, onLoad, onError).then(resolve).catch(rejectError);
|
|
550
|
+
}).catch(rejectError);
|
|
539
551
|
});
|
|
540
552
|
}
|
|
541
553
|
|