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

Revision 2601, 2.6 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1009 - Melhorando a forma de criar cache em uma requisição background.

RevLine 
[2420]1( function( )
2{
3        var _connector = new XConnector;
[2469]4        var _container = null;
[2562]5        var _divAppboxHeader = null;
[2469]6        var _loading = new Image( );
7        _loading.src = URL_SERVER + '/phpgwapi/images/loading.gif';
8
[2420]9        function handler( pLink )
10        {
11                var action = pLink.href;
[2565]12                if ( action == '' )
13                        return false;
14
[2420]15                var a = ( action.indexOf( 'javascript:' ) === 0 );
16                a = ( a || ( action.indexOf( '#' ) === 0 ) );
17                a = ( a || ( action.indexOf( window.location + '#' ) === 0 ) );
[2509]18                a = ( a || ! ( action.indexOf( 'workflow' ) < 0 ) );
[2420]19
20                if ( ! a )
21                        pLink.onclick = function( )
22                        {
[2562]23                                _divAppboxHeader.innerHTML = '';
24
[2469]25                                _container.innerHTML = '';
26                                _container.appendChild( _loading );
[2562]27
[2601]28                                var _cacheit = ( ( pLink.hasAttribute( 'cacheit' ) && pLink.getAttribute( 'cacheit' ) === 'true' ) ? true : false );
[2562]29
[2601]30                                var request = _connector.cache( _cacheit ).go( {
[2420]31                                        'access' : action,
32                                        'handler' : function( data )
33                                        {
34                                                var el = document.createElement( 'div' );
35                                                el.innerHTML = data;
36
[2578]37                                                var _links = el.getElementsByTagName( 'a' );
38                                                for ( var i = 0; i < _links.length; i++ )
39                                                        handler( _links.item( i ) );
[2420]40
[2578]41                                                var _head = document.getElementsByTagName( 'head' ).item( 0 );
42                                                var _loaded = _head.getElementsByTagName( 'script' );
43                                                var _scripts = el.getElementsByTagName( 'script' );
[2601]44                                                var _new_scripts = [ ];
45
46                                                while ( _scripts.length )
47                                                        _new_scripts[ _new_scripts.length ] = el.removeChild( _scripts.item( 0 ) );
48
49                                                _container.innerHTML = '';
50                                                while ( el.hasChildNodes( ) )
51                                                        _container.appendChild( el.firstChild );
52
53                                                fix : for ( var i = 0; i < _new_scripts.length; i++ )
[2578]54                                                {
[2601]55                                                        var _script = _new_scripts[ i ];
[2578]56                                                        if ( _script.getAttribute( 'src' ) == null )
[2601]57                                                        {
58                                                                _container.appendChild( _script );
[2578]59                                                                continue;
[2601]60                                                        }
[2578]61                                                        else
62                                                        {
63                                                                for ( var j = 0; j < _loaded.length; j++ )
64                                                                        if ( _script.getAttribute( 'src' ) === _loaded.item( j ).getAttribute( 'src' )  )
65                                                                                continue fix;
66
67                                                                _head.appendChild( _script );
68                                                        }
69                                                }
[2420]70                                        }
71                                } );
72                                return false;
73                        };
74        }
75
76        XEvents.add( window, 'onload', function( )
77        {
[2473]78                var _center = document.createElement( 'center' );
79                _center.appendChild( _loading );
80
[2562]81                _divAppboxHeader = document.getElementById( 'divAppboxHeader' );
82                _divAppboxHeader.innerHTML = '';
83
[2469]84                _container = document.getElementById( 'divAppbox' );
[2473]85                _loading = _center;
86
[2469]87                document.getElementsByTagName( 'body' ).item( 0 ).style.overflowY = 'scroll';
[2473]88
[2578]89                var _links = document.getElementsByTagName( 'a' );
90                for ( var i = 0; i < _links.length; i++ )
91                        handler( _links.item( i ) );
[2420]92        } );
93} )( );
Note: See TracBrowser for help on using the repository browser.