/* * jQuery Mobile Framework : "customSelect" plugin (based on code from Filament Group,Inc) * Copyright (c) jQuery Project * Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses. * Note: Code is in draft form and is subject to change */ (function($){ $.fn.customSelect = function(options){ return $(this).each(function(){ //extendable options var o = $.extend({ backText: 'Back', chooseText: 'Choose one:', inline: false }, options); var select = $(this), label = $('label[for='+ select.attr('id') +']').addClass('ui-select'), buttonId = select.attr('id')+'-button', menuId = select.attr('id')+'-menu', thisPage = $(this).closest('.ui-page'); //select properties,events select .change(function(){ button.find('.ui-btn-text').text(select.val()); }) .focus(function(){ $(this).blur(); button.focus(); }) .wrap('
') .attr('tabindex','-1') .bind('showmenu',function(){ $(document).data('currScroll', [$(window).scrollLeft(), $(window).scrollTop()]); if(menuHeight > window.innerHeight - 80){ menuType = "page"; thisPage.find('.ui-content').addClass('ui-content-hidden'); listbox.removeClass('ui-listbox-overlay'); } else { menuType = "overlay"; listbox.addClass('ui-listbox-overlay').css({ top: $(window).scrollTop() + (window.innerHeight/2), 'margin-top': -menuHeight/2, left: window.innerWidth/2 }); } screen.css({width: $(window).width(), height: $(document).height()}).removeClass('ui-helper-hidden out').addClass('in'); listbox.removeClass('ui-listbox-hidden'); var selectedLI = list.find('.ui-btn-active').focus(); if(menuType == "page"){ $(window)[0].scrollTo(0, 0); listbox.addClass('slideup in'); } else{ listbox.addClass('pop in'); } }) .bind('hidemenu',function(){ screen.addClass('ui-helper-hidden out'); listbox.removeAttr('style').removeClass('in').addClass('ui-listbox-hidden out'); thisPage.find('.ui-content').removeClass('ui-content-hidden'); setTimeout(function(){ button.focus(); if(menuType == "page"){ $(window)[0].scrollTo($(document).data('currScroll')[0], $(document).data('currScroll')[1]); if(button.offset().top > window.innerHeight){ $(window)[0].scrollTo(0, button.offset().top); } } }, 50); }); //create menu button var button = $(''+ select.val() +'') .buttonMarkup({ iconPos: 'right', icon: 'arrow-d' }) .attr({ 'role': 'button', 'title': 'select menu', 'id': buttonId, 'aria-haspopup': 'true', 'aria-owns': menuId }) .mousedown(function(){ select.trigger('showmenu'); return false; }) .insertBefore(select); //create menu var listbox = $(''); //menu header $('') .prepend( $(''+ o.backText +'').buttonMarkup({icon: 'arrow-l'}) ) .appendTo(listbox); var list = $('