source: trunk/phpgwapi/js/tools/xscript.js @ 2729

Revision 2729, 1.8 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1058 - Corrigindo problema do caregamento do contactcenter.

Line 
1( function( )
2{
3        var _connector = new XConnector;
4        var _loaded = [ ];
5        var _new = [ ];
6
7        function _inline( )
8        {
9                _new[ _new.length ] = {
10                        "type" : "inline",
11                        "content" : arguments[ 0 ]
12                };
13        }
14
15        function _external( )
16        {
17                _new[ _new.length ] = {
18                        "type" : "external",
19                        "content" : arguments[ 0 ]
20                };
21        }
22
23        function _load( )
24        {
25                var _count = 0;
26                function _handler( )
27                {
28                        var _scripts = [ ];
29                        _script : while ( _count < _new.length && _new[ _count ].type != 'inline' )
30                        {
31                                for ( var i = 0; i < _loaded.length; i++ )
32                                        if ( _loaded[ i ] == _new[ _count ].content )
33                                        {
34                                                _count++;
35                                                continue _script;
36                                        }
37
38                                _scripts[ _scripts.length ] = _loaded[ _loaded.length ] = _new[ _count ].content;
39                                _count++;
40                        }
41
42                        _scripts = _scripts.join( ';' );
43
44                        if ( _scripts.length )
45                                _connector.go( {
46                                        "access" : URL_SERVER + 'controller.php?action=phpgwapi.javascript.get_source&source=' + _scripts,
47                                        "handler" : function( data )
48                                        {
49                                                window.eval( data );
50                                                if ( _count < _new.length && _new[ _count ].type == 'inline' )
51                                                {
52                                                        window.eval( _new[ _count ].content );
53                                                        _count++;
54                                                        _handler( );
55                                                }
56                                                else
57                                                {
58                                                        _count++;
59                                                        _handler( );
60                                                }
61                                        }
62                                } );
63                        else
64                                if ( _count < _new.length && _new[ _count ].type == 'inline' )
65                                {
66                                        window.eval( _new[ _count ].content );
67                                        _count++;
68                                        _handler( );
69                                }
70
71                        if ( _count == _new.length )
72                                _new = [ ];
73                }
74                _handler( );
75        }
76
77        function Script( )
78        {
79                if ( arguments.length && typeof arguments[ 0 ] == 'object' && arguments[ 0 ].constructor == Array )
80                        for ( var i = 0; i < arguments[ 0 ].length; i++ )
81                                _loaded[ _loaded.length ] = arguments[ 0 ][ i ];
82        }
83
84        Script.prototype.external = _external;
85        Script.prototype.inline = _inline;
86        Script.prototype.load = _load;
87
88        window.XScript = Script;
89} )( );
Note: See TracBrowser for help on using the repository browser.