This repository has been archived by the owner on Sep 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
angular-server-module.js
192 lines (188 loc) · 5.92 KB
/
angular-server-module.js
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/**
* MOST Web Framework
* A JavaScript Web Framework
* http://themost.io
*
* Copyright (c) 2014, Kyriakos Barbounakis k.barbounakis@gmail.com, Anthi Oikonomou anthioikonomou@gmail.com
*
* Released under the BSD3-Clause license
* Date: 2014-10-09
*/
/**
* @private
*/
var domino = require("domino");
/**
* @class
* @constructor
* @property {*} directives
* @property {*} controllers
* @property {*} filters
* @property {*} services
* @private
*/
function AngularServerModule() {
//
}
/**
* @param {string} name
* @param {function|Array|*=} ctor
* @returns AngularServerModule|function
*/
AngularServerModule.prototype.service = function(name, ctor) { };
/**
* @param {string} name
* @param {function|Array|*=} ctor
* @returns AngularServerModule|function
*/
AngularServerModule.prototype.directive = function(name, ctor) { };
/**
* @param {string} name
* @param {function|Array|*=} ctor
* @returns AngularServerModule|function
*/
AngularServerModule.prototype.filter = function(name, ctor) { };
/**
* @param {string} name
* @param {function|Array|*=} ctor
* @returns AngularServerModule|function
*/
AngularServerModule.prototype.controller = function(name, ctor) { };
var ng = {
/**
* @function
*/
angular: null,
/**
* @function
*/
jQuery: null,
/**
* @param {string=} s
* @returns {HTMLDocument}
*/
createDocument: function(s) {
s = s || '<html/>';
var window = domino.createWindow(s);
window.setTimeout = setTimeout;
window.clearTimeout = clearTimeout;
//define parent window property
Object.defineProperty(window.document, 'parentWindow', { get: function(){
return window;
}, configurable:false, enumerable:false });
window.location.href = "/";
if (typeof global.jQuery !== 'function')
throw new Error('jQuery object cannot be instantiated due to missing constructor.');
global.jQuery(window);
//extend jQuery
var ext = require('./jquery-server-extensions');
ext.extend(window.jQuery);
if (typeof global.angular !== 'function')
throw new Error('Angular JS object cannot be instantiated due to missing constructor.');
//initialize angular
global.angular(window, window.document);
/**
* @param {string|*} s
* @returns {JQuery|HTMLElement|*}
*/
window.document.element = function(s) {
return this.parentWindow.$(s);
}
return window.document;
},
/**
* @param {*} app
*/
init: function (app) {
if (typeof app.module === 'undefined' || app.module===null) {
/**
* @function
* @memberof HttpApplication
* @param {string=} s
* @returns {HTMLDocument}
*/
app.document = ng.createDocument;
/**
* @type {{directive: directive, directives: {}, service: service, services: {}, filter: filter, filters: {}, controller: controller, controllers: {}}}
* @memberOf HttpApplication
*/
app.module = {
/**
* @param {string} name
* @param {function=} ctor
* @returns {*}
*/
directive: function(name, ctor) {
if (typeof ctor === 'undefined')
return this.directives[name];
this.directives[name] = ctor;
return this;
},
directives: {},
/**
* @param {string} name
* @param {function=} ctor
* @returns {*}
*/
service: function(name, ctor) {
if (typeof ctor === 'undefined')
return this.services[name];
this.services[name] = ctor;
return this;
},
services: {},
/**
* @param {string} name
* @param {function=} ctor
* @returns {*}
*/
filter: function(name, ctor) {
if (typeof ctor === 'undefined')
return this.filters[name];
this.filters[name] = ctor;
return this;
},
filters:{},
/**
* @param {string} name
* @param {function=} ctor
* @returns {*}
*/
controller: function(name, ctor) {
if (typeof ctor === 'undefined')
return this.controllers[name];
this.controllers[name] = ctor;
return this;
},
controllers:{}
}
}
}
};
if (typeof exports !== 'undefined') {
if (typeof ng.angular === 'undefined' || ng.angular=== null) {
global.window = domino.createWindow('<html />');
global.window.location.href = "/";
global.document = global.window.document;
global.navigator = { appCodeName:"Mozilla",
appVersion:"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36",
cookieEnabled: false,
hardwareConcurrency:4,
language:"en-US",
platform:"Win32",
product:"Gecko",
userAgent:"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36"
};
//call jQuery initialization
require('./jquery');
//call angular initialization
require('./angular');
//delete dummy property
delete global.window;
delete global.document;
//set methods
ng.angular = global.angular;
ng.jQuery = global.jQuery;
}
module.exports = ng;
}