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

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

Ticket #1009 - Removendo redirecionamento de 'index.php' para 'home.php'.

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