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