|
4 | 4 | * Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
|
5 | 5 | * Note: Code is in draft form and is subject to change
|
6 | 6 | */
|
7 |
| -(function($){ |
8 |
| -$.fn.customSelect = function(options){ |
9 |
| - return $(this).each(function(){ |
10 |
| - var select = $(this) |
| 7 | +(function ( $ ) { |
| 8 | +$.widget( "mobile.selectmenu", $.mobile.widget, { |
| 9 | + options: { |
| 10 | + theme: undefined |
| 11 | + }, |
| 12 | + _create: function(){ |
| 13 | + var select = this.element |
11 | 14 | .attr( "tabindex", "-1" )
|
12 | 15 | .wrap( "<div class='ui-select'>" ),
|
13 | 16 | selectID = select.attr( "id" ),
|
14 | 17 | label = $( "label[for="+ selectID +"]" )
|
15 | 18 | .addClass( "ui-select" ),
|
16 |
| - |
17 |
| - //extendable options |
18 |
| - o = $.extend({ |
19 |
| - chooseText: label.text(), |
20 |
| - theme: select.data("theme") |
21 |
| - }, options), |
22 |
| - |
23 |
| - buttonId = selectID + "-button", |
24 |
| - menuId = selectID + "-menu", |
25 |
| - thisPage = select.closest( ".ui-page" ), |
26 |
| - menuType, |
27 |
| - currScroll, |
28 |
| - button = $( "<a>", { |
29 |
| - "href": "#", |
30 |
| - "role": "button", |
31 |
| - "id": buttonId, |
32 |
| - "aria-haspopup": "true", |
33 |
| - "aria-owns": menuId |
34 |
| - }) |
35 |
| - .text( $( this.options.item(this.selectedIndex) ).text() ) |
36 |
| - .insertBefore( select ) |
37 |
| - .buttonMarkup({ |
38 |
| - iconpos: 'right', |
39 |
| - icon: 'arrow-d', |
40 |
| - theme: o.theme |
41 |
| - }), |
42 |
| - menuPage = $( "<div data-role='dialog' data-theme='a'>" + |
43 |
| - "<div data-role='header' data-theme='b'>" + |
44 |
| - "<div class='ui-title'>" + o.chooseText + "</div>"+ |
45 |
| - "</div>"+ |
46 |
| - "<div data-role='content'></div>"+ |
47 |
| - "</div>" ) |
48 |
| - .appendTo( $.pageContainer ) |
49 |
| - .page(), |
50 |
| - menuPageContent = menuPage.find( ".ui-content" ), |
51 |
| - screen = $( "<div>", { |
52 |
| - "class": "ui-listbox-screen ui-overlay ui-screen-hidden fade" |
| 19 | + chooseText = label.text(), |
| 20 | + buttonId = selectID + "-button", |
| 21 | + menuId = selectID + "-menu", |
| 22 | + thisPage = select.closest( ".ui-page" ), |
| 23 | + menuType, |
| 24 | + currScroll, |
| 25 | + button = $( "<a>", { |
| 26 | + "href": "#", |
| 27 | + "role": "button", |
| 28 | + "id": buttonId, |
| 29 | + "aria-haspopup": "true", |
| 30 | + "aria-owns": menuId |
53 | 31 | })
|
54 |
| - .appendTo( thisPage ), |
55 |
| - listbox = $( "<div>", { "class": "ui-listbox ui-listbox-hidden ui-body-a ui-overlay-shadow ui-corner-all pop"} ) |
56 |
| - .insertAfter(screen), |
57 |
| - list = $( "<ul>", { |
58 |
| - "class": "ui-listbox-list", |
59 |
| - "id": menuId, |
60 |
| - "role": "listbox", |
61 |
| - "aria-labelledby": buttonId |
62 |
| - }) |
63 |
| - .appendTo( listbox ); |
| 32 | + .text( $( select[0].options.item(select[0].selectedIndex) ).text() ) |
| 33 | + .insertBefore( select ) |
| 34 | + .buttonMarkup({ |
| 35 | + iconpos: 'right', |
| 36 | + icon: 'arrow-d', |
| 37 | + theme: this.options.theme |
| 38 | + }), |
| 39 | + menuPage = $( "<div data-role='dialog' data-theme='a'>" + |
| 40 | + "<div data-role='header' data-theme='b'>" + |
| 41 | + "<div class='ui-title'>" + chooseText + "</div>"+ |
| 42 | + "</div>"+ |
| 43 | + "<div data-role='content'></div>"+ |
| 44 | + "</div>" ) |
| 45 | + .appendTo( $.pageContainer ) |
| 46 | + .page(), |
| 47 | + menuPageContent = menuPage.find( ".ui-content" ), |
| 48 | + screen = $( "<div>", { |
| 49 | + "class": "ui-listbox-screen ui-overlay ui-screen-hidden fade" |
| 50 | + }) |
| 51 | + .appendTo( thisPage ), |
| 52 | + listbox = $( "<div>", { "class": "ui-listbox ui-listbox-hidden ui-body-a ui-overlay-shadow ui-corner-all pop"} ) |
| 53 | + .insertAfter(screen), |
| 54 | + list = $( "<ul>", { |
| 55 | + "class": "ui-listbox-list", |
| 56 | + "id": menuId, |
| 57 | + "role": "listbox", |
| 58 | + "aria-labelledby": buttonId |
| 59 | + }) |
| 60 | + .appendTo( listbox ); |
64 | 61 |
|
65 | 62 | //populate menu
|
66 | 63 | select.find( "option" ).each(function( i ){
|
@@ -192,8 +189,15 @@ $.fn.customSelect = function(options){
|
192 | 189 | hidemenu();
|
193 | 190 | return false;
|
194 | 191 | });
|
195 |
| - }); |
196 |
| -}; |
197 |
| - |
198 |
| -})(jQuery); |
| 192 | + }, |
| 193 | + |
| 194 | + disable: function(){ |
| 195 | + this.element.attr("disabled",true); |
| 196 | + }, |
| 197 | + |
| 198 | + enable: function(){ |
| 199 | + this.element.attr("disabled",false); |
| 200 | + } |
| 201 | +}); |
| 202 | +})( jQuery ); |
199 | 203 |
|
0 commit comments