Skip to content

Commit

Permalink
gallery-2010.09.08-19-45 apipkin gallery-button-toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
YUI Builder committed Sep 8, 2010
1 parent 3450a87 commit aed7c9f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 88 deletions.
52 changes: 26 additions & 26 deletions src/gallery-button-toggle/build.properties
@@ -1,27 +1,27 @@
# Button Toggle Build Properties
# As long as the 'builder' project is cloned to the default folder
# next to the 'yui3-gallery' project folder, the 'builddir' property does not
# need to be changed
#
# If the 'builder' project is checked out to an alternate location, this
# property should be updated to point to the checkout location.
builddir=../../../builder/componentbuild
# The name of the component. E.g. event, attribute, widget
component=gallery-button-toggle
# The list of files which should be concatenated to create the component.
# NOTE: For a css component (e.g. cssfonts, cssgrids etc.) use component.cssfiles instead.
# component.jsfiles=button-toggle.js, button-toggleHelperClass.js, button-toggleSubComponentClass.js
component.jsfiles=button-toggle.js
# The list of modules this component requires. Used to set up the Y.add module call for YUI 3.
component.requires=gallery-button
# The list of modules this component supersedes. Used to set up the Y.add module call for YUI 3.
component.supersedes=
# The list of modules that are optional for this module. Used to set up the Y.add module call for YUI 3.
component.optional=
# Button Toggle Build Properties

# As long as the 'builder' project is cloned to the default folder
# next to the 'yui3-gallery' project folder, the 'builddir' property does not
# need to be changed
#
# If the 'builder' project is checked out to an alternate location, this
# property should be updated to point to the checkout location.
builddir=../../../builder/componentbuild

# The name of the component. E.g. event, attribute, widget
component=gallery-button-toggle

# The list of files which should be concatenated to create the component.
# NOTE: For a css component (e.g. cssfonts, cssgrids etc.) use component.cssfiles instead.
# component.jsfiles=button-toggle.js, button-toggleHelperClass.js, button-toggleSubComponentClass.js
component.jsfiles=button-toggle.js

# The list of modules this component requires. Used to set up the Y.add module call for YUI 3.
component.requires=gallery-button

# The list of modules this component supersedes. Used to set up the Y.add module call for YUI 3.
component.supersedes=

# The list of modules that are optional for this module. Used to set up the Y.add module call for YUI 3.
component.optional=

12 changes: 6 additions & 6 deletions src/gallery-button-toggle/build.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- YUI 3 Gallery Component Build File -->
<project name="Button Toggle" default="local">
<description>Button Toggle Build File</description>
<property file="build.properties" />
<import file="${builddir}/3.x/bootstrap.xml" description="Default Build Properties and Targets" />
<?xml version="1.0" encoding="UTF-8"?>
<!-- YUI 3 Gallery Component Build File -->
<project name="Button Toggle" default="local">
<description>Button Toggle Build File</description>
<property file="build.properties" />
<import file="${builddir}/3.x/bootstrap.xml" description="Default Build Properties and Targets" />
</project>
91 changes: 35 additions & 56 deletions src/gallery-button-toggle/js/button-toggle.js
@@ -1,56 +1,35 @@
var YL = Y.Lang,
DESELECTED_CALLBACK = 'deselectedCallback';


Y.ButtonToggle = Y.Base.create('button', Y.Button, [], {

initializer : function(config) {
this.after('selectedChange',this._selectedChanged, this);
},

_bindClick : function() {

this.get('boundingBox').after('click',function(e){
var parent = null;
if(!this.isRoot()) {
var parent = this.get('parent'),
selection = parent.get('selection');
if(
parent instanceof Y.ButtonGroup && // we are in a button group
parent.get('alwaysSelected') && // there should always be at least one
this.get('selected') === 1 && // this is selected
(
selection === this ||
(
selection instanceof Y.ArrayList &&
selection.size() === 1 &&
selection.item(0) === this
)
) // this is the only selected
) {
return;
}
}
this.set('selected', (this.get('selected') === 0) ? 1 : 0);
},this);
},

_selectedChanged : function(e) {
if(e.newVal) {
if(this.get('callback')) {
(Y.bind(this.get('callback'),this))();
}
}else{
if(this.get(DESELECTED_CALLBACK)) {
(Y.bind(this.get(DESELECTED_CALLBACK),this))();
}
}
}

}, {
ATTRS : {
deselectedCallback : {
validator : YL.isFunction
}
}
});
var YL = Y.Lang,
DESELECTED_CALLBACK = 'deselectedCallback';

Y.ButtonToggle = Y.Base.create('button', Y.Button, [], {

initializer : function(config) {
this.after('selectedChange',this._afterSelectedChanged, this);
},

_defPressFn : function(e) {
this.set('selected', (this.get('selected') === 0) ? 1 : 0);
},

_afterSelectedChanged : function(e) {
if(e.newVal) {
this._executeCallback();
}else{
this._executeDeselectCallback();
}
},

_executeDeselectCallback : function(e) {
Y.log('Y.ButtonToggle::_executeDeselectCallback');
if(this.get(DESELECTED_CALLBACK)) {
(this.get(DESELECTED_CALLBACK))();
}
}

}, {
ATTRS : {
deselectedCallback : {
validator : YL.isFunction
}
}
});

0 comments on commit aed7c9f

Please sign in to comment.