Kris Jones
02/04/2019, 5:14 PMconsole.log
etc) but for whatever reason I could not get any click events to fire. Is what I'm trying to do possible? Or am I just attacking it incorrectly? Thanks for any help!lukeabbott
02/04/2019, 5:16 PMlukeabbott
02/04/2019, 5:16 PMKris Jones
02/04/2019, 5:26 PMKris Jones
02/04/2019, 5:27 PMKris Jones
02/04/2019, 5:34 PMsetTimeout
ever fires, even with a long (5s+) delayjkabot
02/04/2019, 5:34 PMKris Jones
02/04/2019, 5:35 PMconsole.log($(".order-info-minimize-ship"));
console.log($(".order-info-minimize-unship"));
setTimeout(function() {
console.log("we survived the timeout!");
$(".order-info-minimize-ship").click(function() {
if($(".shippable-order-container").css("display") === "none") {
$(".shippable-order-container").css("display", "flex");
$(this).text("Hide Orders");
} else {
$(".shippable-order-container").css("display", "none");
$(this).text("Show Orders");
}
});
$(".order-info-minimize-unship").click(function() {
if($(".unshippable-order-container").css("display") === "none") {
$(".unshippable-order-container").css("display", "flex");
$(this).text("Hide Orders");
} else {
$(".unshippable-order-container").css("display", "none");
$(this).text("Show Orders");
}
});
}, 1000);
The above is minimized and included at the end of the html that's assigned to portlet.html
Kris Jones
02/04/2019, 5:36 PMjkabot
02/04/2019, 5:36 PMKris Jones
02/04/2019, 5:36 PMjkabot
02/04/2019, 5:38 PMKris Jones
02/04/2019, 5:40 PMjkabot
02/04/2019, 5:41 PMzach_calh
02/04/2019, 5:47 PMzach_calh
02/04/2019, 5:49 PM<script>jQuery(function($){require([], function(){" + jsCodeAsString + ";})})</script>
Kris Jones
02/04/2019, 5:58 PMjsCodeAsString
to show up, even the first console.logKris Jones
02/04/2019, 5:58 PM'<script>$(function($){require([], function(){console.log("I swear I am not crazy...");setTimeout(function(){console.log("we survived the timeout!"); $(".order-info-minimize-ship").click(function(){if($(".shippable-order-container").css("display")==="none"){$(".shippable-order-container").css("display", "flex"); $(this).text("Hide Orders");}else{$(".shippable-order-container").css("display", "none"); $(this).text("Show Orders");}}); $(".order-info-minimize-unship").click(function(){if($(".unshippable-order-container").css("display")==="none"){$(".unshippable-order-container").css("display", "flex"); $(this).text("Hide Orders");}else{$(".unshippable-order-container").css("display", "none"); $(this).text("Show Orders");}});}, 1000);})})();</script>'
Kris Jones
02/04/2019, 5:59 PM$ = jQuery
)jkabot
02/04/2019, 6:15 PM$(your function)
runs your function once the entire html document has been parsed
if you can get the script into your html document and it's not working, it's probably simpler to drop jquery and just use vanilla event handlers (especially isnce you are just toggling a css value)Kris Jones
02/04/2019, 6:16 PMjkabot
02/04/2019, 6:17 PMjkabot
02/04/2019, 6:25 PM<script>
function toggleShippableOrderContainer(div) {
var container = document.querySelector('.shippable-order-container');
var isDisplay = getComputedStyle(container).display === 'flex';
container.style.display = isDisplay ? 'none' : 'flex';
div.textContent = isDisplay ? 'Hide Orders' : 'Show Orders';
}
</script>
<div class=".order-info-minimize-ship" onclick="toggleShippableOrderContainer(this);">
...
jkabot
02/04/2019, 6:27 PMzach_calh
02/04/2019, 6:27 PMzach_calh
02/04/2019, 6:28 PMzach_calh
02/04/2019, 6:28 PMKris Jones
02/04/2019, 6:38 PMzach_calh
02/04/2019, 6:59 PMKris Jones
02/04/2019, 7:04 PMKris Jones
02/04/2019, 7:05 PMportlet.defaultValue
as a sort of pseudo-html field?Kris Jones
02/04/2019, 7:05 PMjkabot
02/04/2019, 7:25 PMzach_calh
02/04/2019, 7:28 PMzach_calh
02/04/2019, 7:29 PMzach_calh
02/04/2019, 7:29 PMzach_calh
02/04/2019, 7:30 PMzach_calh
02/04/2019, 7:30 PMfield.defaultValue
to set the htmlKris Jones
02/04/2019, 9:11 PM