Browse code
Remove debugging code, Add metabilities, Pass event target to command
fiddlerwoaroof authored on 11/07/2016 21:41:13
Showing 2 changed files
Showing 2 changed files
... | ... |
@@ -1,3 +1,8 @@ |
1 |
+/** |
|
2 |
+ * This file is part of JIM <https://github.com/fiddlerwoaroof/jim/> (c) 2016 Edward Langley |
|
3 |
+ * |
|
4 |
+ * See the COPYING document in the root of the source distribution for licensing information. |
|
5 |
+ */ |
|
1 | 6 |
function PresentationTypeError(msg, expectedType, actualVal) { |
2 | 7 |
if (this instanceof TypeError) { |
3 | 8 |
return new TypeError(msg, expectedType, actualVal); |
... | ... |
@@ -113,6 +118,7 @@ Command = (function() { |
113 | 118 |
throw new PresentationTypeError('wrong type', this.types[idx], args[idx]); |
114 | 119 |
} |
115 | 120 |
} |
121 |
+ args.push(this.cursor.activator); |
|
116 | 122 |
this.execute.apply(this, args); |
117 | 123 |
}, |
118 | 124 |
|
... | ... |
@@ -122,6 +128,7 @@ Command = (function() { |
122 | 128 |
} |
123 | 129 |
|
124 | 130 |
this.cursor = TypeCursor(this.types); |
131 |
+ this.cursor.activator = theEvent.target; |
|
125 | 132 |
this.cursor.activate().then(this.run.bind(this)); |
126 | 133 |
|
127 | 134 |
return true; |
... | ... |
@@ -1,3 +1,8 @@ |
1 |
+/** |
|
2 |
+ * This file is part of JIM <https://github.com/fiddlerwoaroof/jim/> (c) 2016 Edward Langley |
|
3 |
+ * |
|
4 |
+ * See the COPYING document in the root of the source distribution for licensing information. |
|
5 |
+ */ |
|
1 | 6 |
PresentationType = (function () { |
2 | 7 |
var presentationTypes = {}; |
3 | 8 |
|
... | ... |
@@ -27,8 +32,8 @@ PresentationType = (function () { |
27 | 32 |
|
28 | 33 |
isOfType(name) { |
29 | 34 |
var type = presentationTypes[name]; |
30 |
- console.log(name); |
|
31 |
- console.log(type); |
|
35 |
+ //console.log(name); |
|
36 |
+ //console.log(type); |
|
32 | 37 |
return type.isPrototypeOf(this); |
33 | 38 |
}, |
34 | 39 |
|
... | ... |
@@ -78,39 +83,44 @@ PresentationType = (function () { |
78 | 83 |
}, |
79 | 84 |
|
80 | 85 |
bindTags() { |
81 |
- var els = this.selectAllTags().filter(function (theEl) { return theEl.ptObject === undefined; }); |
|
86 |
+ var els = this.selectAllTags().filter(function (theEl) { |
|
87 |
+ return theEl.ptObject === undefined; |
|
88 |
+ }); |
|
82 | 89 |
|
83 |
- els.forEach(function (theEl) { |
|
84 |
- var content = theEl.textContent.trim(); |
|
85 |
- var value = theEl.value; |
|
90 |
+ els.forEach(this.bindEl, this); |
|
86 | 91 |
|
92 |
+ return this; |
|
93 |
+ }, |
|
87 | 94 |
|
88 |
- var bindTypes = theEl.dataset.bind; |
|
89 |
- if (bindTypes !== undefined) { |
|
90 |
- bindTypes = bindTypes.split(','); |
|
91 |
- } else { |
|
92 |
- bindTypes = ['click']; |
|
93 |
- } |
|
95 |
+ bindEl(theEl) { |
|
96 |
+ var content = theEl.textContent.trim(); |
|
97 |
+ var value = theEl.value; |
|
94 | 98 |
|
95 |
- console.log('bt',bindTypes); |
|
99 |
+ var bindTypes = theEl.dataset.bind; |
|
100 |
+ if (bindTypes !== undefined) { |
|
101 |
+ bindTypes = bindTypes.split(','); |
|
102 |
+ } else { |
|
103 |
+ bindTypes = ['click']; |
|
104 |
+ } |
|
96 | 105 |
|
97 |
- if (! theEl.hasAttribute('value') ) { |
|
98 |
- var tmpVal = theEl.dataset.value; |
|
99 |
- value = tmpVal === undefined ? content : theEl.dataset.value; |
|
100 |
- } |
|
106 |
+ //console.log('bt',bindTypes); |
|
101 | 107 |
|
102 |
- this.wrapTag(theEl, value, bindTypes, content); |
|
103 |
- }, this); |
|
108 |
+ if (! theEl.hasAttribute('value') ) { |
|
109 |
+ var tmpVal = theEl.dataset.value; |
|
110 |
+ value = tmpVal === undefined ? content : theEl.dataset.value; |
|
111 |
+ } |
|
104 | 112 |
|
105 |
- return this; |
|
113 |
+ return this.wrapTag(theEl, value, bindTypes, content); |
|
106 | 114 |
}, |
107 | 115 |
|
108 | 116 |
wrapTag(tag, value, bindTypes, content) { |
109 |
- var result = Object.assign(Object.create(this), { |
|
110 |
- tag: tag, |
|
111 |
- value: value, |
|
112 |
- display: content, |
|
113 |
- }); |
|
117 |
+ var result = Object.assign( |
|
118 |
+ Object.create(this), { |
|
119 |
+ tag: tag, |
|
120 |
+ value: value, |
|
121 |
+ display: content, |
|
122 |
+ } |
|
123 |
+ ); |
|
114 | 124 |
tag.ptObject = result; |
115 | 125 |
|
116 | 126 |
this.classes.forEach(function (cls) { |
... | ... |
@@ -118,7 +128,7 @@ PresentationType = (function () { |
118 | 128 |
}); |
119 | 129 |
|
120 | 130 |
bindTypes.forEach(function (event) { |
121 |
- console.log(event); |
|
131 |
+ //console.log(event); |
|
122 | 132 |
tag.addEventListener(event, result, false); |
123 | 133 |
}); |
124 | 134 |
|
... | ... |
@@ -183,7 +193,7 @@ PresentationType = (function () { |
183 | 193 |
}, |
184 | 194 |
|
185 | 195 |
handleEvent(theEvent) { |
186 |
- console.log('handling: ',theEvent); |
|
196 |
+ //console.log('handling: ',theEvent); |
|
187 | 197 |
var handler = this[theEvent.type]; |
188 | 198 |
var result = true; |
189 | 199 |
if (handler !== undefined) { |
... | ... |
@@ -219,6 +229,7 @@ PresentationType = (function () { |
219 | 229 |
}, |
220 | 230 |
|
221 | 231 |
activateAll() { |
232 |
+ this.bindTags(); |
|
222 | 233 |
var els = this.selectAllTags(); |
223 | 234 |
|
224 | 235 |
els.forEach(function (el) { |
... | ... |
@@ -231,5 +242,18 @@ PresentationType = (function () { |
231 | 242 |
|
232 | 243 |
}; |
233 | 244 |
|
245 |
+ var typeType = PresentationType('type'); |
|
246 |
+ typeType.generateTags = function (tagName) { |
|
247 |
+ if (tagName === undefined) { |
|
248 |
+ tagName = 'span'; |
|
249 |
+ } |
|
250 |
+ |
|
251 |
+ return Object.keys(presentationTypes).map( |
|
252 |
+ function (type) { |
|
253 |
+ var tag = document.createElement(tagName); |
|
254 |
+ return this.wrapTag(tag, type, ['click'], type); |
|
255 |
+ }, this |
|
256 |
+ ); |
|
257 |
+ }; |
|
234 | 258 |
return PresentationType; |
235 | 259 |
})(); |