How can I override a function from the modal.js file in the path vendor/magento/module-ui/view/base/web/js/modal/modal.js
?
In this file, line 307, is a function with name closeModal() that I want to overwrite in my module app/code/VendorName/ModuleName/view/frontend/web/js/model/modal.js
This is the original function:
closeModal: function () {
var that = this;
this._removeKeyListener();
this.options.isOpen = false;
this.modal.one(this.options.transitionEvent, function () {
that._close();
});
this.modal.removeClass(this.options.modalVisibleClass);
if (!this.options.transitionEvent) {
that._close();
}
return this.element;
},
In my modal.js
file I tried to write the following code so that the function is overwritten but unfortunately does not work.
define([
'jquery',
'Magento_Ui/js/modal/modal',
'mage/translate'
], function ($, modal, $t) {
'use strict';
return {
closeModal: function (element) {
console.log("override works");
}
};
});
Can you tell me please where is wrong and how can I override this function?
Thank you!
UPDATE:
My requirejs-config.js
has the following code:
var config = {
map: {
'*': {
'Magento_Ui/web/js/modal/modal':'Bhavin_GDPR/js/view/modal/modal'
}
}
};
I create a file with name modal.js
in the following path app/code/Bhavin/GDPR/view/frontend/web/js/view/modal/modal.js
Content modal.js
define([
'jquery',
'Magento_Ui/js/modal/modal',
'mage/translate'
], function ($, modal, $t) {
'use strict';
return {
closeModal: function (element) {
console.log("override works");
}
};
});