Ignore:
Timestamp:
04/26/10 16:03:33 (14 years ago)
Author:
rodsouza
Message:

Ticket #1009 - Organizando javascript e criando cache dos mesmos.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/phpgwapi/js/tools/xlink.js

    r2601 r2628  
    11( function( ) 
    22{ 
    3         var _connector = new XConnector; 
     3        var _connector = null; 
     4        var _script = null; 
     5 
    46        var _container = null; 
    57        var _divAppboxHeader = null; 
     
    2325                                _divAppboxHeader.innerHTML = ''; 
    2426 
     27                                var _center = document.createElement( 'center' ); 
     28                                _center.appendChild( _loading ); 
     29 
    2530                                _container.innerHTML = ''; 
    26                                 _container.appendChild( _loading ); 
     31                                _container.appendChild( _center ); 
    2732 
    28                                 var _cacheit = ( ( pLink.hasAttribute( 'cacheit' ) && pLink.getAttribute( 'cacheit' ) === 'true' ) ? true : false ); 
     33                                var _cacheit = true;//( ( pLink.hasAttribute( 'cacheit' ) && pLink.getAttribute( 'cacheit' ) === 'true' ) ? true : false ); 
    2934 
    30                                 var request = _connector.cache( _cacheit ).go( { 
     35                                var request = _connector.go( { 
    3136                                        'access' : action, 
     37                                        'cache' : _cacheit, 
    3238                                        'handler' : function( data ) 
    3339                                        { 
     40                                                var js = data.match( /<script[^>]*>.*?<\/script>/g ); 
     41                                                var _new_scripts = [ ]; 
     42                                                if ( js ) 
     43                                                { 
     44                                                        var tag = /<script([^>]* src="(\S+)"|[^>]*)>(.*?)<\/script>/; 
     45                                                        for ( var i = 0; i < js.length; i++ ) 
     46                                                        { 
     47                                                                var type = tag.exec( js[ i ] ); 
     48                                                                data = data.replace( "\n\t\t" + type[ 0 ], '' ); 
     49                                                                _new_scripts[ _new_scripts.length ] = type; 
     50                                                        } 
     51                                                } 
     52 
    3453                                                var el = document.createElement( 'div' ); 
    3554                                                el.innerHTML = data; 
     
    3958                                                        handler( _links.item( i ) ); 
    4059 
    41                                                 var _head = document.getElementsByTagName( 'head' ).item( 0 ); 
    42                                                 var _loaded = _head.getElementsByTagName( 'script' ); 
    43                                                 var _scripts = el.getElementsByTagName( 'script' ); 
    44                                                 var _new_scripts = [ ]; 
    45  
    46                                                 while ( _scripts.length ) 
    47                                                         _new_scripts[ _new_scripts.length ] = el.removeChild( _scripts.item( 0 ) ); 
    48  
    4960                                                _container.innerHTML = ''; 
    5061                                                while ( el.hasChildNodes( ) ) 
    5162                                                        _container.appendChild( el.firstChild ); 
    5263 
    53                                                 fix : for ( var i = 0; i < _new_scripts.length; i++ ) 
     64                                                var _inline = [ ]; 
     65                                                for ( var i = 0; i < _new_scripts.length; i++ ) 
     66                                                        if ( _new_scripts[ i ][ 2 ] == undefined || _new_scripts[ i ][ 2 ].length == 0 ) 
     67                                                                _inline[ _inline.length ] = _new_scripts[ i ][ 3 ]; 
     68                                                        else 
     69                                                                _script.add( _new_scripts[ i ][ 2 ].substr( 
     70                                                                        URL_SERVER.length, 
     71                                                                        _new_scripts[ i ][ 2 ].indexOf( '?' ) - URL_SERVER.length 
     72                                                                ) ); 
     73 
     74                                                var _it_has_loaded = _script.load( function( ) 
    5475                                                { 
    55                                                         var _script = _new_scripts[ i ]; 
    56                                                         if ( _script.getAttribute( 'src' ) == null ) 
    57                                                         { 
    58                                                                 _container.appendChild( _script ); 
    59                                                                 continue; 
    60                                                         } 
    61                                                         else 
    62                                                         { 
    63                                                                 for ( var j = 0; j < _loaded.length; j++ ) 
    64                                                                         if ( _script.getAttribute( 'src' ) === _loaded.item( j ).getAttribute( 'src' )  ) 
    65                                                                                 continue fix; 
     76                                                        if ( _inline.length ) 
     77                                                                window.eval( _inline.join( '' ) ); 
     78                                                } ); 
    6679 
    67                                                                 _head.appendChild( _script ); 
    68                                                         } 
    69                                                 } 
     80                                                if ( ! _it_has_loaded && _inline.length ) 
     81                                                        window.eval( _inline.join( '' ) ); 
    7082                                        } 
    7183                                } ); 
     
    7688        XEvents.add( window, 'onload', function( ) 
    7789        { 
    78                 var _center = document.createElement( 'center' ); 
    79                 _center.appendChild( _loading ); 
     90                var _scripts = document.getElementsByTagName( 'head' ).item( 0 ).getElementsByTagName( 'script' ); 
     91                var _loaded = [ ]; 
     92 
     93                for ( var i = 0; i < _scripts.length; i++ ) 
     94                        if ( _scripts.item( i ).getAttribute( 'src' ) != null ) 
     95                                _loaded[ _loaded.length ] = _scripts.item( i ).getAttribute( 'src' ).substr( 
     96                                        URL_SERVER.length, 
     97                                        _scripts.item( i ).getAttribute( 'src' ).indexOf( '?' ) - URL_SERVER.length 
     98                                ); 
     99 
     100                _connector = new XConnector; 
     101                _script = new XScript( _loaded ); 
    80102 
    81103                _divAppboxHeader = document.getElementById( 'divAppboxHeader' ); 
     
    83105 
    84106                _container = document.getElementById( 'divAppbox' ); 
    85                 _loading = _center; 
    86107 
    87108                document.getElementsByTagName( 'body' ).item( 0 ).style.overflowY = 'scroll'; 
Note: See TracChangeset for help on using the changeset viewer.