1 | ( function( ) |
---|
2 | { |
---|
3 | var _connector = new XConnector; |
---|
4 | var _script = null; |
---|
5 | |
---|
6 | var _container = null; |
---|
7 | var _divAppboxHeader = null; |
---|
8 | var _loading = new Image( ); |
---|
9 | _loading.src = URL_SERVER + 'phpgwapi/images/loading.gif'; |
---|
10 | |
---|
11 | function _handler( data ) |
---|
12 | { |
---|
13 | var js = data.match( /<script[^>]*>.*?<\/script>/g ); |
---|
14 | var _new_scripts = [ ]; |
---|
15 | if ( js ) |
---|
16 | { |
---|
17 | var tag = /<script([^>]* src="(\S+)"|[^>]*)>(.*?)<\/script>/; |
---|
18 | for ( var i = 0; i < js.length; i++ ) |
---|
19 | { |
---|
20 | var type = tag.exec( js[ i ] ); |
---|
21 | data = data.replace( "\n\t\t" + type[ 0 ], '' ); |
---|
22 | _new_scripts[ _new_scripts.length ] = type; |
---|
23 | } |
---|
24 | } |
---|
25 | |
---|
26 | var el = document.createElement( 'div' ); |
---|
27 | el.innerHTML = data; |
---|
28 | |
---|
29 | var _links = el.getElementsByTagName( 'a' ); |
---|
30 | for ( var i = 0; i < _links.length; i++ ) |
---|
31 | handler( _links.item( i ) ); |
---|
32 | |
---|
33 | _container.innerHTML = ''; |
---|
34 | while ( el.hasChildNodes( ) ) |
---|
35 | _container.appendChild( el.firstChild ); |
---|
36 | |
---|
37 | var _count = 0; |
---|
38 | function _scripts( ) |
---|
39 | { |
---|
40 | if ( _new_scripts[ _count ][ 2 ] == undefined || _new_scripts[ _count ][ 2 ].length == 0 ) |
---|
41 | _script.load( function( ) |
---|
42 | { |
---|
43 | if ( ++_count < _new_scripts.length ) |
---|
44 | _scripts( ); |
---|
45 | }, _new_scripts[ _count ][ 3 ] ); |
---|
46 | else |
---|
47 | { |
---|
48 | _script.add( |
---|
49 | _new_scripts[ _count ][ 2 ].substr( |
---|
50 | URL_SERVER.length - 1, |
---|
51 | _new_scripts[ _count ][ 2 ].length - URL_SERVER.length + 1 - ( |
---|
52 | ( _new_scripts[ _count ][ 2 ].indexOf( '?' ) < 0 ) ? |
---|
53 | 0 : ( _new_scripts[ _count ][ 2 ].length - _new_scripts[ _count ][ 2 ].indexOf( '?' ) ) |
---|
54 | ) |
---|
55 | ) |
---|
56 | ); |
---|
57 | if ( ++_count < _new_scripts.length ) |
---|
58 | _scripts( ); |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | if ( _new_scripts.length ) |
---|
63 | { |
---|
64 | _scripts( ); |
---|
65 | _script.load( ); |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | function handler( pLink ) |
---|
70 | { |
---|
71 | var action = pLink.href; |
---|
72 | if ( action == '' ) |
---|
73 | return false; |
---|
74 | |
---|
75 | var a = ( action.indexOf( 'javascript:' ) === 0 ); |
---|
76 | a = ( a || ( action.indexOf( '#' ) === 0 ) ); |
---|
77 | a = ( a || ( action.indexOf( window.location + '#' ) === 0 ) ); |
---|
78 | a = ( a || ! ( action.indexOf( 'workflow' ) < 0 ) ); |
---|
79 | |
---|
80 | if ( ! a ) |
---|
81 | pLink.onclick = function( ) |
---|
82 | { |
---|
83 | _divAppboxHeader.innerHTML = ''; |
---|
84 | |
---|
85 | var _center = document.createElement( 'center' ); |
---|
86 | _center.appendChild( _loading ); |
---|
87 | |
---|
88 | _container.innerHTML = ''; |
---|
89 | _container.appendChild( _center ); |
---|
90 | |
---|
91 | var _cacheit = false;//( ( pLink.hasAttribute( 'cacheit' ) && pLink.getAttribute( 'cacheit' ) === 'true' ) ? true : false ); |
---|
92 | |
---|
93 | _connector.go( |
---|
94 | { |
---|
95 | 'access' : action, |
---|
96 | 'cache' : _cacheit, |
---|
97 | 'handler' : _handler |
---|
98 | } ); |
---|
99 | |
---|
100 | window.location = '#' + ( |
---|
101 | ( action.indexOf( URL_SERVER ) < 0 ) ? |
---|
102 | action : action.substr( action.indexOf( URL_SERVER ) + URL_SERVER.length ) |
---|
103 | ); |
---|
104 | |
---|
105 | return false; |
---|
106 | }; |
---|
107 | } |
---|
108 | |
---|
109 | function Link( ) |
---|
110 | { |
---|
111 | var _cacheit = false; |
---|
112 | if ( arguments.length > 1 && arguments[ 1 ].constructor == Boolean ) |
---|
113 | _cacheit = arguments[ 1 ]; |
---|
114 | |
---|
115 | _connector.go( |
---|
116 | { |
---|
117 | "access" : arguments[ 0 ], |
---|
118 | "cache" : _cacheit, |
---|
119 | "handler" : _handler |
---|
120 | } ); |
---|
121 | } |
---|
122 | |
---|
123 | window.XLink = Link; |
---|
124 | |
---|
125 | XEvents.add( window, 'onload', function( ) |
---|
126 | { |
---|
127 | var _scripts = document.getElementsByTagName( 'head' ).item( 0 ).getElementsByTagName( 'script' ); |
---|
128 | var _loaded = [ ]; |
---|
129 | |
---|
130 | for ( var i = 0; i < _scripts.length; i++ ) |
---|
131 | if ( _scripts.item( i ).getAttribute( 'src' ) != null ) |
---|
132 | _loaded[ _loaded.length ] = _scripts.item( i ).getAttribute( 'src' ).substr( |
---|
133 | URL_SERVER.length - 1, |
---|
134 | _scripts.item( i ).getAttribute( 'src' ).indexOf( '?' ) - URL_SERVER.length + 1 |
---|
135 | ); |
---|
136 | |
---|
137 | _script = new XScript( _loaded ); |
---|
138 | |
---|
139 | _divAppboxHeader = document.getElementById( 'divAppboxHeader' ); |
---|
140 | _divAppboxHeader.innerHTML = ''; |
---|
141 | |
---|
142 | _container = document.getElementById( 'divAppbox' ); |
---|
143 | |
---|
144 | document.getElementsByTagName( 'body' ).item( 0 ).style.overflowY = 'scroll'; |
---|
145 | |
---|
146 | var _links = document.getElementsByTagName( 'a' ); |
---|
147 | for ( var i = 0; i < _links.length; i++ ) |
---|
148 | handler( _links.item( i ) ); |
---|
149 | } ); |
---|
150 | } )( ); |
---|