Skip to content

Instantly share code, notes, and snippets.

@arikon
Created February 1, 2014 16:35
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save arikon/8754786 to your computer and use it in GitHub Desktop.
Save arikon/8754786 to your computer and use it in GitHub Desktop.
jQuery plugin with bem-core
// If you are using borschik to expand links (bem make and enb do this for you)
// you could use this hack for any jQuery plugin found in the wild
modules.define('i-jquery__my-plugin', ['jquery'], function(provide, $){
var jQuery = $,
window = {jQuery: jQuery};
/*borschik:include:path/to/jquery-plugin.js*/
provide($);
});
@alexbaumgertner
Copy link

А почему не window. jQuery = jQuery?
Код window = {jQuery: jQuery}; вообще переопределяет window, или я что-то не улавливаю?

@aliosv
Copy link

aliosv commented Feb 13, 2014

@arikon, @alexbaumgertner, все верно, перетирая window можно отгрести проблемы, пример - фоторама, которая без реального window не работает.

@ilyar
Copy link

ilyar commented Jul 2, 2014

что скажите про такую декларацию jQuery-плагина?

modules.define('i-bem__dom', ['jquery'], function(provide, $, DOM) {
  window.jQuery = window.$ = $;
  /*borschik:include:../../libs/jquery-plugin/js/jquery-plugin.js*/
  provide(DOM);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment