Plugin Directory

Changeset 2709451


Ignore:
Timestamp:
04/14/2022 12:15:36 AM (4 years ago)
Author:
diurno10
Message:

Fix bg color detector script

Location:
editor-beautifier/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • editor-beautifier/trunk/js/light-or-dark-bg.js

    r2669493 r2709451  
    22
    33function adjustTextColor() {
    4  
    5     element = document.getElementById('profile-bio');
     4
     5  element = document.getElementById('profile-bio');
    66  wpBlocks = document.querySelectorAll('.wp-block-group');
    7  
     7
    88  [].forEach.call(wpBlocks, function(wpBlock) {
    99    // Get the element's background color
    10       bgColor = window.getComputedStyle(wpBlock, null).getPropertyValue('background-color');
     10    bgColor = window.getComputedStyle(wpBlock, null).getPropertyValue('background-color');
    1111    console.log("bgColor",bgColor);
    1212    // Call lightOrDark function to get the brightness (light or dark)
     
    3535
    3636    // If RGB --> Convert it to HEX: http://gist.github.com/983661
    37     color = +("0x" + color.slice(1).replace( 
    38       color.length < 5 && /./g, '$&$&'
     37    color = +("0x" + color.slice(1).replace(
     38    color.length < 5 && /./g, '$&$&'
    3939    )
    40              );
     40       );
    4141
    4242    r = color >> 16;
     
    4747  // HSP (Highly Sensitive Poo) equation from http://alienryderflex.com/hsp.html
    4848  hsp = Math.sqrt(
    49     0.299 * (r * r) +
    50     0.587 * (g * g) +
    51     0.114 * (b * b)
     49  0.299 * (r * r) +
     50  0.587 * (g * g) +
     51  0.114 * (b * b)
    5252  );
    5353
     
    6161
    6262window.addEventListener('load', (event) => {
    63     adjustTextColor();
    64  
    65  
    66   const targetNode = document.querySelector(".wp-block-group");
     63
     64  adjustTextColor();
     65  const targetNodes = document.querySelectorAll(".wp-block-group");
    6766  const config = { childList: false, subtree: true ,attributes: true, attributeOldValue: true};
    6867
     
    7271        if(mutation.oldValue.startsWith("background-color")){
    7372          adjustTextColor();
    74         }     
     73        }
    7574      }
    7675    }
     
    7877
    7978  const observer = new MutationObserver(callback);
    80   observer.observe(targetNode, config);
     79
     80  [].forEach.call(targetNodes, function(targetNode) {
     81    observer.observe(targetNode, config);
     82  });
     83
    8184});
    82 
    83 
  • editor-beautifier/trunk/readme.txt

    r2613970 r2709451  
    4848== Changelog ==
    4949
     50= 2.1, Apr 13 2022 =
     51* Fix background color detector script
     52
    5053= 2.0, Oct 16 2021 =
    5154* Fix block-editors colors depending on background lightness
Note: See TracChangeset for help on using the changeset viewer.