Skip to content

Instantly share code, notes, and snippets.

@gavinblair
Created June 11, 2010 20:42
Show Gist options
  • Select an option

  • Save gavinblair/435011 to your computer and use it in GitHub Desktop.

Select an option

Save gavinblair/435011 to your computer and use it in GitHub Desktop.
var jQT = new $.jQTouch({
'icon': '/presentation/libraries/jqtouch/themes/mytheme/img/icon.png',
addGlossToIcon: true,
startupScreen: '/presentation/libraries/jqtouch/themes/mytheme/img/startup.png',
statusBar: 'black',
preloadImage: [
//...
],
useFastTouch: false //allows us to do $().submit() on forms
});
$(document).ready(function(){
$("a").each(function(){
//Replace "?t=" with "#" in all <a>'s
//This means that mobile devices with DOM manipulation allowed
//will make use of jQTouch's animations and one-page traversal
//of <div>'s.
//Browsers that don't allow DOM manipulation will link to
//this page with $_GET['t'], allowing us to display a specific
//<div> (by setting the 'current' CSS class)
$(this).attr("href",$(this).attr("href").replace("\?t\=", "#"));
});
$("form#myform").submit(function(){
//Ajax form submission.
//The trick is to use the same function in 'functions.php'
//to process the form, whether it's ajax or non-ajax.
$.ajax(
url: 'functions.php',
data: 'ajax=true&...'
//...
);
return false;
});
});
<?php
include 'functions.php';
if($_POST['myfield']) {
//non-ajax for submission
do_something($_POST);
}
?><!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>My Site</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;"/>
<style type="text/css" media="screen">@import "/presentation/libraries/jqtouch/jqtouch/jqtouch.css";</style>
<style type="text/css" media="screen">@import "/presentation/libraries/jqtouch/themes/mytheme/theme.css";</style>
<script src="/presentation/libraries/jquery-1.4.2.min.js" type="application/x-javascript" charset="utf-8"></script>
<script src="/presentation/libraries/jqtouch/jqtouch/jqtouch.js" type="application/x-javascript" charset="utf-8"></script>
<script src="/presentation/mobile.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<?php
//default: Main Menu page
if(!isset($_GET['t'])) { $_GET['t'] = "menu"; }
//Define the Pages
//The content here would obviously have to come from the database
$pages = array(
0 => array(
'slug' => 'menu',
'section' => 'My Website',
'title' => 'Main Menu',
'content' => "Welcome to My Website."
'links' => array(
0 => array(
'slug' => 'about_us',
'title' => 'About My Site'
),
1 => array(
'slug' => 'news',
'title' => "What's New"
),
2 => array(
'slug' => 'blog_listing',
'title' => 'My Blog'
)
)
),
1 => array(
'parent' => 'menu',
'slug' => 'about_us',
'section' => 'My Website',
'title' => 'About My Site',
'content' => '...'
),
2 => array(
'parent' => 'menu',
'slug' => 'news',
'section' => 'News',
'title' => "What's New",
'links' => array(
0 => array(
'slug' => 'news_item_1',
'title' => 'News Item One'
),
1 => array(
'slug' => 'news_item_2',
'title' => 'News Item Two'
),
2 => array(
'slug' => 'news_item_3',
'title' => 'News Item Three'
),
3 => array(
'slug' => 'news_item_4',
'title' => 'News Item Four'
)
)
),
3 => array(
'parent' => 'news',
'slug' => 'news_item_1',
'section' => 'News',
'title' => 'News Item One',
'content' => "..."
),
4 => array(
'parent' => 'news',
'slug' => 'news_item_2',
'section' => 'News',
'title' => 'News Item Two',
'content' => "..."
),
5 => array(
'parent' => 'news',
'slug' => 'news_item_3',
'section' => 'News',
'title' => 'News Item Three',
'content' => "..."
),
6 => array(
'parent' => 'news',
'slug' => 'news_item_4',
'section' => 'News',
'title' => 'News Item Four',
'content' => "..."
),
7 => array(
'parent' => 'menu',
'slug' => 'blog_listing',
'section' => 'Blog',
'title' => 'My Blog',
'links' => array(
0 => array(
'slug' => 'blog_item_1',
'title' => 'Blog Item One'
),
1 => array(
'slug' => 'blog_item_2',
'title' => 'Blog Item Two'
),
2 => array(
'slug' => 'blog_item_3',
'title' => 'Blog Item Three'
),
3 => array(
'slug' => 'blog_item_4',
'title' => 'Blog Item Four'
)
)
),
8 => array(
'parent' => 'blog_listing',
'slug' => 'blog_item_1',
'section' => 'Blog',
'title' => 'Blog Item One',
'content' => "..."
),
9 => array(
'parent' => 'blog_listing',
'slug' => 'blog_item_2',
'section' => 'Blog',
'title' => 'Blog Item Two',
'content' => "..."
),
10 => array(
'parent' => 'blog_listing',
'slug' => 'blog_item_3',
'section' => 'Blog',
'title' => 'Blog Item Three',
'content' => "..."
),
11 => array(
'parent' => 'blog_listing',
'slug' => 'blog_item_4',
'section' => 'Blog',
'title' => 'Blog Item Four',
'content' => "..."
)
);
?>
<?php foreach($pages as $page) { ?>
<div id="<?php echo $page['slug']; ?>" <?php echo $user->uid && $_GET['t'] == $page['slug'] ? "class='current'" : ""; ?>>
<div class="toolbar">
<h1><?php echo $page['section']; ?></h1>
<?php if(isset($page['parent'])) { ?>
<a href="?t=<?php echo $page['parent']; ?>" class="back">Back</a>
<?php } else { ?>
<a id="logout" href="/logout" class="button">Logout</a>
<?php } ?>
</div>
<h2><?php echo $page['title']; ?></h2>
<?php if(isset($page['content'])) { ?>
<?php if(is_array($page['content'])) { ?>
<ul>
<?php foreach($page['content'] as $content) { ?>
<li><?php echo $content; ?></li>
<?php } ?>
</ul>
<?php } else { ?>
<?php echo $page['content']; ?>
<?php } ?>
<?php } ?>
<?php if(isset($page['links'])) { ?>
<ul>
<?php foreach($page['links'] as $link) { ?>
<li><a href="?t=<?php echo $link['slug']; ?>"><?php echo $link['title']; ?></a></li>
<?php } ?>
</ul>
<?php } ?>
</div>
<?php } ?>
</body>
</html>
@SeanJA
Copy link
Copy Markdown

SeanJA commented Jun 13, 2010

What the what now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment