Skip to content

Commit

Permalink
sample changes to make ui-tabs work within jqm.
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Jehl committed Jul 1, 2012
1 parent e3c173e commit 29d085b
Show file tree
Hide file tree
Showing 9 changed files with 966 additions and 25 deletions.
3 changes: 2 additions & 1 deletion css/structure/jquery.mobile.structure.css
Expand Up @@ -22,4 +22,5 @@
@import url( "jquery.mobile.forms.select.css" ); @import url( "jquery.mobile.forms.select.css" );
@import url( "jquery.mobile.forms.textinput.css" ); @import url( "jquery.mobile.forms.textinput.css" );
@import url( "jquery.mobile.listview.css" ); @import url( "jquery.mobile.listview.css" );
@import url( "jquery.mobile.forms.slider.css" ); @import url( "jquery.mobile.forms.slider.css" );
@import url( "jquery.mobile.tabs.css" );
17 changes: 17 additions & 0 deletions css/structure/jquery.mobile.tabs.css
@@ -0,0 +1,17 @@
/*!
* jQuery UI Tabs @VERSION
*
* Copyright 2012, 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/Tabs#theming
*/
.ui-tabs { position: relative; } /* position: relative prevents IE scroll bug (element with position: relative inside container with overflow: auto appear as "fixed") */
.ui-tabs .ui-tabs-nav { margin: 0; display: table; width: 100%; padding: 0; }
.ui-tabs .ui-tabs-nav li { list-style: none; display: table-cell;white-space: nowrap; }
.ui-tabs .ui-tabs-nav li a { text-decoration: none; }
.ui-tabs .ui-tabs-nav li.ui-tabs-active { margin-bottom: -1px; padding-bottom: 1px; }
.ui-tabs .ui-tabs-nav li.ui-tabs-active a, .ui-tabs .ui-tabs-nav li.ui-state-disabled a, .ui-tabs .ui-tabs-nav li.ui-tabs-loading a { cursor: text; }
.ui-tabs .ui-tabs-nav li a, .ui-tabs-collapsible .ui-tabs-nav li.ui-tabs-active a { cursor: pointer; } /* first selector in group seems obsolete, but required to overcome bug in Opera applying cursor: text overall if defined elsewhere... */
.ui-tabs .ui-tabs-panel { display: block; border-width: 0; padding: 1em 1.4em; background: none; }
49 changes: 49 additions & 0 deletions docs/tabs/index.html
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery Mobile Docs - Tabs</title>
<link rel="stylesheet" href="../../css/themes/default/jquery.mobile.css" />
<link rel="stylesheet" href="../_assets/css/jqm-docs.css"/>

<script src="../../js/jquery.js"></script>
<script src="../../docs/_assets/js/jqm-docs.js"></script>
<script src="../../js/"></script>

</head>
<body>

<div data-role="page" class="type-index">

<div data-role="header" data-theme="f">
<h1>Tabs</h1>
<a href="../../" data-icon="home" data-iconpos="notext" data-direction="reverse">Home</a>
<a href="../nav.html" data-icon="search" data-iconpos="notext" data-rel="dialog" data-transition="fade">Search</a>
</div><!-- /header -->

<div data-role="content">

<div data-role="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">
<p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.</p>
</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><!-- /content -->
</div><!-- /page -->

</body>
</html>
1 change: 1 addition & 0 deletions index.html
Expand Up @@ -49,6 +49,7 @@ <h1 id="jqm-logo"><img src="docs/_assets/images/jquery-logo.png" alt="jQuery Mob
<li><a href="docs/content/index.html">Content formatting</a></li> <li><a href="docs/content/index.html">Content formatting</a></li>
<li><a href="docs/forms/index.html">Form elements</a></li> <li><a href="docs/forms/index.html">Form elements</a></li>
<li><a href="docs/lists/index.html">List views</a></li> <li><a href="docs/lists/index.html">List views</a></li>
<li><a href="docs/tabs/index.html">Tabs</a></li>


<li data-role="list-divider">API</li> <li data-role="list-divider">API</li>
<li><a href="docs/api/globalconfig.html">Configuring defaults</a></li> <li><a href="docs/api/globalconfig.html">Configuring defaults</a></li>
Expand Down
1 change: 1 addition & 0 deletions js/index.php
Expand Up @@ -54,6 +54,7 @@
'widgets/popup.js', 'widgets/popup.js',
'jquery.mobile.zoom.js', 'jquery.mobile.zoom.js',
'jquery.mobile.zoom.iosorientationfix.js', 'jquery.mobile.zoom.iosorientationfix.js',
'widgets/tabs.js',
'jquery.mobile.init.js' 'jquery.mobile.init.js'
); );


