Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Add wrap examples
Browse files Browse the repository at this point in the history
  • Loading branch information
robdodson committed Jul 21, 2014
1 parent 67607e7 commit e3385da
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ The intent is to wrap all the DOM objects that interact with the DOM tree. For t

There are bound to be cases where we haven't done the wrapping for you. In those cases you can use `wrap` to create a wrapper of a native object, or `unwrap` to get the underlying native object from a wrapper. These two functions are available on the `ShadowDOMPolyfill` object.

ex:

wrap(document).addEventListener(...)
unwrap(div).firstChild instanceof HTMLElement

If you plan to work with elements that need to be wrapped over and over, try passing a wrapped version of the element into an immediately-invoked function expression.

(function(document) {
// Now a library like jQuery can add
// listeners to the wrapped document
$(document).on('click', function(e) {
console.log('Clicked on', e.target);
});

})(wrap(document));

#### Event Retargetting

An important aspect of the shadow DOM is that events are retargetted to never expose the shadow DOM to the light DOM. For example.
Expand Down

0 comments on commit e3385da

Please sign in to comment.