Razique Mahroua
2019-11-28 1759c24ad2d2b35ec5c756e3dd3a60185fe944b7
commit | author | age
1759c2 1 /**
RM 2  * angular-strap
3  * @version v2.0.3 - 2014-05-30
4  * @link http://mgcrea.github.io/angular-strap
5  * @author Olivier Louvignes (olivier@mg-crea.com)
6  * @license MIT License, http://www.opensource.org/licenses/MIT
7  */
8 'use strict';
9 angular.module('mgcrea.ngStrap.popover', ['mgcrea.ngStrap.tooltip']).provider('$popover', function () {
10   var defaults = this.defaults = {
11       animation: 'am-fade',
12       container: false,
13       target: false,
14       placement: 'right',
15       template: 'popover/popover.tpl.html',
16       contentTemplate: false,
17       trigger: 'click',
18       keyboard: true,
19       html: false,
20       title: '',
21       content: '',
22       delay: 0
23     };
24   this.$get = [
25     '$tooltip',
26     function ($tooltip) {
27       function PopoverFactory(element, config) {
28         // Common vars
29         var options = angular.extend({}, defaults, config);
30         var $popover = $tooltip(element, options);
31         // Support scope as string options [/*title, */content]
32         if (options.content) {
33           $popover.$scope.content = options.content;
34         }
35         return $popover;
36       }
37       return PopoverFactory;
38     }
39   ];
40 }).directive('bsPopover', [
41   '$window',
42   '$location',
43   '$sce',
44   '$popover',
45   function ($window, $location, $sce, $popover) {
46     var requestAnimationFrame = $window.requestAnimationFrame || $window.setTimeout;
47     return {
48       restrict: 'EAC',
49       scope: true,
50       link: function postLink(scope, element, attr) {
51         // Directive options
52         var options = { scope: scope };
53         angular.forEach([
54           'template',
55           'contentTemplate',
56           'placement',
57           'container',
58           'target',
59           'delay',
60           'trigger',
61           'keyboard',
62           'html',
63           'animation'
64         ], function (key) {
65           if (angular.isDefined(attr[key]))
66             options[key] = attr[key];
67         });
68         // Support scope as data-attrs
69         angular.forEach([
70           'title',
71           'content'
72         ], function (key) {
73           attr[key] && attr.$observe(key, function (newValue, oldValue) {
74             scope[key] = $sce.trustAsHtml(newValue);
75             angular.isDefined(oldValue) && requestAnimationFrame(function () {
76               popover && popover.$applyPlacement();
77             });
78           });
79         });
80         // Support scope as an object
81         attr.bsPopover && scope.$watch(attr.bsPopover, function (newValue, oldValue) {
82           if (angular.isObject(newValue)) {
83             angular.extend(scope, newValue);
84           } else {
85             scope.content = newValue;
86           }
87           angular.isDefined(oldValue) && requestAnimationFrame(function () {
88             popover && popover.$applyPlacement();
89           });
90         }, true);
91         // Initialize popover
92         var popover = $popover(element, options);
93         // Garbage collection
94         scope.$on('$destroy', function () {
95           popover.destroy();
96           options = null;
97           popover = null;
98         });
99       }
100     };
101   }
102 ]);