@base-framework/base 2.6.0 → 2.6.1
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/base.min.js +1 -0
- package/es5/base.js +2968 -0
- package/es5/modules/ajax.js +663 -0
- package/es5/modules/animation.js +188 -0
- package/es5/modules/animations.js +1080 -0
- package/es5/modules/atom.js +65 -0
- package/es5/modules/component.js +1310 -0
- package/es5/modules/data-binder.js +1131 -0
- package/es5/modules/data.js +1808 -0
- package/es5/modules/date.js +525 -0
- package/es5/modules/form-validator.js +324 -0
- package/es5/modules/history.js +126 -0
- package/es5/modules/html-builder.js +461 -0
- package/es5/modules/layout.js +1679 -0
- package/es5/modules/mouse.js +124 -0
- package/es5/modules/nav-link.js +123 -0
- package/es5/modules/olderversions/animations-ease.js +1095 -0
- package/es5/modules/olderversions/animations-update.js +1048 -0
- package/es5/modules/olderversions/base-animations.js +636 -0
- package/es5/modules/olderversions/base-component-class.js +100 -0
- package/es5/modules/olderversions/base-data-binder-1.js +407 -0
- package/es5/modules/olderversions/base-data-binder-class.js +358 -0
- package/es5/modules/olderversions/base-layout-parser-class.js +172 -0
- package/es5/modules/olderversions/base-mode-1.js +777 -0
- package/es5/modules/olderversions/base-model-class.js +585 -0
- package/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
- package/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
- package/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
- package/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
- package/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
- package/es5/modules/olderversions/data-tracker.js +187 -0
- package/es5/modules/olderversions/event-update.js +666 -0
- package/es5/modules/olderversions/nav-link.js +119 -0
- package/es5/modules/olderversions/router-with-templates-1.js +785 -0
- package/es5/modules/olderversions/router-with-templates.js +701 -0
- package/es5/modules/prototypes/ajax.js +657 -0
- package/es5/modules/prototypes/atom.js +65 -0
- package/es5/modules/prototypes/component.js +972 -0
- package/es5/modules/prototypes/data-binder.js +1089 -0
- package/es5/modules/prototypes/data.js +1290 -0
- package/es5/modules/prototypes/html-builder.js +414 -0
- package/es5/modules/prototypes/layout.js +879 -0
- package/es5/modules/router.js +1680 -0
- package/es5/modules/state.js +274 -0
- package/es6/.jshintrc +3 -0
- package/es6/base.js +41 -0
- package/es6/core.js +1 -0
- package/es6/data-tracker.js +351 -0
- package/es6/events.js +602 -0
- package/es6/legacy/es5/base.js +2968 -0
- package/es6/legacy/es5/modules/ajax.js +663 -0
- package/es6/legacy/es5/modules/animation.js +188 -0
- package/es6/legacy/es5/modules/animations.js +1080 -0
- package/es6/legacy/es5/modules/atom.js +65 -0
- package/es6/legacy/es5/modules/component.js +1310 -0
- package/es6/legacy/es5/modules/data-binder.js +1131 -0
- package/es6/legacy/es5/modules/data.js +1808 -0
- package/es6/legacy/es5/modules/date.js +525 -0
- package/es6/legacy/es5/modules/form-validator.js +324 -0
- package/es6/legacy/es5/modules/history.js +126 -0
- package/es6/legacy/es5/modules/html-builder.js +461 -0
- package/es6/legacy/es5/modules/layout.js +1679 -0
- package/es6/legacy/es5/modules/mouse.js +124 -0
- package/es6/legacy/es5/modules/nav-link.js +123 -0
- package/es6/legacy/es5/modules/olderversions/animations-ease.js +1095 -0
- package/es6/legacy/es5/modules/olderversions/animations-update.js +1048 -0
- package/es6/legacy/es5/modules/olderversions/base-animations.js +636 -0
- package/es6/legacy/es5/modules/olderversions/base-component-class.js +100 -0
- package/es6/legacy/es5/modules/olderversions/base-data-binder-1.js +407 -0
- package/es6/legacy/es5/modules/olderversions/base-data-binder-class.js +358 -0
- package/es6/legacy/es5/modules/olderversions/base-layout-parser-class.js +172 -0
- package/es6/legacy/es5/modules/olderversions/base-mode-1.js +777 -0
- package/es6/legacy/es5/modules/olderversions/base-model-class.js +585 -0
- package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
- package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
- package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
- package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
- package/es6/legacy/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
- package/es6/legacy/es5/modules/olderversions/data-tracker.js +187 -0
- package/es6/legacy/es5/modules/olderversions/event-update.js +666 -0
- package/es6/legacy/es5/modules/olderversions/nav-link.js +119 -0
- package/es6/legacy/es5/modules/olderversions/router-with-templates-1.js +785 -0
- package/es6/legacy/es5/modules/olderversions/router-with-templates.js +701 -0
- package/es6/legacy/es5/modules/prototypes/ajax.js +657 -0
- package/es6/legacy/es5/modules/prototypes/atom.js +65 -0
- package/es6/legacy/es5/modules/prototypes/component.js +972 -0
- package/es6/legacy/es5/modules/prototypes/data-binder.js +1089 -0
- package/es6/legacy/es5/modules/prototypes/data.js +1290 -0
- package/es6/legacy/es5/modules/prototypes/html-builder.js +414 -0
- package/es6/legacy/es5/modules/prototypes/layout.js +879 -0
- package/es6/legacy/es5/modules/router.js +1680 -0
- package/es6/legacy/es5/modules/state.js +274 -0
- package/es6/main.js +1331 -0
- package/es6/modules/ajax/ajax.js +514 -0
- package/es6/modules/animation/animation.js +236 -0
- package/es6/modules/animations/animation-controller.js +231 -0
- package/es6/modules/animations/animation.js +64 -0
- package/es6/modules/animations/attr-movement.js +66 -0
- package/es6/modules/animations/css-movement.js +170 -0
- package/es6/modules/animations/movement.js +131 -0
- package/es6/modules/animations/value.js +187 -0
- package/es6/modules/atom/atom.js +54 -0
- package/es6/modules/component/component.js +230 -0
- package/es6/modules/component/event-helper.js +119 -0
- package/es6/modules/component/jot.js +144 -0
- package/es6/modules/component/state-helper.js +262 -0
- package/es6/modules/component/unit.js +551 -0
- package/es6/modules/data/attrs.js +40 -0
- package/es6/modules/data/basic-data.js +500 -0
- package/es6/modules/data/data-utils.js +29 -0
- package/es6/modules/data/data.js +3 -0
- package/es6/modules/data/deep-data.js +541 -0
- package/es6/modules/data/model-service.js +528 -0
- package/es6/modules/data/model.js +133 -0
- package/es6/modules/data/simple-data.js +33 -0
- package/es6/modules/data-binder/connection-tracker.js +113 -0
- package/es6/modules/data-binder/connection.js +16 -0
- package/es6/modules/data-binder/data-binder.js +352 -0
- package/es6/modules/data-binder/data-pub-sub.js +141 -0
- package/es6/modules/data-binder/data-source.js +56 -0
- package/es6/modules/data-binder/element-source.js +219 -0
- package/es6/modules/data-binder/one-way-connection.js +46 -0
- package/es6/modules/data-binder/one-way-source.js +43 -0
- package/es6/modules/data-binder/source.js +36 -0
- package/es6/modules/data-binder/two-way-connection.js +75 -0
- package/es6/modules/data-binder/two-way-source.js +41 -0
- package/es6/modules/date/date.js +544 -0
- package/es6/modules/history/history.js +89 -0
- package/es6/modules/html-builder/html-builder.js +434 -0
- package/es6/modules/import/import.js +390 -0
- package/es6/modules/layout/layout-builder.js +1269 -0
- package/es6/modules/layout/layout-parser.js +134 -0
- package/es6/modules/layout/watcher-helper.js +282 -0
- package/es6/modules/mouse/mouse.js +114 -0
- package/es6/modules/router/component-helper.js +163 -0
- package/es6/modules/router/history-controller.js +216 -0
- package/es6/modules/router/nav-link.js +124 -0
- package/es6/modules/router/route.js +401 -0
- package/es6/modules/router/router.js +789 -0
- package/es6/modules/router/utils.js +31 -0
- package/es6/modules/state/state-target.js +91 -0
- package/es6/modules/state/state.js +171 -0
- package/es6/package-lock.json +13 -0
- package/es6/package.json +28 -0
- package/es6/shared/objects.js +99 -0
- package/legacy/es5/base.js +2968 -0
- package/legacy/es5/modules/ajax.js +663 -0
- package/legacy/es5/modules/animation.js +188 -0
- package/legacy/es5/modules/animations.js +1080 -0
- package/legacy/es5/modules/atom.js +65 -0
- package/legacy/es5/modules/component.js +1310 -0
- package/legacy/es5/modules/data-binder.js +1131 -0
- package/legacy/es5/modules/data.js +1808 -0
- package/legacy/es5/modules/date.js +525 -0
- package/legacy/es5/modules/form-validator.js +324 -0
- package/legacy/es5/modules/history.js +126 -0
- package/legacy/es5/modules/html-builder.js +461 -0
- package/legacy/es5/modules/layout.js +1679 -0
- package/legacy/es5/modules/mouse.js +124 -0
- package/legacy/es5/modules/nav-link.js +123 -0
- package/legacy/es5/modules/olderversions/animations-ease.js +1095 -0
- package/legacy/es5/modules/olderversions/animations-update.js +1048 -0
- package/legacy/es5/modules/olderversions/base-animations.js +636 -0
- package/legacy/es5/modules/olderversions/base-component-class.js +100 -0
- package/legacy/es5/modules/olderversions/base-data-binder-1.js +407 -0
- package/legacy/es5/modules/olderversions/base-data-binder-class.js +358 -0
- package/legacy/es5/modules/olderversions/base-layout-parser-class.js +172 -0
- package/legacy/es5/modules/olderversions/base-mode-1.js +777 -0
- package/legacy/es5/modules/olderversions/base-model-class.js +585 -0
- package/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
- package/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
- package/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
- package/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
- package/legacy/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
- package/legacy/es5/modules/olderversions/data-tracker.js +187 -0
- package/legacy/es5/modules/olderversions/event-update.js +666 -0
- package/legacy/es5/modules/olderversions/nav-link.js +119 -0
- package/legacy/es5/modules/olderversions/router-with-templates-1.js +785 -0
- package/legacy/es5/modules/olderversions/router-with-templates.js +701 -0
- package/legacy/es5/modules/prototypes/ajax.js +657 -0
- package/legacy/es5/modules/prototypes/atom.js +65 -0
- package/legacy/es5/modules/prototypes/component.js +972 -0
- package/legacy/es5/modules/prototypes/data-binder.js +1089 -0
- package/legacy/es5/modules/prototypes/data.js +1290 -0
- package/legacy/es5/modules/prototypes/html-builder.js +414 -0
- package/legacy/es5/modules/prototypes/layout.js +879 -0
- package/legacy/es5/modules/router.js +1680 -0
- package/legacy/es5/modules/state.js +274 -0
- package/package.json +8 -3
- package/update +16 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/* base framework module */
|
|
2
|
+
(function()
|
|
3
|
+
{
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
Component
|
|
8
|
+
|
|
9
|
+
this will allow components to be extend
|
|
10
|
+
from a single factory.
|
|
11
|
+
|
|
12
|
+
example:
|
|
13
|
+
|
|
14
|
+
var QuickFlashPanel = function()
|
|
15
|
+
{
|
|
16
|
+
// call super
|
|
17
|
+
Component.call(this);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
base.Component.extend(
|
|
21
|
+
{
|
|
22
|
+
constructor: QuickFlashPanel
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// or
|
|
26
|
+
|
|
27
|
+
QuickFlashPanel.prototype = base.Component.extend(
|
|
28
|
+
{
|
|
29
|
+
constructor: QuickFlashPanel
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
*/
|
|
33
|
+
var Component = function()
|
|
34
|
+
{
|
|
35
|
+
this.init();
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/* this will extedn the html builder to allow the
|
|
39
|
+
components to build */
|
|
40
|
+
Component.prototype = base.extendClass( base.htmlBuilder,
|
|
41
|
+
{
|
|
42
|
+
constructor: Component,
|
|
43
|
+
|
|
44
|
+
/* this will setup the component number and unique
|
|
45
|
+
instance id for the component elements.
|
|
46
|
+
@param [(string)] overrideName = the component name to
|
|
47
|
+
override the constructor name */
|
|
48
|
+
init: function(overrideName)
|
|
49
|
+
{
|
|
50
|
+
var constructor = this.constructor;
|
|
51
|
+
this.number = (typeof constructor.number === 'undefined')? constructor.number = 0 : (++constructor.number);
|
|
52
|
+
|
|
53
|
+
var name = overrideName || constructor.name || this.componentTypeId;
|
|
54
|
+
this.id = name + this.number;
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
bind: function(element, model, prop)
|
|
58
|
+
{
|
|
59
|
+
if(element)
|
|
60
|
+
{
|
|
61
|
+
base.DataBinder.bind(element, model, value);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
var componentTypeNumber = 0;
|
|
67
|
+
|
|
68
|
+
/* this will allow the components to be extened.
|
|
69
|
+
@param (object) child = the child object to extend
|
|
70
|
+
@return (mixed) the new child prototype or false */
|
|
71
|
+
Component.extend = function(child)
|
|
72
|
+
{
|
|
73
|
+
/* the child constructor must be set to set
|
|
74
|
+
the parent static methods on the child */
|
|
75
|
+
var constructor = child && child.constructor? child.constructor : false;
|
|
76
|
+
if(constructor)
|
|
77
|
+
{
|
|
78
|
+
/* this will add the parent class to the
|
|
79
|
+
child class */
|
|
80
|
+
constructor.prototype = base.extendClass(this.prototype, child);
|
|
81
|
+
|
|
82
|
+
/* this will assign a unique id to the type of
|
|
83
|
+
component */
|
|
84
|
+
constructor.prototype.componentTypeId = 'base-comp-' + (componentTypeNumber++);
|
|
85
|
+
|
|
86
|
+
/* this will add the static methods from the parent to
|
|
87
|
+
the child constructor. could use assign but ie doesn't
|
|
88
|
+
support it */
|
|
89
|
+
//Object.assign(constructor, this);
|
|
90
|
+
base.extendObject(this, constructor);
|
|
91
|
+
return constructor.prototype;
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/* this will add a reference to the component
|
|
97
|
+
object */
|
|
98
|
+
base.extend.component = base.extend.Component = Component;
|
|
99
|
+
|
|
100
|
+
})();
|
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
/* base framework module */
|
|
2
|
+
(function()
|
|
3
|
+
{
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
DataBinder
|
|
8
|
+
|
|
9
|
+
this create a data bind module to add
|
|
10
|
+
two way data binding to base models.
|
|
11
|
+
|
|
12
|
+
@param [(string)] attr
|
|
13
|
+
|
|
14
|
+
*/
|
|
15
|
+
var DataBinder = function(attr)
|
|
16
|
+
{
|
|
17
|
+
this.attr = attr || 'data-bind';
|
|
18
|
+
/* this will create a new pub sub object
|
|
19
|
+
that will be used to propagate the changes */
|
|
20
|
+
this.pubSub = new DataPubSub();
|
|
21
|
+
this.idCount = 0;
|
|
22
|
+
this.setup();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
DataBinder.prototype =
|
|
26
|
+
{
|
|
27
|
+
constructor: DataBinder,
|
|
28
|
+
|
|
29
|
+
setup: function()
|
|
30
|
+
{
|
|
31
|
+
this.setupEvents();
|
|
32
|
+
|
|
33
|
+
/* this will add a callback to our pubsub object
|
|
34
|
+
to check what has been changed even if the model
|
|
35
|
+
is not added to the pub sub. this will allow our
|
|
36
|
+
models to publish changes without being added
|
|
37
|
+
and requiring them to be removed when deleted */
|
|
38
|
+
this.pubSub.callBack = base.bind(this, this.messageChange);
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
/* this will add the data bind attr on an
|
|
42
|
+
|
|
43
|
+
element for a model property.
|
|
44
|
+
@param (object) element
|
|
45
|
+
@param (object) model
|
|
46
|
+
@param (string) prop
|
|
47
|
+
@return (object) the instance of the data binder */
|
|
48
|
+
bind: function(element, model, prop)
|
|
49
|
+
{
|
|
50
|
+
/* this will add the data binding
|
|
51
|
+
attr to out element so it will subscribe to
|
|
52
|
+
the two model changes */
|
|
53
|
+
var modelId = model.getModelId(),
|
|
54
|
+
attr = this.attr;
|
|
55
|
+
base.attr(element, attr, modelId + ':' + prop);
|
|
56
|
+
|
|
57
|
+
/* this will add a unique id to the element
|
|
58
|
+
so the model will know when the element has
|
|
59
|
+
been updated */
|
|
60
|
+
var id = 'bs-db-' + this.idCount++;
|
|
61
|
+
base.attr(element, attr + '-id', id);
|
|
62
|
+
|
|
63
|
+
/* this will setup the model to update
|
|
64
|
+
from the pubSub element changes */
|
|
65
|
+
this.pubSub.on( id, function(evt, prop, value, committer)
|
|
66
|
+
{
|
|
67
|
+
model.set(prop, value, committer);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
/* we want to get the starting value of the
|
|
71
|
+
model and set it on our element */
|
|
72
|
+
var value = model.get(prop);
|
|
73
|
+
if(typeof value !== 'undefined')
|
|
74
|
+
{
|
|
75
|
+
this.set(element, value);
|
|
76
|
+
}
|
|
77
|
+
return this;
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
/* this will remove an element from the data binder
|
|
81
|
+
@param (object) element
|
|
82
|
+
@return (object) the instance of the data binder*/
|
|
83
|
+
unbind: function(element)
|
|
84
|
+
{
|
|
85
|
+
var bindId = base.data(element, this.attr + '-id');
|
|
86
|
+
this.pubSub.remove(bindId);
|
|
87
|
+
return this;
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
messageChange: function(message, prop, value, committer)
|
|
91
|
+
{
|
|
92
|
+
if(typeof message === 'string' && message.indexOf(':') > -1)
|
|
93
|
+
{
|
|
94
|
+
var parts = message.split(':');
|
|
95
|
+
var modelId = parts[0];
|
|
96
|
+
|
|
97
|
+
this.updateElements(modelId, prop, value, committer);
|
|
98
|
+
|
|
99
|
+
/*
|
|
100
|
+
var action = parts[1];
|
|
101
|
+
switch(action)
|
|
102
|
+
{
|
|
103
|
+
case 'change':
|
|
104
|
+
this.updateElements(modelId, prop, value, committer);
|
|
105
|
+
break;
|
|
106
|
+
case 'delete':
|
|
107
|
+
this.deleteElements(modelId, prop);
|
|
108
|
+
break;
|
|
109
|
+
}*/
|
|
110
|
+
}
|
|
111
|
+
return this;
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
/* this will update all elements with the model id
|
|
115
|
+
attr.
|
|
116
|
+
@param (string) modelId
|
|
117
|
+
@param (string) prop
|
|
118
|
+
@param (mixed) value
|
|
119
|
+
@param (object) committer */
|
|
120
|
+
updateElements: function(modelId, prop, value, committer)
|
|
121
|
+
{
|
|
122
|
+
var elements = document.querySelectorAll("[" + this.attr + "='" + modelId + ':' + prop + "']");
|
|
123
|
+
if(elements)
|
|
124
|
+
{
|
|
125
|
+
for(var i = 0, len = elements.length; i < len; i++ )
|
|
126
|
+
{
|
|
127
|
+
var element = elements[i];
|
|
128
|
+
if(committer !== element)
|
|
129
|
+
{
|
|
130
|
+
this.set(element, value);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
/* this will update all elements with the model id
|
|
137
|
+
attr.
|
|
138
|
+
@param (string) modelId
|
|
139
|
+
@param (string) prop
|
|
140
|
+
@param (mixed) value
|
|
141
|
+
@param (object) committer */
|
|
142
|
+
deleteElements: function(modelId, prop)
|
|
143
|
+
{
|
|
144
|
+
var elements = document.querySelectorAll("[" + this.attr + "='" + modelId + ':' + prop + "']");
|
|
145
|
+
if(elements)
|
|
146
|
+
{
|
|
147
|
+
var builder = new base.htmlBuilder();
|
|
148
|
+
for(var i = 0, len = elements.length; i < len; i++ )
|
|
149
|
+
{
|
|
150
|
+
builder.removeElement(elements[i]);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
/* this will set a value on an elememnt.
|
|
156
|
+
@param (object) element
|
|
157
|
+
@param (mixed) value */
|
|
158
|
+
set: function(element, value)
|
|
159
|
+
{
|
|
160
|
+
if(element && typeof element === 'object')
|
|
161
|
+
{
|
|
162
|
+
var tagName = element.tagName.toLowerCase();
|
|
163
|
+
if (tagName === "input" || tagName === "textarea" || tagName === "select" )
|
|
164
|
+
{
|
|
165
|
+
var type = element.type;
|
|
166
|
+
if(type && (type === 'checkbox' || type === 'radio'))
|
|
167
|
+
{
|
|
168
|
+
value = value == 0? false : true;
|
|
169
|
+
element.checked = value;
|
|
170
|
+
}
|
|
171
|
+
else
|
|
172
|
+
{
|
|
173
|
+
element.value = value;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else
|
|
177
|
+
{
|
|
178
|
+
element.textContent = value;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
/* this will get a value on an elememnt.
|
|
184
|
+
@param (object) element
|
|
185
|
+
@param (mixed) value
|
|
186
|
+
@return (mixed) the element value */
|
|
187
|
+
get: function(element)
|
|
188
|
+
{
|
|
189
|
+
var value = '';
|
|
190
|
+
if(element && typeof element === 'object')
|
|
191
|
+
{
|
|
192
|
+
var tagName = element.tagName.toLowerCase();
|
|
193
|
+
if (tagName === "input" || tagName === "textarea" || tagName === "select" )
|
|
194
|
+
{
|
|
195
|
+
var type = element.type;
|
|
196
|
+
if(type && (type === 'checkbox' || type === 'radio'))
|
|
197
|
+
{
|
|
198
|
+
value = element.checked;
|
|
199
|
+
}
|
|
200
|
+
else
|
|
201
|
+
{
|
|
202
|
+
value = element.value;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
else
|
|
206
|
+
{
|
|
207
|
+
value = element.textContent;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return value;
|
|
211
|
+
},
|
|
212
|
+
|
|
213
|
+
/* this will publish a change to the data binder.
|
|
214
|
+
@param (string) message e.g id:change
|
|
215
|
+
@param (string) attrName = the model prop name
|
|
216
|
+
@param (mixed) the prop value
|
|
217
|
+
@param (object) the object committing the change */
|
|
218
|
+
publish: function(message, attrName, value, committer)
|
|
219
|
+
{
|
|
220
|
+
this.pubSub.publish(message, attrName, value, committer);
|
|
221
|
+
return this;
|
|
222
|
+
},
|
|
223
|
+
|
|
224
|
+
onChange: function(message, callBack)
|
|
225
|
+
{
|
|
226
|
+
this.pubSub.on(message, callBack);
|
|
227
|
+
return this;
|
|
228
|
+
},
|
|
229
|
+
|
|
230
|
+
/* this will setup the on change handler and
|
|
231
|
+
add the events. this needs to be setup before adding
|
|
232
|
+
the events. */
|
|
233
|
+
changeHandler: null,
|
|
234
|
+
setupEvents: function()
|
|
235
|
+
{
|
|
236
|
+
var dataAttr = this.attr;
|
|
237
|
+
var isDataBound = function(element)
|
|
238
|
+
{
|
|
239
|
+
if(element)
|
|
240
|
+
{
|
|
241
|
+
var value = base.data(element, dataAttr);
|
|
242
|
+
if(value)
|
|
243
|
+
{
|
|
244
|
+
var parts = value.split(":");
|
|
245
|
+
if(parts.length)
|
|
246
|
+
{
|
|
247
|
+
return {
|
|
248
|
+
id: parts[0],
|
|
249
|
+
value: parts[1],
|
|
250
|
+
bindId: base.data(element, dataAttr + '-id')
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return false;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
/* this will create a closure scope to the object
|
|
259
|
+
by using a local call back function. */
|
|
260
|
+
var self = this, pubSub = this.pubSub;
|
|
261
|
+
this.changeHandler = function(evt)
|
|
262
|
+
{
|
|
263
|
+
if(evt.type === 'keyup')
|
|
264
|
+
{
|
|
265
|
+
var blockedKeys = [
|
|
266
|
+
17, //ctrl
|
|
267
|
+
9, //tab
|
|
268
|
+
16, //shift
|
|
269
|
+
18, //alt
|
|
270
|
+
20, //caps lock
|
|
271
|
+
37, //arrows
|
|
272
|
+
38,
|
|
273
|
+
39,
|
|
274
|
+
40
|
|
275
|
+
];
|
|
276
|
+
/* this will check to block ctrl, shift or alt +
|
|
277
|
+
buttons */
|
|
278
|
+
if(evt.ctrlKey !== false || evt.shiftKey !== false || evt.altKey !== false || base.inArray(blockedKeys, evt.keyCode) !== -1)
|
|
279
|
+
{
|
|
280
|
+
return true;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
var target = evt.target || evt.srcElement;
|
|
285
|
+
var settings = isDataBound(target);
|
|
286
|
+
if(settings)
|
|
287
|
+
{
|
|
288
|
+
var prop = settings.value;
|
|
289
|
+
if(prop && prop !== "")
|
|
290
|
+
{
|
|
291
|
+
var value = self.get(target);
|
|
292
|
+
/* this will publish to the ui and to the
|
|
293
|
+
model that subscribes to the element */
|
|
294
|
+
pubSub.publish(settings.bindId, prop, value, target);
|
|
295
|
+
pubSub.publish(settings.id + ':change', prop, value, target);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
evt.stopPropagation();
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
this.addEvents();
|
|
302
|
+
},
|
|
303
|
+
|
|
304
|
+
/* this will add the binder events */
|
|
305
|
+
addEvents: function()
|
|
306
|
+
{
|
|
307
|
+
base.on(["change", "keyup"], document, this.changeHandler, false);
|
|
308
|
+
},
|
|
309
|
+
|
|
310
|
+
/* this will remove the binder events */
|
|
311
|
+
removeEvents: function()
|
|
312
|
+
{
|
|
313
|
+
base.off(["change", "keyup"], document, this.changeHandler, false);
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
/*
|
|
318
|
+
DataPubSub
|
|
319
|
+
|
|
320
|
+
this will create a pub sub object
|
|
321
|
+
to allow messages to be subscribed to and
|
|
322
|
+
publish changes that will be pushed to the
|
|
323
|
+
subscribers.
|
|
324
|
+
*/
|
|
325
|
+
var DataPubSub = function()
|
|
326
|
+
{
|
|
327
|
+
this.callBacks = {};
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
DataPubSub.prototype =
|
|
331
|
+
{
|
|
332
|
+
constructor: DataPubSub,
|
|
333
|
+
|
|
334
|
+
/* this will get the subscriber array for the
|
|
335
|
+
message or create a new subscriber array if none
|
|
336
|
+
is setup already.
|
|
337
|
+
@param (string) msg
|
|
338
|
+
@return (array) subscriber array */
|
|
339
|
+
get: function(msg)
|
|
340
|
+
{
|
|
341
|
+
var callBacks = this.callBacks;
|
|
342
|
+
return (callBacks[msg] = callBacks[msg] || []);
|
|
343
|
+
},
|
|
344
|
+
|
|
345
|
+
reset: function()
|
|
346
|
+
{
|
|
347
|
+
this.callBacks = [];
|
|
348
|
+
},
|
|
349
|
+
|
|
350
|
+
on: function(msg, callBack)
|
|
351
|
+
{
|
|
352
|
+
var list = this.get(msg);
|
|
353
|
+
list.push(callBack);
|
|
354
|
+
},
|
|
355
|
+
|
|
356
|
+
off: function(msg, callBack)
|
|
357
|
+
{
|
|
358
|
+
var list = this.get(msg);
|
|
359
|
+
var index = base.inArray(list, callBack);
|
|
360
|
+
if(index > -1)
|
|
361
|
+
{
|
|
362
|
+
list.splice(index, 1);
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
|
|
366
|
+
remove: function(msg)
|
|
367
|
+
{
|
|
368
|
+
var callBacks = this.callBacks;
|
|
369
|
+
if(callBacks[msg])
|
|
370
|
+
{
|
|
371
|
+
delete callBacks[msg];
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
|
|
375
|
+
callBack: null,
|
|
376
|
+
|
|
377
|
+
publish: function(msg)
|
|
378
|
+
{
|
|
379
|
+
var i, length,
|
|
380
|
+
list = this.callBacks[msg] || false;
|
|
381
|
+
if(list !== false)
|
|
382
|
+
{
|
|
383
|
+
length = list.length;
|
|
384
|
+
for (i = 0; i < length; i++ )
|
|
385
|
+
{
|
|
386
|
+
list[i].apply(this, arguments);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if(typeof this.callBack === 'function')
|
|
391
|
+
{
|
|
392
|
+
/* this will setujp the params array by pushing
|
|
393
|
+
the publish args to the params array */
|
|
394
|
+
var params = [];
|
|
395
|
+
length = arguments.length;
|
|
396
|
+
for(i = 0; i < length; i++)
|
|
397
|
+
{
|
|
398
|
+
params[i] = arguments[i];
|
|
399
|
+
}
|
|
400
|
+
this.callBack.apply(null, params);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
base.extend.DataPubSub = DataPubSub;
|
|
406
|
+
base.extend.DataBinder = new DataBinder();
|
|
407
|
+
})();
|