/lenasys/0.1

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/0.1
1 by Henrik G.
First seed of Lenasys ... Needs to be Organized Further
1
		/*--------------------------------------------------------------------------------
2
			 AJAX Queue
3
		----------------------------------------------------------------------------------*/		
4
		var AJAXQueue = new Array;
5
		var AJAXServiceRunning=false;
6
		var AJAXReturnfunction;
7
		var httpAjax = false;
8
		function getSVG(fileName) {
9.1.1 by a11vikob
Changed directory structure of SVG-converter.
9
			paramstr="svgname="+escape(fileName);
10
			AjaxService("svgtocanvas.php",paramstr,"returnedSVG");
11
		}
1 by Henrik G.
First seed of Lenasys ... Needs to be Organized Further
12
		
4.5.2 by mattman-03
Städat färdigt
13
		/*--------------------------------------------------------------------------------
1 by Henrik G.
First seed of Lenasys ... Needs to be Organized Further
14
				AjaxService
15
				
16
				This is the only interface to the AJAX wrapper. This makes the ajax service 
17
				browser agnostic and provides a single interface for all of the services.
18
				
19
				Each service uses a different url and a different parameter layout.
20
								
21
		----------------------------------------------------------------------------------*/
22
		function AjaxService(servicename,serviceparam,returnfunction) {
4.5.2 by mattman-03
Städat färdigt
23
			AJAXQueue.push(servicename);
24
			AJAXQueue.push(serviceparam);
25
			AJAXQueue.push(returnfunction);
26
			if( !AJAXServiceRunning ) {
27
				AJAXServiceRunning = true;
28
				AJAXReturnfunction = AJAXQueue.pop();
29
				var Aparam = AJAXQueue.pop();
30
				var Aservice = AJAXQueue.pop();
31
				AjaxServiceExec( Aservice, Aparam );
32
			}				
33
		}
1 by Henrik G.
First seed of Lenasys ... Needs to be Organized Further
34
		
4.5.2 by mattman-03
Städat färdigt
35
		/*--------------------------------------------------------------------------------
1 by Henrik G.
First seed of Lenasys ... Needs to be Organized Further
36
				AjaxService
37
				
38
				This is the only interface to the AJAX wrapper. This makes the ajax service 
39
				browser agnostic and provides a single interface for all of the services.
40
				
41
				Each service uses a different url and a different parameter layout.
42
								
43
		----------------------------------------------------------------------------------*/
44
		function AjaxServiceExec(servicename, serviceparam) {
9.1.1 by a11vikob
Changed directory structure of SVG-converter.
45
		// Parameters are set, initiate AJAX engine
4.5.2 by mattman-03
Städat färdigt
46
			if( window.XMLHttpRequest ) {
47
				httpAjax = new XMLHttpRequest();
48
				if( httpAjax.overrideMimeType ) {
49
					httpAjax.overrideMimeType( 'text/xml' );
50
				}
51
			} else if ( window.ActiveXObject ) {
52
				try{
1 by Henrik G.
First seed of Lenasys ... Needs to be Organized Further
53
					httpAjax = new ActiveXObject( "Msxml2.XMLHTTP" );
4.5.2 by mattman-03
Städat färdigt
54
				} catch(e) {
55
					try {
56
						httpAjax = new ActiveXObject( "Microsoft.XMLHTTP" );
57
					} catch(e) {
58
						alert( "CouldnŽt build an AJAX instance." );
59
						return false;
60
					}
61
				}
62
			}
63
			// Send request to Server and initiate callback.
64
			try{
65
				httpAjax.onreadystatechange = getPage;
66
		    } 
67
			catch(e) {
9.1.1 by a11vikob
Changed directory structure of SVG-converter.
68
				alert( "onreadystatechange didnŽt go well!" );
4.5.2 by mattman-03
Städat färdigt
69
				return false;
70
			} 
71
			try{
72
				httpAjax.open( 'POST', servicename, true );
73
				httpAjax.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded;" );
74
		    } 
75
			catch(e) {
9.1.1 by a11vikob
Changed directory structure of SVG-converter.
76
				alert( "CouldnŽt open url." );
4.5.2 by mattman-03
Städat färdigt
77
				return false;
78
		    } 
79
			try{
80
				httpAjax.send( serviceparam );				
81
		    } 
82
			catch(e) {
9.1.1 by a11vikob
Changed directory structure of SVG-converter.
83
				alert( "CouldnŽt send request." );
4.5.2 by mattman-03
Städat färdigt
84
				return false;
85
			}
86
			return true;
87
		}
1 by Henrik G.
First seed of Lenasys ... Needs to be Organized Further
88
		
4.5.2 by mattman-03
Städat färdigt
89
		/*--------------------------------------------------------------------------------
1 by Henrik G.
First seed of Lenasys ... Needs to be Organized Further
90
				getPage
91
92
				This is the AJAX callback function. It detects the invoking service and handles
93
				the reply from each service accordingly.				
94
								
95
		----------------------------------------------------------------------------------*/
96
97
	function getPage() {				
4.5.2 by mattman-03
Städat färdigt
98
		if(httpAjax.readyState == 4) {
9.1.1 by a11vikob
Changed directory structure of SVG-converter.
99
			tr = httpAjax.responseText;
4.5.2 by mattman-03
Städat färdigt
100
			eval( AJAXReturnfunction + '(tr);' );
9.1.1 by a11vikob
Changed directory structure of SVG-converter.
101
				if( AJAXQueue.length > 0 ) {
4.5.2 by mattman-03
Städat färdigt
102
					AJAXReturnfunction = AJAXQueue.pop();
103
					var Aparam = AJAXQueue.pop();
104
					var Aservice = AJAXQueue.pop();
105
					AjaxServiceExec( Aservice, Aparam );
106
				} else {
107
					AJAXServiceRunning = false;				
108
				}
1 by Henrik G.
First seed of Lenasys ... Needs to be Organized Further
109
				return true;				
110
		} else {
4.11.2 by a11patfr at his
Fixed formatting. trunk/svg Converter/SVG_httpAjax.js
111
	  		// If any other ready state than prepared, do nothing!
1 by Henrik G.
First seed of Lenasys ... Needs to be Organized Further
112
	  }
113
	}
114
	
4.5.2 by mattman-03
Städat färdigt
115
	
116
	function returnedSVG( htmltext ) {
117
		var conto = document.getElementById( 'content' );
118
		conto.innerHTML = htmltext;
119
		str = 'var acanvas=document.getElementById("previewCanvas");acanvas.width=700;var c=acanvas.getContext("2d");' + htmltext;
120
		eval(str);
121
	}
122
1 by Henrik G.
First seed of Lenasys ... Needs to be Organized Further
123