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

Revision 2630, 3.3 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1009 - Mitigando problema com escopo do dominio.

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 _inline = [ ];
65                                                for ( var i = 0; i < _new_scripts.length; i++ )
66                                                        if ( _new_scripts[ i ][ 2 ] == undefined || _new_scripts[ i ][ 2 ].length == 0 )
67                                                                _inline[ _inline.length ] = _new_scripts[ i ][ 3 ];
68                                                        else
69                                                                _script.add( _new_scripts[ i ][ 2 ].substr(
70                                                                        URL_SERVER.length - 1,
71                                                                        _new_scripts[ i ][ 2 ].indexOf( '?' ) - URL_SERVER.length + 1
72                                                                ) );
73
74                                                var _it_has_loaded = _script.load( function( )
75                                                {
76                                                        if ( _inline.length )
77                                                                window.eval( _inline.join( '' ) );
78                                                } );
79
80                                                if ( ! _it_has_loaded && _inline.length )
81                                                        window.eval( _inline.join( '' ) );
82                                        }
83                                } );
84                                return false;
85                        };
86        }
87
88        XEvents.add( window, 'onload', function( )
89        {
90                var _scripts = document.getElementsByTagName( 'head' ).item( 0 ).getElementsByTagName( 'script' );
91                var _loaded = [ ];
92
93                for ( var i = 0; i < _scripts.length; i++ )
94                        if ( _scripts.item( i ).getAttribute( 'src' ) != null )
95                                _loaded[ _loaded.length ] = _scripts.item( i ).getAttribute( 'src' ).substr(
96                                        URL_SERVER.length - 1,
97                                        _scripts.item( i ).getAttribute( 'src' ).indexOf( '?' ) - URL_SERVER.length + 1
98                                );
99
100                _connector = new XConnector;
101                _script = new XScript( _loaded );
102
103                _divAppboxHeader = document.getElementById( 'divAppboxHeader' );
104                _divAppboxHeader.innerHTML = '';
105
106                _container = document.getElementById( 'divAppbox' );
107
108                document.getElementsByTagName( 'body' ).item( 0 ).style.overflowY = 'scroll';
109
110                var _links = document.getElementsByTagName( 'a' );
111                for ( var i = 0; i < _links.length; i++ )
112                        handler( _links.item( i ) );
113        } );
114} )( );
Note: See TracBrowser for help on using the repository browser.