Detalhes do pacote

ember-wormhole

yapplabs164.9kMIT0.6.0

Render a child view somewhere else in the DOM.

ember-addon

readme (leia-me)

Ember Wormhole Build Status Ember Observer Score

This addon provides a component that allows for rendering a block to a DOM element somewhere else on the page. The component retains typical Ember context in terms of bound data and action handling. Ember Wormhole is compatible with Ember FastBoot as of version 0.4.0, so long as the destination element is part of Ember's own templates.

Live Demo

View a live demo here: http://yapplabs.github.io/ember-wormhole/

The source code for the demo is available here: https://github.com/yapplabs/ember-wormhole/tree/master/tests/dummy/app

But Why?

This library is particularly useful for cases where you have UI that is the logical child of a component but needs to render as a top-level DOM element, such as a confirmation dialog.

And How?

This component tracks its element's child nodes. When inserted into the DOM, it appends its child nodes to a destination element elsewhere. When removed from the DOM, it removes its child nodes, so as not to orphan them on the other side of the wormhole.

Nothing else changes -- data binding and action bubbling still flow according to the Ember component hierarchy. That includes usages of yield, so blocks provided to ember-wormhole simply appear in another part of the DOM.

Show Me Some Code!

We thought you'd never ask...

Given the following DOM:

<body class="ember-application">
  <!-- Destination must be in the same element as your ember app -->
  <!-- otherwise events/bindings will not work -->
  <div id="destination">
  </div>
  <div class="ember-view">
    <!-- rest of your Ember app's DOM... -->
  </div>
</body>

and a template like this:

{{#ember-wormhole to="destination"}}
  Hello world!
{{/ember-wormhole}}

Then "Hello world!" would be rendered inside the destination div.

If the ember-wormhole is destroyed its far-off children are destroyed too. For example, given:

{{#if isWormholeEnabled}}
  {{#ember-wormhole to="destination"}}
    Hello world!
  {{/ember-wormhole}}
{{/if}}

If isWormholeEnabled starts off true and becomes false, then the "Hello world!" text will be removed from the destination div.

Similarly, if you use ember-wormhole in a route's template, it will render its children in the destination element when the route is entered and remove them when the route is exited.

Can I Render In Place (i.e. Unwormhole)?

Yes! Sometimes you feel like a wormhole. Sometimes you don't. Situations sometimes call for the same content to be rendered through the wormhole or in place.

In this example, renderInPlace will override to and cause the wormhole content to be rendered in place.

{{#ember-wormhole to="destination" renderInPlace=true}}
  Hello world!
{{/ember-wormhole}}

This technique is useful for:

  • Presenting typically-wormholed content within a styleguide
  • Toggling content back and forth through the wormhole
  • Parlor tricks

What if if my element has no id?

You can provide an element directly to the wormhole. For example:

{{#ember-wormhole destinationElement=someElement}}
  Hello world!
{{/ember-wormhole}}

This usage may be appropriate when using wormhole with dynamic targets, such as rendering into all elements matching a selector.

What Version of Ember is This Compatible With?

This library is compatible with and tested against Ember 1.13 and higher.

Important Note about using this library with Ember 2.10

With latest ember-wormhole and ember@2.10, you need to have a stable root element inside the wormhole block. This is something that the Ember Core team will continue to iterate and work on, but for now the work around is fairly straightforward.

Change:

{{#ember-wormhole to="worm"}}
  {{#if foo}}

  {{/if}}
  <p>Other content, whatever</p>
{{/ember-wormhole}}
To:

{{#ember-wormhole to="worm"}}
  <div>
    {{#if foo}}

    {{/if}}
    <p>Other content, whatever</p>
  </div>
{{/ember-wormhole}}

Development Setup

Simple Installation

To add the ember-wormhole add-on to an existing project, enter this command from the root of your EmberJS project:

  • ember install ember-wormhole

Setting Up The Demo

If you'd like to set up a new EmberJS application with the ember-wormhole sample application configured, follow these steps:

  • git clone this repository
  • npm install
  • bower install

Running Tests

  • ember try:testall
  • ember test
  • ember test --server

Running the dummy app

For more information on using ember-cli, visit http://www.ember-cli.com/.

Credits

This addon was extracted from ember-modal-dialog. Contributions from @stefanpenner, @krisselden, @chrislopresto, @lukemelia, @raycohen and others. Yapp Labs is an Ember.js consultancy based in NYC.

changelog (log de mudanças)

Change Log

0.5.4 (2018-09-20)

Full Changelog

Merged pull requests:

0.5.4 (2017-12-09)

Full Changelog

Merged pull requests:

0.5.3 (2017-11-22)

Full Changelog

Merged pull requests:

0.5.2 (2017-06-12)

Full Changelog

Merged pull requests:

0.5.1 (2016-11-10)

Full Changelog

Merged pull requests:

  • Fix some issues with Glimmer2 usage. #75 (rwjblue)

0.5.0 (2016-10-18)

Full Changelog

Merged pull requests:

  • [Glimmer2] Use the document service for glimmer #73 (chadhietala)
  • Update ember-cli to 2.8.0 and associated dependencies and files. #72 (runspired)
  • Test for dynamic content in Glimmer2 #68 (simonihmig)

0.4.1 (2016-09-12)

Full Changelog

Merged pull requests:

  • Use getDOM util to get dom reference in glimmer2 #65 (bantic)
  • [DOC] Add Ember version compatibility to README #63 (lukemelia)
  • Use native doc.getElementById when available #61 (bantic)
  • Test ember-alpha in CI. #60 (rwjblue)

0.4.0 (2016-06-08)

Full Changelog

Merged pull requests:

  • Fix initializer arity deprecation #56 (bantic)
  • Remove needsBindAttr from x-favicon component in tests #55 (bantic)
  • Refactor to public APIs for head/tail #54 (mixonic)
  • Update ember-cli 1.13.7 to 2.5.1 #53 (mixonic)

0.3.6 (2016-06-02)

Full Changelog

Merged pull requests:

  • Avoid bind-attr in tests for newer Ember #51 (bantic)
  • Update ember-code-snippet to ^1.3.0 #50 (bantic)

0.3.5 (2016-02-01)

Full Changelog

Merged pull requests:

0.3.4 (2015-07-26)

Full Changelog

Merged pull requests:

0.3.3 (2015-06-24)

Full Changelog

0.3.2 (2015-06-24)

Full Changelog

Merged pull requests:

  • fix issue when firstNode is the same as lastNode #15 (piotrpalek)

0.3.1 (2015-04-28)

Full Changelog

Merged pull requests:

0.2.1 (2015-04-17)

Full Changelog

0.2.0 (2015-04-17)

Full Changelog

Merged pull requests:

0.1.0 (2015-04-05)

* This Change Log was automatically generated by github_changelog_generator