added ref to widget controller into the widget dom...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2015-11-09 22:48:13 +03:00
parent d11bf935d3
commit ecb1458f93
6 changed files with 80 additions and 7 deletions

View File

@ -625,7 +625,7 @@ module.MetaActions = {
},
// Same as .inlineMmixin(..) but isolates a mixin in a seporate object
// in the ingeritance chain...
// in the inheritance chain...
//
mixin: function(from, all, descriptors, all_attr_types){
var proto = Object.create(this.__proto__)

View File

@ -91,7 +91,7 @@ var BrowserClassPrototype = {
},
// Construct the dom...
make: function(options){
make: function(obj, options){
var browser = $('<div>')
.addClass('browse-widget')
// make thie widget focusable...
@ -137,6 +137,11 @@ var BrowserClassPrototype = {
.append($('<div>')
.addClass('v-block list'))
// XXX make this part of the framework...
if(obj){
browser.data('widget-controller', obj)
}
return browser
},
}

View File

@ -17,7 +17,7 @@ var widget = require('./widget')
/*********************************************************************/
var DrawerClassPrototype = {
make: function(client, options){
make: function(obj, client, options){
var that = this
var overlay = $('<div>')
.addClass('drawer-widget')
@ -35,6 +35,11 @@ var DrawerClassPrototype = {
overlay.attr('tabindex', 0)
}
// XXX make this part of the framework...
if(obj){
overlay.data('widget-controller', obj)
}
return overlay
},
}

View File

@ -17,7 +17,7 @@ var widget = require('./widget')
/*********************************************************************/
var OverlayClassPrototype = {
make: function(client, options){
make: function(obj, client, options){
var that = this
var overlay = $('<div>')
.addClass('overlay-widget')
@ -35,6 +35,11 @@ var OverlayClassPrototype = {
overlay.attr('tabindex', 0)
}
// XXX make this part of the framework...
if(obj){
overlay.data('widget-controller', obj)
}
return overlay
},
}
@ -120,6 +125,23 @@ Overlay.prototype.__proto__ = widget.Container.prototype
// XXX this should return a proxy with a set of extension API...
var getOverlay =
module.getOverlay = function(obj){
var overlay = $(obj || 'body')
.find('.overlay-widget')
.last()
if(overlay.length == 0){
return null
}
// get the controller...
return overlay.data('widget-controller')
}
/**********************************************************************
* vim:set ts=4 sw=4 : */
return module })

View File

@ -52,7 +52,7 @@ function(){
/*********************************************************************/
var WidgetClassPrototype = {
make: function(client, options){
make: function(obj, client, options){
console.error('Widget must define a .make method.')
},
}
@ -102,7 +102,7 @@ var WidgetPrototype = {
// build the dom...
if(this.constructor.make){
this.dom = this.constructor.make(options)
this.dom = this.constructor.make(this, options)
}
// XXX do we do this here???
@ -172,7 +172,7 @@ var ContainerPrototype = {
// build the dom...
if(this.constructor.make){
this.dom = this.constructor
.make(client.dom || client, options)
.make(this, client.dom || client, options)
}
// add keyboard handler...

View File

@ -2314,6 +2314,36 @@ var drawer = require('lib/widget/drawer')
// scenario:
// - an action is run while a menu runs a state changing action
// - state restoration will overwrite the effects fo the BG action
// XXX .preventClosing(..) mechanism needs revision...
// ...might be a better idea to add a permanent action to work with
// modal overlays and to define strict rules under which such overlays
// operate, like:
// - only the top overlay is active and can receive events
// - an overlay is closed on open event
// - an overlay can be prevented from closing only while handling
// an open event
// - an overlay can close itself or the previous overlay during
// its open event
//
// Proposed API:
// getOverlay(context)
// -> overlay object
// -> null
// returns an overlay controller for a given container
// NOTE: if no overlay is open this returns null
// NOTE: this might be implemented as an action.
// NOTE: this returns an object that represents only
// the top overlay
// NOTE: this should either extend the overlay client
// or encapsulate it (preferred), providing a method to access
// it (something like: .client prop or
// .getCleint() method)...
// .preventClosing()
// prevent closing of an overlay after this open event is
// handled
// .close()
//
//
var makeActionLister = function(list, filter, pre_order){
pre_order = typeof(filter) == typeof(true) ? filter : pre_order
filter = typeof(filter) == typeof(true) ? null : filter
@ -2341,6 +2371,9 @@ var makeActionLister = function(list, filter, pre_order){
if(k.slice(-1) == '*'){
actions[k] = function(){
// XXX this may cause race conditions as we are
// splitting the state in two and then
// overwriting one...
var a = Object.create(that)
a.preventClosing = function(){
closingPrevented = true
@ -2364,6 +2397,9 @@ var makeActionLister = function(list, filter, pre_order){
} else {
actions[k] = function(){
// XXX this may cause race conditions as we are
// splitting the state in two and then
// overwriting one...
var a = Object.create(that)
a.preventClosing = function(){
closingPrevented = true
@ -2403,6 +2439,11 @@ var makeActionLister = function(list, filter, pre_order){
}
var ActionTreeActions = actions.Actions({
// XXX move this to a generic modal overlay feature...
getOverlay: ['Interface/Get overlay object',
function(){
}],
browseActions: ['Interface/Browse actions',
makeActionLister(browse.makePathList, true)],