Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Jquery mobilemenu version 1.0

  • Loading branch information...
commit dd93ffb68d2de57ab58368cc03c2bbd608cf2636 1 parent aadf254
@mambows authored
Showing with 68 additions and 0 deletions.
  1. +68 −0 jquery.mobilemenu.js
View
68 jquery.mobilemenu.js
@@ -0,0 +1,68 @@
+/**
+ * jQuery Mobile Menu
+ * Turn unordered list menu into dropdown select menu
+ * version 1.0(31-OCT-2011)
+ *
+ * Built on top of the jQuery library
+ * http://jquery.com
+ *
+ * Documentation
+ * http://github.com/mambows/mobilemenu
+ */
+(function($){
+$.fn.mobileMenu = function(options) {
+
+ var defaults = {
+ defaultText: 'Navigate to...',
+ className: 'select-menu',
+ subMenuClass: 'sub-menu',
+ subMenuDash: '–'
+ },
+ settings = $.extend( defaults, options ),
+ el = $(this);
+
+ this.each(function(){
+ // Create base menu
+ $('<select />',{
+ 'class' : settings.className
+ }).insertAfter( el );
+
+ // Create default option
+ $('<option />', {
+ "text" : settings.defaultText
+ }).appendTo( '.' + settings.className );
+
+ // Create select option from menu
+ el.find('a').each(function(){
+ var $this = $(this),
+ optText = '&nbsp;' + $this.text(),
+ optSub = $this.parents( '.' + settings.subMenuClass ),
+ len = optSub.length,
+ dash;
+
+ // if menu has sub menu
+ if( $this.parents('ul').hasClass( settings.subMenuClass ) ) {
+ dash = Array( len+1 ).join( settings.subMenuDash );
+ optText = dash + optText;
+ }
+
+ // Now build menu and append it
+ $('<option />', {
+ "value" : this.href,
+ "html" : optText,
+ "selected" : (this.href == window.location.href)
+ }).appendTo( '.' + settings.className );
+
+ }); // End el.find('a').each
+
+ // Change event on select element
+ $('.' + settings.className).change(function(){
+ window.location.href = $(this).val();
+ });
+
+ }); // End this.each
+
+ return this;
+
+};
+})(jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.