From 7f91c5cfcf558e65fb2b1c94d2314c16af7cff13 Mon Sep 17 00:00:00 2001 From: patricklx Date: Sat, 16 Aug 2014 19:55:23 +0100 Subject: [PATCH] improve toolltip code usage with mixins --- app/scripts/components/BsPopover.coffee | 53 +++++++++++++++---------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/app/scripts/components/BsPopover.coffee b/app/scripts/components/BsPopover.coffee index c66ef4a..9782a9d 100644 --- a/app/scripts/components/BsPopover.coffee +++ b/app/scripts/components/BsPopover.coffee @@ -204,26 +204,6 @@ Bootstrap.BsTooltipComponent = Bootstrap.BsPopoverComponent.extend( Ember.Handlebars.helper 'bs-tooltip', Bootstrap.BsTooltipComponent - - - - - - - - - - - -### -The tooltipBox controller is used to render the popovers into the named outlet "bs-tooltip-box" -with the template tooltip-box -### -Bootstrap.TooltipBoxController = Ember.Controller.extend( - popoversBinding: "Bootstrap.TooltipBoxManager.popovers" - tooltipsBinding: "Bootstrap.TooltipBoxManager.tooltips" -) - template = "" + "{{#each pop in popovers}}" + " {{bs-popover" + @@ -428,6 +408,39 @@ Bootstrap.TooltipBoxManager = Ember.Object.create( object ) +Bootstrap.TooltipBoxController = Ember.Controller.create( + popoversBinding: "Bootstrap.TooltipBoxManager.popovers" + tooltipsBinding: "Bootstrap.TooltipBoxManager.tooltips" +) + +#provide mixins that can be used in the application + +Bootstrap.BsTooltipRouteMixin = Ember.Mixin.create( + bsTooltipRenderInto: "application" # important when using at root level + renderTemplate: -> + + # Render default outlet + @_super() + + # render extra outlets + controller = Bootstrap.TooltipBoxController + @render "bs-tooltip-box", + outlet: "bs-tooltip-box" + controller: controller + into: @get("bsTooltipRenderInto") + + return +) + +Bootstrap.BsTooltipViewMixin = Ember.Mixin.create( + attributeBindings: [Bootstrap.TooltipBoxManager.attribute] + didInsertElement: -> + data = @get("bsTooltipData") + type = @get("bsTooltipType") + Bootstrap.TooltipBoxManager.addFromView this, type, data + return +) + Ember.Handlebars.registerHelper "bs-bind-popover", (path) -> options = arguments[arguments.length - 1] object = this