Created
April 15, 2014 17:22
-
-
Save xirzec/10749694 to your computer and use it in GitHub Desktop.
Global Appbar Pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
"use strict"; | |
function doSearch() { | |
if (WinJS.Navigation.location !== '/pages/search/search.html') { | |
WinJS.Navigation.navigate('/pages/search/search.html'); | |
} | |
} | |
function doSignIn() { | |
Application.Auth.signIn(); | |
} | |
function doSignOut() { | |
Application.Auth.signOut(); | |
} | |
function updateLayout() { | |
var location = WinJS.Navigation.location; | |
var signedIn = Application.Auth.signedIn; | |
var appBar = document.getElementById("appbar").winControl; | |
var commands = []; | |
var page = Application.navigator.pageControl; | |
if (page.getCommands) { | |
commands = page.getCommands(signedIn); | |
} | |
if (commands.length === 0) { | |
appBar.disabled = true; | |
} else { | |
appBar.disabled = false; | |
} | |
appBar.showOnlyCommands(commands); | |
} | |
WinJS.Namespace.define("Application.AppBar", { | |
doSignIn: WinJS.Utilities.markSupportedForProcessing(doSignIn), | |
doSignOut: WinJS.Utilities.markSupportedForProcessing(doSignOut), | |
doSearch: WinJS.Utilities.markSupportedForProcessing(doSearch), | |
updateLayout: updateLayout | |
}); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>WinTube.WindowsPhone</title> | |
<!-- WinJS references --> | |
<!-- At runtime, ui-themed.css resolves to ui-themed.light.css or ui-themed.dark.css | |
based on the user’s theme setting. This is part of the MRT resource loading functionality. --> | |
<link href="/css/ui-themed.css" rel="stylesheet" /> | |
<script src="//Microsoft.Phone.WinJS.2.1/js/base.js"></script> | |
<script src="//Microsoft.Phone.WinJS.2.1/js/ui.js"></script> | |
<!-- WinTube references --> | |
<link href="/css/phone.css" rel="stylesheet" /> | |
<script src="/js/default.js"></script> | |
<!-- Shared references --> | |
<script src="/js/appbar.js"></script> | |
<script src="/js/auth.js"></script> | |
<script src="/js/navigator.js"></script> | |
<script src="/js/binding.js"></script> | |
<script src="/js/util.js"></script> | |
</head> | |
<body class="phone"> | |
<div id="contenthost" data-win-control="Application.PageControlNavigator" data-win-options="{home: '/pages/home/home.html'}"></div> | |
<div id="appbar" data-win-control="WinJS.UI.AppBar" data-win-options="{}"> <!-- closedDisplayMode: 'minimal' --> | |
<button data-win-control="WinJS.UI.AppBarCommand" data-win-options="{id:'search', label:'Search', icon:'find', onclick: Application.AppBar.doSearch }" type="button"></button> | |
<button data-win-control="WinJS.UI.AppBarCommand" data-win-options="{id:'signIn', label:'Sign In', section: 'selection', onclick: Application.AppBar.doSignIn }" type="button"></button> | |
<button data-win-control="WinJS.UI.AppBarCommand" data-win-options="{id:'signOut', label:'Sign Out', section: 'selection', onclick: Application.AppBar.doSignOut }" type="button"></button> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
"use strict"; | |
WinJS.UI.Pages.define("/pages/home/home.html", { | |
ready: function (element, options) { | |
this.pivot = element.querySelector('.hub').winControl; | |
this.pivot.onselectionchanged = (function () { | |
this.updateLayout(element); | |
}).bind(this); | |
}, | |
updateLayout: function (element) { | |
var activePage = this.pivot.selectedItem.contentElement.querySelector('.pagecontrol'); | |
if (activePage) { | |
var pageControl = activePage.winControl; | |
pageControl.updateLayout(activePage); | |
} | |
}, | |
getCommands: function (signedIn) { | |
return ['search']; | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment