Skip to content

Instantly share code, notes, and snippets.

View brettbartylla's full-sized avatar

brettbartylla

View GitHub Profile
@brettbartylla
brettbartylla / inlineVideoPlayer.js
Created September 6, 2017 00:03
jQuery I wrote that dynamically builds HTML5 players and inserts them inline on a page. Video content (IDs) came from Brightcove. I've removed the original videos and am using hardcoded values for this example.
(function (context) {
'use strict';
var require = context.require;
var requirejs = context.requirejs;
var define = context.define;
define(['require','jquery','lib/Util','GlobalEventDispatcher','GlobalResizeListener'],function (require) {
//define any required libraries - see config.js for registered names
var $ = require('jquery'), //require jQuery
util = require('lib/Util'), //require util for $debug
@brettbartylla
brettbartylla / hexToRGBA.js
Last active September 6, 2017 00:11
This javascript/jQuery converts color and transparency options selected from a CMS configuration page and converts the values from hex to RGBA so the transparency option that was selected can work.
(function (context) {
'use strict';
var require = context.require;
var requirejs = context.requirejs;
var define = context.define;
define(function (require) {
//define any required libraries - see config.js for registered names
var $ = require('jquery'), //require jQuery
util = require('lib/Util'), //require util for $debug
@brettbartylla
brettbartylla / navScroll.js
Created September 6, 2017 01:58
Snippet of jQuery that is triggered when the navigation link with corresponding id is clicked. This will result in scrolling to an anchor that is placed in the HTML.
//scroll from nav to anchor on page
$("#navLink").click(function() {
$('html, body').animate({
scrollTop: $("#anchor").offset().top
}, 1200);
});
@brettbartylla
brettbartylla / mailer.php
Created September 6, 2017 02:05
PHP file that builds a message and then emails the data that comes from a form submission
<?php
// Only process POST reqeusts.
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the form fields and remove whitespace.
$name = strip_tags(trim($_POST["name"]));
$name = str_replace(array("\r","\n"),array(" "," "),$name);
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$message = trim($_POST["message"]);
@brettbartylla
brettbartylla / ajaxSubmit.js
Last active September 6, 2017 02:07
Form submission using Ajax
$(function() {
// Get the form.
var form = $('#ajax-contact');
// Get the messages div.
var formMessages = $('#form-messages');
// Set up an event listener for the contact form.
$(form).submit(function(e) {
// Stop the browser from submitting the form.
@brettbartylla
brettbartylla / form.html
Created September 6, 2017 02:08
Form that goes with the mailer.php and ajaxSubmit.js files
<form id="ajax-contact" class="form-horizonta" method="post" action="mailer.php">
<div class="field form-group">
<label for="name" class="control-label">Name:</label>
<input class="form-control" type="text" id="name" name="name">
</div>
<div class="field form-group">
<label for="email" class="control-label">Email:</label>
<input class="form-control" type="email" id="email" name="email">
</div>
<div class="field form-group">
@brettbartylla
brettbartylla / typeMessage.js
Created September 9, 2017 22:22
Simulates a message bring typed. Sets a div with the id of "typewriter" as the message that equals the string value of the str variable. There is a working example of this at the top of my website!
var str = "<h2>Full Stack Development</h2>",
i = 0,
isTag,
text;
(function type() {
text = str.slice(0, ++i);
if (text === str) return;
document.getElementById('typewriter').innerHTML = text;
//draw on home image
var canvas = document.querySelector('#paint');
var ctx = canvas.getContext('2d');
var sketch = document.querySelector('.sketch');
var sketch_style = getComputedStyle(sketch);
canvas.width = parseInt(sketch_style.getPropertyValue('width'));
canvas.height = parseInt(sketch_style.getPropertyValue('height'));
var mouse = {x: 0, y: 0};
var last_mouse = {x: 0, y: 0};
@brettbartylla
brettbartylla / mouseDraw.js
Created September 9, 2017 22:26
This javascript allows a mouse to draw on an HTML5 Canvas. A working example of this is on my website.
//draw on home image
var canvas = document.querySelector('#paint');
var ctx = canvas.getContext('2d');
var sketch = document.querySelector('.sketch');
var sketch_style = getComputedStyle(sketch);
canvas.width = parseInt(sketch_style.getPropertyValue('width'));
canvas.height = parseInt(sketch_style.getPropertyValue('height'));
var mouse = {x: 0, y: 0};
var last_mouse = {x: 0, y: 0};
@brettbartylla
brettbartylla / mergeArrays.js
Created September 9, 2017 22:36
Takes two arrays (obj1, obj3) and merges their values into a new array. The result is the values of obj1 and obj2 but in the order of every other one of their values Ex. a1b2c3
function merge(obj1, obj2){
var obj3 = [];
for (var i= 0, len = obj1.length; i < len; i++) {
obj3.push(obj1[i]);
obj3.push(obj2[i]);
}
return obj3;
}
//calls merge function, removes commas using join, displays output