@base-framework/base 2.6.1 → 2.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/base.js +1 -0
- package/package.json +30 -26
- package/.jshintrc +0 -3
- package/base.js +0 -41
- package/base.min.js +0 -1
- package/core.js +0 -1
- package/data-tracker.js +0 -351
- package/es5/base.js +0 -2968
- package/es5/modules/ajax.js +0 -663
- package/es5/modules/animation.js +0 -188
- package/es5/modules/animations.js +0 -1080
- package/es5/modules/atom.js +0 -65
- package/es5/modules/component.js +0 -1310
- package/es5/modules/data-binder.js +0 -1131
- package/es5/modules/data.js +0 -1808
- package/es5/modules/date.js +0 -525
- package/es5/modules/form-validator.js +0 -324
- package/es5/modules/history.js +0 -126
- package/es5/modules/html-builder.js +0 -461
- package/es5/modules/layout.js +0 -1679
- package/es5/modules/mouse.js +0 -124
- package/es5/modules/nav-link.js +0 -123
- package/es5/modules/olderversions/animations-ease.js +0 -1095
- package/es5/modules/olderversions/animations-update.js +0 -1048
- package/es5/modules/olderversions/base-animations.js +0 -636
- package/es5/modules/olderversions/base-component-class.js +0 -100
- package/es5/modules/olderversions/base-data-binder-1.js +0 -407
- package/es5/modules/olderversions/base-data-binder-class.js +0 -358
- package/es5/modules/olderversions/base-layout-parser-class.js +0 -172
- package/es5/modules/olderversions/base-mode-1.js +0 -777
- package/es5/modules/olderversions/base-model-class.js +0 -585
- package/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
- package/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
- package/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
- package/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
- package/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
- package/es5/modules/olderversions/data-tracker.js +0 -187
- package/es5/modules/olderversions/event-update.js +0 -666
- package/es5/modules/olderversions/nav-link.js +0 -119
- package/es5/modules/olderversions/router-with-templates-1.js +0 -785
- package/es5/modules/olderversions/router-with-templates.js +0 -701
- package/es5/modules/prototypes/ajax.js +0 -657
- package/es5/modules/prototypes/atom.js +0 -65
- package/es5/modules/prototypes/component.js +0 -972
- package/es5/modules/prototypes/data-binder.js +0 -1089
- package/es5/modules/prototypes/data.js +0 -1290
- package/es5/modules/prototypes/html-builder.js +0 -414
- package/es5/modules/prototypes/layout.js +0 -879
- package/es5/modules/router.js +0 -1680
- package/es5/modules/state.js +0 -274
- package/es6/.jshintrc +0 -3
- package/es6/base.js +0 -41
- package/es6/core.js +0 -1
- package/es6/data-tracker.js +0 -351
- package/es6/events.js +0 -602
- package/es6/legacy/es5/base.js +0 -2968
- package/es6/legacy/es5/modules/ajax.js +0 -663
- package/es6/legacy/es5/modules/animation.js +0 -188
- package/es6/legacy/es5/modules/animations.js +0 -1080
- package/es6/legacy/es5/modules/atom.js +0 -65
- package/es6/legacy/es5/modules/component.js +0 -1310
- package/es6/legacy/es5/modules/data-binder.js +0 -1131
- package/es6/legacy/es5/modules/data.js +0 -1808
- package/es6/legacy/es5/modules/date.js +0 -525
- package/es6/legacy/es5/modules/form-validator.js +0 -324
- package/es6/legacy/es5/modules/history.js +0 -126
- package/es6/legacy/es5/modules/html-builder.js +0 -461
- package/es6/legacy/es5/modules/layout.js +0 -1679
- package/es6/legacy/es5/modules/mouse.js +0 -124
- package/es6/legacy/es5/modules/nav-link.js +0 -123
- package/es6/legacy/es5/modules/olderversions/animations-ease.js +0 -1095
- package/es6/legacy/es5/modules/olderversions/animations-update.js +0 -1048
- package/es6/legacy/es5/modules/olderversions/base-animations.js +0 -636
- package/es6/legacy/es5/modules/olderversions/base-component-class.js +0 -100
- package/es6/legacy/es5/modules/olderversions/base-data-binder-1.js +0 -407
- package/es6/legacy/es5/modules/olderversions/base-data-binder-class.js +0 -358
- package/es6/legacy/es5/modules/olderversions/base-layout-parser-class.js +0 -172
- package/es6/legacy/es5/modules/olderversions/base-mode-1.js +0 -777
- package/es6/legacy/es5/modules/olderversions/base-model-class.js +0 -585
- package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
- package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
- package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
- package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
- package/es6/legacy/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
- package/es6/legacy/es5/modules/olderversions/data-tracker.js +0 -187
- package/es6/legacy/es5/modules/olderversions/event-update.js +0 -666
- package/es6/legacy/es5/modules/olderversions/nav-link.js +0 -119
- package/es6/legacy/es5/modules/olderversions/router-with-templates-1.js +0 -785
- package/es6/legacy/es5/modules/olderversions/router-with-templates.js +0 -701
- package/es6/legacy/es5/modules/prototypes/ajax.js +0 -657
- package/es6/legacy/es5/modules/prototypes/atom.js +0 -65
- package/es6/legacy/es5/modules/prototypes/component.js +0 -972
- package/es6/legacy/es5/modules/prototypes/data-binder.js +0 -1089
- package/es6/legacy/es5/modules/prototypes/data.js +0 -1290
- package/es6/legacy/es5/modules/prototypes/html-builder.js +0 -414
- package/es6/legacy/es5/modules/prototypes/layout.js +0 -879
- package/es6/legacy/es5/modules/router.js +0 -1680
- package/es6/legacy/es5/modules/state.js +0 -274
- package/es6/main.js +0 -1331
- package/es6/modules/ajax/ajax.js +0 -514
- package/es6/modules/animation/animation.js +0 -236
- package/es6/modules/animations/animation-controller.js +0 -231
- package/es6/modules/animations/animation.js +0 -64
- package/es6/modules/animations/attr-movement.js +0 -66
- package/es6/modules/animations/css-movement.js +0 -170
- package/es6/modules/animations/movement.js +0 -131
- package/es6/modules/animations/value.js +0 -187
- package/es6/modules/atom/atom.js +0 -54
- package/es6/modules/component/component.js +0 -230
- package/es6/modules/component/event-helper.js +0 -119
- package/es6/modules/component/jot.js +0 -144
- package/es6/modules/component/state-helper.js +0 -262
- package/es6/modules/component/unit.js +0 -551
- package/es6/modules/data/attrs.js +0 -40
- package/es6/modules/data/basic-data.js +0 -500
- package/es6/modules/data/data-utils.js +0 -29
- package/es6/modules/data/data.js +0 -3
- package/es6/modules/data/deep-data.js +0 -541
- package/es6/modules/data/model-service.js +0 -528
- package/es6/modules/data/model.js +0 -133
- package/es6/modules/data/simple-data.js +0 -33
- package/es6/modules/data-binder/connection-tracker.js +0 -113
- package/es6/modules/data-binder/connection.js +0 -16
- package/es6/modules/data-binder/data-binder.js +0 -352
- package/es6/modules/data-binder/data-pub-sub.js +0 -141
- package/es6/modules/data-binder/data-source.js +0 -56
- package/es6/modules/data-binder/element-source.js +0 -219
- package/es6/modules/data-binder/one-way-connection.js +0 -46
- package/es6/modules/data-binder/one-way-source.js +0 -43
- package/es6/modules/data-binder/source.js +0 -36
- package/es6/modules/data-binder/two-way-connection.js +0 -75
- package/es6/modules/data-binder/two-way-source.js +0 -41
- package/es6/modules/date/date.js +0 -544
- package/es6/modules/history/history.js +0 -89
- package/es6/modules/html-builder/html-builder.js +0 -434
- package/es6/modules/import/import.js +0 -390
- package/es6/modules/layout/layout-builder.js +0 -1269
- package/es6/modules/layout/layout-parser.js +0 -134
- package/es6/modules/layout/watcher-helper.js +0 -282
- package/es6/modules/mouse/mouse.js +0 -114
- package/es6/modules/router/component-helper.js +0 -163
- package/es6/modules/router/history-controller.js +0 -216
- package/es6/modules/router/nav-link.js +0 -124
- package/es6/modules/router/route.js +0 -401
- package/es6/modules/router/router.js +0 -789
- package/es6/modules/router/utils.js +0 -31
- package/es6/modules/state/state-target.js +0 -91
- package/es6/modules/state/state.js +0 -171
- package/es6/package-lock.json +0 -13
- package/es6/package.json +0 -28
- package/es6/shared/objects.js +0 -99
- package/events.js +0 -602
- package/legacy/es5/base.js +0 -2968
- package/legacy/es5/modules/ajax.js +0 -663
- package/legacy/es5/modules/animation.js +0 -188
- package/legacy/es5/modules/animations.js +0 -1080
- package/legacy/es5/modules/atom.js +0 -65
- package/legacy/es5/modules/component.js +0 -1310
- package/legacy/es5/modules/data-binder.js +0 -1131
- package/legacy/es5/modules/data.js +0 -1808
- package/legacy/es5/modules/date.js +0 -525
- package/legacy/es5/modules/form-validator.js +0 -324
- package/legacy/es5/modules/history.js +0 -126
- package/legacy/es5/modules/html-builder.js +0 -461
- package/legacy/es5/modules/layout.js +0 -1679
- package/legacy/es5/modules/mouse.js +0 -124
- package/legacy/es5/modules/nav-link.js +0 -123
- package/legacy/es5/modules/olderversions/animations-ease.js +0 -1095
- package/legacy/es5/modules/olderversions/animations-update.js +0 -1048
- package/legacy/es5/modules/olderversions/base-animations.js +0 -636
- package/legacy/es5/modules/olderversions/base-component-class.js +0 -100
- package/legacy/es5/modules/olderversions/base-data-binder-1.js +0 -407
- package/legacy/es5/modules/olderversions/base-data-binder-class.js +0 -358
- package/legacy/es5/modules/olderversions/base-layout-parser-class.js +0 -172
- package/legacy/es5/modules/olderversions/base-mode-1.js +0 -777
- package/legacy/es5/modules/olderversions/base-model-class.js +0 -585
- package/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
- package/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
- package/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
- package/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
- package/legacy/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
- package/legacy/es5/modules/olderversions/data-tracker.js +0 -187
- package/legacy/es5/modules/olderversions/event-update.js +0 -666
- package/legacy/es5/modules/olderversions/nav-link.js +0 -119
- package/legacy/es5/modules/olderversions/router-with-templates-1.js +0 -785
- package/legacy/es5/modules/olderversions/router-with-templates.js +0 -701
- package/legacy/es5/modules/prototypes/ajax.js +0 -657
- package/legacy/es5/modules/prototypes/atom.js +0 -65
- package/legacy/es5/modules/prototypes/component.js +0 -972
- package/legacy/es5/modules/prototypes/data-binder.js +0 -1089
- package/legacy/es5/modules/prototypes/data.js +0 -1290
- package/legacy/es5/modules/prototypes/html-builder.js +0 -414
- package/legacy/es5/modules/prototypes/layout.js +0 -879
- package/legacy/es5/modules/router.js +0 -1680
- package/legacy/es5/modules/state.js +0 -274
- package/main.js +0 -1331
- package/modules/ajax/ajax.js +0 -514
- package/modules/animation/animation.js +0 -236
- package/modules/animations/animation-controller.js +0 -231
- package/modules/animations/animation.js +0 -64
- package/modules/animations/attr-movement.js +0 -66
- package/modules/animations/css-movement.js +0 -170
- package/modules/animations/movement.js +0 -131
- package/modules/animations/value.js +0 -187
- package/modules/atom/atom.js +0 -54
- package/modules/component/component.js +0 -230
- package/modules/component/event-helper.js +0 -119
- package/modules/component/jot.js +0 -144
- package/modules/component/state-helper.js +0 -262
- package/modules/component/unit.js +0 -551
- package/modules/data/attrs.js +0 -40
- package/modules/data/basic-data.js +0 -500
- package/modules/data/data-utils.js +0 -29
- package/modules/data/data.js +0 -3
- package/modules/data/deep-data.js +0 -541
- package/modules/data/model-service.js +0 -528
- package/modules/data/model.js +0 -133
- package/modules/data/simple-data.js +0 -33
- package/modules/data-binder/connection-tracker.js +0 -113
- package/modules/data-binder/connection.js +0 -16
- package/modules/data-binder/data-binder.js +0 -352
- package/modules/data-binder/data-pub-sub.js +0 -141
- package/modules/data-binder/data-source.js +0 -56
- package/modules/data-binder/element-source.js +0 -219
- package/modules/data-binder/one-way-connection.js +0 -46
- package/modules/data-binder/one-way-source.js +0 -43
- package/modules/data-binder/source.js +0 -36
- package/modules/data-binder/two-way-connection.js +0 -75
- package/modules/data-binder/two-way-source.js +0 -41
- package/modules/date/date.js +0 -544
- package/modules/history/history.js +0 -89
- package/modules/html-builder/html-builder.js +0 -434
- package/modules/import/import.js +0 -390
- package/modules/layout/layout-builder.js +0 -1269
- package/modules/layout/layout-parser.js +0 -134
- package/modules/layout/watcher-helper.js +0 -282
- package/modules/mouse/mouse.js +0 -114
- package/modules/router/component-helper.js +0 -163
- package/modules/router/history-controller.js +0 -216
- package/modules/router/nav-link.js +0 -124
- package/modules/router/route.js +0 -401
- package/modules/router/router.js +0 -789
- package/modules/router/utils.js +0 -31
- package/modules/state/state-target.js +0 -91
- package/modules/state/state.js +0 -171
- package/shared/objects.js +0 -99
- package/update +0 -16
|
@@ -1,640 +0,0 @@
|
|
|
1
|
-
/* base framework module */
|
|
2
|
-
(function()
|
|
3
|
-
{
|
|
4
|
-
"use strict";
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
DataPubSub
|
|
8
|
-
|
|
9
|
-
this will create a pub sub object
|
|
10
|
-
to allow messages to be subscribed to and
|
|
11
|
-
publish changes that will be pushed to the
|
|
12
|
-
subscribers.
|
|
13
|
-
|
|
14
|
-
*/
|
|
15
|
-
var DataPubSub = base.Class.extend(
|
|
16
|
-
{
|
|
17
|
-
constructor: function()
|
|
18
|
-
{
|
|
19
|
-
this.callBacks = {};
|
|
20
|
-
this.lastToken = -1;
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
/* this will get the subscriber array for the
|
|
24
|
-
message or create a new subscriber array if none
|
|
25
|
-
is setup already.
|
|
26
|
-
@param (string) msg
|
|
27
|
-
@return (array) subscriber array */
|
|
28
|
-
get: function(msg)
|
|
29
|
-
{
|
|
30
|
-
var callBacks = this.callBacks;
|
|
31
|
-
return (callBacks[msg] || (callBacks[msg] = []));
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
reset: function()
|
|
35
|
-
{
|
|
36
|
-
this.callBacks = {};
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
on: function(msg, callBack)
|
|
40
|
-
{
|
|
41
|
-
var token = (++this.lastToken);
|
|
42
|
-
var list = this.get(msg);
|
|
43
|
-
list.push({
|
|
44
|
-
token: token,
|
|
45
|
-
callBack: callBack
|
|
46
|
-
});
|
|
47
|
-
return token;
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
off: function(msg, token)
|
|
51
|
-
{
|
|
52
|
-
var list = this.callBacks[msg] || false;
|
|
53
|
-
if(list)
|
|
54
|
-
{
|
|
55
|
-
var length = list.length;
|
|
56
|
-
for (var i = 0; i < length; i++ )
|
|
57
|
-
{
|
|
58
|
-
var item = list[i];
|
|
59
|
-
if(item.token === token)
|
|
60
|
-
{
|
|
61
|
-
list.splice(i, 1);
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
remove: function(msg)
|
|
69
|
-
{
|
|
70
|
-
var callBacks = this.callBacks;
|
|
71
|
-
if(callBacks[msg])
|
|
72
|
-
{
|
|
73
|
-
delete callBacks[msg];
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
publish: function(msg)
|
|
78
|
-
{
|
|
79
|
-
var i, length,
|
|
80
|
-
list = this.callBacks[msg] || false;
|
|
81
|
-
if(list !== false)
|
|
82
|
-
{
|
|
83
|
-
length = list.length;
|
|
84
|
-
for (i = 0; i < length; i++ )
|
|
85
|
-
{
|
|
86
|
-
list[i].callBack.apply(this, arguments);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
var pubSub = new DataPubSub();
|
|
93
|
-
base.extend.DataPubSub = DataPubSub;
|
|
94
|
-
|
|
95
|
-
var Source = base.Class.extend(
|
|
96
|
-
{
|
|
97
|
-
constructor: function()
|
|
98
|
-
{
|
|
99
|
-
this.msg = null;
|
|
100
|
-
this.token = null;
|
|
101
|
-
},
|
|
102
|
-
|
|
103
|
-
setToken: function(token)
|
|
104
|
-
{
|
|
105
|
-
this.token = token;
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
callBack: null,
|
|
109
|
-
|
|
110
|
-
subscribe: function(msg)
|
|
111
|
-
{
|
|
112
|
-
this.msg = msg;
|
|
113
|
-
var callBack = base.bind(this, this.callBack);
|
|
114
|
-
this.token = pubSub.on(msg, callBack);
|
|
115
|
-
},
|
|
116
|
-
|
|
117
|
-
unsubscribe: function()
|
|
118
|
-
{
|
|
119
|
-
pubSub.off(this.msg, this.token);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
var DataSource = Source.extend(
|
|
124
|
-
{
|
|
125
|
-
constructor: function(data, prop)
|
|
126
|
-
{
|
|
127
|
-
Source.call(this);
|
|
128
|
-
this.data = data;
|
|
129
|
-
this.prop = prop;
|
|
130
|
-
},
|
|
131
|
-
|
|
132
|
-
set: function(value)
|
|
133
|
-
{
|
|
134
|
-
this.data.set(this.prop, value);
|
|
135
|
-
},
|
|
136
|
-
|
|
137
|
-
get: function()
|
|
138
|
-
{
|
|
139
|
-
return this.data.get(this.prop);
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
callBack: function(evt, prop, value, committer)
|
|
143
|
-
{
|
|
144
|
-
if(this.data !== this.committer)
|
|
145
|
-
{
|
|
146
|
-
this.data.set(prop, value, committer);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
var ElementSource = Source.extend(
|
|
152
|
-
{
|
|
153
|
-
constructor: function(element, attr, filter)
|
|
154
|
-
{
|
|
155
|
-
Source.call(this);
|
|
156
|
-
this.element = element;
|
|
157
|
-
this.attr = this.getAttrBind(attr);
|
|
158
|
-
|
|
159
|
-
if(typeof filter === 'string')
|
|
160
|
-
{
|
|
161
|
-
filter = this.setupFilter(filter);
|
|
162
|
-
}
|
|
163
|
-
this.filter = filter;
|
|
164
|
-
},
|
|
165
|
-
|
|
166
|
-
getAttrBind: function(customAttr)
|
|
167
|
-
{
|
|
168
|
-
/* this will setup the custom attr if the prop
|
|
169
|
-
has specified one. */
|
|
170
|
-
if(customAttr)
|
|
171
|
-
{
|
|
172
|
-
return customAttr;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
var attr = 'textContent';
|
|
176
|
-
/* if no custom attr has been requested we will get the
|
|
177
|
-
default attr of the element */
|
|
178
|
-
var element = this.element;
|
|
179
|
-
if(element && typeof element === 'object')
|
|
180
|
-
{
|
|
181
|
-
var tagName = element.tagName.toLowerCase();
|
|
182
|
-
if (tagName === "input" || tagName === "textarea" || tagName === "select")
|
|
183
|
-
{
|
|
184
|
-
var type = element.type;
|
|
185
|
-
if(type && (type === 'checkbox' || type === 'radio'))
|
|
186
|
-
{
|
|
187
|
-
attr = 'checked';
|
|
188
|
-
}
|
|
189
|
-
else
|
|
190
|
-
{
|
|
191
|
-
attr = 'value';
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return attr;
|
|
196
|
-
},
|
|
197
|
-
|
|
198
|
-
setupFilter: function(filter)
|
|
199
|
-
{
|
|
200
|
-
var pattern = /(\[\[[^\]]+\]\])/;
|
|
201
|
-
return function(value)
|
|
202
|
-
{
|
|
203
|
-
return filter.replace(pattern, value);
|
|
204
|
-
};
|
|
205
|
-
},
|
|
206
|
-
|
|
207
|
-
/* this will set a value on an elememnt.
|
|
208
|
-
@param (mixed) value */
|
|
209
|
-
set: function(value)
|
|
210
|
-
{
|
|
211
|
-
var element = this.element;
|
|
212
|
-
if(element && typeof element === 'object')
|
|
213
|
-
{
|
|
214
|
-
/* this will check to apply the option filter before
|
|
215
|
-
settings the value */
|
|
216
|
-
if(this.filter)
|
|
217
|
-
{
|
|
218
|
-
value = this.filter(value);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
var attr = this.attr,
|
|
222
|
-
type = element.type;
|
|
223
|
-
if(type && (type === 'checkbox' || type === 'radio'))
|
|
224
|
-
{
|
|
225
|
-
value = (value == 1);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if(attr.substring(0, 5) === 'data-')
|
|
229
|
-
{
|
|
230
|
-
base.data(element, attr, value);
|
|
231
|
-
}
|
|
232
|
-
else
|
|
233
|
-
{
|
|
234
|
-
element[attr] = value;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
},
|
|
238
|
-
|
|
239
|
-
/* this will get a value on an elememnt.
|
|
240
|
-
@return (mixed) the element value */
|
|
241
|
-
get: function()
|
|
242
|
-
{
|
|
243
|
-
var value = '',
|
|
244
|
-
element = this.element;
|
|
245
|
-
if(element && typeof element === 'object')
|
|
246
|
-
{
|
|
247
|
-
var attr = this.attr;
|
|
248
|
-
if(attr.substring(0, 5) === 'data-')
|
|
249
|
-
{
|
|
250
|
-
value = base.data(element, attr);
|
|
251
|
-
}
|
|
252
|
-
else
|
|
253
|
-
{
|
|
254
|
-
value = element[attr];
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
return value;
|
|
258
|
-
},
|
|
259
|
-
|
|
260
|
-
callBack: function(evt, prop, value, committer)
|
|
261
|
-
{
|
|
262
|
-
if(committer !== this.element)
|
|
263
|
-
{
|
|
264
|
-
this.set(value);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
var Connection = base.Class.extend(
|
|
270
|
-
{
|
|
271
|
-
constructor: function()
|
|
272
|
-
{
|
|
273
|
-
this.element = null;
|
|
274
|
-
this.data = null;
|
|
275
|
-
},
|
|
276
|
-
|
|
277
|
-
addElement: function(element, attr, filter)
|
|
278
|
-
{
|
|
279
|
-
return (this.element = new ElementSource(element, attr, filter));
|
|
280
|
-
},
|
|
281
|
-
|
|
282
|
-
addData: function(data, prop)
|
|
283
|
-
{
|
|
284
|
-
return (this.data = new DataSource(data, prop));
|
|
285
|
-
},
|
|
286
|
-
|
|
287
|
-
unsubscribeSource: function(source)
|
|
288
|
-
{
|
|
289
|
-
if(source)
|
|
290
|
-
{
|
|
291
|
-
source.unsubscribe();
|
|
292
|
-
}
|
|
293
|
-
},
|
|
294
|
-
|
|
295
|
-
unsubscribe: function()
|
|
296
|
-
{
|
|
297
|
-
this.unsubscribeSource(this.element);
|
|
298
|
-
this.unsubscribeSource(this.data);
|
|
299
|
-
|
|
300
|
-
this.element = null;
|
|
301
|
-
this.data = null;
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
var ConnectionTracker = base.Class.extend(
|
|
306
|
-
{
|
|
307
|
-
constructor: function()
|
|
308
|
-
{
|
|
309
|
-
this.connections = {};
|
|
310
|
-
},
|
|
311
|
-
|
|
312
|
-
add: function(id, connection)
|
|
313
|
-
{
|
|
314
|
-
var connections = this.connections;
|
|
315
|
-
return (connections[id] = connection);
|
|
316
|
-
},
|
|
317
|
-
|
|
318
|
-
get: function(id)
|
|
319
|
-
{
|
|
320
|
-
return (this.connections[id] || false);
|
|
321
|
-
},
|
|
322
|
-
|
|
323
|
-
remove: function(id)
|
|
324
|
-
{
|
|
325
|
-
var connection = this.connections[id];
|
|
326
|
-
if(connection)
|
|
327
|
-
{
|
|
328
|
-
connection.unsubscribe();
|
|
329
|
-
delete this.connections[id];
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
var WatcherTracker = base.Class.extend(
|
|
335
|
-
{
|
|
336
|
-
constructor: function()
|
|
337
|
-
{
|
|
338
|
-
this.watchers = {};
|
|
339
|
-
},
|
|
340
|
-
|
|
341
|
-
find: function(id)
|
|
342
|
-
{
|
|
343
|
-
var watchers = this.watchers;
|
|
344
|
-
return (watchers[id] || (watchers[id] = []));
|
|
345
|
-
},
|
|
346
|
-
|
|
347
|
-
add: function(id, data, prop, callBack)
|
|
348
|
-
{
|
|
349
|
-
var subscriptions = this.find(id);
|
|
350
|
-
subscriptions.push({
|
|
351
|
-
data: data,
|
|
352
|
-
msg: prop,
|
|
353
|
-
token: this.getSubscription(data, prop, callBack)
|
|
354
|
-
});
|
|
355
|
-
},
|
|
356
|
-
|
|
357
|
-
getSubscription: function(data, prop, callBack)
|
|
358
|
-
{
|
|
359
|
-
return data.on(prop, callBack);
|
|
360
|
-
},
|
|
361
|
-
|
|
362
|
-
get: function(id)
|
|
363
|
-
{
|
|
364
|
-
return (this.watchers[id] || false);
|
|
365
|
-
},
|
|
366
|
-
|
|
367
|
-
remove: function(id)
|
|
368
|
-
{
|
|
369
|
-
var subscriptions = this.watchers[id];
|
|
370
|
-
if(subscriptions)
|
|
371
|
-
{
|
|
372
|
-
for(var i = 0, length = subscriptions.length; i < length; i++)
|
|
373
|
-
{
|
|
374
|
-
var subscription = subscriptions[i];
|
|
375
|
-
if(subscription)
|
|
376
|
-
{
|
|
377
|
-
subscription.data.off(subscription.msg, subscription.token);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
delete this.watchers[id];
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
/*
|
|
386
|
-
DataBinder
|
|
387
|
-
|
|
388
|
-
this create a data bind module to add
|
|
389
|
-
two way data binding to base models.
|
|
390
|
-
*/
|
|
391
|
-
var DataBinder = base.Class.extend(
|
|
392
|
-
{
|
|
393
|
-
constructor: function()
|
|
394
|
-
{
|
|
395
|
-
this.version = "1.0.1";
|
|
396
|
-
this.attr = 'data-bind';
|
|
397
|
-
|
|
398
|
-
this.connections = new ConnectionTracker();
|
|
399
|
-
this.watchers = new WatcherTracker();
|
|
400
|
-
|
|
401
|
-
this.idCount = 0;
|
|
402
|
-
this.setup();
|
|
403
|
-
},
|
|
404
|
-
|
|
405
|
-
setup: function()
|
|
406
|
-
{
|
|
407
|
-
this.setupEvents();
|
|
408
|
-
},
|
|
409
|
-
|
|
410
|
-
/* this will add the data bind attr on an
|
|
411
|
-
element for a model property.
|
|
412
|
-
@param (object) element
|
|
413
|
-
@param (object) data
|
|
414
|
-
@param (string) prop
|
|
415
|
-
@return (object) the instance of the data binder */
|
|
416
|
-
bind: function(element, data, prop, filter)
|
|
417
|
-
{
|
|
418
|
-
var bindSettings = this.getPropSettings(prop);
|
|
419
|
-
prop = bindSettings.prop;
|
|
420
|
-
|
|
421
|
-
/* this will setup the model bind attr to the
|
|
422
|
-
element and assign a bind id attr to support
|
|
423
|
-
two way binding */
|
|
424
|
-
var connection = this.setupConnection(element, data, prop, bindSettings.attr, filter);
|
|
425
|
-
|
|
426
|
-
/* we want to get the starting value of the
|
|
427
|
-
data and set it on our element */
|
|
428
|
-
var connectionElement = connection.element,
|
|
429
|
-
value = data.get(prop);
|
|
430
|
-
if(typeof value !== 'undefined')
|
|
431
|
-
{
|
|
432
|
-
connectionElement.set(value);
|
|
433
|
-
}
|
|
434
|
-
else
|
|
435
|
-
{
|
|
436
|
-
/* this will set the element value
|
|
437
|
-
as the prop value */
|
|
438
|
-
value = connectionElement.get();
|
|
439
|
-
if(value !== '')
|
|
440
|
-
{
|
|
441
|
-
connection.data.set(value);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
return this;
|
|
445
|
-
},
|
|
446
|
-
|
|
447
|
-
setupConnection: function(element, data, prop, customAttr, filter)
|
|
448
|
-
{
|
|
449
|
-
var connection = new Connection();
|
|
450
|
-
|
|
451
|
-
var id = this.getBindId(element);
|
|
452
|
-
var dataSource = connection.addData(data, prop);
|
|
453
|
-
dataSource.subscribe(id);
|
|
454
|
-
|
|
455
|
-
/* this will add the data binding
|
|
456
|
-
attr to out element so it will subscribe to
|
|
457
|
-
the two data changes */
|
|
458
|
-
var dataId = data.getDataId(),
|
|
459
|
-
msg = dataId + ':' + prop;
|
|
460
|
-
|
|
461
|
-
var elementSource = connection.addElement(element, customAttr, filter);
|
|
462
|
-
elementSource.subscribe(msg);
|
|
463
|
-
|
|
464
|
-
this.addConnection(id, connection);
|
|
465
|
-
|
|
466
|
-
return connection;
|
|
467
|
-
},
|
|
468
|
-
|
|
469
|
-
addConnection: function(id, connection)
|
|
470
|
-
{
|
|
471
|
-
this.connections.add(id, connection);
|
|
472
|
-
},
|
|
473
|
-
|
|
474
|
-
setBindId: function(element)
|
|
475
|
-
{
|
|
476
|
-
var id = 'bs-db-' + this.idCount++;
|
|
477
|
-
base.attr(element, this.attr + '-id', id);
|
|
478
|
-
return id;
|
|
479
|
-
},
|
|
480
|
-
|
|
481
|
-
getBindId: function(element)
|
|
482
|
-
{
|
|
483
|
-
var id = base.attr(element, this.attr + '-id');
|
|
484
|
-
if(!id)
|
|
485
|
-
{
|
|
486
|
-
id = this.setBindId(element);
|
|
487
|
-
}
|
|
488
|
-
return id;
|
|
489
|
-
},
|
|
490
|
-
|
|
491
|
-
getPropSettings: function(prop)
|
|
492
|
-
{
|
|
493
|
-
var bindProp = prop,
|
|
494
|
-
bindAttr = null;
|
|
495
|
-
|
|
496
|
-
/* this will setup the custom attr if the prop
|
|
497
|
-
has specified one. */
|
|
498
|
-
var parts = prop.split(':');
|
|
499
|
-
if(parts.length > 1)
|
|
500
|
-
{
|
|
501
|
-
bindProp = parts[1];
|
|
502
|
-
bindAttr = parts[0];
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
return {
|
|
506
|
-
prop: bindProp,
|
|
507
|
-
attr: bindAttr
|
|
508
|
-
};
|
|
509
|
-
},
|
|
510
|
-
|
|
511
|
-
/* this will remove an element from the data binder
|
|
512
|
-
@param (object) element
|
|
513
|
-
@return (object) the instance of the data binder*/
|
|
514
|
-
unbind: function(element)
|
|
515
|
-
{
|
|
516
|
-
var id = base.data(element, this.attr + '-id');
|
|
517
|
-
if(id)
|
|
518
|
-
{
|
|
519
|
-
this.connections.remove(id);
|
|
520
|
-
this.watchers.remove(id);
|
|
521
|
-
}
|
|
522
|
-
return this;
|
|
523
|
-
},
|
|
524
|
-
|
|
525
|
-
watch: function(element, data, prop, callBack)
|
|
526
|
-
{
|
|
527
|
-
if(!element || typeof element !== 'object')
|
|
528
|
-
{
|
|
529
|
-
return false;
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
var id = this.getBindId(element);
|
|
533
|
-
this.watchers.add(id, data, prop, callBack);
|
|
534
|
-
},
|
|
535
|
-
|
|
536
|
-
unwatch: function(element)
|
|
537
|
-
{
|
|
538
|
-
if(!element || typeof element !== 'object')
|
|
539
|
-
{
|
|
540
|
-
return false;
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
var id = base.attr(element, this.attr + '-id');
|
|
544
|
-
if(id)
|
|
545
|
-
{
|
|
546
|
-
this.watchers.remove(element);
|
|
547
|
-
}
|
|
548
|
-
},
|
|
549
|
-
|
|
550
|
-
/* this will publish a change to the data binder.
|
|
551
|
-
@param (string) message e.g id:change
|
|
552
|
-
@param (string) attrName = the model prop name
|
|
553
|
-
@param (mixed) the prop value
|
|
554
|
-
@param (object) the object committing the change */
|
|
555
|
-
publish: function(msg, attr, value, committer)
|
|
556
|
-
{
|
|
557
|
-
pubSub.publish(msg, attr, value, committer);
|
|
558
|
-
return this;
|
|
559
|
-
},
|
|
560
|
-
|
|
561
|
-
isDataBound: function(element)
|
|
562
|
-
{
|
|
563
|
-
if(element)
|
|
564
|
-
{
|
|
565
|
-
var dataAttr = this.attr;
|
|
566
|
-
var id = base.data(element, dataAttr + '-id');
|
|
567
|
-
if(id)
|
|
568
|
-
{
|
|
569
|
-
return id;
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
return false;
|
|
573
|
-
},
|
|
574
|
-
|
|
575
|
-
blockedKeys: [
|
|
576
|
-
17, //ctrl
|
|
577
|
-
9, //tab
|
|
578
|
-
16, //shift
|
|
579
|
-
18, //alt
|
|
580
|
-
20, //caps lock
|
|
581
|
-
37, //arrows
|
|
582
|
-
38,
|
|
583
|
-
39,
|
|
584
|
-
40
|
|
585
|
-
],
|
|
586
|
-
|
|
587
|
-
bindHandler: function(evt)
|
|
588
|
-
{
|
|
589
|
-
if(evt.type === 'keyup')
|
|
590
|
-
{
|
|
591
|
-
/* this will check to block ctrl, shift or alt +
|
|
592
|
-
buttons */
|
|
593
|
-
if(evt.ctrlKey !== false || evt.shiftKey !== false || evt.altKey !== false || base.inArray(this.blockedKeys, evt.keyCode) !== -1)
|
|
594
|
-
{
|
|
595
|
-
return true;
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
var target = evt.target || evt.srcElement;
|
|
600
|
-
var id = this.isDataBound(target);
|
|
601
|
-
if(id)
|
|
602
|
-
{
|
|
603
|
-
var connection = this.connections.get(id);
|
|
604
|
-
if(connection)
|
|
605
|
-
{
|
|
606
|
-
var value = connection.element.get();
|
|
607
|
-
/* this will publish to the ui and to the
|
|
608
|
-
model that subscribes to the element */
|
|
609
|
-
pubSub.publish(id, connection.data.prop, value, target);
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
evt.stopPropagation();
|
|
613
|
-
},
|
|
614
|
-
|
|
615
|
-
/* this will setup the on change handler and
|
|
616
|
-
add the events. this needs to be setup before adding
|
|
617
|
-
the events. */
|
|
618
|
-
changeHandler: null,
|
|
619
|
-
setupEvents: function()
|
|
620
|
-
{
|
|
621
|
-
this.changeHandler = base.bind(this, this.bindHandler);
|
|
622
|
-
|
|
623
|
-
this.addEvents();
|
|
624
|
-
},
|
|
625
|
-
|
|
626
|
-
/* this will add the binder events */
|
|
627
|
-
addEvents: function()
|
|
628
|
-
{
|
|
629
|
-
base.on(["change", "keyup"], document, this.changeHandler, false);
|
|
630
|
-
},
|
|
631
|
-
|
|
632
|
-
/* this will remove the binder events */
|
|
633
|
-
removeEvents: function()
|
|
634
|
-
{
|
|
635
|
-
base.off(["change", "keyup"], document, this.changeHandler, false);
|
|
636
|
-
}
|
|
637
|
-
});
|
|
638
|
-
|
|
639
|
-
base.extend.DataBinder = new DataBinder();
|
|
640
|
-
})();
|