Вход Регистрация
Файл: wordpress/wp-includes/js/customize-preview.js
Строк: 202
<?php
(function( exports, $ ){
    var 
api wp.customize,
        
debounce;

    
/**
     * Returns a debounced version of the function.
     *
     * @todo Require Underscore.js for this file and retire this.
     */
    
debounce = function( fndelaycontext ) {
        var 
timeout;
        return function() {
            var 
args arguments;

            
context context || this;

            
clearTimeouttimeout );
            
timeout setTimeout( function() {
                
timeout null;
                
fn.applycontextargs );
            }, 
delay );
        };
    };

    
/**
     * @constructor
     * @augments wp.customize.Messenger
     * @augments wp.customize.Class
     * @mixes wp.customize.Events
     */
    
api.Preview api.Messenger.extend({
        
/**
         * Requires params:
         *  - url    - the URL of preview frame
         */
        
initialize: function( paramsoptions ) {
            var 
self this;

            
api.Messenger.prototype.initialize.callthisparamsoptions );

            
this.body = $( document.body );
            
this.body.on'click.preview''a', function( event ) {
                
event.preventDefault();
                
self.send'scroll');
                
self.send'url', $(this).prop('href') );
            });

            
// You cannot submit forms.
            // @todo: Allow form submissions by mixing $_POST data with the customize setting $_POST data.
            
this.body.on'submit.preview''form', function( event ) {
                
event.preventDefault();
            });

            
this.window = $( window );
            
this.window.on'scroll.preview'debounce( function() {
                
self.send'scroll'self.window.scrollTop() );
            }, 
200 ));

            
this.bind'scroll', function( distance ) {
                
self.window.scrollTopdistance );
            });
        }
    });

    $( function() {
        
api.settings window._wpCustomizeSettings;
        if ( ! 
api.settings )
            return;

        var 
bg;

        
api.preview = new api.Preview({
            
urlwindow.location.href,
            
channelapi.settings.channel
        
});

        
api.preview.bind'settings', function( values ) {
            $.
eachvalues, function( idvalue ) {
                if ( 
api.hasid ) )
                    
apiid ).setvalue );
                else
                    
api.createidvalue );
            });
        });

        
api.preview.trigger'settings'api.settings.values );

        
api.preview.bind'setting', function( args ) {
            var 
value;

            
args args.slice();

            if ( 
value apiargs.shift() ) )
                
value.set.applyvalueargs );
        });

        
api.preview.bind'sync', function( events ) {
            $.
eachevents, function( eventargs ) {
                
api.preview.triggereventargs );
            });
            
api.preview.send'synced' );
        });

        
api.preview.bind'active', function() {
            if ( 
api.settings.nonce ) {
                
api.preview.send'nonce'api.settings.nonce );
            }

            
api.preview.send'documentTitle'document.title );
        });

        
api.preview.send'ready', {
            
activePanelsapi.settings.activePanels,
            
activeSectionsapi.settings.activeSections,
            
activeControlsapi.settings.activeControls
        
} );

        
// Display a loading indicator when preview is reloading, and remove on failure.
        
api.preview.bind'loading-initiated', function () {
            $( 
'body' ).addClass'wp-customizer-unloading' );
            $( 
'html' ).prop'title'api.settings.l10n.loading );
        });
        
api.preview.bind'loading-failed', function () {
            $( 
'body' ).removeClass'wp-customizer-unloading' );
            $( 
'html' ).prop'title''' );
        });

        
/* Custom Backgrounds */
        
bg = $.map(['color''image''position_x''repeat''attachment'], function( prop ) {
            return 
'background_' prop;
        });

        
api.when.applyapibg ).done( function( colorimageposition_xrepeatattachment ) {
            var 
body = $(document.body),
                
head = $('head'),
                
style = $('#custom-background-css'),
                
update;

            
update = function() {
                var 
css '';

                
// The body will support custom backgrounds if either
                // the color or image are set.
                //
                // See get_body_class() in /wp-includes/post-template.php
                
body.toggleClass'custom-background', !! ( color() || image() ) );

                if ( 
color() )
                    
css += 'background-color: ' color() + ';';

                if ( 
image() ) {
                    
css += 'background-image: url("' image() + '");';
                    
css += 'background-position: top ' position_x() + ';';
                    
css += 'background-repeat: ' repeat() + ';';
                    
css += 'background-attachment: ' attachment() + ';';
                }

                
// Refresh the stylesheet by removing and recreating it.
                
style.remove();
                
style = $('<style type="text/css" id="custom-background-css">body.custom-background { ' css ' }</style>').appendTohead );
            };

            $.
eacharguments, function() {
                
this.bindupdate );
            });
        });

        
api.trigger'preview-ready' );
    });

})( 
wpjQuery );
?>
Онлайн: 1
Реклама