Skip to content

Commit

Permalink
User-defined defaults (#11)
Browse files Browse the repository at this point in the history
* added app wide options via emberAttacher: {...} in app/config/environment.js
  • Loading branch information
enkol authored and kybishop committed May 18, 2017
1 parent c71358e commit 136b3dc
Showing 1 changed file with 59 additions and 15 deletions.
74 changes: 59 additions & 15 deletions addon/components/ember-attacher.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,37 @@ import Ember from 'ember';
import layout from '../templates/components/ember-attacher';
import { stripInProduction, warn } from '../-debug/helpers';

const { get, set, getOwner } = Ember;

const DEFAULTS = {
animation: 'fill',
arrow: false,
hideDelay: 0,
hideDuration: 300,
hideOn: 'mouseleave blur',
interactive: false,
isOffset: false,
placement: 'top',
popperClass: null,
popperContainer: document.body,
popperOptions: null,
renderInPlace: false,
showDelay: 0,
showDuration: 300,
showOn: 'mouseenter focus',
}

export default Ember.Component.extend({
layout,

/**
* ================== PUBLIC CONFIG OPTIONS ==================
*/

animation: 'fill',
animation: DEFAULTS.animation,
arrow: Ember.computed('animation', {
get() {
return false;
return DEFAULTS.arrow;
},

set(_, val) {
Expand All @@ -25,19 +45,19 @@ export default Ember.Component.extend({
return val;
}
}),
hideDelay: 0,
hideDuration: 300,
hideOn: 'mouseleave blur',
interactive: false,
isOffset: false,
placement: 'top',
popperClass: null,
popperContainer: document.body,
popperOptions: null,
renderInPlace: false,
showDelay: 0,
showDuration: 300,
showOn: 'mouseenter focus',
hideDelay: DEFAULTS.hideDelay,
hideDuration: DEFAULTS.hideDuration,
hideOn: DEFAULTS.hideOn,
interactive: DEFAULTS.interactive,
isOffset: DEFAULTS.isOffset,
placement: DEFAULTS.placement,
popperClass: DEFAULTS.popperClass,
popperContainer: DEFAULTS.popperContainer,
popperOptions: DEFAULTS.popperOptions,
renderInPlace: DEFAULTS.renderInPlace,
showDelay: DEFAULTS.showDelay,
showDuration: DEFAULTS.showDuration,
showOn: DEFAULTS.showOn,
target: Ember.computed(function() {
return this.element.parentNode;
}),
Expand Down Expand Up @@ -65,4 +85,28 @@ export default Ember.Component.extend({

return options;
}),

init() {
this._super(...arguments);

let config = getOwner(this).resolveRegistration('config:environment')
let options = config.emberAttacher;

// If no emberAttacher hash was found, do nothing
if (options) {
let attrs = get(this, 'attrs');

for(let key in options) {

// Only known properties are allowed, ignore otherwise
if (DEFAULTS.hasOwnProperty(key)) {

// Use option from environment, but only if not given as component attribute
if (attrs[key] === undefined) {
set(this, key, options[key]);
}
}
}
}
}
});

0 comments on commit 136b3dc

Please sign in to comment.