From f4bc27d115de4ecb296577bf9faece8512828f77 Mon Sep 17 00:00:00 2001 From: zuzusik Date: Wed, 9 Apr 2014 11:49:27 +0300 Subject: [PATCH 1/2] CHT - IE9 CORS compatibility - use dojo.request.registry when loading templates --- libs/dojox/jtlc/CHT/loader.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/dojox/jtlc/CHT/loader.js b/libs/dojox/jtlc/CHT/loader.js index 88e652b..c972005 100644 --- a/libs/dojox/jtlc/CHT/loader.js +++ b/libs/dojox/jtlc/CHT/loader.js @@ -12,6 +12,7 @@ dojo.provide( 'dojox.jtlc.CHT.loader' ); dojo.require( 'dojox.jtlc.CHT' ); dojo.require( 'dojo.i18n' ); dojo.require( 'dojo.DeferredList' ); +dojo.require( 'dojo.request.registry' ); dojox.jtlc.CHT.loader = (function() { @@ -43,8 +44,8 @@ dojox.jtlc.CHT.loader = (function() { }, sourceText: function() { - return (d.global.preloadedCHT || {})[this.url()] || - d.xhrGet({ url: this.url(), headers: { "X-Requested-With": null } }); + return (d.global.preloadedCHT || {})[this.url()] + || dojo.request.registry.get(this.url(), {method: 'GET', headers: {'X-Requested-With': null}}); } } ); From df6ca79cf40d167a471e42dcb75053d2b523fdee Mon Sep 17 00:00:00 2001 From: zuzusik Date: Wed, 9 Apr 2014 11:51:28 +0300 Subject: [PATCH 2/2] Ability to intercept adstream.navigator.on chain via addInterceptor method --- libs/adstream/navigator/Controller.js | 24 +++++++++------- libs/adstream/navigator/core.js | 41 ++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/libs/adstream/navigator/Controller.js b/libs/adstream/navigator/Controller.js index 421d7d9..67f09dd 100644 --- a/libs/adstream/navigator/Controller.js +++ b/libs/adstream/navigator/Controller.js @@ -27,16 +27,20 @@ dojo.declare('adstream.navigator.Controller', [dijit._Widget], { var hash = dojo.hash(), mapped = hash && this.mapper( hash ); - if( !mapped ) { - if( adstream.navigator.config.defaultHash ) - dojo.hash( adstream.navigator.config.defaultHash ); // Auto-forward to default hash - } else if( this._lastLoaded !== hash ) { - this._lastLoaded = hash; - dojo.when( - mapped.execute( hash, this.domNode ), - done, done - ); - } + adstream.navigator.core.getInterceptors(hash).then(function(res){ + if( !mapped ) { + if( adstream.navigator.config.defaultHash ) + dojo.hash( adstream.navigator.config.defaultHash ); // Auto-forward to default hash + } else if( this._lastLoaded !== hash ) { + this._lastLoaded = hash; + dojo.when( + mapped.execute( hash, this.domNode ), + done, done + ); + } + }, function(newHash){ + dojo.hash(newHash); + }) function done( result ) { if( result instanceof Error ) diff --git a/libs/adstream/navigator/core.js b/libs/adstream/navigator/core.js index 905930d..b559ecf 100644 --- a/libs/adstream/navigator/core.js +++ b/libs/adstream/navigator/core.js @@ -12,7 +12,8 @@ dojo.require( 'adstream.navigator.util' ); if( !navigator.config ) navigator.config = {}; -var src_map = []; +var src_map = [], + interceptorFunctions = []; adstream.navigator.on = function( pattern ) { var e = new MapEntry( pattern ); @@ -20,6 +21,44 @@ adstream.navigator.on = function( pattern ) { return e; }; +// the interceptor function should return Deffered Object +adstream.navigator.addInterceptor = function(interceptorFunc){ + if (interceptorFunc != null) { + interceptorFunctions.push(interceptorFunc); + } + + return adstream.navigator; +} + +adstream.navigator.core.getInterceptors = function (hash) { + var def = new dojo.Deferred(), + count = 0, + resolveOrContinue = function () { + if (interceptorFunctions.length === count) { + def.resolve(); + } else { + executeFunc(); + } + }, + executeFunc = function () { + var func = interceptorFunctions[count]; + func(hash).then( + function () { + count++; + resolveOrContinue(); + }, + function (errHash) { + console.log(errHash); + def.reject(errHash); + } + ); + }; + + resolveOrContinue(); + + return def; +} + adstream.navigator.core.mapper = function() { var map = {}, src = [];