45
40
var namespace = Y.namespace('lp.app.widgets.expander');
47
// Define some constants.
48
var EXPANDER_CREATED = 'expander:created',
49
EXPANDER_DESTROYED = 'expander:destroyed',
50
EXPANDER_STATE_CHANGED = 'expander:state_changed',
51
EXPANDED = 'expander:expanded',
52
COLLAPSED = 'expander:collapsed';
54
namespace.EXPANDER_CREATED = EXPANDER_CREATED;
55
namespace.EXPANDER_DESTORYED = EXPANDER_DESTROYED;
56
namespace.EXPANDER_STATE_CHANGED = EXPANDER_STATE_CHANGED;
57
namespace.EXPANDED = EXPANDED;
58
namespace.COLLAPSED = COLLAPSED;
61
* A single ExpanderRadioController instance is created for this namespace.
62
* Each expander instance which is created with a group id is registered with
63
* this controller. The controller ensures that only one expander from each
64
* group is open at any time.
66
function ExpanderRadioController() {
67
ExpanderRadioController.superclass.constructor.apply(this, arguments);
70
ExpanderRadioController.NAME = "ExpanderRadioController";
72
Y.extend(ExpanderRadioController, Y.Base, {
74
initializer: function() {
76
var controller = this;
77
Y.on(EXPANDER_CREATED, function(group_id, expander) {
78
controller._registerExpander(group_id, expander);
80
Y.on(EXPANDER_DESTROYED, function(group_id, expander) {
81
controller._deregisterExpander(group_id, expander);
83
Y.on(EXPANDER_STATE_CHANGED,
84
function(group_id, new_state, active_expander) {
85
controller._stateChangeProcessor(
86
group_id, new_state, active_expander);
90
_stateChangeProcessor: function(group_id, new_state, active_expander) {
91
this.expanders[group_id].forEach(function(expander) {
92
if (new_state === EXPANDED && expander !== active_expander) {
93
if (expander.isExpanded()) {
94
expander.render(false);
100
_registerExpander: function(group_id, expander) {
101
if (!this.expanders.hasOwnProperty(group_id)) {
102
this.expanders[group_id] = [];
104
this.expanders[group_id].push(expander);
107
_deregisterExpander: function(group_id, expander) {
108
if (this.expanders.hasOwnProperty(group_id)) {
109
var idx = this.expanders[group_id].indexOf(expander);
111
this.expanders[group_id].splice(idx, 1);
117
// Create the controller instance
118
if (namespace.expanderRadioController === undefined) {
119
namespace.expanderRadioController = new ExpanderRadioController();
123
43
* Create an expander.
168
86
this._animation = undefined;
171
if (Y.Lang.isValue(this.config.group_id)) {
172
Y.fire(EXPANDER_CREATED, this.config.group_id, this);
175
89
// Is setup complete? Skip any animations until it is.
176
90
this.fully_set_up = false;
178
Expander.NAME = "Expander";
179
92
namespace.Expander = Expander;
181
Y.extend(Expander, Y.Base, {
94
namespace.Expander.prototype = {
231
* Record the expanded/collapsed state of the content tag and fire the
232
* state_changed event.
138
* Record the expanded/collapsed state of the content tag.
234
140
setExpanded: function(is_expanded) {
235
var state_changed = this.isExpanded() !== is_expanded;
236
141
this.setContentClassIf(is_expanded, this.css_classes.expanded);
237
if (state_changed && Y.Lang.isValue(this.config.group_id)) {
239
EXPANDER_STATE_CHANGED,
240
this.config.group_id,
241
is_expanded?EXPANDED:COLLAPSED, this);