Skip to content

Instantly share code, notes, and snippets.

@pjschreifels
Last active August 3, 2017 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjschreifels/fbc8983362e62a0629b0c57186c66429 to your computer and use it in GitHub Desktop.
Save pjschreifels/fbc8983362e62a0629b0c57186c66429 to your computer and use it in GitHub Desktop.
Bootstrap Popover using Aurelia customAttribute that fetches data from Firebase and inserts it into the popover content area using a dynamic Compose view.
<template>
<div class="dropdown-item ${items.isLoading ? '' : 'hide'}">
<p class="mb5"><i class="fa fa-refresh mr5"></i> Loading data...</p>;
</div>
<div class="dropdown-item" repeat.for="item of items">
<p class="mb5">
<span class="mr10">${item.__firebaseKey__}</span>
</p>
</div>
</template>
<template>
<form id="popover-menu-form">
<div class="form-group">
<label class="sr-only" for="organization-name">Organizations</label>
<input autocomplete="off" id="organization-name" class="form-control" placeholder="Organization name" type="text" bootstrap-popover="query: organizations" data-toggle="popover" title="Organizations" data-trigger="focus" />
</div>
<div class="form-group">
<label class="sr-only" for="organization-name">Users</label>
<input autocomplete="off" id="users-name" class="form-control" placeholder="Users name" type="text" bootstrap-popover="query: users" data-toggle="popover" title="Users" data-trigger="focus" />
</div>
</form>
</template>
import {customAttribute, TemplatingEngine, autoinject, bindable} from 'aurelia-framework';
import {ReactiveCollection} from 'aurelia-firebase'; // fork from github:dashofcode/aurelia-firebase@firebase-3
import $ from 'bootstrap'; // using bootstrap-v4-alpha
export class PopoverMenu {
}
@customAttribute('bootstrap-popover')
@autoinject
export class BootstrapPopover {
@bindable query: string;
viewModelInstance: any;
constructor(private element: Element, private templatingEngine: TemplatingEngine){
this.templatingEngine = templatingEngine;
}
bind() {
let _this = this;
_this.viewModelInstance = new ReactiveCollection(_this.query, true);
jQuery(this.element).popover({
template: '<div class="popover popover-menu" role="tooltip"><h3 class="popover-title"></h3><div class="popover-content"></div></div>',
offset: '-10px 35px',
html: true,
content: () => {
return '<compose view="_this.query+'-menu.html" model.bind="items"></compose>';
}
}).on('shown.bs.popover', () => {
// Reference and target the popover added to the DOM
var popoverID = jQuery(_this.element).attr('aria-describedby');
let popover = document.querySelector('#' + popoverID + '>.popover-content');
if (popover) {
if (!popover.querySelectorAll('.au-target').length) {
_this.templatingEngine.enhance({element: popover, bindingContext: _this.viewModelInstance});
}
}
});
}
unbind() {
jQuery(this.element).popover('dispose');
}
}
<template>
<div class="dropdown-item ${items.isLoading ? '' : 'hide'}">
<p class="mb5"><i class="fa fa-refresh mr5"></i> Loading data...</p>;
</div>
<div class="dropdown-item" repeat.for="item of items">
<p class="mb5">
<span class="mr10">${item.first_name} ${item.last_name}</span>
<span class="small text-muted mb5">${item.ssn}</span>
</p>
</div>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment