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

Revision 2642, 3.4 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1009 - Corigindo problemas com o ordenamento referente aos javascripts.

Line 
1( function( )
2{
3        var _connector = null;
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( pLink )
12        {
13                var action = pLink.href;
14                if ( action == '' )
15                        return false;
16
17                var a = ( action.indexOf( 'javascript:' ) === 0 );
18                a = ( a || ( action.indexOf( '#' ) === 0 ) );
19                a = ( a || ( action.indexOf( window.location + '#' ) === 0 ) );
20                a = ( a || ! ( action.indexOf( 'workflow' ) < 0 ) );
21
22                if ( ! a )
23                        pLink.onclick = function( )
24                        {
25                                _divAppboxHeader.innerHTML = '';
26
27                                var _center = document.createElement( 'center' );
28                                _center.appendChild( _loading );
29
30                                _container.innerHTML = '';
31                                _container.appendChild( _center );
32
33                                var _cacheit = true;//( ( pLink.hasAttribute( 'cacheit' ) && pLink.getAttribute( 'cacheit' ) === 'true' ) ? true : false );
34
35                                var request = _connector.go( {
36                                        'access' : action,
37                                        'cache' : _cacheit,
38                                        'handler' : function( data )
39                                        {
40                                                var js = data.match( /<script[^>]*>.*?<\/script>/g );
41                                                var _new_scripts = [ ];
42                                                if ( js )
43                                                {
44                                                        var tag = /<script([^>]* src="(\S+)"|[^>]*)>(.*?)<\/script>/;
45                                                        for ( var i = 0; i < js.length; i++ )
46                                                        {
47                                                                var type = tag.exec( js[ i ] );
48                                                                data = data.replace( "\n\t\t" + type[ 0 ], '' );
49                                                                _new_scripts[ _new_scripts.length ] = type;
50                                                        }
51                                                }
52
53                                                var el = document.createElement( 'div' );
54                                                el.innerHTML = data;
55
56                                                var _links = el.getElementsByTagName( 'a' );
57                                                for ( var i = 0; i < _links.length; i++ )
58                                                        handler( _links.item( i ) );
59
60                                                _container.innerHTML = '';
61                                                while ( el.hasChildNodes( ) )
62                                                        _container.appendChild( el.firstChild );
63
64                                                var _count = 0;
65                                                function _scripts( )
66                                                {
67                                                        if ( _new_scripts[ _count ][ 2 ] == undefined || _new_scripts[ _count ][ 2 ].length == 0 )
68                                                                _script.load( function( )
69                                                                {
70                                                                        if ( ++_count < _new_scripts.length )
71                                                                                _scripts( );
72                                                                }, _new_scripts[ _count ][ 3 ] );
73                                                        else
74                                                        {
75                                                                _script.add(
76                                                                        _new_scripts[ _count ][ 2 ].substr(
77                                                                                URL_SERVER.length - 1,
78                                                                                _new_scripts[ _count ][ 2 ].indexOf( '?' ) - URL_SERVER.length + 1
79                                                                        )
80                                                                );
81                                                                if ( ++_count < _new_scripts.length )
82                                                                        _scripts( );
83                                                        }
84                                                }
85
86                                                if ( _new_scripts.length )
87                                                {
88                                                        _scripts( );
89                                                        _script.load( );
90                                                }
91                                        }
92                                } );
93                                return false;
94                        };
95        }
96
97        XEvents.add( window, 'onload', function( )
98        {
99                var _scripts = document.getElementsByTagName( 'head' ).item( 0 ).getElementsByTagName( 'script' );
100                var _loaded = [ ];
101
102                for ( var i = 0; i < _scripts.length; i++ )
103                        if ( _scripts.item( i ).getAttribute( 'src' ) != null )
104                                _loaded[ _loaded.length ] = _scripts.item( i ).getAttribute( 'src' ).substr(
105                                        URL_SERVER.length - 1,
106                                        _scripts.item( i ).getAttribute( 'src' ).indexOf( '?' ) - URL_SERVER.length + 1
107                                );
108
109                _connector = new XConnector;
110                _script = new XScript( _loaded );
111
112                _divAppboxHeader = document.getElementById( 'divAppboxHeader' );
113                _divAppboxHeader.innerHTML = '';
114
115                _container = document.getElementById( 'divAppbox' );
116
117                document.getElementsByTagName( 'body' ).item( 0 ).style.overflowY = 'scroll';
118
119                var _links = document.getElementsByTagName( 'a' );
120                for ( var i = 0; i < _links.length; i++ )
121                        handler( _links.item( i ) );
122        } );
123} )( );
Note: See TracBrowser for help on using the repository browser.