How to safely use jQuery UI widgets within Meteor?

jQuery UI is not yet a Meteor package, and even if it eventually becomes one of them, new versions of jQuery and jQuery UI and other jQuery plugins that can be used with Meteor will appear. There are many problems:

  • Download <script> tags or put js files in client or root directory?
  • Any problems finding scripts from CDN? Better stored locally (for example, in a "public" directory)?
  • Since $(document).ready() can be called before the Templates are displayed, where is the best way to call the various configuration functions that are usually called from .ready ()? Should they be called in Templates.<Name>.rendered so that if the DOM changes during template rendering, the various event handlers will be reattached to the new DOM nodes? Will this lead to memory leaks of old handlers that still exist to handle phantom nodes removed from the DOM?
  • If you are trying to modify model data based on an event callback from a jQuery UI widget (and this event is not supported based on Template Template events such as "click" or "dblclick"), this is the best way to identify collection data associated with the widgets during callback? Should you load the _id of an object into the DOM during Template..rendered and then read it back during the associated JQuery UI event handler? Are there any other methods?

Note that issues have changed from 0.5.0 on this , so some existing similar StackOverflow issues may be outdated (, also , also ).

If the example helps you answer, here is a working (?) Meteor project that combines jQuery Draggable and Droppable: http://products-jqueryui.meteor.com/ with a Source here based on the Tutorial here

("Safe" in my question, I mean that this will not cause devastating errors in the Meteor structure (or cause Meteor to break jQuery / jQuery UI), and also as efficiently as possible: avoid excessive DOM manipulation / rendering, excessive client / traffic server or memory leak.)

+4
source share
1 answer
  • Put them in the / client folder. Any javascript files will be automatically downloaded by Meteor and should be available when Meteor.startup occurs.
  • See my answer to question 1.
  • Use Meteor.startup instead of $ (document) .ready (), as this will be called when Meteor and the document are ready. If you want to execute the logic that the templates depend on, use Template.rendered because you want to re-execute the logic every time the template touches Meteor.
  • In the callback, this will refer to the current object.
+4
source

Source: https://habr.com/ru/post/1446359/


All Articles