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

Revision 2756, 1.9 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1058 - Melhorando a manipulação de javascripts.

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                                                if ( _count < _new.length && _new[ _count ].type == 'inline' )
50                                                        data += _new[ _count ].content;
51
52                                                if ( window.execScript )
53                                                        window.execScript( data );
54                                                else
55                                                        with ( window )
56                                                                window.eval( data );
57
58                                                _count++;
59                                                _handler( );
60                                        }
61                                } );
62                        else
63                                if ( _count < _new.length && _new[ _count ].type == 'inline' )
64                                {
65                                        if ( window.execScript )
66                                                window.execScript( _new[ _count ].content );
67                                        else
68                                                with ( window )
69                                                        window.eval( _new[ _count ].content );
70
71                                        _count++;
72                                        _handler( );
73                                }
74
75                        if ( _count == _new.length )
76                                _new = [ ];
77                }
78                _handler( );
79        }
80
81        function Script( )
82        {
83                if ( arguments.length && typeof arguments[ 0 ] == 'object' && arguments[ 0 ].constructor == Array )
84                        for ( var i = 0; i < arguments[ 0 ].length; i++ )
85                                _loaded[ _loaded.length ] = arguments[ 0 ][ i ];
86        }
87
88        Script.prototype.external = _external;
89        Script.prototype.inline = _inline;
90        Script.prototype.load = _load;
91
92        window.XScript = Script;
93} )( );
Note: See TracBrowser for help on using the repository browser.