now widgets inherit correctly (still clunky) and reuse methods...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2015-09-20 21:54:28 +03:00
parent 8afe50cd51
commit 7eaa2374ad
5 changed files with 161 additions and 91 deletions

View File

@ -312,16 +312,7 @@ var BrowserPrototype = {
//
// XXX triggering events from here and from jQuery/dom has a
// different effect...
trigger: widget.triggerEventWithSource,
// proxy event api...
on: widget.proxyToDom('on'),
one: widget.proxyToDom('one'),
off: widget.proxyToDom('off'),
bind: widget.proxyToDom('bind'),
unbind: widget.proxyToDom('unbind'),
deligate: widget.proxyToDom('deligate'),
undeligate: widget.proxyToDom('undeligate'),
//trigger: widget.triggerEventWithSource,
// specific events...
focus: widget.proxyToDom('focus'),
@ -1499,15 +1490,11 @@ var BrowserPrototype = {
// XXX handle copy...
__init__: function(parent, options){
var that = this
options = options || {}
// merge options...
var opts = Object.create(this.options)
Object.keys(options).forEach(function(n){ opts[n] = options[n] })
options = this.options = opts
object.superMethod(Browser, '__init__').call(this, parent, options)
// build the dom...
var dom = this.dom = this.constructor.make(options)
var dom = this.dom
options = this.options
// basic permanent interactions...
dom.find('.path')
@ -1553,13 +1540,6 @@ var BrowserPrototype = {
})
*/
// add keyboard handler...
dom.keydown(
keyboard.makeKeyboardHandler(
this.keyboard,
options.logKeys,
this))
// attach to parent...
if(parent != null){
parent.append(dom)
@ -1602,6 +1582,10 @@ object.makeConstructor('Browser',
BrowserPrototype)
// inherit from widget...
Browser.prototype.__proto__ = widget.Widget.prototype
/*********************************************************************/

View File

@ -59,19 +59,6 @@ var DrawerPrototype = {
},
},
// XXX triggering events from here and from jQuery/dom has a
// different effect...
trigger: widget.triggerEventWithSource,
// proxy event api...
on: widget.proxyToDom('on'),
one: widget.proxyToDom('one'),
off: widget.proxyToDom('off'),
bind: widget.proxyToDom('bind'),
unbind: widget.proxyToDom('unbind'),
deligate: widget.proxyToDom('deligate'),
undeligate: widget.proxyToDom('undeligate'),
// custom events...
close: function(handler){
// trigger the event...
@ -99,32 +86,22 @@ var DrawerPrototype = {
__init__: function(parent, client, options){
var that = this
parent = this.parent = $(parent || 'body')
options = options || {}
this.client = client
object.superMethod(Drawer, '__init__').call(this, parent, client, options)
var client_dom = client.dom || client
var dom = this.dom
options = this.options
// merge options...
var opts = Object.create(this.options)
Object.keys(options).forEach(function(n){ opts[n] = options[n] })
options = this.options = opts
var dom = this.dom = this.constructor.make(client_dom, options)
.click(function(){
that.close()
})
parent
this.parent
.addClass('blur')
.append(dom)
// add keyboard handler...
dom.keydown(
keyboard.makeKeyboardHandler(
this.keyboard,
options.logKeys,
this))
dom
.click(function(){
that.close()
})
.css({opacity: 0})
.animate({
scrollTop: Math.min(
@ -169,6 +146,9 @@ object.makeConstructor('Drawer',
DrawerClassPrototype,
DrawerPrototype)
// inherit from widget...
Drawer.prototype.__proto__ = widget.Container.prototype
/**********************************************************************

View File

@ -55,19 +55,6 @@ var OverlayPrototype = {
},
},
// XXX triggering events from here and from jQuery/dom has a
// different effect...
trigger: widget.triggerEventWithSource,
// proxy event api...
on: widget.proxyToDom('on'),
one: widget.proxyToDom('one'),
off: widget.proxyToDom('off'),
bind: widget.proxyToDom('bind'),
unbind: widget.proxyToDom('unbind'),
deligate: widget.proxyToDom('deligate'),
undeligate: widget.proxyToDom('undeligate'),
// custom events...
close: function(handler){
// trigger the event...
@ -86,31 +73,17 @@ var OverlayPrototype = {
__init__: function(parent, client, options){
var that = this
parent = this.parent = $(parent || 'body')
options = options || {}
this.client = client
object.superMethod(Overlay, '__init__').call(this, parent, client, options)
// merge options...
var opts = Object.create(this.options)
Object.keys(options).forEach(function(n){ opts[n] = options[n] })
options = this.options = opts
var dom = this.dom = this.constructor.make(client.dom || client, options)
this.dom
.click(function(){
that.close()
})
parent
this.parent
.addClass('blur')
.append(dom)
// add keyboard handler...
dom.keydown(
keyboard.makeKeyboardHandler(
this.keyboard,
options.logKeys,
this))
.append(this.dom)
// focus the client...
if(client.focus){
@ -122,6 +95,7 @@ var OverlayPrototype = {
}
var Overlay =
module.Overlay =
object.makeConstructor('Overlay',
@ -129,6 +103,10 @@ object.makeConstructor('Overlay',
OverlayPrototype)
// inherit from widget...
Overlay.prototype.__proto__ = widget.Container.prototype
/**********************************************************************
* vim:set ts=4 sw=4 : */

View File

@ -9,6 +9,10 @@ console.log('>>> widget')
//var DEBUG = DEBUG != null ? DEBUG : true
var keyboard = require('../keyboard')
var object = require('../../object')
/*********************************************************************/
// helpers...
@ -47,6 +51,130 @@ function(){
/*********************************************************************/
var WidgetClassPrototype = {
make: function(client, options){
console.error('Widget must define a .make method.')
},
}
var WidgetPrototype = {
dom: null,
client: null,
options: {
nonPropagatedEvents: [
'click',
'keydown',
],
},
keyboard: null,
// XXX triggering events from here and from jQuery/dom has a
// different effect...
trigger: triggerEventWithSource,
// proxy event api...
on: proxyToDom('on'),
one: proxyToDom('one'),
off: proxyToDom('off'),
bind: proxyToDom('bind'),
unbind: proxyToDom('unbind'),
deligate: proxyToDom('deligate'),
undeligate: proxyToDom('undeligate'),
// XXX this will not:
// - attach dom to parent...
// - handle focus...
// XXX same as ContainerPrototype.__init__ but skips client...
__init__: function(parent, options){
var that = this
parent = this.parent = $(parent || 'body')
options = options || {}
// merge options...
var opts = Object.create(this.options)
Object.keys(options).forEach(function(n){ opts[n] = options[n] })
options = this.options = opts
// build the dom...
if(this.constructor.make){
var dom = this.dom = this.constructor.make(options)
}
// add keyboard handler...
if(this.keyboard){
dom.keydown(
keyboard.makeKeyboardHandler(
this.keyboard,
options.logKeys,
this))
}
return this
},
}
var Widget =
module.Widget =
object.makeConstructor('Widget',
WidgetClassPrototype,
WidgetPrototype)
/*********************************************************************/
var ContainerClassPrototype = {
}
var ContainerPrototype = {
// XXX this is the same as WidgetPrototype.__init__ but also handles
// the client...
__init__: function(parent, client, options){
var that = this
parent = this.parent = $(parent || 'body')
options = options || {}
this.client = client
// merge options...
var opts = Object.create(this.options)
Object.keys(options).forEach(function(n){ opts[n] = options[n] })
options = this.options = opts
// build the dom...
if(this.constructor.make){
var dom = this.dom = this.constructor.make(client.dom || client, options)
}
// add keyboard handler...
if(this.keyboard){
dom.keydown(
keyboard.makeKeyboardHandler(
this.keyboard,
options.logKeys,
this))
}
return this
},
}
var Container =
module.Container =
object.makeConstructor('Container',
ContainerClassPrototype,
ContainerPrototype)
Container.prototype.__proto__ = Widget.prototype

View File

@ -65,10 +65,10 @@ function makeConstructor(name, a, b){
// super equivalent...
var parent =
module.parent =
function parent(obj){
return obj.__proto__.__proto__
var superMethod =
module.superMethod =
function superMethod(cls, meth){
return cls.prototype.__proto__[meth]
}