app.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. (function() {
  2. var app = angular.module('app', ['ui.router', 'navController', 'ngAnimate', 'ui.bootstrap', 'ngResource', 'app.controllers', 'app.services'])
  3. // define for requirejs loaded modules
  4. define('app', [], function() { return app; });
  5. // function for dynamic load with requirejs of a javascript module for use with a view
  6. // in the state definition call add property `resolve: req('/views/ui.js')`
  7. // or `resolve: req(['/views/ui.js'])`
  8. // or `resolve: req('views/ui')`
  9. function req(deps) {
  10. if (typeof deps === 'string') deps = [deps];
  11. return {
  12. deps: function ($q, $rootScope) {
  13. var deferred = $q.defer();
  14. require(deps, function() {
  15. $rootScope.$apply(function () {
  16. deferred.resolve();
  17. });
  18. deferred.resolve();
  19. });
  20. return deferred.promise;
  21. }
  22. }
  23. }
  24. app.config(function($stateProvider, $urlRouterProvider, $controllerProvider){
  25. var origController = app.controller
  26. app.controller = function (name, constructor){
  27. $controllerProvider.register(name, constructor);
  28. return origController.apply(this, arguments);
  29. }
  30. var viewsPrefix = 'views/';
  31. // For any unmatched url, send to /
  32. $urlRouterProvider.otherwise("/")
  33. $stateProvider
  34. // you can set this to no template if you just want to use the html in the page
  35. .state('home', {
  36. url: "/",
  37. templateUrl: viewsPrefix + "home.html",
  38. data: {
  39. pageTitle: 'Home'
  40. }
  41. })
  42. .state('shipwrecks',{
  43. url:'/shipwrecks',
  44. templateUrl: viewsPrefix + 'shipwrecks.html',
  45. controller:'ShipwreckListController'
  46. }).state('viewShipwreck',{
  47. url:'/shipwrecks/:id/view',
  48. templateUrl: viewsPrefix + 'shipwreck-view.html',
  49. controller:'ShipwreckViewController'
  50. }).state('newShipwreck',{
  51. url:'/shipwrecks/new',
  52. templateUrl: viewsPrefix + 'shipwreck-add.html',
  53. controller:'ShipwreckCreateController'
  54. }).state('editShipwreck',{
  55. url:'/shipwrecks/:id/edit',
  56. templateUrl: viewsPrefix + 'shipwreck-edit.html',
  57. controller:'ShipwreckEditController'
  58. })
  59. })
  60. .directive('updateTitle', ['$rootScope', '$timeout',
  61. function($rootScope, $timeout) {
  62. return {
  63. link: function(scope, element) {
  64. var listener = function(event, toState) {
  65. var title = 'Project Name';
  66. if (toState.data && toState.data.pageTitle) title = toState.data.pageTitle + ' - ' + title;
  67. $timeout(function() {
  68. element.text(title);
  69. }, 0, false);
  70. };
  71. $rootScope.$on('$stateChangeSuccess', listener);
  72. }
  73. };
  74. }
  75. ]);
  76. }());