closingtags </> – Page 8 – web development and then some
Categories
CSS jQuery WordPress

CSS Hamburger Menu

I like the hamburger menu. It makes sense. So this is the one that I use when building a menu for mobile devices.
Here’s the HTML:
<nav id=”mobile-navigation” class=”site-navigation mobile-navigation” role=”navigation”>
<a href=”#” class=”mobile-menu-link”>MENU<span></span></a>
</nav>
And the SCSS:
.mobile-navigation {
display: none;

.mobile-menu-link {
display: block;
position: relative;
width: 90px;
height: 30px;
left: 0;
color: #2f6b68;
font-size: 20px;
text-align: right;
margin: 10px;
@include transition(all, 200ms, ease);

span {
content: ” “;
display: block;
position: absolute;
width: 24px;
height: 4px;
left: 50%;
top: 44%;
margin-left: -43px;
background: transparent;
@include transition(all, 200ms, ease);
&:before {
content: ” “;
display: block;
position: absolute;
width: 24px;
height: 4px;
background: #2f6b68;
left: 50%;
margin-left: -12px;
transform: rotate(45deg);
top: 0;
@include transition(all, 200ms, ease);
}
&:after {
content: ” “;
display: block;
position: absolute;
width: 24px;
height: 4px;
background: #2f6b68;
left: 50%;
margin-left: -12px;
transform: rotate(-45deg);
top: 0;
@include transition(all, 200ms, ease);
}
}
}
.menu-mobile-container {
height: auto;
background-color: #ffffff;
.nav-menu {
position: relative;
z-index: 50;
width: 100%;
.menu-item {
display: block;
margin: 0;
a {
display: block;
border-radius: 0;
}
}
}
}
}
.mobile-navigation.closed {
.mobile-menu-link {
span {
background: #2f6b68;
&:before {
top: -7px;
transform: rotate(0);
}
&:after {
top: 7px;
transform: rotate(0);
}
}
}
.menu-mobile-container {
height: 0;
overflow: hidden;
position: relative;
}
}
Here’s my transition mixin:
@mixin transition($property, $time, $type: ease) {
-webkit-transition: $property $time $type;
-moz-transition:$property $time $type;
-ms-transition:$property $time $type;
-o-transition:$property $time $type;
transition:$property $time $type;
}
And here’s some of the jQuery:
$(document).ready( function() {
$(‘.mobile-menu-link’).on(‘click’, function(event) {
event.preventDefault();
$(this).parent(‘.mobile-navigation’).toggleClass(‘closed’, 200);
});
});
Now, this toggleClass function is giving a little bit of a delay, so if you can figure out a way of doing all of this without it, I’d be interested in knowing a fix.
I like the animation of the ‘X’ that is provided with this hamburger menu. It’s intuitive and self-explaining.

Categories
CSS HTML5 jQuery Mobile PHP WordPress

Developing with Vagrant

Recently, I’ve been trying to find ways to speed up my development time, and I came across a great video showcasing Vagrant. I could spend a lot of time writing a bunch of mumbo jumbo here for you to read, or you could just watch the video that explains it a thousand times better than I would ever be able to.

Categories
CSS HTML5 jQuery PHP WordPress

DemocracyOS

It’s been pretty slow on the web development front for me lately, but I have discovered something new and interesting. It’s called DemocracyOS. What is DemocracyOS? Oh, I’m so glad you asked. Well it’s an open-sourced platform that aims to bring democracy back into the hands of the people in a way that makes voting on almost anything, very simple.
Just recently, we had some elections here in the US (Nov. 4th, 2014) and supposedly, Republicans took back control of both the House and the Senate because so many young people didn’t turn out to vote. What DemocracyOS intends to do, is bring the voting to you. No more waiting in lines at the polls, trying to get away from work, attempting to figure out where you’re supposed to go to vote, or filling in the circles ever so perfectly on an outdated technology (paper).
It’s supposed to be as simple to install and use as WordPress, although I haven’t quite gotten that far yet. I’ll keep the blog updated with my findings though. Check it out at Github here or the main site here.
And if you want to chat about this stuff, hit me up on Twitter @awebdevguy.

