Skip to content

Commit

Permalink
Merge pull request #22 from sir-dunxalot/feature/2.0-release
Browse files Browse the repository at this point in the history
Feature/2.0 release
  • Loading branch information
Duncan Walker committed Sep 16, 2015
2 parents 3faafa5 + 57af56d commit 5c20632
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ dist/
.npmignore
**/.gitkeep
bower.json
Brocfile.js
ember-cli-build.js
testem.json
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ env:
matrix:
fast_finish: true
allow_failures:
- env: EMBER_TRY_SCENARIO=ember-beta
- env: EMBER_TRY_SCENARIO=ember-canary

before_install:
Expand Down
16 changes: 0 additions & 16 deletions Brocfile.js

This file was deleted.

11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ Powered by <a href="http://darsa.in/tooltip/" target="_blank">darsain/tooltip (d
ember install ember-tooltips
```

## Compatibility Table

| Ember | Ember Tooltips |
|-------|----------------|
| 1.13 | 0.4.0 |
| 2.0 | 0.5.0 |

## Usage

Documentation for usage is below:
Expand Down Expand Up @@ -200,7 +207,7 @@ export default Ember.Component.extend({

### Customizing the Mixin

By default the `ember-tooltips` mixin is added to all views and components. This mixin contains the helper methods to render tooltips.
By default the `ember-tooltips` mixin is added to all components. This mixin contains the helper methods to render tooltips.

You can customize where the mixin is automatically added by overriding the `addTo` option in your `config/environment.js` file:

Expand All @@ -211,7 +218,7 @@ module.exports = function(environment) {
/* ... */

tooltips: {
addTo: ['View', 'Component'], // Ember.View, Ember.Component
addTo: ['Component'], // Ember.Component
}
}
};
Expand Down
50 changes: 40 additions & 10 deletions addon/mixins/components/tooltips.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,20 @@ export default Ember.Mixin.create({
}

/* Remove observer, even if it was never added */

this.removeObserver('tooltipVisibility', this, this.tooltipVisibilityDidChange);
this.removeObserver('tooltipContent', this, this.tooltipContentDidChange);
}),

/**
Adds a tooltip to the current view using the values of the tooltip
properties on the view or, if a `{{tooltip-on-parent}}` component is
passed, the values set on the component.
Adds a tooltip to the current component using the values of the tooltip
properties on this component's helper or, if a `{{tooltip-on-parent}}` component is
passed, the values set on that component.
In the latter case, the `{{tooltip-on-parent}}` block template will
be used for the tooltip content.
## Example 1 - Setting values on a view or component
## Example 1 - Setting values on a component
```hbs
{{#some-component tooltipContent='This will show' tooltipPlace='right'}}
Expand Down Expand Up @@ -113,6 +115,9 @@ export default Ember.Mixin.create({
let content = this.get('tooltipContent');
let tooltip, tooltipOptions;

const keys = Object.keys(this);
const hasTooltipContentProperty = (Ember.$.inArray('tooltipContent', keys) !== -1);

if (componentWasPassed) {
const componentContent = component.get('content');

Expand All @@ -123,7 +128,7 @@ export default Ember.Mixin.create({
}
}

if (!content) {
if (!content && !hasTooltipContentProperty) {
return;
}

Expand All @@ -148,21 +153,46 @@ export default Ember.Mixin.create({

this.set('tooltip', tooltip);

/* Bind observer if manual-triggering mode */
/* Bind observer if tooltipContent changes */

this.addObserver('tooltipContent', this, this.tooltipContentDidChange);

/* Bind observer if in manual-triggering mode */

if (tooltipOptions.event === 'manual') {
if (componentWasPassed) {
// Keep track of child tooltip component

/* Keep track of child tooltip component */

this.set('tooltipChildComponent', component);
// Turn 'tooltipVisibility' into a computed property, reading from child tooltip component's 'visibility' option

/* Turn 'tooltipVisibility' into a computed property, reading
from child tooltip component's 'visibility' option */

Ember.defineProperty(this, 'tooltipVisibility', Ember.computed.reads('tooltipChildComponent.visibility'));
}

this.addObserver('tooltipVisibility', this, this.tooltipVisibilityDidChange);
this.tooltipVisibilityDidChange();
}
}),

/**
Opens / closes tooltip based on value of 'tooltipVisibility'.
Updates the content value of the tooltip with value of 'tooltipContent'.
@method tooltipContentDidChange
*/

tooltipContentDidChange: function() {
const tooltip = this.get('tooltip');

if (tooltip) {
tooltip.content(this.get('tooltipContent'));
}
},

/**
Opens or closes tooltip based on value of 'tooltipVisibility'.
Only used when event is 'manual'.
@method tooltipVisibilityDidChange
Expand All @@ -179,7 +209,7 @@ export default Ember.Mixin.create({
},

/**
Call this method on any view to attach tooltips to all elements in its
Call this method on any component to attach tooltips to all elements in its
template that have a `.tooltip` class. Tooltip options are set using
data attributes.
Expand Down
23 changes: 15 additions & 8 deletions addon/utils/render-tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ A utility to attach a tooltip to a DOM element.
@submodule utils
@method renderTooltip
@param {Element} domElement The DOM element, not jQuery element, to attach the tooltip to
@param {Object} options The tooltip options to render the tooltip with. For supported options, see the tooltipSupportedProperties array in the views initializer
@param {Object} options The tooltip options to render the tooltip with
*/

import Ember from 'ember';

const Tooltip = window.Tooltip;
const { $, run } = Ember;

export default function renderTooltip(domElement = {}, options = {}) {
const typeClass = options.typeClass;
Expand All @@ -29,8 +30,9 @@ export default function renderTooltip(domElement = {}, options = {}) {
if (options.duration && typeof options.duration === 'string') {
options.duration = parseInt(options.duration, 10);

/* Remove invalid parseInt results */

if (isNaN(options.duration) || !isFinite(options.duration)) {
// Remove invalid parseInt results
options.duration = null;
}
}
Expand All @@ -40,20 +42,25 @@ export default function renderTooltip(domElement = {}, options = {}) {
tooltip.attach(domElement);

if (options.event !== 'manual') {
Ember.$(domElement)[options.event](function() {
$(domElement)[options.event](function() {
const willShow = tooltip.hidden;

tooltip.toggle();

// Clean previously queued removal (if present)
Ember.run.cancel(tooltip._hideTimer);
/* Clean previously queued removal (if present) */

run.cancel(tooltip._hideTimer);

if (willShow && options.duration) {
// Hide tooltip after specified duration
const hideTimer = Ember.run.later(function() {

/* Hide tooltip after specified duration */

const hideTimer = run.later(function() {
tooltip.hide();
}, options.duration);
// Save timer id for cancelling

/* Save timer ID for cancelling */

tooltip._hideTimer = hideTimer;
}
});
Expand Down
2 changes: 1 addition & 1 deletion app/initializers/ember-tooltips.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Tooltips from '../mixins/components/tooltips';

export function initialize() {
const defaultOptions = {
addTo: ['Component', 'View'],
addTo: ['Component'],
};
const overridingOptions = ENV.tooltips || {};
const options = Ember.merge(defaultOptions, overridingOptions);
Expand Down
18 changes: 9 additions & 9 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "ember-tooltips",
"dependencies": {
"ember": "1.13.2",
"ember-cli-shims": "ember-cli/ember-cli-shims#0.0.3",
"ember": "2.0.2",
"ember-cli-shims": "ember-cli/ember-cli-shims#0.0.5",
"ember-cli-test-loader": "ember-cli-test-loader#0.1.3",
"ember-data": "1.0.0-beta.18",
"ember-load-initializers": "ember-cli/ember-load-initializers#0.1.4",
"ember-qunit": "0.3.3",
"ember-data": "2.0.0",
"ember-load-initializers": "ember-cli/ember-load-initializers#0.1.7",
"ember-qunit": "0.4.10",
"ember-qunit-notifications": "0.0.7",
"ember-resolver": "~0.1.15",
"jquery": "^1.11.1",
"loader.js": "ember-cli/loader.js#3.2.0",
"qunit": "~1.17.1"
"ember-resolver": "~0.1.21",
"jquery": "^1.11.3",
"loader.js": "ember-cli/loader.js#3.2.1",
"qunit": "~1.18.0"
}
}
17 changes: 17 additions & 0 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* global require, module */
var EmberApp = require('ember-cli/lib/broccoli/ember-addon');

module.exports = function(defaults) {
var app = new EmberApp(defaults, {
// Add options here
});

/*
This build file specifes the options for the dummy test app of this
addon, located in `/tests/dummy`
This build file does *not* influence how the addon or the app using it
behave. You most likely want to be modifying `./index.js` or app's build file
*/

return app.toTree();
};
37 changes: 20 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
{
"name": "ember-tooltips",
"version": "0.4.0",
"description": "Renders and positions plain text tooltips and HTMLBars tooltips on any Ember view or component",
"version": "0.5.0",
"description": "The default blueprint for ember-cli addons.",
"directories": {
"doc": "doc",
"test": "tests"
},
"scripts": {
"start": "ember server",
"build": "ember build",
"start": "ember server",
"test": "ember try:testall"
},
"repository": "https://github.com/sir-dunxalot/ember-tooltips",
"repository": "",
"engines": {
"node": ">= 0.10.0"
},
"author": "",
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.0.2",
"ember-cli": "0.2.7",
"ember-cli-app-version": "0.3.3",
"broccoli-asset-rev": "^2.1.2",
"ember-cli": "1.13.8",
"ember-cli-app-version": "0.5.0",
"ember-cli-content-security-policy": "0.4.0",
"ember-cli-dependency-checker": "^1.0.0",
"ember-cli-ic-ajax": "0.1.1",
"ember-cli-inject-live-reload": "^1.3.0",
"ember-cli-qunit": "0.3.13",
"ember-cli-uglify": "^1.0.1",
"ember-data": "1.0.0-beta.18",
"ember-disable-prototype-extensions": "^1.0.0",
"ember-cli-dependency-checker": "^1.0.1",
"ember-cli-htmlbars-inline-precompile": "^0.2.0",
"ember-cli-ic-ajax": "0.2.1",
"ember-cli-inject-live-reload": "^1.3.1",
"ember-cli-qunit": "^1.0.0",
"ember-cli-release": "0.2.3",
"ember-cli-sri": "^1.0.3",
"ember-cli-uglify": "^1.2.0",
"ember-data": "2.0.0",
"ember-disable-proxy-controllers": "^1.0.0",
"ember-export-application-global": "^1.0.2",
"ember-export-application-global": "^1.0.3",
"ember-disable-prototype-extensions": "^1.0.0",
"ember-try": "0.0.6"
},
"keywords": [
Expand All @@ -42,8 +45,8 @@
"htmlbars"
],
"dependencies": {
"ember-cli-babel": "^5.0.0",
"ember-cli-htmlbars": "0.7.6"
"ember-cli-babel": "^5.1.3",
"ember-cli-htmlbars": "0.7.9"
},
"ember-addon": {
"configPath": "tests/dummy/config"
Expand Down
5 changes: 3 additions & 2 deletions tests/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"node": false,
"browser": false,
"boss": true,
"curly": false,
"curly": true,
"debug": false,
"devel": false,
"eqeqeq": true,
Expand All @@ -52,5 +52,6 @@
"strict": false,
"white": false,
"eqnull": true,
"esnext": true
"esnext": true,
"unused": true
}
15 changes: 0 additions & 15 deletions tests/dummy/app/initializers/views.js

This file was deleted.

1 change: 0 additions & 1 deletion tests/helpers/async/assert-tooltip-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export default Ember.Test.registerAsyncHelper('assertTooltipProperties',
const tooltip = Ember.$('.tooltip')[0];
const indexOfEffectClass = tooltip.className.indexOf(expectedEffectClass);
const indexOfTypeClass = tooltip.className.indexOf(expectedTypeClass);
const style = tooltip.style;

assert.ok(!!tooltip,
'The tooltip should be added to the DOM after triggering the show event on the target element');
Expand Down
Loading

0 comments on commit 5c20632

Please sign in to comment.