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.aside', ['mgcrea.ngStrap.modal']).provider('$aside', function () { |
|
10 |
var defaults = this.defaults = { |
|
11 |
animation: 'am-fade-and-slide-right', |
|
12 |
prefixClass: 'aside', |
|
13 |
placement: 'right', |
|
14 |
template: 'aside/aside.tpl.html', |
|
15 |
contentTemplate: false, |
|
16 |
container: false, |
|
17 |
element: null, |
|
18 |
backdrop: true, |
|
19 |
keyboard: true, |
|
20 |
html: false, |
|
21 |
show: true |
|
22 |
}; |
|
23 |
this.$get = [ |
|
24 |
'$modal', |
|
25 |
function ($modal) { |
|
26 |
function AsideFactory(config) { |
|
27 |
var $aside = {}; |
|
28 |
// Common vars |
|
29 |
var options = angular.extend({}, defaults, config); |
|
30 |
$aside = $modal(options); |
|
31 |
return $aside; |
|
32 |
} |
|
33 |
return AsideFactory; |
|
34 |
} |
|
35 |
]; |
|
36 |
}).directive('bsAside', [ |
|
37 |
'$window', |
|
38 |
'$sce', |
|
39 |
'$aside', |
|
40 |
function ($window, $sce, $aside) { |
|
41 |
var requestAnimationFrame = $window.requestAnimationFrame || $window.setTimeout; |
|
42 |
return { |
|
43 |
restrict: 'EAC', |
|
44 |
scope: true, |
|
45 |
link: function postLink(scope, element, attr, transclusion) { |
|
46 |
// Directive options |
|
47 |
var options = { |
|
48 |
scope: scope, |
|
49 |
element: element, |
|
50 |
show: false |
|
51 |
}; |
|
52 |
angular.forEach([ |
|
53 |
'template', |
|
54 |
'contentTemplate', |
|
55 |
'placement', |
|
56 |
'backdrop', |
|
57 |
'keyboard', |
|
58 |
'html', |
|
59 |
'container', |
|
60 |
'animation' |
|
61 |
], function (key) { |
|
62 |
if (angular.isDefined(attr[key])) |
|
63 |
options[key] = attr[key]; |
|
64 |
}); |
|
65 |
// Support scope as data-attrs |
|
66 |
angular.forEach([ |
|
67 |
'title', |
|
68 |
'content' |
|
69 |
], function (key) { |
|
70 |
attr[key] && attr.$observe(key, function (newValue, oldValue) { |
|
71 |
scope[key] = $sce.trustAsHtml(newValue); |
|
72 |
}); |
|
73 |
}); |
|
74 |
// Support scope as an object |
|
75 |
attr.bsAside && scope.$watch(attr.bsAside, function (newValue, oldValue) { |
|
76 |
if (angular.isObject(newValue)) { |
|
77 |
angular.extend(scope, newValue); |
|
78 |
} else { |
|
79 |
scope.content = newValue; |
|
80 |
} |
|
81 |
}, true); |
|
82 |
// Initialize aside |
|
83 |
var aside = $aside(options); |
|
84 |
// Trigger |
|
85 |
element.on(attr.trigger || 'click', aside.toggle); |
|
86 |
// Garbage collection |
|
87 |
scope.$on('$destroy', function () { |
|
88 |
aside.destroy(); |
|
89 |
options = null; |
|
90 |
aside = null; |
|
91 |
}); |
|
92 |
} |
|
93 |
}; |
|
94 |
} |
|
95 |
]); |