-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.mobile.fixedToolbar.polyfill.js
92 lines (71 loc) · 2.98 KB
/
jquery.mobile.fixedToolbar.polyfill.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*!
jQuery Mobile fixedtoolbar polyfill for blacklisted browsers that don't natively support position:fixed
Author @scottjehl
Copyright 2012 Filament Group, Inc.
License Dual MIT or GPLv2
*/
(function( $, undefined ) {
// If the supportBlacklist is returning true, it's a blacklisted browser.
if( $.mobile.fixedtoolbar.prototype.options.supportBlacklist() && $.support.scrollTop ){
// Keep a reference to the original _create method
var oldcreate = $.mobile.fixedtoolbar.prototype._create,
// Additional scripting to add to the _create method for polyfilling unsupported browsers
createPolyfill = function(){
if( this.options.polyfillSupport === true ){
var toolbar = this.element,
tbType = toolbar.hasClass( "ui-header-fixed") ? "header" : "footer",
page = toolbar.closest( ":jqmData(role='page')" );
// Add faux support class to toolbar
toolbar.addClass( "ui-fixed-faux" );
// set up a function that resets the top or bottom value, depending on toolbar type
var resetPos = (function(){
if( tbType === "header" ){
return function(){
toolbar.css( "top", $( window ).scrollTop() + "px" );
};
}
else {
return function(){
toolbar.css( "bottom", $(document).outerHeight() - $( window).scrollTop() - $.mobile.getScreenHeight() + "px" );
}
}
})();
$.mobile.fixedtoolbar.prototype.updatePosition = resetPos;
// Per page show, re-set up the event handling
page.bind( "pagebeforeshow", function( e ){
var visible;
// Normalize proper object for scroll event
( ( $( document ).scrollTop() === 0 ) ? $( window ) : $( document ) )
.bind( "scrollstart.fixedtoolbarpolyfill", function(){
visible = toolbar.not( ".ui-fixed-hidden" ).fixedtoolbar( "hide", true );
})
.bind( "scrollstop.fixedtoolbarpolyfill", function(){
resetPos();
visible.fixedtoolbar( "show" );
});
// on resize, reset positioning
$( window ).bind( "throttledresize.fixedtoolbarpolyfill", resetPos );
// on pagehide, unbind the event handlers
page.one( "pagehide", function(){
$( this ).add( this ).add( document ).unbind( ".fixedtoolbarpolyfill" );
});
// align for pageshow
resetPos();
});
}
};
// Set the blacklist test return false, letting any normally-blacklisted browsers in to be polyfilled
$.mobile.fixedtoolbar.prototype.options.supportBlacklist = function(){
return false;
};
// Define a new option for polyfillSupport, which can be disabled per call or via data attr data-polyfill-support
$.mobile.fixedtoolbar.prototype.options.polyfillSupport = true;
// Overwrite the _create method with the old and the new
$.mobile.fixedtoolbar.prototype._create = function(){
// Call the old _create method.
oldcreate.call( this );
// Call the polyfill scripting
createPolyfill.call( this );
};
}
})( jQuery );