1+ //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2+ //>>description: Browser specific workarounds for "fixed" headers and footers
3+ //>>label: Toolbars: Fixed: Workarounds
4+ //>>group: Widgets
5+ //>>css.structure: ../css/structure/jquery.mobile.fixedToolbar.css
6+ define ( [ "jquery" , "../jquery.mobile.widget" , "../jquery.mobile.core" , "../jquery.mobile.navigation" , "./page" , "./page.sections" , "../jquery.mobile.zoom" , "./fixedToolbar" ] , function ( $ ) {
7+ //>>excludeEnd("jqmBuildExclude");
8+ ( function ( $ , undefined ) {
9+ $ . widget ( "mobile.fixedtoolbar" , $ . mobile . fixedtoolbar , {
10+
11+ _create : function ( ) {
12+ this . _super ( ) ;
13+ this . _workarounds ( ) ;
14+ } ,
15+
16+ //check the browser and version and run needed workarounds
17+ _workarounds : function ( ) {
18+ var ua = navigator . userAgent ,
19+ platform = navigator . platform ,
20+ // Rendering engine is Webkit, and capture major version
21+ wkmatch = ua . match ( / A p p l e W e b K i t \/ ( [ 0 - 9 ] + ) / ) ,
22+ wkversion = ! ! wkmatch && wkmatch [ 1 ] ,
23+ os = null ,
24+ self = this ;
25+ //set the os we are working in if it dosent match one with workarounds return
26+ if ( platform . indexOf ( "iPhone" ) > - 1 || platform . indexOf ( "iPad" ) > - 1 || platform . indexOf ( "iPod" ) > - 1 ) {
27+ os = "ios" ;
28+ } else if ( ua . indexOf ( "Android" ) > - 1 ) {
29+ os = "android" ;
30+ } else {
31+ return
32+ }
33+ //check os version if it dosent match one with workarounds return
34+ if ( os === "ios" && wkversion && wkversion > 533 && wkversion < 536 ) {
35+ //iOS 5 run all workarounds for iOS 5
36+ self . _bindScrollWorkaround ( ) ;
37+ } else if ( os === "android" && wkversion && wkversion < 534 ) {
38+ //Android 2.3 run all Android 2.3 workaround
39+ self . _bindScrollWorkaround ( ) ;
40+ self . _bindListThumbWorkaround ( ) ;
41+ } else {
42+ return
43+ }
44+ } ,
45+
46+ //Utility class for checking header and footer positions relative to viewport
47+ _viewportOffset : function ( ) {
48+ var $el = this . element ,
49+ header = $el . is ( ".ui-header" ) ,
50+ offset = Math . abs ( $el . offset ( ) . top - $ ( window ) . scrollTop ( ) ) ;
51+ if ( ! header ) {
52+ offset = Math . round ( offset - $ ( window ) . height ( ) + $el . outerHeight ( ) ) - 60 ;
53+ }
54+ return offset ;
55+ } ,
56+
57+ //bind events for _triggerRedraw() function
58+ _bindScrollWorkaround : function ( ) {
59+ var self = this ;
60+ //bind to scrollstop and check if the toolbars are correctly positioned
61+ this . _on ( $ ( window ) , { scrollstop : function ( ) {
62+ var viewportOffset = self . _viewportOffset ( ) ;
63+ //check if the header is visible and if its in the right place
64+ if ( viewportOffset > 2 && self . _visible ) {
65+ self . _triggerRedraw ( ) ;
66+ }
67+ } } ) ;
68+ } ,
69+
70+ //this addresses issue #4250 Persistent footer instability in v1.1 with long select lists in Android 2.3.3
71+ //and issue #3748 Android 2.x: Page transitions broken when fixed toolbars used
72+ //the absolutely positioned thumbnail in a list view causes problems with fixed position buttons above in a nav bar
73+ //setting the li's to -webkit-transform:translate3d(0,0,0); solves this problem to avoide potential issues in other
74+ //platforms we scope this with the class ui-android-2x-fix
75+ _bindListThumbWorkaround : function ( ) {
76+ this . element . closest ( ".ui-page" ) . addClass ( "ui-android-2x-fixed" ) ;
77+ } ,
78+ //this addresses issues #4337 Fixed header problem after scrolling content on iOS and Android
79+ //and device bugs project issue #1 Form elements can lose click hit area in position: fixed containers.
80+ //this also addresses not on fixed toolbars page in docs
81+ //adding 1px of padding to the bottom then removing it causes a "redraw"
82+ //which positions the toolbars correctly (they will always be visually correct)
83+ _triggerRedraw : function ( ) {
84+ var paddingBottom = parseFloat ( $ ( ".ui-page-active" ) . css ( "padding-bottom" ) ) ;
85+ //trigger page redraw to fix incorrectly positioned fixed elements
86+ $ ( ".ui-page-active" ) . css ( "padding-bottom" , ( paddingBottom + 1 ) + "px" ) ;
87+ //if the padding is reset with out a timeout the reposition will not occure.
88+ //this is independant of JQM the browser seems to need the time to react.
89+ setTimeout ( function ( ) {
90+ $ ( ".ui-page-active" ) . css ( "padding-bottom" , paddingBottom + "px" ) ;
91+ } , 0 ) ;
92+ } ,
93+
94+ destroy : function ( ) {
95+ this . _super ( ) ;
96+ //Remove the class we added to the page previously in android 2.x
97+ this . element . closest ( ".ui-page-active" ) . removeClass ( "ui-android-2x-fix" ) ;
98+ }
99+ } ) ;
100+
101+ } ) ( jQuery ) ;
102+ //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
103+ } ) ;
104+ //>>excludeEnd("jqmBuildExclude");
0 commit comments