Categories
CSS jQuery

The Perfect Browser Home Page

UPDATE! Google removed the ability to host web pages within Google Drive so my simple and free hosting solution provided here (plus the link to the files) is dead.
I decided a while back that I could do my home page (in browser) better than just the standard google.com page. I tailored an html file especially to my needs, and added in some flair. The page will automatically grab the most recent top post from the subreddit /r/EarthPorn. This subreddit basically just supplies cool wallpapers all day. I hosted the file in Google Drive so that I could sync it across my work computer and home computers in Google Chrome. I used this plugin to open this page on a new tab.
So the actual page is here and if you’d like to download the files and tweak it to however you see fit, you can get those here. Let me know @awebdevguy if you do anything cool, or come up with a better way of doing what I did. I know it can be done better.

Categories
PHP

Day of the Year

The most recent challenge I’ve completed was to input a date in plain english (eg. November 19th) and output what day of the year that was (day #323). This was a pretty fun challenge, and was simple enough.
https://www.reddit.com/r/dailyprogrammer/comments/pzo4w/2212012_challenge_13_easy/
<?php
function dayofyear($date, $leap) {
$datenum = explode(” “, date(‘m d’, strtotime($date)));
$months = array(31,28,31,30,31,30,31,31,30,31,30,31);
$day = 0;
if($leap) {
$months[1] = 29;
}
for ($i=0; $i < intval($datenum[0]) – 1; $i++) {
$day = $day + $months[$i];
}
return $day + $datenum[1];
}
echo dayofyear(‘November 19th’, false);
?>
 

Categories
PHP

Simple PHP User Input Sort

I’ve been doing more programming challenges, and thought I would post my results here again. The first one, sorts user input. So if a user inputs a series of integers, they’ll be echoed out in order. It also does strings. The  sort is taking place with the PHP sort() function.
The second challenge was to write out the ’99 bottles of beer on the wall’ song. Both really simple challenges, but I thought it wouldn’t hurt to post them here anyways.
Sort
https://www.reddit.com/r/dailyprogrammer/comments/pu1rf/2172012_challenge_9_easy/
And here are my results:
<!DOCTYPE html>
<html>
<head>
<style>
.content {
text-align: center;
margin: 50px;
}
</style>
</head>
<body>
<div class=”content”>
<form action=”sort.php” method=”post” >
<label for=”inputs”>#’s: </label>
<input type=”text” name=”text1″ id=”text1″><br><br>
<input type=”submit” name=”submit” value=”Submit”>
</form>
<?php
if(!empty($_POST[“text1″])) {
$ints = explode(” “, $_POST[“text1”]);
sort($ints);
foreach ($ints as $key => $value) {
echo $value . “<br>”;
}
}
?>
</div>
</body>
<footer>
</footer>
</html>

99 bottles
https://www.reddit.com/r/dailyprogrammer/comments/pserp/2162012_challenge_8_easy/

With the solution here:
<!DOCTYPE html>
<html>
<head>
<style>
.content {
text-align: center;
margin: 50px;
}
</style>
</head>
<body>
<div class=”content”>
<?php
$bottles = 99;
while ($bottles > 1) {
echo $bottles . ” bottles of beer on the wall, ” . $bottles . ” bottles of beer, take one down and pass it around ” . –$bottles .” bottles of beer on the wall. “;
}
echo $bottles . ” bottle of beer on the wall, ” . $bottles . ” bottle of beer, take one down and pass it around ” . –$bottles .” bottles of beer on the wall. “;
?>
</div>
</body>
<footer>
</footer>
</html>

 

Categories
PHP

Random Password Generator

I’ve had a little bit of downtime at work, and didn’t want to be idle. Luckily for me, I found this awesome subreddit, called /r/dailyprogrammer. They’ve got tons of programming challenges for a wide variety of skills. So I’ve been picking through some simple ones in my down time, and doing some of the easier ones. This one is the most recent challenge I did.
Basically, it just asks you to create a random password generator (like this one) with the ability to specify how many passwords to generate, and how long the string should be. And since the comments are closed, I can’t really submit my solution there, so here is what I came up with, in PHP.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div style=”text-align: center; margin: 50px;”>
<form action=”passwords.php” method=”post” style=”margin-bottom: 25px;” enctype=”multipart/form-data”>
<label for=”inputs”># of passwords: </label>
<input type=”text” name=”text1″ id=”text1″><br><br>
<label for=”inputs”>string length: </label>
<input type=”text” name=”text2″ id=”text2″><br><br>
<input type=”submit” name=”submit” value=”Submit”>
</form>
<?php
if($_POST[“text1”] && $_POST[“text2”]) {

$max = intval($_POST[“text1”]);
$length = intval($_POST[“text2”]);
$count = 0;

$seed = str_split(“abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_”, 1);

$tehstring = “”;

while($count < $max) {
for ($i=0; $i < $length; $i++) {
$tehstring .= $seed[mt_rand(0, count($seed)-1)];
}

echo $tehstring . “<br>”;
$tehstring =””;
$count++;
}
}
?>
</div>
</body>
<footer>
</footer>
</html>

 

Categories
HTML5 jQuery

HTML Games

Whoa. I just discovered this super easy way to build HTML5 web games, where a ton of the heavy lifting is already done for you. Seriously, go check out what the guys and gals over at Photon Storm are doing and check out Phaser

Categories
CSS Themes WordPress

Custom WordPress Admin Login Logo

If you want to replace the WordPress logo on your admin login page with your own custom image, you can do it with just a couple simple lines in your functions.php file.
add_action(“login_head”, “my_login_head”);
function my_login_head() {
echo “<style>
body.login #login h1 a {
background: url(‘”.get_bloginfo(‘template_url’).”/images/logo_login.png’) no-repeat scroll center top transparent;
height: 181px;
width: 269px;
padding:0 25px;
}
</style>”;
}
Simply upload your file to the proper path and adjust the CSS accordingly.

