ember-addons / bootstrap-for-ember

Bootstrap for Ember.js
http://ember-addons.github.io/bootstrap-for-ember
Apache License 2.0
704 stars 103 forks source link

improve toolltip code usage with mixins #166

Open patricklx opened 10 years ago

patricklx commented 10 years ago

Make the TooltipBoxController internal and some mixins for route and view. Then Instead of doing

//Create some controller in your app that references _Bootstrap.TooltipBoxController_
App.TooltipBoxController = Bootstrap.TooltipBoxController

//Application route
App.ApplicationRoute = Ember.Route.extend({
    renderTemplate: function() {
        // Render default outlet
        this.render();
        // render extra outlets
        var controller = this.controllerFor('tooltip-box');
        this.render("bs-tooltip-box", {
            outlet: "bs-tooltip-box",
            controller: controller,
            into: "application" // important when using at root level
        });
    }
});

We can just do

var ApplicationRoute = Ember.Route.extend(Bootstrap.BsTooltipRouteMixin, {});

or for views

Ember.View.extend(Bootstrap.BsTooltipViewMixin, {
    bsTooltipData: function () {
        return Ember.Object.create({
            item: this.get('item'),
            titleBinding: 'item.attributes.description'
        });
    }.property(),
    bsTooltipType: 'tooltip',
}