2011-12-16 02:09:25 +00:00
|
|
|
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
|
2012-01-07 00:28:54 +00:00
|
|
|
//>>description: For making button-like links.
|
|
|
|
|
//>>label: Buttons
|
|
|
|
|
|
2012-01-24 22:43:24 +00:00
|
|
|
define( [ "jquery", "./jquery.mobile.core", "./jquery.mobile.vmouse" ], function( $ ) {
|
2011-12-16 02:09:25 +00:00
|
|
|
//>>excludeEnd("jqmBuildExclude");
|
2011-05-26 19:08:10 +00:00
|
|
|
( function( $, undefined ) {
|
2010-09-29 18:56:41 +00:00
|
|
|
|
2011-05-26 19:08:10 +00:00
|
|
|
$.fn.buttonMarkup = function( options ) {
|
2011-11-01 06:45:42 +00:00
|
|
|
options = options || {};
|
|
|
|
|
for ( var i = 0; i < this.length; i++ ) {
|
|
|
|
|
var el = this.eq( i ),
|
|
|
|
|
e = el[ 0 ],
|
2011-09-15 23:10:10 +00:00
|
|
|
o = $.extend( {}, $.fn.buttonMarkup.defaults, {
|
2011-11-01 16:26:41 +00:00
|
|
|
icon: options.icon !== undefined ? options.icon : el.jqmData( "icon" ),
|
|
|
|
|
iconpos: options.iconpos !== undefined ? options.iconpos : el.jqmData( "iconpos" ),
|
|
|
|
|
theme: options.theme !== undefined ? options.theme : el.jqmData( "theme" ),
|
|
|
|
|
inline: options.inline !== undefined ? options.inline : el.jqmData( "inline" ),
|
|
|
|
|
shadow: options.shadow !== undefined ? options.shadow : el.jqmData( "shadow" ),
|
|
|
|
|
corners: options.corners !== undefined ? options.corners : el.jqmData( "corners" ),
|
|
|
|
|
iconshadow: options.iconshadow !== undefined ? options.iconshadow : el.jqmData( "iconshadow" )
|
2011-09-15 23:10:10 +00:00
|
|
|
}, options ),
|
2010-10-22 15:39:26 +00:00
|
|
|
|
2010-09-29 18:56:41 +00:00
|
|
|
// Classes Defined
|
|
|
|
|
innerClass = "ui-btn-inner",
|
2011-10-31 20:24:17 +00:00
|
|
|
textClass = "ui-btn-text",
|
2011-06-28 22:30:17 +00:00
|
|
|
buttonClass, iconClass,
|
2011-11-01 06:45:42 +00:00
|
|
|
// Button inner markup
|
|
|
|
|
buttonInner = document.createElement( o.wrapperEls ),
|
|
|
|
|
buttonText = document.createElement( o.wrapperEls ),
|
|
|
|
|
buttonIcon = o.icon ? document.createElement( "span" ) : null;
|
2010-10-21 21:18:59 +00:00
|
|
|
|
2012-01-17 00:23:14 +00:00
|
|
|
// if so, prevent double enhancement, and continue with rest of the elements.
|
2012-01-19 01:40:50 +00:00
|
|
|
if( e.tagName === "INPUT" && el.jqmData('role') === "button" ) continue;
|
|
|
|
|
|
2012-01-10 05:38:12 +00:00
|
|
|
// if this is a button, check if it's been enhanced and, if not, use the right function
|
|
|
|
|
if( e.tagName === "BUTTON" ) {
|
|
|
|
|
if ( !$( e.parentNode ).hasClass( "ui-btn" ) ) $( e ).button();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-21 21:18:59 +00:00
|
|
|
if ( attachEvents ) {
|
|
|
|
|
attachEvents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if not, try to find closest theme container
|
|
|
|
|
if ( !o.theme ) {
|
2011-10-17 23:54:20 +00:00
|
|
|
o.theme = $.mobile.getInheritedTheme( el, "c" );
|
2010-10-21 21:18:59 +00:00
|
|
|
}
|
2010-10-22 15:39:26 +00:00
|
|
|
|
|
|
|
|
buttonClass = "ui-btn ui-btn-up-" + o.theme;
|
2011-01-30 08:19:15 +00:00
|
|
|
|
2010-10-21 21:18:59 +00:00
|
|
|
if ( o.inline ) {
|
2010-10-11 19:47:30 +00:00
|
|
|
buttonClass += " ui-btn-inline";
|
|
|
|
|
}
|
2011-01-30 08:19:15 +00:00
|
|
|
|
2010-10-21 21:18:59 +00:00
|
|
|
if ( o.icon ) {
|
|
|
|
|
o.icon = "ui-icon-" + o.icon;
|
|
|
|
|
o.iconpos = o.iconpos || "left";
|
2010-09-29 18:56:41 +00:00
|
|
|
|
|
|
|
|
iconClass = "ui-icon " + o.icon;
|
|
|
|
|
|
2011-07-06 20:22:53 +00:00
|
|
|
if ( o.iconshadow ) {
|
2011-01-30 08:19:15 +00:00
|
|
|
iconClass += " ui-icon-shadow";
|
2010-10-21 21:18:59 +00:00
|
|
|
}
|
2010-09-29 18:56:41 +00:00
|
|
|
}
|
2010-10-22 15:39:26 +00:00
|
|
|
|
2010-10-21 21:18:59 +00:00
|
|
|
if ( o.iconpos ) {
|
2010-10-05 14:58:58 +00:00
|
|
|
buttonClass += " ui-btn-icon-" + o.iconpos;
|
2011-01-30 08:19:15 +00:00
|
|
|
|
2011-05-26 19:08:10 +00:00
|
|
|
if ( o.iconpos == "notext" && !el.attr( "title" ) ) {
|
2011-10-04 22:48:05 +00:00
|
|
|
el.attr( "title", el.getEncodedText() );
|
2010-10-07 15:39:23 +00:00
|
|
|
}
|
2010-10-04 16:48:32 +00:00
|
|
|
}
|
2011-01-30 08:19:15 +00:00
|
|
|
|
|
|
|
|
if ( o.corners ) {
|
2010-09-29 18:56:41 +00:00
|
|
|
buttonClass += " ui-btn-corner-all";
|
|
|
|
|
innerClass += " ui-btn-corner-all";
|
|
|
|
|
}
|
2011-01-30 08:19:15 +00:00
|
|
|
|
2010-10-21 21:18:59 +00:00
|
|
|
if ( o.shadow ) {
|
2010-09-29 18:56:41 +00:00
|
|
|
buttonClass += " ui-shadow";
|
2010-09-10 22:23:13 +00:00
|
|
|
}
|
2011-01-30 08:19:15 +00:00
|
|
|
|
2011-11-11 22:51:58 +00:00
|
|
|
e.setAttribute( "data-" + $.mobile.ns + "theme", o.theme );
|
2011-12-02 01:15:52 +00:00
|
|
|
el.removeClass( "ui-link" ).addClass( buttonClass );
|
2010-10-22 15:39:26 +00:00
|
|
|
|
2011-11-01 06:45:42 +00:00
|
|
|
buttonInner.className = innerClass;
|
|
|
|
|
|
|
|
|
|
buttonText.className = textClass;
|
|
|
|
|
buttonInner.appendChild( buttonText );
|
|
|
|
|
|
|
|
|
|
if ( buttonIcon ) {
|
|
|
|
|
buttonIcon.className = iconClass;
|
|
|
|
|
buttonInner.appendChild( buttonIcon );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while ( e.firstChild ) {
|
|
|
|
|
buttonText.appendChild( e.firstChild );
|
|
|
|
|
}
|
2010-10-22 15:39:26 +00:00
|
|
|
|
2011-11-01 06:45:42 +00:00
|
|
|
e.appendChild( buttonInner );
|
2011-11-20 22:32:14 +00:00
|
|
|
|
2011-10-31 20:24:17 +00:00
|
|
|
// TODO obviously it would be nice to pull this element out instead of
|
|
|
|
|
// retrieving it from the DOM again, but this change is much less obtrusive
|
|
|
|
|
// and 1.0 draws nigh
|
2011-11-11 22:51:58 +00:00
|
|
|
$.data( e, 'textWrapper', $( buttonText ) );
|
2011-11-01 06:45:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this;
|
2010-09-29 18:56:41 +00:00
|
|
|
};
|
2010-09-10 22:23:13 +00:00
|
|
|
|
2010-11-11 15:49:15 +00:00
|
|
|
$.fn.buttonMarkup.defaults = {
|
2010-09-29 18:56:41 +00:00
|
|
|
corners: true,
|
|
|
|
|
shadow: true,
|
|
|
|
|
iconshadow: true,
|
2011-09-23 19:28:24 +00:00
|
|
|
inline: false,
|
2010-10-21 21:18:59 +00:00
|
|
|
wrapperEls: "span"
|
2010-09-10 22:23:13 +00:00
|
|
|
};
|
2010-09-29 18:56:41 +00:00
|
|
|
|
2011-06-22 16:31:49 +00:00
|
|
|
function closestEnabledButton( element ) {
|
2011-10-21 23:08:28 +00:00
|
|
|
var cname;
|
2011-10-31 20:24:17 +00:00
|
|
|
|
2011-10-21 23:08:28 +00:00
|
|
|
while ( element ) {
|
2011-11-15 18:19:37 +00:00
|
|
|
// Note that we check for typeof className below because the element we
|
|
|
|
|
// handed could be in an SVG DOM where className on SVG elements is defined to
|
|
|
|
|
// be of a different type (SVGAnimatedString). We only operate on HTML DOM
|
|
|
|
|
// elements, so we look for plain "string".
|
2011-11-20 22:32:14 +00:00
|
|
|
cname = ( typeof element.className === 'string' ) && (element.className + ' ');
|
|
|
|
|
if ( cname && cname.indexOf("ui-btn ") > -1 && cname.indexOf("ui-disabled ") < 0 ) {
|
2011-10-21 23:08:28 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2011-11-20 22:32:14 +00:00
|
|
|
|
2011-10-21 23:08:28 +00:00
|
|
|
element = element.parentNode;
|
|
|
|
|
}
|
2011-10-31 20:24:17 +00:00
|
|
|
|
2011-10-21 23:08:28 +00:00
|
|
|
return element;
|
2011-04-18 23:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
2010-10-21 21:18:59 +00:00
|
|
|
var attachEvents = function() {
|
2011-12-30 20:24:32 +00:00
|
|
|
var hoverDelay = 200,
|
|
|
|
|
hov, foc;
|
2011-05-26 19:08:10 +00:00
|
|
|
$( document ).bind( {
|
|
|
|
|
"vmousedown": function( event ) {
|
2011-06-28 22:30:17 +00:00
|
|
|
var btn = closestEnabledButton( event.target ),
|
|
|
|
|
$btn, theme;
|
|
|
|
|
|
2011-05-26 19:08:10 +00:00
|
|
|
if ( btn ) {
|
2011-06-28 22:30:17 +00:00
|
|
|
$btn = $( btn );
|
|
|
|
|
theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
|
2011-12-30 20:58:56 +00:00
|
|
|
|
|
|
|
|
if( $.support.touch ) {
|
|
|
|
|
hov = setTimeout(function() {
|
|
|
|
|
$btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-down-" + theme );
|
|
|
|
|
}, hoverDelay );
|
|
|
|
|
} else {
|
2011-12-30 20:24:32 +00:00
|
|
|
$btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-down-" + theme );
|
2011-12-30 20:58:56 +00:00
|
|
|
}
|
2011-04-18 23:13:50 +00:00
|
|
|
}
|
2010-10-21 21:18:59 +00:00
|
|
|
},
|
2011-05-26 19:08:10 +00:00
|
|
|
"vmousecancel vmouseup": function( event ) {
|
2011-06-28 22:30:17 +00:00
|
|
|
var btn = closestEnabledButton( event.target ),
|
|
|
|
|
$btn, theme;
|
|
|
|
|
|
2011-05-26 19:08:10 +00:00
|
|
|
if ( btn ) {
|
2011-06-28 22:30:17 +00:00
|
|
|
$btn = $( btn );
|
|
|
|
|
theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
|
2011-04-18 23:13:50 +00:00
|
|
|
$btn.removeClass( "ui-btn-down-" + theme ).addClass( "ui-btn-up-" + theme );
|
|
|
|
|
}
|
2010-10-21 21:18:59 +00:00
|
|
|
},
|
2011-05-26 19:08:10 +00:00
|
|
|
"vmouseover focus": function( event ) {
|
2011-06-28 22:30:17 +00:00
|
|
|
var btn = closestEnabledButton( event.target ),
|
|
|
|
|
$btn, theme;
|
2011-12-30 20:58:56 +00:00
|
|
|
|
2011-05-26 19:08:10 +00:00
|
|
|
if ( btn ) {
|
2011-06-28 22:30:17 +00:00
|
|
|
$btn = $( btn );
|
|
|
|
|
theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
|
2011-12-30 20:58:56 +00:00
|
|
|
|
|
|
|
|
if( $.support.touch ) {
|
|
|
|
|
foc = setTimeout(function() {
|
|
|
|
|
$btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-hover-" + theme );
|
|
|
|
|
}, hoverDelay );
|
|
|
|
|
} else {
|
2011-12-30 20:24:32 +00:00
|
|
|
$btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-hover-" + theme );
|
2011-12-30 20:58:56 +00:00
|
|
|
}
|
2011-04-18 23:13:50 +00:00
|
|
|
}
|
2010-10-21 21:18:59 +00:00
|
|
|
},
|
2011-12-29 16:13:54 +00:00
|
|
|
"vmouseout blur scrollstart": function( event ) {
|
2011-06-28 22:30:17 +00:00
|
|
|
var btn = closestEnabledButton( event.target ),
|
|
|
|
|
$btn, theme;
|
2011-12-30 20:58:56 +00:00
|
|
|
|
2011-05-26 19:08:10 +00:00
|
|
|
if ( btn ) {
|
2011-06-28 22:30:17 +00:00
|
|
|
$btn = $( btn );
|
|
|
|
|
theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
|
2011-11-01 13:34:53 +00:00
|
|
|
$btn.removeClass( "ui-btn-hover-" + theme + " ui-btn-down-" + theme ).addClass( "ui-btn-up-" + theme );
|
2011-12-30 20:24:32 +00:00
|
|
|
|
|
|
|
|
hov && clearTimeout( hov );
|
|
|
|
|
foc && clearTimeout( foc );
|
2011-04-18 23:13:50 +00:00
|
|
|
}
|
2010-10-21 21:18:59 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
attachEvents = null;
|
2010-10-22 15:39:26 +00:00
|
|
|
};
|
2010-09-10 22:23:13 +00:00
|
|
|
|
This commit decouples all widgets from the page plugin so that they can be used ad-hoc.
- Internally, each plugin self-initializes by binding to the pagecreate event.
- Unit tests have been added and adjusted to support some internal changes involved in this commit.
- In the process, the portions of the page plugin that were used to enhance the header,content,and footer sections of a native-app style page layout are now located in jquery.mobile.page.sections.js.
- No public API options have changed, except that the page plugin no longer has options for keepNative, and degradeInputs, as plugins now handle these internally (keepNative was never documented, and degradeInputs only affected slider, so it lives there now. Page options related to the page sections are now located in the page.sections script, but they are still configurable via the page plugin's options api.
- Make, Ant, and index files are updated with a new load order for all JS files.
2011-07-19 23:05:35 +00:00
|
|
|
//links in bars, or those with data-role become buttons
|
|
|
|
|
//auto self-init widgets
|
2011-07-22 13:05:55 +00:00
|
|
|
$( document ).bind( "pagecreate create", function( e ){
|
This commit decouples all widgets from the page plugin so that they can be used ad-hoc.
- Internally, each plugin self-initializes by binding to the pagecreate event.
- Unit tests have been added and adjusted to support some internal changes involved in this commit.
- In the process, the portions of the page plugin that were used to enhance the header,content,and footer sections of a native-app style page layout are now located in jquery.mobile.page.sections.js.
- No public API options have changed, except that the page plugin no longer has options for keepNative, and degradeInputs, as plugins now handle these internally (keepNative was never documented, and degradeInputs only affected slider, so it lives there now. Page options related to the page sections are now located in the page.sections script, but they are still configurable via the page plugin's options api.
- Make, Ant, and index files are updated with a new load order for all JS files.
2011-07-19 23:05:35 +00:00
|
|
|
|
2011-07-28 18:41:31 +00:00
|
|
|
$( ":jqmData(role='button'), .ui-bar > a, .ui-header > a, .ui-footer > a, .ui-bar > :jqmData(role='controlgroup') > a", e.target )
|
This commit decouples all widgets from the page plugin so that they can be used ad-hoc.
- Internally, each plugin self-initializes by binding to the pagecreate event.
- Unit tests have been added and adjusted to support some internal changes involved in this commit.
- In the process, the portions of the page plugin that were used to enhance the header,content,and footer sections of a native-app style page layout are now located in jquery.mobile.page.sections.js.
- No public API options have changed, except that the page plugin no longer has options for keepNative, and degradeInputs, as plugins now handle these internally (keepNative was never documented, and degradeInputs only affected slider, so it lives there now. Page options related to the page sections are now located in the page.sections script, but they are still configurable via the page plugin's options api.
- Make, Ant, and index files are updated with a new load order for all JS files.
2011-07-19 23:05:35 +00:00
|
|
|
.not( ".ui-btn, :jqmData(role='none'), :jqmData(role='nojs')" )
|
|
|
|
|
.buttonMarkup();
|
|
|
|
|
});
|
|
|
|
|
|
2011-05-26 19:08:10 +00:00
|
|
|
})( jQuery );
|
2011-12-16 02:09:25 +00:00
|
|
|
|
|
|
|
|
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
|
2011-10-31 04:59:56 +00:00
|
|
|
});
|
2011-12-16 07:31:35 +00:00
|
|
|
//>>excludeEnd("jqmBuildExclude");
|