0

How can I call giveAlert() function that's in newsletter.js from within landingpage.js?

landingpage.js

define([
    "jquery",
    "Ignite_Orgbf/js/js.cookie",
    "Ignite_Orgbf/js/newsletter",
    "domReady!",
    "magnificpopup"
], function($,Cookies, newsletter){
    "use strict";

    $.widget('custom.mbLandingPage', {
        _create: function() {
            newsletter.giveAlert();
            // DOESN'T WORK
...
...
...
    return $.custom.mbLandingPage;

newsletter.js

define([
    "jquery",
    "Ignite_Orgbf/js/js.cookie",
    "domReady!",
    "magnificpopup"
], function($,Cookies){
    "use strict";

    $.widget('custom.mbNewsPopup', {
        giveAlert: function(){
            alert("TEST");
        },
...
...
...
    return $.custom.mbNewsPopup;

2 Answers 2

0

Try $.custom.mbNewsPopup.giveAlert().

jQuery widgets should be available on the global jQuery object. Another method can be found on the jQuery docs here but this method relies on you invoking the widget on an element.

5
  • 1
    I've tried that and no go. Commented Nov 23, 2020 at 13:36
  • Damn. What happened when you tried?
    – Ben Crook
    Commented Nov 23, 2020 at 14:59
  • Uncaught TypeError: $.custom.mbNewsPopup.giveAlert is not a function Commented Nov 24, 2020 at 7:39
  • What does console.log($.custom.mbNewsPopup.giveAlert) show you?
    – Ben Crook
    Commented Nov 24, 2020 at 11:39
  • Gives an "undefined" Commented Nov 25, 2020 at 16:22
0

You can refer to my work below, where "updateQuote" is a jquery widget.

define([
    'jquery',
    'Magento_NegotiableQuote/quote/actions/update-quote'
], function ($, updateQuote) {
    'use strict';

    var mixin = {
        _sendData: function () {
            updateQuote()._updateTotal();
            return this._super();
        },
    };

    return function (targetWidget) {
        $.widget('mage.saveAsDraft', targetWidget, mixin);
        return $.mage.saveAsDraft;
    };
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.