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

Revision 2677, 3.9 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1009 - Corrigindo problema de contexto.

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