/* global Dropkick */
import Ember from 'ember';

export default Ember.Select.extend({

  _dk: null,
  settings: {},

  setUpDropKick: function() {
    var self = this,
      oldChange = this.get('settings.change');

    this.set('settings.change', function() {
      self.trigger('change');

      if (typeof oldChange === 'function') {
        oldChange.call(this);
      }
    });
  }.on('init'),

  updateDk: function() {
    if (this._dk !== null) {
      this._dk.select(this.get('value'));
    }
  }.observes('value'),

  createDk: function() {
    this._dk = new Dropkick(this.get('element'), this.get('settings'));
  }.on('didInsertElement'),

  destroyDk: function() {
    if (this._dk !== null) {
      this._dk.dispose();
    }
  }.on('willDestroyElement')

});

@@ -117,21 +117,12 @@
 %0A%0A  
-setUpDropKick
+init
 : fu
@@ -197,24 +197,65 @@
 .change');%0A%0A
+    this._super.apply(this, arguments);%0A%0A
     this.set
@@ -416,19 +416,8 @@
 %0A  %7D
-.on('init')
 ,%0A%0A 
@@ -422,24 +422,48 @@
 %0A  updateDk:
+ Ember.observer('value',
  function() 
@@ -548,40 +548,52 @@
 %0A  %7D
-.observes('value'),%0A%0A  createDk:
+),%0A%0A  createDk: Ember.on('didInsertElement',
  fun
@@ -681,46 +681,55 @@
 %0A  %7D
-.on('didInsertElement'),%0A%0A  destroyDk:
+),%0A%0A  destroyDk: Ember.on('willDestroyElement',
  fun
@@ -806,32 +806,8 @@
 %0A  %7D
-.on('willDestroyElement'
 )%0A%0A%7D

Remove prototype extensions