Spinner: Updates for new button widget and classes option

This commit is contained in:
Alexander Schmitz 2015-01-07 21:51:38 -05:00
parent 9f7f0a4279
commit 16abde399d
19 changed files with 39 additions and 349 deletions

View File

@ -5,18 +5,13 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Button - Default functionality</title>
<link rel="stylesheet" href="../../themes/base/all.css">
<script src="../../external/jquery/jquery.js"></script>
<script src="../../ui/core.js"></script>
<script src="../../ui/widget.js"></script>
<script src="../../ui/button.js"></script>
<link rel="stylesheet" href="../demos.css">
<script>
$( function() {
<script src="../../external/requirejs/require.js"></script>
<script src="../bootstrap.js">
$( ".widget input[type=submit], .widget a, .widget button" ).button();
$( "button, input, a" ).click( function( event ) {
event.preventDefault();
} );
} );
</script>
</head>
<body>

View File

@ -5,13 +5,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Button - Icons</title>
<link rel="stylesheet" href="../../themes/base/all.css">
<script src="../../external/jquery/jquery.js"></script>
<script src="../../ui/core.js"></script>
<script src="../../ui/widget.js"></script>
<script src="../../ui/button.js"></script>
<link rel="stylesheet" href="../demos.css">
<script>
$( function() {
<script src="../../external/requirejs/require.js"></script>
<script src="../bootstrap.js">
$( ".widget button" ).first()
.button()
.next().button( {
@ -29,7 +25,6 @@
icon: "ui-icon-gear",
iconPosition: "bottom"
} );
} );
</script>
</head>
<body>
@ -41,7 +36,6 @@
<button>Button with icon on the right</button>
<button>Button with icon on the top</button>
<button>Button with icon on the bottom</button>
<button>Button with icon on the top</button>
</div>
<div class="css">
<h1>CSS</h1>

View File

@ -1,70 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Button - Split button</title>
<link rel="stylesheet" href="../../themes/base/all.css">
<script src="../../external/jquery/jquery.js"></script>
<script src="../../ui/core.js"></script>
<script src="../../ui/widget.js"></script>
<script src="../../ui/button.js"></script>
<script src="../../ui/position.js"></script>
<script src="../../ui/menu.js"></script>
<link rel="stylesheet" href="../demos.css">
<style>
.ui-menu { position: absolute; width: 100px; }
</style>
<script>
$(function() {
$( "#rerun" )
.button()
.on( "click", function() {
alert( "Running the last action" );
})
.next()
.button({
text: false,
icons: {
primary: "ui-icon-triangle-1-s"
}
})
.on( "click", function() {
var menu = $( this ).parent().next().show().position({
my: "left top",
at: "left bottom",
of: this
});
$( document ).one( "click", function() {
menu.hide();
});
return false;
})
.parent()
.buttonset()
.next()
.hide()
.menu();
});
</script>
</head>
<body>
<div>
<div>
<button id="rerun">Run last action</button>
<button id="select">Select an action</button>
</div>
<ul>
<li><div>Open...</div></li>
<li><div>Save</div></li>
<li><div>Delete</div></li>
</ul>
</div>
<div class="demo-description">
<p>An example of a split button built with two buttons: A plain button with just text, one with only a primary icon
and no text. Both are grouped together in a set.</p>
</div>
</body>
</html>

View File

