Making WordPress.org

Changeset 13742

Timestamp:
05/22/2024 03:35:22 PM (2 months ago)
Author:
ryelle
Message:

wp-themes.com: Fully hide all other page content when showing pattern previews.

See https://github.com/WordPress/wordpress.org/pull/279

Location:
sites/trunk/wp-themes.com/public_html/wp-content/plugins/pattern-page
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wp-themes.com/public_html/wp-content/plugins/pattern-page/build/index.asset.php

    r12419 r13742  
    1 <?php return array('dependencies' => array(), 'version' => '9ace78423de40a3ac234');
     1<?php return array('dependencies' => array(), 'version' => '');
  • sites/trunk/wp-themes.com/public_html/wp-content/plugins/pattern-page/build/index.js

    r12419 r13742  
    1 (()=>{const e=t=>{for(var n=0;n<t.length;n++){var l=t[n];l.style.visibility="visible",l.children.length>0&&e(l.children)}};window.addEventListener("load",(()=>{var t=document.getElementById("wporg-pattern-preview");t&&(e(t.children),(e=>{let t=e;for(;t.parentElement;)t.parentElement.style.display="block",t=t.parentElement})(t),(e=>{const{top:t,height:n}=e.getBoundingClientRect();e.style.transform=`translate(0, -${t}px)`,n<window.innerHeight&&(e.style.height="100vh")})(t))}))})();
     1);
  • sites/trunk/wp-themes.com/public_html/wp-content/plugins/pattern-page/css/style.css

    r12349 r13742  
    1 * {
    2     visibility: hidden;
     1/* Hide everything outside of the pattern container */
     2:not(#wporg-pattern-preview *) {
     3    display: none;
    34}
    45
  • sites/trunk/wp-themes.com/public_html/wp-content/plugins/pattern-page/js/index.js

    r12419 r13742  
    1 /**
    2  * Loops through children of container and set visiblity to 'visible'.
    3  */
    4 const makeVisible = ( children ) => {
    5     for ( var i = 0; i < children.length; i++ ){
    6         var child = children[i];
    7         child.style.visibility = 'visible';
    8 
    9         if( child.children.length > 0 ) {
    10             makeVisible( child.children );
    11         }
    12     }
    13 }
    14 
    15 /**
    16  * Move the pattern to the top of the page.
    17  */
    18 const adjustOffset = ( element ) => {
    19     const { top, height } = element.getBoundingClientRect();
    20     element.style.transform = `translate(0, -${ top }px)`;
    21 
    22     // If the element is smaller than the window width, we'll center it
    23     if( height < window.innerHeight ) {
    24         element.style.height = '100vh';
    25     }
    26 }
    27 
    281/**
    292 * Since we are using a theme template, but hiding everything but 'wporg-pattern-preview',
    303 * we should erase layouts that could stop our element from displaying full width.
    314 * If we don't, we get previews that only take up half of the viewport.
    32  *
     5 *
    336 */
    347const setParentDisplay = ( element ) => {
     
    3710    while( currElement.parentElement ){
    3811        currElement.parentElement.style.display = 'block';
     12
     13
    3914
    4015        currElement = currElement.parentElement;
     
    4318
    4419/**
    45  * We set all elements to visibility: hidden in CSS and then turn visibility on for our pattern container.
    46  * This allows us to preview the page without any distractions, like header, footer, etc...
     20 * All elements outside of the preview container are hidden (with CSS, display: none),
     21 * to display just the pattern, so only the parent elements of the container
     22 * need to be unhidden.
    4723 */
    4824const init = () => {
    4925    var container = document.getElementById( 'wporg-pattern-preview' );
    5026
    51     if( ! container ) {
     27    if( ! container ) {
    5228        return;
    5329    }
    5430
    55     makeVisible( container.children );
    5631    setParentDisplay( container );
    57     adjustOffset( container );
    5832}   
    5933
Note: See TracChangeset for help on using the changeset viewer.