bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

feat(popover): support template url for partial

Open mjp0 opened this issue 13 years ago • 328 comments

As requested in #202 by @joshdmiller here's my request for external partial support for popover which would make popover much more versatile and lower the need of duplicate code in the apps. Already working implementation can be found in one of the "competing" Bootstrap implementations at http://mgcrea.github.com/angular-strap/#/popover.

mjp0 avatar Mar 13 '13 04:03 mjp0

I'm thinking just <a popover popover-template="{{templateUrl}}">Open Me</a> would work well.

The issue we'll need to solve for, however, is getting the scope right. The tooltip and popover use child directives with isolate scopes, so we may have to do some transclusion magic to get this to work as expected. Thoughts?


FWIW - AngularStrap isn't really a "competing implementation" as it's not an "implementation" at all - it just wraps the original jQuery. We can't really translate what they do back here; we really have to re-engineer the original Bootstrap plugins to be in line with the "Angular Way".

joshdmiller avatar Mar 13 '13 04:03 joshdmiller

I have to confess that I'm not familiar enough to give you any advice on scope. My directives so far has been so basic that I haven't had to deal with them, or transclusion. But I think that transclusion might be problematic if you need A LOT of popovers for different elements. I'm not worried that much about desktop but tablets worry me when it comes to doing a lot of binding etc.

mjp0 avatar Mar 15 '13 05:03 mjp0

Hi, I took a look into the last commits. The tooltip has the option of loading external content now. In the demo files I could not find any reference to that for popover. Does this work at well?

jhiemer avatar Apr 04 '13 09:04 jhiemer

@jhiemer The tooltip now supports putting HTML into the tooltip text to be unsafely included into the template. The popover doesn't. However, this issue is for external templating or partial support for the popover. i.e.:

<a tooltip-html-unsafe="<strong>Hello!</strong">Hover!</a>

versus

<button popover-template="'partial.tpl.html'">Click me!</button>

It doesn't make any sense, I don't think, to do partials for tooltips, but we can do HTML content in the popover with a fairly simple code change.

joshdmiller avatar Apr 04 '13 17:04 joshdmiller

@joshdmiller I think doing partials for tooltips is not necessary as well. Perhaps there might be some usecases, but the main usage scenarios will cover just plain text. For the popover instead I see many different usage scenarios. For example I got a date picker, which could be put into the popover as well as a color picker.

Which changes would be necessary?

jhiemer avatar Apr 04 '13 17:04 jhiemer

@joshdmiller any update on this?

jhiemer avatar Apr 10 '13 07:04 jhiemer

@jhiemer Sorry - I remember responding to this days ago... insanity can be inconvenient.

To implement an independent template, we need to decide on a few things:

Syntax

I think something like this:

<button popover popover-template="'partial.tpl.html'">Click me!</button>

Template

The popover default is this:

<div class="popover {{placement}}" ng-class="{ in: isOpen(), fade: animation() }">
  <div class="arrow"></div>

  <div class="popover-inner">
      <h3 class="popover-title" ng-bind="title" ng-show="title"></h3>
      <div class="popover-content" ng-bind="content"></div>
  </div>
</div>

Should we just, in essence, transclude the contents into the popover-inner element? Or is that too generic? We could also do it in popover-content to keep the default popover design from Twitter.

Scope

In which scope is the template compiled? A new sibling of the directive makes sense to me.

joshdmiller avatar Apr 11 '13 04:04 joshdmiller

@joshdmiller thanks for getting back at this. Essentially I think the provided code could be what I am looking for. I created two examples of small directives which I would like to put into a popover and which you can see here: http://plnkr.co/PQOWFO and here: http://plnkr.co/99HHNd.

Both cases would need to access the parent scope. This issue https://github.com/angular-ui/bootstrap/issues/315, is reaching for something similar I guess.

jhiemer avatar Apr 11 '13 06:04 jhiemer

@joshdmiller do you have a working version of your changes where I might take a look at?

jhiemer avatar Apr 16 '13 08:04 jhiemer

any news on this one ?

ffesseler avatar Apr 23 '13 08:04 ffesseler

+1

jhiemer avatar Apr 24 '13 11:04 jhiemer

I just opened a PR for the custom triggers and it changes the $tooltip service somewhat significantly so I won't push this until that PR goes through. But for those curious, here's a rough implementation: http://plnkr.co/edit/RTpGfZG0cl069nkqmm14?p=preview

joshdmiller avatar Apr 27 '13 05:04 joshdmiller

@joshdmiller took a look at it. When I create a real template file, the contents still renders as mypopover.tpl.html so it does not seem to get loaded. Could that be right?

jhiemer avatar Apr 27 '13 10:04 jhiemer

Damn! There seems to a bug in Plunker - I lost a ton of work! I opened a bug report - filearts/plunker#39.

Anyway, here it is re-created: http://plnkr.co/edit/JgeUP0anaU4BmsS5cJNh?p=preview. Can you give it another go?

joshdmiller avatar Apr 27 '13 19:04 joshdmiller

@joshdmiller this doesn't seem to work for me, I'm getting "Error: selectors not implemented"...

pkozlowski-opensource avatar Apr 27 '13 20:04 pkozlowski-opensource

I'm not surprised it doesn't work - there are files missing! Now I'm very frustrated. Plunker's not keeping my most recent changes. This has happened twice now on this same issue - and I re-created it from scratch!

I re-created the changes once again, but it still won't save the changes I'm making even though it tells me it does. I'll just submit a PR later and we can go from there...

joshdmiller avatar Apr 27 '13 20:04 joshdmiller

Yeh, this happened to me couple of times as well... Now I'm using plunker for rather simple experiments only...

pkozlowski-opensource avatar Apr 27 '13 20:04 pkozlowski-opensource

Great, waiting for it @joshdmiller. After you submitted it I will review it asap.

jhiemer avatar Apr 27 '13 20:04 jhiemer

Has anyone had a change to look at #369?

joshdmiller avatar May 03 '13 21:05 joshdmiller

Hi, taking a detailed look at it today!

jhiemer avatar May 04 '13 07:05 jhiemer