Merge branch 'master' into datepicker

This commit is contained in:
Felix Nagel 2016-11-09 10:13:10 +01:00
commit 6b8ac7ef1b
210 changed files with 153985 additions and 7631 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
dist dist
bower_components
node_modules node_modules
.sizecache.json .sizecache.json

View File

@ -8,8 +8,5 @@
"es3": true, "es3": true,
// We want to output all errors // We want to output all errors
"maxErrors": 1000000, "maxErrors": 1000000
// Ref https://github.com/jquery/contribute.jquery.org/issues/80#issuecomment-45253460
"maximumLineLength": null
} }

View File

@ -17,7 +17,7 @@ Christoph Rönsch <christoph.roensch@arcor.de>
Corey Frang <gnarf37@gmail.com> <gnarf@gnarf.net> Corey Frang <gnarf37@gmail.com> <gnarf@gnarf.net>
Courtland Allen <courtlandallen@gmail.com> Courtland Allen <courtlandallen@gmail.com>
Dan Streetman <ddstreet@ieee.org> Dan Streetman <ddstreet@ieee.org>
Dan Strohl <dstrohl@users.noreply.github.com> Dan Strohl <dan@wjcg.net> <dstrohl@users.noreply.github.com>
Danny Trunk <dtrunk90@gmail.com> <dtrunk90@googlemail.com> Danny Trunk <dtrunk90@gmail.com> <dtrunk90@googlemail.com>
David De Sloovere <david.desloovere@outlook.com> <david.desloovere@hotmail.com> David De Sloovere <david.desloovere@outlook.com> <david.desloovere@hotmail.com>
David Murdoch <david@davidmurdoch.com> <musicisair@yahoo.com> David Murdoch <david@davidmurdoch.com> <musicisair@yahoo.com>

View File

@ -2,6 +2,4 @@ sudo: required
dist: trusty dist: trusty
language: node_js language: node_js
node_js: node_js:
- "0.12" - "6"
before_script:
- npm install -g grunt-cli

View File

@ -321,4 +321,13 @@ Piotr Baran <piotros@wp.pl>
Mukul Hase <mukulhase@gmail.com> Mukul Hase <mukulhase@gmail.com>
Konstantin Dinev <kdinev@mail.bw.edu> Konstantin Dinev <kdinev@mail.bw.edu>
Rand Scullard <rand@randscullard.com> Rand Scullard <rand@randscullard.com>
Dan Strohl Dan Strohl <dan@wjcg.net>
Maksim Ryzhikov <rv.maksim@gmail.com>
Amine HADDAD <haddad@allegorie.tv>
Amanpreet Singh <apsdehal@gmail.com>
Alexey Balchunas <bleshik@gmail.com>
Peter Kehl <peter.kehl@gmail.com>
Peter Dave Hello <hsu@peterdavehello.org>
Johannes Schäfer <johnschaefer@gmx.de>
Ville Skyttä <ville.skytta@iki.fi>
Ryan Oriecuia <ryan.oriecuia@visioncritical.com>

View File

