mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-12-17 08:41:40 +00:00
now widgets inherit correctly (still clunky) and reuse methods...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
8afe50cd51
commit
7eaa2374ad
@ -312,16 +312,7 @@ var BrowserPrototype = {
|
|||||||
//
|
//
|
||||||
// XXX triggering events from here and from jQuery/dom has a
|
// XXX triggering events from here and from jQuery/dom has a
|
||||||
// different effect...
|
// different effect...
|
||||||
trigger: widget.triggerEventWithSource,
|
//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'),
|
|
||||||
|
|
||||||
// specific events...
|
// specific events...
|
||||||
focus: widget.proxyToDom('focus'),
|
focus: widget.proxyToDom('focus'),
|
||||||
@ -1499,15 +1490,11 @@ var BrowserPrototype = {
|
|||||||
// XXX handle copy...
|
// XXX handle copy...
|
||||||
__init__: function(parent, options){
|
__init__: function(parent, options){
|
||||||
var that = this
|
var that = this
|
||||||
options = options || {}
|
|
||||||
|
|
||||||
// merge options...
|
object.superMethod(Browser, '__init__').call(this, parent, options)
|
||||||
var opts = Object.create(this.options)
|
|
||||||
Object.keys(options).forEach(function(n){ opts[n] = options[n] })
|
|
||||||
options = this.options = opts
|
|
||||||
|
|
||||||
// build the dom...
|
var dom = this.dom
|
||||||
var dom = this.dom = this.constructor.make(options)
|
options = this.options
|
||||||
|
|
||||||
// basic permanent interactions...
|
// basic permanent interactions...
|
||||||
dom.find('.path')
|
dom.find('.path')
|
||||||
@ -1553,13 +1540,6 @@ var BrowserPrototype = {
|
|||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// add keyboard handler...
|
|
||||||
dom.keydown(
|
|
||||||
keyboard.makeKeyboardHandler(
|
|
||||||
this.keyboard,
|
|
||||||
options.logKeys,
|
|
||||||
this))
|
|
||||||
|
|
||||||
// attach to parent...
|
// attach to parent...
|
||||||
if(parent != null){
|
if(parent != null){
|
||||||
parent.append(dom)
|
parent.append(dom)
|
||||||
@ -1602,6 +1582,10 @@ object.makeConstructor('Browser',
|
|||||||
BrowserPrototype)
|
BrowserPrototype)
|
||||||
|
|
||||||
|
|
||||||
|
// inherit from widget...
|
||||||
|
Browser.prototype.__proto__ = widget.Widget.prototype
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
|
|
||||||
|
|||||||
@ -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...
|
// custom events...
|
||||||
close: function(handler){
|
close: function(handler){
|
||||||
// trigger the event...
|
// trigger the event...
|
||||||
@ -99,32 +86,22 @@ var DrawerPrototype = {
|
|||||||
|
|
||||||
__init__: function(parent, client, options){
|
__init__: function(parent, client, options){
|
||||||
var that = this
|
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 client_dom = client.dom || client
|
||||||
|
var dom = this.dom
|
||||||
|
options = this.options
|
||||||
|
|
||||||
// merge options...
|
this.parent
|
||||||
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
|
|
||||||
.addClass('blur')
|
.addClass('blur')
|
||||||
.append(dom)
|
.append(dom)
|
||||||
|
|
||||||
// add keyboard handler...
|
// add keyboard handler...
|
||||||
dom.keydown(
|
dom
|
||||||
keyboard.makeKeyboardHandler(
|
.click(function(){
|
||||||
this.keyboard,
|
that.close()
|
||||||
options.logKeys,
|
})
|
||||||
this))
|
|
||||||
.css({opacity: 0})
|
.css({opacity: 0})
|
||||||
.animate({
|
.animate({
|
||||||
scrollTop: Math.min(
|
scrollTop: Math.min(
|
||||||
@ -169,6 +146,9 @@ object.makeConstructor('Drawer',
|
|||||||
DrawerClassPrototype,
|
DrawerClassPrototype,
|
||||||
DrawerPrototype)
|
DrawerPrototype)
|
||||||
|
|
||||||
|
// inherit from widget...
|
||||||
|
Drawer.prototype.__proto__ = widget.Container.prototype
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
|
|||||||
@ -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...
|
// custom events...
|
||||||
close: function(handler){
|
close: function(handler){
|
||||||
// trigger the event...
|
// trigger the event...
|
||||||
@ -86,31 +73,17 @@ var OverlayPrototype = {
|
|||||||
|
|
||||||
__init__: function(parent, client, options){
|
__init__: function(parent, client, options){
|
||||||
var that = this
|
var that = this
|
||||||
parent = this.parent = $(parent || 'body')
|
|
||||||
options = options || {}
|
|
||||||
|
|
||||||
this.client = client
|
object.superMethod(Overlay, '__init__').call(this, parent, client, options)
|
||||||
|
|
||||||
// merge options...
|
this.dom
|
||||||
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)
|
|
||||||
.click(function(){
|
.click(function(){
|
||||||
that.close()
|
that.close()
|
||||||
})
|
})
|
||||||
|
|
||||||
parent
|
this.parent
|
||||||
.addClass('blur')
|
.addClass('blur')
|
||||||
.append(dom)
|
.append(this.dom)
|
||||||
|
|
||||||
// add keyboard handler...
|
|
||||||
dom.keydown(
|
|
||||||
keyboard.makeKeyboardHandler(
|
|
||||||
this.keyboard,
|
|
||||||
options.logKeys,
|
|
||||||
this))
|
|
||||||
|
|
||||||
// focus the client...
|
// focus the client...
|
||||||
if(client.focus){
|
if(client.focus){
|
||||||
@ -122,6 +95,7 @@ var OverlayPrototype = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var Overlay =
|
var Overlay =
|
||||||
module.Overlay =
|
module.Overlay =
|
||||||
object.makeConstructor('Overlay',
|
object.makeConstructor('Overlay',
|
||||||
@ -129,6 +103,10 @@ object.makeConstructor('Overlay',
|
|||||||
OverlayPrototype)
|
OverlayPrototype)
|
||||||
|
|
||||||
|
|
||||||
|
// inherit from widget...
|
||||||
|
Overlay.prototype.__proto__ = widget.Container.prototype
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* vim:set ts=4 sw=4 : */
|
* vim:set ts=4 sw=4 : */
|
||||||
|
|||||||
@ -9,6 +9,10 @@ console.log('>>> widget')
|
|||||||
|
|
||||||
//var DEBUG = DEBUG != null ? DEBUG : true
|
//var DEBUG = DEBUG != null ? DEBUG : true
|
||||||
|
|
||||||
|
var keyboard = require('../keyboard')
|
||||||
|
var object = require('../../object')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
// helpers...
|
// 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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -65,10 +65,10 @@ function makeConstructor(name, a, b){
|
|||||||
|
|
||||||
|
|
||||||
// super equivalent...
|
// super equivalent...
|
||||||
var parent =
|
var superMethod =
|
||||||
module.parent =
|
module.superMethod =
|
||||||
function parent(obj){
|
function superMethod(cls, meth){
|
||||||
return obj.__proto__.__proto__
|
return cls.prototype.__proto__[meth]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user