/lenasys/0.1

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/0.1

« back to all changes in this revision

Viewing changes to trunk/svg Converter/SVG_httpAjax.js

  • Committer: gustav.hartvigsson at gmail
  • Date: 2013-04-02 12:13:01 UTC
  • mfrom: (4.2.7 hitlerhorabajs)
  • Revision ID: gustav.hartvigsson@gmail.com-20130402121301-ytfzuo7y6cku9s3o
Merge from implemenation group 2:s branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
                /*--------------------------------------------------------------------------------
3
3
                         AJAX Queue
4
4
                ----------------------------------------------------------------------------------*/            
5
 
 
6
5
                var AJAXQueue = new Array;
7
6
                var AJAXServiceRunning=false;
8
7
                var AJAXReturnfunction;
9
 
 
10
8
                var httpAjax = false;
11
 
 
12
9
                function getSVG(fileName){
13
10
                                paramstr="svgname="+escape(fileName);
14
11
                                AjaxService("SVG_TO_CANVAS_III.php",paramstr,"returnedSVG");
15
12
                }
16
 
                                
 
13
                
17
14
                /*--------------------------------------------------------------------------------
18
15
                                AjaxService
19
16
                                
23
20
                                Each service uses a different url and a different parameter layout.
24
21
                                                                
25
22
                ----------------------------------------------------------------------------------*/
