|
1 | | -;(function(angular, duoshuo, API, configs, NProgress) { |
| 1 | +;(function(angular, NProgress) { |
2 | 2 |
|
3 | 3 | 'use strict'; |
4 | 4 |
|
5 | 5 | if (!angular) throw new Error('angular.js required!'); |
6 | | - if (!duoshuo) throw new Error('duoshuo embed.js required!'); |
7 | | - if (!API) throw new Error('duoshuo embed.js must be unstable version!'); |
8 | | - if (!configs) throw new Error('duoshuoQuery object required!'); |
9 | | - if (!configs.short_name) throw new Error('duoshuo short_name required!'); |
10 | | - |
11 | | - var NProgressExist = NProgress && NProgress.start && NProgress.stop; |
| 6 | + var NProgressExist = NProgress && NProgress.start && NProgress.done; |
12 | 7 |
|
13 | 8 | angular.module('duoshuo', []) |
14 | 9 | .service('$duoshuo', function($rootScope) { |
|
17 | 12 | // lowlevel api set |
18 | 13 | angular.forEach(['get', 'post', 'ajax'], function(method) { |
19 | 14 | self[method] = function(endpoint, data, callback, skipCheck) { |
| 15 | + if (!window.DUOSHUO) throw new Error('duoshuo embed.js required!'); |
| 16 | + var API = window.DUOSHUO.API; |
| 17 | + if (!API) throw new Error('duoshuo embed.js must be unstable version!'); |
20 | 18 | if (NProgressExist) NProgress.start(); |
21 | 19 | return API[method](endpoint, data, function(d) { |
22 | | - if (NProgressExist) NProgress.stop(); |
| 20 | + if (NProgressExist) NProgress.done(); |
23 | 21 | callback(d); |
24 | 22 | if (!skipCheck) $rootScope.$apply(); |
25 | 23 | return; |
|
33 | 31 | return callback(new Error('event not found')); |
34 | 32 | var e = eve; |
35 | 33 | if (e === 'ready') e = 'reset'; |
36 | | - return DUOSHUO.visitor.on(e, function() { |
| 34 | + return window.DUOSHUO.visitor.on(e, function() { |
37 | 35 | var self = this; |
38 | 36 | var data = this.data; |
39 | 37 | callback(null, data, self); |
|
43 | 41 | }; |
44 | 42 | }); |
45 | 43 |
|
46 | | -})( |
47 | | - window.angular, |
48 | | - window.DUOSHUO, |
49 | | - window.DUOSHUO.API, |
50 | | - window.duoshuoQuery, |
51 | | - window.NProgress |
52 | | -); |
| 44 | +})(window.angular, window.NProgress); |
0 commit comments