@ -27,7 +27,7 @@ git clone git://github.com/jquery/jquery-ui.git
cd jquery-ui cd jquery-ui
``` ```
The tests can run in any local web server. Ideally you should test your patch in appropriate web browsers and if possible run `grunt` to lint the code and run automated tests (this will happen automatically when you create a pull request). See the [Recommended Setup](#environment-recommended-setup) for setting up Node.js so that the grunt command works. The tests can run in any local web server. Ideally you should test your patch in appropriate web browsers and if possible run `npm test` to lint the code and run automated tests (this will happen automatically when you create a pull request). See the [Recommended Setup](#environment-recommended-setup) for setting up Node.js so that the `npm test` command works.
### Environment: Getting the Source ### Environment: Getting the Source
@ -61,15 +61,9 @@ git pull upstream master
### Environment: Recommended Setup ### Environment: Recommended Setup
jQuery UI uses Node.js & Grunt to automate the building and validation of source code. Here is how to set that up: jQuery UI uses Node.js to automate the building and validation of source code. Here is how to set that up:
* Get [Node.js](http://nodejs.org/) (includes NPM, necessary for the next step) * Get [Node.js](http://nodejs.org/) (includes NPM, necessary for the next step)
* Install Grunt cli:
```bash
npm install -g grunt-cli
```
* Install local Node.js modules * Install local Node.js modules
```bash ```bash
@ -87,10 +81,10 @@ The tests require a local web server and the samples contain some PHP, so a PHP
### Running the Tests ### Running the Tests
To lint the JavaScript, HTML, and CSS, as well as run a smoke test in PhantomJS, run grunt: To lint the JavaScript, HTML, and CSS, as well as run a smoke test in PhantomJS, run the full test suite through npm:
```bash ```bash
grunt npm test
``` ```
To run the tests for a specific plugin in your browser, open the appropriate file from the `/tests/unit/` directory, for example: `http://localhost/tests/unit/accordion/accordion.html`. The domain will be dependent on your local server configuration; if there is a port, be sure to include it. To run the tests for a specific plugin in your browser, open the appropriate file from the `/tests/unit/` directory, for example: `http://localhost/tests/unit/accordion/accordion.html`. The domain will be dependent on your local server configuration; if there is a port, be sure to include it.

View File

@ -7,18 +7,18 @@ var
coreFiles = [ coreFiles = [
"core.js", "core.js",
"widget.js", "widget.js",
"mouse.js", "widgets/mouse.js",
"draggable.js", "widgets/draggable.js",
"droppable.js", "widgets/droppable.js",
"resizable.js", "widgets/resizable.js",
"selectable.js", "widgets/selectable.js",
"sortable.js", "widgets/sortable.js",
"effect.js" "effect.js"
], ],
uiFiles = coreFiles.map(function( file ) { uiFiles = coreFiles.map(function( file ) {
return "ui/" + file; return "ui/" + file;
}).concat( expandFiles( "ui/*.js" ).filter(function( file ) { }).concat( expandFiles( "ui/**/*.js" ).filter(function( file ) {
return coreFiles.indexOf( file.substring( 3 ) ) === -1; return coreFiles.indexOf( file.substring( 3 ) ) === -1;
}) ), }) ),
@ -178,12 +178,21 @@ grunt.initConfig({
}, },
jscs: { jscs: {
all: { ui: {
options: { options: {
config: true config: true
}, },
files: { files: {
src: [ "demos/**/*.js", "build/**/*.js", "tests/**/*.js", "ui/**/*.js" ] src: [ "demos/**/*.js", "build/**/*.js", "ui/**/*.js" ]
}
},
tests: {
options: {
config: true,
maximumLineLength: null
},
files: {
src: [ "tests/**/*.js" ]
} }
} }
}, },
@ -287,7 +296,7 @@ grunt.initConfig({
"jshint/LICENSE": "jshint/LICENSE", "jshint/LICENSE": "jshint/LICENSE",
"jquery/jquery.js": "jquery-1.x/dist/jquery.js", "jquery/jquery.js": "jquery-1.x/dist/jquery.js",
"jquery/MIT-LICENSE.txt": "jquery-1.x/MIT-LICENSE.txt", "jquery/LICENSE.txt": "jquery-1.x/LICENSE.txt",
"jquery-1.7.0/jquery.js": "jquery-1.7.0/jquery.js", "jquery-1.7.0/jquery.js": "jquery-1.7.0/jquery.js",
"jquery-1.7.0/MIT-LICENSE.txt": "jquery-1.7.0/MIT-LICENSE.txt", "jquery-1.7.0/MIT-LICENSE.txt": "jquery-1.7.0/MIT-LICENSE.txt",
@ -337,6 +346,21 @@ grunt.initConfig({
"jquery-1.11.3/jquery.js": "jquery-1.11.3/dist/jquery.js", "jquery-1.11.3/jquery.js": "jquery-1.11.3/dist/jquery.js",
"jquery-1.11.3/MIT-LICENSE.txt": "jquery-1.11.3/MIT-LICENSE.txt", "jquery-1.11.3/MIT-LICENSE.txt": "jquery-1.11.3/MIT-LICENSE.txt",
"jquery-1.12.0/jquery.js": "jquery-1.12.0/dist/jquery.js",
"jquery-1.12.0/LICENSE.txt": "jquery-1.12.0/LICENSE.txt",
"jquery-1.12.1/jquery.js": "jquery-1.12.1/dist/jquery.js",
"jquery-1.12.1/LICENSE.txt": "jquery-1.12.1/LICENSE.txt",
"jquery-1.12.2/jquery.js": "jquery-1.12.2/dist/jquery.js",
"jquery-1.12.2/LICENSE.txt": "jquery-1.12.2/LICENSE.txt",
"jquery-1.12.3/jquery.js": "jquery-1.12.3/dist/jquery.js",
"jquery-1.12.3/LICENSE.txt": "jquery-1.12.3/LICENSE.txt",
"jquery-1.12.4/jquery.js": "jquery-1.12.4/dist/jquery.js",
"jquery-1.12.4/LICENSE.txt": "jquery-1.12.4/LICENSE.txt",
"jquery-2.0.0/jquery.js": "jquery-2.0.0/jquery.js", "jquery-2.0.0/jquery.js": "jquery-2.0.0/jquery.js",
"jquery-2.0.0/MIT-LICENSE.txt": "jquery-2.0.0/MIT-LICENSE.txt", "jquery-2.0.0/MIT-LICENSE.txt": "jquery-2.0.0/MIT-LICENSE.txt",
@ -359,7 +383,34 @@ grunt.initConfig({
"jquery-2.1.2/MIT-LICENSE.txt": "jquery-2.1.2/MIT-LICENSE.txt", "jquery-2.1.2/MIT-LICENSE.txt": "jquery-2.1.2/MIT-LICENSE.txt",
"jquery-2.1.3/jquery.js": "jquery-2.1.3/dist/jquery.js", "jquery-2.1.3/jquery.js": "jquery-2.1.3/dist/jquery.js",
"jquery-2.1.3/MIT-LICENSE.txt": "jquery-2.1.3/MIT-LICENSE.txt" "jquery-2.1.3/MIT-LICENSE.txt": "jquery-2.1.3/MIT-LICENSE.txt",
"jquery-2.1.4/jquery.js": "jquery-2.1.4/dist/jquery.js",
"jquery-2.1.4/MIT-LICENSE.txt": "jquery-2.1.4/MIT-LICENSE.txt",
"jquery-2.2.0/jquery.js": "jquery-2.2.0/dist/jquery.js",
"jquery-2.2.0/LICENSE.txt": "jquery-2.2.0/LICENSE.txt",
"jquery-2.2.1/jquery.js": "jquery-2.2.1/dist/jquery.js",
"jquery-2.2.1/LICENSE.txt": "jquery-2.2.1/LICENSE.txt",
"jquery-2.2.2/jquery.js": "jquery-2.2.2/dist/jquery.js",
"jquery-2.2.2/LICENSE.txt": "jquery-2.2.2/LICENSE.txt",
"jquery-2.2.3/jquery.js": "jquery-2.2.3/dist/jquery.js",
"jquery-2.2.3/LICENSE.txt": "jquery-2.2.3/LICENSE.txt",
"jquery-2.2.4/jquery.js": "jquery-2.2.4/dist/jquery.js",
"jquery-2.2.4/LICENSE.txt": "jquery-2.2.4/LICENSE.txt",
"jquery-3.0.0/jquery.js": "jquery-3.0.0/dist/jquery.js",
"jquery-3.0.0/LICENSE.txt": "jquery-3.0.0/LICENSE.txt",
"jquery-3.1.0/jquery.js": "jquery-3.1.0/dist/jquery.js",
"jquery-3.1.0/LICENSE.txt": "jquery-3.1.0/LICENSE.txt",
"jquery-3.1.1/jquery.js": "jquery-3.1.1/dist/jquery.js",
"jquery-3.1.1/LICENSE.txt": "jquery-3.1.1/LICENSE.txt"
} }
} }
}, },
@ -405,9 +456,7 @@ grunt.registerTask( "update-authors", function() {
} }
authors = authors.map(function( author ) { authors = authors.map(function( author ) {
if ( author.match( /^Dan Strohl </ ) ) { if ( author.match( /^Jacek Jędrzejewski </ ) ) {
return "Dan Strohl";
} else if ( author.match( /^Jacek Jędrzejewski </ ) ) {
return "Jacek Jędrzejewski (http://jacek.jedrzejewski.name)"; return "Jacek Jędrzejewski (http://jacek.jedrzejewski.name)";
} else if ( author.match( /^Pawel Maruszczyk </ ) ) { } else if ( author.match( /^Pawel Maruszczyk </ ) ) {
return "Pawel Maruszczyk (http://hrabstwo.net)"; return "Pawel Maruszczyk (http://hrabstwo.net)";

View File

@ -7,6 +7,7 @@
"external", "external",
"tests" "tests"
], ],
"license": "MIT",
"dependencies": { "dependencies": {
"jquery": ">=1.6" "jquery": ">=1.6"
}, },
@ -37,7 +38,12 @@
"jquery-1.11.1": "jquery#1.11.1", "jquery-1.11.1": "jquery#1.11.1",
"jquery-1.11.2": "jquery#1.11.2", "jquery-1.11.2": "jquery#1.11.2",
"jquery-1.11.3": "jquery#1.11.3", "jquery-1.11.3": "jquery#1.11.3",
"jquery-1.x": "jquery#1.11.3", "jquery-1.12.0": "jquery#1.12.0",
"jquery-1.12.1": "jquery#1.12.1",
"jquery-1.12.2": "jquery#1.12.2",
"jquery-1.12.3": "jquery#1.12.3",
"jquery-1.12.4": "jquery#1.12.4",
"jquery-1.x": "jquery#1.12.4",
"jquery-2.0.0": "jquery#2.0.0", "jquery-2.0.0": "jquery#2.0.0",
"jquery-2.0.1": "jquery#2.0.1", "jquery-2.0.1": "jquery#2.0.1",
"jquery-2.0.2": "jquery#2.0.2", "jquery-2.0.2": "jquery#2.0.2",
@ -45,6 +51,15 @@
"jquery-2.1.0": "jquery#2.1.0", "jquery-2.1.0": "jquery#2.1.0",
"jquery-2.1.1": "jquery#2.1.1", "jquery-2.1.1": "jquery#2.1.1",
"jquery-2.1.2": "jquery#2.1.2", "jquery-2.1.2": "jquery#2.1.2",
"jquery-2.1.3": "jquery#2.1.3" "jquery-2.1.3": "jquery#2.1.3",
"jquery-2.1.4": "jquery#2.1.4",
"jquery-2.2.0": "jquery#2.2.0",
"jquery-2.2.1": "jquery#2.2.1",
"jquery-2.2.2": "jquery#2.2.2",
"jquery-2.2.3": "jquery#2.2.3",
"jquery-2.2.4": "jquery#2.2.4",
"jquery-3.0.0": "jquery#3.0.0",
"jquery-3.1.0": "jquery#3.1.0",
"jquery-3.1.1": "jquery#3.1.1"
} }
} }

View File

@ -35,6 +35,14 @@ function replaceAtVersion() {
return matches; return matches;
} }
function removeExternals ( packager ) {
Object.keys( packager.builtFiles ).forEach( function( filepath ) {
if ( /^external\//.test( filepath ) ) {
delete packager.builtFiles[ filepath ];
}
} );
}
function addManifest( packager ) { function addManifest( packager ) {
var output = packager.builtFiles; var output = packager.builtFiles;
output.MANIFEST = Object.keys( output ).sort( function( a, b ) { output.MANIFEST = Object.keys( output ).sort( function( a, b ) {
@ -52,7 +60,8 @@ function buildCDNPackage( callback ) {
var Package = require( "download.jqueryui.com/lib/package-1-12-themes" ); var Package = require( "download.jqueryui.com/lib/package-1-12-themes" );
var Packager = require( "node-packager" ); var Packager = require( "node-packager" );
var jqueryUi = new JqueryUi( path.resolve( "." ) ); var jqueryUi = new JqueryUi( path.resolve( "." ) );
var target = fs.createWriteStream( "../" + jqueryUi.pkg.name + "-" + jqueryUi.pkg.version + "-cdn.zip" ); var target = fs.createWriteStream( "../" + jqueryUi.pkg.name + "-" + jqueryUi.pkg.version +
"-cdn.zip" );
var packager = new Packager( jqueryUi.files().cache, Package, { var packager = new Packager( jqueryUi.files().cache, Package, {
components: jqueryUi.components().map( function( component ) { components: jqueryUi.components().map( function( component ) {
return component.name; return component.name;
@ -61,6 +70,7 @@ function buildCDNPackage( callback ) {
themeVars: null themeVars: null
} ); } );
packager.ready.then( function() { packager.ready.then( function() {
removeExternals( packager );
addManifest( packager ); addManifest( packager );
packager.toZip( target, { packager.toZip( target, {
basedir: "" basedir: ""
@ -82,7 +92,8 @@ Release.define( {
"August", "September", "October", "November", "December" ], "August", "September", "October", "November", "December" ],
now = new Date(); now = new Date();
return "<script>{\n\t\"title\": \"jQuery UI " + Release.newVersion + " Changelog\"\n" + return "<script>{\n\t\"title\": \"jQuery UI " + Release.newVersion + " Changelog\"\n" +
"}</script>\n\nReleased on " + monthNames[ now.getMonth() ] + " " + now.getDate() + ", " + now.getFullYear() + "\n\n"; "}</script>\n\nReleased on " + monthNames[ now.getMonth() ] + " " + now.getDate() +
", " + now.getFullYear() + "\n\n";
}, },
generateArtifacts: function( fn ) { generateArtifacts: function( fn ) {
var files = replaceAtVersion(); var files = replaceAtVersion();

View File

@ -4,23 +4,32 @@ module.exports = function( grunt ) {
var versions = { var versions = {
"git": "git", "git": "git",
"1.11": "1.11.0 1.11.1 1.11.2 1.11.3", "3.1": "3.1.1",
"1.10": "1.10.0 1.10.2", "3.0": "3.0.0",
"1.9": "1.9.0 1.9.1", "2.2": "2.2.4",
"1.8": "1.8.0 1.8.1 1.8.2 1.8.3", "2.1": "2.1.4",
"1.7": "1.7.0 1.7.1 1.7.2" "2.0": "2.0.3",
"1.12": "1.12.4",
"1.11": "1.11.3",
"1.10": "1.10.2",
"1.9": "1.9.1",
"1.8": "1.8.3",
"1.7": "1.7.2"
}, },
tests = { tests = {
"Accordion": "accordion/accordion.html", "Accordion": "accordion/accordion.html",
"Autocomplete": "autocomplete/autocomplete.html", "Autocomplete": "autocomplete/autocomplete.html",
"Button": "button/button.html", "Button": "button/button.html",
"Calendar": "calendar/calendar.html", "Calendar": "calendar/calendar.html",
"Checkboxradio": "checkboxradio/checkboxradio.html",
"Controlgroup": "controlgroup/controlgroup.html",
"Core": "core/core.html", "Core": "core/core.html",
"Datepicker": "datepicker/datepicker.html", "Datepicker": "datepicker/datepicker.html",
"Dialog": "dialog/dialog.html", "Dialog": "dialog/dialog.html",
"Draggable": "draggable/draggable.html", "Draggable": "draggable/draggable.html",
"Droppable": "droppable/droppable.html", "Droppable": "droppable/droppable.html",
"Effects": "effects/effects.html", "Effects": "effects/effects.html",
"Form Reset Mixin": "form-reset-mixin/form-reset-mixin.html",
"Menu": "menu/menu.html", "Menu": "menu/menu.html",
"Position": "position/position.html", "Position": "position/position.html",
"Progressbar": "progressbar/progressbar.html", "Progressbar": "progressbar/progressbar.html",
@ -43,12 +52,6 @@ function submit( commit, runs, configFile, extra, done ) {
commitUrl = "https://github.com/jquery/jquery-ui/commit/" + commit; commitUrl = "https://github.com/jquery/jquery-ui/commit/" + commit;
if ( extra ) { if ( extra ) {
// jquery-git doesn't support IE 8.
if ( extra === "core git" ) {
browserSets = "jquery-ui-future";
}
extra = " (" + extra + ")"; extra = " (" + extra + ")";
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 997 B

After

Width:  |  Height:  |  Size: 965 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 81 B

After

Width:  |  Height:  |  Size: 68 B

View File

@ -17,7 +17,7 @@
return val.split( /,\s*/ ); return val.split( /,\s*/ );
} }
function extractLast( term ) { function extractLast( term ) {
return split( term ).pop(); return split( term ).pop();
} }
$( "#birds" ) $( "#birds" )

View File

@ -10,7 +10,6 @@
.ui-autocomplete-loading { .ui-autocomplete-loading {
background: white url("images/ui-anim_basic_16x16.gif") right center no-repeat; background: white url("images/ui-anim_basic_16x16.gif") right center no-repeat;
} }
#city { width: 25em; }
</style> </style>
<script src="../../external/requirejs/require.js"></script> <script src="../../external/requirejs/require.js"></script>
<script src="../bootstrap.js"> <script src="../bootstrap.js">
@ -19,24 +18,22 @@
$( "#log" ).scrollTop( 0 ); $( "#log" ).scrollTop( 0 );
} }
$( "#city" ).autocomplete({ $( "#birds" ).autocomplete({
source: function( request, response ) { source: function( request, response ) {
$.ajax( { $.ajax( {
url: "http://gd.geobytes.com/AutoCompleteCity", url: "search.php",
dataType: "jsonp", dataType: "jsonp",
data: { data: {
q: request.term term: request.term
}, },
success: function( data ) { success: function( data ) {
response( data );
// Handle 'no match' indicated by [ "" ] response
response( data.length === 1 && data[ 0 ].length === 0 ? [] : data );
} }
} ); } );
}, },
minLength: 3, minLength: 2,
select: function( event, ui ) { select: function( event, ui ) {
log( "Selected: " + ui.item.label ); log( "Selected: " + ui.item.value + " aka " + ui.item.id );
} }
} ); } );
</script> </script>
@ -44,9 +41,8 @@
<body> <body>
<div class="ui-widget"> <div class="ui-widget">
<label for="city">Your city: </label> <label for="birds">Birds: </label>
<input id="city" type="text"> <input id="birds">
Powered by <a href="http://geobytes.com">geobytes.com</a>
</div> </div>
<div class="ui-widget" style="margin-top:2em; font-family:Arial"> <div class="ui-widget" style="margin-top:2em; font-family:Arial">
@ -55,7 +51,8 @@
</div> </div>
<div class="demo-description"> <div class="demo-description">
<p>The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are cities, displayed when at least three characters are entered into the field. The datasource is the <a href="http://geobytes.com">geobytes.com webservice</a>. That data is also available in callbacks, as illustrated by the Result area below the input.</p> <p>The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are bird names, displayed when at least two characters are entered into the field.</p>
<p>The datasource is a server-side script which returns JSONP data, specified via a function which uses <code>jQuery.ajax()</code> for the <code>source</code> option.</p>
</div> </div>
</body> </body>
</html> </html>

View File

@ -22,9 +22,7 @@
source: "search.php", source: "search.php",
minLength: 2, minLength: 2,
select: function( event, ui ) { select: function( event, ui ) {
log( ui.item ? log( "Selected: " + ui.item.value + " aka " + ui.item.id );
"Selected: " + ui.item.value + " aka " + ui.item.id :
"Nothing selected, input was " + this.value );
} }
}); });
</script> </script>

View File

@ -1,6 +1,6 @@
<?php <?php
sleep( 3 ); sleep( 2 );
// no term passed - just exit early with no response // no term passed - just exit early with no response
if (empty($_GET['term'])) exit ; if (empty($_GET['term'])) exit ;
$q = strtolower($_GET["term"]); $q = strtolower($_GET["term"]);
@ -573,7 +573,6 @@ $items = array(
"Heuglin's Gull"=>"Larus heuglini" "Heuglin's Gull"=>"Larus heuglini"
); );
$result = array(); $result = array();
foreach ($items as $key=>$value) { foreach ($items as $key=>$value) {
if (strpos(strtolower($key), $q) !== false) { if (strpos(strtolower($key), $q) !== false) {
@ -584,6 +583,15 @@ foreach ($items as $key=>$value) {
} }
// json_encode is available in PHP 5.2 and above, or you can install a PECL module in earlier versions // json_encode is available in PHP 5.2 and above, or you can install a PECL module in earlier versions
echo json_encode($result); $output = json_encode($result);
?> if ($_GET["callback"]) {
// Escape special characters to avoid XSS attacks via direct loads of this
// page with a callback that contains HTML. This is a lot easier than validating
// the callback name.
$output = htmlspecialchars($_GET["callback"]) . "($output);";
}
echo $output;
?>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.7 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

@ -75,7 +75,7 @@
<input type="checkbox" name="insurance" id="insurance-v"> <input type="checkbox" name="insurance" id="insurance-v">
<label for="vertical-spinner" class="ui-controlgroup-label"># of cars</label> <label for="vertical-spinner" class="ui-controlgroup-label"># of cars</label>
<input id="vertical-spinner" class="ui-spinner-input"> <input id="vertical-spinner" class="ui-spinner-input">
<button>Book Now!</button> <button id="book">Book Now!</button>
</div> </div>
</fieldset> </fieldset>
</div> </div>

View File

@ -12,7 +12,7 @@
modal: true, modal: true,
buttons: { buttons: {
Ok: function() { Ok: function() {
$( this ).dialog( "close" ); $( this ).dialog( "close" );
} }
} }
}); });

Binary file not shown.

Before

Width:  |  Height:  |  Size: 681 B

After

Width:  |  Height:  |  Size: 395 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 594 B

After

Width:  |  Height:  |  Size: 387 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 649 B

After

Width:  |  Height:  |  Size: 487 B

View File

@ -0,0 +1,42 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Slider - Custom handle</title>
<link rel="stylesheet" href="../../themes/base/all.css">
<link rel="stylesheet" href="../demos.css">
<style>
#custom-handle {
width: 3em;
height: 1.6em;
top: 50%;
margin-top: -.8em;
text-align: center;
line-height: 1.6em;
}
</style>
<script src="../../external/requirejs/require.js"></script>
<script src="../bootstrap.js">
var handle = $( "#custom-handle" );
$( "#slider" ).slider({
create: function() {
handle.text( $( this ).slider( "value" ) );
},
slide: function( event, ui ) {
handle.text( ui.value );
}
});
</script>
</head>
<body>
<div id="slider">
<div id="custom-handle" class="ui-slider-handle"></div>
</div>
<div class="demo-description">
<p>The basic slider is horizontal and has a single handle that can be moved with the mouse or by using the arrow keys.</p>
</div>
</body>
</html>

View File

@ -18,6 +18,7 @@
<li><a href="range-vertical.html">Vertical range slider</a></li> <li><a href="range-vertical.html">Vertical range slider</a></li>
<li><a href="multiple-vertical.html">Multiple sliders</a></li> <li><a href="multiple-vertical.html">Multiple sliders</a></li>
<li><a href="colorpicker.html">Simple colorpicker</a></li> <li><a href="colorpicker.html">Simple colorpicker</a></li>
<li><a href="custom-handle.html">Custom handle</a></li>
</ul> </ul>
</body> </body>

View File

@ -9,10 +9,21 @@
<script src="../../external/requirejs/require.js"></script> <script src="../../external/requirejs/require.js"></script>
<script src="../bootstrap.js" data-modules="sortable"> <script src="../bootstrap.js" data-modules="sortable">
var tabs = $( "#tabs" ).tabs(); var tabs = $( "#tabs" ).tabs();
var previouslyFocused = false;
tabs.find( ".ui-tabs-nav" ).sortable({ tabs.find( ".ui-tabs-nav" ).sortable({
axis: "x", axis: "x",
stop: function() {
// Sortable removes focus, so we need to restore it if the tab was focused
// prior to sorting
start: function(event, ui) {
previouslyFocused = document.activeElement === ui.item[ 0 ];
},
stop: function(event, ui) {
tabs.tabs( "refresh" ); tabs.tabs( "refresh" );
if (previouslyFocused) {
ui.item.focus();
}
} }
}); });
</script> </script>

36
external/jquery-1.12.0/LICENSE.txt vendored Normal file
View File

@ -0,0 +1,36 @@
Copyright jQuery Foundation and other contributors, https://jquery.org/
This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at https://github.com/jquery/jquery
The following license applies to all parts of this software except as
documented below:
====
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
====
All files located in the node_modules and external directories are
externally maintained libraries used by this software which have their
own licenses; we recommend you read them, as their terms may differ from
the terms above.

11027
external/jquery-1.12.0/jquery.js vendored Normal file

File diff suppressed because it is too large Load Diff

36
external/jquery-1.12.1/LICENSE.txt vendored Normal file
View File

@ -0,0 +1,36 @@
Copyright jQuery Foundation and other contributors, https://jquery.org/
This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at https://github.com/jquery/jquery
The following license applies to all parts of this software except as
documented below:
====
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
====
All files located in the node_modules and external directories are
externally maintained libraries used by this software which have their
own licenses; we recommend you read them, as their terms may differ from
the terms above.

11026
external/jquery-1.12.1/jquery.js vendored Normal file

File diff suppressed because it is too large Load Diff

36
external/jquery-1.12.2/LICENSE.txt vendored Normal file
View File

@ -0,0 +1,36 @@
Copyright jQuery Foundation and other contributors, https://jquery.org/
This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at https://github.com/jquery/jquery
The following license applies to all parts of this software except as
documented below:
====
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
====
All files located in the node_modules and external directories are
externally maintained libraries used by this software which have their
own licenses; we recommend you read them, as their terms may differ from
the terms above.

11022
external/jquery-1.12.2/jquery.js vendored Normal file

File diff suppressed because it is too large Load Diff

36
external/jquery-1.12.3/LICENSE.txt vendored Normal file
View File

@ -0,0 +1,36 @@
Copyright jQuery Foundation and other contributors, https://jquery.org/
This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at https://github.com/jquery/jquery
The following license applies to all parts of this software except as
documented below:
====
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
====
All files located in the node_modules and external directories are
externally maintained libraries used by this software which have their
own licenses; we recommend you read them, as their terms may differ from
the terms above.

11015
external/jquery-1.12.3/jquery.js vendored Normal file

File diff suppressed because it is too large Load Diff

36
external/jquery-1.12.4/LICENSE.txt vendored Normal file
View File

@ -0,0 +1,36 @@
Copyright jQuery Foundation and other contributors, https://jquery.org/
This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at https://github.com/jquery/jquery
The following license applies to all parts of this software except as
documented below:
====
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
====
All files located in the node_modules and external directories are
externally maintained libraries used by this software which have their
own licenses; we recommend you read them, as their terms may differ from
the terms above.

11008
external/jquery-1.12.4/jquery.js vendored Normal file

File diff suppressed because it is too large Load Diff

21
external/jquery-2.1.4/MIT-LICENSE.txt vendored Normal file
View File

@ -0,0 +1,21 @@
Copyright 2014 jQuery Foundation and other contributors
http://jquery.com/
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

9210
external/jquery-2.1.4/jquery.js vendored Normal file

File diff suppressed because it is too large Load Diff

36
external/jquery-2.2.0/LICENSE.txt vendored Normal file
View File

@ -0,0 +1,36 @@
Copyright jQuery Foundation and other contributors, https://jquery.org/
This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at https://github.com/jquery/jquery
The following license applies to all parts of this software except as
documented below:
====
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
====
All files located in the node_modules and external directories are
externally maintained libraries used by this software which have their
own licenses; we recommend you read them, as their terms may differ from
the terms above.

9831
external/jquery-2.2.0/jquery.js vendored Normal file

File diff suppressed because it is too large Load Diff

36
external/jquery-2.2.1/LICENSE.txt vendored Normal file
View File

@ -0,0 +1,36 @@
Copyright jQuery Foundation and other contributors, https://jquery.org/
This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at https://github.com/jquery/jquery
The following license applies to all parts of this software except as
documented below:
====
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
====
All files located in the node_modules and external directories are
externally maintained libraries used by this software which have their
own licenses; we recommend you read them, as their terms may differ from
the terms above.

9831
external/jquery-2.2.1/jquery.js vendored Normal file

File diff suppressed because it is too large Load Diff

36
external/jquery-2.2.2/LICENSE.txt vendored Normal file
View File

@ -0,0 +1,36 @@
Copyright jQuery Foundation and other contributors, https://jquery.org/
This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at https://github.com/jquery/jquery
The following license applies to all parts of this software except as
documented below:
====
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
====
All files located in the node_modules and external directories are
externally maintained libraries used by this software which have their
own licenses; we recommend you read them, as their terms may differ from
the terms above.

9842
external/jquery-2.2.2/jquery.js vendored Normal file

File diff suppressed because it is too large Load Diff

36
external/jquery-2.2.3/LICENSE.txt vendored Normal file
View File

@ -0,0 +1,36 @@
Copyright jQuery Foundation and other contributors, https://jquery.org/
This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at https://github.com/jquery/jquery
The following license applies to all parts of this software except as
documented below:
====
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
====
All files located in the node_modules and external directories are
externally maintained libraries used by this software which have their
own licenses; we recommend you read them, as their terms may differ from
the terms above.

9842
external/jquery-2.2.3/jquery.js vendored Normal file

File diff suppressed because it is too large Load Diff

36
external/jquery-2.2.4/LICENSE.txt vendored Normal file
View File

@ -0,0 +1,36 @@
Copyright jQuery Foundation and other contributors, https://jquery.org/
This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at https://github.com/jquery/jquery
The following license applies to all parts of this software except as
documented below:
====
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
====
All files located in the node_modules and external directories are
externally maintained libraries used by this software which have their
own licenses; we recommend you read them, as their terms may differ from
the terms above.

9814
external/jquery-2.2.4/jquery.js vendored Normal file

File diff suppressed because it is too large Load Diff

36
external/jquery-3.0.0/LICENSE.txt vendored Normal file
View File

@ -0,0 +1,36 @@
Copyright jQuery Foundation and other contributors, https://jquery.org/
This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at https://github.com/jquery/jquery
The following license applies to all parts of this software except as
documented below:
====
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
====
All files located in the node_modules and external directories are
externally maintained libraries used by this software which have their
own licenses; we recommend you read them, as their terms may differ from
the terms above.

10037
external/jquery-3.0.0/jquery.js vendored Normal file

File diff suppressed because it is too large Load Diff

36
external/jquery-3.1.0/LICENSE.txt vendored Normal file
View File

@ -0,0 +1,36 @@
Copyright jQuery Foundation and other contributors, https://jquery.org/
This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at https://github.com/jquery/jquery
The following license applies to all parts of this software except as
documented below:
====
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
====
All files located in the node_modules and external directories are
externally maintained libraries used by this software which have their
own licenses; we recommend you read them, as their terms may differ from
the terms above.

10074
external/jquery-3.1.0/jquery.js vendored Normal file

File diff suppressed because it is too large Load Diff

36
external/jquery-3.1.1/LICENSE.txt vendored Normal file
View File

@ -0,0 +1,36 @@
Copyright jQuery Foundation and other contributors, https://jquery.org/
This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at https://github.com/jquery/jquery
The following license applies to all parts of this software except as
documented below:
====
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
====
All files located in the node_modules and external directories are
externally maintained libraries used by this software which have their
own licenses; we recommend you read them, as their terms may differ from
the terms above.

10220
external/jquery-3.1.1/jquery.js vendored Normal file

File diff suppressed because it is too large Load Diff

36
external/jquery/LICENSE.txt vendored Normal file
View File

@ -0,0 +1,36 @@
Copyright jQuery Foundation and other contributors, https://jquery.org/
This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at https://github.com/jquery/jquery
The following license applies to all parts of this software except as
documented below:
====
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
====
All files located in the node_modules and external directories are
externally maintained libraries used by this software which have their
own licenses; we recommend you read them, as their terms may differ from
the terms above.

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
"name": "jquery-ui", "name": "jquery-ui",
"title": "jQuery UI", "title": "jQuery UI",
"description": "A curated set of user interface interactions, effects, widgets, and themes built on top of the jQuery JavaScript Library.", "description": "A curated set of user interface interactions, effects, widgets, and themes built on top of the jQuery JavaScript Library.",
"version": "1.12.0-pre", "version": "1.12.2-pre",
"homepage": "http://jqueryui.com", "homepage": "http://jqueryui.com",
"author": { "author": {
"name": "jQuery Foundation and other contributors", "name": "jQuery Foundation and other contributors",
@ -57,6 +57,7 @@
"globalize-compiler": "0.2.0", "globalize-compiler": "0.2.0",
"grunt": "0.4.5", "grunt": "0.4.5",
"grunt-bowercopy": "1.2.4", "grunt-bowercopy": "1.2.4",
"grunt-cli": "0.1.13",
"grunt-compare-size": "0.4.0", "grunt-compare-size": "0.4.0",
"grunt-contrib-concat": "0.5.1", "grunt-contrib-concat": "0.5.1",
"grunt-contrib-csslint": "0.5.0", "grunt-contrib-csslint": "0.5.0",

View File

@ -18,24 +18,11 @@
"jquery": true, "jquery": true,
"globals": { "globals": {
"asyncTest": false,
"deepEqual": false,
"define": false, "define": false,
"equal": false,
"expect": false,
"Globalize": false, "Globalize": false,
"module": false, "QUnit": false,
"notEqual": false,
"notDeepEqual": false,
"notStrictEqual": false,
"ok": false,
"QUnit": true,
"require": true, "require": true,
"requirejs": true, "requirejs": true,
"start": false,
"strictEqual": false,
"stop": false,
"test": false,
"JSHINT": false "JSHINT": false
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -105,7 +105,7 @@ function jqueryUrl() {
if ( version === "git" ) { if ( version === "git" ) {
url = "http://code.jquery.com/jquery-" + version; url = "http://code.jquery.com/jquery-" + version;
} else { } else {
url = "../../../external/jquery-" + ( version || "1.11.3" ) + "/jquery"; url = "../../../external/jquery-" + ( version || "1.12.4" ) + "/jquery";
} }
return url; return url;

View File

@ -1,6 +1,7 @@
define( [ define( [
"jquery" "qunit",
], function( $ ) { "jquery" ],
function( QUnit, $ ) {
var exports = {}; var exports = {};
@ -8,39 +9,39 @@ function testWidgetDefaults( widget, defaults ) {
var pluginDefaults = $.ui[ widget ].prototype.options; var pluginDefaults = $.ui[ widget ].prototype.options;
// Ensure that all defaults have the correct value // Ensure that all defaults have the correct value
test( "defined defaults", function() { QUnit.test( "defined defaults", function( assert ) {
var count = 0; var count = 0;
$.each( defaults, function( key, val ) { $.each( defaults, function( key, val ) {
expect( ++count ); assert.expect( ++count );
if ( $.isFunction( val ) ) { if ( $.isFunction( val ) ) {
ok( $.isFunction( pluginDefaults[ key ] ), key ); assert.ok( $.isFunction( pluginDefaults[ key ] ), key );
return; return;
} }
deepEqual( pluginDefaults[ key ], val, key ); assert.deepEqual( pluginDefaults[ key ], val, key );
} ); } );
} ); } );
// Ensure that all defaults were tested // Ensure that all defaults were tested
test( "tested defaults", function() { QUnit.test( "tested defaults", function( assert ) {
var count = 0; var count = 0;
$.each( pluginDefaults, function( key ) { $.each( pluginDefaults, function( key ) {
expect( ++count ); assert.expect( ++count );
ok( key in defaults, key ); assert.ok( key in defaults, key );
} ); } );
} ); } );
} }
function testWidgetOverrides( widget ) { function testWidgetOverrides( widget ) {
if ( $.uiBackCompat === false ) { if ( $.uiBackCompat === false ) {
test( "$.widget overrides", function() { QUnit.test( "$.widget overrides", function( assert ) {
expect( 4 ); assert.expect( 4 );
$.each( [ $.each( [
"_createWidget", "_createWidget",
"destroy", "destroy",
"option", "option",
"_trigger" "_trigger"
], function( i, method ) { ], function( i, method ) {
strictEqual( $.ui[ widget ].prototype[ method ], assert.strictEqual( $.ui[ widget ].prototype[ method ],
$.Widget.prototype[ method ], "should not override " + method ); $.Widget.prototype[ method ], "should not override " + method );
} ); } );
} ); } );
@ -48,24 +49,24 @@ function testWidgetOverrides( widget ) {
} }
function testBasicUsage( widget ) { function testBasicUsage( widget ) {
test( "basic usage", function() { QUnit.test( "basic usage", function( assert ) {
expect( 3 ); assert.expect( 3 );
var defaultElement = $.ui[ widget ].prototype.defaultElement; var defaultElement = $.ui[ widget ].prototype.defaultElement;
$( defaultElement ).appendTo( "body" )[ widget ]().remove(); $( defaultElement ).appendTo( "body" )[ widget ]().remove();
ok( true, "initialized on element" ); assert.ok( true, "initialized on element" );
$( defaultElement )[ widget ]().remove(); $( defaultElement )[ widget ]().remove();
ok( true, "initialized on disconnected DOMElement - never connected" ); assert.ok( true, "initialized on disconnected DOMElement - never connected" );
// Ensure manipulating removed elements works (#3664) // Ensure manipulating removed elements works (#3664)
$( defaultElement ).appendTo( "body" ).remove()[ widget ]().remove(); $( defaultElement ).appendTo( "body" ).remove()[ widget ]().remove();
ok( true, "initialized on disconnected DOMElement - removed" ); assert.ok( true, "initialized on disconnected DOMElement - removed" );
} ); } );
} }
exports.testWidget = function( widget, settings ) { exports.testWidget = function( widget, settings ) {
module( widget + ": common widget" ); QUnit.module( widget + ": common widget" );
exports.testJshint( "/widgets/" + widget ); exports.testJshint( "/widgets/" + widget );
testWidgetDefaults( widget, settings.defaults ); testWidgetDefaults( widget, settings.defaults );
@ -73,9 +74,9 @@ exports.testWidget = function( widget, settings ) {
if ( !settings.noDefaultElement ) { if ( !settings.noDefaultElement ) {
testBasicUsage( widget ); testBasicUsage( widget );
} }
test( "version", function() { QUnit.test( "version", function( assert ) {
expect( 1 ); assert.expect( 1 );
ok( "version" in $.ui[ widget ].prototype, "version property exists" ); assert.ok( "version" in $.ui[ widget ].prototype, "version property exists" );
} ); } );
}; };
@ -87,9 +88,10 @@ exports.testJshint = function( module ) {
return; return;
} }
asyncTest( "JSHint", function() { QUnit.test( "JSHint", function( assert ) {
var ready = assert.async();
require( [ "jshint" ], function() { require( [ "jshint" ], function() {
expect( 1 ); assert.expect( 1 );
$.when( $.when(
$.ajax( { $.ajax( {
@ -119,12 +121,12 @@ exports.testJshint = function( module ) {
return "[L" + error.line + ":C" + error.character + "] " + return "[L" + error.line + ":C" + error.character + "] " +
error.reason + "\n" + error.evidence + "\n"; error.reason + "\n" + error.evidence + "\n";
} ).join( "\n" ); } ).join( "\n" );
ok( passed, errors ); assert.ok( passed, errors );
start(); ready();
} ) } )
.fail( function( hintError, srcError ) { .fail( function( hintError, srcError ) {
ok( false, "error loading source: " + ( hintError || srcError ).statusText ); assert.ok( false, "error loading source: " + ( hintError || srcError ).statusText );
start(); ready();
} ); } );
} ); } );
} ); } );

View File

@ -99,11 +99,11 @@ function extract( selector, message ) {
var children; var children;
$.each( domEqual.properties, function( index, attr ) { $.each( domEqual.properties, function( index, attr ) {
var value = elem.prop( attr ); var value = elem.prop( attr );
result[ attr ] = value != null ? value : ""; result[ attr ] = value != null ? value : "";
} ); } );
$.each( domEqual.attributes, function( index, attr ) { $.each( domEqual.attributes, function( index, attr ) {
var value = elem.attr( attr ); var value = elem.attr( attr );
result[ attr ] = value != null ? value : ""; result[ attr ] = value != null ? value : "";
} ); } );
result.style = getElementStyles( elem[ 0 ] ); result.style = getElementStyles( elem[ 0 ] );
result.events = $._data( elem[ 0 ], "events" ); result.events = $._data( elem[ 0 ], "events" );

View File

@ -26,8 +26,12 @@ QUnit.config.urlConfig.push( {
"1.9.0", "1.9.1", "1.9.0", "1.9.1",
"1.10.0", "1.10.1", "1.10.2", "1.10.0", "1.10.1", "1.10.2",
"1.11.0", "1.11.1", "1.11.2", "1.11.3", "1.11.0", "1.11.1", "1.11.2", "1.11.3",
"1.12.0", "1.12.1", "1.12.2", "1.12.3", "1.12.4",
"2.0.0", "2.0.1", "2.0.2", "2.0.3", "2.0.0", "2.0.1", "2.0.2", "2.0.3",
"2.1.0", "2.1.1", "2.1.2", "2.1.3", "2.1.0", "2.1.1", "2.1.2", "2.1.3", "2.1.4",
"2.2.0", "2.2.1", "2.2.2", "2.2.3", "2.2.4",
"3.0.0",
"3.1.0", "3.1.1",
"git", "custom" "git", "custom"
], ],
tooltip: "Which jQuery Core version to test against" tooltip: "Which jQuery Core version to test against"

View File

@ -1,129 +1,131 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"./helper", "./helper",
"ui/widgets/accordion" "ui/widgets/accordion"
], function( $, testHelper ) { ], function( QUnit, $, testHelper ) {
var setupTeardown = testHelper.setupTeardown, var setupTeardown = testHelper.setupTeardown,
state = testHelper.state; state = testHelper.state;
module( "accordion: core", setupTeardown() ); QUnit.module( "accordion: core", setupTeardown() );
$.each( { div: "#list1", ul: "#navigation", dl: "#accordion-dl" }, function( type, selector ) { $.each( { div: "#list1", ul: "#navigation", dl: "#accordion-dl" }, function( type, selector ) {
test( "markup structure: " + type, function( assert ) { QUnit.test( "markup structure: " + type, function( assert ) {
expect( 10 ); assert.expect( 10 );
var element = $( selector ).accordion(), var element = $( selector ).accordion(),
headers = element.find( ".ui-accordion-header" ), headers = element.find( ".ui-accordion-header" ),
content = headers.next(); content = headers.next();
assert.hasClasses( element, "ui-accordion ui-widget" ); assert.hasClasses( element, "ui-accordion ui-widget" );
equal( headers.length, 3, ".ui-accordion-header elements exist, correct number" ); assert.equal( headers.length, 3, ".ui-accordion-header elements exist, correct number" );
assert.hasClasses( headers[ 0 ], assert.hasClasses( headers[ 0 ],
"ui-accordion-header ui-accordion-header-active ui-accordion-icons" ); "ui-accordion-header ui-accordion-header-active ui-accordion-icons" );
assert.hasClasses( headers[ 1 ], assert.hasClasses( headers[ 1 ],
"ui-accordion-header ui-accordion-header-collapsed ui-accordion-icons" ); "ui-accordion-header ui-accordion-header-collapsed ui-accordion-icons" );
assert.hasClasses( headers[ 2 ], assert.hasClasses( headers[ 2 ],
"ui-accordion-header ui-accordion-header-collapsed ui-accordion-icons" ); "ui-accordion-header ui-accordion-header-collapsed ui-accordion-icons" );
equal( content.length, 3, ".ui-accordion-content elements exist, correct number" ); assert.equal( content.length, 3, ".ui-accordion-content elements exist, correct number" );
assert.hasClasses( content[ 0 ], assert.hasClasses( content[ 0 ],
"ui-accordion-content ui-widget-content ui-accordion-content-active" ); "ui-accordion-content ui-widget-content ui-accordion-content-active" );
assert.hasClasses( content[ 1 ], "ui-accordion-content ui-widget-content" ); assert.hasClasses( content[ 1 ], "ui-accordion-content ui-widget-content" );
assert.hasClasses( content[ 2 ], "ui-accordion-content ui-widget-content" ); assert.hasClasses( content[ 2 ], "ui-accordion-content ui-widget-content" );
deepEqual( element.find( ".ui-accordion-header" ).next().get(), assert.deepEqual( element.find( ".ui-accordion-header" ).next().get(),
element.find( ".ui-accordion-content" ).get(), element.find( ".ui-accordion-content" ).get(),
"content panels come immediately after headers" ); "content panels come immediately after headers" );
} ); } );
} ); } );
test( "handle click on header-descendant", function() { QUnit.test( "handle click on header-descendant", function( assert ) {
expect( 1 ); assert.expect( 1 );
var element = $( "#navigation" ).accordion(); var element = $( "#navigation" ).accordion();
$( "#navigation h2:eq(1) a" ).trigger( "click" ); $( "#navigation h2:eq(1) a" ).trigger( "click" );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
} ); } );
test( "accessibility", function() { QUnit.test( "accessibility", function( assert ) {
expect( 61 ); assert.expect( 61 );
var element = $( "#list1" ).accordion( { var element = $( "#list1" ).accordion( {
active: 1, active: 1,
collapsible: true collapsible: true
} ), } ),
headers = element.find( ".ui-accordion-header" ); headers = element.find( ".ui-accordion-header" );
equal( element.attr( "role" ), "tablist", "element role" ); assert.equal( element.attr( "role" ), "tablist", "element role" );
headers.each( function( i ) { headers.each( function( i ) {
var header = headers.eq( i ), var header = headers.eq( i ),
panel = header.next(); panel = header.next();
equal( header.attr( "role" ), "tab", "header " + i + " role" ); assert.equal( header.attr( "role" ), "tab", "header " + i + " role" );
equal( header.attr( "aria-controls" ), panel.attr( "id" ), "header " + i + " aria-controls" ); assert.equal( header.attr( "aria-controls" ), panel.attr( "id" ), "header " + i + " aria-controls" );
equal( panel.attr( "role" ), "tabpanel", "panel " + i + " role" ); assert.equal( panel.attr( "role" ), "tabpanel", "panel " + i + " role" );
equal( panel.attr( "aria-labelledby" ), header.attr( "id" ), "panel " + i + " aria-labelledby" ); assert.equal( panel.attr( "aria-labelledby" ), header.attr( "id" ), "panel " + i + " aria-labelledby" );
} ); } );
equal( headers.eq( 1 ).attr( "tabindex" ), 0, "active header has tabindex=0" ); assert.equal( headers.eq( 1 ).attr( "tabindex" ), 0, "active header has tabindex=0" );
equal( headers.eq( 1 ).attr( "aria-selected" ), "true", "active tab (1) has aria-selected=true" ); assert.equal( headers.eq( 1 ).attr( "aria-selected" ), "true", "active tab (1) has aria-selected=true" );
equal( headers.eq( 1 ).attr( "aria-expanded" ), "true", "active tab (1) has aria-expanded=true" ); assert.equal( headers.eq( 1 ).attr( "aria-expanded" ), "true", "active tab (1) has aria-expanded=true" );
equal( headers.eq( 1 ).next().attr( "aria-hidden" ), "false", "active tabpanel (1) has aria-hidden=false" ); assert.equal( headers.eq( 1 ).next().attr( "aria-hidden" ), "false", "active tabpanel (1) has aria-hidden=false" );
equal( headers.eq( 0 ).attr( "tabindex" ), -1, "inactive header (0) has tabindex=-1" ); assert.equal( headers.eq( 0 ).attr( "tabindex" ), -1, "inactive header (0) has tabindex=-1" );
equal( headers.eq( 0 ).attr( "aria-selected" ), "false", "inactive tab (0) has aria-selected=false" ); assert.equal( headers.eq( 0 ).attr( "aria-selected" ), "false", "inactive tab (0) has aria-selected=false" );
equal( headers.eq( 0 ).attr( "aria-expanded" ), "false", "inactive tab (0) has aria-expanded=false" ); assert.equal( headers.eq( 0 ).attr( "aria-expanded" ), "false", "inactive tab (0) has aria-expanded=false" );
equal( headers.eq( 0 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (0) has aria-hidden=true" ); assert.equal( headers.eq( 0 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (0) has aria-hidden=true" );
equal( headers.eq( 2 ).attr( "tabindex" ), -1, "inactive header (2) has tabindex=-1" ); assert.equal( headers.eq( 2 ).attr( "tabindex" ), -1, "inactive header (2) has tabindex=-1" );
equal( headers.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab (2) has aria-selected=false" ); assert.equal( headers.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab (2) has aria-selected=false" );
equal( headers.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab (2) has aria-expanded=false" ); assert.equal( headers.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab (2) has aria-expanded=false" );
equal( headers.eq( 2 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (2) has aria-hidden=true" ); assert.equal( headers.eq( 2 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (2) has aria-hidden=true" );
element.accordion( "option", "active", 0 ); element.accordion( "option", "active", 0 );
equal( headers.eq( 0 ).attr( "tabindex" ), 0, "active header (0) has tabindex=0" ); assert.equal( headers.eq( 0 ).attr( "tabindex" ), 0, "active header (0) has tabindex=0" );
equal( headers.eq( 0 ).attr( "aria-selected" ), "true", "active tab (0) has aria-selected=true" ); assert.equal( headers.eq( 0 ).attr( "aria-selected" ), "true", "active tab (0) has aria-selected=true" );
equal( headers.eq( 0 ).attr( "aria-expanded" ), "true", "active tab (0) has aria-expanded=true" ); assert.equal( headers.eq( 0 ).attr( "aria-expanded" ), "true", "active tab (0) has aria-expanded=true" );
equal( headers.eq( 0 ).next().attr( "aria-hidden" ), "false", "active tabpanel (0) has aria-hidden=false" ); assert.equal( headers.eq( 0 ).next().attr( "aria-hidden" ), "false", "active tabpanel (0) has aria-hidden=false" );
equal( headers.eq( 1 ).attr( "tabindex" ), -1, "inactive header (1) has tabindex=-1" ); assert.equal( headers.eq( 1 ).attr( "tabindex" ), -1, "inactive header (1) has tabindex=-1" );
equal( headers.eq( 1 ).attr( "aria-selected" ), "false", "inactive tab (1) has aria-selected=false" ); assert.equal( headers.eq( 1 ).attr( "aria-selected" ), "false", "inactive tab (1) has aria-selected=false" );
equal( headers.eq( 1 ).attr( "aria-expanded" ), "false", "inactive tab (1) has aria-expanded=false" ); assert.equal( headers.eq( 1 ).attr( "aria-expanded" ), "false", "inactive tab (1) has aria-expanded=false" );
equal( headers.eq( 1 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (1) has aria-hidden=true" ); assert.equal( headers.eq( 1 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (1) has aria-hidden=true" );
equal( headers.eq( 2 ).attr( "tabindex" ), -1, "inactive header (2) has tabindex=-1" ); assert.equal( headers.eq( 2 ).attr( "tabindex" ), -1, "inactive header (2) has tabindex=-1" );
equal( headers.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab (2) has aria-selected=false" ); assert.equal( headers.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab (2) has aria-selected=false" );
equal( headers.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab (2) has aria-expanded=false" ); assert.equal( headers.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab (2) has aria-expanded=false" );
equal( headers.eq( 2 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (2) has aria-hidden=true" ); assert.equal( headers.eq( 2 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (2) has aria-hidden=true" );
element.accordion( "option", "active", false ); element.accordion( "option", "active", false );
equal( headers.eq( 0 ).attr( "tabindex" ), 0, "previously active header (0) has tabindex=0" ); assert.equal( headers.eq( 0 ).attr( "tabindex" ), 0, "previously active header (0) has tabindex=0" );
equal( headers.eq( 0 ).attr( "aria-selected" ), "false", "inactive tab (0) has aria-selected=false" ); assert.equal( headers.eq( 0 ).attr( "aria-selected" ), "false", "inactive tab (0) has aria-selected=false" );
equal( headers.eq( 0 ).attr( "aria-expanded" ), "false", "inactive tab (0) has aria-expanded=false" ); assert.equal( headers.eq( 0 ).attr( "aria-expanded" ), "false", "inactive tab (0) has aria-expanded=false" );
equal( headers.eq( 0 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (0) has aria-hidden=true" ); assert.equal( headers.eq( 0 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (0) has aria-hidden=true" );
equal( headers.eq( 1 ).attr( "tabindex" ), -1, "inactive header (1) has tabindex=-1" ); assert.equal( headers.eq( 1 ).attr( "tabindex" ), -1, "inactive header (1) has tabindex=-1" );
equal( headers.eq( 1 ).attr( "aria-selected" ), "false", "inactive tab (1) has aria-selected=false" ); assert.equal( headers.eq( 1 ).attr( "aria-selected" ), "false", "inactive tab (1) has aria-selected=false" );
equal( headers.eq( 1 ).attr( "aria-expanded" ), "false", "inactive tab (1) has aria-expanded=false" ); assert.equal( headers.eq( 1 ).attr( "aria-expanded" ), "false", "inactive tab (1) has aria-expanded=false" );
equal( headers.eq( 1 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (1) has aria-hidden=true" ); assert.equal( headers.eq( 1 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (1) has aria-hidden=true" );
equal( headers.eq( 2 ).attr( "tabindex" ), -1, "inactive header (2) has tabindex=-1" ); assert.equal( headers.eq( 2 ).attr( "tabindex" ), -1, "inactive header (2) has tabindex=-1" );
equal( headers.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab (2) has aria-selected=false" ); assert.equal( headers.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab (2) has aria-selected=false" );
equal( headers.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab (2) has aria-expanded=false" ); assert.equal( headers.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab (2) has aria-expanded=false" );
equal( headers.eq( 2 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (2) has aria-hidden=true" ); assert.equal( headers.eq( 2 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (2) has aria-hidden=true" );
element.accordion( "option", "active", 1 ); element.accordion( "option", "active", 1 );
equal( headers.eq( 1 ).attr( "tabindex" ), 0, "active header has tabindex=0" ); assert.equal( headers.eq( 1 ).attr( "tabindex" ), 0, "active header has tabindex=0" );
equal( headers.eq( 1 ).attr( "aria-selected" ), "true", "active tab (1) has aria-selected=true" ); assert.equal( headers.eq( 1 ).attr( "aria-selected" ), "true", "active tab (1) has aria-selected=true" );
equal( headers.eq( 1 ).attr( "aria-expanded" ), "true", "active tab (1) has aria-expanded=true" ); assert.equal( headers.eq( 1 ).attr( "aria-expanded" ), "true", "active tab (1) has aria-expanded=true" );
equal( headers.eq( 1 ).next().attr( "aria-hidden" ), "false", "active tabpanel (1) has aria-hidden=false" ); assert.equal( headers.eq( 1 ).next().attr( "aria-hidden" ), "false", "active tabpanel (1) has aria-hidden=false" );
equal( headers.eq( 0 ).attr( "tabindex" ), -1, "inactive header (0) has tabindex=-1" ); assert.equal( headers.eq( 0 ).attr( "tabindex" ), -1, "inactive header (0) has tabindex=-1" );
equal( headers.eq( 0 ).attr( "aria-selected" ), "false", "inactive tab (0) has aria-selected=false" ); assert.equal( headers.eq( 0 ).attr( "aria-selected" ), "false", "inactive tab (0) has aria-selected=false" );
equal( headers.eq( 0 ).attr( "aria-expanded" ), "false", "inactive tab (0) has aria-expanded=false" ); assert.equal( headers.eq( 0 ).attr( "aria-expanded" ), "false", "inactive tab (0) has aria-expanded=false" );
equal( headers.eq( 0 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (0) has aria-hidden=true" ); assert.equal( headers.eq( 0 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (0) has aria-hidden=true" );
equal( headers.eq( 2 ).attr( "tabindex" ), -1, "inactive header (2) has tabindex=-1" ); assert.equal( headers.eq( 2 ).attr( "tabindex" ), -1, "inactive header (2) has tabindex=-1" );
equal( headers.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab (2) has aria-selected=false" ); assert.equal( headers.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab (2) has aria-selected=false" );
equal( headers.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab (2) has aria-expanded=false" ); assert.equal( headers.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab (2) has aria-expanded=false" );
equal( headers.eq( 2 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (2) has aria-hidden=true" ); assert.equal( headers.eq( 2 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (2) has aria-hidden=true" );
} ); } );
asyncTest( "keyboard support", function( assert ) { QUnit.test( "keyboard support", function( assert ) {
expect( 13 ); var ready = assert.async();
assert.expect( 13 );
var element = $( "#list1" ).accordion(), var element = $( "#list1" ).accordion(),
headers = element.find( ".ui-accordion-header" ), headers = element.find( ".ui-accordion-header" ),
anchor = headers.eq( 1 ).next().find( "a" ).eq( 0 ), anchor = headers.eq( 1 ).next().find( "a" ).eq( 0 ),
keyCode = $.ui.keyCode; keyCode = $.ui.keyCode;
equal( headers.filter( ".ui-state-focus" ).length, 0, "no headers focused on init" ); assert.equal( headers.filter( ".ui-state-focus" ).length, 0, "no headers focused on init" );
headers.eq( 0 ).simulate( "focus" ); headers.eq( 0 ).simulate( "focus" );
setTimeout( step1 ); setTimeout( step1 );
@ -180,13 +182,13 @@ asyncTest( "keyboard support", function( assert ) {
} }
function step9() { function step9() {
equal( element.accordion( "option", "active" ), 2, "ENTER activates panel" ); assert.equal( element.accordion( "option", "active" ), 2, "ENTER activates panel" );
headers.eq( 1 ).simulate( "keydown", { keyCode: keyCode.SPACE } ); headers.eq( 1 ).simulate( "keydown", { keyCode: keyCode.SPACE } );
setTimeout( step10 ); setTimeout( step10 );
} }
function step10() { function step10() {
equal( element.accordion( "option", "active" ), 1, "SPACE activates panel" ); assert.equal( element.accordion( "option", "active" ), 1, "SPACE activates panel" );
anchor.simulate( "focus" ); anchor.simulate( "focus" );
setTimeout( step11 ); setTimeout( step11 );
} }
@ -200,7 +202,7 @@ asyncTest( "keyboard support", function( assert ) {
function step12() { function step12() {
assert.hasClasses( headers.eq( 1 ), "ui-state-focus", "CTRL+UP moves focus to header" ); assert.hasClasses( headers.eq( 1 ), "ui-state-focus", "CTRL+UP moves focus to header" );
start(); ready();
} }
} ); } );

View File

@ -1,16 +1,17 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"./helper", "./helper",
"ui/widgets/accordion" "ui/widgets/accordion"
], function( $, testHelper ) { ], function( QUnit, $, testHelper ) {
var setupTeardown = testHelper.setupTeardown, var setupTeardown = testHelper.setupTeardown,
state = testHelper.state; state = testHelper.state;
module( "accordion: events", setupTeardown() ); QUnit.module( "accordion: events", setupTeardown() );
test( "create", function() { QUnit.test( "create", function( assert ) {
expect( 10 ); assert.expect( 10 );
var element = $( "#list1" ), var element = $( "#list1" ),
headers = element.children( "h3" ), headers = element.children( "h3" ),
@ -18,10 +19,10 @@ test( "create", function() {
element.accordion( { element.accordion( {
create: function( event, ui ) { create: function( event, ui ) {
equal( ui.header.length, 1, "header length" ); assert.equal( ui.header.length, 1, "header length" );
strictEqual( ui.header[ 0 ], headers[ 0 ], "header" ); assert.strictEqual( ui.header[ 0 ], headers[ 0 ], "header" );
equal( ui.panel.length, 1, "panel length" ); assert.equal( ui.panel.length, 1, "panel length" );
strictEqual( ui.panel[ 0 ], contents[ 0 ], "panel" ); assert.strictEqual( ui.panel[ 0 ], contents[ 0 ], "panel" );
} }
} ); } );
element.accordion( "destroy" ); element.accordion( "destroy" );
@ -29,10 +30,10 @@ test( "create", function() {
element.accordion( { element.accordion( {
active: 2, active: 2,
create: function( event, ui ) { create: function( event, ui ) {
equal( ui.header.length, 1, "header length" ); assert.equal( ui.header.length, 1, "header length" );
strictEqual( ui.header[ 0 ], headers[ 2 ], "header" ); assert.strictEqual( ui.header[ 0 ], headers[ 2 ], "header" );
equal( ui.panel.length, 1, "panel length" ); assert.equal( ui.panel.length, 1, "panel length" );
strictEqual( ui.panel[ 0 ], contents[ 2 ], "panel" ); assert.strictEqual( ui.panel[ 0 ], contents[ 2 ], "panel" );
} }
} ); } );
element.accordion( "destroy" ); element.accordion( "destroy" );
@ -41,15 +42,15 @@ test( "create", function() {
active: false, active: false,
collapsible: true, collapsible: true,
create: function( event, ui ) { create: function( event, ui ) {
equal( ui.header.length, 0, "header length" ); assert.equal( ui.header.length, 0, "header length" );
equal( ui.panel.length, 0, "panel length" ); assert.equal( ui.panel.length, 0, "panel length" );
} }
} ); } );
element.accordion( "destroy" ); element.accordion( "destroy" );
} ); } );
test( "beforeActivate", function() { QUnit.test( "beforeActivate", function( assert ) {
expect( 38 ); assert.expect( 38 );
var element = $( "#list1" ).accordion( { var element = $( "#list1" ).accordion( {
active: false, active: false,
collapsible: true collapsible: true
@ -58,63 +59,63 @@ test( "beforeActivate", function() {
content = element.find( ".ui-accordion-content" ); content = element.find( ".ui-accordion-content" );
element.one( "accordionbeforeactivate", function( event, ui ) { element.one( "accordionbeforeactivate", function( event, ui ) {
ok( !( "originalEvent" in event ) ); assert.ok( !( "originalEvent" in event ) );
equal( ui.oldHeader.length, 0 ); assert.equal( ui.oldHeader.length, 0 );
equal( ui.oldPanel.length, 0 ); assert.equal( ui.oldPanel.length, 0 );
equal( ui.newHeader.length, 1 ); assert.equal( ui.newHeader.length, 1 );
strictEqual( ui.newHeader[ 0 ], headers[ 0 ] ); assert.strictEqual( ui.newHeader[ 0 ], headers[ 0 ] );
equal( ui.newPanel.length, 1 ); assert.equal( ui.newPanel.length, 1 );
strictEqual( ui.newPanel[ 0 ], content[ 0 ] ); assert.strictEqual( ui.newPanel[ 0 ], content[ 0 ] );
state( element, 0, 0, 0 ); state( assert, element, 0, 0, 0 );
} ); } );
element.accordion( "option", "active", 0 ); element.accordion( "option", "active", 0 );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
element.one( "accordionbeforeactivate", function( event, ui ) { element.one( "accordionbeforeactivate", function( event, ui ) {
equal( event.originalEvent.type, "click" ); assert.equal( event.originalEvent.type, "click" );
equal( ui.oldHeader.length, 1 ); assert.equal( ui.oldHeader.length, 1 );
strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] ); assert.strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] );
equal( ui.oldPanel.length, 1 ); assert.equal( ui.oldPanel.length, 1 );
strictEqual( ui.oldPanel[ 0 ], content[ 0 ] ); assert.strictEqual( ui.oldPanel[ 0 ], content[ 0 ] );
equal( ui.newHeader.length, 1 ); assert.equal( ui.newHeader.length, 1 );
strictEqual( ui.newHeader[ 0 ], headers[ 1 ] ); assert.strictEqual( ui.newHeader[ 0 ], headers[ 1 ] );
equal( ui.newPanel.length, 1 ); assert.equal( ui.newPanel.length, 1 );
strictEqual( ui.newPanel[ 0 ], content[ 1 ] ); assert.strictEqual( ui.newPanel[ 0 ], content[ 1 ] );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
} ); } );
headers.eq( 1 ).trigger( "click" ); headers.eq( 1 ).trigger( "click" );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
element.one( "accordionbeforeactivate", function( event, ui ) { element.one( "accordionbeforeactivate", function( event, ui ) {
ok( !( "originalEvent" in event ) ); assert.ok( !( "originalEvent" in event ) );
equal( ui.oldHeader.length, 1 ); assert.equal( ui.oldHeader.length, 1 );
strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] ); assert.strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] );
equal( ui.oldPanel.length, 1 ); assert.equal( ui.oldPanel.length, 1 );
strictEqual( ui.oldPanel[ 0 ], content[ 1 ] ); assert.strictEqual( ui.oldPanel[ 0 ], content[ 1 ] );
equal( ui.newHeader.length, 0 ); assert.equal( ui.newHeader.length, 0 );
equal( ui.newPanel.length, 0 ); assert.equal( ui.newPanel.length, 0 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
} ); } );
element.accordion( "option", "active", false ); element.accordion( "option", "active", false );
state( element, 0, 0, 0 ); state( assert, element, 0, 0, 0 );
element.one( "accordionbeforeactivate", function( event, ui ) { element.one( "accordionbeforeactivate", function( event, ui ) {
ok( !( "originalEvent" in event ) ); assert.ok( !( "originalEvent" in event ) );
equal( ui.oldHeader.length, 0 ); assert.equal( ui.oldHeader.length, 0 );
equal( ui.oldPanel.length, 0 ); assert.equal( ui.oldPanel.length, 0 );
equal( ui.newHeader.length, 1 ); assert.equal( ui.newHeader.length, 1 );
strictEqual( ui.newHeader[ 0 ], headers[ 2 ] ); assert.strictEqual( ui.newHeader[ 0 ], headers[ 2 ] );
equal( ui.newPanel.length, 1 ); assert.equal( ui.newPanel.length, 1 );
strictEqual( ui.newPanel[ 0 ], content[ 2 ] ); assert.strictEqual( ui.newPanel[ 0 ], content[ 2 ] );
event.preventDefault(); event.preventDefault();
state( element, 0, 0, 0 ); state( assert, element, 0, 0, 0 );
} ); } );
element.accordion( "option", "active", 2 ); element.accordion( "option", "active", 2 );
state( element, 0, 0, 0 ); state( assert, element, 0, 0, 0 );
} ); } );
test( "activate", function() { QUnit.test( "activate", function( assert ) {
expect( 21 ); assert.expect( 21 );
var element = $( "#list1" ).accordion( { var element = $( "#list1" ).accordion( {
active: false, active: false,
collapsible: true collapsible: true
@ -123,44 +124,44 @@ test( "activate", function() {
content = element.find( ".ui-accordion-content" ); content = element.find( ".ui-accordion-content" );
element.one( "accordionactivate", function( event, ui ) { element.one( "accordionactivate", function( event, ui ) {
equal( ui.oldHeader.length, 0 ); assert.equal( ui.oldHeader.length, 0 );
equal( ui.oldPanel.length, 0 ); assert.equal( ui.oldPanel.length, 0 );
equal( ui.newHeader.length, 1 ); assert.equal( ui.newHeader.length, 1 );
strictEqual( ui.newHeader[ 0 ], headers[ 0 ] ); assert.strictEqual( ui.newHeader[ 0 ], headers[ 0 ] );
equal( ui.newPanel.length, 1 ); assert.equal( ui.newPanel.length, 1 );
strictEqual( ui.newPanel[ 0 ], content[ 0 ] ); assert.strictEqual( ui.newPanel[ 0 ], content[ 0 ] );
} ); } );
element.accordion( "option", "active", 0 ); element.accordion( "option", "active", 0 );
element.one( "accordionactivate", function( event, ui ) { element.one( "accordionactivate", function( event, ui ) {
equal( ui.oldHeader.length, 1 ); assert.equal( ui.oldHeader.length, 1 );
strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] ); assert.strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] );
equal( ui.oldPanel.length, 1 ); assert.equal( ui.oldPanel.length, 1 );
strictEqual( ui.oldPanel[ 0 ], content[ 0 ] ); assert.strictEqual( ui.oldPanel[ 0 ], content[ 0 ] );
equal( ui.newHeader.length, 1 ); assert.equal( ui.newHeader.length, 1 );
strictEqual( ui.newHeader[ 0 ], headers[ 1 ] ); assert.strictEqual( ui.newHeader[ 0 ], headers[ 1 ] );
equal( ui.newPanel.length, 1 ); assert.equal( ui.newPanel.length, 1 );
strictEqual( ui.newPanel[ 0 ], content[ 1 ] ); assert.strictEqual( ui.newPanel[ 0 ], content[ 1 ] );
} ); } );
headers.eq( 1 ).trigger( "click" ); headers.eq( 1 ).trigger( "click" );
element.one( "accordionactivate", function( event, ui ) { element.one( "accordionactivate", function( event, ui ) {
equal( ui.oldHeader.length, 1 ); assert.equal( ui.oldHeader.length, 1 );
strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] ); assert.strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] );
equal( ui.oldPanel.length, 1 ); assert.equal( ui.oldPanel.length, 1 );
strictEqual( ui.oldPanel[ 0 ], content[ 1 ] ); assert.strictEqual( ui.oldPanel[ 0 ], content[ 1 ] );
equal( ui.newHeader.length, 0 ); assert.equal( ui.newHeader.length, 0 );
equal( ui.newPanel.length, 0 ); assert.equal( ui.newPanel.length, 0 );
} ); } );
element.accordion( "option", "active", false ); element.accordion( "option", "active", false );
// Prevent activation // Prevent activation
element.one( "accordionbeforeactivate", function( event ) { element.one( "accordionbeforeactivate", function( event ) {
ok( true ); assert.ok( true );
event.preventDefault(); event.preventDefault();
} ); } );
element.one( "accordionactivate", function() { element.one( "accordionactivate", function() {
ok( false ); assert.ok( false );
} ); } );
element.accordion( "option", "active", 1 ); element.accordion( "option", "active", 1 );
} ); } );

View File

@ -1,13 +1,14 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"lib/helper", "lib/helper",
"ui/widgets/accordion" "ui/widgets/accordion"
], function( $, helper ) { ], function( QUnit, $, helper ) {
return $.extend( helper, { return $.extend( helper, {
equalHeight: function( accordion, height ) { equalHeight: function( assert, accordion, height ) {
accordion.find( ".ui-accordion-content" ).each( function() { accordion.find( ".ui-accordion-content" ).each( function() {
equal( $( this ).outerHeight(), height ); assert.equal( $( this ).outerHeight(), height );
} ); } );
}, },
@ -23,12 +24,12 @@ return $.extend( helper, {
}; };
}, },
state: function( accordion ) { state: function( assert, accordion ) {
var expected = $.makeArray( arguments ).slice( 1 ), var expected = $.makeArray( arguments ).slice( 2 ),
actual = accordion.find( ".ui-accordion-content" ).map( function() { actual = accordion.find( ".ui-accordion-content" ).map( function() {
return $( this ).css( "display" ) === "none" ? 0 : 1; return $( this ).css( "display" ) === "none" ? 0 : 1;
} ).get(); } ).get();
QUnit.push( QUnit.equiv( actual, expected ), actual, expected ); assert.deepEqual( actual, expected );
} }
} ); } );

View File

@ -1,47 +1,48 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"./helper", "./helper",
"ui/widgets/accordion" "ui/widgets/accordion"
], function( $, testHelper ) { ], function( QUnit, $, testHelper ) {
var equalHeight = testHelper.equalHeight, var equalHeight = testHelper.equalHeight,
setupTeardown = testHelper.setupTeardown, setupTeardown = testHelper.setupTeardown,
state = testHelper.state; state = testHelper.state;
module( "accordion: methods", setupTeardown() ); QUnit.module( "accordion: methods", setupTeardown() );
test( "destroy", function( assert ) { QUnit.test( "destroy", function( assert ) {
expect( 1 ); assert.expect( 1 );
assert.domEqual( "#list1", function() { assert.domEqual( "#list1", function() {
$( "#list1" ).accordion().accordion( "destroy" ); $( "#list1" ).accordion().accordion( "destroy" );
} ); } );
} ); } );
test( "enable/disable", function( assert ) { QUnit.test( "enable/disable", function( assert ) {
expect( 7 ); assert.expect( 7 );
var element = $( "#list1" ).accordion(); var element = $( "#list1" ).accordion();
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
element.accordion( "disable" ); element.accordion( "disable" );
assert.hasClasses( element, "ui-state-disabled" ); assert.hasClasses( element, "ui-state-disabled" );
equal( element.attr( "aria-disabled" ), "true", "element gets aria-disabled" ); assert.equal( element.attr( "aria-disabled" ), "true", "element gets aria-disabled" );
assert.hasClasses( element, "ui-accordion-disabled" ); assert.hasClasses( element, "ui-accordion-disabled" );
// Event does nothing // Event does nothing
element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "click" ); element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "click" );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
// Option still works // Option still works
element.accordion( "option", "active", 1 ); element.accordion( "option", "active", 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
element.accordion( "enable" ); element.accordion( "enable" );
element.accordion( "option", "active", 2 ); element.accordion( "option", "active", 2 );
state( element, 0, 0, 1 ); state( assert, element, 0, 0, 1 );
} ); } );
test( "refresh", function() { QUnit.test( "refresh", function( assert ) {
expect( 19 ); assert.expect( 19 );
var element = $( "#navigation" ) var element = $( "#navigation" )
.parent() .parent()
.height( 300 ) .height( 300 )
@ -49,37 +50,37 @@ test( "refresh", function() {
.accordion( { .accordion( {
heightStyle: "fill" heightStyle: "fill"
} ); } );
equalHeight( element, 255 ); equalHeight( assert, element, 255 );
element.parent().height( 500 ); element.parent().height( 500 );
element.accordion( "refresh" ); element.accordion( "refresh" );
equalHeight( element, 455 ); equalHeight( assert, element, 455 );
element = $( "#list1" ); element = $( "#list1" );
element.accordion(); element.accordion();
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
// Disable panel via markup // Disable panel via markup
element.find( "h3.bar" ).eq( 1 ).addClass( "ui-state-disabled" ); element.find( "h3.bar" ).eq( 1 ).addClass( "ui-state-disabled" );
element.accordion( "refresh" ); element.accordion( "refresh" );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
// Don't add multiple icons // Don't add multiple icons
element.accordion( "refresh" ); element.accordion( "refresh" );
equal( element.find( ".ui-accordion-header-icon" ).length, 3 ); assert.equal( element.find( ".ui-accordion-header-icon" ).length, 3 );
// Add a panel // Add a panel
element element
.append( "<h3 class='bar' id='new_1'>new 1</h3>" ) .append( "<h3 class='bar' id='new_1'>new 1</h3>" )
.append( "<div class='foo' id='new_1_panel'>new 1</div>" ); .append( "<div class='foo' id='new_1_panel'>new 1</div>" );
element.accordion( "refresh" ); element.accordion( "refresh" );
state( element, 1, 0, 0, 0 ); state( assert, element, 1, 0, 0, 0 );
// Remove all tabs // Remove all tabs
element.find( "h3.bar, div.foo" ).remove(); element.find( "h3.bar, div.foo" ).remove();
element.accordion( "refresh" ); element.accordion( "refresh" );
state( element ); state( assert, element );
equal( element.accordion( "option", "active" ), false, "no active accordion panel" ); assert.equal( element.accordion( "option", "active" ), false, "no active accordion panel" );
// Add panels // Add panels
element element
@ -92,46 +93,46 @@ test( "refresh", function() {
.append( "<h3 class='bar' id='new_5'>new 5</h3>" ) .append( "<h3 class='bar' id='new_5'>new 5</h3>" )
.append( "<div class='foo' id='new_5_panel'>new 5</div>" ); .append( "<div class='foo' id='new_5_panel'>new 5</div>" );
element.accordion( "refresh" ); element.accordion( "refresh" );
state( element, 1, 0, 0, 0 ); state( assert, element, 1, 0, 0, 0 );
// Activate third tab // Activate third tab
element.accordion( "option", "active", 2 ); element.accordion( "option", "active", 2 );
state( element, 0, 0, 1, 0 ); state( assert, element, 0, 0, 1, 0 );
// Remove fourth panel, third panel should stay active // Remove fourth panel, third panel should stay active
element.find( "h3.bar" ).eq( 3 ).remove(); element.find( "h3.bar" ).eq( 3 ).remove();
element.find( "div.foo" ).eq( 3 ).remove(); element.find( "div.foo" ).eq( 3 ).remove();
element.accordion( "refresh" ); element.accordion( "refresh" );
state( element, 0, 0, 1 ); state( assert, element, 0, 0, 1 );
// Remove third (active) panel, second panel should become active // Remove third (active) panel, second panel should become active
element.find( "h3.bar" ).eq( 2 ).remove(); element.find( "h3.bar" ).eq( 2 ).remove();
element.find( "div.foo" ).eq( 2 ).remove(); element.find( "div.foo" ).eq( 2 ).remove();
element.accordion( "refresh" ); element.accordion( "refresh" );
state( element, 0, 1 ); state( assert, element, 0, 1 );
// Remove first panel, previously active panel (now first) should stay active // Remove first panel, previously active panel (now first) should stay active
element.find( "h3.bar" ).eq( 0 ).remove(); element.find( "h3.bar" ).eq( 0 ).remove();
element.find( "div.foo" ).eq( 0 ).remove(); element.find( "div.foo" ).eq( 0 ).remove();
element.accordion( "refresh" ); element.accordion( "refresh" );
state( element, 1 ); state( assert, element, 1 );
// Collapse all panels // Collapse all panels
element.accordion( "option", { element.accordion( "option", {
collapsible: true, collapsible: true,
active: false active: false
} ); } );
state( element, 0 ); state( assert, element, 0 );
element.accordion( "refresh" ); element.accordion( "refresh" );
state( element, 0 ); state( assert, element, 0 );
} ); } );
test( "widget", function() { QUnit.test( "widget", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#list1" ).accordion(), var element = $( "#list1" ).accordion(),
widgetElement = element.accordion( "widget" ); widgetElement = element.accordion( "widget" );
equal( widgetElement.length, 1, "one element" ); assert.equal( widgetElement.length, 1, "one element" );
strictEqual( widgetElement[ 0 ], element[ 0 ], "same element" ); assert.strictEqual( widgetElement[ 0 ], element[ 0 ], "same element" );
} ); } );
} ); } );

View File

@ -1,56 +1,57 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"./helper", "./helper",
"ui/widgets/accordion" "ui/widgets/accordion"
], function( $, testHelper ) { ], function( QUnit, $, testHelper ) {
var equalHeight = testHelper.equalHeight, var equalHeight = testHelper.equalHeight,
setupTeardown = testHelper.setupTeardown, setupTeardown = testHelper.setupTeardown,
state = testHelper.state; state = testHelper.state;
module( "accordion: options", setupTeardown() ); QUnit.module( "accordion: options", setupTeardown() );
test( "{ active: default }", function() { QUnit.test( "{ active: default }", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#list1" ).accordion(); var element = $( "#list1" ).accordion();
equal( element.accordion( "option", "active" ), 0 ); assert.equal( element.accordion( "option", "active" ), 0 );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
} ); } );
test( "{ active: null }", function() { QUnit.test( "{ active: null }", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#list1" ).accordion( { var element = $( "#list1" ).accordion( {
active: null active: null
} ); } );
equal( element.accordion( "option", "active" ), 0 ); assert.equal( element.accordion( "option", "active" ), 0 );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
} ); } );
test( "{ active: false }", function() { QUnit.test( "{ active: false }", function( assert ) {
expect( 7 ); assert.expect( 7 );
var element = $( "#list1" ).accordion( { var element = $( "#list1" ).accordion( {
active: false, active: false,
collapsible: true collapsible: true
} ); } );
state( element, 0, 0, 0 ); state( assert, element, 0, 0, 0 );
equal( element.find( ".ui-accordion-header.ui-state-active" ).length, 0, "no headers selected" ); assert.equal( element.find( ".ui-accordion-header.ui-state-active" ).length, 0, "no headers selected" );
equal( element.accordion( "option", "active" ), false ); assert.equal( element.accordion( "option", "active" ), false );
element.accordion( "option", "collapsible", false ); element.accordion( "option", "collapsible", false );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
equal( element.accordion( "option", "active" ), 0 ); assert.equal( element.accordion( "option", "active" ), 0 );
element.accordion( "destroy" ); element.accordion( "destroy" );
element.accordion( { element.accordion( {
active: false active: false
} ); } );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
strictEqual( element.accordion( "option", "active" ), 0 ); assert.strictEqual( element.accordion( "option", "active" ), 0 );
} ); } );
// http://bugs.jqueryui.com/ticket/11938 // http://bugs.jqueryui.com/ticket/11938
test( "{ active: false, collapsible: true }", function() { QUnit.test( "{ active: false, collapsible: true }", function( assert ) {
expect( 1 ); assert.expect( 1 );
var element = $( "#collapsible" ).accordion(), var element = $( "#collapsible" ).accordion(),
height = element.outerHeight(); height = element.outerHeight();
@ -61,71 +62,72 @@ test( "{ active: false, collapsible: true }", function() {
collapsible: true collapsible: true
} ) } )
.accordion( "option", "active", 0 ); .accordion( "option", "active", 0 );
equal( element.outerHeight(), height ); assert.equal( element.outerHeight(), height );
} ); } );
test( "{ active: Number }", function() { QUnit.test( "{ active: Number }", function( assert ) {
expect( 8 ); assert.expect( 8 );
var element = $( "#list1" ).accordion( { var element = $( "#list1" ).accordion( {
active: 2 active: 2
} ); } );
equal( element.accordion( "option", "active" ), 2 ); assert.equal( element.accordion( "option", "active" ), 2 );
state( element, 0, 0, 1 ); state( assert, element, 0, 0, 1 );
element.accordion( "option", "active", 0 ); element.accordion( "option", "active", 0 );
equal( element.accordion( "option", "active" ), 0 ); assert.equal( element.accordion( "option", "active" ), 0 );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "click" ); element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "click" );
equal( element.accordion( "option", "active" ), 1 ); assert.equal( element.accordion( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
element.accordion( "option", "active", 10 ); element.accordion( "option", "active", 10 );
equal( element.accordion( "option", "active" ), 1 ); assert.equal( element.accordion( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
} ); } );
test( "{ active: -Number }", function() { QUnit.test( "{ active: -Number }", function( assert ) {
expect( 8 ); assert.expect( 8 );
var element = $( "#list1" ).accordion( { var element = $( "#list1" ).accordion( {
active: -1 active: -1
} ); } );
equal( element.accordion( "option", "active" ), 2 ); assert.equal( element.accordion( "option", "active" ), 2 );
state( element, 0, 0, 1 ); state( assert, element, 0, 0, 1 );
element.accordion( "option", "active", -2 ); element.accordion( "option", "active", -2 );
equal( element.accordion( "option", "active" ), 1 ); assert.equal( element.accordion( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
element.accordion( "option", "active", -10 ); element.accordion( "option", "active", -10 );
equal( element.accordion( "option", "active" ), 1 ); assert.equal( element.accordion( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
element.accordion( "option", "active", -3 ); element.accordion( "option", "active", -3 );
equal( element.accordion( "option", "active" ), 0 ); assert.equal( element.accordion( "option", "active" ), 0 );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
} ); } );
test( "{ animate: false }", function() { QUnit.test( "{ animate: false }", function( assert ) {
expect( 3 ); assert.expect( 3 );
var element = $( "#list1" ).accordion( { var element = $( "#list1" ).accordion( {
animate: false animate: false
} ), } ),
panels = element.find( ".ui-accordion-content" ), panels = element.find( ".ui-accordion-content" ),
animate = $.fn.animate; animate = $.fn.animate;
$.fn.animate = function() { $.fn.animate = function() {
ok( false, ".animate() called" ); assert.ok( false, ".animate() called" );
}; };
ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" );
element.accordion( "option", "active", 1 ); element.accordion( "option", "active", 1 );
ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" ); assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" );
ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" ); assert.ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" );
$.fn.animate = animate; $.fn.animate = animate;
} ); } );
asyncTest( "{ animate: Number }", function() { QUnit.test( "{ animate: Number }", function( assert ) {
expect( 7 ); var ready = assert.async();
assert.expect( 7 );
var element = $( "#list1" ).accordion( { var element = $( "#list1" ).accordion( {
animate: 100 animate: 100
} ), } ),
@ -134,23 +136,24 @@ asyncTest( "{ animate: Number }", function() {
// Called twice (both panels) // Called twice (both panels)
$.fn.animate = function( props, options ) { $.fn.animate = function( props, options ) {
equal( options.duration, 100, "correct duration" ); assert.equal( options.duration, 100, "correct duration" );
equal( options.easing, undefined, "default easing" ); assert.equal( options.easing, undefined, "default easing" );
animate.apply( this, arguments ); animate.apply( this, arguments );
}; };
ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" );
element.accordion( "option", "active", 1 ); element.accordion( "option", "active", 1 );
panels.promise().done( function() { panels.promise().done( function() {
ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" ); assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" );
ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" ); assert.ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" );
$.fn.animate = animate; $.fn.animate = animate;
start(); ready();
} ); } );
} ); } );
asyncTest( "{ animate: String }", function() { QUnit.test( "{ animate: String }", function( assert ) {
expect( 7 ); var ready = assert.async();
assert.expect( 7 );
var element = $( "#list1" ).accordion( { var element = $( "#list1" ).accordion( {
animate: "linear" animate: "linear"
} ), } ),
@ -159,23 +162,24 @@ asyncTest( "{ animate: String }", function() {
// Called twice (both panels) // Called twice (both panels)
$.fn.animate = function( props, options ) { $.fn.animate = function( props, options ) {
equal( options.duration, undefined, "default duration" ); assert.equal( options.duration, undefined, "default duration" );
equal( options.easing, "linear", "correct easing" ); assert.equal( options.easing, "linear", "correct easing" );
animate.apply( this, arguments ); animate.apply( this, arguments );
}; };
ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" );
element.accordion( "option", "active", 1 ); element.accordion( "option", "active", 1 );
panels.promise().done( function() { panels.promise().done( function() {
ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" ); assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" );
ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" ); assert.ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" );
$.fn.animate = animate; $.fn.animate = animate;
start(); ready();
} ); } );
} ); } );
asyncTest( "{ animate: {} }", function() { QUnit.test( "{ animate: {} }", function( assert ) {
expect( 7 ); var ready = assert.async();
assert.expect( 7 );
var element = $( "#list1" ).accordion( { var element = $( "#list1" ).accordion( {
animate: {} animate: {}
} ), } ),
@ -184,23 +188,24 @@ asyncTest( "{ animate: {} }", function() {
// Called twice (both panels) // Called twice (both panels)
$.fn.animate = function( props, options ) { $.fn.animate = function( props, options ) {
equal( options.duration, undefined, "default duration" ); assert.equal( options.duration, undefined, "default duration" );
equal( options.easing, undefined, "default easing" ); assert.equal( options.easing, undefined, "default easing" );
animate.apply( this, arguments ); animate.apply( this, arguments );
}; };
ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" );
element.accordion( "option", "active", 1 ); element.accordion( "option", "active", 1 );
panels.promise().done( function() { panels.promise().done( function() {
ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" ); assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" );
ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" ); assert.ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" );
$.fn.animate = animate; $.fn.animate = animate;
start(); ready();
} ); } );
} ); } );
asyncTest( "{ animate: { duration, easing } }", function() { QUnit.test( "{ animate: { duration, easing } }", function( assert ) {
expect( 7 ); var ready = assert.async();
assert.expect( 7 );
var element = $( "#list1" ).accordion( { var element = $( "#list1" ).accordion( {
animate: { duration: 100, easing: "linear" } animate: { duration: 100, easing: "linear" }
} ), } ),
@ -209,23 +214,24 @@ asyncTest( "{ animate: { duration, easing } }", function() {
// Called twice (both panels) // Called twice (both panels)
$.fn.animate = function( props, options ) { $.fn.animate = function( props, options ) {
equal( options.duration, 100, "correct duration" ); assert.equal( options.duration, 100, "correct duration" );
equal( options.easing, "linear", "correct easing" ); assert.equal( options.easing, "linear", "correct easing" );
animate.apply( this, arguments ); animate.apply( this, arguments );
}; };
ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" );
element.accordion( "option", "active", 1 ); element.accordion( "option", "active", 1 );
panels.promise().done( function() { panels.promise().done( function() {
ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" ); assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" );
ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" ); assert.ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" );
$.fn.animate = animate; $.fn.animate = animate;
start(); ready();
} ); } );
} ); } );
asyncTest( "{ animate: { duration, easing } }, animate down", function() { QUnit.test( "{ animate: { duration, easing } }, animate down", function( assert ) {
expect( 7 ); var ready = assert.async();
assert.expect( 7 );
var element = $( "#list1" ).accordion( { var element = $( "#list1" ).accordion( {
active: 1, active: 1,
animate: { duration: 100, easing: "linear" } animate: { duration: 100, easing: "linear" }
@ -235,23 +241,24 @@ asyncTest( "{ animate: { duration, easing } }, animate down", function() {
// Called twice (both panels) // Called twice (both panels)
$.fn.animate = function( props, options ) { $.fn.animate = function( props, options ) {
equal( options.duration, 100, "correct duration" ); assert.equal( options.duration, 100, "correct duration" );
equal( options.easing, "linear", "correct easing" ); assert.equal( options.easing, "linear", "correct easing" );
animate.apply( this, arguments ); animate.apply( this, arguments );
}; };
ok( panels.eq( 1 ).is( ":visible" ), "first panel visible" ); assert.ok( panels.eq( 1 ).is( ":visible" ), "first panel visible" );
element.accordion( "option", "active", 0 ); element.accordion( "option", "active", 0 );
panels.promise().done( function() { panels.promise().done( function() {
ok( panels.eq( 1 ).is( ":hidden" ), "first panel hidden" ); assert.ok( panels.eq( 1 ).is( ":hidden" ), "first panel hidden" );
ok( panels.eq( 0 ).is( ":visible" ), "second panel visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "second panel visible" );
$.fn.animate = animate; $.fn.animate = animate;
start(); ready();
} ); } );
} ); } );
asyncTest( "{ animate: { duration, easing, down } }, animate down", function() { QUnit.test( "{ animate: { duration, easing, down } }, animate down", function( assert ) {
expect( 7 ); var ready = assert.async();
assert.expect( 7 );
var element = $( "#list1" ).accordion( { var element = $( "#list1" ).accordion( {
active: 1, active: 1,
animate: { animate: {
@ -267,156 +274,156 @@ asyncTest( "{ animate: { duration, easing, down } }, animate down", function() {
// Called twice (both panels) // Called twice (both panels)
$.fn.animate = function( props, options ) { $.fn.animate = function( props, options ) {
equal( options.duration, 100, "correct duration" ); assert.equal( options.duration, 100, "correct duration" );
equal( options.easing, "swing", "correct easing" ); assert.equal( options.easing, "swing", "correct easing" );
animate.apply( this, arguments ); animate.apply( this, arguments );
}; };
ok( panels.eq( 1 ).is( ":visible" ), "first panel visible" ); assert.ok( panels.eq( 1 ).is( ":visible" ), "first panel visible" );
element.accordion( "option", "active", 0 ); element.accordion( "option", "active", 0 );
panels.promise().done( function() { panels.promise().done( function() {
ok( panels.eq( 1 ).is( ":hidden" ), "first panel hidden" ); assert.ok( panels.eq( 1 ).is( ":hidden" ), "first panel hidden" );
ok( panels.eq( 0 ).is( ":visible" ), "second panel visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "second panel visible" );
$.fn.animate = animate; $.fn.animate = animate;
start(); ready();
} ); } );
} ); } );
test( "{ collapsible: false }", function() { QUnit.test( "{ collapsible: false }", function( assert ) {
expect( 4 ); assert.expect( 4 );
var element = $( "#list1" ).accordion( { var element = $( "#list1" ).accordion( {
active: 1 active: 1
} ); } );
element.accordion( "option", "active", false ); element.accordion( "option", "active", false );
equal( element.accordion( "option", "active" ), 1 ); assert.equal( element.accordion( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "click" ); element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "click" );
equal( element.accordion( "option", "active" ), 1 ); assert.equal( element.accordion( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
} ); } );
test( "{ collapsible: true }", function() { QUnit.test( "{ collapsible: true }", function( assert ) {
expect( 6 ); assert.expect( 6 );
var element = $( "#list1" ).accordion( { var element = $( "#list1" ).accordion( {
active: 1, active: 1,
collapsible: true collapsible: true
} ); } );
element.accordion( "option", "active", false ); element.accordion( "option", "active", false );
equal( element.accordion( "option", "active" ), false ); assert.equal( element.accordion( "option", "active" ), false );
state( element, 0, 0, 0 ); state( assert, element, 0, 0, 0 );
element.accordion( "option", "active", 1 ); element.accordion( "option", "active", 1 );
equal( element.accordion( "option", "active" ), 1 ); assert.equal( element.accordion( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "click" ); element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "click" );
equal( element.accordion( "option", "active" ), false ); assert.equal( element.accordion( "option", "active" ), false );
state( element, 0, 0, 0 ); state( assert, element, 0, 0, 0 );
} ); } );
test( "{ event: null }", function() { QUnit.test( "{ event: null }", function( assert ) {
expect( 5 ); assert.expect( 5 );
var element = $( "#list1" ).accordion( { var element = $( "#list1" ).accordion( {
event: null event: null
} ); } );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
element.accordion( "option", "active", 1 ); element.accordion( "option", "active", 1 );
equal( element.accordion( "option", "active" ), 1 ); assert.equal( element.accordion( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
// Ensure default click handler isn't bound // Ensure default click handler isn't bound
element.find( ".ui-accordion-header" ).eq( 2 ).trigger( "click" ); element.find( ".ui-accordion-header" ).eq( 2 ).trigger( "click" );
equal( element.accordion( "option", "active" ), 1 ); assert.equal( element.accordion( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
} ); } );
test( "{ event: custom }", function() { QUnit.test( "{ event: custom }", function( assert ) {
expect( 11 ); assert.expect( 11 );
var element = $( "#list1" ).accordion( { var element = $( "#list1" ).accordion( {
event: "custom1 custom2" event: "custom1 custom2"
} ); } );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "custom1" ); element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "custom1" );
equal( element.accordion( "option", "active" ), 1 ); assert.equal( element.accordion( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
// Ensure default click handler isn't bound // Ensure default click handler isn't bound
element.find( ".ui-accordion-header" ).eq( 2 ).trigger( "click" ); element.find( ".ui-accordion-header" ).eq( 2 ).trigger( "click" );
equal( element.accordion( "option", "active" ), 1 ); assert.equal( element.accordion( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
element.find( ".ui-accordion-header" ).eq( 2 ).trigger( "custom2" ); element.find( ".ui-accordion-header" ).eq( 2 ).trigger( "custom2" );
equal( element.accordion( "option", "active" ), 2 ); assert.equal( element.accordion( "option", "active" ), 2 );
state( element, 0, 0, 1 ); state( assert, element, 0, 0, 1 );
element.accordion( "option", "event", "custom3" ); element.accordion( "option", "event", "custom3" );
// Ensure old event handlers are unbound // Ensure old event handlers are unbound
element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "custom1" ); element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "custom1" );
element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "custom2" ); element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "custom2" );
equal( element.accordion( "option", "active" ), 2 ); assert.equal( element.accordion( "option", "active" ), 2 );
state( element, 0, 0, 1 ); state( assert, element, 0, 0, 1 );
element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "custom3" ); element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "custom3" );
equal( element.accordion( "option", "active" ), 1 ); assert.equal( element.accordion( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
} ); } );
test( "{ header: default }", function() { QUnit.test( "{ header: default }", function( assert ) {
expect( 2 ); assert.expect( 2 );
// Default: > li > :first-child,> :not(li):even // Default: > li > :first-child,> :not(li):even
// > :not(li):even // > :not(li):even
state( $( "#list1" ).accordion(), 1, 0, 0 ); state( assert, $( "#list1" ).accordion(), 1, 0, 0 );
// > li > :first-child // > li > :first-child
state( $( "#navigation" ).accordion(), 1, 0, 0 ); state( assert, $( "#navigation" ).accordion(), 1, 0, 0 );
} ); } );
test( "{ header: custom }", function( assert ) { QUnit.test( "{ header: custom }", function( assert ) {
expect( 6 ); assert.expect( 6 );
var element = $( "#navigationWrapper" ).accordion( { var element = $( "#navigationWrapper" ).accordion( {
header: "h2" header: "h2"
} ); } );
element.find( "h2" ).each( function() { element.find( "h2" ).each( function() {
assert.hasClasses( this, "ui-accordion-header" ); assert.hasClasses( this, "ui-accordion-header" );
} ); } );
equal( element.find( ".ui-accordion-header" ).length, 3 ); assert.equal( element.find( ".ui-accordion-header" ).length, 3 );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
element.accordion( "option", "active", 2 ); element.accordion( "option", "active", 2 );
state( element, 0, 0, 1 ); state( assert, element, 0, 0, 1 );
} ); } );
test( "{ heightStyle: 'auto' }", function() { QUnit.test( "{ heightStyle: 'auto' }", function( assert ) {
expect( 3 ); assert.expect( 3 );
var element = $( "#navigation" ).accordion( { heightStyle: "auto" } ); var element = $( "#navigation" ).accordion( { heightStyle: "auto" } );
equalHeight( element, 105 ); equalHeight( assert, element, 105 );
} ); } );
test( "{ heightStyle: 'content' }", function() { QUnit.test( "{ heightStyle: 'content' }", function( assert ) {
expect( 3 ); assert.expect( 3 );
var element = $( "#navigation" ).accordion( { heightStyle: "content" } ), var element = $( "#navigation" ).accordion( { heightStyle: "content" } ),
sizes = element.find( ".ui-accordion-content" ).map( function() { sizes = element.find( ".ui-accordion-content" ).map( function() {
return $( this ).height(); return $( this ).height();
} ).get(); } ).get();
equal( sizes[ 0 ], 75 ); assert.equal( sizes[ 0 ], 75 );
equal( sizes[ 1 ], 105 ); assert.equal( sizes[ 1 ], 105 );
equal( sizes[ 2 ], 45 ); assert.equal( sizes[ 2 ], 45 );
} ); } );
test( "{ heightStyle: 'fill' }", function() { QUnit.test( "{ heightStyle: 'fill' }", function( assert ) {
expect( 3 ); assert.expect( 3 );
$( "#navigationWrapper" ).height( 500 ); $( "#navigationWrapper" ).height( 500 );
var element = $( "#navigation" ).accordion( { heightStyle: "fill" } ); var element = $( "#navigation" ).accordion( { heightStyle: "fill" } );
equalHeight( element, 455 ); equalHeight( assert, element, 455 );
} ); } );
test( "{ heightStyle: 'fill' } with sibling", function() { QUnit.test( "{ heightStyle: 'fill' } with sibling", function( assert ) {
expect( 3 ); assert.expect( 3 );
$( "#navigationWrapper" ).height( 500 ); $( "#navigationWrapper" ).height( 500 );
$( "<p>Lorem Ipsum</p>" ) $( "<p>Lorem Ipsum</p>" )
.css( { .css( {
@ -426,11 +433,11 @@ test( "{ heightStyle: 'fill' } with sibling", function() {
} ) } )
.prependTo( "#navigationWrapper" ); .prependTo( "#navigationWrapper" );
var element = $( "#navigation" ).accordion( { heightStyle: "fill" } ); var element = $( "#navigation" ).accordion( { heightStyle: "fill" } );
equalHeight( element, 355 ); equalHeight( assert, element, 355 );
} ); } );
test( "{ heightStyle: 'fill' } with multiple siblings", function() { QUnit.test( "{ heightStyle: 'fill' } with multiple siblings", function( assert ) {
expect( 3 ); assert.expect( 3 );
$( "#navigationWrapper" ).height( 500 ); $( "#navigationWrapper" ).height( 500 );
$( "<p>Lorem Ipsum</p>" ) $( "<p>Lorem Ipsum</p>" )
.css( { .css( {
@ -455,15 +462,15 @@ test( "{ heightStyle: 'fill' } with multiple siblings", function() {
} ) } )
.prependTo( "#navigationWrapper" ); .prependTo( "#navigationWrapper" );
var element = $( "#navigation" ).accordion( { heightStyle: "fill" } ); var element = $( "#navigation" ).accordion( { heightStyle: "fill" } );
equalHeight( element, 305 ); equalHeight( assert, element, 305 );
} ); } );
test( "{ icons: false }", function() { QUnit.test( "{ icons: false }", function( assert ) {
expect( 8 ); assert.expect( 8 );
var element = $( "#list1" ); var element = $( "#list1" );
function icons( on ) { function icons( on ) {
deepEqual( element.find( "span.ui-icon" ).length, on ? 3 : 0 ); assert.deepEqual( element.find( "span.ui-icon" ).length, on ? 3 : 0 );
deepEqual( element.find( ".ui-accordion-header.ui-accordion-icons" ).length, on ? 3 : 0 ); assert.deepEqual( element.find( ".ui-accordion-header.ui-accordion-icons" ).length, on ? 3 : 0 );
} }
element.accordion(); element.accordion();
icons( true ); icons( true );
@ -477,8 +484,8 @@ test( "{ icons: false }", function() {
icons( false ); icons( false );
} ); } );
test( "{ icons: hash }", function( assert ) { QUnit.test( "{ icons: hash }", function( assert ) {
expect( 3 ); assert.expect( 3 );
var element = $( "#list1" ).accordion( { var element = $( "#list1" ).accordion( {
icons: { activeHeader: "a1", header: "h1" } icons: { activeHeader: "a1", header: "h1" }
} ); } );

View File

@ -19,6 +19,8 @@
"accordion/accordion.html", "accordion/accordion.html",
"autocomplete/autocomplete.html", "autocomplete/autocomplete.html",
"button/button.html", "button/button.html",
"checkboxradio/checkboxradio.html",
"controlgroup/controlgroup.html",
"core/core.html", "core/core.html",
"calendar/calendar.html", "calendar/calendar.html",
"datepicker/datepicker.html", "datepicker/datepicker.html",
@ -32,6 +34,7 @@
"progressbar/progressbar.html", "progressbar/progressbar.html",
"resizable/resizable.html", "resizable/resizable.html",
"selectable/selectable.html", "selectable/selectable.html",
"selectmenu/selectmenu.html",
"slider/slider.html", "slider/slider.html",
"sortable/sortable.html", "sortable/sortable.html",
"spinner/spinner.html", "spinner/spinner.html",

View File

@ -1,12 +1,13 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/widgets/autocomplete" "ui/widgets/autocomplete"
], function( $ ) { ], function( QUnit, $ ) {
module( "autocomplete: core" ); QUnit.module( "autocomplete: core" );
test( "markup structure", function( assert ) { QUnit.test( "markup structure", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#autocomplete" ).autocomplete(), var element = $( "#autocomplete" ).autocomplete(),
menu = element.autocomplete( "widget" ); menu = element.autocomplete( "widget" );
@ -14,8 +15,8 @@ test( "markup structure", function( assert ) {
assert.hasClasses( menu, "ui-autocomplete ui-widget ui-widget-content" ); assert.hasClasses( menu, "ui-autocomplete ui-widget ui-widget-content" );
} ); } );
test( "prevent form submit on enter when menu is active", function() { QUnit.test( "prevent form submit on enter when menu is active", function( assert ) {
expect( 2 ); assert.expect( 2 );
var event, var event,
element = $( "#autocomplete" ) element = $( "#autocomplete" )
.autocomplete( { .autocomplete( {
@ -28,17 +29,17 @@ test( "prevent form submit on enter when menu is active", function() {
event = $.Event( "keydown" ); event = $.Event( "keydown" );
event.keyCode = $.ui.keyCode.DOWN; event.keyCode = $.ui.keyCode.DOWN;
element.trigger( event ); element.trigger( event );
equal( menu.find( ".ui-menu-item-wrapper.ui-state-active" ).length, 1, assert.equal( menu.find( ".ui-menu-item-wrapper.ui-state-active" ).length, 1,
"menu item is active" ); "menu item is active" );
event = $.Event( "keydown" ); event = $.Event( "keydown" );
event.keyCode = $.ui.keyCode.ENTER; event.keyCode = $.ui.keyCode.ENTER;
element.trigger( event ); element.trigger( event );
ok( event.isDefaultPrevented(), "default action is prevented" ); assert.ok( event.isDefaultPrevented(), "default action is prevented" );
} ); } );
test( "allow form submit on enter when menu is not active", function() { QUnit.test( "allow form submit on enter when menu is not active", function( assert ) {
expect( 1 ); assert.expect( 1 );
var event, var event,
element = $( "#autocomplete" ) element = $( "#autocomplete" )
.autocomplete( { .autocomplete( {
@ -51,84 +52,84 @@ test( "allow form submit on enter when menu is not active", function() {
event = $.Event( "keydown" ); event = $.Event( "keydown" );
event.keyCode = $.ui.keyCode.ENTER; event.keyCode = $.ui.keyCode.ENTER;
element.trigger( event ); element.trigger( event );
ok( !event.isDefaultPrevented(), "default action is prevented" ); assert.ok( !event.isDefaultPrevented(), "default action is prevented" );
} ); } );
( function() { ( function() {
test( "up arrow invokes search - input", function() { QUnit.test( "up arrow invokes search - input", function( assert ) {
arrowsInvokeSearch( "#autocomplete", true, true ); arrowsInvokeSearch( assert, "#autocomplete", true, true );
} ); } );
test( "down arrow invokes search - input", function() { QUnit.test( "down arrow invokes search - input", function( assert ) {
arrowsInvokeSearch( "#autocomplete", false, true ); arrowsInvokeSearch( assert, "#autocomplete", false, true );
} ); } );
test( "up arrow invokes search - textarea", function() { QUnit.test( "up arrow invokes search - textarea", function( assert ) {
arrowsInvokeSearch( "#autocomplete-textarea", true, false ); arrowsInvokeSearch( assert, "#autocomplete-textarea", true, false );
} ); } );
test( "down arrow invokes search - textarea", function() { QUnit.test( "down arrow invokes search - textarea", function( assert ) {
arrowsInvokeSearch( "#autocomplete-textarea", false, false ); arrowsInvokeSearch( assert, "#autocomplete-textarea", false, false );
} ); } );
test( "up arrow invokes search - contenteditable", function() { QUnit.test( "up arrow invokes search - contenteditable", function( assert ) {
arrowsInvokeSearch( "#autocomplete-contenteditable", true, false ); arrowsInvokeSearch( assert, "#autocomplete-contenteditable", true, false );
} ); } );
test( "down arrow invokes search - contenteditable", function() { QUnit.test( "down arrow invokes search - contenteditable", function( assert ) {
arrowsInvokeSearch( "#autocomplete-contenteditable", false, false ); arrowsInvokeSearch( assert, "#autocomplete-contenteditable", false, false );
} ); } );
test( "up arrow moves focus - input", function() { QUnit.test( "up arrow moves focus - input", function( assert ) {
arrowsMoveFocus( "#autocomplete", true ); arrowsMoveFocus( assert, "#autocomplete", true );
} ); } );
test( "down arrow moves focus - input", function() { QUnit.test( "down arrow moves focus - input", function( assert ) {
arrowsMoveFocus( "#autocomplete", false ); arrowsMoveFocus( assert, "#autocomplete", false );
} ); } );
test( "up arrow moves focus - textarea", function() { QUnit.test( "up arrow moves focus - textarea", function( assert ) {
arrowsMoveFocus( "#autocomplete-textarea", true ); arrowsMoveFocus( assert, "#autocomplete-textarea", true );
} ); } );
test( "down arrow moves focus - textarea", function() { QUnit.test( "down arrow moves focus - textarea", function( assert ) {
arrowsMoveFocus( "#autocomplete-textarea", false ); arrowsMoveFocus( assert, "#autocomplete-textarea", false );
} ); } );
test( "up arrow moves focus - contenteditable", function() { QUnit.test( "up arrow moves focus - contenteditable", function( assert ) {
arrowsMoveFocus( "#autocomplete-contenteditable", true ); arrowsMoveFocus( assert, "#autocomplete-contenteditable", true );
} ); } );
test( "down arrow moves focus - contenteditable", function() { QUnit.test( "down arrow moves focus - contenteditable", function( assert ) {
arrowsMoveFocus( "#autocomplete-contenteditable", false ); arrowsMoveFocus( assert, "#autocomplete-contenteditable", false );
} ); } );
test( "up arrow moves cursor - input", function() { QUnit.test( "up arrow moves cursor - input", function( assert ) {
arrowsNavigateElement( "#autocomplete", true, false ); arrowsNavigateElement( assert, "#autocomplete", true, false );
} ); } );
test( "down arrow moves cursor - input", function() { QUnit.test( "down arrow moves cursor - input", function( assert ) {
arrowsNavigateElement( "#autocomplete", false, false ); arrowsNavigateElement( assert, "#autocomplete", false, false );
} ); } );
test( "up arrow moves cursor - textarea", function() { QUnit.test( "up arrow moves cursor - textarea", function( assert ) {
arrowsNavigateElement( "#autocomplete-textarea", true, true ); arrowsNavigateElement( assert, "#autocomplete-textarea", true, true );
} ); } );
test( "down arrow moves cursor - textarea", function() { QUnit.test( "down arrow moves cursor - textarea", function( assert ) {
arrowsNavigateElement( "#autocomplete-textarea", false, true ); arrowsNavigateElement( assert, "#autocomplete-textarea", false, true );
} ); } );
test( "up arrow moves cursor - contenteditable", function() { QUnit.test( "up arrow moves cursor - contenteditable", function( assert ) {
arrowsNavigateElement( "#autocomplete-contenteditable", true, true ); arrowsNavigateElement( assert, "#autocomplete-contenteditable", true, true );
} ); } );
test( "down arrow moves cursor - contenteditable", function() { QUnit.test( "down arrow moves cursor - contenteditable", function( assert ) {
arrowsNavigateElement( "#autocomplete-contenteditable", false, true ); arrowsNavigateElement( assert, "#autocomplete-contenteditable", false, true );
} ); } );
function arrowsInvokeSearch( id, isKeyUp, shouldMove ) { function arrowsInvokeSearch( assert, id, isKeyUp, shouldMove ) {
expect( 1 ); assert.expect( 1 );
var didMove = false, var didMove = false,
element = $( id ).autocomplete( { element = $( id ).autocomplete( {
@ -140,11 +141,11 @@ test( "allow form submit on enter when menu is not active", function() {
didMove = true; didMove = true;
}; };
element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } ); element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } );
equal( didMove, shouldMove, "respond to arrow" ); assert.equal( didMove, shouldMove, "respond to arrow" );
} }
function arrowsMoveFocus( id, isKeyUp ) { function arrowsMoveFocus( assert, id, isKeyUp ) {
expect( 1 ); assert.expect( 1 );
var element = $( id ).autocomplete( { var element = $( id ).autocomplete( {
source: [ "a" ], source: [ "a" ],
@ -152,14 +153,14 @@ test( "allow form submit on enter when menu is not active", function() {
minLength: 0 minLength: 0
} ); } );
element.autocomplete( "instance" )._move = function() { element.autocomplete( "instance" )._move = function() {
ok( true, "repsond to arrow" ); assert.ok( true, "repsond to arrow" );
}; };
element.autocomplete( "search" ); element.autocomplete( "search" );
element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } ); element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } );
} }
function arrowsNavigateElement( id, isKeyUp, shouldMove ) { function arrowsNavigateElement( assert, id, isKeyUp, shouldMove ) {
expect( 1 ); assert.expect( 1 );
var didMove = false, var didMove = false,
element = $( id ).autocomplete( { element = $( id ).autocomplete( {
@ -172,19 +173,20 @@ test( "allow form submit on enter when menu is not active", function() {
} ); } );
element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } ); element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } );
element.simulate( "keypress" ); element.simulate( "keypress" );
equal( didMove, shouldMove, "respond to arrow" ); assert.equal( didMove, shouldMove, "respond to arrow" );
} }
} )(); } )();
asyncTest( "past end of menu in multiline autocomplete", function() { QUnit.test( "past end of menu in multiline autocomplete", function( assert ) {
expect( 2 ); var ready = assert.async();
assert.expect( 2 );
var customVal = "custom value", var customVal = "custom value",
element = $( "#autocomplete-contenteditable" ).autocomplete( { element = $( "#autocomplete-contenteditable" ).autocomplete( {
delay: 0, delay: 0,
source: [ "javascript" ], source: [ "javascript" ],
focus: function( event, ui ) { focus: function( event, ui ) {
equal( ui.item.value, "javascript", "Item gained focus" ); assert.equal( ui.item.value, "javascript", "Item gained focus" );
$( this ).text( customVal ); $( this ).text( customVal );
event.preventDefault(); event.preventDefault();
} }
@ -197,20 +199,21 @@ asyncTest( "past end of menu in multiline autocomplete", function() {
setTimeout( function() { setTimeout( function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( element.text(), customVal ); assert.equal( element.text(), customVal );
start(); ready();
} ); } );
} ); } );
asyncTest( "ESCAPE in multiline autocomplete", function() { QUnit.test( "ESCAPE in multiline autocomplete", function( assert ) {
expect( 2 ); var ready = assert.async();
assert.expect( 2 );
var customVal = "custom value", var customVal = "custom value",
element = $( "#autocomplete-contenteditable" ).autocomplete( { element = $( "#autocomplete-contenteditable" ).autocomplete( {
delay: 0, delay: 0,
source: [ "javascript" ], source: [ "javascript" ],
focus: function( event, ui ) { focus: function( event, ui ) {
equal( ui.item.value, "javascript", "Item gained focus" ); assert.equal( ui.item.value, "javascript", "Item gained focus" );
$( this ).text( customVal ); $( this ).text( customVal );
event.preventDefault(); event.preventDefault();
} }
@ -223,26 +226,27 @@ asyncTest( "ESCAPE in multiline autocomplete", function() {
setTimeout( function() { setTimeout( function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
equal( element.text(), customVal ); assert.equal( element.text(), customVal );
start(); ready();
} ); } );
} ); } );
asyncTest( "handle race condition", function() { QUnit.test( "handle race condition", function( assert ) {
expect( 3 ); var ready = assert.async();
assert.expect( 3 );
var count = 0, var count = 0,
element = $( "#autocomplete" ).autocomplete( { element = $( "#autocomplete" ).autocomplete( {
source: function( request, response ) { source: function( request, response ) {
count++; count++;
if ( request.term.length === 1 ) { if ( request.term.length === 1 ) {
equal( count, 1, "request with 1 character is first" ); assert.equal( count, 1, "request with 1 character is first" );
setTimeout( function() { setTimeout( function() {
response( [ "one" ] ); response( [ "one" ] );
setTimeout( checkResults ); setTimeout( checkResults );
} ); } );
return; return;
} }
equal( count, 2, "request with 2 characters is second" ); assert.equal( count, 2, "request with 2 characters is second" );
response( [ "two" ] ); response( [ "two" ] );
} }
} ); } );
@ -251,14 +255,15 @@ asyncTest( "handle race condition", function() {
element.autocomplete( "search", "ab" ); element.autocomplete( "search", "ab" );
function checkResults() { function checkResults() {
equal( element.autocomplete( "widget" ).find( ".ui-menu-item" ).text(), "two", assert.equal( element.autocomplete( "widget" ).find( ".ui-menu-item" ).text(), "two",
"correct results displayed" ); "correct results displayed" );
start(); ready();
} }
} ); } );
asyncTest( "simultaneous searches (#9334)", function() { QUnit.test( "simultaneous searches (#9334)", function( assert ) {
expect( 2 ); var ready = assert.async();
assert.expect( 2 );
var element = $( "#autocomplete" ).autocomplete( { var element = $( "#autocomplete" ).autocomplete( {
source: function( request, response ) { source: function( request, response ) {
setTimeout( function() { setTimeout( function() {
@ -266,7 +271,7 @@ asyncTest( "simultaneous searches (#9334)", function() {
} ); } );
}, },
response: function() { response: function() {
ok( true, "response from first instance" ); assert.ok( true, "response from first instance" );
} }
} ), } ),
element2 = $( "#autocomplete-textarea" ).autocomplete( { element2 = $( "#autocomplete-textarea" ).autocomplete( {
@ -276,8 +281,8 @@ asyncTest( "simultaneous searches (#9334)", function() {
} ); } );
}, },
response: function() { response: function() {
ok( true, "response from second instance" ); assert.ok( true, "response from second instance" );
start(); ready();
} }
} ); } );
@ -285,60 +290,60 @@ asyncTest( "simultaneous searches (#9334)", function() {
element2.autocomplete( "search", "test" ); element2.autocomplete( "search", "test" );
} ); } );
test( "ARIA", function() { QUnit.test( "ARIA", function( assert ) {
expect( 13 ); assert.expect( 13 );
var element = $( "#autocomplete" ).autocomplete( { var element = $( "#autocomplete" ).autocomplete( {
source: [ "java", "javascript" ] source: [ "java", "javascript" ]
} ), } ),
liveRegion = element.autocomplete( "instance" ).liveRegion; liveRegion = element.autocomplete( "instance" ).liveRegion;
equal( liveRegion.children().length, 0, "Empty live region on create" ); assert.equal( liveRegion.children().length, 0, "Empty live region on create" );
equal( liveRegion.attr( "aria-live" ), "assertive", assert.equal( liveRegion.attr( "aria-live" ), "assertive",
"Live region's aria-live attribute must be assertive" ); "Live region's aria-live attribute must be assertive" );
equal( liveRegion.attr( "aria-relevant" ), "additions", assert.equal( liveRegion.attr( "aria-relevant" ), "additions",
"Live region's aria-relevant attribute must be additions" ); "Live region's aria-relevant attribute must be additions" );
equal( liveRegion.attr( "role" ), "status", assert.equal( liveRegion.attr( "role" ), "status",
"Live region's role attribute must be status" ); "Live region's role attribute must be status" );
element.autocomplete( "search", "j" ); element.autocomplete( "search", "j" );
equal( liveRegion.children().first().text(), assert.equal( liveRegion.children().first().text(),
"2 results are available, use up and down arrow keys to navigate.", "2 results are available, use up and down arrow keys to navigate.",
"Live region for multiple values" ); "Live region for multiple values" );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( liveRegion.children().filter( ":visible" ).text(), "java", assert.equal( liveRegion.children().filter( ":visible" ).text(), "java",
"Live region changed on keydown to announce the highlighted value" ); "Live region changed on keydown to announce the highlighted value" );
element.one( "autocompletefocus", function( event ) { element.one( "autocompletefocus", function( event ) {
event.preventDefault(); event.preventDefault();
} ); } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( liveRegion.children().filter( ":visible" ).text(), "javascript", assert.equal( liveRegion.children().filter( ":visible" ).text(), "javascript",
"Live region updated when default focus is prevented" ); "Live region updated when default focus is prevented" );
element.autocomplete( "search", "javas" ); element.autocomplete( "search", "javas" );
equal( liveRegion.children().filter( ":visible" ).text(), assert.equal( liveRegion.children().filter( ":visible" ).text(),
"1 result is available, use up and down arrow keys to navigate.", "1 result is available, use up and down arrow keys to navigate.",
"Live region for one value" ); "Live region for one value" );
element.autocomplete( "search", "z" ); element.autocomplete( "search", "z" );
equal( liveRegion.children().filter( ":visible" ).text(), "No search results.", assert.equal( liveRegion.children().filter( ":visible" ).text(), "No search results.",
"Live region for no values" ); "Live region for no values" );
equal( liveRegion.children().length, 5, assert.equal( liveRegion.children().length, 5,
"Should be five children in the live region after the above" ); "Should be five children in the live region after the above" );
equal( liveRegion.children().filter( ":visible" ).length, 1, assert.equal( liveRegion.children().filter( ":visible" ).length, 1,
"Only one should be still visible" ); "Only one should be still visible" );
ok( liveRegion.children().filter( ":visible" )[ 0 ] === liveRegion.children().last()[ 0 ], assert.ok( liveRegion.children().filter( ":visible" )[ 0 ] === liveRegion.children().last()[ 0 ],
"The last one should be the visible one" ); "The last one should be the visible one" );
element.autocomplete( "destroy" ); element.autocomplete( "destroy" );
equal( liveRegion.parent().length, 0, assert.equal( liveRegion.parent().length, 0,
"The liveRegion should be detached after destroy" ); "The liveRegion should be detached after destroy" );
} ); } );
test( "ARIA, aria-label announcement", function() { QUnit.test( "ARIA, aria-label announcement", function( assert ) {
expect( 1 ); assert.expect( 1 );
$.widget( "custom.catcomplete", $.ui.autocomplete, { $.widget( "custom.catcomplete", $.ui.autocomplete, {
_renderMenu: function( ul, items ) { _renderMenu: function( ul, items ) {
var that = this; var that = this;
@ -354,31 +359,32 @@ test( "ARIA, aria-label announcement", function() {
liveRegion = element.catcomplete( "instance" ).liveRegion; liveRegion = element.catcomplete( "instance" ).liveRegion;
element.catcomplete( "search", "a" ); element.catcomplete( "search", "a" );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( liveRegion.children().filter( ":visible" ).text(), "People : anders andersson", assert.equal( liveRegion.children().filter( ":visible" ).text(), "People : anders andersson",
"Live region changed on keydown to announce the highlighted value's aria-label attribute" ); "Live region changed on keydown to announce the highlighted value's aria-label attribute" );
} ); } );
test( "ARIA, init on detached input", function() { QUnit.test( "ARIA, init on detached input", function( assert ) {
expect( 1 ); assert.expect( 1 );
var element = $( "<input>" ).autocomplete( { var element = $( "<input>" ).autocomplete( {
source: [ "java", "javascript" ] source: [ "java", "javascript" ]
} ), } ),
liveRegion = element.autocomplete( "instance" ).liveRegion; liveRegion = element.autocomplete( "instance" ).liveRegion;
equal( liveRegion.parent().length, 1, "liveRegion must have a parent" ); assert.equal( liveRegion.parent().length, 1, "liveRegion must have a parent" );
} ); } );
test( ".replaceWith() (#9172)", function() { QUnit.test( ".replaceWith() (#9172)", function( assert ) {
expect( 1 ); assert.expect( 1 );
var element = $( "#autocomplete" ).autocomplete(), var element = $( "#autocomplete" ).autocomplete(),
replacement = "<div>test</div>", replacement = "<div>test</div>",
parent = element.parent(); parent = element.parent();
element.replaceWith( replacement ); element.replaceWith( replacement );
equal( parent.html().toLowerCase(), replacement ); assert.equal( parent.html().toLowerCase(), replacement );
} ); } );
asyncTest( "Search if the user retypes the same value (#7434)", function() { QUnit.test( "Search if the user retypes the same value (#7434)", function( assert ) {
expect( 3 ); var ready = assert.async();
assert.expect( 3 );
var element = $( "#autocomplete" ).autocomplete( { var element = $( "#autocomplete" ).autocomplete( {
source: [ "java", "javascript" ], source: [ "java", "javascript" ],
delay: 0 delay: 0
@ -387,19 +393,20 @@ asyncTest( "Search if the user retypes the same value (#7434)", function() {
element.val( "j" ).simulate( "keydown" ); element.val( "j" ).simulate( "keydown" );
setTimeout( function() { setTimeout( function() {
ok( menu.is( ":visible" ), "menu displays initially" ); assert.ok( menu.is( ":visible" ), "menu displays initially" );
element.trigger( "blur" ); element.trigger( "blur" );
ok( !menu.is( ":visible" ), "menu hidden after blur" ); assert.ok( !menu.is( ":visible" ), "menu hidden after blur" );
element.val( "j" ).simulate( "keydown" ); element.val( "j" ).simulate( "keydown" );
setTimeout( function() { setTimeout( function() {
ok( menu.is( ":visible" ), "menu displays after typing the same value" ); assert.ok( menu.is( ":visible" ), "menu displays after typing the same value" );
start(); ready();
} ); } );
} ); } );
} ); } );
asyncTest( "Close on click outside when focus remains", function() { QUnit.test( "Close on click outside when focus remains", function( assert ) {
expect( 2 ); var ready = assert.async();
assert.expect( 2 );
var element = $( "#autocomplete" ).autocomplete( { var element = $( "#autocomplete" ).autocomplete( {
source: [ "java", "javascript" ], source: [ "java", "javascript" ],
@ -413,11 +420,11 @@ asyncTest( "Close on click outside when focus remains", function() {
element.val( "j" ).autocomplete( "search", "j" ); element.val( "j" ).autocomplete( "search", "j" );
setTimeout( function() { setTimeout( function() {
ok( menu.is( ":visible" ), "menu displays initially" ); assert.ok( menu.is( ":visible" ), "menu displays initially" );
$( "body" ).simulate( "mousedown" ); $( "body" ).simulate( "mousedown" );
setTimeout( function() { setTimeout( function() {
ok( menu.is( ":hidden" ), "menu closes after clicking elsewhere" ); assert.ok( menu.is( ":hidden" ), "menu closes after clicking elsewhere" );
start(); ready();
} ); } );
} ); } );
} ); } );

View File

@ -1,9 +1,10 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/widgets/autocomplete" "ui/widgets/autocomplete"
], function( $ ) { ], function( QUnit, $ ) {
module( "autocomplete: events" ); QUnit.module( "autocomplete: events" );
var data = [ "Clojure", "COBOL", "ColdFusion", "Java", "JavaScript", "Scala", "Scheme" ]; var data = [ "Clojure", "COBOL", "ColdFusion", "Java", "JavaScript", "Scala", "Scheme" ];
@ -24,18 +25,19 @@ $.each( [
valueMethod: "text" valueMethod: "text"
} }
], function( i, settings ) { ], function( i, settings ) {
asyncTest( "all events - " + settings.type, function() { QUnit.test( "all events - " + settings.type, function( assert ) {
expect( 13 ); var ready = assert.async();
assert.expect( 13 );
var element = $( settings.selector ) var element = $( settings.selector )
.autocomplete( { .autocomplete( {
autoFocus: false, autoFocus: false,
delay: 0, delay: 0,
source: data, source: data,
search: function( event ) { search: function( event ) {
equal( event.originalEvent.type, "keydown", "search originalEvent" ); assert.equal( event.originalEvent.type, "keydown", "search originalEvent" );
}, },
response: function( event, ui ) { response: function( event, ui ) {
deepEqual( ui.content, [ assert.deepEqual( ui.content, [
{ label: "Clojure", value: "Clojure" }, { label: "Clojure", value: "Clojure" },
{ label: "Java", value: "Java" }, { label: "Java", value: "Java" },
{ label: "JavaScript", value: "JavaScript" } { label: "JavaScript", value: "JavaScript" }
@ -43,32 +45,32 @@ $.each( [
ui.content.splice( 0, 1 ); ui.content.splice( 0, 1 );
}, },
open: function() { open: function() {
ok( menu.is( ":visible" ), "menu open on open" ); assert.ok( menu.is( ":visible" ), "menu open on open" );
}, },
focus: function( event, ui ) { focus: function( event, ui ) {
equal( event.originalEvent.type, "menufocus", "focus originalEvent" ); assert.equal( event.originalEvent.type, "menufocus", "focus originalEvent" );
deepEqual( ui.item, { label: "Java", value: "Java" }, "focus ui.item" ); assert.deepEqual( ui.item, { label: "Java", value: "Java" }, "focus ui.item" );
}, },
close: function( event ) { close: function( event ) {
equal( event.originalEvent.type, "menuselect", "close originalEvent" ); assert.equal( event.originalEvent.type, "menuselect", "close originalEvent" );
ok( menu.is( ":hidden" ), "menu closed on close" ); assert.ok( menu.is( ":hidden" ), "menu closed on close" );
}, },
select: function( event, ui ) { select: function( event, ui ) {
equal( event.originalEvent.type, "menuselect", "select originalEvent" ); assert.equal( event.originalEvent.type, "menuselect", "select originalEvent" );
deepEqual( ui.item, { label: "Java", value: "Java" }, "select ui.item" ); assert.deepEqual( ui.item, { label: "Java", value: "Java" }, "select ui.item" );
}, },
change: function( event, ui ) { change: function( event, ui ) {
equal( event.originalEvent.type, "blur", "change originalEvent" ); assert.equal( event.originalEvent.type, "blur", "change originalEvent" );
deepEqual( ui.item, { label: "Java", value: "Java" }, "change ui.item" ); assert.deepEqual( ui.item, { label: "Java", value: "Java" }, "change ui.item" );
ok( menu.is( ":hidden" ), "menu closed on change" ); assert.ok( menu.is( ":hidden" ), "menu closed on change" );
start(); ready();
} }
} ), } ),
menu = element.autocomplete( "widget" ); menu = element.autocomplete( "widget" );
element.simulate( "focus" )[ settings.valueMethod ]( "j" ).trigger( "keydown" ); element.simulate( "focus" )[ settings.valueMethod ]( "j" ).trigger( "keydown" );
setTimeout( function() { setTimeout( function() {
ok( menu.is( ":visible" ), "menu is visible after delay" ); assert.ok( menu.is( ":visible" ), "menu is visible after delay" );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
@ -80,53 +82,56 @@ $.each( [
} ); } );
} ); } );
asyncTest( "change without selection", function() { QUnit.test( "change without selection", function( assert ) {
expect( 1 ); var ready = assert.async();
assert.expect( 1 );
var element = $( "#autocomplete" ).autocomplete( { var element = $( "#autocomplete" ).autocomplete( {
delay: 0, delay: 0,
source: data, source: data,
change: function( event, ui ) { change: function( event, ui ) {
strictEqual( ui.item, null ); assert.strictEqual( ui.item, null );
start(); ready();
} }
} ); } );
element.triggerHandler( "focus" ); element.triggerHandler( "focus" );
element.val( "ja" ).triggerHandler( "blur" ); element.val( "ja" ).triggerHandler( "blur" );
} ); } );
asyncTest( "cancel search", function() { QUnit.test( "cancel search", function( assert ) {
expect( 6 ); var ready = assert.async();
assert.expect( 6 );
var first = true, var first = true,
element = $( "#autocomplete" ).autocomplete( { element = $( "#autocomplete" ).autocomplete( {
delay: 0, delay: 0,
source: data, source: data,
search: function() { search: function() {
if ( first ) { if ( first ) {
equal( element.val(), "ja", "val on first search" ); assert.equal( element.val(), "ja", "val on first search" );
first = false; first = false;
return false; return false;
} }
equal( element.val(), "java", "val on second search" ); assert.equal( element.val(), "java", "val on second search" );
}, },
open: function() { open: function() {
ok( true, "menu opened" ); assert.ok( true, "menu opened" );
} }
} ), } ),
menu = element.autocomplete( "widget" ); menu = element.autocomplete( "widget" );
element.val( "ja" ).trigger( "keydown" ); element.val( "ja" ).trigger( "keydown" );
setTimeout( function() { setTimeout( function() {
ok( menu.is( ":hidden" ), "menu is hidden after first search" ); assert.ok( menu.is( ":hidden" ), "menu is hidden after first search" );
element.val( "java" ).trigger( "keydown" ); element.val( "java" ).trigger( "keydown" );
setTimeout( function() { setTimeout( function() {
ok( menu.is( ":visible" ), "menu is visible after second search" ); assert.ok( menu.is( ":visible" ), "menu is visible after second search" );
equal( menu.find( ".ui-menu-item" ).length, 2, "# of menu items" ); assert.equal( menu.find( ".ui-menu-item" ).length, 2, "# of menu items" );
start(); ready();
} ); } );
} ); } );
} ); } );
asyncTest( "cancel focus", function() { QUnit.test( "cancel focus", function( assert ) {
expect( 1 ); var ready = assert.async();
assert.expect( 1 );
var customVal = "custom value", var customVal = "custom value",
element = $( "#autocomplete" ).autocomplete( { element = $( "#autocomplete" ).autocomplete( {
delay: 0, delay: 0,
@ -139,13 +144,14 @@ asyncTest( "cancel focus", function() {
element.val( "ja" ).trigger( "keydown" ); element.val( "ja" ).trigger( "keydown" );
setTimeout( function() { setTimeout( function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( element.val(), customVal ); assert.equal( element.val(), customVal );
start(); ready();
} ); } );
} ); } );
asyncTest( "cancel select", function() { QUnit.test( "cancel select", function( assert ) {
expect( 1 ); var ready = assert.async();
assert.expect( 1 );
var customVal = "custom value", var customVal = "custom value",
element = $( "#autocomplete" ).autocomplete( { element = $( "#autocomplete" ).autocomplete( {
delay: 0, delay: 0,
@ -159,25 +165,26 @@ asyncTest( "cancel select", function() {
setTimeout( function() { setTimeout( function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
equal( element.val(), customVal ); assert.equal( element.val(), customVal );
start(); ready();
} ); } );
} ); } );
asyncTest( "blur during remote search", function() { QUnit.test( "blur during remote search", function( assert ) {
expect( 1 ); var ready = assert.async();
assert.expect( 1 );
var ac = $( "#autocomplete" ).autocomplete( { var ac = $( "#autocomplete" ).autocomplete( {
delay: 0, delay: 0,
source: function( request, response ) { source: function( request, response ) {
ok( true, "trigger request" ); assert.ok( true, "trigger request" );
ac.simulate( "blur" ); ac.simulate( "blur" );
setTimeout( function() { setTimeout( function() {
response( [ "result" ] ); response( [ "result" ] );
start(); ready();
}, 25 ); }, 25 );
}, },
open: function() { open: function() {
ok( false, "opened after a blur" ); assert.ok( false, "opened after a blur" );
} }
} ); } );
ac.val( "ro" ).trigger( "keydown" ); ac.val( "ro" ).trigger( "keydown" );

View File

@ -1,19 +1,20 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/widgets/autocomplete" "ui/widgets/autocomplete"
], function( $ ) { ], function( QUnit, $ ) {
module( "autocomplete: methods" ); QUnit.module( "autocomplete: methods" );
test( "destroy", function( assert ) { QUnit.test( "destroy", function( assert ) {
expect( 1 ); assert.expect( 1 );
assert.domEqual( "#autocomplete", function() { assert.domEqual( "#autocomplete", function() {
$( "#autocomplete" ).autocomplete().autocomplete( "destroy" ); $( "#autocomplete" ).autocomplete().autocomplete( "destroy" );
} ); } );
} ); } );
test( "search, close", function() { QUnit.test( "search, close", function( assert ) {
expect( 6 ); assert.expect( 6 );
var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl" ], var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl" ],
element = $( "#autocomplete" ).autocomplete( { element = $( "#autocomplete" ).autocomplete( {
source: data, source: data,
@ -21,27 +22,27 @@ test( "search, close", function() {
} ), } ),
menu = element.autocomplete( "widget" ); menu = element.autocomplete( "widget" );
ok( menu.is( ":hidden" ), "menu is hidden on init" ); assert.ok( menu.is( ":hidden" ), "menu is hidden on init" );
element.autocomplete( "search" ); element.autocomplete( "search" );
ok( menu.is( ":visible" ), "menu is visible after search" ); assert.ok( menu.is( ":visible" ), "menu is visible after search" );
equal( menu.find( ".ui-menu-item" ).length, data.length, "all items for a blank search" ); assert.equal( menu.find( ".ui-menu-item" ).length, data.length, "all items for a blank search" );
element.val( "has" ).autocomplete( "search" ); element.val( "has" ).autocomplete( "search" );
equal( menu.find( ".ui-menu-item" ).text(), "haskell", "only one item for set input value" ); assert.equal( menu.find( ".ui-menu-item" ).text(), "haskell", "only one item for set input value" );
element.autocomplete( "search", "ja" ); element.autocomplete( "search", "ja" );
equal( menu.find( ".ui-menu-item" ).length, 2, "only java and javascript for 'ja'" ); assert.equal( menu.find( ".ui-menu-item" ).length, 2, "only java and javascript for 'ja'" );
element.autocomplete( "close" ); element.autocomplete( "close" );
ok( menu.is( ":hidden" ), "menu is hidden after close" ); assert.ok( menu.is( ":hidden" ), "menu is hidden after close" );
} ); } );
test( "widget", function( assert ) { QUnit.test( "widget", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#autocomplete" ).autocomplete(), var element = $( "#autocomplete" ).autocomplete(),
widgetElement = element.autocomplete( "widget" ); widgetElement = element.autocomplete( "widget" );
equal( widgetElement.length, 1, "one element" ); assert.equal( widgetElement.length, 1, "one element" );
assert.hasClasses( widgetElement, "ui-menu" ); assert.hasClasses( widgetElement, "ui-menu" );
} ); } );

View File

@ -1,108 +1,110 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/widgets/autocomplete" "ui/widgets/autocomplete"
], function( $ ) { ], function( QUnit, $ ) {
module( "autocomplete: options" ); QUnit.module( "autocomplete: options" );
var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby",
"python", "c", "scala", "groovy", "haskell", "perl" ]; "python", "c", "scala", "groovy", "haskell", "perl" ];
test( "appendTo: null", function() { QUnit.test( "appendTo: null", function( assert ) {
expect( 1 ); assert.expect( 1 );
var element = $( "#autocomplete" ).autocomplete(); var element = $( "#autocomplete" ).autocomplete();
equal( element.autocomplete( "widget" ).parent()[ 0 ], document.body, assert.equal( element.autocomplete( "widget" ).parent()[ 0 ], document.body,
"defaults to body" ); "defaults to body" );
element.autocomplete( "destroy" ); element.autocomplete( "destroy" );
} ); } );
test( "appendTo: explicit", function() { QUnit.test( "appendTo: explicit", function( assert ) {
expect( 6 ); assert.expect( 6 );
var detached = $( "<div>" ), var detached = $( "<div>" ),
element = $( "#autocomplete" ); element = $( "#autocomplete" );
element.autocomplete( { element.autocomplete( {
appendTo: ".autocomplete-wrap" appendTo: ".autocomplete-wrap"
} ); } );
equal( element.autocomplete( "widget" ).parent()[ 0 ], assert.equal( element.autocomplete( "widget" ).parent()[ 0 ],
$( "#autocomplete-wrap1" )[ 0 ], "first found element" ); $( "#autocomplete-wrap1" )[ 0 ], "first found element" );
equal( $( "#autocomplete-wrap2 .ui-autocomplete" ).length, 0, assert.equal( $( "#autocomplete-wrap2 .ui-autocomplete" ).length, 0,
"only appends to one element" ); "only appends to one element" );
element.autocomplete( "destroy" ); element.autocomplete( "destroy" );
element.autocomplete().autocomplete( "option", "appendTo", "#autocomplete-wrap1" ); element.autocomplete().autocomplete( "option", "appendTo", "#autocomplete-wrap1" );
equal( element.autocomplete( "widget" ).parent()[ 0 ], assert.equal( element.autocomplete( "widget" ).parent()[ 0 ],
$( "#autocomplete-wrap1" )[ 0 ], "modified after init" ); $( "#autocomplete-wrap1" )[ 0 ], "modified after init" );
element.autocomplete( "destroy" ); element.autocomplete( "destroy" );
element.autocomplete( { element.autocomplete( {
appendTo: detached appendTo: detached
} ); } );
equal( element.autocomplete( "widget" ).parent()[ 0 ], detached[ 0 ], assert.equal( element.autocomplete( "widget" ).parent()[ 0 ], detached[ 0 ],
"detached jQuery object" ); "detached jQuery object" );
element.autocomplete( "destroy" ); element.autocomplete( "destroy" );
element.autocomplete( { element.autocomplete( {
appendTo: detached[ 0 ] appendTo: detached[ 0 ]
} ); } );
equal( element.autocomplete( "widget" ).parent()[ 0 ], detached[ 0 ], assert.equal( element.autocomplete( "widget" ).parent()[ 0 ], detached[ 0 ],
"detached DOM element" ); "detached DOM element" );
element.autocomplete( "destroy" ); element.autocomplete( "destroy" );
element.autocomplete().autocomplete( "option", "appendTo", detached ); element.autocomplete().autocomplete( "option", "appendTo", detached );
equal( element.autocomplete( "widget" ).parent()[ 0 ], detached[ 0 ], assert.equal( element.autocomplete( "widget" ).parent()[ 0 ], detached[ 0 ],
"detached DOM element via option()" ); "detached DOM element via option()" );
element.autocomplete( "destroy" ); element.autocomplete( "destroy" );
} ); } );
test( "appendTo: ui-front", function() { QUnit.test( "appendTo: ui-front", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#autocomplete" ); var element = $( "#autocomplete" );
$( "#autocomplete-wrap2" ).addClass( "ui-front" ); $( "#autocomplete-wrap2" ).addClass( "ui-front" );
element.autocomplete(); element.autocomplete();
equal( element.autocomplete( "widget" ).parent()[ 0 ], assert.equal( element.autocomplete( "widget" ).parent()[ 0 ],
$( "#autocomplete-wrap2" )[ 0 ], "null, inside .ui-front" ); $( "#autocomplete-wrap2" )[ 0 ], "null, inside .ui-front" );
element.autocomplete( "destroy" ); element.autocomplete( "destroy" );
element.autocomplete( { element.autocomplete( {
appendTo: $() appendTo: $()
} ); } );
equal( element.autocomplete( "widget" ).parent()[ 0 ], assert.equal( element.autocomplete( "widget" ).parent()[ 0 ],
$( "#autocomplete-wrap2" )[ 0 ], "empty jQuery object, inside .ui-front" ); $( "#autocomplete-wrap2" )[ 0 ], "empty jQuery object, inside .ui-front" );
} ); } );
function autoFocusTest( afValue, focusedLength ) { function autoFocusTest( assert, afValue, focusedLength ) {
var ready = assert.async();
var element = $( "#autocomplete" ).autocomplete( { var element = $( "#autocomplete" ).autocomplete( {
autoFocus: afValue, autoFocus: afValue,
delay: 0, delay: 0,
source: data, source: data,
open: function() { open: function() {
equal( assert.equal(
element.autocomplete( "widget" ) element.autocomplete( "widget" )
.find( ".ui-menu-item-wrapper.ui-state-active" ) .find( ".ui-menu-item-wrapper.ui-state-active" )
.length, .length,
focusedLength, focusedLength,
"first item is " + ( afValue ? "" : "not" ) + " auto focused" ); "first item is " + ( afValue ? "" : "not" ) + " auto focused" );
start(); ready();
} }
} ); } );
element.val( "ja" ).trigger( "keydown" ); element.val( "ja" ).trigger( "keydown" );
stop();
} }
test( "autoFocus: false", function() { QUnit.test( "autoFocus: false", function( assert ) {
expect( 1 ); assert.expect( 1 );
autoFocusTest( false, 0 ); autoFocusTest( assert, false, 0 );
} ); } );
test( "autoFocus: true", function() { QUnit.test( "autoFocus: true", function( assert ) {
expect( 1 ); assert.expect( 1 );
autoFocusTest( true, 1 ); autoFocusTest( assert, true, 1 );
} ); } );
asyncTest( "delay", function() { QUnit.test( "delay", function( assert ) {
expect( 2 ); var ready = assert.async();
assert.expect( 2 );
var element = $( "#autocomplete" ).autocomplete( { var element = $( "#autocomplete" ).autocomplete( {
source: data, source: data,
delay: 25 delay: 25
@ -110,16 +112,17 @@ asyncTest( "delay", function() {
menu = element.autocomplete( "widget" ); menu = element.autocomplete( "widget" );
element.val( "ja" ).trigger( "keydown" ); element.val( "ja" ).trigger( "keydown" );
ok( menu.is( ":hidden" ), "menu is closed immediately after search" ); assert.ok( menu.is( ":hidden" ), "menu is closed immediately after search" );
setTimeout( function() { setTimeout( function() {
ok( menu.is( ":visible" ), "menu is open after delay" ); assert.ok( menu.is( ":visible" ), "menu is open after delay" );
start(); ready();
}, 50 ); }, 50 );
} ); } );
asyncTest( "disabled", function( assert ) { QUnit.test( "disabled", function( assert ) {
expect( 5 ); var ready = assert.async();
assert.expect( 5 );
var element = $( "#autocomplete" ).autocomplete( { var element = $( "#autocomplete" ).autocomplete( {
source: data, source: data,
delay: 0 delay: 0
@ -127,38 +130,39 @@ asyncTest( "disabled", function( assert ) {
menu = element.autocomplete( "disable" ).autocomplete( "widget" ); menu = element.autocomplete( "disable" ).autocomplete( "widget" );
element.val( "ja" ).trigger( "keydown" ); element.val( "ja" ).trigger( "keydown" );
ok( menu.is( ":hidden" ) ); assert.ok( menu.is( ":hidden" ) );
assert.lacksClasses( element, "ui-state-disabled" ); assert.lacksClasses( element, "ui-state-disabled" );
assert.hasClasses( menu, "ui-autocomplete-disabled" ); assert.hasClasses( menu, "ui-autocomplete-disabled" );
ok( !element.attr( "aria-disabled" ), "element doesn't get aria-disabled" ); assert.ok( !element.attr( "aria-disabled" ), "element doesn't get aria-disabled" );
setTimeout( function() { setTimeout( function() {
ok( menu.is( ":hidden" ) ); assert.ok( menu.is( ":hidden" ) );
start(); ready();
} ); } );
} ); } );
test( "minLength", function() { QUnit.test( "minLength", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#autocomplete" ).autocomplete( { var element = $( "#autocomplete" ).autocomplete( {
source: data source: data
} ), } ),
menu = element.autocomplete( "widget" ); menu = element.autocomplete( "widget" );
element.autocomplete( "search", "" ); element.autocomplete( "search", "" );
ok( menu.is( ":hidden" ), "blank not enough for minLength: 1" ); assert.ok( menu.is( ":hidden" ), "blank not enough for minLength: 1" );
element.autocomplete( "option", "minLength", 0 ); element.autocomplete( "option", "minLength", 0 );
element.autocomplete( "search", "" ); element.autocomplete( "search", "" );
ok( menu.is( ":visible" ), "blank enough for minLength: 0" ); assert.ok( menu.is( ":visible" ), "blank enough for minLength: 0" );
} ); } );
asyncTest( "minLength, exceed then drop below", function() { QUnit.test( "minLength, exceed then drop below", function( assert ) {
expect( 4 ); var ready = assert.async();
assert.expect( 4 );
var element = $( "#autocomplete" ).autocomplete( { var element = $( "#autocomplete" ).autocomplete( {
minLength: 2, minLength: 2,
source: function( req, res ) { source: function( req, res ) {
equal( req.term, "12", "correct search term" ); assert.equal( req.term, "12", "correct search term" );
setTimeout( function() { setTimeout( function() {
res( [ "item" ] ); res( [ "item" ] );
} ); } );
@ -166,20 +170,20 @@ asyncTest( "minLength, exceed then drop below", function() {
} ), } ),
menu = element.autocomplete( "widget" ); menu = element.autocomplete( "widget" );
ok( menu.is( ":hidden" ), "menu is hidden before first search" ); assert.ok( menu.is( ":hidden" ), "menu is hidden before first search" );
element.autocomplete( "search", "12" ); element.autocomplete( "search", "12" );
ok( menu.is( ":hidden" ), "menu is hidden before second search" ); assert.ok( menu.is( ":hidden" ), "menu is hidden before second search" );
element.autocomplete( "search", "1" ); element.autocomplete( "search", "1" );
setTimeout( function() { setTimeout( function() {
ok( menu.is( ":hidden" ), "menu is hidden after searches" ); assert.ok( menu.is( ":hidden" ), "menu is hidden after searches" );
start(); ready();
} ); } );
} ); } );
test( "minLength, exceed then drop below then exceed", function() { QUnit.test( "minLength, exceed then drop below then exceed", function( assert ) {
expect( 3 ); assert.expect( 3 );
var _res = [], var _res = [],
element = $( "#autocomplete" ).autocomplete( { element = $( "#autocomplete" ).autocomplete( {
minLength: 2, minLength: 2,
@ -190,11 +194,11 @@ test( "minLength, exceed then drop below then exceed", function() {
menu = element.autocomplete( "widget" ); menu = element.autocomplete( "widget" );
// Trigger a valid search // Trigger a valid search
ok( menu.is( ":hidden" ), "menu is hidden before first search" ); assert.ok( menu.is( ":hidden" ), "menu is hidden before first search" );
element.autocomplete( "search", "12" ); element.autocomplete( "search", "12" );
// Trigger a search below the minLength, to turn on cancelSearch flag // Trigger a search below the minLength, to turn on cancelSearch flag
ok( menu.is( ":hidden" ), "menu is hidden before second search" ); assert.ok( menu.is( ":hidden" ), "menu is hidden before second search" );
element.autocomplete( "search", "1" ); element.autocomplete( "search", "1" );
// Trigger a valid search // Trigger a valid search
@ -206,46 +210,47 @@ test( "minLength, exceed then drop below then exceed", function() {
// React to second search // React to second search
_res[ 1 ]( [ "13" ] ); _res[ 1 ]( [ "13" ] );
ok( menu.is( ":visible" ), "menu is visible after searches" ); assert.ok( menu.is( ":visible" ), "menu is visible after searches" );
} ); } );
test( "source, local string array", function() { QUnit.test( "source, local string array", function( assert ) {
expect( 1 ); assert.expect( 1 );
var element = $( "#autocomplete" ).autocomplete( { var element = $( "#autocomplete" ).autocomplete( {
source: data source: data
} ), } ),
menu = element.autocomplete( "widget" ); menu = element.autocomplete( "widget" );
element.val( "ja" ).autocomplete( "search" ); element.val( "ja" ).autocomplete( "search" );
equal( menu.find( ".ui-menu-item" ).text(), "javajavascript" ); assert.equal( menu.find( ".ui-menu-item" ).text(), "javajavascript" );
} ); } );
function sourceTest( source, async ) { function sourceTest( assert, source, async ) {
var ready;
var element = $( "#autocomplete" ).autocomplete( { var element = $( "#autocomplete" ).autocomplete( {
source: source source: source
} ), } ),
menu = element.autocomplete( "widget" ); menu = element.autocomplete( "widget" );
function result() { function result() {
var items = menu.find( ".ui-menu-item" ); var items = menu.find( ".ui-menu-item" );
equal( items.length, 3, "Should find three results." ); assert.equal( items.length, 3, "Should find three results." );
deepEqual( items.eq( 0 ).data( "ui-autocomplete-item" ), { assert.deepEqual( items.eq( 0 ).data( "ui-autocomplete-item" ), {
label: "java", label: "java",
value: "java" value: "java"
} ); } );
deepEqual( items.eq( 1 ).data( "ui-autocomplete-item" ), { assert.deepEqual( items.eq( 1 ).data( "ui-autocomplete-item" ), {
label: "javascript", label: "javascript",
value: "javascript" value: "javascript"
} ); } );
deepEqual( items.eq( 2 ).data( "ui-autocomplete-item" ), { assert.deepEqual( items.eq( 2 ).data( "ui-autocomplete-item" ), {
label: "clojure", label: "clojure",
value: "clojure" value: "clojure"
} ); } );
element.autocomplete( "destroy" ); element.autocomplete( "destroy" );
if ( async ) { if ( async ) {
start(); ready();
} }
} }
if ( async ) { if ( async ) {
stop(); ready = assert.async();
$( document ).one( "ajaxStop", result ); $( document ).one( "ajaxStop", result );
} }
element.val( "j" ).autocomplete( "search" ); element.val( "j" ).autocomplete( "search" );
@ -254,9 +259,9 @@ function sourceTest( source, async ) {
} }
} }
test( "source, local object array, only labels", function() { QUnit.test( "source, local object array, only labels", function( assert ) {
expect( 4 ); assert.expect( 4 );
sourceTest( [ sourceTest( assert, [
{ label: "java", value: null }, { label: "java", value: null },
{ label: "php", value: null }, { label: "php", value: null },
{ label: "coldfusion", value: "" }, { label: "coldfusion", value: "" },
@ -265,9 +270,9 @@ test( "source, local object array, only labels", function() {
] ); ] );
} ); } );
test( "source, local object array, only values", function() { QUnit.test( "source, local object array, only values", function( assert ) {
expect( 4 ); assert.expect( 4 );
sourceTest( [ sourceTest( assert, [
{ value: "java", label: null }, { value: "java", label: null },
{ value: "php", label: null }, { value: "php", label: null },
{ value: "coldfusion", label: "" }, { value: "coldfusion", label: "" },
@ -276,25 +281,25 @@ test( "source, local object array, only values", function() {
] ); ] );
} ); } );
test( "source, url string with remote json string array", function() { QUnit.test( "source, url string with remote json string array", function( assert ) {
expect( 4 ); assert.expect( 4 );
sourceTest( "remote_string_array.txt", true ); sourceTest( assert, "remote_string_array.txt", true );
} ); } );
test( "source, url string with remote json object array, only value properties", function() { QUnit.test( "source, url string with remote json object array, only value properties", function( assert ) {
expect( 4 ); assert.expect( 4 );
sourceTest( "remote_object_array_values.txt", true ); sourceTest( assert, "remote_object_array_values.txt", true );
} ); } );
test( "source, url string with remote json object array, only label properties", function() { QUnit.test( "source, url string with remote json object array, only label properties", function( assert ) {
expect( 4 ); assert.expect( 4 );
sourceTest( "remote_object_array_labels.txt", true ); sourceTest( assert, "remote_object_array_labels.txt", true );
} ); } );
test( "source, custom", function() { QUnit.test( "source, custom", function( assert ) {
expect( 5 ); assert.expect( 5 );
sourceTest( function( request, response ) { sourceTest( assert, function( request, response ) {
equal( request.term, "j" ); assert.equal( request.term, "j" );
response( [ response( [
"java", "java",
{ label: "javascript", value: null }, { label: "javascript", value: null },
@ -303,17 +308,17 @@ test( "source, custom", function() {
} ); } );
} ); } );
test( "source, update after init", function() { QUnit.test( "source, update after init", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#autocomplete" ).autocomplete( { var element = $( "#autocomplete" ).autocomplete( {
source: [ "java", "javascript", "haskell" ] source: [ "java", "javascript", "haskell" ]
} ), } ),
menu = element.autocomplete( "widget" ); menu = element.autocomplete( "widget" );
element.val( "ja" ).autocomplete( "search" ); element.val( "ja" ).autocomplete( "search" );
equal( menu.find( ".ui-menu-item" ).text(), "javajavascript" ); assert.equal( menu.find( ".ui-menu-item" ).text(), "javajavascript" );
element.autocomplete( "option", "source", [ "php", "asp" ] ); element.autocomplete( "option", "source", [ "php", "asp" ] );
element.val( "ph" ).autocomplete( "search" ); element.val( "ph" ).autocomplete( "search" );
equal( menu.find( ".ui-menu-item" ).text(), "php" ); assert.equal( menu.find( ".ui-menu-item" ).text(), "php" );
} ); } );
} ); } );

View File

@ -1,23 +1,25 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/safe-active-element", "ui/safe-active-element",
"ui/widgets/button" "ui/widgets/button"
], function( $ ) { ], function( QUnit, $ ) {
module( "Button: core" ); QUnit.module( "Button: core" );
asyncTest( "Disabled button loses focus", function() { QUnit.test( "Disabled button loses focus", function( assert ) {
expect( 2 ); var ready = assert.async();
assert.expect( 2 );
var element = $( "#button" ).button(); var element = $( "#button" ).button();
element.focus(); element.focus();
setTimeout( function() { setTimeout( function() {
equal( element[ 0 ], $.ui.safeActiveElement( document ), "Button is focused" ); assert.equal( element[ 0 ], $.ui.safeActiveElement( document ), "Button is focused" );
element.button( "disable" ); element.button( "disable" );
notEqual( element[ 0 ], $.ui.safeActiveElement( document ), "Button has had focus removed" ); assert.notEqual( element[ 0 ], $.ui.safeActiveElement( document ), "Button has had focus removed" );
start(); ready();
} ); } );
} ); } );

View File

@ -1,134 +1,135 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/widgets/button" "ui/widgets/button"
], function( $ ) { ], function( QUnit, $ ) {
module( "Button (deprecated): core" ); QUnit.module( "Button (deprecated): core" );
test( "Calling button on a checkbox input calls checkboxradio widget", function() { QUnit.test( "Calling button on a checkbox input calls checkboxradio widget", function( assert ) {
var checkbox = $( "#checkbox01" ); var checkbox = $( "#checkbox01" );
expect( 2 ); assert.expect( 2 );
checkbox.button(); checkbox.button();
ok( !!checkbox.checkboxradio( "instance" ), assert.ok( !!checkbox.checkboxradio( "instance" ),
"Calling button on a checkbox creates checkboxradio instance" ); "Calling button on a checkbox creates checkboxradio instance" );
ok( !checkbox.checkboxradio( "option", "icon" ), assert.ok( !checkbox.checkboxradio( "option", "icon" ),
"Calling button on a checkbox sets the checkboxradio icon option to false" ); "Calling button on a checkbox sets the checkboxradio icon option to false" );
} ); } );
test( "Calling buttonset calls controlgroup", function() { QUnit.test( "Calling buttonset calls controlgroup", function( assert ) {
var controlgroup = $( ".buttonset" ); var controlgroup = $( ".buttonset" );
expect( 1 ); assert.expect( 1 );
controlgroup.buttonset(); controlgroup.buttonset();
ok( controlgroup.is( ":ui-controlgroup" ), "Calling buttonset creates controlgroup instance" ); assert.ok( controlgroup.is( ":ui-controlgroup" ), "Calling buttonset creates controlgroup instance" );
} ); } );
module( "Button (deprecated): methods" ); QUnit.module( "Button (deprecated): methods" );
test( "destroy", function( assert ) { QUnit.test( "destroy", function( assert ) {
expect( 1 ); assert.expect( 1 );
assert.domEqual( "#checkbox02", function() { assert.domEqual( "#checkbox02", function() {
$( "#checkbox02" ).button().button( "destroy" ); $( "#checkbox02" ).button().button( "destroy" );
} ); } );
} ); } );
test( "refresh: Ensure disabled state is preserved correctly.", function() { QUnit.test( "refresh: Ensure disabled state is preserved correctly.", function( assert ) {
expect( 5 ); assert.expect( 5 );
var element = null; var element = null;
element = $( "#checkbox02" ); element = $( "#checkbox02" );
element.button( { disabled: true } ).button( "refresh" ); element.button( { disabled: true } ).button( "refresh" );
ok( element.button( "option", "disabled" ), "Checkboxes should remain disabled after refresh" ); assert.ok( element.button( "option", "disabled" ), "Checkboxes should remain disabled after refresh" );
ok( element.prop( "disabled" ), "Input remains disabled after refresh" ); assert.ok( element.prop( "disabled" ), "Input remains disabled after refresh" );
element = $( "#radio02" ); element = $( "#radio02" );
element.button( { disabled: true } ).button( "refresh" ); element.button( { disabled: true } ).button( "refresh" );
ok( element.button( "option", "disabled" ), "Radio buttons should remain disabled after refresh" ); assert.ok( element.button( "option", "disabled" ), "Radio buttons should remain disabled after refresh" );
element = $( "#checkbox02" ); element = $( "#checkbox02" );
element.button( { disabled: true } ).prop( "disabled", false ).button( "refresh" ); element.button( { disabled: true } ).prop( "disabled", false ).button( "refresh" );
ok( !element.button( "option", "disabled" ), "Changing a checkbox's disabled property should update the state after refresh." ); assert.ok( !element.button( "option", "disabled" ), "Changing a checkbox's disabled property should update the state after refresh." );
element = $( "#radio02" ); element = $( "#radio02" );
element.button( { disabled: true } ).prop( "disabled", false ).button( "refresh" ); element.button( { disabled: true } ).prop( "disabled", false ).button( "refresh" );
ok( !element.button( "option", "disabled" ), "Changing a radio button's disabled property should update the state after refresh." ); assert.ok( !element.button( "option", "disabled" ), "Changing a radio button's disabled property should update the state after refresh." );
} ); } );
module( "button (deprecated): options" ); QUnit.module( "button (deprecated): options" );
test( "Setting items option on buttonset sets the button properties on the items option", function() { QUnit.test( "Setting items option on buttonset sets the button properties on the items option", function( assert ) {
expect( 2 ); assert.expect( 2 );
var controlgroup = $( ".buttonset" ); var controlgroup = $( ".buttonset" );
controlgroup.buttonset( { items: "bar" } ); controlgroup.buttonset( { items: "bar" } );
equal( controlgroup.controlgroup( "option", "items.button" ), "bar", assert.equal( controlgroup.controlgroup( "option", "items.button" ), "bar",
"items.button set when setting items option on init on buttonset" ); "items.button set when setting items option on init on buttonset" );
controlgroup.buttonset( "option", "items", "foo" ); controlgroup.buttonset( "option", "items", "foo" );
equal( controlgroup.controlgroup( "option", "items.button" ), "foo", assert.equal( controlgroup.controlgroup( "option", "items.button" ), "foo",
"items.button set when setting items option on buttonset" ); "items.button set when setting items option on buttonset" );
} ); } );
test( "disabled, null", function() { QUnit.test( "disabled, null", function( assert ) {
expect( 2 ); assert.expect( 2 );
$( "#radio02" ).prop( "disabled", true ).button( { disabled: null } ); $( "#radio02" ).prop( "disabled", true ).button( { disabled: null } );
deepEqual( $( "#radio02" ).button( "option", "disabled" ), true, assert.deepEqual( $( "#radio02" ).button( "option", "disabled" ), true,
"disabled option set to true" ); "disabled option set to true" );
deepEqual( true, $( "#radio02" ).prop( "disabled" ), "element is not disabled" ); assert.deepEqual( true, $( "#radio02" ).prop( "disabled" ), "element is not disabled" );
} ); } );
test( "text / showLabel options proxied", function() { QUnit.test( "text / showLabel options proxied", function( assert ) {
expect( 8 ); assert.expect( 8 );
var button = $( "#button" ); var button = $( "#button" );
button.button( { button.button( {
text: false, text: false,
icon: "ui-icon-gear" icon: "ui-icon-gear"
} ); } );
equal( button.button( "option", "showLabel" ), false, assert.equal( button.button( "option", "showLabel" ), false,
"Setting the text option to false sets the showLabel option to false on init" ); "Setting the text option to false sets the showLabel option to false on init" );
button.button( "option", "showLabel", true ); button.button( "option", "showLabel", true );
equal( button.button( "option", "text" ), true, assert.equal( button.button( "option", "text" ), true,
"Setting showLabel true with option method sets text option to true" ); "Setting showLabel true with option method sets text option to true" );
button.button( "option", "text", false ); button.button( "option", "text", false );
equal( button.button( "option", "showLabel" ), false, assert.equal( button.button( "option", "showLabel" ), false,
"Setting text false with option method sets showLabel option to false" ); "Setting text false with option method sets showLabel option to false" );
button.button( "option", "text", true ); button.button( "option", "text", true );
equal( button.button( "option", "showLabel" ), true, assert.equal( button.button( "option", "showLabel" ), true,
"Setting text true with option method sets showLabel option to true" ); "Setting text true with option method sets showLabel option to true" );
button.button( "option", "showLabel", false ); button.button( "option", "showLabel", false );
equal( button.button( "option", "text" ), false, assert.equal( button.button( "option", "text" ), false,
"Setting showLabel false with option method sets text option to false" ); "Setting showLabel false with option method sets text option to false" );
button.button( "destroy" ); button.button( "destroy" );
button.button( { button.button( {
text: true, text: true,
icon: "ui-icon-gear" icon: "ui-icon-gear"
} ); } );
equal( button.button( "option", "showLabel" ), true, assert.equal( button.button( "option", "showLabel" ), true,
"Setting the text option to true sets the showLabel option to true on init" ); "Setting the text option to true sets the showLabel option to true on init" );
button.button( "destroy" ); button.button( "destroy" );
button.button( { button.button( {
showLabel: true, showLabel: true,
icon: "ui-icon-gear" icon: "ui-icon-gear"
} ); } );
equal( button.button( "option", "text" ), true, assert.equal( button.button( "option", "text" ), true,
"Setting the showLabel option to true sets the text option to true on init" ); "Setting the showLabel option to true sets the text option to true on init" );
button.button( "destroy" ); button.button( "destroy" );
button.button( { button.button( {
showLabel: false, showLabel: false,
icon: "ui-icon-gear" icon: "ui-icon-gear"
} ); } );
equal( button.button( "option", "text" ), false, assert.equal( button.button( "option", "text" ), false,
"Setting the showLabel option to false sets the text option to false on init" ); "Setting the showLabel option to false sets the text option to false on init" );
} ); } );
test( "icon / icons options properly proxied", function() { QUnit.test( "icon / icons options properly proxied", function( assert ) {
expect( 10 ); assert.expect( 10 );
var button = $( "#button" ); var button = $( "#button" );
@ -136,14 +137,14 @@ test( "icon / icons options properly proxied", function() {
icon: "foo" icon: "foo"
} ); } );
equal( button.button( "option", "icons.primary" ), "foo", assert.equal( button.button( "option", "icons.primary" ), "foo",
"Icon option properly proxied on init" ); "Icon option properly proxied on init" );
button.button( { button.button( {
icon: "bar" icon: "bar"
} ); } );
equal( button.button( "option", "icons.primary" ), "bar", assert.equal( button.button( "option", "icons.primary" ), "bar",
"Icon option properly proxied with option method" ); "Icon option properly proxied with option method" );
button.button( { button.button( {
@ -152,9 +153,9 @@ test( "icon / icons options properly proxied", function() {
} }
} ); } );
equal( button.button( "option", "icon" ), "foo", assert.equal( button.button( "option", "icon" ), "foo",
"Icons primary option properly proxied with option method" ); "Icons primary option properly proxied with option method" );
equal( button.button( "option", "iconPosition" ), "beginning", assert.equal( button.button( "option", "iconPosition" ), "beginning",
"Icons primary option sets iconPosition option to beginning" ); "Icons primary option sets iconPosition option to beginning" );
button.button( { button.button( {
@ -163,9 +164,9 @@ test( "icon / icons options properly proxied", function() {
} }
} ); } );
equal( button.button( "option", "icon" ), "bar", assert.equal( button.button( "option", "icon" ), "bar",
"Icons secondary option properly proxied with option method" ); "Icons secondary option properly proxied with option method" );
equal( button.button( "option", "iconPosition" ), "end", assert.equal( button.button( "option", "iconPosition" ), "end",
"Icons secondary option sets iconPosition option to end" ); "Icons secondary option sets iconPosition option to end" );
button.button( "destroy" ); button.button( "destroy" );
@ -176,9 +177,9 @@ test( "icon / icons options properly proxied", function() {
} }
} ); } );
equal( button.button( "option", "icon" ), "foo", assert.equal( button.button( "option", "icon" ), "foo",
"Icons primary option properly proxied on init" ); "Icons primary option properly proxied on init" );
equal( button.button( "option", "iconPosition" ), "beginning", assert.equal( button.button( "option", "iconPosition" ), "beginning",
"Icons primary option sets iconPosition option to beginning on init" ); "Icons primary option sets iconPosition option to beginning on init" );
button.button( { button.button( {
@ -187,9 +188,9 @@ test( "icon / icons options properly proxied", function() {
} }
} ); } );
equal( button.button( "option", "icon" ), "bar", assert.equal( button.button( "option", "icon" ), "bar",
"Icons secondary option properly proxied on init" ); "Icons secondary option properly proxied on init" );
equal( button.button( "option", "iconPosition" ), "end", assert.equal( button.button( "option", "iconPosition" ), "end",
"Icons secondary option sets iconPosition option to end on init" ); "Icons secondary option sets iconPosition option to end on init" );
} ); } );

View File

@ -1,18 +1,20 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/widgets/button" "ui/widgets/button"
], function( $ ) { ], function( QUnit, $ ) {
module( "Button: events" ); QUnit.module( "Button: events" );
asyncTest( "Anchor recieves click event when spacebar is pressed", function() { QUnit.test( "Anchor recieves click event when spacebar is pressed", function( assert ) {
expect( 1 ); var ready = assert.async();
assert.expect( 1 );
var element = $( "#anchor-button" ).button(); var element = $( "#anchor-button" ).button();
element.on( "click", function( event ) { element.on( "click", function( event ) {
event.preventDefault(); event.preventDefault();
ok( true, "click occcured as a result of spacebar" ); assert.ok( true, "click occcured as a result of spacebar" );
start(); ready();
} ); } );
element.trigger( $.Event( "keyup", { keyCode: $.ui.keyCode.SPACE } ) ); element.trigger( $.Event( "keyup", { keyCode: $.ui.keyCode.SPACE } ) );

View File

@ -1,32 +1,33 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/widgets/button" "ui/widgets/button"
], function( $ ) { ], function( QUnit, $ ) {
module( "Button: methods" ); QUnit.module( "Button: methods" );
test( "destroy", function( assert ) { QUnit.test( "destroy", function( assert ) {
expect( 1 ); assert.expect( 1 );
assert.domEqual( "#button", function() { assert.domEqual( "#button", function() {
$( "#button" ).button().button( "destroy" ); $( "#button" ).button().button( "destroy" );
} ); } );
} ); } );
test( "refresh: Ensure disabled state is preserved correctly.", function() { QUnit.test( "refresh: Ensure disabled state is preserved correctly.", function( assert ) {
expect( 3 ); assert.expect( 3 );
var element = $( "<a href='#'></a>" ); var element = $( "<a href='#'></a>" );
element.button( { disabled: true } ).button( "refresh" ); element.button( { disabled: true } ).button( "refresh" );
ok( element.button( "option", "disabled" ), assert.ok( element.button( "option", "disabled" ),
"Anchor button should remain disabled after refresh" ); "Anchor button should remain disabled after refresh" );
element = $( "<button></button>" ); element = $( "<button></button>" );
element.button( { disabled: true } ).button( "refresh" ); element.button( { disabled: true } ).button( "refresh" );
ok( element.button( "option", "disabled" ), "<button> should remain disabled after refresh" ); assert.ok( element.button( "option", "disabled" ), "<button> should remain disabled after refresh" );
element = $( "<button></button>" ); element = $( "<button></button>" );
element.button( { disabled: true } ).prop( "disabled", false ).button( "refresh" ); element.button( { disabled: true } ).prop( "disabled", false ).button( "refresh" );
ok( !element.button( "option", "disabled" ), assert.ok( !element.button( "option", "disabled" ),
"Changing a <button>'s disabled property should update the state after refresh." ); "Changing a <button>'s disabled property should update the state after refresh." );
} ); } );

View File

@ -1,66 +1,67 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/widgets/button" "ui/widgets/button"
], function( $ ) { ], function( QUnit, $ ) {
module( "button: options" ); QUnit.module( "button: options" );
test( "disabled, explicit value", function( assert ) { QUnit.test( "disabled, explicit value", function( assert ) {
expect( 8 ); assert.expect( 8 );
var element = $( "#button" ).button( { disabled: false } ); var element = $( "#button" ).button( { disabled: false } );
strictEqual( element.button( "option", "disabled" ), false, "disabled option set to false" ); assert.strictEqual( element.button( "option", "disabled" ), false, "disabled option set to false" );
strictEqual( element.prop( "disabled" ), false, "Disabled property is false" ); assert.strictEqual( element.prop( "disabled" ), false, "Disabled property is false" );
assert.lacksClasses( element.button( "widget" ), "ui-state-disabled ui-button-disabled" ); assert.lacksClasses( element.button( "widget" ), "ui-state-disabled ui-button-disabled" );
element = $( "#button" ).button( { disabled: true } ); element = $( "#button" ).button( { disabled: true } );
assert.hasClasses( element.button( "widget" ), "ui-state-disabled" ); assert.hasClasses( element.button( "widget" ), "ui-state-disabled" );
strictEqual( element.button( "widget" ).attr( "aria-disabled" ), undefined, assert.strictEqual( element.button( "widget" ).attr( "aria-disabled" ), undefined,
"element does not get aria-disabled" ); "element does not get aria-disabled" );
assert.hasClasses( element.button( "widget" ), "ui-button-disabled" ); assert.hasClasses( element.button( "widget" ), "ui-button-disabled" );
strictEqual( element.button( "option", "disabled" ), true, "disabled option set to true" ); assert.strictEqual( element.button( "option", "disabled" ), true, "disabled option set to true" );
strictEqual( element.prop( "disabled" ), true, "Disabled property is set" ); assert.strictEqual( element.prop( "disabled" ), true, "Disabled property is set" );
} ); } );
// We are testing the default here because the default null is a special value which means to check // We are testing the default here because the default null is a special value which means to check
// the DOM. We need to make sure this happens correctly. Checking the options should never return // the DOM. We need to make sure this happens correctly. Checking the options should never return
// null, it should always be true or false. // null, it should always be true or false.
test( "disabled, null", function() { QUnit.test( "disabled, null", function( assert ) {
expect( 4 ); assert.expect( 4 );
var element = $( "#button" ), var element = $( "#button" ),
elementDisabled = $( "#button-disabled" ); elementDisabled = $( "#button-disabled" );
element.add( elementDisabled ).button( { disabled: null } ); element.add( elementDisabled ).button( { disabled: null } );
strictEqual( element.button( "option", "disabled" ), false, "disabled option set to false" ); assert.strictEqual( element.button( "option", "disabled" ), false, "disabled option set to false" );
strictEqual( element.prop( "disabled" ), false, "element is disabled" ); assert.strictEqual( element.prop( "disabled" ), false, "element is disabled" );
strictEqual( elementDisabled.button( "option", "disabled" ), true, assert.strictEqual( elementDisabled.button( "option", "disabled" ), true,
"disabled option set to true" ); "disabled option set to true" );
strictEqual( elementDisabled.prop( "disabled" ), true, "element is disabled" ); assert.strictEqual( elementDisabled.prop( "disabled" ), true, "element is disabled" );
} ); } );
test( "showLabel, false, without icon", function( assert ) { QUnit.test( "showLabel, false, without icon", function( assert ) {
expect( 4 ); assert.expect( 4 );
var button = $( "#button" ).button( { var button = $( "#button" ).button( {
showLabel: false showLabel: false
} ); } );
assert.lacksClasses( button, "ui-button-icon-only" ); assert.lacksClasses( button, "ui-button-icon-only" );
strictEqual( button.button( "option", "showLabel" ), true, assert.strictEqual( button.button( "option", "showLabel" ), true,
"showLabel false only allowed if icon true" ); "showLabel false only allowed if icon true" );
button.button( "option", "showLabel", false ); button.button( "option", "showLabel", false );
assert.lacksClasses( button, "ui-button-icon-only" ); assert.lacksClasses( button, "ui-button-icon-only" );
strictEqual( button.button( "option", "showLabel" ), true, assert.strictEqual( button.button( "option", "showLabel" ), true,
"showLabel false only allowed if icon true" ); "showLabel false only allowed if icon true" );
} ); } );
test( "showLabel, false, with icon", function( assert ) { QUnit.test( "showLabel, false, with icon", function( assert ) {
expect( 1 ); assert.expect( 1 );
var button = $( "#button" ).button( { var button = $( "#button" ).button( {
showLabel: false, showLabel: false,
icon: "iconclass" icon: "iconclass"
@ -68,53 +69,53 @@ test( "showLabel, false, with icon", function( assert ) {
assert.hasClasses( button, "ui-button ui-corner-all ui-widget ui-button-icon-only" ); assert.hasClasses( button, "ui-button ui-corner-all ui-widget ui-button-icon-only" );
} ); } );
test( "label, default", function() { QUnit.test( "label, default", function( assert ) {
expect( 2 ); assert.expect( 2 );
var button = $( "#button" ).button(); var button = $( "#button" ).button();
deepEqual( button.text(), "Label" ); assert.deepEqual( button.text(), "Label" );
deepEqual( button.button( "option", "label" ), "Label" ); assert.deepEqual( button.button( "option", "label" ), "Label" );
} ); } );
test( "label, with html markup", function() { QUnit.test( "label, with html markup", function( assert ) {
expect( 3 ); assert.expect( 3 );
var button = $( "#button2" ).button(); var button = $( "#button2" ).button();
deepEqual( button.text(), "label with span" ); assert.deepEqual( button.text(), "label with span" );
deepEqual( button.html().toLowerCase(), "label <span>with span</span>" ); assert.deepEqual( button.html().toLowerCase(), "label <span>with span</span>" );
deepEqual( button.button( "option", "label" ).toLowerCase(), "label <span>with span</span>" ); assert.deepEqual( button.button( "option", "label" ).toLowerCase(), "label <span>with span</span>" );
} ); } );
test( "label, explicit value", function() { QUnit.test( "label, explicit value", function( assert ) {
expect( 2 ); assert.expect( 2 );
var button = $( "#button" ).button( { var button = $( "#button" ).button( {
label: "xxx" label: "xxx"
} ); } );
deepEqual( button.text(), "xxx" ); assert.deepEqual( button.text(), "xxx" );
deepEqual( button.button( "option", "label" ), "xxx" ); assert.deepEqual( button.button( "option", "label" ), "xxx" );
} ); } );
test( "label, default, with input type submit", function() { QUnit.test( "label, default, with input type submit", function( assert ) {
expect( 2 ); assert.expect( 2 );
var button = $( "#submit" ).button(); var button = $( "#submit" ).button();
deepEqual( button.val(), "Label" ); assert.deepEqual( button.val(), "Label" );
deepEqual( button.button( "option", "label" ), "Label" ); assert.deepEqual( button.button( "option", "label" ), "Label" );
} ); } );
test( "label, explicit value, with input type submit", function() { QUnit.test( "label, explicit value, with input type submit", function( assert ) {
expect( 2 ); assert.expect( 2 );
var button = $( "#submit" ).button( { var button = $( "#submit" ).button( {
label: "xxx" label: "xxx"
} ); } );
deepEqual( button.val(), "xxx" ); assert.deepEqual( button.val(), "xxx" );
deepEqual( button.button( "option", "label" ), "xxx" ); assert.deepEqual( button.button( "option", "label" ), "xxx" );
} ); } );
test( "icon", function( assert ) { QUnit.test( "icon", function( assert ) {
expect( 4 ); assert.expect( 4 );
var button = $( "#button" ).button( { var button = $( "#button" ).button( {
showLabel: false, showLabel: false,
icon: "iconclass" icon: "iconclass"
@ -122,18 +123,18 @@ test( "icon", function( assert ) {
icon = button.find( ".ui-icon" ); icon = button.find( ".ui-icon" );
assert.hasClasses( icon, "iconclass" ); assert.hasClasses( icon, "iconclass" );
equal( icon.length, 1, "button with icon option set has icon" ); assert.equal( icon.length, 1, "button with icon option set has icon" );
button.button( "option", "icon", false ); button.button( "option", "icon", false );
equal( button.find( ".ui-icon" ).length, 0, "setting icon to false removes the icon" ); assert.equal( button.find( ".ui-icon" ).length, 0, "setting icon to false removes the icon" );
button.button( "option", "icon", "iconclass" ); button.button( "option", "icon", "iconclass" );
ok( button.find( ".ui-icon" ).length, "setting icon to a value adds the icon" ); assert.ok( button.find( ".ui-icon" ).length, "setting icon to a value adds the icon" );
} ); } );
test( "icon position", function( assert ) { QUnit.test( "icon position", function( assert ) {
expect( 22 ); assert.expect( 22 );
var button = $( "#button" ).button( { var button = $( "#button" ).button( {
icon: "ui-icon-gear" icon: "ui-icon-gear"
@ -141,41 +142,41 @@ test( "icon position", function( assert ) {
icon = button.find( ".ui-icon" ), icon = button.find( ".ui-icon" ),
space = button.find( ".ui-button-icon-space" ); space = button.find( ".ui-button-icon-space" );
equal( icon.length, 1, "button with icon option set has icon" ); assert.equal( icon.length, 1, "button with icon option set has icon" );
equal( button.button( "option", "iconPosition" ), "beginning", assert.equal( button.button( "option", "iconPosition" ), "beginning",
"Button has iconPosition beginning by default" ); "Button has iconPosition beginning by default" );
equal( button.contents()[ 0 ], icon[ 0 ], "icon is prepended when position is begining" ); assert.equal( button.contents()[ 0 ], icon[ 0 ], "icon is prepended when position is begining" );
equal( icon.next()[ 0 ], space[ 0 ], "icon is followed by a space when position is begining" ); assert.equal( icon.next()[ 0 ], space[ 0 ], "icon is followed by a space when position is begining" );
equal( space.length, 1, assert.equal( space.length, 1,
"ui-button-icon-space contains a breaking space iconPosition:beginning" ); "ui-button-icon-space contains a breaking space iconPosition:beginning" );
assert.lacksClasses( icon, "ui-widget-icon-block" ); assert.lacksClasses( icon, "ui-widget-icon-block" );
button.button( "option", "iconPosition", "end" ); button.button( "option", "iconPosition", "end" );
icon = button.find( ".ui-icon" ); icon = button.find( ".ui-icon" );
space = button.find( ".ui-button-icon-space" ); space = button.find( ".ui-button-icon-space" );
equal( icon.length, 1, "Changing position to end does not re-create or duplicate icon" ); assert.equal( icon.length, 1, "Changing position to end does not re-create or duplicate icon" );
equal( button.button( "option", "iconPosition" ), "end", "Button has iconPosition end" ); assert.equal( button.button( "option", "iconPosition" ), "end", "Button has iconPosition end" );
equal( button.contents().last()[ 0 ], icon[ 0 ], "icon is appended when position is end" ); assert.equal( button.contents().last()[ 0 ], icon[ 0 ], "icon is appended when position is end" );
equal( icon.prev()[ 0 ], space[ 0 ], "icon is preceeded by a space when position is end" ); assert.equal( icon.prev()[ 0 ], space[ 0 ], "icon is preceeded by a space when position is end" );
equal( space.length, 1, assert.equal( space.length, 1,
"ui-button-icon-space contains a breaking space iconPosition:beginning" ); "ui-button-icon-space contains a breaking space iconPosition:beginning" );
assert.lacksClasses( icon, "ui-widget-icon-block" ); assert.lacksClasses( icon, "ui-widget-icon-block" );
button.button( "option", "iconPosition", "top" ); button.button( "option", "iconPosition", "top" );
icon = button.find( ".ui-icon" ); icon = button.find( ".ui-icon" );
equal( icon.length, 1, "Changing position to top does not re-create or duplicate icon" ); assert.equal( icon.length, 1, "Changing position to top does not re-create or duplicate icon" );
equal( button.button( "option", "iconPosition" ), "top", "Button has iconPosition top" ); assert.equal( button.button( "option", "iconPosition" ), "top", "Button has iconPosition top" );
equal( button.contents()[ 0 ], icon[ 0 ], "icon is prepended when position is top" ); assert.equal( button.contents()[ 0 ], icon[ 0 ], "icon is prepended when position is top" );
ok( !button.find( "ui-button-icon-space" ).length, assert.ok( !button.find( "ui-button-icon-space" ).length,
"Button should not have an iconSpace with position: top" ); "Button should not have an iconSpace with position: top" );
assert.hasClasses( icon, "ui-widget-icon-block" ); assert.hasClasses( icon, "ui-widget-icon-block" );
button.button( "option", "iconPosition", "bottom" ); button.button( "option", "iconPosition", "bottom" );
icon = button.find( ".ui-icon" ); icon = button.find( ".ui-icon" );
equal( icon.length, 1, "Changing position to bottom does not re-create or duplicate icon" ); assert.equal( icon.length, 1, "Changing position to bottom does not re-create or duplicate icon" );
equal( button.button( "option", "iconPosition" ), "bottom", "Button has iconPosition top" ); assert.equal( button.button( "option", "iconPosition" ), "bottom", "Button has iconPosition top" );
equal( button.contents().last()[ 0 ], icon[ 0 ], "icon is prepended when position is bottom" ); assert.equal( button.contents().last()[ 0 ], icon[ 0 ], "icon is prepended when position is bottom" );
ok( !button.find( "ui-button-icon-space" ).length, assert.ok( !button.find( "ui-button-icon-space" ).length,
"Button should not have an iconSpace with position: bottom" ); "Button should not have an iconSpace with position: bottom" );
assert.hasClasses( icon, "ui-widget-icon-block" ); assert.hasClasses( icon, "ui-widget-icon-block" );

View File

@ -1,12 +1,13 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/widgets/checkboxradio" "ui/widgets/checkboxradio"
], function( $ ) { ], function( QUnit, $ ) {
module( "Checkboxradio: core" ); QUnit.module( "Checkboxradio: core" );
test( "Checkbox - Initial class structure", function( assert ) { QUnit.test( "Checkbox - Initial class structure", function( assert ) {
expect( 2 ); assert.expect( 2 );
var input = $( "#check" ), var input = $( "#check" ),
label = $( "label[for=check]" ); label = $( "label[for=check]" );
@ -15,8 +16,8 @@ test( "Checkbox - Initial class structure", function( assert ) {
assert.hasClasses( label, "ui-button ui-widget ui-checkboxradio-label ui-corner-all" ); assert.hasClasses( label, "ui-button ui-widget ui-checkboxradio-label ui-corner-all" );
} ); } );
test( "Radios - Initial class structure", function( assert ) { QUnit.test( "Radios - Initial class structure", function( assert ) {
expect( 6 ); assert.expect( 6 );
var inputs = $( "#radio0 input" ), var inputs = $( "#radio0 input" ),
labels = $( "#radio0 label" ); labels = $( "#radio0 label" );
@ -29,12 +30,13 @@ test( "Radios - Initial class structure", function( assert ) {
} ); } );
} ); } );
asyncTest( "Ensure checked after single click on checkbox label button", function( assert ) { QUnit.test( "Ensure checked after single click on checkbox label button", function( assert ) {
expect( 2 ); var ready = assert.async();
assert.expect( 2 );
$( "#check2" ).checkboxradio().change( function() { $( "#check2" ).checkboxradio().change( function() {
var label = $( this ).checkboxradio( "widget" ); var label = $( this ).checkboxradio( "widget" );
ok( this.checked, "checked ok" ); assert.ok( this.checked, "checked ok" );
assert.hasClasses( label, "ui-state-active" ); assert.hasClasses( label, "ui-state-active" );
} ); } );
@ -45,12 +47,12 @@ asyncTest( "Ensure checked after single click on checkbox label button", functio
// tracked down, this delay will have to do. // tracked down, this delay will have to do.
setTimeout( function() { setTimeout( function() {
$( "#check2" ).checkboxradio( "widget" ).simulate( "click" ); $( "#check2" ).checkboxradio( "widget" ).simulate( "click" );
start(); ready();
} ); } );
} ); } );
test( "Handle form association via form attribute", function( assert ) { QUnit.test( "Handle form association via form attribute", function( assert ) {
expect( 4 ); assert.expect( 4 );
var radio1 = $( "#crazy-form-1" ).checkboxradio(); var radio1 = $( "#crazy-form-1" ).checkboxradio();
var radio1Label = radio1.checkboxradio( "widget" ); var radio1Label = radio1.checkboxradio( "widget" );
@ -58,8 +60,8 @@ test( "Handle form association via form attribute", function( assert ) {
var radio2Label = radio2.checkboxradio( "widget" ); var radio2Label = radio2.checkboxradio( "widget" );
radio2.change( function() { radio2.change( function() {
ok( this.checked, "#2 checked" ); assert.ok( this.checked, "#2 checked" );
ok( !radio1[ 0 ].checked, "#1 not checked" ); assert.ok( !radio1[ 0 ].checked, "#1 not checked" );
assert.hasClasses( radio2Label, "ui-state-active" ); assert.hasClasses( radio2Label, "ui-state-active" );
assert.lacksClasses( radio1Label, "ui-state-active" ); assert.lacksClasses( radio1Label, "ui-state-active" );
@ -68,8 +70,8 @@ test( "Handle form association via form attribute", function( assert ) {
radio2Label.simulate( "click" ); radio2Label.simulate( "click" );
} ); } );
test( "Checkbox creation requires a label, and finds it in all cases", function( assert ) { QUnit.test( "Checkbox creation requires a label, and finds it in all cases", function( assert ) {
expect( 7 ); assert.expect( 7 );
var groups = [ var groups = [
"<span><label for='t7092a'></label><input type='checkbox' id='t7092a'></span>", "<span><label for='t7092a'></label><input type='checkbox' id='t7092a'></span>",
"<span><input type='checkbox' id='t7092b'><label for='t7092b'></label></span>", "<span><input type='checkbox' id='t7092b'><label for='t7092b'></label></span>",
@ -88,8 +90,8 @@ test( "Checkbox creation requires a label, and finds it in all cases", function(
} ); } );
} ); } );
test( "Calling checkboxradio on an unsupported element throws an error", function( assert ) { QUnit.test( "Calling checkboxradio on an unsupported element throws an error", function( assert ) {
expect( 2 ); assert.expect( 2 );
var errorMessage = var errorMessage =
"Can't create checkboxradio on element.nodeName=div and element.type=undefined"; "Can't create checkboxradio on element.nodeName=div and element.type=undefined";
@ -117,8 +119,8 @@ test( "Calling checkboxradio on an unsupported element throws an error", functio
); );
} ); } );
test( "Calling checkboxradio on an input with no label throws an error", function( assert ) { QUnit.test( "Calling checkboxradio on an input with no label throws an error", function( assert ) {
expect( 1 ); assert.expect( 1 );
var errorMessage = "No label found for checkboxradio widget"; var errorMessage = "No label found for checkboxradio widget";
var error = new Error( errorMessage ); var error = new Error( errorMessage );

View File

@ -1,14 +1,16 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/widgets/checkboxradio" "ui/widgets/checkboxradio"
], function( $ ) { ], function( QUnit, $ ) {
module( "Checkboxradio: events" ); QUnit.module( "Checkboxradio: events" );
asyncTest( QUnit.test(
"Resetting a checkbox's form should refresh the visual state of the checkbox", "Resetting a checkbox's form should refresh the visual state of the checkbox",
function( assert ) { function( assert ) {
expect( 2 ); var ready = assert.async();
assert.expect( 2 );
var form = $( "<form>" + var form = $( "<form>" +
"<label for='c1'></label><input id='c1' type='checkbox' checked>" + "<label for='c1'></label><input id='c1' type='checkbox' checked>" +
"</form>" ), "</form>" ),
@ -22,20 +24,21 @@ asyncTest(
setTimeout( function() { setTimeout( function() {
assert.hasClasses( widget, "ui-state-active" ); assert.hasClasses( widget, "ui-state-active" );
start(); ready();
}, 1 ); }, 1 );
} }
); );
asyncTest( "Checkbox shows focus when using keyboard navigation", function( assert ) { QUnit.test( "Checkbox shows focus when using keyboard navigation", function( assert ) {
expect( 2 ); var ready = assert.async();
assert.expect( 2 );
var check = $( "#check" ).checkboxradio(), var check = $( "#check" ).checkboxradio(),
label = $( "label[for='check']" ); label = $( "label[for='check']" );
assert.lacksClasses( label, "ui-state-focus" ); assert.lacksClasses( label, "ui-state-focus" );
check.focus(); check.focus();
setTimeout( function() { setTimeout( function() {
assert.hasClasses( label, "ui-state-focus" ); assert.hasClasses( label, "ui-state-focus" );
start(); ready();
} ); } );
} ); } );

View File

@ -1,29 +1,30 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/widgets/checkboxradio" "ui/widgets/checkboxradio"
], function( $ ) { ], function( QUnit, $ ) {
module( "Checkboxradio: methods" ); QUnit.module( "Checkboxradio: methods" );
$.each( [ "checkbox", "radio" ], function( index, value ) { $.each( [ "checkbox", "radio" ], function( index, value ) {
test( value + ": refresh", function( assert ) { QUnit.test( value + ": refresh", function( assert ) {
var widget, icon, var widget, icon,
checkbox = value === "checkbox", checkbox = value === "checkbox",
input = $( "#" + value + "-method-refresh" ); input = $( "#" + value + "-method-refresh" );
expect( checkbox ? 11 : 8 ); assert.expect( checkbox ? 11 : 8 );
input.checkboxradio(); input.checkboxradio();
widget = input.checkboxradio( "widget" ); widget = input.checkboxradio( "widget" );
icon = widget.find( ".ui-icon" ); icon = widget.find( ".ui-icon" );
strictEqual( icon.length, 1, assert.strictEqual( icon.length, 1,
"There is initally one icon" ); "There is initally one icon" );
icon.remove(); icon.remove();
input.checkboxradio( "refresh" ); input.checkboxradio( "refresh" );
icon = widget.find( ".ui-icon" ); icon = widget.find( ".ui-icon" );
strictEqual( icon.length, 1, assert.strictEqual( icon.length, 1,
"Icon is recreated on refresh if absent" ); "Icon is recreated on refresh if absent" );
assert.hasClasses( icon, "ui-icon-blank" ); assert.hasClasses( icon, "ui-icon-blank" );
if ( checkbox ) { if ( checkbox ) {
@ -48,49 +49,49 @@ $.each( [ "checkbox", "radio" ], function( index, value ) {
assert.lacksClasses( widget, "ui-checkboxradio-checked" ); assert.lacksClasses( widget, "ui-checkboxradio-checked" );
} ); } );
test( value + ": destroy", function( assert ) { QUnit.test( value + ": destroy", function( assert ) {
expect( 1 ); assert.expect( 1 );
assert.domEqual( "#" + value + "-method-destroy", function() { assert.domEqual( "#" + value + "-method-destroy", function() {
$( "#" + value + "-method-destroy" ).checkboxradio().checkboxradio( "destroy" ); $( "#" + value + "-method-destroy" ).checkboxradio().checkboxradio( "destroy" );
} ); } );
} ); } );
test( value + ": disable / enable", function( assert ) { QUnit.test( value + ": disable / enable", function( assert ) {
expect( 4 ); assert.expect( 4 );
var input = $( "#" + value + "-method-disable" ), var input = $( "#" + value + "-method-disable" ),
widget = input.checkboxradio().checkboxradio( "widget" ); widget = input.checkboxradio().checkboxradio( "widget" );
input.checkboxradio( "disable" ); input.checkboxradio( "disable" );
assert.hasClasses( widget, "ui-state-disabled" ); assert.hasClasses( widget, "ui-state-disabled" );
strictEqual( input.is( ":disabled" ), true, assert.strictEqual( input.is( ":disabled" ), true,
value + " is disabled when disable is called" ); value + " is disabled when disable is called" );
input.checkboxradio( "enable" ); input.checkboxradio( "enable" );
assert.lacksClasses( widget, "ui-state-disabled" ); assert.lacksClasses( widget, "ui-state-disabled" );
strictEqual( input.is( ":disabled" ), false, assert.strictEqual( input.is( ":disabled" ), false,
value + " has disabled prop removed when enable is called" ); value + " has disabled prop removed when enable is called" );
} ); } );
test( value + ": widget returns the label", function() { QUnit.test( value + ": widget returns the label", function( assert ) {
expect( 1 ); assert.expect( 1 );
var input = $( "#" + value + "-method-refresh" ), var input = $( "#" + value + "-method-refresh" ),
label = $( "#" + value + "-method-refresh-label" ); label = $( "#" + value + "-method-refresh-label" );
input.checkboxradio(); input.checkboxradio();
strictEqual( input.checkboxradio( "widget" )[ 0 ], label[ 0 ], assert.strictEqual( input.checkboxradio( "widget" )[ 0 ], label[ 0 ],
"widget method returns label" ); "widget method returns label" );
} ); } );
} ); } );
test( "Input wrapped in a label preserved on refresh", function() { QUnit.test( "Input wrapped in a label preserved on refresh", function( assert ) {
var input = $( "#label-with-no-for" ).checkboxradio(), var input = $( "#label-with-no-for" ).checkboxradio(),
element = input.checkboxradio( "widget" ); element = input.checkboxradio( "widget" );
expect( 1 ); assert.expect( 1 );
input.checkboxradio( "refresh" ); input.checkboxradio( "refresh" );
strictEqual( input.parent()[ 0 ], element[ 0 ], "Input preserved" ); assert.strictEqual( input.parent()[ 0 ], element[ 0 ], "Input preserved" );
} ); } );
} ); } );

View File

@ -1,25 +1,26 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/widgets/checkboxradio" "ui/widgets/checkboxradio"
], function( $ ) { ], function( QUnit, $ ) {
module( "Checkboxradio: options" ); QUnit.module( "Checkboxradio: options" );
function assertDisabled( checkbox, assert ) { function assertDisabled( checkbox, assert ) {
assert.hasClasses( checkbox.checkboxradio( "widget" ), "ui-state-disabled", assert.hasClasses( checkbox.checkboxradio( "widget" ), "ui-state-disabled",
"label gets ui-state-disabled" ); "label gets ui-state-disabled" );
strictEqual( checkbox.is( ":disabled" ), true, "checkbox is disabled" ); assert.strictEqual( checkbox.is( ":disabled" ), true, "checkbox is disabled" );
} }
function assertEnabled( checkbox, assert ) { function assertEnabled( checkbox, assert ) {
assert.lacksClasses( checkbox.checkboxradio( "widget" ), "ui-state-disabled", assert.lacksClasses( checkbox.checkboxradio( "widget" ), "ui-state-disabled",
"label has ui-state-disabled removed when disabled set to false" ); "label has ui-state-disabled removed when disabled set to false" );
strictEqual( checkbox.is( ":disabled" ), false, assert.strictEqual( checkbox.is( ":disabled" ), false,
"checkbox has disabled prop removed when disabled set to false" ); "checkbox has disabled prop removed when disabled set to false" );
} }
test( "disabled", function( assert ) { QUnit.test( "disabled", function( assert ) {
expect( 6 ); assert.expect( 6 );
var checkbox = $( "#checkbox-option-disabled" ); var checkbox = $( "#checkbox-option-disabled" );
checkbox.checkboxradio( { checkbox.checkboxradio( {
@ -35,8 +36,8 @@ test( "disabled", function( assert ) {
assertDisabled( checkbox, assert ); assertDisabled( checkbox, assert );
} ); } );
test( "disabled - prop true on init", function( assert ) { QUnit.test( "disabled - prop true on init", function( assert ) {
expect( 2 ); assert.expect( 2 );
var checkbox = $( "#checkbox-option-disabled" ); var checkbox = $( "#checkbox-option-disabled" );
checkbox.prop( "disabled", true ); checkbox.prop( "disabled", true );
@ -45,8 +46,8 @@ test( "disabled - prop true on init", function( assert ) {
assertDisabled( checkbox, assert ); assertDisabled( checkbox, assert );
} ); } );
test( "disabled - explicit null value, checks the DOM", function( assert ) { QUnit.test( "disabled - explicit null value, checks the DOM", function( assert ) {
expect( 2 ); assert.expect( 2 );
var checkbox = $( "#checkbox-option-disabled" ); var checkbox = $( "#checkbox-option-disabled" );
checkbox.prop( "disabled", true ); checkbox.prop( "disabled", true );
@ -56,8 +57,8 @@ test( "disabled - explicit null value, checks the DOM", function( assert ) {
assertDisabled( checkbox, assert ); assertDisabled( checkbox, assert );
} ); } );
function assertNoIcon( checkbox ) { function assertNoIcon( assert, checkbox ) {
strictEqual( checkbox.checkboxradio( "widget" ).find( "span.ui-icon" ).length, 0, assert.strictEqual( checkbox.checkboxradio( "widget" ).find( "span.ui-icon" ).length, 0,
"Label does not contain an icon" ); "Label does not contain an icon" );
} }
@ -65,83 +66,83 @@ function assertIcon( checkbox, icon, assert ) {
var iconElement = checkbox.checkboxradio( "widget" ).find( ".ui-icon" ); var iconElement = checkbox.checkboxradio( "widget" ).find( ".ui-icon" );
icon = icon || "blank"; icon = icon || "blank";
strictEqual( iconElement.length, 1, assert.strictEqual( iconElement.length, 1,
"Label contains icon" ); "Label contains icon" );
assert.hasClasses( iconElement, "ui-checkboxradio-icon ui-corner-all ui-icon " + assert.hasClasses( iconElement, "ui-checkboxradio-icon ui-corner-all ui-icon " +
"ui-icon-background ui-icon-" + icon, "ui-icon-background ui-icon-" + icon,
"Icon has proper classes" ); "Icon has proper classes" );
if ( icon === "blank" ) { if ( icon === "blank" ) {
assert.lacksClasses( iconElement, "ui-icon-check ui-state-highlight" ); assert.lacksClasses( iconElement, "ui-icon-check ui-state-checked" );
} }
} }
test( "icon - false on init", function() { QUnit.test( "icon - false on init", function( assert ) {
var checkbox = $( "#checkbox-option-icon" ); var checkbox = $( "#checkbox-option-icon" );
expect( 1 ); assert.expect( 1 );
checkbox.checkboxradio( { icon: false } ); checkbox.checkboxradio( { icon: false } );
assertNoIcon( checkbox ); assertNoIcon( assert, checkbox );
} ); } );
test( "icon - default unchecked", function( assert ) { QUnit.test( "icon - default unchecked", function( assert ) {
var checkbox = $( "#checkbox-option-icon" ); var checkbox = $( "#checkbox-option-icon" );
expect( 3 ); assert.expect( 3 );
checkbox.checkboxradio(); checkbox.checkboxradio();
assertIcon( checkbox, false, assert ); assertIcon( checkbox, false, assert );
} ); } );
test( "icon - default checked", function( assert ) { QUnit.test( "icon - default checked", function( assert ) {
var checkbox = $( "#checkbox-option-icon" ).attr( "checked", true ); var checkbox = $( "#checkbox-option-icon" ).attr( "checked", true );
expect( 2 ); assert.expect( 2 );
checkbox.checkboxradio(); checkbox.checkboxradio();
assertIcon( checkbox, "check ui-state-highlight", assert ); assertIcon( checkbox, "check ui-state-checked", assert );
} ); } );
test( "icon", function( assert ) { QUnit.test( "icon", function( assert ) {
var checkbox = $( "#checkbox-option-icon" ); var checkbox = $( "#checkbox-option-icon" );
expect( 9 ); assert.expect( 9 );
checkbox.prop( "checked", true ); checkbox.prop( "checked", true );
checkbox.checkboxradio(); checkbox.checkboxradio();
assertIcon( checkbox, "check ui-state-highlight", assert ); assertIcon( checkbox, "check ui-state-checked", assert );
checkbox.checkboxradio( "option", "icon", false ); checkbox.checkboxradio( "option", "icon", false );
assertNoIcon( checkbox ); assertNoIcon( assert, checkbox );
checkbox.checkboxradio( "option", "icon", true ); checkbox.checkboxradio( "option", "icon", true );
assertIcon( checkbox, "check ui-state-highlight", assert ); assertIcon( checkbox, "check ui-state-checked", assert );
checkbox.checkboxradio( "option", "icon", false ); checkbox.checkboxradio( "option", "icon", false );
assertNoIcon( checkbox ); assertNoIcon( assert, checkbox );
checkbox.checkboxradio( "option", "icon", true ); checkbox.checkboxradio( "option", "icon", true );
checkbox.prop( "checked", false ).checkboxradio( "refresh" ); checkbox.prop( "checked", false ).checkboxradio( "refresh" );
assertIcon( checkbox, false, assert ); assertIcon( checkbox, false, assert );
} ); } );
test( "label - default", function() { QUnit.test( "label - default", function( assert ) {
var checkbox = $( "#checkbox-option-label" ), var checkbox = $( "#checkbox-option-label" ),
widget; widget;
expect( 2 ); assert.expect( 2 );
checkbox.checkboxradio(); checkbox.checkboxradio();
widget = checkbox.checkboxradio( "widget" ); widget = checkbox.checkboxradio( "widget" );
strictEqual( checkbox.checkboxradio( "option", "label" ), assert.strictEqual( checkbox.checkboxradio( "option", "label" ),
"checkbox label", "When no value passed on create text from dom is used for option" ); "checkbox label", "When no value passed on create text from dom is used for option" );
strictEqual( $.trim( widget.text() ), assert.strictEqual( $.trim( widget.text() ),
"checkbox label", "When no value passed on create text from dom is used in dom" ); "checkbox label", "When no value passed on create text from dom is used in dom" );
} ); } );
test( "label - explicit value", function() { QUnit.test( "label - explicit value", function( assert ) {
expect( 5 ); assert.expect( 5 );
var checkbox = $( "#checkbox-option-label" ).checkboxradio( { var checkbox = $( "#checkbox-option-label" ).checkboxradio( {
label: "foo" label: "foo"
} ), } ),
@ -149,23 +150,23 @@ test( "label - explicit value", function() {
icon = widget.find( ".ui-icon" ), icon = widget.find( ".ui-icon" ),
iconSpace = widget.find( ".ui-checkboxradio-icon-space" ); iconSpace = widget.find( ".ui-checkboxradio-icon-space" );
strictEqual( checkbox.checkboxradio( "option", "label" ), assert.strictEqual( checkbox.checkboxradio( "option", "label" ),
"foo", "When value is passed on create value is used for option" ); "foo", "When value is passed on create value is used for option" );
strictEqual( $.trim( widget.text() ), assert.strictEqual( $.trim( widget.text() ),
"foo", "When value is passed on create value is used in dom" ); "foo", "When value is passed on create value is used in dom" );
strictEqual( icon.length, 1, assert.strictEqual( icon.length, 1,
"Icon is preserved when label is set on init when wrapped in label" ); "Icon is preserved when label is set on init when wrapped in label" );
strictEqual( iconSpace.length, 1, assert.strictEqual( iconSpace.length, 1,
"Icon space is preserved when label is set on init when wrapped in label" ); "Icon space is preserved when label is set on init when wrapped in label" );
strictEqual( $( "#checkbox-option-label" ).length, 1, assert.strictEqual( $( "#checkbox-option-label" ).length, 1,
"Element is preserved when label is set on init when wrapped in label" ); "Element is preserved when label is set on init when wrapped in label" );
} ); } );
test( "label - explicit null value", function() { QUnit.test( "label - explicit null value", function( assert ) {
var checkbox = $( "#checkbox-option-label" ), var checkbox = $( "#checkbox-option-label" ),
widget; widget;
expect( 2 ); assert.expect( 2 );
// The default null is a special value which means to check the DOM. // The default null is a special value which means to check the DOM.
// We need to make sure that the option never return null. // We need to make sure that the option never return null.
@ -174,15 +175,15 @@ test( "label - explicit null value", function() {
label: null label: null
} ); } );
widget = checkbox.checkboxradio( "widget" ); widget = checkbox.checkboxradio( "widget" );
strictEqual( checkbox.checkboxradio( "option", "label" ), assert.strictEqual( checkbox.checkboxradio( "option", "label" ),
"checkbox label", "When null is passed on create text from dom is used for option" ); "checkbox label", "When null is passed on create text from dom is used for option" );
strictEqual( $.trim( widget.text() ), assert.strictEqual( $.trim( widget.text() ),
"checkbox label", "When null is passed on create text from dom is used in dom" ); "checkbox label", "When null is passed on create text from dom is used in dom" );
} ); } );
test( "label", function() { QUnit.test( "label", function( assert ) {
expect( 4 ); assert.expect( 4 );
var checkbox = $( "#checkbox-option-label" ), var checkbox = $( "#checkbox-option-label" ),
widget; widget;
@ -190,15 +191,15 @@ test( "label", function() {
checkbox.checkboxradio(); checkbox.checkboxradio();
widget = checkbox.checkboxradio( "widget" ); widget = checkbox.checkboxradio( "widget" );
checkbox.checkboxradio( "option", "label", "bar" ); checkbox.checkboxradio( "option", "label", "bar" );
strictEqual( checkbox.checkboxradio( "option", "label" ), assert.strictEqual( checkbox.checkboxradio( "option", "label" ),
"bar", "When value is passed value is used for option" ); "bar", "When value is passed value is used for option" );
strictEqual( $.trim( widget.text() ), assert.strictEqual( $.trim( widget.text() ),
"bar", "When value is passed value is used in dom" ); "bar", "When value is passed value is used in dom" );
checkbox.checkboxradio( "option", "label", null ); checkbox.checkboxradio( "option", "label", null );
strictEqual( checkbox.checkboxradio( "option", "label" ), assert.strictEqual( checkbox.checkboxradio( "option", "label" ),
"bar", "When null is passed text from dom is used for option" ); "bar", "When null is passed text from dom is used for option" );
strictEqual( $.trim( widget.text() ), assert.strictEqual( $.trim( widget.text() ),
"bar", "When null is passed text from dom is used in dom" ); "bar", "When null is passed text from dom is used in dom" );
} ); } );

View File

@ -3,7 +3,8 @@ define( [
"ui/widgets/controlgroup", "ui/widgets/controlgroup",
"ui/widgets/checkboxradio", "ui/widgets/checkboxradio",
"ui/widgets/selectmenu", "ui/widgets/selectmenu",
"ui/widgets/button" "ui/widgets/button",
"ui/widgets/spinner"
], function( common ) { ], function( common ) {
common.testWidget( "controlgroup", { common.testWidget( "controlgroup", {

View File

@ -36,6 +36,54 @@
<option>Slow</option> <option>Slow</option>
</select> </select>
</div> </div>
<select id="select-sanatize">
<option>Fast</option>
<option>Medium</option>
<option>Slow</option>
</select>
<div class="controlgroup-pre">
<select id="select-pre">
<option>Fast</option>
<option>Medium</option>
<option>Slow</option>
</select>
<button>Button with icon on the bottom</button>
</div>
<div class="controlgroup-refresh">
<select id="select-refresh">
<option>Fast</option>
<option>Medium</option>
<option>Slow</option>
</select>
<label class="ui-controlgroup-label">Label</label>
<button>Button with icon on the bottom</button>
</div>
<div class="controlgroup-single-select">
<select id="select-single">
<option>Fast</option>
<option>Medium</option>
<option>Slow</option>
</select>
</div>
<div class="controlgroup-single-button">
<button class="single-button">button</button>
</div>
<div class="controlgroup-class-key-init">
<select id="class-key-init-child">
<option>Option 1</option>
<option>Option 2</option>
</select>
</div>
<div class="controlgroup-class-key-dupe">
<select id="class-key-dupe-first">
<option>Option 1</option>
<option>Option 2</option>
</select>
<select id="class-key-dupe-second">
<option>Option 1</option>
<option>Option 2</option>
</select>
</div>
</div> </div>
</body> </body>
</html> </html>

View File

@ -1,15 +1,17 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/widgets/controlgroup", "ui/widgets/controlgroup",
"ui/widgets/checkboxradio", "ui/widgets/checkboxradio",
"ui/widgets/selectmenu", "ui/widgets/selectmenu",
"ui/widgets/button" "ui/widgets/button",
], function( $ ) { "ui/widgets/spinner"
], function( QUnit, $ ) {
module( "Controlgroup: Core" ); QUnit.module( "Controlgroup: Core" );
test( "selectmenu: open/close corners", function( assert ) { QUnit.test( "selectmenu: open/close corners", function( assert ) {
expect( 12 ); assert.expect( 12 );
var element = $( ".controlgroup" ).controlgroup(), var element = $( ".controlgroup" ).controlgroup(),
selects = element.find( "select" ), selects = element.find( "select" ),
selectButton = selects.eq( 0 ).selectmenu( "widget" ); selectButton = selects.eq( 0 ).selectmenu( "widget" );
@ -64,8 +66,8 @@ test( "selectmenu: open/close corners", function( assert ) {
"vertical: Last selectmenu gets ui-corner-bottom when closed" ); "vertical: Last selectmenu gets ui-corner-bottom when closed" );
} ); } );
test( "selectmenu: controlgroupLabel", function( assert ) { QUnit.test( "selectmenu: controlgroupLabel", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( ".controlgroup" ).controlgroup(); var element = $( ".controlgroup" ).controlgroup();
var label = element.find( ".ui-controlgroup-label" ); var label = element.find( ".ui-controlgroup-label" );
@ -73,4 +75,126 @@ test( "selectmenu: controlgroupLabel", function( assert ) {
assert.hasClasses( label.find( "span" ), "ui-controlgroup-label-contents" ); assert.hasClasses( label.find( "span" ), "ui-controlgroup-label-contents" );
} ); } );
var assertSanatized = function( assert, initClasses, expectedClasses, message ) {
var selectmenu = $( "#select-sanatize" ).selectmenu( {
classes: {
"ui-selectmenu-button-open": initClasses
}
} ).selectmenu( "instance" );
var classes = {
"ui-selectmenu-button-open": "ui-corner-top"
};
var result = $.ui.controlgroup.prototype._resolveClassesValues( classes, selectmenu );
assert.deepEqual( result, {
"ui-selectmenu-button-open": expectedClasses + " ui-corner-top"
}, message );
};
QUnit.test( "_resolveClassesValues", function( assert ) {
assert.expect( 6 );
assertSanatized( assert, "bar ui-corner-bottom", "bar", "Single corner class removed end" );
assertSanatized( assert, "ui-corner-bottom bar", "bar", "Single corner class removed beginning" );
assertSanatized( assert, "bar ui-corner-bottom ui-corner-left", "bar", "Multiple corner classes removed end" );
assertSanatized( assert, "ui-corner-bottom ui-corner-left bar", "bar", "Multiple corner classes removed beginning" );
assertSanatized( assert, "bar ui-corner-bottom ui-corner-left foo", "bar foo", "Multiple corner class removed middle" );
assertSanatized( assert, "bar", "bar", "No corner classes" );
} );
QUnit.test( "Single controlgroup select - horizontal", function( assert ) {
assert.expect( 4 );
var group = $( ".controlgroup-single-select" ).controlgroup();
var select = group.find( ".ui-selectmenu-button" );
assert.hasClasses( select, "ui-corner-all" );
assert.lacksClasses( select,
"ui-corner-left ui-corner-right ui-corner-top ui-corner-left" +
" ui-corner-tr ui-corner-tl ui-corner-bl ui corner-br" );
group.find( "select" ).selectmenu( "open" );
assert.hasClasses( select, "ui-corner-top" );
assert.lacksClasses( select,
"ui-corner-left ui-corner-right ui-corner-all ui-corner-left" +
" ui-corner-tr ui-corner-tl ui-corner-bl ui corner-br" );
} );
QUnit.test( "Single controlgroup select - vertical", function( assert ) {
assert.expect( 4 );
var group = $( ".controlgroup-single-select" ).controlgroup( {
direction: "verticle"
} );
var select = group.find( ".ui-selectmenu-button" );
assert.hasClasses( select, "ui-corner-all" );
assert.lacksClasses( select,
"ui-corner-left ui-corner-right ui-corner-top ui-corner-left" +
" ui-corner-tr ui-corner-tl ui-corner-bl ui corner-br" );
group.find( "select" ).selectmenu( "open" );
assert.hasClasses( select, "ui-corner-top" );
assert.lacksClasses( select,
"ui-corner-left ui-corner-right ui-corner-all ui-corner-left" +
" ui-corner-tr ui-corner-tl ui-corner-bl ui corner-br" );
} );
QUnit.test( "Single controlgroup button - horizontal", function( assert ) {
assert.expect( 2 );
var group = $( ".controlgroup-single-button" ).controlgroup();
var button = group.find( "button" );
assert.hasClasses( button, "ui-corner-all" );
assert.lacksClasses( button,
"ui-corner-left ui-corner-right ui-corner-top ui-corner-left" +
" ui-corner-tr ui-corner-tl ui-corner-bl ui corner-br" );
} );
QUnit.test( "Single controlgroup button - vertical", function( assert ) {
assert.expect( 2 );
var group = $( ".controlgroup-single-button" ).controlgroup( {
direction: "verticle"
} );
var button = group.find( "button" );
assert.hasClasses( button, "ui-corner-all" );
assert.lacksClasses( button,
"ui-corner-left ui-corner-right ui-corner-top ui-corner-left" +
" ui-corner-tr ui-corner-tl ui-corner-bl ui corner-br" );
} );
QUnit.module( "Controlgroup: Non-empty class key", {
setup: function() {
this.classKey = $.ui.selectmenu.prototype.options.classes[ "ui-selectmenu-button-closed" ];
$.ui.selectmenu.prototype.options.classes[ "ui-selectmenu-button-closed" ] =
"something-custom";
},
teardown: function() {
$.ui.selectmenu.prototype.options.classes[ "ui-selectmenu-button-closed" ] = this.classKey;
}
} );
QUnit.test( "Controlgroup instantiates child widgets with correct options", function( assert ) {
assert.expect( 1 );
$( ".controlgroup-class-key-init" ).controlgroup();
assert.hasClasses( $( "#class-key-init-child" ).next(), "something-custom" );
} );
QUnit.test( "Controlgroup correctly assigns child widget classes options key", function( assert ) {
assert.expect( 2 );
$( ".controlgroup-class-key-dupe" ).controlgroup();
assert.strictEqual(
( $( "#class-key-dupe-first" )
.selectmenu( "option", "classes.ui-selectmenu-button-closed" )
.match( /something-custom/g ) || [] ).length, 1,
"Class 'something-custom' appears exactly once in the first widget's class key value" );
assert.strictEqual(
( $( "#class-key-dupe-second" )
.selectmenu( "option", "classes.ui-selectmenu-button-closed" )
.match( /something-custom/g ) || [] ).length, 1,
"Class 'something-custom' appears exactly once in the second widget's class key value" );
} );
} ); } );

View File

@ -1,42 +1,46 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/widgets/controlgroup", "ui/widgets/controlgroup",
"ui/widgets/checkboxradio", "ui/widgets/checkboxradio",
"ui/widgets/selectmenu", "ui/widgets/selectmenu",
"ui/widgets/button" "ui/widgets/button",
], function( $ ) { "ui/widgets/spinner"
], function( QUnit, $ ) {
module( "Controlgroup: methods" ); QUnit.module( "Controlgroup: methods" );
test( "destroy", function( assert ) { QUnit.test( "destroy", function( assert ) {
expect( 1 ); assert.expect( 1 );
assert.domEqual( ".controlgroup", function() { assert.domEqual( ".controlgroup", function() {
$( ".controlgroup" ).controlgroup().controlgroup( "destroy" ); $( ".controlgroup" ).controlgroup().controlgroup( "destroy" );
$( "#spinner" ).addClass( "ui-spinner-input" );
} ); } );
} ); } );
test( "disable", function( assert ) { QUnit.test( "disable", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( ".controlgroup" ).controlgroup().controlgroup( "disable" ); var element = $( ".controlgroup" ).controlgroup().controlgroup( "disable" );
assert.lacksClasses( element, "ui-state-disabled", assert.lacksClasses( element, "ui-state-disabled",
"The widget does not get the disabled class, because we disable each child widget" ); "The widget does not get the disabled class, because we disable each child widget" );
strictEqual( element.find( ".ui-state-disabled" ).length, 6, assert.strictEqual( element.find( ".ui-state-disabled" ).length, 9,
"Child widgets are disabled" ); "Child widgets are disabled" );
} ); } );
test( "enable", function( assert ) { QUnit.test( "enable", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( ".controlgroup" ).controlgroup().controlgroup( "enable" ); var element = $( ".controlgroup" ).controlgroup().controlgroup( "enable" );
assert.lacksClasses( element, "ui-state-disabled", assert.lacksClasses( element, "ui-state-disabled",
"ui-state-disabled is not present on widget after enabling" ); "ui-state-disabled is not present on widget after enabling" );
strictEqual( element.find( "ui-state-disabled" ).length, 0, assert.strictEqual( element.find( "ui-state-disabled" ).length, 0,
"Child widgets are disabled" ); "Child widgets are disabled" );
} ); } );
var tests = { var tests = {
"checkboxradio": "<input type='checkbox'>", "checkboxradio": "<input type='checkbox'>",
"selectmenu": "<select><option>foo</option></select>", "selectmenu": "<select><option>foo</option></select>",
"button": "<button>button text</button>" "button": "<button>button text</button>",
"spinner": "<input class='ui-spinner-input'>"
}, },
orientations = { orientations = {
"horizontal": [ "horizontal": [
@ -59,16 +63,16 @@ $.each( tests, function( widget, html ) {
// Check in both horizontal and vertical orientations // Check in both horizontal and vertical orientations
$.each( orientations, function( name, classes ) { $.each( orientations, function( name, classes ) {
test( "refresh: " + widget + ": " + name, function( assert ) { QUnit.test( "refresh: " + widget + ": " + name, function( assert ) {
expect( 41 ); assert.expect( 41 );
var i, control, currentClasses, var i, control, label, currentClasses,
controls = [], controls = [],
element = $( "<div>" ).controlgroup( { element = $( "<div>" ).controlgroup( {
direction: name direction: name
} ).appendTo( "body" ); } ).appendTo( "body" );
// checks the elements with in the controlgroup against the expected class list // Checks the elements with in the controlgroup against the expected class list
function checkCornerClasses( classList ) { function checkCornerClasses( classList ) {
for ( var j = 0; j < 4; j++ ) { for ( var j = 0; j < 4; j++ ) {
if ( classList[ j ] ) { if ( classList[ j ] ) {
@ -108,24 +112,24 @@ $.each( tests, function( widget, html ) {
// Add a label for each element and then append the element to the control group // Add a label for each element and then append the element to the control group
for ( i = 0; i < 4; i++ ) { for ( i = 0; i < 4; i++ ) {
control = $( html ).attr( "id", "id" + i ) control = $( html ).attr( "id", "id" + i );
.add( $( "<label>label text</label>" ).clone().attr( "for", "id" + i ) ); label = $( "<label>label text</label>" ).attr( "for", "id" + i );
controls.push( control ); controls.push( control );
element.append( control ); element.append( control, label );
} }
// Refresh the controlgroup now that its populated // Refresh the controlgroup now that its populated
element.controlgroup( "refresh" ); element.controlgroup( "refresh" );
for ( i = 0; i < 4; i++ ) { for ( i = 0; i < 4; i++ ) {
strictEqual( controls[ i ].is( ":ui-" + widget ), true, assert.strictEqual( controls[ i ].is( ":ui-" + widget ), true,
name + ": " + widget + " " + i + ": is a " + widget + " widget" ); name + ": " + widget + " " + i + ": is a " + widget + " widget" );
} }
// Check that we have the right classes // Check that we have the right classes
checkCornerClasses( classes ); checkCornerClasses( classes );
// hide each element and then check its classes // Hide each element and then check its classes
iterateHidden( true ); iterateHidden( true );
// Set the exclude option to false so we no longer care about hidden // Set the exclude option to false so we no longer care about hidden
@ -135,16 +139,50 @@ $.each( tests, function( widget, html ) {
iterateHidden(); iterateHidden();
// Disable the first control // Disable the first control
if ( widget === "spinner" ) {
controls[ 0 ].spinner( "disable" );
}
controls[ 0 ].prop( "disabled", true ); controls[ 0 ].prop( "disabled", true );
element.controlgroup( "refresh" ); element.controlgroup( "refresh" );
assert.hasClasses( controls[ 0 ][ widget ]( "widget" ), "ui-state-disabled" ); assert.hasClasses( controls[ 0 ][ widget ]( "widget" ), "ui-state-disabled" );
// remove the controlgroup before we start the next set // Remove the controlgroup before we start the next set
element.remove(); element.remove();
} ); } );
} ); } );
} ); } );
QUnit.test( "Child Classes Option: init", function( assert ) {
assert.expect( 1 );
var selectmenu = $( "#select-pre" ).selectmenu( {
classes: {
"ui-selectmenu-button-closed": "test-class"
}
} );
$( ".controlgroup-pre" ).controlgroup();
assert.hasClasses( selectmenu.selectmenu( "widget" ), "test-class" );
} );
QUnit.test( "Child Classes Option: refresh", function( assert ) {
assert.expect( 1 );
var controlgroup = $( ".controlgroup-refresh" ).controlgroup();
var selectmenu = $( "#select-refresh" ).selectmenu( {
classes: {
"ui-selectmenu-button-closed": "test-class"
}
} );
controlgroup.controlgroup( "refresh" );
assert.hasClasses( selectmenu.selectmenu( "widget" ), "test-class" );
} );
QUnit.test( "Controlgroup Label: refresh", function( assert ) {
assert.expect( 1 );
var controlgroup = $( ".controlgroup-refresh" ).controlgroup();
controlgroup.controlgroup( "refresh" );
assert.strictEqual( controlgroup.find( ".ui-controlgroup-label-contents" ).length, 1,
"Controlgroup label does not re-wrap on refresh" );
} );
} ); } );

View File

@ -1,27 +1,29 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/widgets/controlgroup", "ui/widgets/controlgroup",
"ui/widgets/checkboxradio", "ui/widgets/checkboxradio",
"ui/widgets/selectmenu", "ui/widgets/selectmenu",
"ui/widgets/button" "ui/widgets/button",
], function( $ ) { "ui/widgets/spinner"
], function( QUnit, $ ) {
module( "Controlgroup: options" ); QUnit.module( "Controlgroup: options" );
test( "disabled", function( assert ) { QUnit.test( "disabled", function( assert ) {
expect( 4 ); assert.expect( 4 );
var element = $( ".controlgroup" ).controlgroup().controlgroup( "option", "disabled", true ); var element = $( ".controlgroup" ).controlgroup().controlgroup( "option", "disabled", true );
assert.lacksClasses( element, "ui-state-disabled" ); assert.lacksClasses( element, "ui-state-disabled" );
equal( element.find( ".ui-state-disabled" ).length, 6, "Child widgets are disabled" ); assert.equal( element.find( ".ui-state-disabled" ).length, 9, "Child widgets are disabled" );
element.controlgroup( "option", "disabled", false ); element.controlgroup( "option", "disabled", false );
assert.lacksClasses( element, "ui-state-disabled" ); assert.lacksClasses( element, "ui-state-disabled" );
strictEqual( element.find( ".ui-state-disabled" ).length, 0, "Child widgets are not disabled" ); assert.strictEqual( element.find( ".ui-state-disabled" ).length, 0, "Child widgets are not disabled" );
} ); } );
test( "items - null", function() { QUnit.test( "items - null", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( ".controlgroup" ).controlgroup( { var element = $( ".controlgroup" ).controlgroup( {
items: { items: {
"button": null, "button": null,
@ -30,24 +32,24 @@ test( "items - null", function() {
} }
} ); } );
strictEqual( element.children( ".ui-button" ).length, 0, assert.strictEqual( element.children( ".ui-button" ).length, 0,
"Child widgets are not called when selector is null" ); "Child widgets are not called when selector is null" );
element.controlgroup( "option", "items", { element.controlgroup( "option", "items", {
"button": "button" "button": "button"
} ); } );
strictEqual( element.children( ".ui-button" ).length, 2, assert.strictEqual( element.children( ".ui-button" ).length, 2,
"Correct child widgets are called when selector is updated" ); "Correct child widgets are called when selector is updated" );
} ); } );
test( "items: custom selector", function() { QUnit.test( "items: custom selector", function( assert ) {
expect( 1 ); assert.expect( 1 );
var element = $( ".controlgroup" ).controlgroup( { var element = $( ".controlgroup" ).controlgroup( {
items: { items: {
"button": ".button" "button": ".button"
} }
} ); } );
strictEqual( element.children( ".ui-button" ).length, 4, assert.strictEqual( element.children( ".ui-button" ).length, 4,
"Correct child widgets are called when custom selector used" ); "Correct child widgets are called when custom selector used" );
} ); } );
@ -60,22 +62,22 @@ $.widget( "ui.test", {
refresh: $.noop refresh: $.noop
} ); } );
test( "items: custom widget", function() { QUnit.test( "items: custom widget", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( ".controlgroup" ).controlgroup( { var element = $( ".controlgroup" ).controlgroup( {
items: { items: {
"test": ".test" "test": ".test"
} }
} ); } );
strictEqual( element.children( ".ui-button" ).length, 7, assert.strictEqual( element.children( ".ui-button" ).length, 7,
"Correct child widgets are called when custom selector used" ); "Correct child widgets are called when custom selector used" );
strictEqual( element.children( ".ui-test" ).length, 1, assert.strictEqual( element.children( ".ui-test" ).length, 1,
"Custom widget called" ); "Custom widget called" );
} ); } );
test( "onlyVisible", function( assert ) { QUnit.test( "onlyVisible", function( assert ) {
expect( 4 ); assert.expect( 4 );
var element = $( ".controlgroup" ).controlgroup( { var element = $( ".controlgroup" ).controlgroup( {
onlyVisible: false onlyVisible: false
} ), } ),
@ -91,8 +93,8 @@ test( "onlyVisible", function( assert ) {
"onlyVisible: true: First button is hidden second button get corner class" ); "onlyVisible: true: First button is hidden second button get corner class" );
} ); } );
test( "direction", function( assert ) { QUnit.test( "direction", function( assert ) {
expect( 6 ); assert.expect( 6 );
var element = $( ".controlgroup" ).controlgroup(), var element = $( ".controlgroup" ).controlgroup(),
buttons = element.children( ".ui-button" ).filter( ":visible" ); buttons = element.children( ".ui-button" ).filter( ":visible" );

View File

@ -38,6 +38,15 @@
<input> <input>
</form> </form>
<form>
<fieldset id="enabledFieldset">
<input>
</fieldset>
<fieldset id="disabledFieldset" disabled="disabled">
<input>
</fieldset>
</form>
<div> <div>
<input id="visibleAncestor-inputTypeNone"> <input id="visibleAncestor-inputTypeNone">
<input type="text" id="visibleAncestor-inputTypeText"> <input type="text" id="visibleAncestor-inputTypeText">

View File

@ -1,147 +1,148 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"lib/common", "lib/common",
"ui/form", "ui/form",
"ui/labels", "ui/labels",
"ui/unique-id" "ui/unique-id"
], function( $, common ) { ], function( QUnit, $, common ) {
module( "core - jQuery extensions" ); QUnit.module( "core - jQuery extensions" );
common.testJshint( "core" ); common.testJshint( "core" );
test( "innerWidth - getter", function() { QUnit.test( "innerWidth - getter", function( assert ) {
expect( 2 ); assert.expect( 2 );
var el = $( "#dimensions" ); var el = $( "#dimensions" );
equal( el.innerWidth(), 122, "getter passthru" ); assert.equal( el.innerWidth(), 122, "getter passthru" );
el.hide(); el.hide();
equal( el.innerWidth(), 122, "getter passthru when hidden" ); assert.equal( el.innerWidth(), 122, "getter passthru when hidden" );
} ); } );
test( "innerWidth - setter", function() { QUnit.test( "innerWidth - setter", function( assert ) {
expect( 2 ); assert.expect( 2 );
var el = $( "#dimensions" ); var el = $( "#dimensions" );
el.innerWidth( 120 ); el.innerWidth( 120 );
equal( el.width(), 98, "width set properly" ); assert.equal( el.width(), 98, "width set properly" );
el.hide(); el.hide();
el.innerWidth( 100 ); el.innerWidth( 100 );
equal( el.width(), 78, "width set properly when hidden" ); assert.equal( el.width(), 78, "width set properly when hidden" );
} ); } );
test( "innerHeight - getter", function() { QUnit.test( "innerHeight - getter", function( assert ) {
expect( 2 ); assert.expect( 2 );
var el = $( "#dimensions" ); var el = $( "#dimensions" );
equal( el.innerHeight(), 70, "getter passthru" ); assert.equal( el.innerHeight(), 70, "getter passthru" );
el.hide(); el.hide();
equal( el.innerHeight(), 70, "getter passthru when hidden" ); assert.equal( el.innerHeight(), 70, "getter passthru when hidden" );
} ); } );
test( "innerHeight - setter", function() { QUnit.test( "innerHeight - setter", function( assert ) {
expect( 2 ); assert.expect( 2 );
var el = $( "#dimensions" ); var el = $( "#dimensions" );
el.innerHeight( 60 ); el.innerHeight( 60 );
equal( el.height(), 40, "height set properly" ); assert.equal( el.height(), 40, "height set properly" );
el.hide(); el.hide();
el.innerHeight( 50 ); el.innerHeight( 50 );
equal( el.height(), 30, "height set properly when hidden" ); assert.equal( el.height(), 30, "height set properly when hidden" );
} ); } );
test( "outerWidth - getter", function() { QUnit.test( "outerWidth - getter", function( assert ) {
expect( 2 ); assert.expect( 2 );
var el = $( "#dimensions" ); var el = $( "#dimensions" );
equal( el.outerWidth(), 140, "getter passthru" ); assert.equal( el.outerWidth(), 140, "getter passthru" );
el.hide(); el.hide();
equal( el.outerWidth(), 140, "getter passthru when hidden" ); assert.equal( el.outerWidth(), 140, "getter passthru when hidden" );
} ); } );
test( "outerWidth - setter", function() { QUnit.test( "outerWidth - setter", function( assert ) {
expect( 2 ); assert.expect( 2 );
var el = $( "#dimensions" ); var el = $( "#dimensions" );
el.outerWidth( 130 ); el.outerWidth( 130 );
equal( el.width(), 90, "width set properly" ); assert.equal( el.width(), 90, "width set properly" );
el.hide(); el.hide();
el.outerWidth( 120 ); el.outerWidth( 120 );
equal( el.width(), 80, "width set properly when hidden" ); assert.equal( el.width(), 80, "width set properly when hidden" );
} ); } );
test( "outerWidth(true) - getter", function() { QUnit.test( "outerWidth(true) - getter", function( assert ) {
expect( 2 ); assert.expect( 2 );
var el = $( "#dimensions" ); var el = $( "#dimensions" );
equal( el.outerWidth( true ), 154, "getter passthru w/ margin" ); assert.equal( el.outerWidth( true ), 154, "getter passthru w/ margin" );
el.hide(); el.hide();
equal( el.outerWidth( true ), 154, "getter passthru w/ margin when hidden" ); assert.equal( el.outerWidth( true ), 154, "getter passthru w/ margin when hidden" );
} ); } );
test( "outerWidth(true) - setter", function() { QUnit.test( "outerWidth(true) - setter", function( assert ) {
expect( 2 ); assert.expect( 2 );
var el = $( "#dimensions" ); var el = $( "#dimensions" );
el.outerWidth( 130, true ); el.outerWidth( 130, true );
equal( el.width(), 76, "width set properly" ); assert.equal( el.width(), 76, "width set properly" );
el.hide(); el.hide();
el.outerWidth( 120, true ); el.outerWidth( 120, true );
equal( el.width(), 66, "width set properly when hidden" ); assert.equal( el.width(), 66, "width set properly when hidden" );
} ); } );
test( "outerHeight - getter", function() { QUnit.test( "outerHeight - getter", function( assert ) {
expect( 2 ); assert.expect( 2 );
var el = $( "#dimensions" ); var el = $( "#dimensions" );
equal( el.outerHeight(), 86, "getter passthru" ); assert.equal( el.outerHeight(), 86, "getter passthru" );
el.hide(); el.hide();
equal( el.outerHeight(), 86, "getter passthru when hidden" ); assert.equal( el.outerHeight(), 86, "getter passthru when hidden" );
} ); } );
test( "outerHeight - setter", function() { QUnit.test( "outerHeight - setter", function( assert ) {
expect( 2 ); assert.expect( 2 );
var el = $( "#dimensions" ); var el = $( "#dimensions" );
el.outerHeight( 80 ); el.outerHeight( 80 );
equal( el.height(), 44, "height set properly" ); assert.equal( el.height(), 44, "height set properly" );
el.hide(); el.hide();
el.outerHeight( 70 ); el.outerHeight( 70 );
equal( el.height(), 34, "height set properly when hidden" ); assert.equal( el.height(), 34, "height set properly when hidden" );
} ); } );
test( "outerHeight(true) - getter", function() { QUnit.test( "outerHeight(true) - getter", function( assert ) {
expect( 2 ); assert.expect( 2 );
var el = $( "#dimensions" ); var el = $( "#dimensions" );
equal( el.outerHeight( true ), 98, "getter passthru w/ margin" ); assert.equal( el.outerHeight( true ), 98, "getter passthru w/ margin" );
el.hide(); el.hide();
equal( el.outerHeight( true ), 98, "getter passthru w/ margin when hidden" ); assert.equal( el.outerHeight( true ), 98, "getter passthru w/ margin when hidden" );
} ); } );
test( "outerHeight(true) - setter", function() { QUnit.test( "outerHeight(true) - setter", function( assert ) {
expect( 2 ); assert.expect( 2 );
var el = $( "#dimensions" ); var el = $( "#dimensions" );
el.outerHeight( 90, true ); el.outerHeight( 90, true );
equal( el.height(), 42, "height set properly" ); assert.equal( el.height(), 42, "height set properly" );
el.hide(); el.hide();
el.outerHeight( 80, true ); el.outerHeight( 80, true );
equal( el.height(), 32, "height set properly when hidden" ); assert.equal( el.height(), 32, "height set properly when hidden" );
} ); } );
test( "uniqueId / removeUniqueId", function() { QUnit.test( "uniqueId / removeUniqueId", function( assert ) {
expect( 3 ); assert.expect( 3 );
var el = $( "img" ).eq( 0 ); var el = $( "img" ).eq( 0 );
equal( el.attr( "id" ), null, "element has no initial id" ); assert.equal( el.attr( "id" ), null, "element has no initial id" );
el.uniqueId(); el.uniqueId();
ok( /ui-id-\d+$/.test( el.attr( "id" ) ), "element has generated id" ); assert.ok( /ui-id-\d+$/.test( el.attr( "id" ) ), "element has generated id" );
el.removeUniqueId(); el.removeUniqueId();
equal( el.attr( "id" ), null, "unique id has been removed from element" ); assert.equal( el.attr( "id" ), null, "unique id has been removed from element" );
} ); } );
test( "Labels", function() { QUnit.test( "Labels", function( assert ) {
expect( 2 ); assert.expect( 2 );
var expected = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ]; var expected = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ];
var dom = $( "#labels-fragment" ); var dom = $( "#labels-fragment" );
@ -155,7 +156,7 @@ test( "Labels", function() {
return $.trim( $( this ).text() ); return $.trim( $( this ).text() );
} ).get(); } ).get();
deepEqual( found, expected, assert.deepEqual( found, expected,
".labels() finds all labels in " + testType + ", and sorts them in DOM order" ); ".labels() finds all labels in " + testType + ", and sorts them in DOM order" );
} }
@ -176,9 +177,10 @@ test( "Labels", function() {
inputs.each( function() { inputs.each( function() {
var input = $( this ); var input = $( this );
asyncTest( name + this.id.replace( /_/g, " " ), function() { QUnit.test( name + this.id.replace( /_/g, " " ), function( assert ) {
expect( 1 ); var ready = assert.async();
var form = input.form(); assert.expect( 1 );
var form = input._form();
// If input has a form the value should reset to "" if not it should be "changed" // If input has a form the value should reset to "" if not it should be "changed"
var value = form.length ? "" : "changed"; var value = form.length ? "" : "changed";
@ -193,8 +195,8 @@ test( "Labels", function() {
} ); } );
setTimeout( function() { setTimeout( function() {
equal( input.val(), value, "Proper form found for #" + input.attr( "id" ) ); assert.equal( input.val(), value, "Proper form found for #" + input.attr( "id" ) );
start(); ready();
} ); } );
} ); } );
} ); } );

View File

@ -1,44 +1,45 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/data", "ui/data",
"ui/escape-selector", "ui/escape-selector",
"ui/focusable", "ui/focusable",
"ui/tabbable" "ui/tabbable"
], function( $ ) { ], function( QUnit, $ ) {
module( "core - selectors" ); QUnit.module( "core - selectors" );
function isFocusable( selector, msg ) { QUnit.assert.isFocusable = function( selector, msg ) {
QUnit.push( $( selector ).is( ":focusable" ), null, null, this.push( $( selector ).is( ":focusable" ), null, null,
msg + " - selector " + selector + " is focusable" ); msg + " - selector " + selector + " is focusable" );
} };
function isNotFocusable( selector, msg ) { QUnit.assert.isNotFocusable = function( selector, msg ) {
QUnit.push( $( selector ).length && !$( selector ).is( ":focusable" ), null, null, this.push( $( selector ).length && !$( selector ).is( ":focusable" ), null, null,
msg + " - selector " + selector + " is not focusable" ); msg + " - selector " + selector + " is not focusable" );
} };
function isTabbable( selector, msg ) { QUnit.assert.isTabbable = function( selector, msg ) {
QUnit.push( $( selector ).is( ":tabbable" ), null, null, this.push( $( selector ).is( ":tabbable" ), null, null,
msg + " - selector " + selector + " is tabbable" ); msg + " - selector " + selector + " is tabbable" );
} };
function isNotTabbable( selector, msg ) { QUnit.assert.isNotTabbable = function( selector, msg ) {
QUnit.push( $( selector ).length && !$( selector ).is( ":tabbable" ), null, null, this.push( $( selector ).length && !$( selector ).is( ":tabbable" ), null, null,
msg + " - selector " + selector + " is not tabbable" ); msg + " - selector " + selector + " is not tabbable" );
} };
test( "data", function() { QUnit.test( "data", function( assert ) {
expect( 15 ); assert.expect( 15 );
var element; var element;
function shouldHaveData( msg ) { function shouldHaveData( msg ) {
ok( element.is( ":data(test)" ), msg ); assert.ok( element.is( ":data(test)" ), msg );
} }
function shouldNotHaveData( msg ) { function shouldNotHaveData( msg ) {
ok( !element.is( ":data(test)" ), msg ); assert.ok( !element.is( ":data(test)" ), msg );
} }
element = $( "<div>" ); element = $( "<div>" );
@ -87,193 +88,197 @@ test( "data", function() {
shouldHaveData( "data set to function" ); shouldHaveData( "data set to function" );
} ); } );
test( "focusable - visible, enabled elements", function() { QUnit.test( "focusable - visible, enabled elements", function( assert ) {
expect( 20 ); assert.expect( 22 );
isNotFocusable( "#formNoTabindex", "form" ); assert.isNotFocusable( "#formNoTabindex", "form" );
isFocusable( "#formTabindex", "form with tabindex" ); assert.isFocusable( "#formTabindex", "form with tabindex" );
isFocusable( "#visibleAncestor-inputTypeNone", "input, no type" ); assert.isFocusable( "#enabledFieldset input", "input in enabled fieldset" );
isFocusable( "#visibleAncestor-inputTypeText", "input, type text" ); assert.isNotFocusable( "#disabledFieldset input", "input in disabled fieldset" );
isFocusable( "#visibleAncestor-inputTypeCheckbox", "input, type checkbox" ); assert.isFocusable( "#visibleAncestor-inputTypeNone", "input, no type" );
isFocusable( "#visibleAncestor-inputTypeRadio", "input, type radio" ); assert.isFocusable( "#visibleAncestor-inputTypeText", "input, type text" );
isFocusable( "#visibleAncestor-inputTypeButton", "input, type button" ); assert.isFocusable( "#visibleAncestor-inputTypeCheckbox", "input, type checkbox" );
isNotFocusable( "#visibleAncestor-inputTypeHidden", "input, type hidden" ); assert.isFocusable( "#visibleAncestor-inputTypeRadio", "input, type radio" );
isFocusable( "#visibleAncestor-button", "button" ); assert.isFocusable( "#visibleAncestor-inputTypeButton", "input, type button" );
isFocusable( "#visibleAncestor-select", "select" ); assert.isNotFocusable( "#visibleAncestor-inputTypeHidden", "input, type hidden" );
isFocusable( "#visibleAncestor-textarea", "textarea" ); assert.isFocusable( "#visibleAncestor-button", "button" );
isFocusable( "#visibleAncestor-object", "object" ); assert.isFocusable( "#visibleAncestor-select", "select" );
isFocusable( "#visibleAncestor-anchorWithHref", "anchor with href" ); assert.isFocusable( "#visibleAncestor-textarea", "textarea" );
isNotFocusable( "#visibleAncestor-anchorWithoutHref", "anchor without href" ); assert.isFocusable( "#visibleAncestor-object", "object" );
isNotFocusable( "#visibleAncestor-span", "span" ); assert.isFocusable( "#visibleAncestor-anchorWithHref", "anchor with href" );
isNotFocusable( "#visibleAncestor-div", "div" ); assert.isNotFocusable( "#visibleAncestor-anchorWithoutHref", "anchor without href" );
isFocusable( "#visibleAncestor-spanWithTabindex", "span with tabindex" ); assert.isNotFocusable( "#visibleAncestor-span", "span" );
isFocusable( "#visibleAncestor-divWithNegativeTabindex", "div with tabindex" ); assert.isNotFocusable( "#visibleAncestor-div", "div" );
isFocusable( "#nestedVisibilityInheritWithVisibleAncestor", assert.isFocusable( "#visibleAncestor-spanWithTabindex", "span with tabindex" );
assert.isFocusable( "#visibleAncestor-divWithNegativeTabindex", "div with tabindex" );
assert.isFocusable( "#nestedVisibilityInheritWithVisibleAncestor",
"span, visibility: inherit inside visibility: visible parent" ); "span, visibility: inherit inside visibility: visible parent" );
isFocusable( "#nestedVisibilityInheritWithVisibleAncestor-input", assert.isFocusable( "#nestedVisibilityInheritWithVisibleAncestor-input",
"input, visibility: inherit inside visibility: visible parent" ); "input, visibility: inherit inside visibility: visible parent" );
} ); } );
test( "focusable - disabled elements", function() { QUnit.test( "focusable - disabled elements", function( assert ) {
expect( 9 ); assert.expect( 9 );
isNotFocusable( "#disabledElement-inputTypeNone", "input, no type" ); assert.isNotFocusable( "#disabledElement-inputTypeNone", "input, no type" );
isNotFocusable( "#disabledElement-inputTypeText", "input, type text" ); assert.isNotFocusable( "#disabledElement-inputTypeText", "input, type text" );
isNotFocusable( "#disabledElement-inputTypeCheckbox", "input, type checkbox" ); assert.isNotFocusable( "#disabledElement-inputTypeCheckbox", "input, type checkbox" );
isNotFocusable( "#disabledElement-inputTypeRadio", "input, type radio" ); assert.isNotFocusable( "#disabledElement-inputTypeRadio", "input, type radio" );
isNotFocusable( "#disabledElement-inputTypeButton", "input, type button" ); assert.isNotFocusable( "#disabledElement-inputTypeButton", "input, type button" );
isNotFocusable( "#disabledElement-inputTypeHidden", "input, type hidden" ); assert.isNotFocusable( "#disabledElement-inputTypeHidden", "input, type hidden" );
isNotFocusable( "#disabledElement-button", "button" ); assert.isNotFocusable( "#disabledElement-button", "button" );
isNotFocusable( "#disabledElement-select", "select" ); assert.isNotFocusable( "#disabledElement-select", "select" );
isNotFocusable( "#disabledElement-textarea", "textarea" ); assert.isNotFocusable( "#disabledElement-textarea", "textarea" );
} ); } );
test( "focusable - hidden styles", function() { QUnit.test( "focusable - hidden styles", function( assert ) {
expect( 12 ); assert.expect( 12 );
isNotFocusable( "#displayNoneAncestor-input", "input, display: none parent" ); assert.isNotFocusable( "#displayNoneAncestor-input", "input, display: none parent" );
isNotFocusable( "#displayNoneAncestor-span", "span with tabindex, display: none parent" ); assert.isNotFocusable( "#displayNoneAncestor-span", "span with tabindex, display: none parent" );
isNotFocusable( "#visibilityHiddenAncestor-input", "input, visibility: hidden parent" ); assert.isNotFocusable( "#visibilityHiddenAncestor-input", "input, visibility: hidden parent" );
isNotFocusable( "#visibilityHiddenAncestor-span", "span with tabindex, visibility: hidden parent" ); assert.isNotFocusable( "#visibilityHiddenAncestor-span", "span with tabindex, visibility: hidden parent" );
isFocusable( "#nestedVisibilityOverrideAncestor-input", "input, visibility: visible parent but visibility: hidden grandparent" ); assert.isFocusable( "#nestedVisibilityOverrideAncestor-input", "input, visibility: visible parent but visibility: hidden grandparent" );
isFocusable( "#nestedVisibilityOverrideAncestor-span", "span with tabindex, visibility: visible parent but visibility: hidden grandparent " ); assert.isFocusable( "#nestedVisibilityOverrideAncestor-span", "span with tabindex, visibility: visible parent but visibility: hidden grandparent " );
isNotFocusable( "#nestedVisibilityInheritWithHiddenAncestor", "span, visibility: inherit inside visibility: hidden parent" ); assert.isNotFocusable( "#nestedVisibilityInheritWithHiddenAncestor", "span, visibility: inherit inside visibility: hidden parent" );
isNotFocusable( "#nestedVisibilityInheritWithHiddenAncestor-input", "input, visibility: inherit inside visibility: hidden parent" ); assert.isNotFocusable( "#nestedVisibilityInheritWithHiddenAncestor-input", "input, visibility: inherit inside visibility: hidden parent" );
isNotFocusable( "#displayNone-input", "input, display: none" ); assert.isNotFocusable( "#displayNone-input", "input, display: none" );
isNotFocusable( "#visibilityHidden-input", "input, visibility: hidden" ); assert.isNotFocusable( "#visibilityHidden-input", "input, visibility: hidden" );
isNotFocusable( "#displayNone-span", "span with tabindex, display: none" ); assert.isNotFocusable( "#displayNone-span", "span with tabindex, display: none" );
isNotFocusable( "#visibilityHidden-span", "span with tabindex, visibility: hidden" ); assert.isNotFocusable( "#visibilityHidden-span", "span with tabindex, visibility: hidden" );
} ); } );
test( "focusable - natively focusable with various tabindex", function() { QUnit.test( "focusable - natively focusable with various tabindex", function( assert ) {
expect( 4 ); assert.expect( 4 );
isFocusable( "#inputTabindex0", "input, tabindex 0" ); assert.isFocusable( "#inputTabindex0", "input, tabindex 0" );
isFocusable( "#inputTabindex10", "input, tabindex 10" ); assert.isFocusable( "#inputTabindex10", "input, tabindex 10" );
isFocusable( "#inputTabindex-1", "input, tabindex -1" ); assert.isFocusable( "#inputTabindex-1", "input, tabindex -1" );
isFocusable( "#inputTabindex-50", "input, tabindex -50" ); assert.isFocusable( "#inputTabindex-50", "input, tabindex -50" );
} ); } );
test( "focusable - not natively focusable with various tabindex", function() { QUnit.test( "focusable - not natively focusable with various tabindex", function( assert ) {
expect( 4 ); assert.expect( 4 );
isFocusable( "#spanTabindex0", "span, tabindex 0" ); assert.isFocusable( "#spanTabindex0", "span, tabindex 0" );
isFocusable( "#spanTabindex10", "span, tabindex 10" ); assert.isFocusable( "#spanTabindex10", "span, tabindex 10" );
isFocusable( "#spanTabindex-1", "span, tabindex -1" ); assert.isFocusable( "#spanTabindex-1", "span, tabindex -1" );
isFocusable( "#spanTabindex-50", "span, tabindex -50" ); assert.isFocusable( "#spanTabindex-50", "span, tabindex -50" );
} ); } );
test( "focusable - area elements", function() { QUnit.test( "focusable - area elements", function( assert ) {
expect( 3 ); assert.expect( 3 );
isFocusable( "#areaCoordsHref", "coords and href" ); assert.isFocusable( "#areaCoordsHref", "coords and href" );
isFocusable( "#areaNoCoordsHref", "href but no coords" ); assert.isFocusable( "#areaNoCoordsHref", "href but no coords" );
isNotFocusable( "#areaNoImg", "not associated with an image" ); assert.isNotFocusable( "#areaNoImg", "not associated with an image" );
} ); } );
test( "focusable - dimensionless parent with overflow", function() { QUnit.test( "focusable - dimensionless parent with overflow", function( assert ) {
expect( 1 ); assert.expect( 1 );
isFocusable( "#dimensionlessParent", "input" ); assert.isFocusable( "#dimensionlessParent", "input" );
} ); } );
test( "tabbable - visible, enabled elements", function() { QUnit.test( "tabbable - visible, enabled elements", function( assert ) {
expect( 18 ); assert.expect( 20 );
isNotTabbable( "#formNoTabindex", "form" ); assert.isNotTabbable( "#formNoTabindex", "form" );
isTabbable( "#formTabindex", "form with tabindex" ); assert.isTabbable( "#formTabindex", "form with tabindex" );
isTabbable( "#visibleAncestor-inputTypeNone", "input, no type" ); assert.isTabbable( "#enabledFieldset input", "input in enabled fieldset" );
isTabbable( "#visibleAncestor-inputTypeText", "input, type text" ); assert.isNotTabbable( "#disabledFieldset input", "input in disabled fieldset" );
isTabbable( "#visibleAncestor-inputTypeCheckbox", "input, type checkbox" ); assert.isTabbable( "#visibleAncestor-inputTypeNone", "input, no type" );
isTabbable( "#visibleAncestor-inputTypeRadio", "input, type radio" ); assert.isTabbable( "#visibleAncestor-inputTypeText", "input, type text" );
isTabbable( "#visibleAncestor-inputTypeButton", "input, type button" ); assert.isTabbable( "#visibleAncestor-inputTypeCheckbox", "input, type checkbox" );
isNotTabbable( "#visibleAncestor-inputTypeHidden", "input, type hidden" ); assert.isTabbable( "#visibleAncestor-inputTypeRadio", "input, type radio" );
isTabbable( "#visibleAncestor-button", "button" ); assert.isTabbable( "#visibleAncestor-inputTypeButton", "input, type button" );
isTabbable( "#visibleAncestor-select", "select" ); assert.isNotTabbable( "#visibleAncestor-inputTypeHidden", "input, type hidden" );
isTabbable( "#visibleAncestor-textarea", "textarea" ); assert.isTabbable( "#visibleAncestor-button", "button" );
isTabbable( "#visibleAncestor-object", "object" ); assert.isTabbable( "#visibleAncestor-select", "select" );
isTabbable( "#visibleAncestor-anchorWithHref", "anchor with href" ); assert.isTabbable( "#visibleAncestor-textarea", "textarea" );
isNotTabbable( "#visibleAncestor-anchorWithoutHref", "anchor without href" ); assert.isTabbable( "#visibleAncestor-object", "object" );
isNotTabbable( "#visibleAncestor-span", "span" ); assert.isTabbable( "#visibleAncestor-anchorWithHref", "anchor with href" );
isNotTabbable( "#visibleAncestor-div", "div" ); assert.isNotTabbable( "#visibleAncestor-anchorWithoutHref", "anchor without href" );
isTabbable( "#visibleAncestor-spanWithTabindex", "span with tabindex" ); assert.isNotTabbable( "#visibleAncestor-span", "span" );
isNotTabbable( "#visibleAncestor-divWithNegativeTabindex", "div with tabindex" ); assert.isNotTabbable( "#visibleAncestor-div", "div" );
assert.isTabbable( "#visibleAncestor-spanWithTabindex", "span with tabindex" );
assert.isNotTabbable( "#visibleAncestor-divWithNegativeTabindex", "div with tabindex" );
} ); } );
test( "tabbable - disabled elements", function() { QUnit.test( "tabbable - disabled elements", function( assert ) {
expect( 9 ); assert.expect( 9 );
isNotTabbable( "#disabledElement-inputTypeNone", "input, no type" ); assert.isNotTabbable( "#disabledElement-inputTypeNone", "input, no type" );
isNotTabbable( "#disabledElement-inputTypeText", "input, type text" ); assert.isNotTabbable( "#disabledElement-inputTypeText", "input, type text" );
isNotTabbable( "#disabledElement-inputTypeCheckbox", "input, type checkbox" ); assert.isNotTabbable( "#disabledElement-inputTypeCheckbox", "input, type checkbox" );
isNotTabbable( "#disabledElement-inputTypeRadio", "input, type radio" ); assert.isNotTabbable( "#disabledElement-inputTypeRadio", "input, type radio" );
isNotTabbable( "#disabledElement-inputTypeButton", "input, type button" ); assert.isNotTabbable( "#disabledElement-inputTypeButton", "input, type button" );
isNotTabbable( "#disabledElement-inputTypeHidden", "input, type hidden" ); assert.isNotTabbable( "#disabledElement-inputTypeHidden", "input, type hidden" );
isNotTabbable( "#disabledElement-button", "button" ); assert.isNotTabbable( "#disabledElement-button", "button" );
isNotTabbable( "#disabledElement-select", "select" ); assert.isNotTabbable( "#disabledElement-select", "select" );
isNotTabbable( "#disabledElement-textarea", "textarea" ); assert.isNotTabbable( "#disabledElement-textarea", "textarea" );
} ); } );
test( "tabbable - hidden styles", function() { QUnit.test( "tabbable - hidden styles", function( assert ) {
expect( 10 ); assert.expect( 10 );
isNotTabbable( "#displayNoneAncestor-input", "input, display: none parent" ); assert.isNotTabbable( "#displayNoneAncestor-input", "input, display: none parent" );
isNotTabbable( "#displayNoneAncestor-span", "span with tabindex, display: none parent" ); assert.isNotTabbable( "#displayNoneAncestor-span", "span with tabindex, display: none parent" );
isNotTabbable( "#visibilityHiddenAncestor-input", "input, visibility: hidden parent" ); assert.isNotTabbable( "#visibilityHiddenAncestor-input", "input, visibility: hidden parent" );
isNotTabbable( "#visibilityHiddenAncestor-span", "span with tabindex, visibility: hidden parent" ); assert.isNotTabbable( "#visibilityHiddenAncestor-span", "span with tabindex, visibility: hidden parent" );
isTabbable( "#nestedVisibilityOverrideAncestor-input", "input, visibility: visible parent but visibility: hidden grandparent" ); assert.isTabbable( "#nestedVisibilityOverrideAncestor-input", "input, visibility: visible parent but visibility: hidden grandparent" );
isTabbable( "#nestedVisibilityOverrideAncestor-span", "span with tabindex, visibility: visible parent but visibility: hidden grandparent " ); assert.isTabbable( "#nestedVisibilityOverrideAncestor-span", "span with tabindex, visibility: visible parent but visibility: hidden grandparent " );
isNotTabbable( "#displayNone-input", "input, display: none" ); assert.isNotTabbable( "#displayNone-input", "input, display: none" );
isNotTabbable( "#visibilityHidden-input", "input, visibility: hidden" ); assert.isNotTabbable( "#visibilityHidden-input", "input, visibility: hidden" );
isNotTabbable( "#displayNone-span", "span with tabindex, display: none" ); assert.isNotTabbable( "#displayNone-span", "span with tabindex, display: none" );
isNotTabbable( "#visibilityHidden-span", "span with tabindex, visibility: hidden" ); assert.isNotTabbable( "#visibilityHidden-span", "span with tabindex, visibility: hidden" );
} ); } );
test( "tabbable - natively tabbable with various tabindex", function() { QUnit.test( "tabbable - natively tabbable with various tabindex", function( assert ) {
expect( 4 ); assert.expect( 4 );
isTabbable( "#inputTabindex0", "input, tabindex 0" ); assert.isTabbable( "#inputTabindex0", "input, tabindex 0" );
isTabbable( "#inputTabindex10", "input, tabindex 10" ); assert.isTabbable( "#inputTabindex10", "input, tabindex 10" );
isNotTabbable( "#inputTabindex-1", "input, tabindex -1" ); assert.isNotTabbable( "#inputTabindex-1", "input, tabindex -1" );
isNotTabbable( "#inputTabindex-50", "input, tabindex -50" ); assert.isNotTabbable( "#inputTabindex-50", "input, tabindex -50" );
} ); } );
test( "tabbable - not natively tabbable with various tabindex", function() { QUnit.test( "tabbable - not natively tabbable with various tabindex", function( assert ) {
expect( 4 ); assert.expect( 4 );
isTabbable( "#spanTabindex0", "span, tabindex 0" ); assert.isTabbable( "#spanTabindex0", "span, tabindex 0" );
isTabbable( "#spanTabindex10", "span, tabindex 10" ); assert.isTabbable( "#spanTabindex10", "span, tabindex 10" );
isNotTabbable( "#spanTabindex-1", "span, tabindex -1" ); assert.isNotTabbable( "#spanTabindex-1", "span, tabindex -1" );
isNotTabbable( "#spanTabindex-50", "span, tabindex -50" ); assert.isNotTabbable( "#spanTabindex-50", "span, tabindex -50" );
} ); } );
test( "tabbable - area elements", function() { QUnit.test( "tabbable - area elements", function( assert ) {
expect( 3 ); assert.expect( 3 );
isTabbable( "#areaCoordsHref", "coords and href" ); assert.isTabbable( "#areaCoordsHref", "coords and href" );
isTabbable( "#areaNoCoordsHref", "href but no coords" ); assert.isTabbable( "#areaNoCoordsHref", "href but no coords" );
isNotTabbable( "#areaNoImg", "not associated with an image" ); assert.isNotTabbable( "#areaNoImg", "not associated with an image" );
} ); } );
test( "tabbable - dimensionless parent with overflow", function() { QUnit.test( "tabbable - dimensionless parent with overflow", function( assert ) {
expect( 1 ); assert.expect( 1 );
isTabbable( "#dimensionlessParent", "input" ); assert.isTabbable( "#dimensionlessParent", "input" );
} ); } );
test( "escapeSelector", function() { QUnit.test( "escapeSelector", function( assert ) {
expect( 1 ); assert.expect( 1 );
equal( $( "#" + $.ui.escapeSelector( "weird-['x']-id" ) ).length, 1, assert.equal( $( "#" + $.ui.escapeSelector( "weird-['x']-id" ) ).length, 1,
"properly escapes selectors to use as an id" ); "properly escapes selectors to use as an id" );
} ); } );

View File

@ -1,13 +1,14 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/widgets/dialog" "ui/widgets/dialog"
], function( $ ) { ], function( QUnit, $ ) {
// TODO add teardown callback to remove dialogs // TODO add teardown callback to remove dialogs
module( "dialog: core" ); QUnit.module( "dialog: core" );
test( "markup structure", function( assert ) { QUnit.test( "markup structure", function( assert ) {
expect( 11 ); assert.expect( 11 );
var element = $( "<div>" ).dialog( { var element = $( "<div>" ).dialog( {
buttons: [ { buttons: [ {
@ -25,20 +26,20 @@ test( "markup structure", function( assert ) {
assert.hasClasses( widget, "ui-dialog ui-dialog-buttons ui-widget ui-widget-content" ); assert.hasClasses( widget, "ui-dialog ui-dialog-buttons ui-widget ui-widget-content" );
assert.hasClasses( titlebar, "ui-dialog-titlebar ui-widget-header" ); assert.hasClasses( titlebar, "ui-dialog-titlebar ui-widget-header" );
equal( titlebar.length, 1, "Dialog has exactly one titlebar" ); assert.equal( titlebar.length, 1, "Dialog has exactly one titlebar" );
assert.hasClasses( close, "ui-dialog-titlebar-close ui-widget" ); assert.hasClasses( close, "ui-dialog-titlebar-close ui-widget" );
equal( close.length, 1, "Titlebar has exactly one close button" ); assert.equal( close.length, 1, "Titlebar has exactly one close button" );
equal( title.length, 1, "Titlebar has exactly one title" ); assert.equal( title.length, 1, "Titlebar has exactly one title" );
assert.hasClasses( element, "ui-dialog-content ui-widget-content" ); assert.hasClasses( element, "ui-dialog-content ui-widget-content" );
assert.hasClasses( buttonpane, "ui-dialog-buttonpane ui-widget-content" ); assert.hasClasses( buttonpane, "ui-dialog-buttonpane ui-widget-content" );
equal( buttonpane.length, 1, "Dialog has exactly one buttonpane" ); assert.equal( buttonpane.length, 1, "Dialog has exactly one buttonpane" );
equal( buttonset.length, 1, "Buttonpane has exactly one buttonset" ); assert.equal( buttonset.length, 1, "Buttonpane has exactly one buttonset" );
equal( buttons.length, 1, "Buttonset contains exactly 1 button when created with 1" ); assert.equal( buttons.length, 1, "Buttonset contains exactly 1 button when created with 1" );
} ); } );
test( "markup structure - no buttons", function( assert ) { QUnit.test( "markup structure - no buttons", function( assert ) {
expect( 7 ); assert.expect( 7 );
var element = $( "<div>" ).dialog(), var element = $( "<div>" ).dialog(),
widget = element.dialog( "widget" ), widget = element.dialog( "widget" ),
@ -48,48 +49,49 @@ test( "markup structure - no buttons", function( assert ) {
assert.hasClasses( widget, "ui-dialog ui-widget ui-widget-content" ); assert.hasClasses( widget, "ui-dialog ui-widget ui-widget-content" );
assert.hasClasses( titlebar, "ui-dialog-titlebar ui-widget-header" ); assert.hasClasses( titlebar, "ui-dialog-titlebar ui-widget-header" );
equal( titlebar.length, 1, "Dialog has exactly one titlebar" ); assert.equal( titlebar.length, 1, "Dialog has exactly one titlebar" );
assert.hasClasses( close, "ui-dialog-titlebar-close ui-widget" ); assert.hasClasses( close, "ui-dialog-titlebar-close ui-widget" );
equal( close.length, 1, "Titlebar has exactly one close button" ); assert.equal( close.length, 1, "Titlebar has exactly one close button" );
equal( title.length, 1, "Titlebar has exactly one title" ); assert.equal( title.length, 1, "Titlebar has exactly one title" );
assert.hasClasses( element, "ui-dialog-content ui-widget-content" ); assert.hasClasses( element, "ui-dialog-content ui-widget-content" );
} ); } );
test( "title id", function() { QUnit.test( "title id", function( assert ) {
expect( 1 ); assert.expect( 1 );
var titleId, var titleId,
element = $( "<div>" ).dialog(); element = $( "<div>" ).dialog();
titleId = element.dialog( "widget" ).find( ".ui-dialog-title" ).attr( "id" ); titleId = element.dialog( "widget" ).find( ".ui-dialog-title" ).attr( "id" );
ok( /ui-id-\d+$/.test( titleId ), "auto-numbered title id" ); assert.ok( /ui-id-\d+$/.test( titleId ), "auto-numbered title id" );
element.remove(); element.remove();
} ); } );
test( "ARIA", function() { QUnit.test( "ARIA", function( assert ) {
expect( 4 ); assert.expect( 4 );
var element = $( "<div>" ).dialog(), var element = $( "<div>" ).dialog(),
wrapper = element.dialog( "widget" ); wrapper = element.dialog( "widget" );
equal( wrapper.attr( "role" ), "dialog", "dialog role" ); assert.equal( wrapper.attr( "role" ), "dialog", "dialog role" );
equal( wrapper.attr( "aria-labelledby" ), wrapper.find( ".ui-dialog-title" ).attr( "id" ) ); assert.equal( wrapper.attr( "aria-labelledby" ), wrapper.find( ".ui-dialog-title" ).attr( "id" ) );
equal( wrapper.attr( "aria-describedby" ), element.attr( "id" ), "aria-describedby added" ); assert.equal( wrapper.attr( "aria-describedby" ), element.attr( "id" ), "aria-describedby added" );
element.remove(); element.remove();
element = $( "<div><div aria-describedby='section2'><p id='section2'>descriotion</p></div></div>" ).dialog(); element = $( "<div><div aria-describedby='section2'><p id='section2'>descriotion</p></div></div>" ).dialog();
equal( element.dialog( "widget" ).attr( "aria-describedby" ), null, "no aria-describedby added, as already present in markup" ); assert.equal( element.dialog( "widget" ).attr( "aria-describedby" ), null, "no aria-describedby added, as already present in markup" );
element.remove(); element.remove();
} ); } );
test( "widget method", function() { QUnit.test( "widget method", function( assert ) {
expect( 1 ); assert.expect( 1 );
var dialog = $( "<div>" ).appendTo( "#qunit-fixture" ).dialog(); var dialog = $( "<div>" ).appendTo( "#qunit-fixture" ).dialog();
deepEqual( dialog.parent()[ 0 ], dialog.dialog( "widget" )[ 0 ] ); assert.deepEqual( dialog.parent()[ 0 ], dialog.dialog( "widget" )[ 0 ] );
dialog.remove(); dialog.remove();
} ); } );
asyncTest( "focus tabbable", function() { QUnit.test( "focus tabbable", function( assert ) {
expect( 8 ); var ready = assert.async();
assert.expect( 8 );
var element, var element,
options = { options = {
buttons: [ { buttons: [ {
@ -119,7 +121,7 @@ asyncTest( "focus tabbable", function() {
var input = element.find( "input:last" ).trigger( "focus" ).trigger( "blur" ); var input = element.find( "input:last" ).trigger( "focus" ).trigger( "blur" );
element.dialog( "instance" )._focusTabbable(); element.dialog( "instance" )._focusTabbable();
setTimeout( function() { setTimeout( function() {
equal( document.activeElement, input[ 0 ], assert.equal( document.activeElement, input[ 0 ],
"1. an element that was focused previously." ); "1. an element that was focused previously." );
done(); done();
} ); } );
@ -128,7 +130,7 @@ asyncTest( "focus tabbable", function() {
function step2() { function step2() {
checkFocus( "<div><input><input autofocus></div>", options, function( done ) { checkFocus( "<div><input><input autofocus></div>", options, function( done ) {
equal( document.activeElement, element.find( "input" )[ 1 ], assert.equal( document.activeElement, element.find( "input" )[ 1 ],
"2. first element inside the dialog matching [autofocus]" ); "2. first element inside the dialog matching [autofocus]" );
done(); done();
}, step3 ); }, step3 );
@ -136,7 +138,7 @@ asyncTest( "focus tabbable", function() {
function step3() { function step3() {
checkFocus( "<div><input><input></div>", options, function( done ) { checkFocus( "<div><input><input></div>", options, function( done ) {
equal( document.activeElement, element.find( "input" )[ 0 ], assert.equal( document.activeElement, element.find( "input" )[ 0 ],
"3. tabbable element inside the content element" ); "3. tabbable element inside the content element" );
done(); done();
}, step4 ); }, step4 );
@ -144,7 +146,7 @@ asyncTest( "focus tabbable", function() {
function step4() { function step4() {
checkFocus( "<div>text</div>", options, function( done ) { checkFocus( "<div>text</div>", options, function( done ) {
equal( document.activeElement, assert.equal( document.activeElement,
element.dialog( "widget" ).find( ".ui-dialog-buttonpane button" )[ 0 ], element.dialog( "widget" ).find( ".ui-dialog-buttonpane button" )[ 0 ],
"4. tabbable element inside the buttonpane" ); "4. tabbable element inside the buttonpane" );
done(); done();
@ -153,7 +155,7 @@ asyncTest( "focus tabbable", function() {
function step5() { function step5() {
checkFocus( "<div>text</div>", {}, function( done ) { checkFocus( "<div>text</div>", {}, function( done ) {
equal( document.activeElement, assert.equal( document.activeElement,
element.dialog( "widget" ).find( ".ui-dialog-titlebar .ui-dialog-titlebar-close" )[ 0 ], element.dialog( "widget" ).find( ".ui-dialog-titlebar .ui-dialog-titlebar-close" )[ 0 ],
"5. the close button" ); "5. the close button" );
done(); done();
@ -165,7 +167,7 @@ asyncTest( "focus tabbable", function() {
element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).hide(); element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).hide();
element.dialog( "open" ); element.dialog( "open" );
setTimeout( function() { setTimeout( function() {
equal( document.activeElement, element.parent()[ 0 ], "6. the dialog itself" ); assert.equal( document.activeElement, element.parent()[ 0 ], "6. the dialog itself" );
done(); done();
} ); } );
}, step7 ); }, step7 );
@ -184,36 +186,39 @@ asyncTest( "focus tabbable", function() {
} }
}, },
function( done ) { function( done ) {
var inputs = element.find( "input" ); var inputs = element.find( "input"
equal( document.activeElement, inputs[ 1 ], "Focus starts on second input" ); );
assert.equal
( document.activeElement, inputs[ 1 ], "Focus starts on second input" );
inputs.last().simulate( "keydown", { keyCode: $.ui.keyCode.TAB } ); inputs.last().simulate( "keydown", { keyCode: $.ui.keyCode.TAB } );
setTimeout( function() { setTimeout( function() {
equal( document.activeElement, inputs[ 0 ], assert.equal( document.activeElement, inputs[ 0 ],
"Honor preventDefault, allowing custom focus management" ); "Honor preventDefault, allowing custom focus management" );
done(); done();
}, 50 ); }, 50 );
}, },
start ready
); );
} }
step1(); step1();
} ); } );
test( "#7960: resizable handles below modal overlays", function() { QUnit.test( "#7960: resizable handles below modal overlays", function( assert ) {
expect( 1 ); assert.expect( 1 );
var resizable = $( "<div>" ).resizable(), var resizable = $( "<div>" ).resizable(),
dialog = $( "<div>" ).dialog( { modal: true } ), dialog = $( "<div>" ).dialog( { modal: true } ),
resizableZindex = parseInt( resizable.find( ".ui-resizable-handle" ).css( "zIndex" ), 10 ), resizableZindex = parseInt( resizable.find( ".ui-resizable-handle" ).css( "zIndex" ), 10 ),
overlayZindex = parseInt( $( ".ui-widget-overlay" ).css( "zIndex" ), 10 ); overlayZindex = parseInt( $( ".ui-widget-overlay" ).css( "zIndex" ), 10 );
ok( resizableZindex < overlayZindex, "Resizable handles have lower z-index than modal overlay" ); assert.ok( resizableZindex < overlayZindex, "Resizable handles have lower z-index than modal overlay" );
dialog.dialog( "destroy" ); dialog.dialog( "destroy" );
} ); } );
asyncTest( "Prevent tabbing out of dialogs", function() { QUnit.test( "Prevent tabbing out of dialogs", function( assert ) {
expect( 3 ); var ready = assert.async();
assert.expect( 3 );
var element = $( "<div><input name='0'><input name='1'></div>" ).dialog(), var element = $( "<div><input name='0'><input name='1'></div>" ).dialog(),
inputs = element.find( "input" ); inputs = element.find( "input" );
@ -222,7 +227,7 @@ asyncTest( "Prevent tabbing out of dialogs", function() {
element.dialog( "widget" ).find( ".ui-button" ).remove(); element.dialog( "widget" ).find( ".ui-button" ).remove();
function checkTab() { function checkTab() {
equal( document.activeElement, inputs[ 0 ], "Tab key event moved focus within the modal" ); assert.equal( document.activeElement, inputs[ 0 ], "Tab key event move d focus within the modal" );
// Check shift tab // Check shift tab
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.TAB, shiftKey: true } ); $( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.TAB, shiftKey: true } );
@ -230,23 +235,25 @@ asyncTest( "Prevent tabbing out of dialogs", function() {
} }
function checkShiftTab() { function checkShiftTab() {
equal( document.activeElement, inputs[ 1 ], "Shift-Tab key event moved focus back to second input" ); assert.equal( document.activeElement, inputs[ 1 ], "Shift-Tab key event moved focus back to second input" );
element.remove(); element.remove();
setTimeout( start ); setTimeout( ready );
} }
inputs[ 1 ].focus(); inputs[ 1 ].focus();
setTimeout( function() { setTimeout( function() {
equal( document.activeElement, inputs[ 1 ], "Focus set on second input" ); assert.equal( document.activeElement, inputs[ 1 ], "Focus set on second input" );
inputs.eq( 1 ).simulate( "keydown", { keyCode: $.ui.keyCode.TAB } ); inputs.eq( 1 ).simulate( "keydown", { keyCode: $.ui.keyCode.TAB } );
setTimeout( checkTab ); setTimeout( checkTab );
} ); } );
} ); } );
asyncTest( "#9048: multiple modal dialogs opened and closed in different order", function() { QUnit.test( "#9048: multiple modal dialogs opened and closed in different order",
expect( 1 ); function( assert ) {
var ready = assert.async();
assert.expect( 1 );
$( "#dialog1, #dialog2" ).dialog( { autoOpen: false, modal:true } ); $( "#dialog1, #dialog2" ).dialog( { autoOpen: false, modal:true } );
$( "#dialog1" ).dialog( "open" ); $( "#dialog1" ).dialog( "open" );
$( "#dialog2" ).dialog( "open" ); $( "#dialog2" ).dialog( "open" );
@ -254,19 +261,20 @@ asyncTest( "#9048: multiple modal dialogs opened and closed in different order",
setTimeout( function() { setTimeout( function() {
$( "#dialog2" ).dialog( "close" ); $( "#dialog2" ).dialog( "close" );
$( "#favorite-animal" ).trigger( "focus" ); $( "#favorite-animal" ).trigger( "focus" );
ok( true, "event handlers cleaned up (no errors thrown)" ); assert.ok( true, "event handlers cleaned up (no errors thrown)" );
start(); ready();
} ); } );
} ); } );
asyncTest( "interaction between overlay and other dialogs", function() { QUnit.test( "interaction between overlay and other dialogs", function( assert ) {
var ready = assert.async();
$.widget( "ui.testWidget", $.ui.dialog, { $.widget( "ui.testWidget", $.ui.dialog, {
options: { options: {
modal: true, modal: true,
autoOpen: false autoOpen: false
} }
} ); } );
expect( 2 ); assert.expect( 2 );
var first = $( "<div><input id='input-1'></div>" ).dialog( { var first = $( "<div><input id='input-1'></div>" ).dialog( {
modal: true modal: true
} ), } ),
@ -281,25 +289,28 @@ asyncTest( "interaction between overlay and other dialogs", function() {
// Wait for the modal to init // Wait for the modal to init
setTimeout( function() { setTimeout( function() {
second.testWidget( "open" );
// Simulate user tabbing from address bar to an element outside the dialog second.
testWidget
( "open" );
// Simulate user tabbing from address bar to an element outside the dialog
$( "#favorite-animal" ).trigger( "focus" ); $( "#favorite-animal" ).trigger( "focus" );
setTimeout( function() { setTimeout( function() {
equal( document.activeElement, secondInput[ 0 ] ); assert.equal( document.activeElement, secondInput[ 0 ] );
// Last active dialog must receive focus // Last active dialog must receive focus
firstInput.trigger( "focus" ); firstInput.trigger( "focus" );
$( "#favorite-animal" ).trigger( "focus" ); $( "#favorite-animal" ).trigger( "focus" );
setTimeout( function() { setTimeout( function() {
equal( document.activeElement, firstInput[ 0 ] ); assert.equal( document.activeElement, firstInput[ 0 ] );
// Cleanup // Cleanup
first.remove(); first.remove();
second.remove(); second.remove();
delete $.ui.testWidget; delete $.ui.testWidget;
delete $.fn.testWidget; delete $.fn.testWidget;
start(); ready();
} ); } );
} ); } );
} ); } );

View File

@ -1,12 +1,13 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/widgets/dialog" "ui/widgets/dialog"
], function( $ ) { ], function( QUnit, $ ) {
module( "dialog (deprecated): options" ); QUnit.module( "dialog (deprecated): options" );
test( "dialogClass", function( assert ) { QUnit.test( "dialogClass", function( assert ) {
expect( 5 ); assert.expect( 5 );
var element = $( "<div>" ).dialog(), var element = $( "<div>" ).dialog(),
widget = element.dialog( "widget" ); widget = element.dialog( "widget" );
@ -27,4 +28,34 @@ test( "dialogClass", function( assert ) {
element.remove(); element.remove();
} ); } );
QUnit.test( "buttons - deprecated options", function( assert ) {
assert.expect( 7 );
var buttons,
element = $( "<div></div>" ).dialog( {
buttons: [
{
html: "a button",
"class": "additional-class",
id: "my-button-id",
click: function() {
assert.equal( this, element[ 0 ], "correct context" );
},
icons: { primary: "ui-icon-cancel" },
text: false
}
]
} );
buttons = element.dialog( "widget" ).find( ".ui-dialog-buttonpane button" );
assert.equal( buttons.length, 1, "correct number of buttons" );
assert.equal( buttons.attr( "id" ), "my-button-id", "correct id" );
assert.equal( $.trim( buttons.text() ), "a button", "correct label" );
assert.hasClasses( buttons, "additional-class" );
assert.deepEqual( buttons.button( "option", "icon" ), "ui-icon-cancel" );
assert.equal( buttons.button( "option", "showLabel" ), false );
buttons.trigger( "click" );
element.remove();
} );
} ); } );

View File

@ -1,22 +1,23 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"./helper", "./helper",
"ui/widgets/dialog" "ui/widgets/dialog"
], function( $, testHelper ) { ], function( QUnit, $, testHelper ) {
module( "dialog: events" ); QUnit.module( "dialog: events" );
test( "open", function() { QUnit.test( "open", function( assert ) {
expect( 13 ); assert.expect( 13 );
var element = $( "<div></div>" ); var element = $( "<div></div>" );
element.dialog( { element.dialog( {
open: function( ev, ui ) { open: function( ev, ui ) {
ok( element.dialog( "instance" )._isOpen, "interal _isOpen flag is set" ); assert.ok( element.dialog( "instance" )._isOpen, "interal _isOpen flag is set" );
ok( true, "autoOpen: true fires open callback" ); assert.ok( true, "autoOpen: true fires open callback" );
equal( this, element[ 0 ], "context of callback" ); assert.equal( this, element[ 0 ], "context of callback" );
equal( ev.type, "dialogopen", "event type in callback" ); assert.equal( ev.type, "dialogopen", "event type in callback" );
deepEqual( ui, {}, "ui hash in callback" ); assert.deepEqual( ui, {}, "ui hash in callback" );
} }
} ); } );
element.remove(); element.remove();
@ -25,23 +26,23 @@ test( "open", function() {
element.dialog( { element.dialog( {
autoOpen: false, autoOpen: false,
open: function( ev, ui ) { open: function( ev, ui ) {
ok( true, ".dialog('open') fires open callback" ); assert.ok( true, ".dialog('open') fires open callback" );
equal( this, element[ 0 ], "context of callback" ); assert.equal( this, element[ 0 ], "context of callback" );
equal( ev.type, "dialogopen", "event type in callback" ); assert.equal( ev.type, "dialogopen", "event type in callback" );
deepEqual( ui, {}, "ui hash in callback" ); assert.deepEqual( ui, {}, "ui hash in callback" );
} }
} ).on( "dialogopen", function( ev, ui ) { } ).on( "dialogopen", function( ev, ui ) {
ok( element.dialog( "instance" )._isOpen, "interal _isOpen flag is set" ); assert.ok( element.dialog( "instance" )._isOpen, "interal _isOpen flag is set" );
ok( true, "dialog('open') fires open event" ); assert.ok( true, "dialog('open') fires open event" );
equal( this, element[ 0 ], "context of event" ); assert.equal( this, element[ 0 ], "context of event" );
deepEqual( ui, {}, "ui hash in event" ); assert.deepEqual( ui, {}, "ui hash in event" );
} ); } );
element.dialog( "open" ); element.dialog( "open" );
element.remove(); element.remove();
} ); } );
test( "focus", function() { QUnit.test( "focus", function( assert ) {
expect( 5 ); assert.expect( 5 );
var element, other; var element, other;
element = $( "#dialog1" ).dialog( { element = $( "#dialog1" ).dialog( {
autoOpen: false autoOpen: false
@ -51,27 +52,27 @@ test( "focus", function() {
} ); } );
element.one( "dialogopen", function() { element.one( "dialogopen", function() {
ok( true, "open, just once" ); assert.ok( true, "open, just once" );
} ); } );
element.one( "dialogfocus", function() { element.one( "dialogfocus", function() {
ok( true, "focus on open" ); assert.ok( true, "focus on open" );
} ); } );
other.dialog( "open" ); other.dialog( "open" );
element.one( "dialogfocus", function() { element.one( "dialogfocus", function() {
ok( true, "when opening and already open and wasn't on top" ); assert.ok( true, "when opening and already open and wasn't on top" );
} ); } );
other.dialog( "open" ); other.dialog( "open" );
element.dialog( "open" ); element.dialog( "open" );
element.one( "dialogfocus", function() { element.one( "dialogfocus", function() {
ok( true, "when calling moveToTop and wasn't on top" ); assert.ok( true, "when calling moveToTop and wasn't on top" );
} ); } );
other.dialog( "moveToTop" ); other.dialog( "moveToTop" );
element.dialog( "moveToTop" ); element.dialog( "moveToTop" );
element.on( "dialogfocus", function() { element.on( "dialogfocus", function() {
ok( true, "when mousedown anywhere on the dialog and it wasn't on top" ); assert.ok( true, "when mousedown anywhere on the dialog and it wasn't on top" );
} ); } );
other.dialog( "moveToTop" ); other.dialog( "moveToTop" );
element.trigger( "mousedown" ); element.trigger( "mousedown" );
@ -84,23 +85,23 @@ test( "focus", function() {
element.add( other ).remove(); element.add( other ).remove();
} ); } );
test( "dragStart", function() { QUnit.test( "dragStart", function( assert ) {
expect( 9 ); assert.expect( 9 );
var handle, var handle,
element = $( "<div></div>" ).dialog( { element = $( "<div></div>" ).dialog( {
dragStart: function( ev, ui ) { dragStart: function( ev, ui ) {
ok( true, "dragging fires dragStart callback" ); assert.ok( true, "dragging fires dragStart callback" );
equal( this, element[ 0 ], "context of callback" ); assert.equal( this, element[ 0 ], "context of callback" );
equal( ev.type, "dialogdragstart", "event type in callback" ); assert.equal( ev.type, "dialogdragstart", "event type in callback" );
ok( ui.position !== undefined, "ui.position in callback" ); assert.ok( ui.position !== undefined, "ui.position in callback" );
ok( ui.offset !== undefined, "ui.offset in callback" ); assert.ok( ui.offset !== undefined, "ui.offset in callback" );
} }
} ).on( "dialogdragstart", function( ev, ui ) { } ).on( "dialogdragstart", function( ev, ui ) {
ok( true, "dragging fires dialogdragstart event" ); assert.ok( true, "dragging fires dialogdragstart event" );
equal( this, element[ 0 ], "context of event" ); assert.equal( this, element[ 0 ], "context of event" );
ok( ui.position !== undefined, "ui.position in callback" ); assert.ok( ui.position !== undefined, "ui.position in callback" );
ok( ui.offset !== undefined, "ui.offset in callback" ); assert.ok( ui.offset !== undefined, "ui.offset in callback" );
} ); } );
handle = $( ".ui-dialog-titlebar", element.dialog( "widget" ) ); handle = $( ".ui-dialog-titlebar", element.dialog( "widget" ) );
@ -108,27 +109,27 @@ test( "dragStart", function() {
element.remove(); element.remove();
} ); } );
test( "drag", function() { QUnit.test( "drag", function( assert ) {
expect( 9 ); assert.expect( 9 );
var handle, var handle,
hasDragged = false, hasDragged = false,
element = $( "<div></div>" ).dialog( { element = $( "<div></div>" ).dialog( {
drag: function( ev, ui ) { drag: function( ev, ui ) {
if ( !hasDragged ) { if ( !hasDragged ) {
ok( true, "dragging fires drag callback" ); assert.ok( true, "dragging fires drag callback" );
equal( this, element[ 0 ], "context of callback" ); assert.equal( this, element[ 0 ], "context of callback" );
equal( ev.type, "dialogdrag", "event type in callback" ); assert.equal( ev.type, "dialogdrag", "event type in callback" );
ok( ui.position !== undefined, "ui.position in callback" ); assert.ok( ui.position !== undefined, "ui.position in callback" );
ok( ui.offset !== undefined, "ui.offset in callback" ); assert.ok( ui.offset !== undefined, "ui.offset in callback" );
hasDragged = true; hasDragged = true;
} }
} }
} ).one( "dialogdrag", function( ev, ui ) { } ).one( "dialogdrag", function( ev, ui ) {
ok( true, "dragging fires dialogdrag event" ); assert.ok( true, "dragging fires dialogdrag event" );
equal( this, element[ 0 ], "context of event" ); assert.equal( this, element[ 0 ], "context of event" );
ok( ui.position !== undefined, "ui.position in callback" ); assert.ok( ui.position !== undefined, "ui.position in callback" );
ok( ui.offset !== undefined, "ui.offset in callback" ); assert.ok( ui.offset !== undefined, "ui.offset in callback" );
} ); } );
handle = $( ".ui-dialog-titlebar", element.dialog( "widget" ) ); handle = $( ".ui-dialog-titlebar", element.dialog( "widget" ) );
@ -136,23 +137,23 @@ test( "drag", function() {
element.remove(); element.remove();
} ); } );
test( "dragStop", function() { QUnit.test( "dragStop", function( assert ) {
expect( 9 ); assert.expect( 9 );
var handle, var handle,
element = $( "<div></div>" ).dialog( { element = $( "<div></div>" ).dialog( {
dragStop: function( ev, ui ) { dragStop: function( ev, ui ) {
ok( true, "dragging fires dragStop callback" ); assert.ok( true, "dragging fires dragStop callback" );
equal( this, element[ 0 ], "context of callback" ); assert.equal( this, element[ 0 ], "context of callback" );
equal( ev.type, "dialogdragstop", "event type in callback" ); assert.equal( ev.type, "dialogdragstop", "event type in callback" );
ok( ui.position !== undefined, "ui.position in callback" ); assert.ok( ui.position !== undefined, "ui.position in callback" );
ok( ui.offset !== undefined, "ui.offset in callback" ); assert.ok( ui.offset !== undefined, "ui.offset in callback" );
} }
} ).on( "dialogdragstop", function( ev, ui ) { } ).on( "dialogdragstop", function( ev, ui ) {
ok( true, "dragging fires dialogdragstop event" ); assert.ok( true, "dragging fires dialogdragstop event" );
equal( this, element[ 0 ], "context of event" ); assert.equal( this, element[ 0 ], "context of event" );
ok( ui.position !== undefined, "ui.position in callback" ); assert.ok( ui.position !== undefined, "ui.position in callback" );
ok( ui.offset !== undefined, "ui.offset in callback" ); assert.ok( ui.offset !== undefined, "ui.offset in callback" );
} ); } );
handle = $( ".ui-dialog-titlebar", element.dialog( "widget" ) ); handle = $( ".ui-dialog-titlebar", element.dialog( "widget" ) );
@ -160,27 +161,27 @@ test( "dragStop", function() {
element.remove(); element.remove();
} ); } );
test( "resizeStart", function() { QUnit.test( "resizeStart", function( assert ) {
expect( 13 ); assert.expect( 13 );
var handle, var handle,
element = $( "<div></div>" ).dialog( { element = $( "<div></div>" ).dialog( {
resizeStart: function( ev, ui ) { resizeStart: function( ev, ui ) {
ok( true, "resizing fires resizeStart callback" ); assert.ok( true, "resizing fires resizeStart callback" );
equal( this, element[ 0 ], "context of callback" ); assert.equal( this, element[ 0 ], "context of callback" );
equal( ev.type, "dialogresizestart", "event type in callback" ); assert.equal( ev.type, "dialogresizestart", "event type in callback" );
ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" ); assert.ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" );
ok( ui.originalSize !== undefined, "ui.originalSize in callback" ); assert.ok( ui.originalSize !== undefined, "ui.originalSize in callback" );
ok( ui.position !== undefined, "ui.position in callback" ); assert.ok( ui.position !== undefined, "ui.position in callback" );
ok( ui.size !== undefined, "ui.size in callback" ); assert.ok( ui.size !== undefined, "ui.size in callback" );
} }
} ).on( "dialogresizestart", function( ev, ui ) { } ).on( "dialogresizestart", function( ev, ui ) {
ok( true, "resizing fires dialogresizestart event" ); assert.ok( true, "resizing fires dialogresizestart event" );
equal( this, element[ 0 ], "context of event" ); assert.equal( this, element[ 0 ], "context of event" );
ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" ); assert.ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" );
ok( ui.originalSize !== undefined, "ui.originalSize in callback" ); assert.ok( ui.originalSize !== undefined, "ui.originalSize in callback" );
ok( ui.position !== undefined, "ui.position in callback" ); assert.ok( ui.position !== undefined, "ui.position in callback" );
ok( ui.size !== undefined, "ui.size in callback" ); assert.ok( ui.size !== undefined, "ui.size in callback" );
} ); } );
handle = $( ".ui-resizable-se", element.dialog( "widget" ) ); handle = $( ".ui-resizable-se", element.dialog( "widget" ) );
@ -188,31 +189,31 @@ test( "resizeStart", function() {
element.remove(); element.remove();
} ); } );
test( "resize", function() { QUnit.test( "resize", function( assert ) {
expect( 13 ); assert.expect( 13 );
var handle, var handle,
hasResized = false, hasResized = false,
element = $( "<div></div>" ).dialog( { element = $( "<div></div>" ).dialog( {
resize: function( ev, ui ) { resize: function( ev, ui ) {
if ( !hasResized ) { if ( !hasResized ) {
ok( true, "resizing fires resize callback" ); assert.ok( true, "resizing fires resize callback" );
equal( this, element[ 0 ], "context of callback" ); assert.equal( this, element[ 0 ], "context of callback" );
equal( ev.type, "dialogresize", "event type in callback" ); assert.equal( ev.type, "dialogresize", "event type in callback" );
ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" ); assert.ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" );
ok( ui.originalSize !== undefined, "ui.originalSize in callback" ); assert.ok( ui.originalSize !== undefined, "ui.originalSize in callback" );
ok( ui.position !== undefined, "ui.position in callback" ); assert.ok( ui.position !== undefined, "ui.position in callback" );
ok( ui.size !== undefined, "ui.size in callback" ); assert.ok( ui.size !== undefined, "ui.size in callback" );
hasResized = true; hasResized = true;
} }
} }
} ).one( "dialogresize", function( ev, ui ) { } ).one( "dialogresize", function( ev, ui ) {
ok( true, "resizing fires dialogresize event" ); assert.ok( true, "resizing fires dialogresize event" );
equal( this, element[ 0 ], "context of event" ); assert.equal( this, element[ 0 ], "context of event" );
ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" ); assert.ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" );
ok( ui.originalSize !== undefined, "ui.originalSize in callback" ); assert.ok( ui.originalSize !== undefined, "ui.originalSize in callback" );
ok( ui.position !== undefined, "ui.position in callback" ); assert.ok( ui.position !== undefined, "ui.position in callback" );
ok( ui.size !== undefined, "ui.size in callback" ); assert.ok( ui.size !== undefined, "ui.size in callback" );
} ); } );
handle = $( ".ui-resizable-se", element.dialog( "widget" ) ); handle = $( ".ui-resizable-se", element.dialog( "widget" ) );
@ -220,27 +221,27 @@ test( "resize", function() {
element.remove(); element.remove();
} ); } );
test( "resizeStop", function() { QUnit.test( "resizeStop", function( assert ) {
expect( 13 ); assert.expect( 13 );
var handle, var handle,
element = $( "<div></div>" ).dialog( { element = $( "<div></div>" ).dialog( {
resizeStop: function( ev, ui ) { resizeStop: function( ev, ui ) {
ok( true, "resizing fires resizeStop callback" ); assert.ok( true, "resizing fires resizeStop callback" );
equal( this, element[ 0 ], "context of callback" ); assert.equal( this, element[ 0 ], "context of callback" );
equal( ev.type, "dialogresizestop", "event type in callback" ); assert.equal( ev.type, "dialogresizestop", "event type in callback" );
ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" ); assert.ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" );
ok( ui.originalSize !== undefined, "ui.originalSize in callback" ); assert.ok( ui.originalSize !== undefined, "ui.originalSize in callback" );
ok( ui.position !== undefined, "ui.position in callback" ); assert.ok( ui.position !== undefined, "ui.position in callback" );
ok( ui.size !== undefined, "ui.size in callback" ); assert.ok( ui.size !== undefined, "ui.size in callback" );
} }
} ).on( "dialogresizestop", function( ev, ui ) { } ).on( "dialogresizestop", function( ev, ui ) {
ok( true, "resizing fires dialogresizestop event" ); assert.ok( true, "resizing fires dialogresizestop event" );
equal( this, element[ 0 ], "context of event" ); assert.equal( this, element[ 0 ], "context of event" );
ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" ); assert.ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" );
ok( ui.originalSize !== undefined, "ui.originalSize in callback" ); assert.ok( ui.originalSize !== undefined, "ui.originalSize in callback" );
ok( ui.position !== undefined, "ui.position in callback" ); assert.ok( ui.position !== undefined, "ui.position in callback" );
ok( ui.size !== undefined, "ui.size in callback" ); assert.ok( ui.size !== undefined, "ui.size in callback" );
} ); } );
handle = $( ".ui-resizable-se", element.dialog( "widget" ) ); handle = $( ".ui-resizable-se", element.dialog( "widget" ) );
@ -248,20 +249,21 @@ test( "resizeStop", function() {
element.remove(); element.remove();
} ); } );
asyncTest( "close", function() { QUnit.test( "close", function( assert ) {
expect( 14 ); var ready = assert.async();
assert.expect( 14 );
var element = $( "<div></div>" ).dialog( { var element = $( "<div></div>" ).dialog( {
close: function( ev, ui ) { close: function( ev, ui ) {
ok( true, ".dialog('close') fires close callback" ); assert.ok( true, ".dialog('close') fires close callback" );
equal( this, element[ 0 ], "context of callback" ); assert.equal( this, element[ 0 ], "context of callback" );
equal( ev.type, "dialogclose", "event type in callback" ); assert.equal( ev.type, "dialogclose", "event type in callback" );
deepEqual( ui, {}, "ui hash in callback" ); assert.deepEqual( ui, {}, "ui hash in callback" );
} }
} ).on( "dialogclose", function( ev, ui ) { } ).on( "dialogclose", function( ev, ui ) {
ok( true, ".dialog('close') fires dialogclose event" ); assert.ok( true, ".dialog('close') fires dialogclose event" );
equal( this, element[ 0 ], "context of event" ); assert.equal( this, element[ 0 ], "context of event" );
deepEqual( ui, {}, "ui hash in event" ); assert.deepEqual( ui, {}, "ui hash in event" );
} ); } );
element.dialog( "close" ); element.dialog( "close" );
element.remove(); element.remove();
@ -270,100 +272,101 @@ asyncTest( "close", function() {
element = $( "<div></div>" ).dialog( { element = $( "<div></div>" ).dialog( {
hide: 10, hide: 10,
close: function( ev, ui ) { close: function( ev, ui ) {
ok( true, ".dialog('close') fires close callback" ); assert.ok( true, ".dialog('close') fires close callback" );
equal( this, element[ 0 ], "context of callback" ); assert.equal( this, element[ 0 ], "context of callback" );
equal( ev.type, "dialogclose", "event type in callback" ); assert.equal( ev.type, "dialogclose", "event type in callback" );
deepEqual( ui, {}, "ui hash in callback" ); assert.deepEqual( ui, {}, "ui hash in callback" );
start(); ready();
} }
} ).on( "dialogclose", function( ev, ui ) { } ).on( "dialogclose", function( ev, ui ) {
ok( true, ".dialog('close') fires dialogclose event" ); assert.ok( true, ".dialog('close') fires dialogclose event" );
equal( this, element[ 0 ], "context of event" ); assert.equal( this, element[ 0 ], "context of event" );
deepEqual( ui, {}, "ui hash in event" ); assert.deepEqual( ui, {}, "ui hash in event" );
} ); } );
element.dialog( "close" ); element.dialog( "close" );
} ); } );
test( "beforeClose", function() { QUnit.test( "beforeClose", function( assert ) {
expect( 14 ); assert.expect( 14 );
var element = $( "<div></div>" ).dialog( { var element = $( "<div></div>" ).dialog( {
beforeClose: function( ev, ui ) { beforeClose: function( ev, ui ) {
ok( true, ".dialog('close') fires beforeClose callback" ); assert.ok( true, ".dialog('close') fires beforeClose callback" );
equal( this, element[ 0 ], "context of callback" ); assert.equal( this, element[ 0 ], "context of callback" );
equal( ev.type, "dialogbeforeclose", "event type in callback" ); assert.equal( ev.type, "dialogbeforeclose", "event type in callback" );
deepEqual( ui, {}, "ui hash in callback" ); assert.deepEqual( ui, {}, "ui hash in callback" );
return false; return false;
} }
} ); } );
element.dialog( "close" ); element.dialog( "close" );
ok( element.dialog( "widget" ).is( ":visible" ), "beforeClose callback should prevent dialog from closing" ); assert.ok( element.dialog( "widget" ).is( ":visible" ), "beforeClose callback should prevent dialog from closing" );
element.remove(); element.remove();
element = $( "<div></div>" ).dialog(); element = $( "<div></div>" ).dialog();
element.dialog( "option", "beforeClose", function( ev, ui ) { element.dialog( "option", "beforeClose", function( ev, ui ) {
ok( true, ".dialog('close') fires beforeClose callback" ); assert.ok( true, ".dialog('close') fires beforeClose callback" );
equal( this, element[ 0 ], "context of callback" ); assert.equal( this, element[ 0 ], "context of callback" );
equal( ev.type, "dialogbeforeclose", "event type in callback" ); assert.equal( ev.type, "dialogbeforeclose", "event type in callback" );
deepEqual( ui, {}, "ui hash in callback" ); assert.deepEqual( ui, {}, "ui hash in callback" );
return false; return false;
} ); } );
element.dialog( "close" ); element.dialog( "close" );
ok( element.dialog( "widget" ).is( ":visible" ), "beforeClose callback should prevent dialog from closing" ); assert.ok( element.dialog( "widget" ).is( ":visible" ), "beforeClose callback should prevent dialog from closing" );
element.remove(); element.remove();
element = $( "<div></div>" ).dialog().on( "dialogbeforeclose", function( ev, ui ) { element = $( "<div></div>" ).dialog().on( "dialogbeforeclose", function( ev, ui ) {
ok( true, ".dialog('close') triggers dialogbeforeclose event" ); assert.ok( true, ".dialog('close') triggers dialogbeforeclose event" );
equal( this, element[ 0 ], "context of event" ); assert.equal( this, element[ 0 ], "context of event" );
deepEqual( ui, {}, "ui hash in event" ); assert.deepEqual( ui, {}, "ui hash in event" );
return false; return false;
} ); } );
element.dialog( "close" ); element.dialog( "close" );
ok( element.dialog( "widget" ).is( ":visible" ), "dialogbeforeclose event should prevent dialog from closing" ); assert.ok( element.dialog( "widget" ).is( ":visible" ), "dialogbeforeclose event should prevent dialog from closing" );
element.remove(); element.remove();
} ); } );
// #8789 and #8838 // #8789 and #8838
asyncTest( "ensure dialog's container doesn't scroll on resize and focus", function() { QUnit.test( "ensure dialog's container doesn't scroll on resize and focus", function( assert ) {
expect( 2 ); var ready = assert.async();
assert.expect( 2 );
var element = $( "#dialog1" ).dialog(), var element = $( "#dialog1" ).dialog(),
initialScroll = $( window ).scrollTop(); initialScroll = $( window ).scrollTop();
element.dialog( "option", "height", 600 ); element.dialog( "option", "height", 600 );
equal( $( window ).scrollTop(), initialScroll, "scroll hasn't moved after height change" ); assert.equal( $( window ).scrollTop(), initialScroll, "scroll hasn't moved after height change" );
setTimeout( function() { setTimeout( function() {
$( ".ui-dialog-titlebar-close" ).simulate( "mousedown" ); $( ".ui-dialog-titlebar-close" ).simulate( "mousedown" );
equal( $( window ).scrollTop(), initialScroll, "scroll hasn't moved after focus moved to dialog" ); assert.equal( $( window ).scrollTop(), initialScroll, "scroll hasn't moved after focus moved to dialog" );
element.dialog( "destroy" ); element.dialog( "destroy" );
start(); ready();
} ); } );
} ); } );
test( "#5184: isOpen in dialogclose event is true", function() { QUnit.test( "#5184: isOpen in dialogclose event is true", function( assert ) {
expect( 3 ); assert.expect( 3 );
var element = $( "<div></div>" ).dialog( { var element = $( "<div></div>" ).dialog( {
close: function() { close: function() {
ok( !element.dialog( "isOpen" ), "dialog is not open during close" ); assert.ok( !element.dialog( "isOpen" ), "dialog is not open during close" );
} }
} ); } );
ok( element.dialog( "isOpen" ), "dialog is open after init" ); assert.ok( element.dialog( "isOpen" ), "dialog is open after init" );
element.dialog( "close" ); element.dialog( "close" );
ok( !element.dialog( "isOpen" ), "dialog is not open after close" ); assert.ok( !element.dialog( "isOpen" ), "dialog is not open after close" );
element.remove(); element.remove();
} ); } );
test( "ensure dialog keeps focus when clicking modal overlay", function() { QUnit.test( "ensure dialog keeps focus when clicking modal overlay", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "<div></div>" ).dialog( { var element = $( "<div></div>" ).dialog( {
modal: true modal: true
} ); } );
equal( $( document.activeElement ).closest( ".ui-dialog" ).length, 1, "focus is in dialog" ); assert.equal( $( document.activeElement ).closest( ".ui-dialog" ).length, 1, "focus is in dialog" );
$( ".ui-widget-overlay" ).simulate( "mousedown" ); $( ".ui-widget-overlay" ).simulate( "mousedown" );
equal( $( document.activeElement ).closest( ".ui-dialog" ).length, 1, "focus is still in dialog" ); assert.equal( $( document.activeElement ).closest( ".ui-dialog" ).length, 1, "focus is still in dialog" );
element.remove(); element.remove();
} ); } );

View File

@ -1,21 +1,22 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"lib/helper", "lib/helper",
"ui/widgets/dialog" "ui/widgets/dialog"
], function( $, helper ) { ], function( QUnit, $, helper ) {
return $.extend( helper, { return $.extend( helper, {
drag: function( element, handle, dx, dy ) { drag: function( element, handle, dx, dy ) {
var d = element.dialog( "widget" ); var d = element.dialog( "widget" );
//this mouseover is to work around a limitation in resizable //This mouseover is to work around a limitation in resizable
//TODO: fix resizable so handle doesn't require mouseover in order to be used //TODO: fix resizable so handle doesn't require mouseover in order to be used
$( handle, d ).simulate( "mouseover" ).simulate( "drag", { $( handle, d ).simulate( "mouseover" ).simulate( "drag", {
dx: dx, dx: dx,
dy: dy dy: dy
} ); } );
}, },
testDrag: function( element, dx, dy, expectedDX, expectedDY, msg ) { testDrag: function( assert, element, dx, dy, expectedDX, expectedDY, msg ) {
var actualDX, actualDY, offsetAfter, var actualDX, actualDY, offsetAfter,
d = element.dialog( "widget" ), d = element.dialog( "widget" ),
handle = $( ".ui-dialog-titlebar", d ), handle = $( ".ui-dialog-titlebar", d ),
@ -29,14 +30,11 @@ return $.extend( helper, {
actualDX = offsetAfter.left - offsetBefore.left; actualDX = offsetAfter.left - offsetBefore.left;
actualDY = offsetAfter.top - offsetBefore.top; actualDY = offsetAfter.top - offsetBefore.top;
ok( expectedDX - actualDX <= 1 && expectedDY - actualDY <= 1, "dragged[" + expectedDX + ", " + expectedDY + "] " + msg ); assert.ok( expectedDX - actualDX <= 1 && expectedDY - actualDY <= 1, "dragged[" + expectedDX + ", " + expectedDY + "] " + msg );
}, },
// TODO switch back to checking the size of the .ui-dialog element (var d) shouldResize: function( assert, element, dw, dh, msg ) {
// once we switch to using box-sizing: border-box (#9845) that should work fine var actualDH, actualDW, heightAfter, widthAfter,
// using the element's dimensions to avoid subpixel errors
shouldResize: function( element, dw, dh, msg ) {
var heightAfter, widthAfter, actual, expected,
d = element.dialog( "widget" ), d = element.dialog( "widget" ),
handle = $( ".ui-resizable-se", d ), handle = $( ".ui-resizable-se", d ),
heightBefore = element.height(), heightBefore = element.height(),
@ -48,9 +46,13 @@ return $.extend( helper, {
widthAfter = element.width(); widthAfter = element.width();
msg = msg ? msg + "." : ""; msg = msg ? msg + "." : "";
actual = { width: widthAfter, height: heightAfter },
expected = { width: widthBefore + dw, height: heightBefore + dh }; actualDH = heightAfter - heightBefore;
deepEqual( actual, expected, "resized[" + 50 + ", " + 50 + "] " + msg ); actualDW = widthAfter - widthBefore;
// TODO: Switch to assert.close().
// Also change the testDrag() helper.
assert.ok( Math.abs( actualDH - dh ) <= 1 && Math.abs( actualDW - dw ) <= 1, "resized[50, 50] " + msg );
} }
} ); } );

Some files were not shown because too many files have changed in this diff Show More