Skip to content

Commit

Permalink
Fix for require on hyva
Browse files Browse the repository at this point in the history
  • Loading branch information
supercid committed Feb 28, 2025
1 parent c764c42 commit ce55373
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
6 changes: 5 additions & 1 deletion view/frontend/requirejs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@
*
*/

const config = {
var config = {
map: {
'*': {
nostojs: 'Nosto_Tagging/js/nostojs',
recobuy: 'Nosto_Tagging/js/recobuy'
}
},
paths: {
'Nosto_Tagging/js/nostojs': 'Nosto_Tagging/js/nostojs',
'Nosto_Tagging/js/tagging-providers': 'Nosto_Tagging/js/tagging-providers'
}
};
14 changes: 6 additions & 8 deletions view/frontend/web/js/nostojs.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,16 @@
*
*/

(function (root) {
define('Nosto_Tagging/js/nostojs', [], function () {
'use strict';

// Initialize nostojs if not already present
var root = typeof self !== 'undefined' ? self : window;
if (typeof root.nostojs !== 'function') {
root.nostojs = function (cb) {
(root.nostojs.q = root.nostojs.q || []).push(cb);
};
}

if (typeof define === 'function' && define.amd) {
define([], function () {
return root.nostojs;
});
}
}(typeof self !== 'undefined' ? self : this));

return root.nostojs;
});
18 changes: 3 additions & 15 deletions view/frontend/web/js/tagging-providers.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
// noinspection JSUnresolvedReference

(function (root, factory) {
'use strict';

// Support both RequireJS and vanilla JS environments
if (typeof define === 'function' && define.amd) {
define(['Nosto_Tagging/js/nostojs'], factory);
} else {
// Browser globals: Create function directly
root.initNostoTaggingProviders = factory(root.nostojs);
}
}(typeof self !== 'undefined' ? self : this, function (nostojs) {
define('Nosto_Tagging/js/tagging-providers', ['Nosto_Tagging/js/nostojs'], function (nostojs) {
'use strict';

/**
* Initialize Nosto tagging providers
*
* Can be used in both RequireJS and vanilla JS contexts:
* - In Luma: require(['Nosto_Tagging/js/tagging-providers'], function(initTaggingProviders) { ... })
* - In Hyva (vanilla): As a global function
* - In Hyva (vanilla): As a global function window.initNostoTaggingProviders
*
* @param {Object} config The tagging configuration
*/
Expand Down Expand Up @@ -103,4 +91,4 @@
}

return initTaggingProviders;
}));
});

0 comments on commit ce55373

Please sign in to comment.