neon 2.0.0 → 2.0.2
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/.jshintrc +3 -0
- package/LICENSE +21 -0
- package/README.markdown +5 -5
- package/bower.json +23 -0
- package/license.txt +9 -0
- package/neon.js +1 -1
- package/package.json +14 -9
- package/stdlib/bubbling_support.js +2 -2
- package/stdlib/custom_event.js +18 -1
- package/stdlib/custom_event_support.js +24 -9
- package/stdlib/node_support.js +8 -8
- package/stdlib/widget.js +340 -0
- package/test/neon_stdlib_test.js +4 -4
- package/.npmignore +0 -1
package/.jshintrc
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014 Freshout.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.markdown
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# Neon
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## JavaScript DSL for Classical Inheritance
|
|
4
4
|
|
|
5
5
|
This files provides a DSL for the following design patterns:
|
|
6
6
|
|
|
@@ -13,11 +13,11 @@ Neon packs a DSL for Class creation, that helps in making programs following an
|
|
|
13
13
|
The philosophy is that it should not try to emulate other languages, so it preserves the JavaScript good parts,
|
|
14
14
|
but with a nicer syntax to create classes that ensure interfaces and include reusable functionality as modules.
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
## Why another Class System?
|
|
17
17
|
|
|
18
18
|
As the web applications are getting more complex these times, backend and frontend engineers work has fusioned, and they need to be able to establish a common language. It was created for people coming from OOP languages like Ruby to Javascript.
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
### Usage
|
|
21
21
|
|
|
22
22
|
Interface('Editable')({
|
|
23
23
|
constructor : ['x'],
|
|
@@ -52,7 +52,7 @@ As the web applications are getting more complex these times, backend and fronte
|
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
## License
|
|
56
56
|
|
|
57
57
|
Copyright (c) 2009 Fernando Trasviña
|
|
58
58
|
|
package/bower.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "neon",
|
|
3
|
+
"main": "neon.js",
|
|
4
|
+
"version": "2.0.0",
|
|
5
|
+
"homepage": "https://github.com/azendal/neon",
|
|
6
|
+
"authors": [
|
|
7
|
+
"Fernando Trasviña <fernando@freshout.us>"
|
|
8
|
+
],
|
|
9
|
+
"description": "JavaScript DSL for Classical Inheritance",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"DSL",
|
|
12
|
+
"class",
|
|
13
|
+
"inheritance"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"ignore": [
|
|
17
|
+
"**/.*",
|
|
18
|
+
"node_modules",
|
|
19
|
+
"bower_components",
|
|
20
|
+
"test",
|
|
21
|
+
"tests"
|
|
22
|
+
]
|
|
23
|
+
}
|
package/license.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2009-2017 Fernando Trasvina
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/neon.js
CHANGED
package/package.json
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name"
|
|
3
|
-
"version"
|
|
4
|
-
"description"
|
|
5
|
-
"main"
|
|
6
|
-
"directories"
|
|
7
|
-
"lib"
|
|
2
|
+
"name": "neon",
|
|
3
|
+
"version": "2.0.2",
|
|
4
|
+
"description": "Javascript DSL for Classical Inheritance",
|
|
5
|
+
"main": "./neon",
|
|
6
|
+
"directories": {
|
|
7
|
+
"lib": "./lib"
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
|
-
"type"
|
|
11
|
-
"url"
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/azendal/neon.git"
|
|
12
12
|
},
|
|
13
|
-
"keywords": [
|
|
13
|
+
"keywords": [
|
|
14
|
+
"class",
|
|
15
|
+
"prototype",
|
|
16
|
+
"inheritance",
|
|
17
|
+
"oop"
|
|
18
|
+
]
|
|
14
19
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Module('BubblingSupport')({
|
|
2
2
|
dispatch : function (type, data) {
|
|
3
3
|
data = data || {};
|
|
4
|
-
var event =
|
|
4
|
+
var event = NeCustomEventSupport.prototype.dispatch.call(this, type, data);
|
|
5
5
|
if (event.isPropagationStopped === false) {
|
|
6
6
|
if (this.parent && this.parent.dispatch) {
|
|
7
7
|
data.target = event.target;
|
|
@@ -16,7 +16,7 @@ Module('BubblingSupport')({
|
|
|
16
16
|
dispatch : function (type, data) {
|
|
17
17
|
data = data || {};
|
|
18
18
|
|
|
19
|
-
var event =
|
|
19
|
+
var event = NeCustomEventSupport.prototype.dispatch.call(this, type, data);
|
|
20
20
|
|
|
21
21
|
if (event.isPropagationStopped === false && event.bubbles === true) {
|
|
22
22
|
if (this.parent && this.parent.dispatch) {
|
package/stdlib/custom_event.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated CustomEvent is deprecated and will be removed on February 1st, 2026. Use NeCustomEvent instead.
|
|
3
|
+
*/
|
|
4
|
+
Class('NeCustomEvent')({
|
|
2
5
|
prototype : {
|
|
3
6
|
bubbles : true,
|
|
4
7
|
cancelable : true,
|
|
@@ -34,4 +37,18 @@ Class('CustomEvent')({
|
|
|
34
37
|
this.areImmediateHandlersPrevented = true;
|
|
35
38
|
}
|
|
36
39
|
}
|
|
40
|
+
|
|
37
41
|
});
|
|
42
|
+
|
|
43
|
+
if (typeof window !== 'undefined') {
|
|
44
|
+
window.CustomEvent = new Proxy(NeCustomEvent, {
|
|
45
|
+
construct(target, args) {
|
|
46
|
+
console.warn('DEPRECATION NOTICE: CustomEvent is deprecated and will be removed on February 1st, 2026. Use NeCustomEvent instead.');
|
|
47
|
+
return new target(...args);
|
|
48
|
+
},
|
|
49
|
+
get(target, prop, receiver) {
|
|
50
|
+
console.warn('DEPRECATION NOTICE: CustomEvent is deprecated and will be removed on February 1st, 2026. Use NeCustomEvent instead.');
|
|
51
|
+
return Reflect.get(target, prop, receiver);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
@@ -1,8 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated CustomEventSupport is deprecated and will be removed on February 1st, 2026. Use NeCustomEventSupport instead.
|
|
3
|
+
*/
|
|
4
|
+
if (typeof window !== 'undefined') {
|
|
5
|
+
window.CustomEventSupport = new Proxy(NeCustomEventSupport, {
|
|
6
|
+
construct(target, args) {
|
|
7
|
+
console.warn('DEPRECATION NOTICE: CustomEventSupport is deprecated and will be removed on February 1st, 2026. Use NeCustomEventSupport instead.');
|
|
8
|
+
return new target(...args);
|
|
9
|
+
},
|
|
10
|
+
get(target, prop, receiver) {
|
|
11
|
+
console.warn('DEPRECATION NOTICE: CustomEventSupport is deprecated and will be removed on February 1st, 2026. Use NeCustomEventSupport instead.');
|
|
12
|
+
return Reflect.get(target, prop, receiver);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
Module('NeCustomEventSupport')({
|
|
2
17
|
|
|
3
18
|
eventListeners : null,
|
|
4
19
|
|
|
5
|
-
bind : function(type, eventHandler) {
|
|
20
|
+
bind : function bind(type, eventHandler) {
|
|
6
21
|
var found, i, listeners;
|
|
7
22
|
|
|
8
23
|
if(!this.eventListeners) {
|
|
@@ -30,7 +45,7 @@ Module('CustomEventSupport')({
|
|
|
30
45
|
return this;
|
|
31
46
|
},
|
|
32
47
|
|
|
33
|
-
unbind : function(type, eventHandler) {
|
|
48
|
+
unbind : function unbind(type, eventHandler) {
|
|
34
49
|
var i, found, listeners;
|
|
35
50
|
|
|
36
51
|
found = false;
|
|
@@ -58,7 +73,7 @@ Module('CustomEventSupport')({
|
|
|
58
73
|
return this;
|
|
59
74
|
},
|
|
60
75
|
|
|
61
|
-
dispatch : function(type, data) {
|
|
76
|
+
dispatch : function dispatch(type, data) {
|
|
62
77
|
var event, listeners, instance, i;
|
|
63
78
|
|
|
64
79
|
if (this.eventListeners === null) {
|
|
@@ -73,7 +88,7 @@ Module('CustomEventSupport')({
|
|
|
73
88
|
data.target = this;
|
|
74
89
|
}
|
|
75
90
|
|
|
76
|
-
|
|
91
|
+
event = new NeCustomEvent(type, data);
|
|
77
92
|
listeners = this.eventListeners[type] || [];
|
|
78
93
|
instance = this;
|
|
79
94
|
|
|
@@ -91,7 +106,7 @@ Module('CustomEventSupport')({
|
|
|
91
106
|
|
|
92
107
|
eventListeners : null,
|
|
93
108
|
|
|
94
|
-
bind : function(type, eventHandler) {
|
|
109
|
+
bind : function bind(type, eventHandler) {
|
|
95
110
|
var found, i, listeners;
|
|
96
111
|
|
|
97
112
|
if(!this.eventListeners) {
|
|
@@ -119,7 +134,7 @@ Module('CustomEventSupport')({
|
|
|
119
134
|
return this;
|
|
120
135
|
},
|
|
121
136
|
|
|
122
|
-
unbind : function(type, eventHandler) {
|
|
137
|
+
unbind : function unbind(type, eventHandler) {
|
|
123
138
|
var i, found, listeners;
|
|
124
139
|
|
|
125
140
|
found = false;
|
|
@@ -148,7 +163,7 @@ Module('CustomEventSupport')({
|
|
|
148
163
|
return this;
|
|
149
164
|
},
|
|
150
165
|
|
|
151
|
-
dispatch : function(type, data) {
|
|
166
|
+
dispatch : function dispatch(type, data) {
|
|
152
167
|
var event, listeners, instance, i;
|
|
153
168
|
|
|
154
169
|
if (this.eventListeners === null) {
|
|
@@ -163,7 +178,7 @@ Module('CustomEventSupport')({
|
|
|
163
178
|
data.target = this;
|
|
164
179
|
}
|
|
165
180
|
|
|
166
|
-
event = new
|
|
181
|
+
event = new NeCustomEvent(type, data);
|
|
167
182
|
listeners = this.eventListeners[type] || [];
|
|
168
183
|
instance = this;
|
|
169
184
|
|
package/stdlib/node_support.js
CHANGED
|
@@ -4,7 +4,7 @@ Module('NodeSupport')({
|
|
|
4
4
|
|
|
5
5
|
children : [],
|
|
6
6
|
|
|
7
|
-
appendChild : function(child) {
|
|
7
|
+
appendChild : function appendChild(child) {
|
|
8
8
|
if(child.parent) {
|
|
9
9
|
child.parent.removeChild(child);
|
|
10
10
|
}
|
|
@@ -19,7 +19,7 @@ Module('NodeSupport')({
|
|
|
19
19
|
return child;
|
|
20
20
|
},
|
|
21
21
|
|
|
22
|
-
insertBefore : function (child, beforeChild) {
|
|
22
|
+
insertBefore : function insertBefore(child, beforeChild) {
|
|
23
23
|
var position;
|
|
24
24
|
|
|
25
25
|
if (child.parent) {
|
|
@@ -44,7 +44,7 @@ Module('NodeSupport')({
|
|
|
44
44
|
|
|
45
45
|
},
|
|
46
46
|
|
|
47
|
-
insertChild : function(child, position) {
|
|
47
|
+
insertChild : function insertChild(child, position) {
|
|
48
48
|
console.warn('NodeSupport insertChild method is deprecated, try insertBefore');
|
|
49
49
|
|
|
50
50
|
if (child.parent) {
|
|
@@ -68,7 +68,7 @@ Module('NodeSupport')({
|
|
|
68
68
|
return child;
|
|
69
69
|
},
|
|
70
70
|
|
|
71
|
-
removeChild : function (child) {
|
|
71
|
+
removeChild : function removeChild(child) {
|
|
72
72
|
var position = this.children.indexOf(child);
|
|
73
73
|
|
|
74
74
|
if (position !== -1) {
|
|
@@ -80,12 +80,12 @@ Module('NodeSupport')({
|
|
|
80
80
|
return child;
|
|
81
81
|
},
|
|
82
82
|
|
|
83
|
-
setParent
|
|
83
|
+
setParent : function setParent(parent) {
|
|
84
84
|
this.parent = parent;
|
|
85
85
|
return this;
|
|
86
86
|
},
|
|
87
87
|
|
|
88
|
-
getDescendants : function () {
|
|
88
|
+
getDescendants : function getDescendants() {
|
|
89
89
|
var nodes = [];
|
|
90
90
|
this.children.forEach(function (node) {
|
|
91
91
|
nodes.push(node);
|
|
@@ -96,7 +96,7 @@ Module('NodeSupport')({
|
|
|
96
96
|
return nodes;
|
|
97
97
|
},
|
|
98
98
|
|
|
99
|
-
getPreviousSibling : function () {
|
|
99
|
+
getPreviousSibling : function getPreviousSibling() {
|
|
100
100
|
if (typeof this.parent === 'undefined') {
|
|
101
101
|
return;
|
|
102
102
|
}
|
|
@@ -108,7 +108,7 @@ Module('NodeSupport')({
|
|
|
108
108
|
return this.parent.children[ this.parent.children.indexOf(this) - 1 ];
|
|
109
109
|
},
|
|
110
110
|
|
|
111
|
-
getNextSibling : function () {
|
|
111
|
+
getNextSibling : function getNextSibling() {
|
|
112
112
|
if (typeof this.parent === 'undefined') {
|
|
113
113
|
return;
|
|
114
114
|
}
|
package/stdlib/widget.js
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Base Class from which almost all widgets are based overall the project
|
|
3
|
+
|
|
4
|
+
The main idea behind constructing a new widget toolkit instead of using one of the many high quality widget
|
|
5
|
+
toolkits available is that we considered that currently, no widget system provides all the features that where
|
|
6
|
+
required for this project.
|
|
7
|
+
|
|
8
|
+
Features of the widget system
|
|
9
|
+
* A custom and easy to handle event binding, dispatching and manipulation, with some sort of bubbling support
|
|
10
|
+
* A module system which we can use to include specific behaviour to any widget and reuse the code where needed
|
|
11
|
+
* A tree structure support for the widgets that the event system could bubble, and that also serves as
|
|
12
|
+
* A navigation system.
|
|
13
|
+
* The widgets must be able to be grouped to form more complex widgets
|
|
14
|
+
* Remove the complexity of DOM manipulation and handling
|
|
15
|
+
* A way to wrap widgets at our convenience to reuse widgets available and make them commonly to our needs
|
|
16
|
+
without the need to hack those widgets, that would force us to maintain the new versions of those widgets
|
|
17
|
+
and that is a very complex task when widgets become so complex.
|
|
18
|
+
* A widget system that would allow us to start wrapping some widgets for a fast start and later code our own widgets
|
|
19
|
+
at will.
|
|
20
|
+
* expose a consistent API that allow us to choose the use of widgets by API calls and user interaction at will and with the same
|
|
21
|
+
clearance and capacity
|
|
22
|
+
* an easy way to allow subclasing widgets
|
|
23
|
+
* an easy way to provide new html, class, and css for a specific instance of a widget that would remove us the need
|
|
24
|
+
to create complex inheritance structures that are hard to maintain.
|
|
25
|
+
|
|
26
|
+
Usage Example.
|
|
27
|
+
|
|
28
|
+
The most basic usage of a widget is to simply create an instance and render it at a target element
|
|
29
|
+
in this case body
|
|
30
|
+
var myWidgetInstance = new Widget();
|
|
31
|
+
myWidgetInstance.render(document.body);
|
|
32
|
+
|
|
33
|
+
like this widget does renders does not display anything so lets give it something to display first
|
|
34
|
+
var myWidgetInstance = new Widget();
|
|
35
|
+
myWidgetInstance.element.html('Im a simple widget');
|
|
36
|
+
myWidgetInstance.render(document.body);
|
|
37
|
+
|
|
38
|
+
this reveals that internally every widget has an element property that is initialized by default to a DOM Element instance
|
|
39
|
+
this allows direct DOM manipulation using standard JavaScript methods.
|
|
40
|
+
@class Widget
|
|
41
|
+
@inlcudes NeCustomEventSupport
|
|
42
|
+
@includes NodeSupport
|
|
43
|
+
@dependency Neon
|
|
44
|
+
@dependency NeCustomEventSupport
|
|
45
|
+
@dependency NodeSupport
|
|
46
|
+
**/
|
|
47
|
+
Class('Widget').includes(NeCustomEventSupport, NodeSupport)({
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
The default html for the widget, at the most simple case this is just a div.
|
|
51
|
+
@name HTML
|
|
52
|
+
@attribute_type CONSTANT
|
|
53
|
+
@type String
|
|
54
|
+
*/
|
|
55
|
+
HTML : '<div></div>',
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
the widget container default class for all widgets is widget
|
|
59
|
+
@name ELEMENT_CLASS
|
|
60
|
+
@constant
|
|
61
|
+
@type String
|
|
62
|
+
**/
|
|
63
|
+
ELEMENT_CLASS : 'widget',
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
@property prototype
|
|
67
|
+
@type Object
|
|
68
|
+
**/
|
|
69
|
+
prototype : {
|
|
70
|
+
/**
|
|
71
|
+
Holds the active status of the widget
|
|
72
|
+
By default all widgets are deactivated waiting
|
|
73
|
+
for an action to activate it.
|
|
74
|
+
@property active <public> [Boolean] (false)
|
|
75
|
+
**/
|
|
76
|
+
active : false,
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
Holds the disabled status of the widget
|
|
80
|
+
By default all widgets are enabled and only by
|
|
81
|
+
API could be disabled.
|
|
82
|
+
@property disabled <public> [Boolean] (false)
|
|
83
|
+
**/
|
|
84
|
+
disabled : false,
|
|
85
|
+
|
|
86
|
+
__destroyed : false,
|
|
87
|
+
|
|
88
|
+
init : function init(config) {
|
|
89
|
+
var property;
|
|
90
|
+
|
|
91
|
+
Object.keys(config || {}).forEach(function (propertyName) {
|
|
92
|
+
this[propertyName] = config[propertyName];
|
|
93
|
+
}, this);
|
|
94
|
+
|
|
95
|
+
if (this.element == null) {
|
|
96
|
+
var html = this.constructor.HTML.replace(/\s\s+/g, '');
|
|
97
|
+
var template = document.createElement('template');
|
|
98
|
+
template.innerHTML = html.trim();
|
|
99
|
+
this.element = template.content.firstElementChild;
|
|
100
|
+
if (this.element && this.constructor.ELEMENT_CLASS) {
|
|
101
|
+
this.element.classList.add(this.constructor.ELEMENT_CLASS);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (this.hasOwnProperty('className') === true && this.element) {
|
|
106
|
+
this.element.classList.add(this.className);
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
implementation of the activate method, when you need an override, do it
|
|
112
|
+
over this method instead of doing it on activate
|
|
113
|
+
@property _activate <private> [Function]
|
|
114
|
+
@return undefined [undefined]
|
|
115
|
+
**/
|
|
116
|
+
_activate : function _activate() {
|
|
117
|
+
this.active = true;
|
|
118
|
+
if (this.element) {
|
|
119
|
+
this.element.classList.add('active');
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
Public activation method for widget, you can listen to this event
|
|
125
|
+
to take some other actions, but the most important part of this
|
|
126
|
+
method is that it runs its default action, (its activation)
|
|
127
|
+
this method uses _activate as its implementation to maintain
|
|
128
|
+
the events order intact.
|
|
129
|
+
@property activate <public> [Function]
|
|
130
|
+
@method
|
|
131
|
+
@dispatch beforeActivate
|
|
132
|
+
@dispatch activate
|
|
133
|
+
@return this [Widget]
|
|
134
|
+
**/
|
|
135
|
+
activate : function activate() {
|
|
136
|
+
if (this.__destroyed === true) {
|
|
137
|
+
console.warn('calling on destroyed object');
|
|
138
|
+
}
|
|
139
|
+
this.dispatch('beforeActivate');
|
|
140
|
+
this._activate();
|
|
141
|
+
this.dispatch('activate');
|
|
142
|
+
return this;
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
deactivation implementation
|
|
147
|
+
this is the oposite of activation method and as such it must be
|
|
148
|
+
treated as important as that.
|
|
149
|
+
@property _deactivate <private> [Function]
|
|
150
|
+
@method
|
|
151
|
+
@return undefined [undefined]
|
|
152
|
+
**/
|
|
153
|
+
_deactivate : function _deactivate() {
|
|
154
|
+
this.active = false;
|
|
155
|
+
if (this.element) {
|
|
156
|
+
this.element.classList.remove('active');
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
Public deactivation method for widget, you can listen to this event
|
|
162
|
+
to take some other actions, but the most important part of this
|
|
163
|
+
method is that it runs its default action, (its activation)
|
|
164
|
+
this method uses _deactivate as its implementation to maintain
|
|
165
|
+
the events order intact.
|
|
166
|
+
@property activate <public> [Function]
|
|
167
|
+
@method
|
|
168
|
+
@dispatch beforeDeactivatee
|
|
169
|
+
@dispatch deactivate
|
|
170
|
+
@return this [Widget]
|
|
171
|
+
**/
|
|
172
|
+
deactivate : function deactivate() {
|
|
173
|
+
if (this.__destroyed === true) {
|
|
174
|
+
console.warn('calling on destroyed object');
|
|
175
|
+
}
|
|
176
|
+
this.dispatch('beforeDeactivate');
|
|
177
|
+
this._deactivate();
|
|
178
|
+
this.dispatch('deactivate');
|
|
179
|
+
return this;
|
|
180
|
+
},
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
Enable implementation method
|
|
184
|
+
if you need to provide a different procedure for enable
|
|
185
|
+
you must override this method and call "super"
|
|
186
|
+
@property _enable <private> [Function]
|
|
187
|
+
@method
|
|
188
|
+
@return undefined [undefined]
|
|
189
|
+
**/
|
|
190
|
+
_enable : function _enable() {
|
|
191
|
+
this.disabled = false;
|
|
192
|
+
if (this.element) {
|
|
193
|
+
this.element.classList.remove('disable');
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
Public enable method, this method should not be
|
|
199
|
+
overriden.
|
|
200
|
+
@property enable <public> [Function]
|
|
201
|
+
@method
|
|
202
|
+
@return this [Widget]
|
|
203
|
+
**/
|
|
204
|
+
enable : function enable() {
|
|
205
|
+
if (this.__destroyed === true) {
|
|
206
|
+
console.warn('calling on destroyed object');
|
|
207
|
+
}
|
|
208
|
+
this.dispatch('beforeEnable');
|
|
209
|
+
this._enable();
|
|
210
|
+
this.dispatch('enable');
|
|
211
|
+
|
|
212
|
+
return this;
|
|
213
|
+
},
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
Disable implementation
|
|
217
|
+
@property _disable <private> [Function]
|
|
218
|
+
@return undefined [undefined]
|
|
219
|
+
**/
|
|
220
|
+
_disable : function _disable() {
|
|
221
|
+
this.disabled = true;
|
|
222
|
+
if (this.element) {
|
|
223
|
+
this.element.classList.add('disable');
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
Disables the widget, the idea behind disabling a widget
|
|
229
|
+
comes from DOM form elements. so following this idea
|
|
230
|
+
all widgets can be disabled and queried for its disabled
|
|
231
|
+
state via the disabled property.
|
|
232
|
+
Same as DOM form elements there is feedback and that is why
|
|
233
|
+
the default implementation sets the "disable" class
|
|
234
|
+
on the element so proper visual feedback can be provided
|
|
235
|
+
to the user.
|
|
236
|
+
@property disable <public> [Function]
|
|
237
|
+
@method
|
|
238
|
+
@return this [Widget]
|
|
239
|
+
**/
|
|
240
|
+
disable : function disable() {
|
|
241
|
+
if (this.__destroyed === true) {
|
|
242
|
+
console.warn('calling on destroyed object');
|
|
243
|
+
}
|
|
244
|
+
this.dispatch('beforeDisable');
|
|
245
|
+
this._disable();
|
|
246
|
+
this.dispatch('disable');
|
|
247
|
+
|
|
248
|
+
return this;
|
|
249
|
+
},
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
Destroy implementation. Its main responsabilities are cleaning
|
|
253
|
+
all references to other objects so garbage collector can collect
|
|
254
|
+
the memory used by this and the other objects
|
|
255
|
+
@property _destroy <private> [Function]
|
|
256
|
+
@method
|
|
257
|
+
@return undefined [undefined]
|
|
258
|
+
**/
|
|
259
|
+
_destroy : function _destroy() {
|
|
260
|
+
var childrenLength;
|
|
261
|
+
|
|
262
|
+
if (this.element && this.element.parentNode) {
|
|
263
|
+
this.element.parentNode.removeChild(this.element);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (this.children !== null){
|
|
267
|
+
childrenLength = this.children.length;
|
|
268
|
+
while(childrenLength > 0){
|
|
269
|
+
this.children[0].destroy();
|
|
270
|
+
if (this.children.length === childrenLength) {
|
|
271
|
+
this.children.shift();
|
|
272
|
+
}
|
|
273
|
+
childrenLength--;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (this.parent) {
|
|
278
|
+
this.parent.removeChild(this);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
this.children = null;
|
|
282
|
+
this.element = null;
|
|
283
|
+
},
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
Destroy public method, this one should not be replaced
|
|
287
|
+
@property destroy <public> [Function]
|
|
288
|
+
@method
|
|
289
|
+
@return null [null]
|
|
290
|
+
**/
|
|
291
|
+
destroy : function destroy() {
|
|
292
|
+
if (this.__destroyed === true) {
|
|
293
|
+
console.warn('calling on destroyed object');
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
this.dispatch('beforeDestroy');
|
|
297
|
+
this._destroy();
|
|
298
|
+
this.dispatch('destroy');
|
|
299
|
+
|
|
300
|
+
this.eventListeners = null;
|
|
301
|
+
this.__destroyed = true;
|
|
302
|
+
|
|
303
|
+
return null;
|
|
304
|
+
},
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
The render method is the mechanism by which you pass a widget from
|
|
308
|
+
living only on memory to get into the DOM and with this into the
|
|
309
|
+
application flow. The recomendation is that render is the last method
|
|
310
|
+
of the setup of a widget, including appending its children. this is
|
|
311
|
+
because once a widget gets renderer, further operations cause browser
|
|
312
|
+
reflows, and DOM operations are slower than memory operations.
|
|
313
|
+
This method should not be replaced by its children.
|
|
314
|
+
@property render <public> [Function]
|
|
315
|
+
@method
|
|
316
|
+
@argument element <required> [HTMLElement] (undefined) This is the element
|
|
317
|
+
into which the widget will be appended.
|
|
318
|
+
@argument beforeElement <optional> [HTMLElement] (undefined) this is the element
|
|
319
|
+
that will be used as a reference to insert the widgets element. this argument
|
|
320
|
+
must be a child of the "element" argument.
|
|
321
|
+
@return this [Widget]
|
|
322
|
+
**/
|
|
323
|
+
render : function render(element, beforeElement) {
|
|
324
|
+
if (this.__destroyed === true) {
|
|
325
|
+
console.warn('calling on destroyed object');
|
|
326
|
+
}
|
|
327
|
+
this.dispatch('beforeRender', {
|
|
328
|
+
element : element,
|
|
329
|
+
beforeElement : beforeElement
|
|
330
|
+
});
|
|
331
|
+
if (beforeElement && beforeElement.parentNode === element) {
|
|
332
|
+
element.insertBefore(this.element, beforeElement);
|
|
333
|
+
} else {
|
|
334
|
+
element.appendChild(this.element);
|
|
335
|
+
}
|
|
336
|
+
this.dispatch('render');
|
|
337
|
+
return this;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
});
|
package/test/neon_stdlib_test.js
CHANGED
|
@@ -5,8 +5,8 @@ if(typeof require !== 'undefined') {
|
|
|
5
5
|
require('neon/stdlib');
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
console.log("
|
|
9
|
-
console.log("
|
|
8
|
+
console.log("NeCustomEvent ", typeof NeCustomEvent !== 'undefined');
|
|
9
|
+
console.log("NeCustomEventSupport ", typeof NeCustomEventSupport !== 'undefined');
|
|
10
10
|
console.log("NodeSupport ", typeof NodeSupport !== 'undefined');
|
|
11
11
|
console.log("BubblingSupport ", typeof BubblingSupport !== 'undefined');
|
|
12
12
|
|
|
@@ -33,7 +33,7 @@ right.setParent(root);
|
|
|
33
33
|
console.log(root.children.indexOf(left));
|
|
34
34
|
console.log(left == right.parent.left);
|
|
35
35
|
|
|
36
|
-
Class('X').includes(
|
|
36
|
+
Class('X').includes(NeCustomEventSupport)({
|
|
37
37
|
prototype : {
|
|
38
38
|
init : function() {
|
|
39
39
|
|
|
@@ -54,7 +54,7 @@ sender.dispatch('alert', { message : 'TEST' });
|
|
|
54
54
|
|
|
55
55
|
console.log('--- bubbling support');
|
|
56
56
|
|
|
57
|
-
Class('BubblingTreeNode').includes(NodeSupport,
|
|
57
|
+
Class('BubblingTreeNode').includes(NodeSupport, NeCustomEventSupport, BubblingSupport)({
|
|
58
58
|
prototype : {
|
|
59
59
|
init : function(name) {
|
|
60
60
|
this.name = name;
|
package/.npmignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
node_modules
|