JS Gists
To add JS resource to catalog module
add Magento_Catalog/web/js/custom.js file
-------------------------------------------------
define('jquery', function($) {
$.fn.HelloWorld = function() {
console.log("Hello Firstfound");
$(".page-title").hover(function () {
$(".page-title").css('background-color', 'orange');
});
}
}(jQuery)
);
--------------------------------------------------------------------------
add file Magento_Catalog/requirejs-config.js
var config = {
map: {
'*' : {
'hello' : 'Magento_Catalog/js/custom'
}
}
};
----------------------------------------------------------
Add file Magento_Catalog/templates/product/js.phtml
<script>// <![CDATA[
require([
'jquery',
'hello'
], function ($) {
$('.product-info-main').HelloWorld();
});
// ]]>
</script>
/* <div id="modal">
<div id="msg" style="display: none">Modal contents</div>
<button class="modalRun">Run action</button>
</div>
*/
<script>
require([
'jquery',
'Magento_Ui/js/modal/alert'
],
function($, alert){
$('#modal').on('click', 'button.modalRun', function (event) {
event.preventDefault();
alert({
content: $(event.target).parent().children('#msg').text()
})
})
});
</script>