79235708

Date: 2024-11-29 02:46:37
Score: 1
Natty:
Report link

Maybe I will try to add a temporary variable.

let overlayEnabled = true;

function sizer(sz) {
    // a bunch of CSS to resize my content

    overlayEnabled = sz !== 'big';
}

$( "article" ).on("click", function(){
    if (!overlayEnabled) {
        return;
    }
    // build the contents of the overlay on-the-fly for this article
    var aside = $(this).find("aside");
    var o = $("#overlay");
    o.contents().remove(); //destroy old content
    o.append(aside[0].innerHTML); // add new content
    o.css("display","block");
});

or if you don't want a flag variable, you can set data attribute on the overlay.

function sizer(sz) {
    // a bunch of CSS to resize my content

    $("#overlay").attr('data-enabled', sz !== 'big')
}

$( "article" ).on("click", function(){
    const enabled = $("#overlay").attr('data-enabled');

    // notice: the type of enabled is string
    if (enabled === 'false') {
        return;
    }
    // rest of code
})
Reasons:
  • Blacklisted phrase (1): this article
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: zuomeng wang