source: Dev/trunk/src/client/dojo/request/handlers.js @ 529

Last change on this file since 529 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 1.9 KB
Line 
1define([
2        '../json',
3        '../_base/kernel',
4        '../_base/array',
5        '../has',
6        '../has!dom?../selector/_loader' // only included for has() qsa tests
7], function(JSON, kernel, array, has){
8        has.add('activex', typeof ActiveXObject !== 'undefined');
9        has.add('dom-parser', function(global){
10                return 'DOMParser' in global;
11        });
12
13        var handleXML;
14        if(has('activex')){
15                // GUIDs obtained from http://msdn.microsoft.com/en-us/library/ms757837(VS.85).aspx
16                var dp = [
17                        'Msxml2.DOMDocument.6.0',
18                        'Msxml2.DOMDocument.4.0',
19                        'MSXML2.DOMDocument.3.0',
20                        'MSXML.DOMDocument' // 2.0
21                ];
22
23                handleXML = function(response){
24                        var result = response.data;
25
26                        if(result && has('dom-qsa2.1') && !result.querySelectorAll && has('dom-parser')){
27                                // http://bugs.dojotoolkit.org/ticket/15631
28                                // IE9 supports a CSS3 querySelectorAll implementation, but the DOM implementation
29                                // returned by IE9 xhr.responseXML does not. Manually create the XML DOM to gain
30                                // the fuller-featured implementation and avoid bugs caused by the inconsistency
31                                result = new DOMParser().parseFromString(response.text, 'application/xml');
32                        }
33
34                        if(!result || !result.documentElement){
35                                var text = response.text;
36                                array.some(dp, function(p){
37                                        try{
38                                                var dom = new ActiveXObject(p);
39                                                dom.async = false;
40                                                dom.loadXML(text);
41                                                result = dom;
42                                        }catch(e){ return false; }
43                                        return true;
44                                });
45                        }
46
47                        return result;
48                };
49        }
50
51        var handlers = {
52                'javascript': function(response){
53                        return kernel.eval(response.text || '');
54                },
55                'json': function(response){
56                        return JSON.parse(response.text || null);
57                },
58                'xml': handleXML
59        };
60
61        function handle(response){
62                var handler = handlers[response.options.handleAs];
63
64                response.data = handler ? handler(response) : (response.data || response.text);
65
66                return response;
67        }
68
69        handle.register = function(name, handler){
70                handlers[name] = handler;
71        };
72
73        return handle;
74});
Note: See TracBrowser for help on using the repository browser.