Permalink
Browse files

added close targets and actions to handle external control of the dro…

…p down [statecharts] :)
  • Loading branch information...
1 parent 826d576 commit e84f7c7fdf61d80e11dc1a204e0c7a50f3ff29c0 @etgryphon etgryphon committed Mar 28, 2011
Showing with 32 additions and 6 deletions.
  1. +32 −6 frameworks/foundation/mixins/drop_down.js
@@ -22,6 +22,14 @@ SCUI.DropDown = {
isShowingDropDown: NO,
+ /**
+ params
+ */
+ target: null,
+ action: null,
+ closeTarget: null,
+ closeAction: null,
+
/**
@private
Reference to the drop down instance that gets created in init().
@@ -37,8 +45,9 @@ SCUI.DropDown = {
dropDownType: SC.PICKER_MENU,
initMixin: function() {
+ var target, action, cTarget, cAction, dropDown;
// Try to create a new menu instance
- var dropDown = this.get('dropDown');
+ dropDown = this.get('dropDown');
if (dropDown && SC.typeOf(dropDown) === SC.T_CLASS) {
this._dropDownPane = dropDown.create();
this.set('dropDown', this._dropDownPane); // set as pointer to instance for convenience
@@ -47,11 +56,16 @@ SCUI.DropDown = {
}
}
- // TODO: [BB] Check for existance of target and action
- if (this.target !== undefined && this.action !== undefined) {
- this.set('target', this);
- this.set('action', 'toggle');
- }
+ // Set up the action that gets called on the trigger event
+ target = this.target || this;
+ action = this.action || 'toggle';
+ this.set('target', target);
+ this.set('action', action);
+
+ // Set up an observer if picker is closed and you want an external event
+ if (!SC.none(this.closeAction)){
+ this.addObserver('isShowingDropDown', this, this._isShowingDropDownChanged);
+ }
},
/**
@@ -96,6 +110,18 @@ SCUI.DropDown = {
else {
this.showDropDown();
}
+ },
+
+ /**
+ this only gets called if there are special external close actions
+ */
+ _isShowingDropDownChanged: function(){
+ var t, a, st = this.get('isShowingDropDown');
+ if (st === NO){
+ t = this.get('closeTarget') || this.get('target') || this;
+ a = this.get('closeAction');
+ this.getPath('pane.rootResponder').sendAction(a, t, this, this.get('pane'));
+ }
}
};

0 comments on commit e84f7c7

Please sign in to comment.