@lijuhong1981/jsgif 1.0.10 → 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.
Files changed (2) hide show
  1. package/index.js +15 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -507,7 +507,7 @@ function GifPlayer(options = {}) {
507
507
  return player;
508
508
  }
509
509
 
510
- function loadData(data) {
510
+ function loadData(data, onLoad, onError) {
511
511
  Check.defined('data', data);
512
512
 
513
513
  return new Promise(function (resolve, reject) {
@@ -522,21 +522,32 @@ function GifPlayer(options = {}) {
522
522
  stopGif();
523
523
  if (options.autoPlay)
524
524
  playGif();
525
+ if (typeof onLoad === 'function')
526
+ onLoad(player);
525
527
  resolve(player);
526
528
  } catch (error) {
529
+ if (typeof onError === 'function')
530
+ onError(error);
527
531
  reject(error);
528
532
  }
529
533
  });
530
534
  }
531
535
 
532
536
  // 用xhr请求本地文件
533
- function loadUrl(url, requestOptions) {
537
+ function loadUrl(url, requestOptions, onLoad, onError) {
534
538
  Check.typeOf.string('url', url);
535
539
 
536
540
  return new Promise(function (resolve, reject) {
541
+
542
+ function rejectError() {
543
+ if (typeof onError === 'function')
544
+ onError(error);
545
+ reject(error);
546
+ }
547
+
537
548
  fetchArrayBuffer(url, requestOptions).then(function (arraybuffer) {
538
- loadData(arraybuffer).then(resolve).catch(reject);
539
- }).catch(reject);
549
+ loadData(arraybuffer, onLoad, onError).then(resolve).catch(rejectError);
550
+ }).catch(rejectError);
540
551
  });
541
552
  }
542
553
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lijuhong1981/jsgif",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "> TODO: description",
5
5
  "author": "lijuhong1981",
6
6
  "homepage": "https://github.com/lijuhong1981/jslibs#readme",