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.

RevLine 
[2628]1( function( )
2{
[2703]3        var _connector = new XConnector;
[2628]4        var _loaded = [ ];
5        var _new = [ ];
6
[2729]7        function _inline( )
[2628]8        {
[2729]9                _new[ _new.length ] = {
10                        "type" : "inline",
11                        "content" : arguments[ 0 ]
12                };
13        }
[2628]14
[2729]15        function _external( )
16        {
17                _new[ _new.length ] = {
18                        "type" : "external",
19                        "content" : arguments[ 0 ]
20                };
[2628]21        }
22
23        function _load( )
24        {
[2729]25                var _count = 0;
26                function _handler( )
[2642]27                {
[2729]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                                        }
[2628]37
[2729]38                                _scripts[ _scripts.length ] = _loaded[ _loaded.length ] = _new[ _count ].content;
39                                _count++;
40                        }
[2628]41
[2729]42                        _scripts = _scripts.join( ';' );
[2642]43
[2729]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' )
[2756]50                                                        data += _new[ _count ].content;
51
52                                                if ( window.execScript )
53                                                        window.execScript( data );
[2729]54                                                else
[2756]55                                                        with ( window )
56                                                                window.eval( data );
57
58                                                _count++;
59                                                _handler( );
[2729]60                                        }
61                                } );
62                        else
63                                if ( _count < _new.length && _new[ _count ].type == 'inline' )
[2642]64                                {
[2756]65                                        if ( window.execScript )
66                                                window.execScript( _new[ _count ].content );
67                                        else
68                                                with ( window )
69                                                        window.eval( _new[ _count ].content );
70
[2729]71                                        _count++;
72                                        _handler( );
73                                }
[2642]74
[2729]75                        if ( _count == _new.length )
76                                _new = [ ];
[2642]77                }
[2729]78                _handler( );
[2628]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
[2729]88        Script.prototype.external = _external;
89        Script.prototype.inline = _inline;
[2628]90        Script.prototype.load = _load;
91
92        window.XScript = Script;
93} )( );
Note: See TracBrowser for help on using the repository browser.