summaryrefslogtreecommitdiffstats
path: root/jqmobile.js
blob: 2cbd0965ef9b9b21e2d4808b98cb7799a0b23183 (plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* 
 * needs cleaning 
*/

//collapse page navs after use
/*
$(function(){
    $('body').delegate('.content-secondary .ui-collapsible-content', 'click',  function(){
        $(this).trigger("collapse");
    });
});
*/

// Listen for any attempts to call changePage().
$(document).bind( "pagebeforechange", function( e, data ) {

      var commandresult = $( "#content .command-results" );
      var descr =  $( "#content p.descr" );
      var error =  $( "#content p.error" );
      var commandpage = $( "#infopage .content" );
      var showinfopage = false;

      if(commandresult.length > 0) {
	commandresult.hide();
	commandpage.html( commandresult.html() );
	commandresult.remove();
	var showinfopage = true;
      }
      
      if(descr.length > 0) {
	descr.hide();
	commandpage.html( descr.html() );
	descr.remove();
	var showinfopage = true;
      }

      if(error.length > 0) {
	error.hide();
	commandpage.html( error.html() );
	error.remove();
	var showinfopage = true;
      }
        
      if(showinfopage) {
	e.preventDefault();
	$.mobile.changePage( "#infopage", {
	  transition: "pop"
	});
      }
      var section4 = $( "div.section4" );
      section4.attr({
	'data-role': 'collapsible',
	'data-mini': 'true',
	'data-collapsed': 'false',
	'data-content-theme': 'c'
      });
      var alink = $( "dd a" );
      alink.attr({
	'data-role': 'button',
	'data-mini': 'true',
	'data-theme': 'c',
	'data-inline': 'true',
	'data-iconpos': 'left',
	'data-icon': 'gear'
      });
      var inputsubmit = $( "#page input[type='submit']" );
      inputsubmit.attr({
	'data-role': 'button',
	'data-mini': 'false',
	//'data-iconpos': 'left',
	'data-theme': 'd',
	'data-inline': 'false'
      });
      var tdalink = $( "td .a" );
      tdalink.attr({
	'data-role': 'button',
	'data-mini': 'true',
	//'data-iconpos': 'left',
	'data-theme': 'c',
	'data-inline': 'true'
      });

  
});


// display the version of ACF
$(document).bind( 'pagecreate', function() {
    var version = $.mobile.version || "dev",
        words = version.split( "-" ),
        ver = words[0],
        //str = (words[1] || "Final"),
                str = (words[1] || ""),
        //html = 'Acf - ' + ver;
                html = 'Acf - 0.16.0';

    if( str.indexOf( "rc" ) == -1 ){
        str = str.charAt( 0 ).toUpperCase() + str.slice( 1 );
    } else {
        str = str.toUpperCase().replace(".", "");
    }

    if ( $.mobile.version && str ) {
        html += " <b>" + str + "</b>";
    }

    $( "p.acf-version" ).html( html );

    $.mobile.ajaxEnabled = false;
      
});



// Turn off AJAX for local file browsing
if ( location.protocol.substr(0,4)  === 'file' ||
     location.protocol.substr(0,11) === '*-extension' ||
     location.protocol.substr(0,6)  === 'widget' ) {

  // 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 );

  // 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;

      var message = $( '<div>' , {
        'class': "ui-footer ui-bar-e",
        style: "overflow: auto; padding:10px 15px;",
        'data-ajax-warning': true
      });
      message
        .append( "<h3>Note: Navigation may not work if viewed locally</h3>" )
        .append( "<p>The AJAX-based navigation used throughout the ACF jqMobile skin 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.</p>" );
      $( document ).bind( "pagecreate", function( event ) {
        $( event.target ).append( message );
      });
      
    });
  });
}