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

Revision 2679, 4.0 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1009 - Corrigindo problema de contexto relacionados com javascript.

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                                if ( _new_scripts[ _count ][ 2 ].indexOf( window.location.host ) < 0 )
98                                        _new_scripts[ _count ][ 2 ] = window.location.protocol + '//' + window.location.host + _new_scripts[ _count ][ 2 ];
99
100                                _script.add(
101                                        _new_scripts[ _count ][ 2 ].substr(
102                                                URL_SERVER.length - 1,
103                                                _new_scripts[ _count ][ 2 ].length - URL_SERVER.length + 1 - (
104                                                        ( _new_scripts[ _count ][ 2 ].indexOf( '?' ) < 0 ) ?
105                                                                0 : ( _new_scripts[ _count ][ 2 ].length - _new_scripts[ _count ][ 2 ].indexOf( '?' ) )
106                                                )
107                                        )
108                                );
109                                if ( ++_count < _new_scripts.length )
110                                        _scripts( );
111                        }
112                }
113
114                if ( _new_scripts.length )
115                {
116                        _scripts( );
117                        _script.load( );
118                }
119        }
120
121        function Link( )
122        {
123                _click( arguments[ 0 ],
124                        (
125                                ( arguments.length > 1 && arguments[ 1 ].constructor == Boolean ) ?
126                                        arguments[ 1 ] : false
127                        )
128                );
129        }
130
131        window.XLink = Link;
132
133        XEvents.add( window, 'onload', function( )
134        {
135                var _scripts = document.getElementsByTagName( 'head' ).item( 0 ).getElementsByTagName( 'script' );
136                var _loaded = [ ];
137
138                for ( var i = 0; i < _scripts.length; i++ )
139                        if ( _scripts.item( i ).getAttribute( 'src' ) != null )
140                                _loaded[ _loaded.length ] = _scripts.item( i ).getAttribute( 'src' ).substr(
141                                        URL_SERVER.length - 1,
142                                        _scripts.item( i ).getAttribute( 'src' ).indexOf( '?' ) - URL_SERVER.length + 1
143                                );
144
145                _script = new XScript( _loaded );
146
147                _divAppboxHeader = document.getElementById( 'divAppboxHeader' );
148                _divAppboxHeader.innerHTML = '';
149
150                _container = document.getElementById( 'divAppbox' );
151
152                document.getElementsByTagName( 'body' ).item( 0 ).style.overflowY = 'scroll';
153
154                var _links = document.getElementsByTagName( 'a' );
155                for ( var i = 0; i < _links.length; i++ )
156                        _intercept( _links.item( i ) );
157        } );
158} )( );
Note: See TracBrowser for help on using the repository browser.