aside.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * angular-strap
  3. * @version v2.3.5 - 2015-10-29
  4. * @link http://mgcrea.github.io/angular-strap
  5. * @author Olivier Louvignes <olivier@mg-crea.com> (https://github.com/mgcrea)
  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. prefixEvent: 'aside',
  14. placement: 'right',
  15. templateUrl: 'aside/aside.tpl.html',
  16. contentTemplate: false,
  17. container: false,
  18. element: null,
  19. backdrop: true,
  20. keyboard: true,
  21. html: false,
  22. show: true
  23. };
  24. this.$get = [ '$modal', function($modal) {
  25. function AsideFactory(config) {
  26. var $aside = {};
  27. var options = angular.extend({}, defaults, config);
  28. $aside = $modal(options);
  29. return $aside;
  30. }
  31. return AsideFactory;
  32. } ];
  33. }).directive('bsAside', [ '$window', '$sce', '$aside', function($window, $sce, $aside) {
  34. var requestAnimationFrame = $window.requestAnimationFrame || $window.setTimeout;
  35. return {
  36. restrict: 'EAC',
  37. scope: true,
  38. link: function postLink(scope, element, attr, transclusion) {
  39. var options = {
  40. scope: scope,
  41. element: element,
  42. show: false
  43. };
  44. angular.forEach([ 'template', 'templateUrl', 'controller', 'controllerAs', 'contentTemplate', 'placement', 'backdrop', 'keyboard', 'html', 'container', 'animation' ], function(key) {
  45. if (angular.isDefined(attr[key])) options[key] = attr[key];
  46. });
  47. var falseValueRegExp = /^(false|0|)$/i;
  48. angular.forEach([ 'backdrop', 'keyboard', 'html', 'container' ], function(key) {
  49. if (angular.isDefined(attr[key]) && falseValueRegExp.test(attr[key])) options[key] = false;
  50. });
  51. angular.forEach([ 'title', 'content' ], function(key) {
  52. attr[key] && attr.$observe(key, function(newValue, oldValue) {
  53. scope[key] = $sce.trustAsHtml(newValue);
  54. });
  55. });
  56. attr.bsAside && scope.$watch(attr.bsAside, function(newValue, oldValue) {
  57. if (angular.isObject(newValue)) {
  58. angular.extend(scope, newValue);
  59. } else {
  60. scope.content = newValue;
  61. }
  62. }, true);
  63. var aside = $aside(options);
  64. element.on(attr.trigger || 'click', aside.toggle);
  65. scope.$on('$destroy', function() {
  66. if (aside) aside.destroy();
  67. options = null;
  68. aside = null;
  69. });
  70. }
  71. };
  72. } ]);