diff --git a/blocks-common/i-bem/__dom/_init/i-bem__dom_init.js b/blocks-common/i-bem/__dom/_init/i-bem__dom_init.js new file mode 100644 index 00000000..d9d37926 --- /dev/null +++ b/blocks-common/i-bem/__dom/_init/i-bem__dom_init.js @@ -0,0 +1,19 @@ +// Implementation from bem-core#2.5.0 + +/** + * @module i-bem__dom_init + */ + +(typeof modules === 'object') && modules.define('i-bem__dom_init', ['i-bem__dom'], function(provide, BEMDOM) { + + provide( + /** + * Initializes blocks on a fragment of the DOM tree + * @exports + * @param {jQuery} [ctx=scope] Root DOM node + * @returns {jQuery} ctx Initialization context + */ + function(ctx) { + return BEMDOM.init(ctx); + }); +}); diff --git a/blocks-common/i-bem/__dom/_init/i-bem__dom_init_auto.deps.js b/blocks-common/i-bem/__dom/_init/i-bem__dom_init_auto.deps.js new file mode 100644 index 00000000..be17cf80 --- /dev/null +++ b/blocks-common/i-bem/__dom/_init/i-bem__dom_init_auto.deps.js @@ -0,0 +1,5 @@ +({ + shouldDeps : [ + { mod : 'init' } + ] +}) diff --git a/blocks-common/i-bem/__dom/_init/i-bem__dom_init_auto.js b/blocks-common/i-bem/__dom/_init/i-bem__dom_init_auto.js index 399f10c3..c39c8f7d 100755 --- a/blocks-common/i-bem/__dom/_init/i-bem__dom_init_auto.js +++ b/blocks-common/i-bem/__dom/_init/i-bem__dom_init_auto.js @@ -1,6 +1,19 @@ -/* дефолтная инициализация */ -$(function() { - BEM.afterCurrentEvent(function() { - BEM.DOM.init(); +/** + * Auto initialization on DOM ready + */ + +// Support for YModules +if (typeof modules === 'object') { + // Implementation from bem-core#2.5.0 + modules.require(['i-bem__dom_init'], function(init) { + $(function() { + BEM.afterCurrentEvent(init); + }); }); -}); +} else { + $(function() { + BEM.afterCurrentEvent(function() { + BEM.DOM.init(); + }); + }); +} diff --git a/blocks-common/i-bem/__dom/i-bem__dom.js b/blocks-common/i-bem/__dom/i-bem__dom.js index 3da34b62..06a7fc04 100644 --- a/blocks-common/i-bem/__dom/i-bem__dom.js +++ b/blocks-common/i-bem/__dom/i-bem__dom.js @@ -1715,3 +1715,30 @@ $(function() { }); })(BEM, jQuery); + + +/** + * Support for YModules + */ +if (typeof modules === 'object') { + + modules.define('i-bem__dom', function(provide) { + provide(BEM.DOM); + }); + + // Implementation from bem-core#2.5.0 + (function() { + var origDefine = modules.define; + + modules.define = function(name, deps, decl) { + origDefine.apply(modules, arguments); + + if (name !== 'i-bem__dom_init' && arguments.length > 2 && ~deps.indexOf('i-bem__dom')) { + modules.define('i-bem__dom_init', [name], function(provide, _, prev) { + provide(prev); + }); + } + }; + })(); + +}