Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding some docs to Keyboard, making some methods _private

  • Loading branch information...
commit 1f03be39cca0be04e73ab784fd03b9650f5360e5 1 parent cb26725
@anutron anutron authored
View
40 Docs/Interface/Keyboard.md
@@ -143,6 +143,11 @@ Attempts to give control to the previously active keyboard. Will not do anything
myKeyboard.relinquish()
+### Returns
+
+ * (*object*) This instance of [Keyboard][]
+
+
Keyboard Method: isActive {#Keyboard:isActive}
------------------------------------
@@ -152,6 +157,10 @@ Returns *true* if the instance is active.
myKeyboard.isActive()
+### Returns
+
+ * (*boolean*) *true* if the instance is active.
+
Keyboard Method: manage {#Keyboard:manage}
------------------------------------
@@ -162,10 +171,41 @@ The keyboard will become the parent of the passed in keyboard. By default the ma
myKeyboard.manage(childKeyboard)
+
+### Arguments
+
+ 1. childKeyboard - (*object*) an instance of Keyboard that this instance should manage.
+
+### Returns
+
+ * (*object*) This instance of [Keyboard][]
+
### Note
When myKeyboard is active childKeyboard will receive the event first then as long as childKeyboard did not call Keyboard.stop(event) then the event will bubble up to myKeyboard. If myKeyboard manages more than one Keyboard instance, which ever one is active will receive the events as they bubble.
+
+Keyboard Method: drop {#Keyboard:drop}
+------------------------------------
+
+Drops an instance of a keyboard from being managed.
+
+### Syntax
+
+ myKeyboard.drop(childKeyboard)
+
+### Arguments
+
+1. childKeyboard - (*object*) an instance of Keyboard managed by this instance.
+
+### Returns
+
+ * (*object*) This instance of [Keyboard][]
+
+### Note
+
+The result
+
Static Method: Keyboard.stop {#Keyboard:stop}
------------------------------------
View
16 Source/Interface/Keyboard.Extras.js
@@ -33,13 +33,13 @@ Keyboard.implement({
}
*/
addShortcut: function(name, shortcut){
- this.shortcuts = this.shortcuts || [];
- this.shortcutIndex = this.shortcutIndex || {};
+ this._shortcuts = this._shortcuts || [];
+ this._shortcutIndex = this._shortcutIndex || {};
shortcut.getKeyboard = Function.from(this);
shortcut.name = name;
- this.shortcutIndex[name] = shortcut;
- this.shortcuts.push(shortcut);
+ this._shortcutIndex[name] = shortcut;
+ this._shortcuts.push(shortcut);
if (shortcut.keys) this.addEvent(shortcut.keys, shortcut.handler);
return this;
},
@@ -53,8 +53,8 @@ Keyboard.implement({
var shortcut = this.getShortcut(name);
if (shortcut && shortcut.keys){
this.removeEvent(shortcut.keys, shortcut.handler);
- delete this.shortcutIndex[name];
- this.shortcuts.erase(shortcut);
+ delete this._shortcutIndex[name];
+ this._shortcuts.erase(shortcut);
}
return this;
},
@@ -65,11 +65,11 @@ Keyboard.implement({
},
getShortcuts: function(){
- return this.shortcuts || [];
+ return this._shortcuts || [];
},
getShortcut: function(name){
- return (this.shortcutIndex || {})[name];
+ return (this._shortcutIndex || {})[name];
}
});
View
109 Source/Interface/Keyboard.js
@@ -45,33 +45,11 @@ provides: [Keyboard]
initialize: function(options){
if (options && options.manager){
- this.manager = options.manager;
+ this._manager = options.manager;
delete options.manager;
}
this.setOptions(options);
- this.setup();
- },
-
- setup: function(){
- this.addEvents(this.options.events);
- //if this is the root manager, nothing manages it
- if (Keyboard.manager && !this.manager) Keyboard.manager.manage(this);
- if (this.options.active) this.activate();
- else this.relinquish();
- },
-
- handle: function(event, type){
- //Keyboard.stop(event) prevents key propagation
- if (event.preventKeyboardPropagation) return;
-
- var bubbles = !!this.manager;
- if (bubbles && this.activeKB){
- this.activeKB.handle(event, type);
- if (event.preventKeyboardPropagation) return;
- }
- this.fireEvent(type, event);
-
- if (!bubbles && this.activeKB) this.activeKB.handle(event, type);
+ this._setup();
},
addEvent: function(type, fn, internal){
@@ -90,71 +68,100 @@ provides: [Keyboard]
if (instance){
if (instance.isActive()) return this;
//if we're stealing focus, store the last keyboard to have it so the relinquish command works
- if (this.activeKB && instance != this.activeKB){
- this.previous = this.activeKB;
+ if (this._activeKB && instance != this._activeKB){
+ this.previous = this._activeKB;
this.previous.fireEvent('deactivate');
}
//if we're enabling a child, assign it so that events are now passed to it
- this.activeKB = instance.fireEvent('activate');
+ this._activeKB = instance.fireEvent('activate');
Keyboard.manager.fireEvent('changed');
- } else if (this.manager){
+ } else if (this._manager){
//else we're enabling ourselves, we must ask our parent to do it for us
- this.manager.activate(this);
+ this._manager.activate(this);
}
return this;
},
isActive: function(){
- return this.manager ? (this.manager.activeKB == this) : (Keyboard.manager == this);
+ return this._manager ? (this._manager._activeKB == this) : (Keyboard.manager == this);
},
deactivate: function(instance){
if (instance){
- if (instance === this.activeKB){
- this.activeKB = null;
+ if (instance === this._activeKB){
+ this._activeKB = null;
instance.fireEvent('deactivate');
Keyboard.manager.fireEvent('changed');
}
- } else if (this.manager){
- this.manager.deactivate(this);
+ } else if (this._manager){
+ this._manager.deactivate(this);
}
return this;
},
relinquish: function(){
- if (this.isActive() && this.manager && this.manager.previous) this.manager.activate(this.manager.previous);
+ if (this.isActive() && this._manager && this._manager.previous) this._manager.activate(this._manager.previous);
else this.deactivate();
+ return this;
},
//management logic
manage: function(instance){
- if (instance.manager) instance.manager.drop(instance);
- this.instances.push(instance);
- instance.manager = this;
- if (!this.activeKB) this.activate(instance);
- },
-
- _disable: function(instance){
- if (this.activeKB == instance) this.activeKB = null;
+ if (instance._manager) instance._manager.drop(instance);
+ this._instances.push(instance);
+ instance._manager = this;
+ if (!this._activeKB) this.activate(instance);
+ return this;
},
drop: function(instance){
instance.relinquish();
- this.instances.erase(instance);
- if (this.activeKB == instance){
- if (this.previous && this.instances.contains(this.previous)) this.activate(this.previous);
- else this.activeKB = this.instances[0];
+ this._instances.erase(instance);
+ if (this._activeKB == instance){
+ if (this.previous && this._instances.contains(this.previous)) this.activate(this.previous);
+ else this._activeKB = this._instances[0];
}
+ return this;
},
- instances: [],
-
trace: function(){
Keyboard.trace(this);
},
each: function(fn){
Keyboard.each(this, fn);
+ },
+
+ /*
+ PRIVATE METHODS
+ */
+
+ _instances: [],
+
+ _disable: function(instance){
+ if (this._activeKB == instance) this._activeKB = null;
+ },
+
+ _setup: function(){
+ this.addEvents(this.options.events);
+ //if this is the root manager, nothing manages it
+ if (Keyboard.manager && !this._manager) Keyboard.manager.manage(this);
+ if (this.options.active) this.activate();
+ else this.relinquish();
+ },
+
+ _handle: function(event, type){
+ //Keyboard.stop(event) prevents key propagation
+ if (event.preventKeyboardPropagation) return;
+
+ var bubbles = !!this._manager;
+ if (bubbles && this._activeKB){
+ this._activeKB._handle(event, type);
+ if (event.preventKeyboardPropagation) return;
+ }
+ this.fireEvent(type, event);
+
+ if (!bubbles && this._activeKB) this._activeKB._handle(event, type);
}
});
@@ -196,7 +203,7 @@ provides: [Keyboard]
var current = keyboard || Keyboard.manager;
while (current){
fn.run(current);
- current = current.activeKB;
+ current = current._activeKB;
}
};
@@ -224,7 +231,7 @@ provides: [Keyboard]
});
if (!regex.test(event.key)) keys.push(event.key);
- Keyboard.manager.handle(event, event.type + ':keys(' + keys.join('+') + ')');
+ Keyboard.manager._handle(event, event.type + ':keys(' + keys.join('+') + ')');
};
document.addEvents({
Please sign in to comment.
Something went wrong with that request. Please try again.