a dozen.5 Populate object which have DOM node references based on params and you may get back object

a dozen.5 Populate object which have DOM node references based on params and you may get back object

New params factor enacted to help you dom(), after that about the getOrMakeDom() varies from the form of factor which are enacted. The same as jQuery the type’s off value’s passed should be any one of many following:

The result of passing params is the framework regarding a string-in a position target which includes records so you can nodes (age

  • css selector sequence (elizabeth.grams. dom(‘body’))
  • html string (e.g. dom(‘




  • Feature node (elizabeth.g. dom(document.body))
  • assortment of element nodes (age.grams. dom([file.body]))
  • a beneficial NodeList (e.g. dom(document.human body.children))
  • a good HTMLcollection (elizabeth.grams. dom(file.all))
  • a beneficial dom() target in itself. (elizabeth.grams. dom(dom()))

g. <0:ELEMENT_NODE,1:ELEMENT_NODE,length:2>) either in the DOM or in a document fragment. Lets examine how each of the above parameters can be used to produce an object containing node references.

The fresh new logic to allow such numerous factor versions try found below in the code and you will starts with a straightforward check to ensure you to params is not undefined, an empty string, or a string having empty areas. If this sounds like the way it is we add a length property having a worth of 0 with the target made of getting in touch with GetOrMakeDOM and you will https://datingranking.net/music-dating/ come back the item so that the performance of the setting stops. In the event the params isn’t a bogus (or untrue such as) worthy of the execution of mode continues.

Next the params value, if a string, is checked to see if contains HTML. If the string contains HTML then a document fragment is created and the string is used as the innerHTML value for a

contained in the document fragment so that the string is converted to a DOM structure. With the html string converted to a node tree, the structure is looped over accessing top level nodes, and references to these nodes are passed to the object being created by GetOrMakeDom. If the string does not contain HTML execution of the function continues.

In the event the its a sequence selector, a good node list is established by contacting the latest queryselectorAll() strategy on the currentContext. In the event that its not a sequence selector we cycle across the html collection, node record, assortment, or object breaking down this new node sources and utilizing the latest recommendations due to the fact viewpoints within the target repaid out of contacting the newest GetOrMakeDom.

All of this reasoning inside of GetOrMakeDom() form is somewhat daunting just understand that the idea of your own constructor means would be to build an object with records so you’re able to nodes (age.g. ) and you can returns this object to help you dom().

a dozen.6 Manage per() approach and then make it a great chainable method

Whenever we invoke dom() we are able to availability things connected to dom.fn as a consequence of prototypical inheritance. (age.grams. dom().each()). Maybe not as opposed to jQuery strategies linked to dom.fn run-on the item created from this new GetOrMakeDom constructor means. The latest code below setups the newest each() strategy.

As you you will predict the latest for each and every() method takes good callback end up being the a factor and you may invokes the fresh mode (setting the latest that it value on the feature node object having name()) for each and every node factor in the new getOrMakeDom target like. The it really worth inside of the for each and every() mode is a reference to the getOrMakeDom target for example (elizabeth.g. ).

When a technique cannot get back an admiration (age.g. dom().duration output a range) its potential so that approach chaning by simply coming back the thing the process belongs as well unlike a particular worthy of. Generally, we’re returning the newest GetOrMakeDom target so some other approach should be entitled on this subject exemplory instance of the thing. Regarding password lower than I would like the fresh new for every() method to be chainable, meaning significantly more strategies is named immediately after getting in touch with for every(), therefore i just get back this. The latest so it regarding code below ‘s the target such created away from getting in touch with brand new getOrMakeDom form.