changed custom data method to $.fn.mobileData() and updated plugins that use it.

This commit is contained in:
scottjehl 2011-03-09 23:27:21 -05:00
parent 0bf5ce8a37
commit ea60207c1b
14 changed files with 61 additions and 61 deletions

View file

@ -9,7 +9,7 @@
$.fn.buttonMarkup = function( options ){
return this.each( function() {
var el = $( this ),
o = $.extend( {}, $.fn.buttonMarkup.defaults, el.data(), options),
o = $.extend( {}, $.fn.buttonMarkup.defaults, el.mobileData(), options),
// Classes Defined
buttonClass,

View file

@ -62,7 +62,7 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
.addClass('ui-corner-all');
}
else {
if( collapsibleContain.data('collapsible-last') ){
if( collapsibleContain.mobileData('collapsible-last') ){
collapsibleHeading
.find('a:eq(0), .ui-btn-inner')
.addClass('ui-corner-bottom');
@ -82,7 +82,7 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
collapsibleHeading.find('.ui-icon').removeClass('ui-icon-minus').addClass('ui-icon-plus');
collapsibleContent.addClass('ui-collapsible-content-collapsed').attr('aria-hidden',true);
if( collapsibleContain.data('collapsible-last') ){
if( collapsibleContain.mobileData('collapsible-last') ){
collapsibleHeading
.find('a:eq(0), .ui-btn-inner')
.addClass('ui-corner-bottom');
@ -100,7 +100,7 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
collapsibleHeading.find('.ui-icon').removeClass('ui-icon-plus').addClass('ui-icon-minus');
collapsibleContent.removeClass('ui-collapsible-content-collapsed').attr('aria-hidden',false);
if( collapsibleContain.data('collapsible-last') ){
if( collapsibleContain.mobileData('collapsible-last') ){
collapsibleHeading
.find('a:eq(0), .ui-btn-inner')
.removeClass('ui-corner-bottom');
@ -112,9 +112,9 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
//close others in a set
if( collapsibleParent.length && !collapsibleParent.data("collapsiblebound") ){
if( collapsibleParent.length && !collapsibleParent.mobileData("collapsiblebound") ){
collapsibleParent
.data("collapsiblebound", true)
.mobileData("collapsiblebound", true)
.bind("expand", function( event ){
$(this).find( ".ui-collapsible-contain" )
.not( $(event.target).closest( ".ui-collapsible-contain" ) )
@ -129,7 +129,7 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
.find('.ui-btn-inner')
.addClass('ui-corner-top');
set.last().data('collapsible-last', true)
set.last().mobileData('collapsible-last', true)
}
collapsibleHeading

View file

@ -9,7 +9,7 @@ $.fn.controlgroup = function(options){
return this.each(function(){
var o = $.extend({
direction: $( this ).data( "type" ) || "vertical",
direction: $( this ).mobileData( "type" ) || "vertical",
shadow: false
},options);
var groupheading = $(this).find('>legend'),

View file

@ -111,7 +111,7 @@
//mobile version of data() method
//treats namespaced data-attrs the same as non-namespaced ones
$.mobile.data = function( prop, value ){
$.fn.mobileData = function( prop, value ){
var pUndef = prop === undefined,
vUndef = value === undefined;
@ -130,7 +130,7 @@
}
//if it's a prop get, try namepaced version if prop is undefined
else if( vUndef ){
ret = jqd.call( this, prop );
ret = this.data( prop );
if( ret === undefined ){
nsret = this.data( $.mobile.ns + prop );
if( nsret !== undefined ){

View file

@ -42,7 +42,7 @@ $.widget( "mobile.dialog", $.mobile.widget, {
$targetel = $(e.target).closest("form");
}
if( $targetel.length && !$targetel.data("transition") ){
if( $targetel.length && !$targetel.mobileData("transition") ){
$targetel
.attr("data-" + $.mobile.ns + "transition", $.mobile.urlHistory.getActive().transition )
.attr("data-" + $.mobile.ns + "direction", "reverse");

View file

@ -66,13 +66,13 @@ $.event.special.tap = {
.bind( "mousedown touchstart", function( event ) {
if ( event.which && event.which !== 1 ||
//check if event fired once already by a device that fires both mousedown and touchstart (while supporting both events)
$this.data( "prevEvent") && $this.data( "prevEvent") !== event.type ) {
$this.mobileData( "prevEvent") && $this.mobileData( "prevEvent") !== event.type ) {
return false;
}
//save event type so only this type is let through for a temp duration,
//allowing quick repetitive taps but not duplicative events
$this.data( "prevEvent", event.type );
$this.mobileData( "prevEvent", event.type );
setTimeout(function(){
$this.removeData( "prevEvent" );
}, 800);

View file

@ -11,7 +11,7 @@ $.fn.fixHeaderFooter = function(options){
return this.each(function(){
var $this = $(this);
if( $this.data('fullscreen') ){ $this.addClass('ui-page-fullscreen'); }
if( $this.mobileData('fullscreen') ){ $this.addClass('ui-page-fullscreen'); }
$this.find( ".ui-header[data-" + $.mobile.ns + "position='fixed']" ).addClass('ui-header-fixed ui-fixed-inline fade'); //should be slidedown
$this.find( ".ui-footer[data-" + $.mobile.ns + "position='fixed']" ).addClass('ui-footer-fixed ui-fixed-inline fade'); //should be slideup
});
@ -105,7 +105,7 @@ $.fixedToolbars = (function(){
$('.ui-page').live('pagebeforeshow', function(event, ui){
var page = $(event.target),
footer = page.find( "[data-" + $.mobile.ns + "role='footer']:not(.ui-sticky-footer)" ),
id = footer.data('id');
id = footer.mobileData('id');
stickyFooter = null;
if (id)
{

View file

@ -21,7 +21,7 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
// If there's no selected theme...
if( !this.options.theme ) {
this.options.theme = this.element.data( "theme" );
this.options.theme = this.element.mobileData( "theme" );
}
label
@ -43,14 +43,14 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
"touchmove": function( event ){
var oe = event.originalEvent.touches[0];
if( label.data("movestart") ){
if( Math.abs( label.data("movestart")[0] - oe.pageX ) > 10 ||
Math.abs( label.data("movestart")[1] - oe.pageY ) > 10 ){
label.data("moved", true);
if( label.mobileData("movestart") ){
if( Math.abs( label.mobileData("movestart")[0] - oe.pageX ) > 10 ||
Math.abs( label.mobileData("movestart")[1] - oe.pageY ) > 10 ){
label.mobileData("moved", true);
}
}
else{
label.data("movestart", [ parseFloat( oe.pageX ), parseFloat( oe.pageY ) ]);
label.mobileData("movestart", [ parseFloat( oe.pageX ), parseFloat( oe.pageY ) ]);
}
},
@ -61,14 +61,14 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
}
label.removeData("movestart");
if( label.data("etype") && label.data("etype") !== event.type || label.data("moved") ){
if( label.mobileData("etype") && label.mobileData("etype") !== event.type || label.mobileData("moved") ){
label.removeData("etype").removeData("moved");
if( label.data("moved") ){
if( label.mobileData("moved") ){
label.removeData("moved");
}
return false;
}
label.data( "etype", event.type );
label.mobileData( "etype", event.type );
self._cacheVals();
input.attr( "checked", inputtype === "radio" && true || !input.is( ":checked" ) );
self._updateAll();
@ -104,7 +104,7 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
_cacheVals: function(){
this._getInputSet().each(function(){
$(this).data("cacheVal", $(this).is(":checked") );
$(this).mobileData("cacheVal", $(this).is(":checked") );
});
},
@ -116,7 +116,7 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
_updateAll: function(){
this._getInputSet().each(function(){
var dVal = $(this).data("cacheVal");
var dVal = $(this).mobileData("cacheVal");
if( dVal && dVal !== $(this).is(":checked") || $(this).is( "[type='checkbox']" ) ){
$(this).trigger("change");
}

View file

@ -206,11 +206,11 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
button
.bind( "touchstart" , function( event ){
//set startTouches to cached copy of
$( this ).data( "startTouches", $.extend({}, event.originalEvent.touches[ 0 ]) );
$( this ).mobileData( "startTouches", $.extend({}, event.originalEvent.touches[ 0 ]) );
})
.bind( $.support.touch ? "touchend" : "mouseup" , function( event ){
//if it's a scroll, don't open
if( $( this ).data( "moved" ) ){
if( $( this ).mobileData( "moved" ) ){
$( this ).removeData( "moved" );
} else {
self.open();
@ -220,12 +220,12 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
.bind( "touchmove", function( event ){
//if touch moved enough, set data moved and don't open menu
var thisTouches = event.originalEvent.touches[ 0 ],
startTouches = $( this ).data( "startTouches" ),
startTouches = $( this ).mobileData( "startTouches" ),
deltaX = Math.abs(thisTouches.pageX - startTouches.pageX),
deltaY = Math.abs(thisTouches.pageY - startTouches.pageY);
if( deltaX > 10 || deltaY > 10 ){
$( this ).data( "moved", true );
$( this ).mobileData( "moved", true );
}
});
@ -313,7 +313,7 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
}
//find placeholder text
if( !this.getAttribute('value') || text.length == 0 || $this.data('placeholder') ){
if( !this.getAttribute('value') || text.length == 0 || $this.mobileData('placeholder') ){
if( o.hidePlaceholderMenuItems ){
classes.push( "ui-selectmenu-placeholder" );
}
@ -427,7 +427,7 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
//for webos (set lastscroll using button offset)
if( scrollTop == 0 && btnOffset > screenHeight ){
self.thisPage.one('pagehide',function(){
$(this).data('lastScroll', btnOffset);
$(this).mobileData('lastScroll', btnOffset);
});
}

View file

@ -70,7 +70,7 @@
var $this = $(this);
// unless the data url is already set set it to the id
if( !$this.data('url') ){
if( !$this.mobileData('url') ){
$this.attr( "data-" + $.mobile.ns + "url", $this.attr( "id" ) );
}
});

View file

@ -10,7 +10,7 @@ $.mobile.listview.prototype.options.filter = false;
$( "[data-" + $.mobile.ns + "role='listview']" ).live( "listviewcreate", function() {
var list = $( this ),
listview = list.data( "listview" );
listview = list.mobileData( "listview" );
if ( !listview.options.filter ) {
return;
}

View file

@ -121,7 +121,7 @@ $.widget( "mobile.listview", $.mobile.widget, {
_itemApply: function( $list, item ) {
// TODO class has to be defined in markup
item.find( ".ui-li-count" )
.addClass( "ui-btn-up-" + ($list.data( "counttheme" ) || this.options.countTheme) + " ui-btn-corner-all" );
.addClass( "ui-btn-up-" + ($list.mobileData( "counttheme" ) || this.options.countTheme) + " ui-btn-corner-all" );
item.find( "h1, h2, h3, h4, h5, h6" ).addClass( "ui-li-heading" );
@ -157,7 +157,7 @@ $.widget( "mobile.listview", $.mobile.widget, {
var o = this.options,
$list = this.element,
self = this,
dividertheme = $list.data( "dividertheme" ) || o.dividerTheme,
dividertheme = $list.mobileData( "dividertheme" ) || o.dividerTheme,
li = $list.children( "li" ),
counter = $.support.cssPseudoElement || !$.nodeName( $list[0], "ol" ) ? 0 : 1;
@ -178,12 +178,12 @@ $.widget( "mobile.listview", $.mobile.widget, {
return;
}
var itemTheme = item.data("theme") || o.theme;
var itemTheme = item.mobileData("theme") || o.theme;
var a = item.find( "a" );
if ( a.length ) {
var icon = item.data("icon");
var icon = item.mobileData("icon");
item
.buttonMarkup({
@ -201,7 +201,7 @@ $.widget( "mobile.listview", $.mobile.widget, {
itemClass += " ui-li-has-alt";
var last = a.last(),
splittheme = $list.data( "splittheme" ) || last.data( "theme" ) || o.splitTheme;
splittheme = $list.mobileData( "splittheme" ) || last.mobileData( "theme" ) || o.splitTheme;
last
.appendTo(item)
@ -221,11 +221,11 @@ $.widget( "mobile.listview", $.mobile.widget, {
corners: true,
theme: splittheme,
iconpos: "notext",
icon: $list.data( "spliticon" ) || last.data( "icon" ) || o.splitIcon
icon: $list.mobileData( "spliticon" ) || last.mobileData( "icon" ) || o.splitIcon
} ) );
}
} else if ( item.data( "role" ) === "list-divider" ) {
} else if ( item.mobileData( "role" ) === "list-divider" ) {
itemClass += " ui-li-divider ui-btn ui-bar-" + dividertheme;
item.attr( "role", "heading" );
@ -296,18 +296,18 @@ $.widget( "mobile.listview", $.mobile.widget, {
_createSubPages: function() {
var parentList = this.element,
parentPage = parentList.closest( ".ui-page" ),
parentId = parentPage.data( "url" ),
parentId = parentPage.mobileData( "url" ),
o = this.options,
self = this,
persistentFooterID = parentPage.find( "[data-" + $.mobile.ns + "role='footer']" ).data( "id" );
persistentFooterID = parentPage.find( "[data-" + $.mobile.ns + "role='footer']" ).mobileData( "id" );
$( parentList.find( "ul, ol" ).toArray().reverse() ).each(function( i ) {
var list = $( this ),
parent = list.parent(),
title = $.trim(parent.contents()[ 0 ].nodeValue) || parent.find('a:first').text(),
id = parentId + "&" + $.mobile.subPageUrlKey + "=" + self._idStringEscape(title + " " + i),
theme = list.data( "theme" ) || o.theme,
countTheme = list.data( "counttheme" ) || parentList.data( "counttheme" ) || o.countTheme,
theme = list.mobileData( "theme" ) || o.theme,
countTheme = list.mobileData( "counttheme" ) || parentList.mobileData( "counttheme" ) || o.countTheme,
newPage = list.wrap( "<div data-" + $.mobile.ns + "role='page'><div data-" + $.mobile.ns + "role='content'></div></div>" )
.parent()
.before( "<div data-" + $.mobile.ns + "role='header' data-" + $.mobile.ns + "theme='" + o.headerTheme + "'><div class='ui-title'>" + title + "</div></div>" )

View file

@ -363,11 +363,11 @@
if( from ){
//set as data for returning to that spot
from.data( "lastScroll", currScroll);
from.mobileData( "lastScroll", currScroll);
//trigger before show/hide events
from.data( "page" )._trigger( "beforehide", { nextPage: to } );
from.mobileData( "page" )._trigger( "beforehide", { nextPage: to } );
}
to.data( "page" )._trigger( "beforeshow", { prevPage: from || $("") } );
to.mobileData( "page" )._trigger( "beforeshow", { prevPage: from || $("") } );
function loadComplete(){
@ -386,16 +386,16 @@
removeActiveLinkClass();
//jump to top or prev scroll, sometimes on iOS the page has not rendered yet. I could only get by this with a setTimeout, but would like to avoid that.
$.mobile.silentScroll( to.data( "lastScroll" ) );
$.mobile.silentScroll( to.mobileData( "lastScroll" ) );
reFocus( to );
//trigger show/hide events
if( from ){
from.data( "page" )._trigger( "hide", null, { nextPage: to } );
from.mobileData( "page" )._trigger( "hide", null, { nextPage: to } );
}
//trigger pageshow, define prevPage as either from or empty jQuery obj
to.data( "page" )._trigger( "show", null, { prevPage: from || $("") } );
to.mobileData( "page" )._trigger( "show", null, { prevPage: from || $("") } );
//set "to" as activePage
$.mobile.activePage = to;
@ -464,7 +464,7 @@
function enhancePage(){
//set next page role, if defined
if ( nextPageRole || to.data('role') === 'dialog' ) {
if ( nextPageRole || to.mobileData('role') === 'dialog' ) {
url = urlHistory.getActive().url + dialogHashKey;
if(nextPageRole){
to.attr( "data-" + $.mobile.ns + "role", nextPageRole );
@ -684,11 +684,11 @@
}
else {
//use ajax
var transition = $this.data( "transition" ),
direction = $this.data("direction"),
var transition = $this.mobileData( "transition" ),
direction = $this.mobileData("direction"),
reverse = (direction && direction === "reverse") ||
// deprecated - remove by 1.0
$this.data( "back" );
$this.mobileData( "back" );
//this may need to be more specific as we use data-rel more
nextPageRole = $this.attr( "data-" + $.mobile.ns + "rel" );

View file

@ -42,7 +42,7 @@ $.widget( "mobile.page", $.mobile.widget, {
// classes so we'll handle page and content roles outside of the main role processing
// loop below.
$elem.find( "[data-" + $.mobile.ns + "role='page'], [data-" + $.mobile.ns + "role='content']" ).andSelf().each(function() {
$(this).addClass( "ui-" + $(this).data( $.mobile.ns + "role" ) );
$(this).addClass( "ui-" + $(this).mobileData( $.mobile.ns + "role" ) );
});
$elem.find( "[data-" + $.mobile.ns + "role='nojs']" ).addClass( "ui-nojs" );
@ -50,12 +50,12 @@ $.widget( "mobile.page", $.mobile.widget, {
// pre-find data els
var $dataEls = $elem.find( "[data-" + $.mobile.ns + "role]" ).andSelf().each(function() {
var $this = $( this ),
role = $this.data( "role" ),
theme = $this.data( "theme" );
role = $this.mobileData( "role" ),
theme = $this.mobileData( "theme" );
//apply theming and markup modifications to page,header,content,footer
if ( role === "header" || role === "footer" ) {
$this.addClass( "ui-bar-" + (theme || $this.parent( "[data-" + $.mobile.ns + "role='page']" ).data( "theme" ) || "a") );
$this.addClass( "ui-bar-" + (theme || $this.parent( "[data-" + $.mobile.ns + "role='page']" ).mobileData( "theme" ) || "a") );
// add ARIA role
$this.attr( "role", role === "header" ? "banner" : "contentinfo" );
@ -76,8 +76,8 @@ $.widget( "mobile.page", $.mobile.widget, {
// auto-add back btn on pages beyond first view
if ( o.addBackBtn && role === "header" &&
$( ".ui-page" ).length > 1 &&
$elem.data( "url" ) !== $.mobile.path.stripHash( location.hash ) &&
!leftbtn && $this.data( "backbtn" ) !== false ) {
$elem.mobileData( "url" ) !== $.mobile.path.stripHash( location.hash ) &&
!leftbtn && $this.mobileData( "backbtn" ) !== false ) {
$( "<a href='#' class='ui-btn-left' data-" + $.mobile.ns + "rel='back' data-" + $.mobile.ns + "icon='arrow-l'>"+ o.backBtnText +"</a>" ).prependTo( $this );
}