Code Monkey home page Code Monkey logo

ember-tether's Introduction

Ember Tether Build Status Ember Observer Score

This ember-cli addon provides a component that allows for 'tethering' a block to a target somewhere else on the page. The target may be an element, an element selector, or an Ember view. Importantly, the component retains typical context for Ember action handling and data binding.

Live Demo

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

Installation

ember install ember-tether

Note: Ember CLI versions < 0.2.3 should use ember install:addon instead of ember install

Example Usage

Given the following DOM:

<body class="ember-application">
  <!-- Target must be in the same element as your ember app -->
  <!-- otherwise events/bindings on the tethered content will not work -->
  <div id="a-nice-person">
    Nice person
  </div>
  <div class="ember-view">
    <!-- rest of your Ember app's DOM... -->
  </div>
</body>

and a template like this:

{{#ember-tether
    target='#a-nice-person'
    targetAttachment='top right'
    attachment='top left'
}}
  A puppy
{{/ember-tether}}

Then "A puppy" would be rendered alongside the a-nice-person div.

If the ember-tether component is destroyed, its far-off content is destroyed too. For example, given:

{{#if isShowing}}
  {{#ember-tether
      target='#a-nice-person'
      targetAttachment='top right'
      attachment='top left'
  }}
    A puppy
  {{/ember-tether}}
{{/if}}

If isShowing starts off true and becomes false, then the "A puppy" text will be removed from the page.

Similarly, if you use ember-tether in a route's template, it will render its content next to the target element when the route is entered and remove it when the route is exited.

Acceptance Testing

Hubspot Tether works by appending tethered elements to the <body> tag. Unfortunately, this moves your content outside of the Ember application rootElement during acceptance testing. This breaks event dispatch and action handling, including traditional Ember test helpers like click.

In order to short-circuit Hubspot's positioning behavior, we must use static positioning on the #ember-testing-container div as follows:

tests/index.html
<style>
  #ember-testing-container {
    /* Set position static to short-circuit Hubspot Tether's positioning */
    /* https://github.com/HubSpot/tether/pull/98/ */
    position: static !important;
  }
</style>

Using ember-tether in Your Own Addon

ember-tether depends on Hubspot Tether, which is imported as a globals-style JS dependency. When using ember-tether directly in an Ember app, everything will work out of the box with no configuration necessary.

However, addons nested in other addons do not have access to app.import in their included hook and are therefore unable to import their own dependencies. This is not a problem unique to ember-tether.

The solution to this is to declare ember-tether as a peerDependency to ensure that it gets installed alongside your addon as a dependency of the root application. You'll likely also want it as a devDependency so that it's available during development and testing.

Development Setup

Installation

  • 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/.

Generating the Changelog

This project uses https://github.com/skywinder/github-changelog-generator to generate its changelog.

Credits

  • Hubspot Tether, the underlying library that implement the actual tethering behavior
  • ember-wormhole, whose pattern for element content manipulation inspired the approach in ember-tether
  • Tetherball, for providing countless hours of entertainment over the past century

ember-tether's People

Contributors

cball avatar chrislopresto avatar dfreeman avatar heroiceric avatar lukemelia avatar rwjblue avatar xtian avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.