@ -1,115 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Button - Toolbar</title>
<link rel="stylesheet" href="../../themes/base/all.css">
<script src="../../external/jquery/jquery.js"></script>
<script src="../../ui/core.js"></script>
<script src="../../ui/widget.js"></script>
<script src="../../ui/button.js"></script>
<link rel="stylesheet" href="../demos.css">
<style>
#toolbar {
padding: 4px;
display: inline-block;
}
</style>
<script>
$(function() {
$( "#beginning" ).button({
text: false,
icons: {
primary: "ui-icon-seek-start"
}
});
$( "#rewind" ).button({
text: false,
icons: {
primary: "ui-icon-seek-prev"
}
});
$( "#play" ).button({
text: false,
icons: {
primary: "ui-icon-play"
}
})
.on( "click", function() {
var options;
if ( $( this ).text() === "play" ) {
options = {
label: "pause",
icons: {
primary: "ui-icon-pause"
}
};
} else {
options = {
label: "play",
icons: {
primary: "ui-icon-play"
}
};
}
$( this ).button( "option", options );
});
$( "#stop" ).button({
text: false,
icons: {
primary: "ui-icon-stop"
}
})
.on( "click", function() {
$( "#play" ).button( "option", {
label: "play",
icons: {
primary: "ui-icon-play"
}
});
});
$( "#forward" ).button({
text: false,
icons: {
primary: "ui-icon-seek-next"
}
});
$( "#end" ).button({
text: false,
icons: {
primary: "ui-icon-seek-end"
}
});
$( "#shuffle" ).button();
$( "#repeat" ).buttonset();
});
</script>
</head>
<body>
<div id="toolbar" class="ui-widget-header ui-corner-all">
<button id="beginning">go to beginning</button>
<button id="rewind">rewind</button>
<button id="play">play</button>
<button id="stop">stop</button>
<button id="forward">fast forward</button>
<button id="end">go to end</button>
<input type="checkbox" id="shuffle" /><label for="shuffle">Shuffle</label>
<span id="repeat">
<input type="radio" id="repeat0" name="repeat" checked="checked" /><label for="repeat0">No Repeat</label>
<input type="radio" id="repeat1" name="repeat" /><label for="repeat1">Once</label>
<input type="radio" id="repeatall" name="repeat" /><label for="repeatall">All</label>
</span>
</div>
<div class="demo-description">
<p>
A mediaplayer toolbar. Take a look at the underlying markup: A few button elements,
an input of type checkbox for the Shuffle button, and three inputs of type radio for the Repeat options.
</p>
</div>
</body>
</html>

View File

@ -4,17 +4,12 @@
<meta charset="utf-8">
<title>jQuery UI Checkboxradio - Default functionality</title>
<link rel="stylesheet" href="../../themes/base/all.css">
<script src="../../external/jquery/jquery.js"></script>
<script src="../../ui/core.js"></script>
<script src="../../ui/widget.js"></script>
<script src="../../ui/checkboxradio.js"></script>
<link rel="stylesheet" href="../demos.css">
<script>
$(function() {
<script src="../../external/requirejs/require.js"></script>
<script src="../bootstrap.js">
$( "input" ).checkboxradio({
label: "foo"
});
});
</script>
</head>
<body>

View File

@ -4,17 +4,12 @@
<meta charset="utf-8">
<title>jQuery UI Checkboxradio - No Icons</title>
<link rel="stylesheet" href="../../themes/base/all.css">
<script src="../../external/jquery/jquery.js"></script>
<script src="../../ui/core.js"></script>
<script src="../../ui/widget.js"></script>
<script src="../../ui/checkboxradio.js"></script>
<link rel="stylesheet" href="../demos.css">
<script>
$(function() {
<script src="../../external/requirejs/require.js"></script>
<script src="../bootstrap.js">
$( "input" ).checkboxradio({
icon: false
});
});
</script>
</head>
<body>

View File

