aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--demos/selectmenu/custom_render.html120
-rw-r--r--demos/selectmenu/default.html102
-rw-r--r--demos/selectmenu/images/24-podcast-square.pngbin0 -> 681 bytes
-rw-r--r--demos/selectmenu/images/24-rss-square.pngbin0 -> 594 bytes
-rw-r--r--demos/selectmenu/images/24-video-square.pngbin0 -> 649 bytes
-rw-r--r--demos/selectmenu/index.html17
-rw-r--r--tests/unit/selectmenu/all.html30
-rw-r--r--tests/unit/selectmenu/selectmenu.html87
-rw-r--r--tests/unit/selectmenu/selectmenu_core.js59
-rw-r--r--tests/unit/selectmenu/selectmenu_defaults.js20
-rw-r--r--tests/unit/selectmenu/selectmenu_events.js7
-rw-r--r--tests/unit/selectmenu/selectmenu_methods.js73
-rw-r--r--tests/unit/selectmenu/selectmenu_options.js7
-rw-r--r--tests/visual/selectmenu/autocomplete.html94
-rw-r--r--tests/visual/selectmenu/dialog.html72
-rw-r--r--tests/visual/selectmenu/disabled.html137
-rw-r--r--tests/visual/selectmenu/events.html74
-rw-r--r--tests/visual/selectmenu/methods.html74
-rw-r--r--tests/visual/selectmenu/option.html63
-rw-r--r--tests/visual/selectmenu/tabs.html68
-rw-r--r--themes/base/jquery.ui.base.css1
-rw-r--r--themes/base/jquery.ui.selectmenu.css20
-rw-r--r--ui/jquery.ui.selectmenu.js413
23 files changed, 1538 insertions, 0 deletions
diff --git a/demos/selectmenu/custom_render.html b/demos/selectmenu/custom_render.html
new file mode 100644
index 000000000..f993bab2a
--- /dev/null
+++ b/demos/selectmenu/custom_render.html
@@ -0,0 +1,120 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>jQuery UI Selectmenu - Default functionality</title>
+ <link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
+ <script src="../../jquery-1.7.js"></script>
+ <script src="../../ui/jquery.ui.core.js"></script>
+ <script src="../../ui/jquery.ui.widget.js"></script>
+ <script src="../../ui/jquery.ui.position.js"></script>
+ <script src="../../ui/jquery.ui.button.js"></script>
+ <script src="../../ui/jquery.ui.menu.js"></script>
+ <script src="../../ui/jquery.ui.selectmenu.js"></script>
+ <link rel="stylesheet" href="../demos.css">
+ <script>
+ $(function() {
+
+ $.widget( "custom.iconselectmenu", $.ui.selectmenu, {
+ _renderItem: function( ul, item ) {
+ var li = $( "<li />" ).data( "item.selectmenu", item );
+ if ( item.disabled ) {
+ li.addClass( 'ui-state-disabled' ).text( item.label );
+ } else {
+ el = item.element;
+ var link = $( "<a />", {
+ html: icon = '<span style="' + el.attr("style") + '" class="ui-icon ' + el.attr("class") + '"></span>' + item.label,
+ href: '#'
+ });
+ li.append( link );
+ }
+
+ return li.appendTo( ul );
+ }
+ });
+
+ var files = $('select#files').iconselectmenu({
+ dropdown: false
+ });
+ files.iconselectmenu("widget").children("ul").addClass("ui-menu-icons");
+
+ var filesB = $('select#filesB').iconselectmenu({
+ dropdown: false
+ });
+ filesB.iconselectmenu("widget").children("ul").addClass("ui-menu-icons customicons");
+
+ var peopleA = $('select#peopleA').iconselectmenu();
+ peopleA.iconselectmenu("widget").children("ul").addClass("ui-menu-icons avatar");
+ });
+ </script>
+ <style>
+ form { margin: 100px 0 0 0 }
+ h2 { margin: 30px 0 0 0 }
+ fieldset { border: 0; }
+ label { display: block; }
+ select { width: 200px; }
+
+ .ui-selectmenu-menu .ui-menu .ui-icon { top: 0.4em; }
+ .ui-selectmenu-menu .ui-menu .ui-menu-item a { padding-left: 2em; }
+
+ /* select with custom icons */
+ .ui-selectmenu-menu .ui-menu.customicons .ui-menu-item a { padding: 0.5em 0 0.5em 3em; }
+ .ui-selectmenu-menu .ui-menu.customicons .ui-menu-item a .ui-icon { height: 24px; width: 24px; top: 0.2em;}
+ .ui-icon.video { background: url(images/24-video-square.png) 0 0 no-repeat; }
+ .ui-icon.podcast { background: url(images/24-podcast-square.png) 0 0 no-repeat; }
+ .ui-icon.rss { background: url(images/24-rss-square.png) 0 0 no-repeat; }
+
+ /* native select with CSS avatar icons */
+ option.avatar { background-repeat: no-repeat !important; padding-left: 20px; }
+ </style>
+</head>
+<body>
+
+<div class="demo">
+
+<form action="#">
+
+ <h2>"popup" style with framework icons</h2>
+ <fieldset>
+ <label for="files">Select a File:</label>
+ <select name="files" id="files">
+ <option value="jquery" class="ui-icon-script">jQuery.js</option>
+ <option value="jquerylogo" class="ui-icon-image">jQuery Logo</option>
+ <option value="jqueryui" class="ui-icon-script">ui.jQuery.js</option>
+ <option value="jqueryuilogo" selected="selected" class="ui-icon-image">jQuery UI Logo</option>
+ <option value="somefile">Some unknown file</option>
+ </select>
+ </fieldset>
+
+ <h2>"popup" style with custom icon images</h2>
+ <fieldset>
+ <label for="filesB">Select a File:</label>
+ <select name="filesB" id="filesB">
+ <option value="mypodcast" class="podcast">John Resig Podcast</option>
+ <option value="myvideo" class="video">Scott Gonzales Video</option>
+ <option value="myrss" class="rss">jQuery RSS XML</option>
+ </select>
+ </fieldset>
+
+ <h2>"dropdown" style with custom avatar 16x16 images as CSS background</h2>
+ <fieldset>
+ <label for="peopleA">Select a Person:</label>
+ <select name="peopleA" id="peopleA">
+ <option value="1" class="avatar" style="background-image: url(http://www.gravatar.com/avatar/b3e04a46e85ad3e165d66f5d927eb609?d=monsterid&r=g&s=16);">John Resig</option>
+ <option value="2" class="avatar" style="background-image: url(http://www.gravatar.com/avatar/e42b1e5c7cfd2be0933e696e292a4d5f?d=monsterid&r=g&s=16);">Tauren Mills</option>
+ <option value="3" class="avatar" style="background-image: url(http://www.gravatar.com/avatar/bdeaec11dd663f26fa58ced0eb7facc8?d=monsterid&r=g&s=16);">Jane Doe</option>
+ </select>
+ </fieldset>
+
+</form>
+
+</div><!-- End demo -->
+
+
+
+<div class="demo-description">
+<p>The whole rendering process is extendable to make custom styling as easy as possible.</p>
+</div><!-- End demo-description -->
+
+</body>
+</html>
diff --git a/demos/selectmenu/default.html b/demos/selectmenu/default.html
new file mode 100644
index 000000000..5ae45472a
--- /dev/null
+++ b/demos/selectmenu/default.html
@@ -0,0 +1,102 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>jQuery UI Selectmenu - Default functionality</title>
+ <link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
+ <script src="../../jquery-1.7.js"></script>
+ <script src="../../ui/jquery.ui.core.js"></script>
+ <script src="../../ui/jquery.ui.widget.js"></script>
+ <script src="../../ui/jquery.ui.position.js"></script>
+ <script src="../../ui/jquery.ui.button.js"></script>
+ <script src="../../ui/jquery.ui.menu.js"></script>
+ <script src="../../ui/jquery.ui.selectmenu.js"></script>
+ <link rel="stylesheet" href="../demos.css">
+ <script>
+ $(function() {
+ $('select#speed').selectmenu();
+
+ var withOverflow = $('select#number').selectmenu({
+ dropdown: false
+ });
+ withOverflow.selectmenu("widget").addClass("overflow");
+
+ $('select#files').selectmenu();
+
+ });
+ </script>
+ <style>
+ form { margin: 100px 0 0 0 }
+ fieldset { border: 0; }
+ label { display: block; }
+ select { width: 200px; }
+ .overflow ul { height: 200px; overflow: auto; overflow-y: auto; overflow-x: hidden;}
+ </style>
+</head>
+<body>
+
+<div class="demo">
+
+<form action="#">
+ <fieldset>
+ <label for="speed">Select a speed:</label>
+ <select name="speed" id="speed">
+ <option value="Slower">Slower</option>
+ <option value="Slow">Slow</option>
+ <option value="Medium" selected="selected">Medium</option>
+ <option value="Fast">Fast</option>
+ <option value="Faster">Faster</option>
+ </select>
+ <br />
+ <br />
+ <br />
+ <label for="number">Select a number:</label>
+ <select name="number" id="number">
+ <option value="1">1</option>
+ <option value="2" selected="selected">2</option>
+ <option value="3">3</option>
+ <option value="4">4</option>
+ <option value="5">5</option>
+ <option value="6">6</option>
+ <option value="7">7</option>
+ <option value="8">8</option>
+ <option value="9">9</option>
+ <option value="10">10</option>
+ <option value="11">11</option>
+ <option value="12">12</option>
+ <option value="13">13</option>
+ <option value="14">14</option>
+ <option value="15">15</option>
+ <option value="16">16</option>
+ <option value="17">17</option>
+ <option value="18">18</option>
+ <option value="19">19</option>
+ </select>
+ <br />
+ <br />
+ <br />
+ <label for="files">Select a file:</label>
+ <select name="files" id="files">
+ <optgroup label="Scripts">
+ <option value="jquery">jQuery.js</option>
+ <option value="jqueryui">ui.jQuery.js</option>
+ </optgroup>
+ <optgroup label="Other files">
+ <option value="somefile">Some unknown file</option>
+ <option value="someotherfile">Some other file</option>
+ </optgroup>
+ </select>
+ </fieldset>
+</form>
+
+</div><!-- End demo -->
+
+
+
+<div class="demo-description">
+<p>The Selectmenu widgets provides a styleable select element replacement. It will act as a proxy back to the original select element, controlling its state for form submission or serialization </p>
+<p>The datasource is a native select element. Supports optgroups.</p>
+</div><!-- End demo-description -->
+
+</body>
+</html>
diff --git a/demos/selectmenu/images/24-podcast-square.png b/demos/selectmenu/images/24-podcast-square.png
new file mode 100644
index 000000000..3c3e38f3f
--- /dev/null
+++ b/demos/selectmenu/images/24-podcast-square.png
Binary files differ
diff --git a/demos/selectmenu/images/24-rss-square.png b/demos/selectmenu/images/24-rss-square.png
new file mode 100644
index 000000000..f59b69ed3
--- /dev/null
+++ b/demos/selectmenu/images/24-rss-square.png
Binary files differ
diff --git a/demos/selectmenu/images/24-video-square.png b/demos/selectmenu/images/24-video-square.png
new file mode 100644
index 000000000..ce50ccfde
--- /dev/null
+++ b/demos/selectmenu/images/24-video-square.png
Binary files differ
diff --git a/demos/selectmenu/index.html b/demos/selectmenu/index.html
new file mode 100644
index 000000000..45aa0c8e1
--- /dev/null
+++ b/demos/selectmenu/index.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>jQuery UI Selectmenu Demos</title>
+ <link rel="stylesheet" href="../demos.css">
+</head>
+<body>
+ <div class="demos-nav">
+ <h4>Examples</h4>
+ <ul>
+ <li class="demo-config-on"><a href="default.html">Default functionality</a></li>
+ <li class="demo-config-on"><a href="custom_render.html">Custom item rendering functionality</a></li>
+ </ul>
+ </div>
+</body>
+</html>
diff --git a/tests/unit/selectmenu/all.html b/tests/unit/selectmenu/all.html
new file mode 100644
index 000000000..9bb6835d0
--- /dev/null
+++ b/tests/unit/selectmenu/all.html
@@ -0,0 +1,30 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>jQuery UI Selectmenu Test Suite</title>
+
+ <script src="../../../jquery-1.6.2.js"></script>
+
+ <link rel="stylesheet" href="../../../external/qunit.css">
+ <link rel="stylesheet" href="../subsuiteRunner.css">
+ <script src="../../../external/qunit.js"></script>
+ <script src="../subsuiteRunner.js"></script>
+ <script src="../subsuite.js"></script>
+
+ <script>
+ testAllVersions( "selectmenu" );
+ </script>
+</head>
+<body>
+
+<h1 id="qunit-header">jQuery UI Selectmenu Test Suite</h1>
+<h2 id="qunit-banner"></h2>
+<div id="qunit-testrunner-toolbar"></div>
+<h2 id="qunit-userAgent"></h2>
+<ol id="qunit-tests"></ol>
+<div id="qunit-fixture">
+
+</div>
+</body>
+</html>
diff --git a/tests/unit/selectmenu/selectmenu.html b/tests/unit/selectmenu/selectmenu.html
new file mode 100644
index 000000000..c64b364fa
--- /dev/null
+++ b/tests/unit/selectmenu/selectmenu.html
@@ -0,0 +1,87 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>jQuery UI Selectmenu Test Suite</title>
+
+ <link rel="stylesheet" href="../../../themes/base/jquery.ui.core.css">
+ <link rel="stylesheet" href="../../../themes/base/jquery.ui.button.css">
+ <link rel="stylesheet" href="../../../themes/base/jquery.ui.menu.css">
+ <link rel="stylesheet" href="../../../themes/base/jquery.ui.selectmenu.css">
+
+ <script src="../../jquery.js"></script>
+ <script src="../../../ui/jquery.ui.core.js"></script>
+ <script src="../../../ui/jquery.ui.widget.js"></script>
+ <script src="../../../ui/jquery.ui.button.js"></script>
+ <script src="../../../ui/jquery.ui.menu.js"></script>
+ <script src="../../../ui/jquery.ui.selectmenu.js"></script>
+
+ <link rel="stylesheet" href="../../../external/qunit.css">
+ <script src="../../../external/qunit.js"></script>
+ <script src="../../jquery.simulate.js"></script>
+ <script src="../testsuite.js"></script>
+
+ <script src="selectmenu_core.js"></script>
+ <script src="selectmenu_defaults.js"></script>
+ <script src="selectmenu_events.js"></script>
+ <script src="selectmenu_methods.js"></script>
+ <script src="selectmenu_options.js"></script>
+
+ <script src="../swarminject.js"></script>
+</head>
+<body>
+
+<h1 id="qunit-header">jQuery UI Selectmenu Test Suite</h1>
+<h2 id="qunit-banner"></h2>
+<div id="qunit-testrunner-toolbar"></div>
+<h2 id="qunit-userAgent"></h2>
+<ol id="qunit-tests"></ol>
+<div id="qunit-fixture">
+
+ <label for="speed">Select a speed:</label>
+ <select name="speed" id="speed">
+ <option value="Slower">Slower</option>
+ <option value="Slow">Slow</option>
+ <option value="Medium" selected="selected">Medium</option>
+ <option value="Fast">Fast</option>
+ <option value="Faster">Faster</option>
+ </select>
+
+ <label for="number">Select a number:</label>
+ <select name="number" id="number">
+ <option value="1">1</option>
+ <option value="2" selected="selected">2</option>
+ <option value="3">3</option>
+ <option value="4">4</option>
+ <option value="5">5</option>
+ <option value="6">6</option>
+ <option value="7">7</option>
+ <option value="8">8</option>
+ <option value="9">9</option>
+ <option value="10">10</option>
+ <option value="11">11</option>
+ <option value="12">12</option>
+ <option value="13">13</option>
+ <option value="14">14</option>
+ <option value="15">15</option>
+ <option value="16">16</option>
+ <option value="17">17</option>
+ <option value="18">18</option>
+ <option value="19">19</option>
+ </select>
+
+ <label for="files">Select a file:</label>
+ <select name="files" id="files">
+ <optgroup label="Scripts">
+ <option value="jquery">jQuery.js</option>
+ <option value="jqueryui">ui.jQuery.js</option>
+ </optgroup>
+ <optgroup label="Other files">
+ <option value="somefile">Some unknown file</option>
+ <option value="someotherfile">Some other file</option>
+ </optgroup>
+ </select>
+
+</div>
+</body>
+</html>
diff --git a/tests/unit/selectmenu/selectmenu_core.js b/tests/unit/selectmenu/selectmenu_core.js
new file mode 100644
index 000000000..e19fefeea
--- /dev/null
+++ b/tests/unit/selectmenu/selectmenu_core.js
@@ -0,0 +1,59 @@
+(function( $ ) {
+
+module( "selectmenu: core" );
+
+test("accessibility", function () {
+ var element = $('#speed').selectmenu();
+ var widget = element.selectmenu("widget");
+ var button = widget.filter(".ui-selectmenu-button");
+ var menu = widget.filter(".ui-selectmenu-menu");
+ var link = button.children("a");
+ var ul = menu.children("ul")
+ var links = ul.find("li.ui-menu-item a");
+ expect(6 + links.length);
+
+ equals( button.attr("aria-disabled"), "false", "button aria-disabled" );
+ equals( link.attr("aria-disabled"), "false", "button link aria-disabled" );
+ equals( link.attr("aria-haspopup"), "true", "button link aria-haspopup" );
+ equals( link.attr("role"), "button", "button link role" );
+ equals( link.attr("aria-owns"), ul.attr("id"), "button link aria-owns" );
+ equals( link.attr("tabindex"), 0, "button link tabindex" );
+
+ $.each( links, function(index){
+ equals( $(this).attr("role"), "option", "menu link #" + index +" role" );
+ });
+});
+
+
+$.each([
+ {
+ type: "default",
+ selector: "#speed"
+ },
+ {
+ type: "optgroups",
+ selector: "#files"
+ }
+], function( i, settings ) {
+ test("state synchronization - " + settings.type, function () {
+ expect(6);
+ var element = $(settings.selector).selectmenu();
+ var widget = element.selectmenu("widget");
+ var button = widget.filter(".ui-selectmenu-button");
+ var menu = widget.filter(".ui-selectmenu-menu");
+
+ equals( element[0].value, element.selectmenu("option", "value"), "inital value" );
+ equals( element.find("option:selected").text(), button.text(), "inital button text" );
+
+ button.find("a").simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+ equals( element[0].value, element.selectmenu("option", "value"), "after keydown value" );
+ equals( element.find("option:selected").text(), button.text(), "after keydown button text" );
+
+ button.find("a").simulate( "click" );
+ menu.find("a").last().simulate( "click" );
+ equals( element[0].value, element.selectmenu("option", "value"), "after click value" );
+ equals( element.find("option:selected").text(), button.text(), "after click button text" );
+ });
+});
+
+})( jQuery );
diff --git a/tests/unit/selectmenu/selectmenu_defaults.js b/tests/unit/selectmenu/selectmenu_defaults.js
new file mode 100644
index 000000000..a0f4f985e
--- /dev/null
+++ b/tests/unit/selectmenu/selectmenu_defaults.js
@@ -0,0 +1,20 @@
+commonWidgetTests( "selectmenu", {
+ defaults: {
+ appendTo: "body",
+ disabled: false,
+ dropdown: true,
+ position: {
+ my: "left top",
+ at: "left bottom",
+ collision: "none"
+ },
+ value: null,
+ // callbacks,
+ create: null,
+ open: null,
+ focus: null,
+ select: null,
+ close: null,
+ change: null
+ }
+});
diff --git a/tests/unit/selectmenu/selectmenu_events.js b/tests/unit/selectmenu/selectmenu_events.js
new file mode 100644
index 000000000..888ab9e9b
--- /dev/null
+++ b/tests/unit/selectmenu/selectmenu_events.js
@@ -0,0 +1,7 @@
+(function( $ ) {
+
+module( "selectmenu: events" );
+
+
+
+})( jQuery );
diff --git a/tests/unit/selectmenu/selectmenu_methods.js b/tests/unit/selectmenu/selectmenu_methods.js
new file mode 100644
index 000000000..17d5488d6
--- /dev/null
+++ b/tests/unit/selectmenu/selectmenu_methods.js
@@ -0,0 +1,73 @@
+(function( $ ) {
+
+module( "selectmenu: methods" );
+
+test( "destroy", function() {
+ expect( 1 );
+ domEqual( "#speed", function() {
+ $( "#speed" ).selectmenu().selectmenu( "destroy" );
+ });
+});
+
+
+test( "open", function() {
+ expect( 2 );
+
+ var element = $("#speed").selectmenu();
+ var widget = element.selectmenu("widget");
+ var button = widget.filter(".ui-selectmenu-button");
+ var menu = widget.filter(".ui-selectmenu-menu");
+
+ element.selectmenu("open");
+ ok( menu.is( ":visible" ), "menu visible" );
+ equals( menu.find("ul").attr("aria-hidden"), "false", "menu aria-disabled" );
+});
+
+
+test( "close", function() {
+ expect( 2 );
+
+ var element = $("#speed").selectmenu();
+ var widget = element.selectmenu("widget");
+ var button = widget.filter(".ui-selectmenu-button");
+ var menu = widget.filter(".ui-selectmenu-menu");
+
+ element.selectmenu("open");
+ element.selectmenu("close");
+ ok( menu.is( ":hidden" ), "menu hidden" );
+ equals( menu.find("ul").attr("aria-hidden"), "true", "menu aria-disabled" );
+});
+
+
+$.each([
+ {
+ type: "default",
+ selector: "#speed",
+ options: null
+ },
+ {
+ type: "pop-up",
+ selector: "#number",
+ options: {
+ dropdown: false
+ }
+ },
+ {
+ type: "optgroups",
+ selector: "#files",
+ options: null
+ }
+], function( i, settings ) {
+ test("refresh - " + settings.type, function () {
+ // expect(6);
+ var element = $(settings.selector).selectmenu(settings.options);
+ var widget = element.selectmenu("widget");
+ var button = widget.filter(".ui-selectmenu-button");
+ var menu = widget.filter(".ui-selectmenu-menu");
+
+ element.selectmenu("refresh");
+ });
+});
+
+
+})( jQuery );
diff --git a/tests/unit/selectmenu/selectmenu_options.js b/tests/unit/selectmenu/selectmenu_options.js
new file mode 100644
index 000000000..b19dac4d4
--- /dev/null
+++ b/tests/unit/selectmenu/selectmenu_options.js
@@ -0,0 +1,7 @@
+(function( $ ) {
+
+module( "selectmenu: options" );
+
+
+
+})( jQuery );
diff --git a/tests/visual/selectmenu/autocomplete.html b/tests/visual/selectmenu/autocomplete.html
new file mode 100644
index 000000000..ad7b80640
--- /dev/null
+++ b/tests/visual/selectmenu/autocomplete.html
@@ -0,0 +1,94 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>jQuery UI Selectmenu - Event functionality</title>
+ <link rel="stylesheet" href="../../../themes/base/jquery.ui.all.css">
+ <script src="../../../jquery-1.7.js"></script>
+ <script src="../../../ui/jquery.ui.core.js"></script>
+ <script src="../../../ui/jquery.ui.widget.js"></script>
+ <script src="../../../ui/jquery.ui.position.js"></script>
+ <script src="../../../ui/jquery.ui.autocomplete.js"></script>
+ <script src="../../../ui/jquery.ui.button.js"></script>
+ <script src="../../../ui/jquery.ui.menu.js"></script>
+ <script src="../../../ui/jquery.ui.selectmenu.js"></script>
+ <link rel="stylesheet" href="../../../demos/demos.css">
+ <script>
+ $(function() {
+ $('select#speed').selectmenu();
+
+ var availableTags = [
+ "ActionScript",
+ "AppleScript",
+ "Asp",
+ "BASIC",
+ "C",
+ "C++",
+ "Clojure",
+ "COBOL",
+ "ColdFusion",
+ "Erlang",
+ "Fortran",
+ "Groovy",
+ "Haskell",
+ "Java",
+ "JavaScript",
+ "Lisp",
+ "Perl",
+ "PHP",
+ "Python",
+ "Ruby",
+ "Scala",
+ "Scheme"
+ ];
+ $( "#tags" ).autocomplete({
+ source: availableTags
+ });
+ });
+ </script>
+ <style>
+ form { margin: 20px 0 0 0 }
+ fieldset { border: 0; }
+ label { display: block; }
+ select { width: 200px; }
+ </style>
+</head>
+<body>
+
+<div class="demo">
+
+
+<form action="#">
+ <fieldset>
+ <label for="speed">Select a speed:</label>
+ <select name="speed" id="speed">
+ <option value="Slower">Slower</option>
+ <option value="Slow">Slow</option>
+ <option value="Medium" selected="selected">Medium</option>
+ <option value="Fast">Fast</option>
+ <option value="Faster">Faster</option>
+ </select>
+ </fieldset>
+</form>
+
+<br />
+<br />
+<br />
+<br />
+<br />
+<br />
+<br />
+<br />
+<br />
+
+<div class="ui-widget">
+ <label for="tags">Tags: </label>
+ <input id="tags">
+</div>
+
+</div><!-- End demo -->
+
+
+
+</body>
+</html>
diff --git a/tests/visual/selectmenu/dialog.html b/tests/visual/selectmenu/dialog.html
new file mode 100644
index 000000000..e8aac5f67
--- /dev/null
+++ b/tests/visual/selectmenu/dialog.html
@@ -0,0 +1,72 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>jQuery UI Selectmenu - Event functionality</title>
+ <link rel="stylesheet" href="../../../themes/base/jquery.ui.all.css">
+ <script src="../../../jquery-1.7.js"></script>
+ <script src="../../../ui/jquery.ui.core.js"></script>
+ <script src="../../../ui/jquery.ui.widget.js"></script>
+ <script src="../../../ui/jquery.ui.position.js"></script>
+ <script src="../../../ui/jquery.ui.dialog.js"></script>
+ <script src="../../../ui/jquery.ui.button.js"></script>
+ <script src="../../../ui/jquery.ui.menu.js"></script>
+ <script src="../../../ui/jquery.ui.selectmenu.js"></script>
+ <link rel="stylesheet" href="../../../demos/demos.css">
+ <script>
+ $(function() {
+ $('select#speed').selectmenu();
+
+ $( "#dialog" ).dialog();
+ });
+ </script>
+ <style>
+ form { margin: 20px 0 0 0 }
+ fieldset { border: 0; }
+ label { display: block; }
+ select { width: 200px; }
+ </style>
+</head>
+<body>
+
+<div class="demo">
+
+
+<div id="dialog" title="Basic dialog">
+ <p>Some example content</p>
+ <p><a href="#nogo">Test Link</a></p>
+ <form action="#">
+ <fieldset>
+ <label for="speed">Select a speed:</label>
+ <select name="speed" id="speed">
+ <option value="Slower">Slower</option>
+ <option value="Slow">Slow</option>
+ <option value="Medium" selected="selected">Medium</option>
+ <option value="Fast">Fast</option>
+ <option value="Faster">Faster</option>
+ </select>
+ </fieldset>
+ </form>
+</div>
+
+<!-- Sample page content to illustrate the layering of the dialog -->
+<div class="hiddenInViewSource" style="padding:20px;">
+<p>Sed vel diam id libero <a href="http://example.com">rutrum convallis</a>. Donec aliquet leo vel magna. Phasellus rhoncus faucibus ante. Etiam bibendum, enim faucibus aliquet rhoncus, arcu felis ultricies neque, sit amet auctor elit eros a lectus.</p>
+<form>
+ <input value="text input" /><br />
+ <input type="checkbox" />checkbox<br />
+ <input type="radio" />radio<br />
+ <select>
+ <option>select</option>
+ </select><br /><br />
+ <textarea>textarea</textarea><br />
+</form>
+</div><!-- End sample page content -->
+
+
+</div><!-- End demo -->
+
+
+
+</body>
+</html>
diff --git a/tests/visual/selectmenu/disabled.html b/tests/visual/selectmenu/disabled.html
new file mode 100644
index 000000000..508cb7bf9
--- /dev/null
+++ b/tests/visual/selectmenu/disabled.html
@@ -0,0 +1,137 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>jQuery UI Selectmenu - Disable functionality</title>
+ <link rel="stylesheet" href="../../../themes/base/jquery.ui.all.css">
+ <script src="../../../jquery-1.7.js"></script>
+ <script src="../../../ui/jquery.ui.core.js"></script>
+ <script src="../../../ui/jquery.ui.widget.js"></script>
+ <script src="../../../ui/jquery.ui.position.js"></script>
+ <script src="../../../ui/jquery.ui.button.js"></script>
+ <script src="../../../ui/jquery.ui.menu.js"></script>
+ <script src="../../../ui/jquery.ui.selectmenu.js"></script>
+ <link rel="stylesheet" href="../../../demos/demos.css">
+ <script>
+ $(function() {
+ $('select#speed').selectmenu({
+ dropdown: false
+ });
+ var withOverflow = $('select#number').selectmenu({
+ dropdown: false
+ });
+ withOverflow.selectmenu("widget").addClass("overflow");
+ $('select#files').selectmenu();
+ var files2 = $('select#files2').selectmenu();
+
+ $("#disable_select").toggle( function() {
+ files2.selectmenu("disable");
+ }, function() {
+ files2.removeAttr("disabled");
+ files2.selectmenu("refresh");
+ });
+ $("#disable_option").toggle( function() {
+ files2.find("option:eq(0)").attr("disabled", "disabled");
+ files2.selectmenu("refresh");
+ }, function() {
+ files2.find("option:eq(0)").removeAttr("disabled");
+ files2.selectmenu("refresh");
+ });
+ $("#disable_optgroup").toggle( function() {
+ files2.find("optgroup:eq(0)").attr("disabled", "disabled");
+ files2.selectmenu("refresh");
+ }, function() {
+ files2.find("optgroup:eq(0)").removeAttr("disabled");
+ files2.selectmenu("refresh");
+
+ });
+ });
+ </script>
+ <style>
+ form { margin: 100px 0 0 0 }
+ fieldset { border: 0; }
+ label { display: block; }
+ select { width: 200px; }
+ .overflow ul { height: 200px; overflow: auto; }
+ </style>
+</head>
+<body>
+
+<div class="demo">
+
+<form action="#">
+ <fieldset>
+ <label for="speed">Select a speed:</label>
+ <select disabled="disabled" name="speed" id="speed">
+ <option value="Slower">Slower</option>
+ <option value="Slow">Slow</option>
+ <option value="Medium" selected="selected">Medium</option>
+ <option value="Fast">Fast</option>
+ <option value="Faster">Faster</option>
+ </select>
+ <br />
+ <br />
+ <br />
+ <label for="number">Select a number:</label>
+ <select name="number" id="number">
+ <option value="1">1</option>
+ <option value="2" selected="selected">2</option>
+ <option value="3">3</option>
+ <option disabled="disabled" value="4">4</option>
+ <option value="5">5</option>
+ <option value="6">6</option>
+ <option value="7">7</option>
+ <option disabled="disabled" value="8">8</option>
+ <option value="9">9</option>
+ <option value="10">10</option>
+ <option disabled="disabled" value="11">11</option>
+ <option value="12">12</option>
+ <option value="13">13</option>
+ <option disabled="disabled" value="14">14</option>
+ <option disabled="disabled" value="15">15</option>
+ <option value="16">16</option>
+ <option value="17">17</option>
+ <option value="18">18</option>
+ <option value="19">19</option>
+ </select>
+ <br />
+ <br />
+ <br />
+ <label for="files">Select a file:</label>
+ <select name="files" id="files">
+ <optgroup disabled="disabled" label="Scripts">
+ <option value="jquery">jQuery.js</option>
+ <option value="jqueryui">ui.jQuery.js</option>
+ </optgroup>
+ <optgroup label="Other files">
+ <option value="somefile">Some unknown file</option>
+ <option value="someotherfile">Some other file</option>
+ </optgroup>
+ </select>
+ <br />
+ <br />
+ <br />
+ <label for="files2">Select a file:</label>
+ <select name="files2" id="files2">
+ <optgroup label="Scripts">
+ <option value="jquery">jQuery.js</option>
+ <option value="jqueryui">ui.jQuery.js</option>
+ </optgroup>
+ <optgroup label="Other files">
+ <option value="somefile">Some unknown file</option>
+ <option value="someotherfile">Some other file</option>
+ </optgroup>
+ </select>
+ </fieldset>
+</form>
+<br />
+<button id="disable_select">Toggle disable select</button>
+<button id="disable_option">Toggle disable option</button>
+<button id="disable_optgroup">Toggle disable optgroup</button>
+
+</div><!-- End demo -->
+
+
+
+</body>
+</html>
diff --git a/tests/visual/selectmenu/events.html b/tests/visual/selectmenu/events.html
new file mode 100644
index 000000000..021dfcb48
--- /dev/null
+++ b/tests/visual/selectmenu/events.html
@@ -0,0 +1,74 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>jQuery UI Selectmenu - Event functionality</title>
+ <link rel="stylesheet" href="../../../themes/base/jquery.ui.all.css">
+ <script src="../../../jquery-1.7.js"></script>
+ <script src="../../../ui/jquery.ui.core.js"></script>
+ <script src="../../../ui/jquery.ui.widget.js"></script>
+ <script src="../../../ui/jquery.ui.position.js"></script>
+ <script src="../../../ui/jquery.ui.button.js"></script>
+ <script src="../../../ui/jquery.ui.menu.js"></script>
+ <script src="../../../ui/jquery.ui.selectmenu.js"></script>
+ <link rel="stylesheet" href="../../../demos/demos.css">
+ <script>
+ $(function() {
+ var log = $("#log");
+ var index = 0;
+ $('select').selectmenu({
+ open: function(event, ui) {
+ $("<div/>").text( index++ + " Opened").prependTo(log);
+ },
+ close: function(event, ui) {
+ $("<div/>").text( index++ + " Closed").prependTo(log);
+ },
+ focus : function(event, ui) {
+ $("<div/>").text( index++ + " Focused: " + ui.item.label + " #" + ui.item.index ).prependTo(log);
+ },
+ select: function(event, ui) {
+ $("<div/>").text( index++ + " Selected: " + ui.item.label + " #" + ui.item.index ).prependTo(log);
+ },
+ change: function(event, ui) {
+ $("<div/>").text( index++ + " Changed to: " + ui.item.label + " #" + ui.item.index ).prependTo(log);
+ }
+ });
+ });
+ </script>
+ <style>
+ form { margin: 20px 0 0 0 }
+ fieldset { border: 0; }
+ label { display: block; }
+ select { width: 200px; }
+ .overflow ul { height: 200px; overflow: auto; }
+ </style>
+</head>
+<body>
+
+<div class="demo">
+
+
+<div class="ui-widget" style="float: left; margin-top:2em; font-family:Arial">
+ Log:
+ <div id="log" style="height: 400px; width: 270px; overflow: auto;" class="ui-widget-content"></div>
+</div>
+
+<form action="#">
+ <fieldset>
+ <label for="speed">Select a speed:</label>
+ <select name="speed" id="speed">
+ <option value="Slower">Slower</option>
+ <option value="Slow">Slow</option>
+ <option value="Medium" selected="selected">Medium</option>
+ <option value="Fast">Fast</option>
+ <option value="Faster">Faster</option>
+ </select>
+ </fieldset>
+</form>
+
+</div><!-- End demo -->
+
+
+
+</body>
+</html>
diff --git a/tests/visual/selectmenu/methods.html b/tests/visual/selectmenu/methods.html
new file mode 100644
index 000000000..1cb527444
--- /dev/null
+++ b/tests/visual/selectmenu/methods.html
@@ -0,0 +1,74 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>jQuery UI Selectmenu - Event functionality</title>
+ <link rel="stylesheet" href="../../../themes/base/jquery.ui.all.css">
+ <script src="../../../jquery-1.7.js"></script>
+ <script src="../../../ui/jquery.ui.core.js"></script>
+ <script src="../../../ui/jquery.ui.widget.js"></script>
+ <script src="../../../ui/jquery.ui.position.js"></script>
+ <script src="../../../ui/jquery.ui.button.js"></script>
+ <script src="../../../ui/jquery.ui.menu.js"></script>
+ <script src="../../../ui/jquery.ui.selectmenu.js"></script>
+ <link rel="stylesheet" href="../../../demos/demos.css">
+ <script>
+ $(function() {
+ var mySelectmenu = $('select').selectmenu();
+
+ $("#destroy").click( function() {
+ mySelectmenu.selectmenu("destroy");
+ });
+
+ $("#refresh").click( function() {
+ mySelectmenu.append('<option value="fastsound">Faster than sound</option>');
+ mySelectmenu.selectmenu("refresh");
+ });
+
+ $("#open").click( function() {
+ mySelectmenu.selectmenu("open");
+ return false;
+ });
+
+ $("#close").click( function() {
+ mySelectmenu.selectmenu("close");
+ return false;
+ });
+ });
+ </script>
+ <style>
+ form { margin: 20px 0 0 0 }
+ fieldset { border: 0; }
+ label { display: block; }
+ select { width: 200px; }
+ .overflow ul { height: 200px; overflow: auto; }
+ </style>
+</head>
+<body>
+
+<div class="demo">
+
+<form action="#">
+ <fieldset>
+ <label for="speed">Select a speed:</label>
+ <select name="speed" id="speed">
+ <option value="Slower">Slower</option>
+ <option value="Slow">Slow</option>
+ <option value="Medium" selected="selected">Medium</option>
+ <option value="Fast">Fast</option>
+ <option value="Faster">Faster</option>
+ </select>
+ </fieldset>
+</form>
+<br />
+<button id="destroy">Destroy</button>
+<button id="refresh">Add item and refresh</button>
+<button id="open">Open</button>
+<button id="close">Close</button>
+
+</div><!-- End demo -->
+
+
+
+</body>
+</html>
diff --git a/tests/visual/selectmenu/option.html b/tests/visual/selectmenu/option.html
new file mode 100644
index 000000000..33dd381c3
--- /dev/null
+++ b/tests/visual/selectmenu/option.html
@@ -0,0 +1,63 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>jQuery UI Selectmenu - Event functionality</title>
+ <link rel="stylesheet" href="../../../themes/base/jquery.ui.all.css">
+ <script src="../../../jquery-1.7.js"></script>
+ <script src="../../../ui/jquery.ui.core.js"></script>
+ <script src="../../../ui/jquery.ui.widget.js"></script>
+ <script src="../../../ui/jquery.ui.position.js"></script>
+ <script src="../../../ui/jquery.ui.button.js"></script>
+ <script src="../../../ui/jquery.ui.menu.js"></script>
+ <script src="../../../ui/jquery.ui.selectmenu.js"></script>
+ <link rel="stylesheet" href="../../../demos/demos.css">
+ <script>
+ $(function() {
+ var mySelectmenu = $('select').selectmenu();
+
+ $("#value").click( function() {
+ mySelectmenu.selectmenu("option", "value", "Faster");
+ });
+
+ $("#dropdown").toggle( function() {
+ mySelectmenu.selectmenu("option", "dropdown", false);
+ }, function() {
+ mySelectmenu.selectmenu("option", "dropdown", true);
+ });
+ });
+ </script>
+ <style>
+ form { margin: 20px 0 0 0 }
+ fieldset { border: 0; }
+ label { display: block; }
+ select { width: 200px; }
+ .overflow ul { height: 200px; overflow: auto; }
+ </style>
+</head>
+<body>
+
+<div class="demo">
+
+<form action="#">
+ <fieldset>
+ <label for="speed">Select a speed:</label>
+ <select name="speed" id="speed">
+ <option value="Slower">Slower</option>
+ <option value="Slow">Slow</option>
+ <option value="Medium" selected="selected">Medium</option>
+ <option value="Fast">Fast</option>
+ <option value="Faster">Faster</option>
+ </select>
+ </fieldset>
+</form>
+<br />
+<!-- <button id="dropdown">Toggle dropdown style</button> -->
+<button id="value">Set option value = 'Faster'</button>
+
+</div><!-- End demo -->
+
+
+
+</body>
+</html>
diff --git a/tests/visual/selectmenu/tabs.html b/tests/visual/selectmenu/tabs.html
new file mode 100644
index 000000000..da1221c7a
--- /dev/null
+++ b/tests/visual/selectmenu/tabs.html
@@ -0,0 +1,68 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>jQuery UI Selectmenu - Event functionality</title>
+ <link rel="stylesheet" href="../../../themes/base/jquery.ui.all.css">
+ <script src="../../../jquery-1.7.js"></script>
+ <script src="../../../ui/jquery.ui.core.js"></script>
+ <script src="../../../ui/jquery.ui.widget.js"></script>
+ <script src="../../../ui/jquery.ui.position.js"></script>
+ <script src="../../../ui/jquery.ui.tabs.js"></script>
+ <script src="../../../ui/jquery.ui.button.js"></script>
+ <script src="../../../ui/jquery.ui.menu.js"></script>
+ <script src="../../../ui/jquery.ui.selectmenu.js"></script>
+ <link rel="stylesheet" href="../../../demos/demos.css">
+ <script>
+ $(function() {
+ $( "#tabs" ).tabs();
+ $('select').selectmenu();
+ });
+ </script>
+ <style>
+ form { margin: 20px 0 0 0 }
+ fieldset { border: 0; }
+ label { display: block; }
+ select { width: 200px; }
+ </style>
+</head>
+<body>
+
+<div class="demo">
+
+
+<div id="tabs">
+ <ul>
+ <li><a href="#tabs-1">Nunc tincidunt</a></li>
+ <li><a href="#tabs-2">Proin dolor</a></li>
+ <li><a href="#tabs-3">Aenean lacinia</a></li>
+ </ul>
+ <div id="tabs-1">
+ <p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.</p>
+ </div>
+ <div id="tabs-2">
+ <form action="#">
+ <fieldset>
+ <label for="speed">Select a speed:</label>
+ <select name="speed" id="speed">
+ <option value="Slower">Slower</option>
+ <option value="Slow">Slow</option>
+ <option value="Medium" selected="selected">Medium</option>
+ <option value="Fast">Fast</option>
+ <option value="Faster">Faster</option>
+ </select>
+ </fieldset>
+ </form>
+ </div>
+ <div id="tabs-3">
+ <p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.</p>
+ <p>Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit, magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.</p>
+ </div>
+</div>
+
+</div><!-- End demo -->
+
+
+
+</body>
+</html>
diff --git a/themes/base/jquery.ui.base.css b/themes/base/jquery.ui.base.css
index a359c2ba4..6973ff0f0 100644
--- a/themes/base/jquery.ui.base.css
+++ b/themes/base/jquery.ui.base.css
@@ -19,6 +19,7 @@
@import url("jquery.ui.progressbar.css");
@import url("jquery.ui.resizable.css");
@import url("jquery.ui.selectable.css");
+@import url("jquery.ui.selectmenu.css");
@import url("jquery.ui.slider.css");
@import url("jquery.ui.spinner.css");
@import url("jquery.ui.tabs.css");
diff --git a/themes/base/jquery.ui.selectmenu.css b/themes/base/jquery.ui.selectmenu.css
new file mode 100644
index 000000000..2b3c148a0
--- /dev/null
+++ b/themes/base/jquery.ui.selectmenu.css
@@ -0,0 +1,20 @@
+/*
+ * jQuery UI Selectmenu @VERSION
+ *
+ * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ * http://jquery.org/license
+ *
+ * http://docs.jquery.com/UI/Selectmenu#theming
+ */
+
+.ui-selectmenu-menu { padding: 0; margin: 0; position:absolute; top: 0; display: none; }
+.ui-selectmenu-menu .ui-menu .ui-menu-item a { padding: 0.3em 1em 0.3em 1em; }
+.ui-selectmenu-menu .ui-menu li.ui-state-disabled { padding: 0.3em 1em 0.3em 1em; }
+.ui-selectmenu-menu .ui-menu li.ui-selectmenu-optgroup { font-weight: bold; line-height: 1.5; padding: 2px 0.4em; margin: 0.5em 0 0 0; }
+.ui-selectmenu-open { display: block; }
+
+.ui-selectmenu-button span.ui-icon { right: 0.5em; left: auto; }
+.ui-selectmenu-button span.ui-button-text { text-align: left; padding: 0.4em 2.1em 0.4em 1em }
+
+.ui-selectmenu-menu .ui-menu .ui-menu-item { width: auto; } /* IE7 fix */ \ No newline at end of file
diff --git a/ui/jquery.ui.selectmenu.js b/ui/jquery.ui.selectmenu.js
new file mode 100644
index 000000000..b8aec3750
--- /dev/null
+++ b/ui/jquery.ui.selectmenu.js
@@ -0,0 +1,413 @@
+/*
+ * jQuery UI Selectmenu @VERSION
+ *
+ * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ * http://jquery.org/license
+ *
+ * http://docs.jquery.com/UI/Selectmenu
+ *
+ * Depends:
+ * jquery.ui.core.js
+ * jquery.ui.widget.js
+ * jquery.ui.position.js
+ * jquery.ui.menu.js
+ * jquery.ui.button.js
+ */
+(function( $, undefined ) {
+
+$.widget( "ui.selectmenu", {
+ version: "@VERSION",
+ defaultElement: "<select>",
+ options: {
+ dropdown: true,
+ appendTo: "body",
+ position: {
+ my: "left top",
+ at: "left bottom",
+ collision: "none"
+ },
+ value: null,
+ // callbacks
+ open: null,
+ focus: null,
+ select: null,
+ close: null,
+ change: null
+ },
+
+ _create: function() {
+ // set a default id value, generate a new random one if not set by developer
+ var selectmenuId = this.element.attr( 'id' ) || 'ui-selectmenu-' + Math.random().toString( 16 ).slice( 2, 10 );
+
+ // array of button and menu id's
+ this.ids = { id: selectmenuId, button: selectmenuId + '-button', menu: selectmenuId + '-menu' };
+
+ // set current value
+ if ( this.options.value ) {
+ this.element[0].value = this.options.value;
+ } else {
+ this.options.value = this.element[0].value;
+ }
+
+ // catch click event of the label
+ this._bind({
+ 'click': function( event ) {
+ this.button.focus();
+ event.preventDefault();
+ }
+ });
+
+ this._drawButton();
+ this._bind( this.button, this._buttonEvents );
+
+ this._drawMenu();
+ this.refresh();
+ },
+
+ _drawButton: function() {
+ var tabindex = this.element.attr( 'tabindex' );
+
+ // hide original select tag
+ this.element.hide();
+
+ // create button
+ this.button = $( '<a />', {
+ href: '#' + this.ids.id,
+ tabindex: ( tabindex ? tabindex : this.element.attr( 'disabled' ) ? -1 : 0 ),
+ id: this.ids.button,
+ css: {
+ width: this.element.outerWidth()
+ },
+ 'aria-disabled': this.options.disabled,
+ 'aria-owns': this.ids.menu,
+ 'aria-haspopup': true
+ })
+ .button({
+ label: this.element.find( "option:selected" ).text(),
+ icons: {
+ primary: ( this.options.dropdown ? 'ui-icon-triangle-1-s' : 'ui-icon-triangle-2-n-s' )
+ }
+ });
+
+ // wrap and insert new button
+ this.buttonWrap = $( '<span />' )
+ .addClass( 'ui-selectmenu-button' )
+ .append( this.button )
+ .insertAfter( this.element );
+ },
+
+ _drawMenu: function() {
+ var that = this;
+
+ // create menu portion, append to body
+ this.menu = $( '<ul />', {
+ 'class': 'ui-widget ui-widget-content',
+ 'aria-hidden': true,
+ 'aria-labelledby': this.ids.button,
+ role: 'menubox',
+ id: this.ids.menu
+ });
+
+ // set width
+ if ( this.options.dropdown ) {
+ var setWidth = this.button.outerWidth();
+ } else {
+ var text = this.button.find( "span.ui-button-text");
+ var setWidth = text.width() + parseFloat( text.css( "padding-left" ) ) || 0 + parseFloat( text.css( "margin-left" ) || 0 );
+ }
+
+ // wrap menu
+ this.menuWrap = $( '<div />' )
+ .addClass( 'ui-selectmenu-menu' )
+ .width( setWidth )
+ .append( this.menu )
+ .appendTo( this.options.appendTo );
+
+ // init menu widget
+ this.menu.menu({
+ select: function( event, ui ) {
+ var flag = false,
+ item = ui.item.data( "item.selectmenu" ),
+ oldIndex = that.element[0].selectedIndex;
+
+ that._setOption( "value", item.value );
+ that._trigger( "select", event, { item: item } );
+
+ if ( item.index != oldIndex ) {
+ that._trigger( "change", event, { item: item } );
+ }
+
+ if ( that.isOpen ) {
+ event.preventDefault();
+ that.close( event, true);
+ }
+ },
+ focus: function( event, ui ) {
+ var item = ui.item.data( "item.selectmenu" );
+
+ if ( that.focus !== undefined && item.index != that.focus ) {
+ that._trigger( "focus", event, { item: item } );
+ }
+
+ that.focus = item.index;
+ }
+ });
+
+ // document click closes menu
+ this._bind( document, {
+ 'click': function( event ) {
+ if ( this.isOpen && !$( event.target ).closest( "#" + this.ids.button).length ) {
+ this.close( event );
+ }
+ }
+ });
+ },
+
+ refresh: function() {
+ this.menu.empty();
+
+ this._readOptions();
+ this._renderMenu( this.menu, this.items );
+
+ this.menu.menu( "refresh" );
+
+ // adjust ARIA
+ this.menu.find( "li" ).not( '.ui-selectmenu-optgroup' ).find( 'a' ).attr( 'role', 'option' );
+
+ if ( this.options.dropdown ) {
+ this.menu
+ .addClass( 'ui-corner-bottom' )
+ .removeClass( 'ui-corner-all' );
+ }
+
+ // transfer disabled state
+ if ( this.element.attr( 'disabled' ) ) {
+ this.disable();
+ } else {
+ this.enable()
+ }
+ },
+
+ open: function( event ) {
+ var currentItem = this._getSelectedItem();
+
+ if ( !this.options.disabled ) {
+ if ( this.options.dropdown ) {
+ this.button
+ .addClass( 'ui-corner-top' )
+ .removeClass( 'ui-corner-all' );
+ }
+
+ this.menuWrap.addClass( 'ui-selectmenu-open' );
+ this.menu.attr("aria-hidden", false);
+ // needs to be fired after the document click event has closed all other Selectmenus
+ // otherwise the current item is not indicated
+ // TODO check if this should be handled by Menu
+ this._delay( function(){
+ this.menu.menu( "focus", event, currentItem );
+ }, 1);
+
+ if ( !this.options.dropdown ) {
+ // center current item
+ if ( this.menu.css("overflow") == "auto" ) {
+ this.menu.scrollTop( this.menu.scrollTop() + currentItem.position().top - this.menu.outerHeight()/2 + currentItem.outerHeight()/2 );
+ }
+ // calculate offset
+ var _offset = ( this.menu.offset().top - currentItem.offset().top + ( this.button.outerHeight() - currentItem.outerHeight() ) / 2);
+ $.extend( this.options.position, {
+ my: "left top",
+ at: "left top",
+ offset: "0 " + _offset
+ });
+ }
+
+ this.menuWrap
+ .zIndex( this.element.zIndex() + 1 )
+ .position( $.extend({
+ of: this.button
+ }, this.options.position ));
+
+ this.isOpen = true;
+ this._trigger( "open", event );
+ }
+ },
+
+ close: function( event, focus ) {
+ if ( this.isOpen ) {
+ if ( this.options.dropdown ) {
+ this.button
+ .addClass( 'ui-corner-all' )
+ .removeClass( 'ui-corner-top' );
+ }
+
+ this.menuWrap.removeClass( 'ui-selectmenu-open' );
+ this.menu.attr("aria-hidden", true);
+ this.isOpen = false;
+
+ if ( focus ) {
+ this.button.focus();
+ }
+
+ this._trigger( "close", event );
+ }
+ },
+
+ widget: function() {
+ return this.buttonWrap.add( this.menuWrap );
+ },
+
+ _renderMenu: function( ul, items ) {
+ var that = this,
+ currentOptgroup = "";
+
+ $.each( items, function( index, item ) {
+ if ( item.optgroup != currentOptgroup ) {
+ var optgroup = $( '<li class="ui-selectmenu-optgroup">' + item.optgroup + '</li>' );
+ if ( item.element.parent( "optgroup" ).attr( "disabled" ) ) optgroup.addClass( 'ui-state-disabled' );
+ ul.append( optgroup );
+ currentOptgroup = item.optgroup;
+ }
+ that._renderItem( ul, item );
+ });
+ },
+
+ _renderItem: function( ul, item) {
+ var li = $( "<li />" ).data( "item.selectmenu", item );
+ if ( item.disabled ) {
+ li.addClass( 'ui-state-disabled' ).text( item.label );
+ } else {
+ li.append( $( "<a />", {
+ text: item.label,
+ href: '#'
+ })
+ );
+ }
+
+ return li.appendTo( ul );
+ },
+
+ _move: function( key, event ) {
+ if ( !this.isOpen ) {
+ this.menu.menu( "focus", event, this._getSelectedItem() );
+ }
+
+ this.menu.menu( key, event );
+
+ if ( !this.isOpen ) {
+ this.menu.menu( "select", event );
+ }
+ },
+
+ _getSelectedItem: function() {
+ return this.menu.find( "li" ).not( '.ui-selectmenu-optgroup' ).eq( this.element[0].selectedIndex );
+ },
+
+ _toggle: function( event ) {
+ if ( this.isOpen ) {
+ this.close( event );
+ } else {
+ this.open( event );
+ }
+ },
+
+ _buttonEvents: {
+ click: function( event ) {
+ this._toggle( event );
+ event.preventDefault();
+ },
+ keydown: function( event ) {
+ switch (event.keyCode) {
+ case $.ui.keyCode.TAB:
+ if ( this.isOpen ) {
+ this.close( event );
+ }
+ break;
+ case $.ui.keyCode.ENTER:
+ if ( this.isOpen ) {
+ this.menu.menu( "select", this._getSelectedItem() );
+ }
+ event.preventDefault();
+ break;
+ case $.ui.keyCode.SPACE:
+ event.preventDefault();
+ break;
+ case $.ui.keyCode.UP:
+ if ( event.altKey ) {
+ this._toggle( event );
+ } else {
+ this._move( "previous", event );
+ }
+ event.preventDefault();
+ break;
+ case $.ui.keyCode.DOWN:
+ if ( event.altKey ) {
+ this._toggle( event );
+ } else {
+ this._move( "next", event );
+ }
+ event.preventDefault();
+ break;
+ case $.ui.keyCode.LEFT:
+ this._move( "previous", event );
+ event.preventDefault();
+ break;
+ case $.ui.keyCode.RIGHT:
+ this._move( "next", event );
+ event.preventDefault();
+ break;
+ default:
+ this.menu.trigger( event );
+ }
+ }
+ },
+
+ _setOption: function( key, value ) {
+ this._super( key, value );
+
+ if ( key === "appendTo" ) {
+ this.menuWrap.appendTo( $( value || "body", this.element[0].ownerDocument )[0] );
+ }
+ if ( key === "value" && value !== undefined ) {
+ this.element[0].value = value;
+ this.button.children( '.ui-button-text' ).text( this.items[ this.element[0].selectedIndex ].label );
+ }
+ if ( key === "disabled" ) {
+ this.button.button( "option", "disabled", value );
+ if ( value ) {
+ this.element.attr( "disabled", "disabled" );
+ this.button.attr( "tabindex", -1 );
+ this.close();
+ } else {
+ this.element.removeAttr( "disabled" );
+ this.button.attr( "tabindex", 0 );
+ }
+ this.menu.attr( "aria-disabled", value );
+ }
+ },
+
+ _readOptions: function() {
+ var data = [];
+ $.each( this.element.find( 'option' ), function( index, item ) {
+ var option = $( item ),
+ optgroup = option.parent( "optgroup" );
+ data.push({
+ element: option,
+ index: index,
+ value: option.attr( 'value' ),
+ label: option.text(),
+ optgroup: optgroup.attr( "label" ) || false,
+ disabled: optgroup.attr( "disabled" ) || option.attr( "disabled" )
+ });
+ });
+ this.items = data;
+ },
+
+ _destroy: function() {
+ this.menuWrap.remove();
+ this.buttonWrap.remove();
+ this.element.show();
+ }
+});
+
+}( jQuery ));