Changeset 32088
- Timestamp:
- 04/08/2015 08:51:39 PM (10 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/customize-controls.js
r32087 r32088 553 553 overlay: '', 554 554 template: '', 555 screenshotQueue: null, 556 $window: $( window ), 557 $customizeSidebar: $( '.wp-full-overlay-sidebar-content:first' ), 555 558 556 559 /** … … 583 586 } 584 587 }); 588 589 _.bindAll( this, 'renderScreenshots' ); 585 590 }, 586 591 … … 651 656 }); 652 657 658 var renderScreenshots = _.throttle( _.bind( section.renderScreenshots, this ), 100 ); 653 659 section.container.on( 'input', '#themes-filter', function( event ) { 654 660 var count, … … 660 666 }); 661 667 668 renderScreenshots(); 669 662 670 // Update theme count. 663 671 count = section.container.find( 'li.customize-control:visible' ).length; 664 672 section.container.find( '.theme-count' ).text( count ); 673 }); 674 675 // Pre-load the first 3 theme screenshots. 676 api.bind( 'ready', function () { 677 _.each( section.controls().slice( 0, 3 ), function ( control ) { 678 var img, src = control.params.theme.screenshot[0]; 679 if ( src ) { 680 img = new Image(); 681 img.src = src; 682 } 683 }); 665 684 }); 666 685 }, … … 707 726 }); 708 727 api.panel.each( function ( otherPanel ) { 709 if ( panel !== otherPanel ) { 710 otherPanel.collapse( { duration: 0 } ); 711 } 728 otherPanel.collapse( { duration: 0 } ); 712 729 }); 713 730 … … 719 736 overlay.addClass( 'in-themes-panel' ); 720 737 container.scrollTop( 0 ); 738 _.delay( panel.renderScreenshots, 10 ); // Wait for the controls 739 panel.$customizeSidebar.on( 'scroll.customize-themes-section', _.throttle( panel.renderScreenshots, 300 ) ); 721 740 if ( args.completeCallback ) { 722 741 args.completeCallback(); … … 730 749 section.removeClass( 'current-panel' ); 731 750 overlay.removeClass( 'in-themes-panel' ); 751 panel.$customizeSidebar.off( 'scroll.customize-themes-section' ); 732 752 content.delay( 180 ).hide( 0, function() { 733 753 content.css( 'margin-top', 'inherit' ); // Reset … … 744 764 745 765 /** 766 * Render control's screenshot if the control comes into view. 767 * 768 * @since 4.2.0 769 */ 770 renderScreenshots: function( ) { 771 var section = this; 772 773 // Fill queue initially. 774 if ( section.screenshotQueue === null ) { 775 section.screenshotQueue = section.controls(); 776 } 777 778 // Are all screenshots rendered? 779 if ( ! section.screenshotQueue.length ) { 780 return; 781 } 782 783 section.screenshotQueue = _.filter( section.screenshotQueue, function( control ) { 784 var $imageWrapper = control.container.find( '.theme-screenshot' ), 785 $image = $imageWrapper.find( 'img' ); 786 787 if ( ! $image.length ) { 788 return false; 789 } 790 791 if ( $image.is( ':hidden' ) ) { 792 return true; 793 } 794 795 // Based on unveil.js. 796 var wt = section.$window.scrollTop(), 797 wb = wt + section.$window.height(), 798 et = $image.offset().top, 799 ih = $imageWrapper.height(), 800 eb = et + ih, 801 threshold = ih * 3, 802 inView = eb >= wt - threshold && et <= wb + threshold; 803 804 if ( inView ) { 805 control.container.trigger( 'render-screenshot' ); 806 } 807 808 // If the image is in view return false so it's cleared from the queue. 809 return ! inView; 810 } ); 811 }, 812 813 /** 746 814 * Advance the modal to the next theme. 747 815 * … … 833 901 section.currentTheme = theme.id; 834 902 section.overlay.html( section.template( theme ) ) 835 836 903 .fadeIn( 'fast' ) 904 .focus(); 837 905 $( 'body' ).addClass( 'modal-open' ); 838 906 section.containFocus( section.overlay ); … … 1498 1566 this.params.attachment = this.params.defaultAttachment; 1499 1567 this.setting( this.params.defaultAttachment.url ); 1500 1568 }, 1501 1569 1502 1570 /** … … 1917 1985 api.section( control.section() ).showDetails( control.params.theme ); 1918 1986 }); 1987 1988 control.container.on( 'render-screenshot', function() { 1989 var $screenshot = $( this ).find( 'img' ), 1990 source = $screenshot.data( 'src' ); 1991 1992 if ( source ) { 1993 $screenshot.attr( 'src', source ); 1994 } 1995 }); 1919 1996 }, 1920 1997 … … 1926 2003 filter: function( term ) { 1927 2004 var control = this, 1928 1929 1930 1931 2005 haystack = control.params.theme.name + ' ' + 2006 control.params.theme.description + ' ' + 2007 control.params.theme.tags + ' ' + 2008 control.params.theme.author; 1932 2009 haystack = haystack.toLowerCase().replace( '-', ' ' ); 1933 2010 if ( -1 !== haystack.search( term ) ) { -
trunk/src/wp-includes/class-wp-customize-control.php
r32086 r32088 1249 1249 <# if ( data.theme.screenshot[0] ) { #> 1250 1250 <div class="theme-screenshot"> 1251 <img src="{{ data.theme.screenshot[0] }}" alt="" />1251 <img data-src="{{ data.theme.screenshot[0] }}" alt="" /> 1252 1252 </div> 1253 1253 <# } else { #>
Note: See TracChangeset
for help on using the changeset viewer.