diff --git a/code/hooks.js b/code/hooks.js index e0633691..629c5ff3 100644 --- a/code/hooks.js +++ b/code/hooks.js @@ -43,7 +43,8 @@ // array [GUID, time, details]. Plugin can manipulate the // array to change order or add additional values to the // details of a portal. -// requestFinished: called after each request finished. Argument is +// requestFinished: DEPRECATED: best to use mapDataRefreshEnd instead +// called after each map data request finished. Argument is // {success: boolean} indicated the request success or fail. // iitcLoaded: called after IITC and all plugins loaded @@ -72,7 +73,11 @@ window.runHooks = function(event, data) { window.addHook = function(event, callback) { - if(VALID_HOOKS.indexOf(event) === -1) throw('Unknown event type: ' + event); + if(VALID_HOOKS.indexOf(event) === -1) { + console.error('addHook: Unknown event type: ' + event + ' - ignoring'); + return; + } + if(typeof callback !== 'function') throw('Callback must be a function.'); if(!_hooks[event]) diff --git a/code/map_data_request.js b/code/map_data_request.js index 4c839407..3b37eb1b 100644 --- a/code/map_data_request.js +++ b/code/map_data_request.js @@ -368,6 +368,9 @@ window.MapDataRequest.prototype.handleResponse = function (data, tiles, success) var id = tiles[i]; this.requeueTile(id, true); } + + window.runHooks('requestFinished', {success: false}); + } else { // TODO: use result.minLevelOfDetail ??? stock site doesn't use it yet... @@ -407,6 +410,8 @@ window.MapDataRequest.prototype.handleResponse = function (data, tiles, success) } } + + window.runHooks('requestFinished', {success: true}); } this.processRequestQueue();