
/*  
 *Disclaimer: This license only applies to the code within this file. 
 *Navitaire Inc. reserves rights to all other code within this web application
===============================================================================  
Metaobjects is a jQuery plugin for setting properties of DOM elements  by means  
of metaobjects (OBJECT elements with a 'metaobject' class)
...............................................................................                                                 
                                               Copyright 2007 / Andrea Ercolino  
-------------------------------------------------------------------------------  
LICENSE: http://www.opensource.org/licenses/mit-license.php 
MANUAL:  http://www.mondotondo.com/aercolino/noteslog/?page_id=105 
UPDATES: http://www.mondotondo.com/aercolino/noteslog/?cat=20  
===============================================================================  
*/ 
 
( function($) { 
$.metaobjects = function( options ) { 
 
    options = $.extend( { 
          context:  document 
        , clean:    true 
        , selector: 'object.metaobject' 
    }, options ); 
 
    function jsValue( value, name ) {
        if (name == "regex") {
           value = escapeRegex(value); 
        } else {
            value = escapeValue(value);
        }
        eval( 'value = ' + value + ";" );
        return value; 
    }
    
    function escapeValue( value ) {
        if (value.match(/^'.*'$/)) {
            value = value.replace(/'/g, "\\'");
            value = value.replace(/^\\\'/, "'");
            value = value.replace(/\\\'$/, "'");
        }
        return value;
    }
    
    function escapeRegex( value ) {
        if (value.match(/^'.*'$/)) {
            value = value.replace(/^'/, "/");
            value = value.replace(/'$/, "/");
        }
        return value;
    }
 
    return $( options.selector, options.context ) 
    .each( function() { 
 
        var settings = { target: this.parentNode }; 
        $( '> param[name=metaparam]', this ) 
        .each( function() {  
            $.extend( settings, jsValue( this.value ) ); 
        } ); 
 
        $( '> param', this ) 
        .not( '[name=metaparam]' ) 
        .each( function() {
            var type= $(this).attr('type');
            var name = this.name;
            var value = jsValue( this.value, name );
            $( settings.target ) 
            .each( function() {
                    this[ name ] = value; 
            } ); 
        } ); 
 
        if( options.clean ) { 
            $( this ).remove(); 
        } 
    } ); 
} 
} ) ( jQuery );

/*
 *Disclaimer: This license only applies to the code within this file. 
 *Navitaire Inc. reserves rights to all other code within this web application
 */