Categories
CSS Themes WordPress

Shortcodes for Custom Column Sizes

WordPress is great, but sometimes, when you’re writing a blog post, the WSIWYG is just lacking certain features. Say you want to format your content and make things a little cleaner. Like this:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vel urna ut elit faucibus semper. Morbi dignissim ex enim, et consectetur justo blandit vel. Etiam lobortis nulla vel tellus dictum dignissim. Fusce purus lectus, luctus vitae imperdiet ac, lobortis quis urna. Integer id venenatis quam. Cras ac neque sit amet urna consequat pellentesque.

Nunc vitae laoreet purus. Ut egestas, metus eget accumsan fringilla, erat justo congue tellus, pulvinar vehicula nunc enim nec augue. Praesent gravida blandit risus dapibus pharetra. Proin consequat et nisl quis tincidunt. Proin at massa odio. Cras malesuada porta ultricies. Fusce tristique blandit leo at tempus. Curabitur tincidunt ex quis lacus sodales ornare.

By the way, you can get copy/paste lorem ipsum from http://www.lipsum.com/feed/html
Well, if this is something you’d like to be able to do, you can make a couple quick edits in functions.php and style.css of your theme. The CSS code looks like this:
/*
* Fluid Columns
* —————————————————————————-
*/
.one_half{ width:48%; }
.one_third{ width:30.66%; }
.two_third{ width:65.33%; }
.one_fourth{ width:22%; }
.three_fourth{ width:74%; }
.one_fifth{ width:16.8%; }
.two_fifth{ width:37.6%; }
.three_fifth{ width:58.4%; }
.four_fifth{ width:79.2%; }
.one_sixth{ width:13.33%; }
.five_sixth{ width:82.67%; }
.one_half,.one_third,.two_third,.three_fourth,.one_fourth,.one_fifth,.two_fifth,.three_fifth,.four_fifth,.one_sixth,.five_sixth{ position:relative; margin-right:2%; padding-right:2%; float:left; }
.last{ margin-right:0 !important; padding-right:0 !important; clear:right; }
.clearboth {clear:both;display:block;font-size:0;height:0;line-height:0;width:100%;}