26
 
 
27
 
                function AjaxService(servicename,serviceparam,returnfunction){
28
 
                                                                
29
 
                                AJAXQueue.push(servicename);
30
 
                                AJAXQueue.push(serviceparam);
31
 
                                AJAXQueue.push(returnfunction);
32
 
 
33
 
                                if(!AJAXServiceRunning){
34
 
                                                AJAXServiceRunning=true;
35
 
                                                AJAXReturnfunction=AJAXQueue.pop();
36
 
                                                var Aparam=AJAXQueue.pop();
37
 
                                                var Aservice=AJAXQueue.pop();
38
 
                                                AjaxServiceExec(Aservice,Aparam);
39
 
                                }                               
 
23
                function AjaxService(servicename,serviceparam,returnfunction) {
 
24
                        AJAXQueue.push(servicename);
 
25
                        AJAXQueue.push(serviceparam);
 
26
                        AJAXQueue.push(returnfunction);
 
27
                        if( !AJAXServiceRunning ) {
 
28
                                AJAXServiceRunning = true;
 
29
                                AJAXReturnfunction = AJAXQueue.pop();
 
30
                                var Aparam = AJAXQueue.pop();
 
31
                                var Aservice = AJAXQueue.pop();
 
32
                                AjaxServiceExec( Aservice, Aparam );
 
33
                        }                               
40
34
                }
41
 
 
 
35
                
42
36
                /*--------------------------------------------------------------------------------
43
37
                                AjaxService
44
38
                                
48
42
                                Each service uses a different url and a different parameter layout.
49
43
                                                                
50
44
                ----------------------------------------------------------------------------------*/
51
 
 
52
 
                function AjaxServiceExec(servicename,serviceparam){
53
 
 
54
 
                        // Parameters are set, initiate AJAX engine
55
 
                  if (window.XMLHttpRequest) {
56
 
                        httpAjax = new XMLHttpRequest();
57
 
                    if (httpAjax.overrideMimeType) {
58
 
                        httpAjax.overrideMimeType('text/xml');
59
 
                    }
60
 
                  }else if(window.ActiveXObject){
 
45
                function AjaxServiceExec( servicename, serviceparam ) {
 
46
                // Parameters are set, initiate AJAX engine
 
47
                        if( window.XMLHttpRequest ) {
 
48
                                httpAjax = new XMLHttpRequest();
 
49
                                if( httpAjax.overrideMimeType ) {
 
50
                                        httpAjax.overrideMimeType( 'text/xml' );
 
51
                                }
 
52
                        } else if ( window.ActiveXObject ) {
61
53
                                try{
62
 
                                        httpAjax = new ActiveXObject("Msxml2.XMLHTTP");
63
 
                                                }catch(e){
64
 
                                                        try{
65
 
                                                                httpAjax = new ActiveXObject("Microsoft.XMLHTTP");
66
 
                                }catch(e){
67
 
                                                                alert("Couldn�t build an AJAX instance.");
68
 
                                  return false;
69
 
                                                        }
70
 
                                                }
71
 
                                }
72
 
                                
73
 
                                // Send request to Server and initiate callback.
74
 
                                
75
 
                    try{
76
 
                                        httpAjax.onreadystatechange = getPage;
77
 
                    }catch(e){
78
 
                                        alert("onreadystatechange didn�t go well!");
79
 
                                        return false;
80
 
                                }try{
81
 
                                        httpAjax.open('POST', servicename, true);
82
 
                                  httpAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
83
 
                    }catch(e){
84
 
                                        alert("Couldn�t open url.");
85
 
                      return false;
86
 
                    }try{
87
 
                                                httpAjax.send(serviceparam);                            
88
 
                    }catch(e){
89
 
                                        alert("Couldn�t send request.");
90
 
                                        return false;
91
 
                                }
92
 
                   
93
 
                         return true;
94
 
 
 
54
                                        httpAjax = new ActiveXObject( "Msxml2.XMLHTTP" );
 
55
                                } catch(e) {
 
56
                                        try {
 
57
                                                httpAjax = new ActiveXObject( "Microsoft.XMLHTTP" );
 
58
                                        } catch(e) {
 
59
                                                alert( "Couldn�t build an AJAX instance." );
 
60
                                                return false;
 
61
                                        }
 
62
                                }
 
63
                        }
 
64
                        // Send request to Server and initiate callback.
 
65
                        try{
 
66
                                httpAjax.onreadystatechange = getPage;
 
67
                    } 
 
68
                        catch(e){
 
69
                                alert( "onreadystatechange didn�t go well!" );
 
70
                                return false;
 
71
                        } 
 
72
                        try{
 
73
                                httpAjax.open( 'POST', servicename, true );
 
74
                                httpAjax.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded;" );
 
75
                    } 
 
76
                        catch(e){
 
77
                                alert( "Couldn�t open url." );
 
78
                                return false;
 
79
                    } 
 
80
                        try{
 
81
                                httpAjax.send( serviceparam );                          
 
82
                    } 
 
83
                        catch(e){
 
84
                                alert( "Couldn�t send request." );
 
85
                                return false;
 
86
                        }
 
87
                        return true;
95
88
                }
96
 
 
 
89
                
97
90
                /*--------------------------------------------------------------------------------
98
91
                                getPage
99
92
 
102
95
                                                                
103
96
                ----------------------------------------------------------------------------------*/
104
97
 
105
 
        function getPage() {
106
 
                                        
 
98
        function getPage() {                            
107
99
                if(httpAjax.readyState == 4){
108
 
 
109
 
                                str=httpAjax.responseText;
110
 
                                eval(AJAXReturnfunction+'(str);');
111
 
 
112
 
                                if(AJAXQueue.length>0){
113
 
                                                AJAXReturnfunction=AJAXQueue.pop();
114
 
                                                var Aparam=AJAXQueue.pop();
115
 
                                                var Aservice=AJAXQueue.pop();
116
 
                                                AjaxServiceExec(Aservice,Aparam);
117
 
                                }else{
118
 
                                                AJAXServiceRunning=false;                               
 
100
                        tr = httpAjax.responseText;
 
101
                        eval( AJAXReturnfunction + '(str);' );
 
102
                                if( AJAXQueue.length > 0 ) {
 
103
                                        AJAXReturnfunction = AJAXQueue.pop();
 
104
                                        var Aparam = AJAXQueue.pop();
 
105
                                        var Aservice = AJAXQueue.pop();
 
106
                                        AjaxServiceExec( Aservice, Aparam );
 
107
                                } else {
 
108
                                        AJAXServiceRunning = false;                             
119
109
                                }
120
 
                                                                
121
110
                                return true;                            
122
 
                }else{
 
111
                } else {
123
112
                        // If any other ready state than prepared, do nothing!
124
113
          }
125
114
        }
 
115
        
 
116
        
 
117
        function returnedSVG( htmltext ) {
 
118
                var conto = document.getElementById( 'content' );
 
119
                conto.innerHTML = htmltext;
 
120
                str = 'var acanvas=document.getElementById("previewCanvas");acanvas.width=700;var c=acanvas.getContext("2d");' + htmltext;
 
121
                eval(str);
 
122
        }
126
123