import Ember from 'ember';

export default Ember.Component.extend({

    classNameBindings: ['tooltip'],

    attributeBindings: ['title'],

    updateTitle: Ember.observer('title', function() {
      Ember.run.schedule('afterRender', this, function() {
        this.$().tooltipster('content', this.get('title'));
      });
    }),

    updateContent: Ember.observer('content', function(){
      Ember.run.schedule('afterRender', this, function() {
        this.$().tooltipster('content', this.get('content'));
      });
    }),

    /**
     * Set how tooltips should be activated and closed.
     * Default: 'hover'
     * Options: [hover, click]
     * @type {String}
     */
    triggerEvent: 'hover',

    tooltipsterOptions: ['animation', 'arrow', 'arrowColor', 'content', 'contentAsHTML', 'debug', 'delay', 'interactive',
        'minWidth', 'maxWidth', 'offsetX', 'offsetY', 'position', 'positionTracker', 'speed', 'timer', 'theme',
        'updateAnimation'
    ],

    _initializeTooltipster: Ember.on('didInsertElement', function() {
        var _this = this;
        var options = {};

        _this.get('tooltipsterOptions').forEach(function(item) {
            if (!Ember.isEmpty(_this.get(item))) {
                options[item] = _this.get(item);
            }
        });

        options.trigger = _this.get('triggerEvent');
        options.functionInit = Ember.$.proxy(this.functionInit, this);
        options.functionBefore = Ember.$.proxy(this.functionBefore, this);
        options.functionReady = Ember.$.proxy(this.functionReady, this);
        options.functionAfter = Ember.$.proxy(this.functionAfter, this);
        options.positionTrackerCallback = Ember.$.proxy(this.positionTrackerCallback, this);

        this.$().tooltipster(options);

    }),

    _destroyTooltipster: Ember.on('willDestroyElement', function() {
        this.$().tooltipster('destroy');
    }),
    /**
    * Send action ´open´ when open info
    *
    * @method functionBefore
    **/
    functionReady: function(origin, tooltip) {
        this.sendAction('open', tooltip);
    },

    /**
    * Send action close when close info
    *
    * @method functionBefore
    **/
    functionAfter: function(/*origin*/) {
        this.sendAction('close');
    }
});

@@ -21,16 +21,340 @@
 mber';%0A%0A
+/*%0A * Only calls fn if component is inDOM. Furthermore, binds fn to fnContext%0A */%0Avar callIfInDom = function(component, fn, fnContext) %7B%0A  var _this = fnContext %7C%7C component;%0A  var callback = fn %7C%7C Ember.K;%0A  return function() %7B%0A    if (component._state === 'inDOM') %7B%0A      callback.apply(_this, arguments);%0A    %7D%0A  %7D;%0A%7D;%0A%0A
 export d
@@ -1691,30 +1691,34 @@
 nInit = 
-Ember.$.proxy(
+callIfInDom(this, 
 this.fun
@@ -1768,30 +1768,34 @@
 efore = 
-Ember.$.proxy(
+callIfInDom(this, 
 this.fun
@@ -1846,30 +1846,34 @@
 Ready = 
-Ember.$.proxy(
+callIfInDom(this, 
 this.fun
@@ -1923,30 +1923,34 @@
 After = 
-Ember.$.proxy(
+callIfInDom(this, 
 this.fun
@@ -2014,22 +2014,26 @@
 k = 
-Ember.$.proxy(
+callIfInDom(this, 
 this

Fix tooltipster callback when component is destroyed