Expand Down
3 changes: 2 additions & 1 deletion js/jquery.mobile.js
Expand Up @@ -31,7 +31,8 @@ define([
'./widgets/fixedToolbar', './widgets/fixedToolbar',
'./widgets/popup', './widgets/popup',
'./jquery.mobile.zoom', './jquery.mobile.zoom',
'./jquery.mobile.zoom.iosorientationfix' './jquery.mobile.zoom.iosorientationfix',
'./widgets/tabs'
], function( require ) { ], function( require ) {
require( [ './jquery.mobile.init' ], function() {} ); require( [ './jquery.mobile.init' ], function() {} );
}); });
Expand Down
55 changes: 33 additions & 22 deletions js/jquery.ui.widget.js
Expand Up @@ -9,9 +9,9 @@
*/ */
(function( $, undefined ) { (function( $, undefined ) {


var slice = Array.prototype.slice; var uuid = 0,

slice = Array.prototype.slice,
var _cleanData = $.cleanData; _cleanData = $.cleanData;
$.cleanData = function( elems ) { $.cleanData = function( elems ) {
for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) { for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
try { try {
Expand Down Expand Up @@ -73,11 +73,11 @@ $.widget = function( name, base, prototype ) {
if ( $.isFunction( value ) ) { if ( $.isFunction( value ) ) {
prototype[ prop ] = (function() { prototype[ prop ] = (function() {
var _super = function() { var _super = function() {
return base.prototype[ prop ].apply( this, arguments ); return base.prototype[ prop ].apply( this, arguments );
}; },
var _superApply = function( args ) { _superApply = function( args ) {
return base.prototype[ prop ].apply( this, args ); return base.prototype[ prop ].apply( this, args );
}; };
return function() { return function() {
var __super = this._super, var __super = this._super,
__superApply = this._superApply, __superApply = this._superApply,
Expand Down Expand Up @@ -163,15 +163,16 @@ $.widget.bridge = function( name, object ) {


if ( isMethodCall ) { if ( isMethodCall ) {
this.each(function() { this.each(function() {
var instance = $.data( this, fullName ); var methodValue,
instance = $.data( this, fullName );
if ( !instance ) { if ( !instance ) {
return $.error( "cannot call methods on " + name + " prior to initialization; " + return $.error( "cannot call methods on " + name + " prior to initialization; " +
"attempted to call method '" + options + "'" ); "attempted to call method '" + options + "'" );
} }
if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) { if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
return $.error( "no such method '" + options + "' for " + name + " widget instance" ); return $.error( "no such method '" + options + "' for " + name + " widget instance" );
} }
var methodValue = instance[ options ].apply( instance, args ); methodValue = instance[ options ].apply( instance, args );
if ( methodValue !== instance && methodValue !== undefined ) { if ( methodValue !== instance && methodValue !== undefined ) {
returnValue = methodValue && methodValue.jquery ? returnValue = methodValue && methodValue.jquery ?
returnValue.pushStack( methodValue.get() ) : returnValue.pushStack( methodValue.get() ) :
Expand Down Expand Up @@ -210,6 +211,8 @@ $.Widget.prototype = {
_createWidget: function( options, element ) { _createWidget: function( options, element ) {
element = $( element || this.defaultElement || this )[ 0 ]; element = $( element || this.defaultElement || this )[ 0 ];
this.element = $( element ); this.element = $( element );
this.uuid = uuid++;
this.eventNamespace = "." + this.widgetName + this.uuid;
this.options = $.widget.extend( {}, this.options = $.widget.extend( {},
this.options, this.options,
this._getCreateOptions(), this._getCreateOptions(),
Expand All @@ -224,7 +227,7 @@ $.Widget.prototype = {
// TODO remove dual storage // TODO remove dual storage
$.data( element, this.widgetName, this ); $.data( element, this.widgetName, this );
$.data( element, this.widgetFullName, this ); $.data( element, this.widgetFullName, this );
this._bind({ remove: "destroy" }); this._on({ remove: "destroy" });
this.document = $( element.style ? this.document = $( element.style ?
// element within the document // element within the document
element.ownerDocument : element.ownerDocument :
Expand All @@ -245,22 +248,25 @@ $.Widget.prototype = {
destroy: function() { destroy: function() {
this._destroy(); this._destroy();
// we can probably remove the unbind calls in 2.0 // we can probably remove the unbind calls in 2.0
// all event bindings should go through this._bind() // all event bindings should go through this._on()
this.element this.element
.unbind( "." + this.widgetName ) .unbind( this.eventNamespace )
// 1.9 BC for #7810 // 1.9 BC for #7810
// TODO remove dual storage // TODO remove dual storage
.removeData( this.widgetName ) .removeData( this.widgetName )
.removeData( this.widgetFullName ); .removeData( this.widgetFullName )
// support: jquery <1.6.3
// http://bugs.jquery.com/ticket/9413
.removeData( $.camelCase( this.widgetFullName ) );
this.widget() this.widget()
.unbind( "." + this.widgetName ) .unbind( this.eventNamespace )
.removeAttr( "aria-disabled" ) .removeAttr( "aria-disabled" )
.removeClass( .removeClass(
this.widgetFullName + "-disabled " + this.widgetFullName + "-disabled " +
"ui-state-disabled" ); "ui-state-disabled" );


// clean up events and states // clean up events and states
this.bindings.unbind( "." + this.widgetName ); this.bindings.unbind( this.eventNamespace );
this.hoverable.removeClass( "ui-state-hover" ); this.hoverable.removeClass( "ui-state-hover" );
this.focusable.removeClass( "ui-state-focus" ); this.focusable.removeClass( "ui-state-focus" );
}, },
Expand Down Expand Up @@ -339,7 +345,7 @@ $.Widget.prototype = {
return this._setOption( "disabled", true ); return this._setOption( "disabled", true );
}, },


_bind: function( element, handlers ) { _on: function( element, handlers ) {
// no element argument, shuffle and use this.element // no element argument, shuffle and use this.element
if ( !handlers ) { if ( !handlers ) {
handlers = element; handlers = element;
Expand Down Expand Up @@ -367,11 +373,11 @@ $.Widget.prototype = {
// copy the guid so direct unbinding works // copy the guid so direct unbinding works
if ( typeof handler !== "string" ) { if ( typeof handler !== "string" ) {
handlerProxy.guid = handler.guid = handlerProxy.guid = handler.guid =
handler.guid || handlerProxy.guid || jQuery.guid++; handler.guid || handlerProxy.guid || $.guid++;
} }


var match = event.match( /^(\w+)\s*(.*)$/ ), var match = event.match( /^(\w+)\s*(.*)$/ ),
eventName = match[1] + "." + instance.widgetName, eventName = match[1] + instance.eventNamespace,
selector = match[2]; selector = match[2];
if ( selector ) { if ( selector ) {
instance.widget().delegate( selector, eventName, handlerProxy ); instance.widget().delegate( selector, eventName, handlerProxy );
Expand All @@ -381,6 +387,11 @@ $.Widget.prototype = {
}); });
}, },


_off: function( element, eventName ) {
eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + this.eventNamespace;
element.unbind( eventName ).undelegate( eventName );
},

_delay: function( handler, delay ) { _delay: function( handler, delay ) {
function handlerProxy() { function handlerProxy() {
return ( typeof handler === "string" ? instance[ handler ] : handler ) return ( typeof handler === "string" ? instance[ handler ] : handler )
Expand All @@ -392,7 +403,7 @@ $.Widget.prototype = {


_hoverable: function( element ) { _hoverable: function( element ) {
this.hoverable = this.hoverable.add( element ); this.hoverable = this.hoverable.add( element );
this._bind( element, { this._on( element, {
mouseenter: function( event ) { mouseenter: function( event ) {
$( event.currentTarget ).addClass( "ui-state-hover" ); $( event.currentTarget ).addClass( "ui-state-hover" );
}, },
Expand All @@ -404,7 +415,7 @@ $.Widget.prototype = {


_focusable: function( element ) { _focusable: function( element ) {
this.focusable = this.focusable.add( element ); this.focusable = this.focusable.add( element );
this._bind( element, { this._on( element, {
focusin: function( event ) { focusin: function( event ) {
$( event.currentTarget ).addClass( "ui-state-focus" ); $( event.currentTarget ).addClass( "ui-state-focus" );
}, },
Expand Down Expand Up @@ -487,4 +498,4 @@ if ( $.uiBackCompat !== false ) {
}; };
} }


})( jQuery ); })( jQuery );
2 changes: 1 addition & 1 deletion js/widgets/navbar.js
Expand Up @@ -24,7 +24,7 @@ $.widget( "mobile.navbar", $.mobile.widget, {
iconpos = $navbtns.filter( ":jqmData(icon)" ).length ? iconpos = $navbtns.filter( ":jqmData(icon)" ).length ?
this.options.iconpos : undefined; this.options.iconpos : undefined;


$navbar.addClass( "ui-navbar ui-mini" ) $navbar.addClass( "ui-navbar" )
.attr( "role","navigation" ) .attr( "role","navigation" )
.find( "ul" ) .find( "ul" )
.jqmEnhanceable() .jqmEnhanceable()
Expand Down

0 comments on commit 29d085b

Please sign in to comment.