jq-mobile で表示パネルを無効にするのに問題があります。
各ページが同じヘッダーとフッターを共有するテンプレート PHP を使用しているため、この質問の HTML バージョンを作成しました。
ヘッダーには、左または右のパネルを開く 2 つのボタンがあります。page1.html には 2 つのパネル (左右) があり、page2.html には 1 つのパネル (左) があります。
したがって、page2.html には右パネルがないため、page2.html ではヘッダーの右ボタン パネルを無効にする必要があります。
問題は、page1 を開いて左側のパネル メニューから page2 に移動すると、右側のパネルのヘッダー ボタンが無効にならないことです。page2.html にui-disableクラス スクリプトを具体的に追加しましたが、機能しません。
page2.html に直接アクセスすると、ボタンが無効になります。
ここにソースコード:
page1.html
<!DOCTYPE html>
<html>
<head>
<title>HOME</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
<script>
$( document ).on( "pageinit", "#index-page", function() {
$( document ).on( "swipeleft swiperight", "#index-page", function( e ) {
if ( $.mobile.activePage.jqmData( "panel" ) !== "open" ) {
if ( e.type === "swipeleft" ) {
$( "#index-page .right-panel" ).panel( "open" );
} else if ( e.type === "swiperight" ) {
$( "#index-page .left-panel" ).panel( "open" );
}
}
});
});
</script>
</head>
<body>
<div data-role="page" id="index-page" class="index-page">
<!--header-->
<div data-role="header" data-position="fixed">
<h1>HOME</h1>
<a id="show-left-panel" href="#left-panel" data-theme="b" data-icon="arrow-r" data-iconpos="notext" data-shadow="false" data-iconshadow="false" class="ui-icon-nodisc">Open left panel</a>
<a id="show-right-panel" href="#right-panel" data-theme="b" data-icon="arrow-l" data-iconpos="notext" data-shadow="false" data-iconshadow="false" class="ui-icon-nodisc">Open right panel</a>
</div><!--/header-->
<!-- content -->
<div data-role="content">
<ul data-role="listview">
<li data-role="list-divider"><h2>Latest News</h2></li>
<li><a href="#">
<h3>News 1</h3>
<p>News news news news news news news news news news news news news ...</p>
<p class="ui-li-aside">Fri, Feb 14th 2013</p>
</a></li>
<li><a href="#">
<h3>Dummy word example</h3>
<p>The quick brown fox jumps over the lazy doug blah blah The quick brown fox jumps over the lazy doug blah blah...</p>
<p class="ui-li-aside">Mon, Jan 14th 2013</p>
</a></li>
</ul>
</div><!-- /content -->
<!-- left-panel -->
<div data-role="panel" id="left-panel" class="left-panel" data-display="push">
<ul data-role="listview" data-count-theme="e">
<li data-icon="delete"><a href="#" data-rel="close">Close</a></li>
<li data-icon="info" data-iconpos="notext"><a href="page2.html">Page 2</a></li>
</ul>
</div><!-- /left-panel -->
<!-- right-panel -->
<div data-role="panel" id="right-panel" class="right-panel" data-display="overlay" data-position="right">
<ul data-role="listview" data-icon="false">
<li data-icon="delete"><a href="#" data-rel="close">Close</a></li>
<li data-role="list-divider">Submenu</li>
<li data-theme="e">Foo</li>
<li><a href="#">Bar</a></li>
</ul>
</div><!-- /right-panel -->
<!--footer-->
<div data-role="footer" data-position="fixed">
<h3>Copyright © 2013 Example.com</h3>
</div><!--/footer-->
</div>
</body>
</html>
page2.html
<!DOCTYPE html>
<html>
<head>
<title>HOME</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
<script>
$( document ).on( "pageinit", "#index-page", function() {
$( document ).on( "swipeleft swiperight", "#index-page", function( e ) {
if ( $.mobile.activePage.jqmData( "panel" ) !== "open" ) {
if ( e.type === "swipeleft" ) {
$( "#index-page .right-panel" ).panel( "open" );
} else if ( e.type === "swiperight" ) {
$( "#index-page .left-panel" ).panel( "open" );
}
}
});
$('#show-right-panel').addClass('ui-disabled'); //if I load page1.html first, than goes here, this line seems to have no effect?
});
</script>
</head>
<body>
<div data-role="page" id="index-page" class="index-page">
<!--header-->
<div data-role="header" data-position="fixed">
<h1>HOME</h1>
<a id="show-left-panel" href="#left-panel" data-theme="b" data-icon="arrow-r" data-iconpos="notext" data-shadow="false" data-iconshadow="false" class="ui-icon-nodisc">Open left panel</a>
<a id="show-right-panel" href="#right-panel" data-theme="b" data-icon="arrow-l" data-iconpos="notext" data-shadow="false" data-iconshadow="false" class="ui-icon-nodisc">Open right panel</a>
</div><!--/header-->
<!-- content -->
<div data-role="content">
<ul data-role="listview">
<li data-role="list-divider"><h2>Subpage</h2></li>
<li><a href="#">
<h3>SUb 1</h3>
<p>News news news news news news news news news news news news news ...</p>
<p class="ui-li-aside">Fri, Feb 14th 2013</p>
</a></li>
</ul>
</div><!-- /content -->
<!-- left-panel -->
<div data-role="panel" id="left-panel" class="left-panel" data-display="push">
<ul data-role="listview" data-count-theme="e">
<li data-icon="delete"><a href="#" data-rel="close">Close</a></li>
<li data-icon="info" data-iconpos="notext"><a href="page1.html">Page 1</a></li>
</ul>
</div><!-- /left-panel -->
<!--footer-->
<div data-role="footer" data-position="fixed">
<h3>Copyright © 2013 Example.com</h3>
</div><!--/footer-->
</div>
</body>
</html>