And this is what you will put in the functions.php:
function columns_one_third( $atts, $content = null ) { return ‘<div class=”one_third”>’ . do_shortcode($content) . ‘</div>’; } add_shortcode(‘one_third’, ‘columns_one_third’);
function columns_one_third_last( $atts, $content = null ) { return ‘<div class=”one_third last”>’ . do_shortcode($content) . ‘</div><div class=”clearboth”></div>’; } add_shortcode(‘one_third_last’, ‘columns_one_third_last’);
function columns_two_third( $atts, $content = null ) { return ‘<div class=”two_third”>’ . do_shortcode($content) . ‘</div>’; } add_shortcode(‘two_third’, ‘columns_two_third’);
function columns_two_third_last( $atts, $content = null ) { return ‘<div class=”two_third last”>’ . do_shortcode($content) . ‘</div><div class=”clearboth”></div>’; } add_shortcode(‘two_third_last’, ‘columns_two_third_last’);
function columns_one_half( $atts, $content = null ) { return ‘<div class=”one_half”>’ . do_shortcode($content) . ‘</div>’; } add_shortcode(‘one_half’, ‘columns_one_half’);
function columns_one_half_last( $atts, $content = null ) { return ‘<div class=”one_half last”>’ . do_shortcode($content) . ‘</div><div class=”clearboth”></div>’; } add_shortcode(‘one_half_last’, ‘columns_one_half_last’);
function columns_one_fourth( $atts, $content = null ) { return ‘<div class=”one_fourth”>’ . do_shortcode($content) . ‘</div>’; } add_shortcode(‘one_fourth’, ‘columns_one_fourth’);
function columns_one_fourth_last( $atts, $content = null ) { return ‘<div class=”one_fourth last”>’ . do_shortcode($content) . ‘</div><div class=”clearboth”></div>’; } add_shortcode(‘one_fourth_last’, ‘columns_one_fourth_last’);
function columns_three_fourth( $atts, $content = null ) { return ‘<div class=”three_fourth”>’ . do_shortcode($content) . ‘</div>’; } add_shortcode(‘three_fourth’, ‘columns_three_fourth’);
function columns_three_fourth_last( $atts, $content = null ) { return ‘<div class=”three_fourth last”>’ . do_shortcode($content) . ‘</div><div class=”clearboth”></div>’; } add_shortcode(‘three_fourth_last’, ‘columns_three_fourth_last’);
function columns_one_fifth( $atts, $content = null ) { return ‘<div class=”one_fifth”>’ . do_shortcode($content) . ‘</div>’; } add_shortcode(‘one_fifth’, ‘columns_one_fifth’);
function columns_one_fifth_last( $atts, $content = null ) { return ‘<div class=”one_fifth last”>’ . do_shortcode($content) . ‘</div><div class=”clearboth”></div>’; } add_shortcode(‘one_fifth_last’, ‘columns_one_fifth_last’);
function columns_two_fifth( $atts, $content = null ) { return ‘<div class=”two_fifth”>’ . do_shortcode($content) . ‘</div>’; } add_shortcode(‘two_fifth’, ‘columns_two_fifth’);
function columns_two_fifth_last( $atts, $content = null ) { return ‘<div class=”two_fifth last”>’ . do_shortcode($content) . ‘</div><div class=”clearboth”></div>’; } add_shortcode(‘two_fifth_last’, ‘columns_two_fifth_last’);
function columns_three_fifth( $atts, $content = null ) { return ‘<div class=”three_fifth”>’ . do_shortcode($content) . ‘</div>’; } add_shortcode(‘three_fifth’, ‘columns_three_fifth’);
function columns_three_fifth_last( $atts, $content = null ) { return ‘<div class=”three_fifth last”>’ . do_shortcode($content) . ‘</div><div class=”clearboth”></div>’; } add_shortcode(‘three_fifth_last’, ‘columns_three_fifth_last’);
function columns_four_fifth( $atts, $content = null ) { return ‘<div class=”four_fifth”>’ . do_shortcode($content) . ‘</div>’; } add_shortcode(‘four_fifth’, ‘columns_four_fifth’);
function columns_four_fifth_last( $atts, $content = null ) { return ‘<div class=”four_fifth last”>’ . do_shortcode($content) . ‘</div><div class=”clearboth”></div>’; } add_shortcode(‘four_fifth_last’, ‘columns_four_fifth_last’);
function columns_one_sixth( $atts, $content = null ) { return ‘<div class=”one_sixth”>’ . do_shortcode($content) . ‘</div>’; } add_shortcode(‘one_sixth’, ‘columns_one_sixth’);
function columns_one_sixth_last( $atts, $content = null ) { return ‘<div class=”one_sixth last”>’ . do_shortcode($content) . ‘</div><div class=”clearboth”></div>’; } add_shortcode(‘one_sixth_last’, ‘columns_one_sixth_last’);
function columns_five_sixth( $atts, $content = null ) { return ‘<div class=”five_sixth”>’ . do_shortcode($content) . ‘</div>’; } add_shortcode(‘five_sixth’, ‘columns_five_sixth’);
function columns_five_sixth_last( $atts, $content = null ) { return ‘<div class=”five_sixth last”>’ . do_shortcode($content) . ‘</div><div class=”clearboth”></div>’; } add_shortcode(‘five_sixth_last’, ‘columns_five_sixth_last’);

function columns_formatter($content) {
$new_content = ”;

/* Matches the contents and the open and closing tags */
$pattern_full = ‘{(\[raw\].*?\[/raw\])}is’;

/* Matches just the contents */
$pattern_contents = ‘{\[raw\](.*?)\[/raw\]}is’;

/* Divide content into pieces */
$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);

/* Loop over pieces */
foreach ($pieces as $piece) {
/* Look for presence of the shortcode */
if (preg_match($pattern_contents, $piece, $matches)) {

/* Append to content (no formatting) */
$new_content .= $matches[1];
} else {

/* Format and append to content */
$new_content .= wptexturize(wpautop($piece));
}
}

return $new_content;
}

// Remove the 2 main auto-formatters
remove_filter(‘the_content’, ‘wpautop’);
remove_filter(‘the_content’, ‘wptexturize’);

// Before displaying for viewing, apply this function
add_filter(‘the_content’, ‘columns_formatter’, 99);
add_filter(‘widget_text’, ‘columns_formatter’, 99);

Now to use this handy feature, you basically say:

Your content goes here…..

Your content goes here…..

If you wanted three columns, you’d replace ‘one_half’ with ‘one_third’, four columns, you’d replace ‘one_half’ with ‘one_fourth, and so on. Just make sure your last column has the ‘_last’ appended to both opening and closing tags.
Mobile
This is a pretty great feature, but it does break down on mobile devices. So in the media queries of the theme, I find it best to simple break the columns, and set each section to full width. The .clearboth class in the CSS code has pretty much everything you need (but also some extra) so we’ll take a piece out of that and do this in our media queries.
@media screen and (max-width: 758px) {

.one_half,.one_third,.two_third,.three_fourth,.one_fourth,.one_fifth,.two_fifth,.three_fifth,.four_fifth,.one_sixth,.five_sixth {
clear:both;
display:block;
width:100%;
}
}
This way, when the device screen gets to a smaller size, your columns will break into full width divs.
Source