Permalink
Browse files

all in.

  • Loading branch information...
0 parents commit fe4a1925ca7982b9471c861c07e340103a3c0e86 scottjehl committed Apr 6, 2012
Showing with 241 additions and 0 deletions.
  1. +10 −0 .htaccess
  2. +12 −0 README.md
  3. +46 −0 _concat/quickconcat.php
  4. +115 −0 _js/_lib/app.js
  5. +43 −0 _js/app.enhance.js
  6. +15 −0 sample.html
@@ -0,0 +1,10 @@
+# Cleaner URLs for quickconcat.php
+# this allows for urls like this: "/path/to/file.html,path/to/fileb.html=concat"
+# or wrapped, "/path/to/file.html,path/to/fileb.html=concat&wrap"
+RewriteEngine On
+RewriteRule ^([^\?]+)=concat(&wrap)?$ _concat/quickconcat.php?files=$1$2
+
+# compress transfer
+<IfModule mod_deflate.c>
+AddOutputFilterByType DEFLATE text/html text/css text/javascript
+</IfModule>
@@ -0,0 +1,12 @@
+# app
+
+A progressive enhancement bootstrapping pattern.
+
+* Copyright 2012 @scottjehl, @beep, @wilto, @maggiewachs, Filament Group, Inc.
+* Licensed MIT/GPLv2
+
+## API
+
+TODO!
+
+...for now, check out `tmpl.html`, and `_js/_lib/app.js` and `_/js/app.enhance.js`
@@ -0,0 +1,46 @@
+<?php
+/*
+quickconcat: a simple dynamic concatenator for html, css, and js files
+ Copyright 2012, Scott Jehl, Filament Group, Inc. Dual licensed under MIT and GPLv2
+ * accepts 2 query strings:
+ * files (required): a comma-separated list of root-relative file paths
+ * wrap (optional): Enclose each result in an element node with url attribute? False by default.
+*/
+// List of files, comma-separated paths
+$filelist = $_REQUEST[ "files" ];
+// If needed, you can add a url prefix here for files, like "../"
+$baseurl = "../";
+
+// Enclose each result in an element node with url attribute?
+$wrap = isset( $_REQUEST[ "wrap" ] );
+
+// Get the filetype and array of files
+if ( ! isset( $filelist ) ){
+ echo '$files must be specified!';
+ exit;
+}
+
+$files = explode( ",", $filelist );
+
+// Guess file type
+$fext = preg_match( '/\.(js|html|css)$/', $files[ 0 ], $match );
+$ftype = $fext ? $match[ 1 ] : "html";
+$type = "text/" . ( $ftype === "js" ? "javascript" : $ftype );
+
+$contents = '';
+
+// Loop through the files adding them to a string
+foreach ( $files as $file ) {
+ if( preg_match( '/\.(js|html|css)$/', $file ) ){
+ $open = $wrap ? "<entry url=\"". $file . "\">" : "";
+ $close = $wrap ? "</entry>\n" : "";
+ $contents .= $open . file_get_contents($baseurl . $file). $close;
+ }
+}
+
+// Set the content type and filesize headers
+header('Content-Type: ' . $type);
+header('Content-Length: ' . strlen($contents));
+
+// Deliver the file
+echo $contents;
@@ -0,0 +1,115 @@
+/*! app: a progressive enhancement bootstrapper. Copyright 2012 @scottjehl, Filament Group, Inc. Licensed MIT/GPLv2 */
+(function( w, undefined ) {
+
+ // Enable JS strict mode
+ "use strict";
+
+ var doc = w.document,
+ docElem = doc.documentElement,
+ head = doc.head || doc.getElementsByTagName( "head" )[ 0 ];
+
+ //app object for app-specific functions
+ w.app = {};
+
+ // hasClass function - check if element has a class
+ app.hasClass = function( elem, cls ){
+ return elem.className.indexOf( cls ) >= -1
+ }
+
+ // IE browser flags, based on conditional comments
+ app.oldIE = app.hasClass( docElem, "ieOld" );
+ app.ie8 = app.hasClass( docElem, "ie8" );
+
+ // Callback for running body-element-dependent logic
+ app.bodyready = (function(){
+ var callbackStack = [],
+ checkRun = function( callback ){
+ if( callback ){
+ callbackStack.push( callback );
+ }
+ if( doc.body ){
+ while( callbackStack[0] && typeof( callbackStack[0] ) === "function" ){
+ callbackStack.shift().call( w );
+ }
+ }
+ else{
+ setTimeout(checkRun, 15);
+ }
+ };
+ return checkRun;
+ })();
+
+ //private style load function
+ function css( href, media ){
+ var lk = doc.createElement( "link" ),
+ links = head.getElementsByTagName( "link" ),
+ lastlink = links[ links.length-1 ];
+
+ lk.type = "text/css";
+ lk.href = href;
+ lk.rel = "stylesheet";
+
+ if( media ){
+ lk.media = media;
+ }
+ if( lastlink && lastlink.nextSibling ){
+ head.insertBefore(lk, lastlink.nextSibling );
+ }
+ else {
+ head.appendChild( lk );
+ }
+ };
+
+ // Private script load function
+ function js( src ){
+ var script = doc.createElement( "script" ),
+ fc = head.firstChild;
+ script.src = src;
+
+ if( fc ){
+ head.insertBefore(script, fc );
+ } else {
+ head.appendChild( script );
+ }
+ };
+
+ // Define base directory paths for referencing js, css, img files. Optional.
+ app.basepath = {
+ js : "",
+ css : ""
+ };
+
+ // Define arrays to contain JS and CSS files that are available
+ app.files = {
+ js: {},
+ css: {}
+ };
+
+ // Define arrays to contain JS and CSS files that will be loaded
+ app.jsToLoad = [];
+ app.cssToLoad = [];
+
+ // Function for adding files to the queue for loading.
+ // CSS or JS is discovered by file path.
+ // Files should not include base paths, if already defined in app.basepath.
+ app.addFile = function( file ){
+ var js = file.indexOf( ".js" ) > -1;
+ app[ js ? "jsToLoad" : "cssToLoad" ].push( app.basepath[ js ? "js" : "css" ] + file );
+ };
+
+ // CSS and JS loading functions: load CSS or JS via single app.load method
+ app.load = function ( url ){
+ return ( url.indexOf( ".js" ) > -1 ? js : css )( url );
+ };
+
+ // Function for triggering the CSS and JS requests
+ app.enhance = function(){
+ if( app.jsToLoad.length ){
+ app.load( app.jsToLoad.join(",") + "=concat" );
+ }
+ if( app.cssToLoad.length ){
+ app.load( app.cssToLoad.join(",") + "=concat" );
+ }
+ };
+
+}( this ));
@@ -0,0 +1,43 @@
+/*
+ app.enhance: this site-specific 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;
+
+ //basic browsers: last stop here!
+ if( !"querySelectorAll" in win.document ){
+ return;
+ }
+
+ // Configure css and js paths
+ app.basepath.js = "_js/";
+ app.basepath.css = "_css/";
+
+ // Define potential JS files for loading
+ app.files.js = {
+ //foo : "bar.js"
+ };
+
+ // Define potential CSS files for loading
+ app.files.css = {
+ //foo : "bar.css"
+ };
+
+ // Start queueing files for load.
+ // Pass js or css paths one at a time to app.addFile
+ // Example:
+ // app.addFile( app.files.js.foo );
+ // app.addFile( app.files.css.foo );
+
+ // Note: if you need to use hasClass to check if the body element has a class or not,
+ // wrap all remaining logic in a call to app.bodyready
+
+ // Load the files
+ app.enhance();
+
+}( window ));
@@ -0,0 +1,15 @@
+<!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>
+ <script src="_js/_lib/app.js,_js/app.enhance.js=concat"></script>
+ </head>
+ <body class="type-test type-test2">
+
+
+ </body>
+</html>

0 comments on commit fe4a192

Please sign in to comment.