Skip to content

Instantly share code, notes, and snippets.

@FlorianX
FlorianX / gist:1240428
Created September 25, 2011 09:50
.changePage() changes page, but reloads previous page for a second
<script>
$(document).ready(function(){
$("#pageone").bind("swipeleft", function(event,ui){
$.mobile.changePage($("#pagetwo"));
})
$("#pagetwo").bind("swiperight", function(event,ui){
$.mobile.changePage($("#pageone"));
})
});
@FlorianX
FlorianX / gist:1263865
Created October 5, 2011 07:37
Android Activity
// create a webView
WebView webView = (WebView)findViewById(R.id.webView);
// enable some settings
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
// use the WebChromeClient
webView.setWebChromeClient(new WebChromeClient());
@FlorianX
FlorianX / gist:1263870
Created October 5, 2011 07:39
Die eigentliche App
<!DOCTYPE html>
<html>
<head>
<title>Spirit HTML5 App</title>
<meta charset="utf-8"/>
<!-- Import the libraries -->
<link rel="stylesheet" href="jquery.mobile.min.css" />
<script src="jquery.min.js"></script>
<script src="jquery.mobile.min.js"></script>
<script src="textile.js"></script>
@FlorianX
FlorianX / gist:1263874
Created October 5, 2011 07:40
Die erste page
<div data-role="page" data-theme="b">
<button data-role="button" data-icon="refresh"
onclick="getNews(true);" data-theme="b">Update!</button>
<div data-role="content" id="content"></div><!-- /content -->
</div><!-- /page -->
@FlorianX
FlorianX / gist:1263875
Created October 5, 2011 07:41
document ready
// if the page ist loaded call getNews()
$(document).ready(function(){
getNews();
});
@FlorianX
FlorianX / gist:1263876
Created October 5, 2011 07:42
Daten aus dem Storage holen
// check if localStorage is available
if(typeof localStorage !== 'undefined'){
// get the saved data if it's available
var localNewsJSON = localStorage.getItem('SpiritNews');
}
@FlorianX
FlorianX / gist:1263878
Created October 5, 2011 07:43
der Request
// check if there is data from the localStorage and
// whether the data must be fetched live
if(localNewsJSON && !live){
// call renderNews with the data from the localStorage
renderNews(JSON.parse(localNewsJSON));
}else{
// fetch the news from the REST interface of the news plattform
$.ajax({
url: "http://spirit.fh-schmalkalden.de/news",
dataType: 'json',
@FlorianX
FlorianX / gist:1263882
Created October 5, 2011 07:44
check if localStorage API is available?
if(typeof localStorage !== 'undefined')
@FlorianX
FlorianX / gist:1263885
Created October 5, 2011 07:45
getItem from localStorage
var localNewsJSON = localStorage.getItem('SpiritNews');
@FlorianX
FlorianX / gist:1263889
Created October 5, 2011 07:45
setItem to localStorage
localStorage.setItem('SpiritNews', JSON.stringify(data));