This repository is currently being migrated. It's locked while the migration is in progress.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
region.js
56 lines (44 loc) · 1.58 KB
/
region.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
define(['component'], function (component) {
/**
* Region is activity container that has only one running activity at a time
*/
var region = Object.create(component);
/**
* Adds activity to region
*
* @param {String} uid UID for the activity
* @param {Activity} activity
*/
region.addActivity = function(uid, activity) {
var region = this;
// var elId = 'activity' + uid.substr(0, 1).toUpperCase() + uid.substr(1);
var elId = uid;
var el = this.el.find('#' + elId);
if (el.length == 0) {
// Create element for the activity
el = $('<div>').attr('id', elId).appendTo(this.el);
}
// Init activity list, if not inited
if (!this.activities) this.activities = {};
// Add activity to the list
this.activities[activity.uid] = activity;
// Auto-initialize activity
activity.init(uid, {el: el});
// Proxy start method
var activityStart = activity.start;
activity.start = function(intent) {
// console.info('REG start');
// Stop running activity
if (region.currentActivity && region.currentActivity.running
&& region.currentActivity !== this) {
region.currentActivity.stop();
}
// Store this as current activity
region.currentActivity = this;
activityStart.call(activity, intent);
}
// Proxy setState method
var activitySetState = activity.setState;
};
return region;
});