source: trunk/phpgwapi/js/tools/xlink.js @ 2710

Revision 2710, 4.1 KB checked in by amuller, 14 years ago (diff)

Ticket #1058 - Troca a imagem de loading por uma com tema azul

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