/
classes.js
554 lines (554 loc) · 16.8 KB
/
classes.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
/**
* Class stubs for documentation purposes
* @main F2
*/
F2.extend('', {
/**
* The App Class is an optional class that can be namespaced onto the
* {{#crossLink "F2\Apps"}}{{/crossLink}} namespace. The
* [F2 Docs](../../app-development.html#app-class)
* has more information on the usage of the App Class.
* @class F2.App
* @constructor
* @param {F2.AppConfig} appConfig The F2.AppConfig object for the app
* @param {F2.AppManifest.AppContent} appContent The F2.AppManifest.AppContent
* object
* @param {Element} root The root DOM Element for the app
*/
App: function(appConfig, appContent, root) {
return {
/**
* An optional init function that will automatically be called when
* F2.{{#crossLink "F2\registerApps"}}{{/crossLink}} is called.
* @method init
* @optional
*/
init:function() {},
/**
* An optional destroy function that will automatically be called when
* F2.{{#crossLink "F2\removeApp"}}{{/crossLink}} and subsequently
* the {{#crossLink "F2.Constants.AppHandlers\APP_DESTROY"}} AppHandler.
*/
destroy:function() {}
};
},
/**
* The AppConfig object represents an app's meta data
* @class F2.AppConfig
*/
AppConfig: {
/**
* The unique ID of the app. More information can be found
* [here](../../app-development.html#f2-appid)
* @property appId
* @type string
* @required
*/
appId: '',
/**
* An object that represents the context of an app
* @property context
* @type object
*/
context: {},
/**
* True if the app should be requested in a single request with other apps.
* @property enableBatchRequests
* @type bool
* @default false
*/
enableBatchRequests: false,
/**
* The height of the app. The initial height will be pulled from
* the {{#crossLink "F2.AppConfig"}}{{/crossLink}} object, but later
* modified by calling
* F2.UI.{{#crossLink "F2.UI/updateHeight"}}{{/crossLink}}. This is used
* for secure apps to be able to set the initial height of the iframe.
* @property height
* @type int
*/
height: 0,
/**
* The unique runtime ID of the app.
*
* **This property is populated during the
* F2.{{#crossLink "F2/registerApps"}}{{/crossLink}} process**
* @property instanceId
* @type string
*/
instanceId: '',
/**
* True if the app will be loaded in an iframe. This property
* will be true if the {{#crossLink "F2.AppConfig"}}{{/crossLink}} object
* sets isSecure = true. It will also be true if the
* [container](../../container-development.html) has made the decision to
* run apps in iframes.
* @property isSecure
* @type bool
* @default false
*/
isSecure: false,
/**
* The language and region specification for this container
* represented as an IETF-defined standard language tag,
* e.g. `"en-us"` or `"de-de"`. This is passed during the
* F2.{{#crossLink "F2/registerApps"}}{{/crossLink}} process.
*
* @property containerLocale
* @type string
* @default null
* @since 1.4.0
*/
containerLocale: null,
/**
* The languages and regions supported by this app represented
* as an array of IETF-defined standard language tags,
* e.g. `["en-us","de-de"]`.
*
* @property localeSupport
* @type array
* @default []
* @since 1.4.0
*/
localeSupport: [],
/**
* The url to retrieve the {{#crossLink "F2.AppManifest"}}{{/crossLink}}
* object.
* @property manifestUrl
* @type string
* @required
*/
manifestUrl: '',
/**
* The recommended maximum width in pixels that this app should be run.
* **It is up to the [container](../../container-development.html) to
* implement the logic to prevent an app from being run when the maxWidth
* requirements are not met.**
* @property maxWidth
* @type int
*/
maxWidth: 0,
/**
* The recommended minimum grid size that this app should be run. This
* value corresponds to the 12-grid system that is used by the
* [container](../../container-development.html). This property should be
* set by apps that require a certain number of columns in their layout.
* @property minGridSize
* @type int
* @default 4
*/
minGridSize: 4,
/**
* The recommended minimum width in pixels that this app should be run. **It
* is up to the [container](../../container-development.html) to implement
* the logic to prevent an app from being run when the minWidth requirements
* are not met.
* @property minWidth
* @type int
* @default 300
*/
minWidth: 300,
/**
* The name of the app
* @property name
* @type string
* @required
*/
name: '',
/**
* The root DOM element that contains the app
*
* **This property is populated during the
* F2.{{#crossLink "F2/registerApps"}}{{/crossLink}} process**
* @property root
* @type Element
*/
root: undefined,
/**
* The instance of F2.UI providing easy access to F2.UI methods
*
* **This property is populated during the
* F2.{{#crossLink "F2/registerApps"}}{{/crossLink}} process**
* @property ui
* @type F2.UI
*/
ui: undefined,
/**
* The views that this app supports. Available views
* are defined in {{#crossLink "F2.Constants.Views"}}{{/crossLink}}. The
* presence of a view can be checked via
* F2.{{#crossLink "F2/inArray"}}{{/crossLink}}:
*
* F2.inArray(F2.Constants.Views.SETTINGS, app.views)
*
* @property views
* @type Array
*/
views: []
},
/**
* The assets needed to render an app on the page
* @class F2.AppManifest
*/
AppManifest: {
/**
* The array of {{#crossLink "F2.AppManifest.AppContent"}}{{/crossLink}}
* objects
* @property apps
* @type Array
* @required
*/
apps: [],
/**
* Any inline javascript tha should initially be run
* @property inlineScripts
* @type Array
* @optional
*/
inlineScripts: [],
/**
* Urls to javascript files required by the app
* @property scripts
* @type Array
* @optional
*/
scripts: [],
/**
* Urls to CSS files required by the app
* @property styles
* @type Array
* @optional
*/
styles: []
},
/**
* The AppContent object
* @class F2.AppManifest.AppContent
**/
AppContent: {
/**
* Arbitrary data to be passed along with the app
* @property data
* @type object
* @optional
*/
data: {},
/**
* The string of HTML representing the app
* @property html
* @type string
* @required
*/
html: '',
/**
* A status message
* @property status
* @type string
* @optional
*/
status: ''
},
/**
* An object containing configuration information for the
* [container](../../container-development.html)
* @class F2.ContainerConfig
*/
ContainerConfig: {
/**
* Allows the [container](../../container-development.html) to override how
* an app's html is inserted into the page. The function should accept an
* {{#crossLink "F2.AppConfig"}}{{/crossLink}} object and also a string of
* html
* @method afterAppRender
* @deprecated This has been replaced with {{#crossLink "F2.AppHandlers"}}{{/crossLink}} and will be removed in v2.0
* @param {F2.AppConfig} appConfig The F2.AppConfig object
* @param {string} html The string of html representing the app
* @return {Element} The DOM Element surrounding the app
*/
afterAppRender: function(appConfig, html) {},
/**
* Allows the [container](../../container-development.html) to wrap an app
* in extra html. The function should accept an
* {{#crossLink "F2.AppConfig"}}{{/crossLink}} object and also a string of
* html. The extra html can provide links to edit app settings and remove an
* app from the container. See
* {{#crossLink "F2.Constants.Css"}}{{/crossLink}} for CSS classes that
* should be applied to elements.
* @method appRender
* @deprecated This has been replaced with {{#crossLink "F2.AppHandlers"}}{{/crossLink}} and will be removed in v2.0
* @param {F2.AppConfig} appConfig The F2.AppConfig object
* @param {string} html The string of html representing the app
*/
appRender: function(appConfig, html) {},
/**
* Allows the container to render html for an app before the AppManifest for
* an app has loaded. This can be useful if the design calls for loading
* icons to appear for each app before each app is loaded and rendered to
* the page.
* @method beforeAppRender
* @deprecated This has been replaced with {{#crossLink "F2.AppHandlers"}}{{/crossLink}} and will be removed in v2.0
* @param {F2.AppConfig} appConfig The F2.AppConfig object
* @return {Element} The DOM Element surrounding the app
*/
beforeAppRender: function(appConfig) {},
/**
* True to enable debug mode in F2.js. Adds additional logging, resource cache busting, etc.
* @property debugMode
* @type bool
* @default false
*/
debugMode: false,
/**
* The default language and region specification for this container
* represented as an IETF-defined standard language tag,
* e.g. `"en-us"` or `"de-de"`. This value is passed to each app
* registered as `containerLocale`.
*
* @property locale
* @type string
* @default null
* @since 1.4.0
*/
locale: null,
/**
* Milliseconds before F2 fires callback on script resource load errors. Due to issue with the way Internet Explorer attaches load events to script elements, the error event doesn't fire.
* @property scriptErrorTimeout
* @type milliseconds
* @default 7000 (7 seconds)
*/
scriptErrorTimeout: 7000,
/**
* Tells the container that it is currently running within
* a secure app page
* @property isSecureAppPage
* @type bool
*/
isSecureAppPage: false,
/**
* Allows the container to specify which page is used when
* loading a secure app. The page must reside on a different domain than the
* container
* @property secureAppPagePath
* @type string
* @for F2.ContainerConfig
*/
secureAppPagePath: '',
/**
* Specifies what views a container will provide buttons
* or links to. Generally, the views will be switched via buttons or links
* in the app's header.
* @property supportedViews
* @type Array
* @required
*/
supportedViews: [],
/**
* An object containing configuration defaults for F2.UI
* @class F2.ContainerConfig.UI
*/
UI: {
/**
* An object containing configuration defaults for the
* F2.UI.{{#crossLink "F2.UI/showMask"}}{{/crossLink}} and
* F2.UI.{{#crossLink "F2.UI/hideMask"}}{{/crossLink}} methods.
* @class F2.ContainerConfig.UI.Mask
*/
Mask: {
/**
* The backround color of the overlay
* @property backgroundColor
* @type string
* @default #FFF
*/
backgroundColor: '#FFF',
/**
* The path to the loading icon
* @property loadingIcon
* @type string
*/
loadingIcon: '',
/**
* The opacity of the background overlay
* @property opacity
* @type int
* @default 0.6
*/
opacity: 0.6,
/**
* Do not use inline styles for mask functinality. Instead classes will
* be applied to the elements and it is up to the container provider to
* implement the class definitions.
* @property useClasses
* @type bool
* @default false
*/
useClasses: false,
/**
* The z-index to use for the overlay
* @property zIndex
* @type int
* @default 2
*/
zIndex: 2
}
},
/**
* Allows the container to fully override how the AppManifest request is
* made inside of F2.
*
* @method xhr
* @param {string} url The manifest url
* @param {Array} appConfigs An array of {{#crossLink "F2.AppConfig"}}{{/crossLink}}
* objects
* @param {function} success The function to be called if the request
* succeeds
* @param {function} error The function to be called if the request fails
* @param {function} complete The function to be called when the request
* finishes (after success and error callbacks have been executed)
* @return {XMLHttpRequest} The XMLHttpRequest object (or an object that has
* an `abort` function (such as the jqXHR object in jQuery) to abort the
* request)
*
* @example
* F2.init({
* xhr: function(url, appConfigs, success, error, complete) {
* $.ajax({
* url: url,
* type: 'POST',
* data: {
* params: F2.stringify(appConfigs, F2.appConfigReplacer)
* },
* jsonp: false, // do not put 'callback=' in the query string
* jsonpCallback: F2.Constants.JSONP_CALLBACK + appConfigs[0].appId, // Unique function name
* dataType: 'json',
* success: function(appManifest) {
* // custom success logic
* success(appManifest); // fire success callback
* },
* error: function() {
* // custom error logic
* error(); // fire error callback
* },
* complete: function() {
* // custom complete logic
* complete(); // fire complete callback
* }
* });
* }
* });
*
* @for F2.ContainerConfig
*/
//xhr: function(url, appConfigs, success, error, complete) {},
/**
* Allows the container to override individual parts of the AppManifest
* request. See properties and methods with the `xhr.` prefix.
* @property xhr
* @type Object
*
* @example
* F2.init({
* xhr: {
* url: function(url, appConfigs) {
* return 'http://example.com/proxy.php?url=' + encocdeURIComponent(url);
* }
* }
* });
*/
xhr: {
/**
* Allows the container to override the request data type (JSON or JSONP)
* that is used for the request
* @method xhr.dataType
* @param {string} url The manifest url
* @param {Array} appConfigs An array of {{#crossLink "F2.AppConfig"}}{{/crossLink}}
* objects
* @return {string} The request data type that should be used
*
* @example
* F2.init({
* xhr: {
* dataType: function(url) {
* return F2.isLocalRequest(url) ? 'json' : 'jsonp';
* },
* type: function(url) {
* return F2.isLocalRequest(url) ? 'POST' : 'GET';
* }
* }
* });
*/
dataType: function(url, appConfigs) {},
/**
* Allows the container to override the request method that is used (just
* like the `type` parameter to `jQuery.ajax()`.
* @method xhr.type
* @param {string} url The manifest url
* @param {Array} appConfigs An array of {{#crossLink "F2.AppConfig"}}{{/crossLink}}
* objects
* @return {string} The request method that should be used
*
* @example
* F2.init({
* xhr: {
* dataType: function(url) {
* return F2.isLocalRequest(url) ? 'json' : 'jsonp';
* },
* type: function(url) {
* return F2.isLocalRequest(url) ? 'POST' : 'GET';
* }
* }
* });
*/
type: function(url, appConfigs) {},
/**
* Allows the container to override the url that is used to request an
* app's F2.{{#crossLink "F2.AppManifest"}}{{/crossLink}}
* @method xhr.url
* @param {string} url The manifest url
* @param {Array} appConfigs An array of {{#crossLink "F2.AppConfig"}}{{/crossLink}}
* objects
* @return {string} The url that should be used for the request
*
* @example
* F2.init({
* xhr: {
* url: function(url, appConfigs) {
* return 'http://example.com/proxy.php?url=' + encocdeURIComponent(url);
* }
* }
* });
*/
url: function(url, appConfigs) {}
},
/**
* Allows the container to override the script loader which requests
* dependencies defined in the {{#crossLink "F2.AppManifest"}}{{/crossLink}}.
* @property loadScripts
* @type function
*
* @example
* F2.init({
* loadScripts: function(scripts,inlines,callback){
* //load scripts using $.load() for each script or require(scripts)
* callback();
* }
* });
*/
loadScripts: function(scripts,inlines,callback){},
/**
* Allows the container to override the stylesheet loader which requests
* dependencies defined in the {{#crossLink "F2.AppManifest"}}{{/crossLink}}.
* @property loadStyles
* @type function
*
* @example
* F2.init({
* loadStyles: function(styles,callback){
* //load styles using $.load() for each stylesheet or another method
* callback();
* }
* });
*/
loadStyles: function(styles,callback){}
}
});