everything.html revision 9d2b984ddc990a339c99c2ee8ab13348846a0bcb
1570N/A<!DOCTYPE html>
1570N/A<html>
1570N/A <head>
1570N/A <!-- reset the default browser styles -->
1570N/A <style>
1570N/A
1570N/A /* Fix this - Shouldn't require body specificity */
1570N/A body .yui3-button-selected {
1570N/A background-color:#426FD9;
1570N/A color:white;
1570N/A }
1570N/A
1570N/A </style>
1570N/A
1570N/A <script src='/build/yui/yui-min.js'></script>
1570N/A
1570N/A <script>
1570N/A
1570N/A YUI({
1570N/A base: '/build/',
1570N/A debug: true,
1570N/A combo: false,
1570N/A filter: 'raw'
1570N/A }).use('button', 'cssbuttons', 'cssfonts', 'console', function(Y){
3232N/A
1570N/A new Y.Console().render();
1570N/A
1570N/A Y.log(new Y.Button({label:'A ninja button'}).getNode().getContent());
1570N/A
1570N/A /*
1570N/A Just a basic test with a listener
1570N/A */
1647N/A var button = new Y.Button({
1570N/A srcNode: Y.one('#event')
1570N/A });
1570N/A
1570N/A // One way of listening for events
1647N/A button.on('click', function(e){
1570N/A console.log("Clicked!");
1647N/A });
1570N/A
1570N/A
1570N/A
1570N/A
1570N/A
1647N/A /*
1647N/A A 'toggle' button listening for the selectedChange event
1647N/A */
1570N/A var button2 = new Y.Button({
1570N/A srcNode: Y.one('#toggle'),
1570N/A type: 'toggle'
1570N/A });
1570N/A
1570N/A // An alternative to button.get('srcNode').on('click', ...
1986N/A button2.on('selectedChange', function(){
1570N/A Y.log('toggled');
1570N/A });
1570N/A
1570N/A
1570N/A /*
1570N/A A 'link' button
1570N/A Preferably, the user would just apply a yui3-button style to an <a> element and not use JS
1570N/A */
1570N/A var button3 = new Y.Button({
1570N/A srcNode: Y.one('#link')
1570N/A });
1570N/A
1570N/A
1986N/A
1570N/A
1570N/A
1570N/A
1570N/A
1570N/A /*
1570N/A A disabled button
1570N/A */
1570N/A var button4 = new Y.Button({
1570N/A srcNode: Y.one('#disabled'),
1570N/A disabled: true
});
/*
A group of radio-like buttons
*/
var buttonGroup = new Y.ButtonGroup({
srcNodes: Y.all('.group'),
type: 'radio'
});
buttonGroup.after('selectionChange', function(e){
Y.log('buttonGroup selection changed');
});
/*
A group of checkbox-like buttons
*/
var buttonGroup2 = new Y.ButtonGroup({
srcNodes: Y.all('.multigroup'),
type: 'checkbox'
});
buttonGroup2.after('selectionChange', function(e){
var selection = buttonGroup2.get('selection');
Y.log('buttonGroup2 selected count = ' + selection.length);
});
/*
A button generator
Y.Buttons adds nothing useful for the gernator buttons, so just add the class and a listener.
*/
Y.all('.generator').addClass('yui3-button').on('click', function(e){
var button, type, config;
type = e.target.getAttribute('data-type');
config = {
label: type
};
if (type === 'disabled') {
config.type = 'push';
config.disabled = true;
}
else {
config.type = type;
}
config.srcNode = Y.Node.create('<button>' + config.label + '</button>');
button = new Y.Button(config);
Y.one('#generated').append(button.getNode());
})
});
</script>
</head>
<body class='yui3-skin-sam'>
<div id='yconsole'></div>
<h1>Button prototype</h1>
<hr />
<h2>Event</h2>
<button id='event' tabindex='3'>Change <br /> Color</button>
<br>
<h2>Toggle w/ event</h2>
<input type='button' id='toggle' value='Toggle'></input>
<br>
<h2>Link</h2>
<a href='http://yahoo.com' id='link'>Go to yahoo.com</a>
<h2>Disabled</h2>
<button id='disabled'>Should be disabled</button>
<br>
<h2>Group (radio)</h2>
<button class='group' id='btn1'>Button 13</button>
<button class='group' id='btn2'>Button 27</button>
<button class='group' id='btn3'>Button 40</button>
<br>
<h2>Multi-Group (checkbox)</h2>
<button class='multigroup' id='btn4'>Button 4</button>
<button class='multigroup' id='btn5'>Button 5</button>
<button type='button' class='multigroup' id='btn6'>Button 6</button>
<br>
<h2>Generator</h2>
<button class='generator' data-type='push'>Generate Push Button</button>
<button class='generator' data-type='toggle'>Generate Toggle Button</button>
<button class='generator' data-type='disabled'>Generate Disabled Button</button>
<div id='generated' style='border:solid black 1px;'></div>
</body>
</html>