@ -4,14 +4,9 @@
<meta charset="utf-8">
<title>jQuery UI Checkboxradio - Product Selector</title>
<link rel="stylesheet" href="../../themes/base/all.css">
<script src="../../external/jquery/jquery.js"></script>
<script src="../../ui/core.js"></script>
<script src="../../ui/widget.js"></script>
<script src="../../ui/checkboxradio.js"></script>
<script src="../../ui/controlgroup.js"></script>
<link rel="stylesheet" href="../demos.css">
<script>
$(function() {
<script src="../../external/requirejs/require.js"></script>
<script src="../bootstrap.js">
$( "input" ).checkboxradio();
$( "[name='shape']").on( "change", function(){
$( ".shape" ).removeClass( "circle pill square rectangle" )
@ -34,7 +29,6 @@
$( ".toggles" ).controlgroup({
direction: "vertical"
});
});
</script>
<style>
.shape {

View File

@ -4,17 +4,11 @@
<meta charset="utf-8">
<title>jQuery UI Checkboxradio - Radio Group</title>
<link rel="stylesheet" href="../../themes/base/all.css">
<script src="../../external/jquery/jquery.js"></script>
<script src="../../ui/core.js"></script>
<script src="../../ui/widget.js"></script>
<script src="../../ui/checkboxradio.js"></script>
<script src="../../ui/controlgroup.js"></script>
<link rel="stylesheet" href="../demos.css">
<script>
$(function() {
<script src="../../external/requirejs/require.js"></script>
<script src="../bootstrap.js">
$( "input" ).checkboxradio();
$( "fieldset" ).controlgroup();
});
</script>
</head>
<body>

View File

@ -1,6 +1,6 @@
define( [
"lib/common",
"ui/button"
"ui/widgets/button"
], function( common ) {
common.testWidget( "button", {

View File

@ -1,5 +1,6 @@
define( [
"jquery",
"ui/safe-active-element",
"ui/widgets/button"
], function( $ ) {

View File

@ -1,6 +1,6 @@
define( [
"jquery",
"ui/button"
"ui/widgets/button"
], function( $ ) {
module( "Button (deprecated): core" );

View File

@ -1,6 +1,6 @@
define( [
"lib/common",
"ui/checkboxradio"
"ui/widgets/checkboxradio"
], function( common ) {
common.testWidget( "checkboxradio", {

View File

@ -1,6 +1,6 @@
define( [
"jquery",
"ui/checkboxradio"
"ui/widgets/checkboxradio"
], function( $ ) {
module( "Checkboxradio: core" );

View File

@ -1,80 +1,10 @@
define( [
"jquery",
"ui/checkboxradio"
"ui/widgets/checkboxradio"
], function( $ ) {
module( "Checkboxradio: events" );
asyncTest( "form reset / click", function( assert ) {
expect( 35 );
var radios = [
$( "#radio11" ).checkboxradio(),
$( "#radio12" ).checkboxradio(),
$( "#radio13" ).checkboxradio()
],
widgets = [
radios[ 0 ].checkboxradio( "widget" ),
radios[ 1 ].checkboxradio( "widget" ),
radios[ 2 ].checkboxradio( "widget" )
],
form1 = $( "#form1" ),
form2 = $( "#form2" );
// Checkes that only the specified radio is checked in the group
function assertChecked( checked ) {
$.each( widgets, function( index ) {
var method = index === checked ? "hasClasses" : "lacksClasses";
assert[ method ]( widgets[ index ], "ui-checkboxradio-checked ui-state-active" );
} );
}
// Checks the form count on each form
function assertFormCount( count ) {
equal( form1.data( "uiCheckboxradioCount" ), count, "Form1 has a count of " + count );
equal( form2.data( "uiCheckboxradioCount" ), 3, "Form2 has a count of 3" );
}
// Run the tests
function testForms( current, start ) {
assertChecked( 2 );
if ( !start && current !== 0 ) {
radios[ current - 1 ].checkboxradio( "destroy" );
}
assertFormCount( 3 - current );
radios[ current ].prop( "checked", true );
radios[ current ].trigger( "change" );
assertChecked( current );
form1.trigger( "reset" );
}
// Recoursivly run the tests in a setTimeout with call back for the resets
function iterate( i ) {
setTimeout( function() {
if ( i < 3 ) {
testForms( i );
iterate( i + 1 );
return;
}
radios[ 2 ].checkboxradio( "destroy" );
assertChecked( false );
start();
} );
}
$( "#form2 input" ).checkboxradio();
// Check the starting state then kick everything off
testForms( 0, true );
iterate( 0 );
} );
asyncTest(
"Resetting a checkbox's form should refresh the visual state of the checkbox",
function( assert ) {

View File

@ -1,6 +1,6 @@
define( [
"jquery",
"ui/checkboxradio"
"ui/widgets/checkboxradio"
], function( $ ) {
module( "Checkboxradio: methods" );

View File

@ -1,6 +1,6 @@
define( [
"jquery",
"ui/checkboxradio"
"ui/widgets/checkboxradio"
], function( $ ) {
module( "Checkboxradio: options" );

View File

@ -12,8 +12,7 @@
//>>description: Enhances a form with themeable buttons.
//>>docs: http://api.jqueryui.com/button/
//>>demos: http://jqueryui.com/button/
//>>css.structure: ../themes/base/core.css
//>>css.structure: ../themes/base/button.css
//>>css.structure: ../themes/base/core.css, ../themes/base/button.css
//>>css.theme: ../themes/base/theme.css
( function( factory ) {

View File

@ -14,8 +14,10 @@
// AMD. Register as an anonymous module.
define( [
"jquery",
"./core",
"./widget"
"../escape-selector",
"../form-reset-mixin",
"../labels",
"../widget"
], factory );
} else {
@ -24,19 +26,7 @@
}
}( function( $ ) {
// Remove and replace with reset handler extension
var formResetHandler = function() {
var form = $( this );
// Wait for the form reset to actually happen before refreshing
setTimeout( function() {
// We dont filter for css only versions since css only is not supported
form.find( ".ui-checkboxradio" ).checkboxradio( "refresh" );
} );
};
$.widget( "ui.checkboxradio", {
$.widget( "ui.checkboxradio", [ $.ui.formResetMixin, {
version: "@VERSION",
options: {
disabled: null,
@ -91,20 +81,12 @@ $.widget( "ui.checkboxradio", {
},
_create: function() {
var formCount,
checked = this.element[ 0 ].checked,
form = this.element.form();
this.formParent = !!form.length ? form : $( "body" );
var checked = this.element[ 0 ].checked;
formCount = this.formParent.data( "uiCheckboxradioCount" ) || 0;
this._bindFormResetHandler();
// We don't use _on and _off here because we want all the checkboxes in the same form to use
// single handler which handles all the checkboxradio widgets in the form
if ( formCount === 0 ) {
this.formParent.on( "reset." + this.widgetFullName, formResetHandler );
}
this.formParent.data( "uiCheckboxradioCount", formCount + 1 );
// this.form is set by the form-reset-mixin
this.formParent = this.form.length ? this.form : $( "body" );
if ( this.options.disabled == null ) {
this.options.disabled = this.element[ 0 ].disabled || false;
@ -199,13 +181,7 @@ $.widget( "ui.checkboxradio", {
},
_destroy: function() {
var formCount = this.formParent.data( "uiCheckboxradioCount" ) - 1;
this.formParent.data( "uiCheckboxradioCount", formCount );
if ( formCount === 0 ) {
this.formParent.off( "reset." + this.widgetFullName, formResetHandler );
}
this._unbindFormResetHandler();
if ( this.icon ) {
this.icon.remove();
@ -282,7 +258,7 @@ $.widget( "ui.checkboxradio", {
}
}
} );
} ] );
return $.ui.checkboxradio;

View File

@ -250,17 +250,19 @@ $.widget( "ui.spinner", {
// Button bindings
this.buttons = this.uiSpinner.children( "a" )
.attr( "tabIndex", -1 )
.button();
.button( {
classes: {
"ui-button": ""
}
} );
// TODO: Right now button does not support classes this is already updated in button PR
this._removeClass( this.buttons, "ui-corner-all" );
this._addClass( this.buttons.first(), "ui-spinner-button ui-spinner-up" );
this._addClass( this.buttons.last(), "ui-spinner-button ui-spinner-down" );
this._addClass( this.buttons.first().find( ".ui-button-text span" ), null,
"ui-icon " + this.options.icons.up );
this._addClass( this.buttons.last().find( ".ui-button-text span" ), null,
"ui-icon " + this.options.icons.down );
this.buttons.first().button( "option", "icon", this.options.icons.up );
this.buttons.last().button( "option", "icon", this.options.icons.down );
// IE 6 doesn't understand height: 50% for the buttons
// unless the wrapper has an explicit height