bootstrap.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. 'use strict';
  2. /* Controllers */
  3. // bootstrap controller
  4. app.controller('AccordionDemoCtrl', ['$scope', function($scope) {
  5. $scope.oneAtATime = true;
  6. $scope.groups = [
  7. {
  8. title: 'Accordion group header - #1',
  9. content: 'Dynamic group body - #1'
  10. },
  11. {
  12. title: 'Accordion group header - #2',
  13. content: 'Dynamic group body - #2'
  14. }
  15. ];
  16. $scope.items = ['Item 1', 'Item 2', 'Item 3'];
  17. $scope.addItem = function() {
  18. var newItemNo = $scope.items.length + 1;
  19. $scope.items.push('Item ' + newItemNo);
  20. };
  21. $scope.status = {
  22. isFirstOpen: true,
  23. isFirstDisabled: false
  24. };
  25. }])
  26. ;
  27. app.controller('AlertDemoCtrl', ['$scope', function($scope) {
  28. $scope.alerts = [
  29. { type: 'success', msg: 'Well done! You successfully read this important alert message.' },
  30. { type: 'info', msg: 'Heads up! This alert needs your attention, but it is not super important.' },
  31. { type: 'warning', msg: 'Warning! Best check yo self, you are not looking too good...' }
  32. ];
  33. $scope.addAlert = function() {
  34. $scope.alerts.push({type: 'danger', msg: 'Oh snap! Change a few things up and try submitting again.'});
  35. };
  36. $scope.closeAlert = function(index) {
  37. $scope.alerts.splice(index, 1);
  38. };
  39. }])
  40. ;
  41. app.controller('ButtonsDemoCtrl', ['$scope', function($scope) {
  42. $scope.singleModel = 1;
  43. $scope.radioModel = 'Middle';
  44. $scope.checkModel = {
  45. left: false,
  46. middle: true,
  47. right: false
  48. };
  49. }])
  50. ;
  51. app.controller('CarouselDemoCtrl', ['$scope', function($scope) {
  52. $scope.myInterval = 5000;
  53. var slides = $scope.slides = [];
  54. $scope.addSlide = function() {
  55. slides.push({
  56. image: 'img/c' + slides.length + '.jpg',
  57. text: ['Carousel text #0','Carousel text #1','Carousel text #2','Carousel text #3'][slides.length % 4]
  58. });
  59. };
  60. for (var i=0; i<4; i++) {
  61. $scope.addSlide();
  62. }
  63. }])
  64. ;
  65. app.controller('DropdownDemoCtrl', ['$scope', function($scope) {
  66. $scope.items = [
  67. 'The first choice!',
  68. 'And another choice for you.',
  69. 'but wait! A third!'
  70. ];
  71. $scope.status = {
  72. isopen: false
  73. };
  74. $scope.toggled = function(open) {
  75. //console.log('Dropdown is now: ', open);
  76. };
  77. $scope.toggleDropdown = function($event) {
  78. $event.preventDefault();
  79. $event.stopPropagation();
  80. $scope.status.isopen = !$scope.status.isopen;
  81. };
  82. }])
  83. ;
  84. app.controller('ModalInstanceCtrl', ['$scope', '$modalInstance', 'items', function($scope, $modalInstance, items) {
  85. $scope.items = items;
  86. $scope.selected = {
  87. item: $scope.items[0]
  88. };
  89. $scope.ok = function () {
  90. $modalInstance.close($scope.selected.item);
  91. };
  92. $scope.cancel = function () {
  93. $modalInstance.dismiss('cancel');
  94. };
  95. }])
  96. ;
  97. app.controller('ModalDemoCtrl', ['$scope', '$modal', '$log', function($scope, $modal, $log) {
  98. $scope.items = ['item1', 'item2', 'item3'];
  99. $scope.open = function (size) {
  100. var modalInstance = $modal.open({
  101. templateUrl: 'myModalContent.html',
  102. controller: 'ModalInstanceCtrl',
  103. size: size,
  104. resolve: {
  105. items: function () {
  106. return $scope.items;
  107. }
  108. }
  109. });
  110. modalInstance.result.then(function (selectedItem) {
  111. $scope.selected = selectedItem;
  112. }, function () {
  113. $log.info('Modal dismissed at: ' + new Date());
  114. });
  115. };
  116. }])
  117. ;
  118. app.controller('PaginationDemoCtrl', ['$scope', '$log', function($scope, $log) {
  119. $scope.totalItems = 64;
  120. $scope.currentPage = 4;
  121. $scope.setPage = function (pageNo) {
  122. $scope.currentPage = pageNo;
  123. };
  124. $scope.pageChanged = function() {
  125. $log.info('Page changed to: ' + $scope.currentPage);
  126. };
  127. $scope.maxSize = 5;
  128. $scope.bigTotalItems = 175;
  129. $scope.bigCurrentPage = 1;
  130. }])
  131. ;
  132. app.controller('PopoverDemoCtrl', ['$scope', function($scope) {
  133. $scope.dynamicPopover = 'Hello, World!';
  134. $scope.dynamicPopoverTitle = 'Title';
  135. }])
  136. ;
  137. app.controller('ProgressDemoCtrl', ['$scope', function($scope) {
  138. $scope.max = 200;
  139. $scope.random = function() {
  140. var value = Math.floor((Math.random() * 100) + 1);
  141. var type;
  142. if (value < 25) {
  143. type = 'success';
  144. } else if (value < 50) {
  145. type = 'info';
  146. } else if (value < 75) {
  147. type = 'warning';
  148. } else {
  149. type = 'danger';
  150. }
  151. $scope.showWarning = (type === 'danger' || type === 'warning');
  152. $scope.dynamic = value;
  153. $scope.type = type;
  154. };
  155. $scope.random();
  156. $scope.randomStacked = function() {
  157. $scope.stacked = [];
  158. var types = ['success', 'info', 'warning', 'danger'];
  159. for (var i = 0, n = Math.floor((Math.random() * 4) + 1); i < n; i++) {
  160. var index = Math.floor((Math.random() * 4));
  161. $scope.stacked.push({
  162. value: Math.floor((Math.random() * 30) + 1),
  163. type: types[index]
  164. });
  165. }
  166. };
  167. $scope.randomStacked();
  168. }])
  169. ;
  170. app.controller('TabsDemoCtrl', ['$scope', function($scope) {
  171. $scope.tabs = [
  172. { title:'Dynamic Title 1', content:'Dynamic content 1' },
  173. { title:'Dynamic Title 2', content:'Dynamic content 2', disabled: true }
  174. ];
  175. }])
  176. ;
  177. app.controller('RatingDemoCtrl', ['$scope', function($scope) {
  178. $scope.rate = 7;
  179. $scope.max = 10;
  180. $scope.isReadonly = false;
  181. $scope.hoveringOver = function(value) {
  182. $scope.overStar = value;
  183. $scope.percent = 100 * (value / $scope.max);
  184. };
  185. }])
  186. ;
  187. app.controller('TooltipDemoCtrl', ['$scope', function($scope) {
  188. $scope.dynamicTooltip = 'Hello, World!';
  189. $scope.dynamicTooltipText = 'dynamic';
  190. $scope.htmlTooltip = 'I\'ve been made <b>bold</b>!';
  191. }])
  192. ;
  193. app.controller('TypeaheadDemoCtrl', ['$scope', '$http', function($scope, $http) {
  194. $scope.selected = undefined;
  195. $scope.states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Dakota', 'North Carolina', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'];
  196. // Any function returning a promise object can be used to load values asynchronously
  197. $scope.getLocation = function(val) {
  198. return $http.get('http://maps.googleapis.com/maps/api/geocode/json', {
  199. params: {
  200. address: val,
  201. sensor: false
  202. }
  203. }).then(function(res){
  204. var addresses = [];
  205. angular.forEach(res.data.results, function(item){
  206. addresses.push(item.formatted_address);
  207. });
  208. return addresses;
  209. });
  210. };
  211. }])
  212. ;
  213. app.controller('DatepickerDemoCtrl', ['$scope', function($scope) {
  214. $scope.today = function() {
  215. $scope.dt = new Date();
  216. };
  217. $scope.today();
  218. $scope.clear = function () {
  219. $scope.dt = null;
  220. };
  221. // Disable weekend selection
  222. $scope.disabled = function(date, mode) {
  223. return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) );
  224. };
  225. $scope.toggleMin = function() {
  226. $scope.minDate = $scope.minDate ? null : new Date();
  227. };
  228. $scope.toggleMin();
  229. $scope.open = function($event) {
  230. $event.preventDefault();
  231. $event.stopPropagation();
  232. $scope.opened = true;
  233. };
  234. $scope.dateOptions = {
  235. formatYear: 'yy',
  236. startingDay: 1,
  237. class: 'datepicker'
  238. };
  239. $scope.initDate = new Date('2016-15-20');
  240. $scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
  241. $scope.format = $scope.formats[0];
  242. }])
  243. ;
  244. app.controller('TimepickerDemoCtrl', ['$scope', function($scope) {
  245. $scope.mytime = new Date();
  246. $scope.hstep = 1;
  247. $scope.mstep = 15;
  248. $scope.options = {
  249. hstep: [1, 2, 3],
  250. mstep: [1, 5, 10, 15, 25, 30]
  251. };
  252. $scope.ismeridian = true;
  253. $scope.toggleMode = function() {
  254. $scope.ismeridian = ! $scope.ismeridian;
  255. };
  256. $scope.update = function() {
  257. var d = new Date();
  258. d.setHours( 14 );
  259. d.setMinutes( 0 );
  260. $scope.mytime = d;
  261. };
  262. $scope.changed = function () {
  263. //console.log('Time changed to: ' + $scope.mytime);
  264. };
  265. $scope.clear = function() {
  266. $scope.mytime = null;
  267. };
  268. }]);