mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-03-16 22:10:25 +00:00
Split support tests into jQuery.mobile.support.js and refactored tests.
This commit is contained in:
parent
f584e3385f
commit
aee5e02740
3 changed files with 54 additions and 65 deletions
|
|
@ -33,71 +33,6 @@
|
|||
maxSwipeTime = 1000,
|
||||
minSwipeXDistance = 180,
|
||||
maxSwipeYtolerance = 80;
|
||||
|
||||
/*
|
||||
add some properties to $.support
|
||||
- Notes:
|
||||
- add $.support.scrollTop ?
|
||||
- CSS matrix support needed?
|
||||
*/
|
||||
$.support.orientation = !!window.orientation;
|
||||
|
||||
/* Some CSS capability tests from EnhanceJS -- in the vein of $.support.boxmodel -- almost certainly needed for widgets to work
|
||||
*/
|
||||
//test CSS display none
|
||||
$.support.display = (function(){
|
||||
var fakeBody = $('<body></body>').prependTo($html),
|
||||
testDiv = $('<div style="height: 5px; position: absolute; display: none;"></div>').prependTo(fakeBody),
|
||||
divHeight = testDiv[0].offsetHeight; //note: jQuery .height() returned "5"
|
||||
fakeBody.remove();
|
||||
return divHeight === 0;
|
||||
})();
|
||||
|
||||
//test CSS absolute positioning
|
||||
$.support.position = (function(){
|
||||
var fakeBody = $('<body></body>').prependTo($html),
|
||||
testDiv = $('<div style="position: absolute; left: 10px;"></div>').prependTo(fakeBody),
|
||||
divLeft = testDiv[0].offsetLeft;
|
||||
fakeBody.remove();
|
||||
return divLeft === 10;
|
||||
})();
|
||||
|
||||
//test CSS overflow (used in widgets for clearfix, hiding, etc)
|
||||
$.support.overflow = (function(){
|
||||
var fakeBody = $('<body></body>').prependTo($html),
|
||||
testDiv = $('<div style="position: absolute; overflow: hidden; height: 0;"><div style="height: 10px;"></div></div>').prependTo(fakeBody),
|
||||
divHeight = testDiv[0].offsetHeight;
|
||||
fakeBody.remove();
|
||||
return divHeight === 0;
|
||||
})();
|
||||
|
||||
//test CSS float,clear
|
||||
$.support.floatclear = (function(){
|
||||
var fakeBody = $('<body></body>').prependTo($html),
|
||||
pass = false,
|
||||
innerStyle = 'style="width: 5px; height: 5px; float: left;"',
|
||||
testDiv = $('<div><div ' + innerStyle + '></div><div ' + innerStyle + '></div></div>').prependTo(fakeBody),
|
||||
kids = testDiv[0].childNodes,
|
||||
topA = kids[0].offsetTop,
|
||||
divB = kids[1],
|
||||
topB = divB.offsetTop;
|
||||
if (topA === topB) {
|
||||
divB.style.clear = 'left';
|
||||
topB = divB.offsetTop;
|
||||
if (topA !== topB) {
|
||||
pass = true;
|
||||
}
|
||||
}
|
||||
fakeBody.remove();
|
||||
return pass;
|
||||
})();
|
||||
|
||||
//right about here, we *could* make sure all of the above css support props are true, if not, return and leave the page usable fercryin'outloud
|
||||
if(!$.support.display || !$.support.position || !$.support.overflow || !$.support.floatclear ) { return; }
|
||||
|
||||
//support properties from jQtouch
|
||||
$.support.touch = (typeof Touch == "object");
|
||||
$.support.WebKitAnimationEvent = (typeof WebKitTransitionEvent == "object");
|
||||
|
||||
/*
|
||||
add some core behavior,events
|
||||
|
|
|
|||
53
js/jQuery.mobile.support.js
Normal file
53
js/jQuery.mobile.support.js
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
Possible additions:
|
||||
scollTop
|
||||
CSS Matrix
|
||||
*/
|
||||
|
||||
$.extend( $.support, {
|
||||
orientation: !!window.orientation,
|
||||
// to use bbq-style navigation with external pages
|
||||
// we will need to first test for ajax support (and fall back to normal urls)
|
||||
ajax: !!$.ajaxSettings.xhr(),
|
||||
touch: typeof Touch === "object",
|
||||
WebKitAnimationEvent: typeof WebKitTransitionEvent === "object"
|
||||
});
|
||||
|
||||
(function() {
|
||||
var fakeBody = $( "<body>" ).prependTo( "html" ),
|
||||
displayDiv = $( "<div style='height: 5px; position: absolute; display: none;'></div>" )
|
||||
.prependTo( fakeBody ),
|
||||
positionDiv = $( "<div style='position: absolute; left: 10px;'></div>" )
|
||||
.prependTo( fakeBody ),
|
||||
overflowDiv = $( "<div style='position: absolute; overflow: hidden; height: 0;'>" +
|
||||
"<div style='height: 10px;'></div></div>" ).prependTo( fakeBody ),
|
||||
floatClearHtml = "<div style='width:5px;height:5px;float:left;'></div>",
|
||||
floatClearWrap = $( "<div>" )
|
||||
.append( floatClearHtml + floatClearHtml )
|
||||
.prependTo( fakeBody ),
|
||||
floatClearDivs = floatClearWrap.children(),
|
||||
floatClearDiv1Top = floatClearDivs[ 0 ].offsetTop,
|
||||
floatClearDiv2 = floatClearDivs[ 1 ],
|
||||
supportFloatClear = false;
|
||||
|
||||
if ( floatClearDiv1Top === floatClearDiv2.offsetTop ) {
|
||||
floatClearDiv2.style.clear = "left";
|
||||
if ( floatClearDiv1Top !== floatClearDiv2.offsetTop ) {
|
||||
supportFloatClear = true;
|
||||
}
|
||||
}
|
||||
|
||||
$.extend( $.support, {
|
||||
display: displayDiv[ 0 ].offsetHeight === 0,
|
||||
position: positionDiv[ 0 ].offsetLeft === 10,
|
||||
overflow: overflowDiv[ 0 ].offsetHeight === 0,
|
||||
floatclear: supportFloatClear
|
||||
});
|
||||
|
||||
fakeBody.remove();
|
||||
})();
|
||||
|
||||
// if we're missing support for any of these, then we're a C-grade browser
|
||||
if ( !$.support.display || !$.support.position || !$.support.overflow || !$.support.floatclear ) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -16,6 +16,7 @@ $elements = array(
|
|||
'jQuery.tabs.js',
|
||||
'jQuery.tree.js',
|
||||
'jQuery.globalnav.js',
|
||||
'jQuery.mobile.support.js',
|
||||
'jQuery.mobile.js'
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue