This repository has been archived by the owner on Oct 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleaned up some core app methods, and separated the demo and demo fil…
…es to make a more realistic example scenario
- Loading branch information
scottjehl
committed
Apr 10, 2012
1 parent
fe4a192
commit 65aa130
Showing
13 changed files
with
138 additions
and
79 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<!--[if (lt IE 8)]><html lang="en" class="ieOld"><![endif]--> | ||
<!--[if IE 8]><html lang="en" class="ie8"> <![endif]--> | ||
<!--[if (gte IE 9)|!(IE)]><!--><html lang="en"><!--<![endif]--> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Sample template</title> | ||
<link href="_demo/sample-files/general.css" rel="stylesheet" /> | ||
<script src="app.js,_demo/app.enhance.js=concat"></script> | ||
</head> | ||
<body class="tmpl-home"> | ||
<h1>This is a sample template.</h1> | ||
<p class="explain">It includes app.js and an example file: app.enhance.js, which uses app.js to determine whether - and which - files should be added to enhance this browser's experience.</p> | ||
<p class=""> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
app.enhance: this example file uses the app.js api to: | ||
* determine whether a browser is qualified for enhancements | ||
* define available CSS and JS assets | ||
* test features and device conditions and environment to determine which files to load | ||
* load those files via a single concatenated call | ||
*/ | ||
(function( win ){ | ||
|
||
//re-reference app var locally | ||
var app = win.app; | ||
|
||
// Add your qualifications for major browser experience divisions here. | ||
// For example, you might choose to only enhance browsers that support document.querySelectorAll (IE8+, etc). | ||
// Use case will vary, but basic browsers: last stop here! | ||
if( !"querySelectorAll" in win.document ){ | ||
return; | ||
} | ||
|
||
// Configure css and js paths, if desirable. | ||
app.basepath.js = app.basepath.css = "_demo/sample-files/"; | ||
|
||
// Define potential JS files for loading | ||
app.files.js = { | ||
general : "generalenhancements.js", | ||
touch : "touch.js", | ||
widescreen : "widescreen.js" | ||
}; | ||
|
||
// Define potential CSS files for loading | ||
app.files.css = { | ||
sample : "sample1.css" | ||
}; | ||
|
||
// Start queueing files for load. | ||
// Pass js or css paths one at a time to app.addFile | ||
|
||
// Add general js enhancements to all qualified browsers | ||
app.addFile( app.files.js.general ); | ||
|
||
// if touch events are supported, add touch file | ||
if( "ontouchend" in win.document ){ | ||
app.addFile( app.files.js.touch ); | ||
} | ||
|
||
// if screen is wider than 500px, add widescreen file | ||
if( screen.width > 500 ){ | ||
app.addFile( app.files.js.widescreen ); | ||
} | ||
|
||
// add a CSS file if the body has a class of "tmpl-home" | ||
// (beware: don't rely on loading CSS this way for styles that need to apply at page load or you'll get a FOUC) | ||
|
||
// Note: since we're using hasClass to check if the body element has a class or not, we need to wrap all remaining logic in a call to app.isDefined | ||
app.bodyready( function(){ | ||
|
||
if( app.hasClass( win.document.body, "tmpl-home" ) ){ | ||
app.addFile( app.files.css.sample ); | ||
} | ||
|
||
// Load the files, enhance page | ||
app.enhance(); | ||
|
||
}); | ||
|
||
}( window )); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
body { | ||
font-family: sans-serif; | ||
margin: 50px 30%; | ||
} | ||
.explain { | ||
border-bottom: 1px dotted #fff; | ||
padding-bottom: 2em; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// NOTE: the real contents of this file would actually do something useful. | ||
// for demo purposes, it logs a message to the page. | ||
var p = document.createElement( "p" ); | ||
p.innerHTML = "generalenhancements.js was loaded because it is meant for all enhanced browsers"; | ||
document.body.appendChild( p ); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
body { background: green; color: white; } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// NOTE: the real contents of this file would actually do something useful. | ||
// for demo purposes, it logs a message to the page. | ||
var p = document.createElement( "p" ); | ||
p.innerHTML = "generalenhancements.js was loaded because touch events are supported"; | ||
document.body.appendChild( p ); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// NOTE: the real contents of this file would actually do something useful. | ||
// for demo purposes, it logs a message to the page. | ||
var p = document.createElement( "p" ); | ||
p.innerHTML = "widescreen.js was loaded because the screen width is greater than 500px"; | ||
document.body.appendChild( p ); |
This file was deleted.
Oops, something went wrong.
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
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
This file was deleted.
Oops, something went wrong.