-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.js
More file actions
69 lines (54 loc) · 1.93 KB
/
Copy pathscript.js
File metadata and controls
69 lines (54 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var App = angular.module('myFramework', []);
App.config(function AppConfig($routeProvider) {
$routeProvider
.when('/', {
redirectTo: '/apps'
})
.when('/apps', {
templateUrl: '/templates/apps.html'
})
.when('/apps/:token', {
templateUrl: '/templates/app.html'
})
.otherwise({
redirectTo: '/apps'
});
console.log('framework config');
});
App.run(function AppRun() {
console.log('running framework');
});
// helper service to fetch scripts and include them in the page...
App.service('HelperService', [function HelperService() {
var includeJavaScript = function includeJavaScript(scriptFile, callback) {
// ... snip, testing if argument is string, or array ... for the ease lets say its a single script: string
$.when(
$.getScript(scriptFile)
).done(function cb() {
callback();
});
};
return {
includeJavaScript: includeJavaScript
};
}]);
// controller to load an application
App.controller('framework.appController', ['$scope', '$routeParams', 'HelperService', function appController($scope, $routeParams, HelperService) {
$scope.app = {
appTemplate: '/templates/loading.html'
};
var bootApp = function bootApplication() {
$scope.app.name = $routeParams.token;
var appServiceUrl = '/apps/' + $scope.app.name + '/' + $scope.app.name + '.js';
HelperService.includeJavaScript(appServiceUrl, function callback() {
angular.bootstrap($('#application-container'), [$scope.app.name]);
appPreloaded();
});
};
var appPreloaded = function appPreloaded() {
console.warn('loaded!', arguments);
// application preloaded, scripts are included, fire it up...
$scope.app.appTemplate = '/apps/' + $scope.app.name + '/views/app.html';
};
bootApp();
}]);