2010-10-15 01:56:51 +00:00
//set up the theme switcher on the homepage
2011-12-07 23:41:40 +00:00
define ( [ "jquery.mobile" ] , function ( ) {
2010-10-20 16:09:03 +00:00
$ ( 'div' ) . live ( 'pagecreate' , function ( event ) {
2011-11-22 21:16:04 +00:00
if ( ! $ ( this ) . is ( '.ui-dialog' ) ) {
2011-06-20 13:34:31 +00:00
var appendEl = $ ( this ) . find ( '.ui-footer:last' ) ;
2011-11-22 21:16:04 +00:00
2011-06-20 01:58:12 +00:00
if ( ! appendEl . length ) {
appendEl = $ ( this ) . find ( '.ui-content' ) ;
}
2011-11-22 21:16:04 +00:00
2011-06-20 22:23:09 +00:00
if ( appendEl . is ( "[data-position]" ) ) {
return ;
}
2011-11-22 21:16:04 +00:00
2011-02-20 18:46:23 +00:00
$ ( '<a href="#themeswitcher" data-' + $ . mobile . ns + 'rel="dialog" data-' + $ . mobile . ns + 'transition="pop">Switch theme</a>' )
2010-10-15 22:03:17 +00:00
. buttonMarkup ( {
'icon' : 'gear' ,
'inline' : true ,
'shadow' : false ,
'theme' : 'd'
} )
2011-06-20 01:58:12 +00:00
. appendTo ( appendEl )
2010-10-15 22:03:17 +00:00
. wrap ( '<div class="jqm-themeswitcher">' )
2011-06-20 13:34:31 +00:00
. bind ( "vclick" , function ( ) {
2010-10-15 22:03:17 +00:00
$ . themeswitcher ( ) ;
} ) ;
2011-11-22 21:16:04 +00:00
}
2011-06-20 22:23:09 +00:00
2011-06-20 01:58:12 +00:00
} ) ;
//collapse page navs after use
$ ( function ( ) {
2011-08-03 17:41:12 +00:00
$ ( 'body' ) . delegate ( '.content-secondary .ui-collapsible-content' , 'click' , function ( ) {
2011-11-19 19:29:20 +00:00
$ ( this ) . trigger ( "collapse" ) ;
2011-06-20 01:58:12 +00:00
} ) ;
2011-06-20 19:17:05 +00:00
} ) ;
function setDefaultTransition ( ) {
2011-06-20 22:23:09 +00:00
var winwidth = $ ( window ) . width ( ) ,
trans = "slide" ;
2011-11-22 21:16:04 +00:00
2011-06-20 22:23:09 +00:00
if ( winwidth >= 1000 ) {
trans = "none" ;
}
else if ( winwidth >= 650 ) {
trans = "fade" ;
}
$ . mobile . defaultPageTransition = trans ;
2011-06-20 19:17:05 +00:00
}
2011-08-02 22:22:55 +00:00
2011-06-20 19:17:05 +00:00
$ ( function ( ) {
2011-08-02 22:22:55 +00:00
setDefaultTransition ( ) ;
2011-06-20 19:17:05 +00:00
$ ( window ) . bind ( "throttledresize" , setDefaultTransition ) ;
2011-11-19 19:29:20 +00:00
} ) ;
2011-11-19 20:30:44 +00:00
// Turn off AJAX for local file browsing
2011-11-21 21:34:06 +00:00
if ( location . protocol . substr ( 0 , 4 ) === 'file' ||
location . protocol . substr ( 0 , 11 ) === '*-extension' ||
location . protocol . substr ( 0 , 6 ) === 'widget' ) {
2011-11-22 18:30:43 +00:00
// Start with links with only the trailing slash and that aren't external links
var fixLinks = function ( ) {
$ ( "a[href$='/'], a[href='.'], a[href='..']" ) . not ( "[rel='external']" ) . each ( function ( ) {
this . href = $ ( this ) . attr ( "href" ) . replace ( /\/$/ , "" ) + "/index.html" ;
} ) ;
} ;
// fix the links for the initial page
$ ( fixLinks ) ;
// fix the links for subsequent ajax page loads
$ ( document ) . bind ( 'pagecreate' , fixLinks ) ;
2011-11-21 21:34:06 +00:00
// Check to see if ajax can be used. This does a quick ajax request and blocks the page until its done
$ . ajax ( {
url : '.' ,
async : false ,
isLocal : true
} ) . error ( function ( ) {
// Ajax doesn't work so turn it off
$ ( document ) . bind ( "mobileinit" , function ( ) {
$ . mobile . ajaxEnabled = false ;
2011-11-22 03:01:12 +00:00
var message = $ ( '<div>' , {
2011-11-22 18:30:43 +00:00
'class' : "ui-footer ui-bar-e" ,
style : "overflow: auto; padding:10px 15px;" ,
'data-ajax-warning' : true
} ) ;
2011-11-22 03:01:12 +00:00
message
. append ( "<h3>Note: Navigation may not work if viewed locally</h3>" )
2011-11-22 21:16:04 +00:00
. append ( "<p>The AJAX-based navigation used throughout the jQuery Mobile docs may need to be viewed on a web server to work in certain browsers. If you see an error message when you click a link, try a different browser or <a href='https://github.com/jquery/jquery-mobile/wiki/Downloadable-Docs-Help'>view help</a>.</p>" ) ;
2011-11-22 03:01:12 +00:00
2011-11-22 18:30:43 +00:00
$ ( document ) . bind ( "pagecreate" , function ( event ) {
$ ( event . target ) . append ( message ) ;
2011-11-22 03:01:12 +00:00
} ) ;
2011-11-21 21:34:06 +00:00
} ) ;
2011-11-19 20:30:44 +00:00
} ) ;
}
2011-12-07 23:41:40 +00:00
} ) ;