This repository has been archived by the owner on Mar 13, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chris Wallace
committed
May 20, 2016
1 parent
5a4422b
commit 4ec66ef
Showing
36 changed files
with
9,690 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
<?php | ||
/** | ||
* Browser Sync Module | ||
* | ||
* Enables the Browser Sync grunt module for local WordPress | ||
* development environments. Allows developers to sync their | ||
* CSS changes across connected clients over WI-FI networks. | ||
*/ | ||
|
||
|
||
/* | ||
* Wrap everything in a class for namespacing | ||
*/ | ||
class browser_sync_localhost { | ||
|
||
/* | ||
* define variables and call setup method from init | ||
*/ | ||
public static function init() { | ||
|
||
//if DEVENV isn't defined in wp-config.php, bail | ||
if( !defined('DEVENV') || DEVENV !== true ){ | ||
return; | ||
} | ||
|
||
//run plugin setup after plugins/themes are loaded | ||
add_action('after_setup_theme', array(__CLASS__, 'setup')); | ||
|
||
//Set Time Zone | ||
date_default_timezone_set('America/Chicago'); | ||
|
||
}//end init method | ||
|
||
/* | ||
* actions/hooks in setup, after plugins/themes are loaded | ||
*/ | ||
public static function setup() { | ||
|
||
//add Browser Sync JS to footer if on localhost | ||
if( self::different_host() ){ | ||
add_action( 'wp_footer', array(__CLASS__, 'browser_sync_js'), 9999 ); | ||
add_filter('option_home', array(__CLASS__, 'url_filter'), 99, 1); | ||
add_filter('option_siteurl', array(__CLASS__, 'url_filter'), 99, 1); | ||
add_filter('stylesheet_directory_uri', array(__CLASS__, 'url_filter'), 99, 1); | ||
add_filter('template_directory_uri', array(__CLASS__, 'url_filter'), 99, 1); | ||
} | ||
|
||
}//end setup method | ||
|
||
/** | ||
* Get WordPress host from site url | ||
*/ | ||
private static function wordpress_host(){ | ||
|
||
$host_matches = array(); | ||
|
||
global $wpdb; | ||
|
||
//get WordPress url from database | ||
$wordpress_url = $wpdb->get_var("SELECT `option_value` FROM $wpdb->options WHERE `option_name` = 'siteurl';"); | ||
|
||
//remove www. | ||
$wordpress_url = str_replace('www.', '', $wordpress_url); | ||
|
||
//strip http, www, etc from wordpress url | ||
preg_match('|http://([^/]+)|',$wordpress_url, $host_matches); | ||
|
||
if( !empty($host_matches) AND isset($host_matches[1]) ){ | ||
//if successful return wordpress host | ||
return $host_matches[1]; | ||
} else{ | ||
//otherwise return false | ||
return false; | ||
} | ||
|
||
}//end wordpress_host method | ||
|
||
/** | ||
* get localhost if defined | ||
*/ | ||
private static function get_localhost(){ | ||
|
||
$local_host = $_SERVER['HTTP_HOST']; | ||
|
||
//if localhost is empty, bail | ||
if( empty($local_host) ){ | ||
return false; | ||
} else{ | ||
//otherwise strip www and return | ||
return str_replace('www.', '', $local_host); | ||
} | ||
|
||
}//end get_localhost method | ||
|
||
/** | ||
* Does WordPress host differ from localhost? | ||
*/ | ||
private static function different_host(){ | ||
|
||
//get localhost | ||
$local_host = self::get_localhost(); | ||
|
||
//if no localhost, bail | ||
if( $local_host === false ){ | ||
return false; | ||
} | ||
|
||
//get WordPress host | ||
$wordpress_host = self::wordpress_host(); | ||
|
||
//if no WordPress host, bail | ||
if( $wordpress_host === false ){ | ||
return false; | ||
} | ||
|
||
//if wordpress host doesn't match the localhost return true, otherwise return false | ||
if( $wordpress_host != $current_host ){ | ||
return true; | ||
} else{ | ||
return false; | ||
} | ||
|
||
}//end different_host method | ||
|
||
/** | ||
* Add browser sync JS to footer | ||
*/ | ||
public static function browser_sync_js() { | ||
echo "<script type='text/javascript'>//<![CDATA[ | ||
document.write(\"<script async src='//HOST:3000/browser-sync-client.1.3.6.js'><\/script>\".replace(/HOST/g, location.hostname)); | ||
//]]></script>"; | ||
}//end browser_sync_js method | ||
|
||
/** | ||
* Filter URL, replacing localhost w/ IP | ||
*/ | ||
public static function url_filter($url){ | ||
|
||
//get WordPress host | ||
$wordpress_host = self::wordpress_host(); | ||
|
||
//get localhost | ||
$local_host = self::get_localhost(); | ||
|
||
//if current host is not the same as what's in WordPress filter the WordPress value | ||
if( self::different_host() ){ | ||
$url = str_replace($wordpress_host, $local_host, $url ); | ||
} | ||
|
||
return $url; | ||
|
||
}//end url_filter | ||
|
||
}//end browser_sync_localhost | ||
|
||
//run init | ||
browser_sync_localhost::init(); |
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,28 @@ | ||
$contrasted-dark-default: #000 !default; | ||
$contrasted-light-default: #fff !default; | ||
$contrasted-lightness-threshold: 30% !default; | ||
|
||
// Returns the `$light` color when the `$color` is dark | ||
// and the `$dark` color when the `$color` is light. | ||
// The `$threshold` is a percent between `0%` and `100%` and it determines | ||
// when the lightness of `$color` changes from "dark" to "light". | ||
@function contrast-color( | ||
$color, | ||
$dark: $contrasted-dark-default, | ||
$light: $contrasted-light-default, | ||
$threshold: $contrasted-lightness-threshold | ||
) { | ||
@return if(lightness($color) < $threshold, $light, $dark) | ||
} | ||
|
||
// Sets the specified background color and calculates a dark or light contrasted text color. | ||
// The arguments are passed through to the [contrast-color function](#function-contrast-color). | ||
@mixin contrasted( | ||
$background-color, | ||
$dark: $contrasted-dark-default, | ||
$light: $contrasted-light-default, | ||
$threshold: $contrasted-lightness-threshold | ||
) { | ||
background-color: $background-color; | ||
color: contrast-color($background-color, $dark, $light, $threshold); | ||
} |
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,114 @@ | ||
// Foundation by ZURB | ||
// foundation.zurb.com | ||
// Licensed under MIT Open Source | ||
|
||
@import 'color-contrast'; | ||
|
||
// This is the default html and body font-size for the base rem value. | ||
$rem-base: 16px !default; | ||
|
||
// IMPORT ONCE | ||
// We use this to prevent styles from being loaded multiple times for compenents that rely on other components. | ||
$modules: () !default; | ||
@mixin exports($name) { | ||
@if (index($modules, $name) == false) { | ||
$modules: append($modules, $name); | ||
@content; | ||
} | ||
} | ||
|
||
// | ||
// @functions | ||
// | ||
|
||
|
||
// RANGES | ||
// We use these functions to define ranges for various things, like media queries. | ||
@function lower-bound($range){ | ||
@if length($range) <= 0 { | ||
@return 0; | ||
} | ||
@return nth($range,1); | ||
} | ||
|
||
@function upper-bound($range) { | ||
@if length($range) < 2 { | ||
@return 999999999999; | ||
} | ||
@return nth($range, 2); | ||
} | ||
|
||
// STRIP UNIT | ||
// It strips the unit of measure and returns it | ||
@function strip-unit($num) { | ||
@return $num / ($num * 0 + 1); | ||
} | ||
|
||
// CONVERT TO REM | ||
@function convert-to-rem($value, $base-value: $rem-base) { | ||
$value: strip-unit($value) / strip-unit($base-value) * 1rem; | ||
@if ($value == 0rem) { $value: 0; } // Turn 0rem into 0 | ||
@return $value; | ||
} | ||
|
||
@function data($attr) { | ||
@if $namespace { | ||
@return '[data-' + $namespace + '-' + $attr + ']'; | ||
} | ||
|
||
@return '[data-' + $attr + ']'; | ||
} | ||
|
||
// REM CALC | ||
|
||
// New Syntax, allows to optionally calculate on a different base value to counter compounding effect of rem's. | ||
// Call with 1, 2, 3 or 4 parameters, 'px' is not required but supported: | ||
// | ||
// rem-calc(10 20 30px 40); | ||
// | ||
// Space delimited, if you want to delimit using comma's, wrap it in another pair of brackets | ||
// | ||
// rem-calc((10, 20, 30, 40px)); | ||
// | ||
// Optionally call with a different base (eg: 8px) to calculate rem. | ||
// | ||
// rem-calc(16px 32px 48px, 8px); | ||
// | ||
// If you require to comma separate your list | ||
// | ||
// rem-calc((16px, 32px, 48), 8px); | ||
|
||
@function rem-calc($values, $base-value: $rem-base) { | ||
$max: length($values); | ||
|
||
@if $max == 1 { @return convert-to-rem(nth($values, 1), $base-value); } | ||
|
||
$remValues: (); | ||
@for $i from 1 through $max { | ||
$remValues: append($remValues, convert-to-rem(nth($values, $i), $base-value)); | ||
} | ||
@return $remValues; | ||
} | ||
|
||
// OLD EM CALC | ||
// Deprecated: We'll drop support for this in 5.1.0, use rem-calc() | ||
@function emCalc($values){ | ||
@return rem-calc($values); | ||
} | ||
|
||
// OLD EM CALC | ||
// Deprecated: We'll drop support for this in 5.1.0, use rem-calc() | ||
@function em-calc($values){ | ||
@return rem-calc($values); | ||
} | ||
|
||
// Clearfix | ||
@mixin clearfix() { | ||
content: ""; | ||
display: table; | ||
} | ||
|
||
// Center after (not all clearfix need this also) | ||
@mixin clearfix-after() { | ||
clear: both; | ||
} |
Oops, something went wrong.