Skip to content

Instantly share code, notes, and snippets.

View BenjaminAdams's full-sized avatar
🤠
wrangling up the codes at the wild west corral

Benjamin Adams BenjaminAdams

🤠
wrangling up the codes at the wild west corral
  • Austin, Tx
View GitHub Profile
@BenjaminAdams
BenjaminAdams / css-nav-tabs.html
Last active August 29, 2015 14:01
Pure CSS tabs with checkbox hack
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head></head><body>
<style>
.tab-area p {
font-size: 11px;
color: #666;
}
@BenjaminAdams
BenjaminAdams / upload.js
Created October 1, 2013 07:15
Upload image and/or a file with Javascript
uploadImg: function(file, imgPreview, imgUrl) {
var self = this
console.log('file=', file)
imgPreview.html('<i class="icon-spinner icon-spin"></i>')
imgUrl.val('')
reader = new FileReader();
reader.onload = (function(tFile) {
return function(evt, response) {
@BenjaminAdams
BenjaminAdams / main.js
Created September 29, 2013 20:04
How to properly serialize a form into a javascript object
var data = {};
$(".form-selector").serializeArray().map(function(x){data[x.name] = x.value;})
@BenjaminAdams
BenjaminAdams / Split string on words.php
Last active December 19, 2015 17:29
Splitting a string between multiple lines. When you are splitting a string to go on multiple lines we want to split the string where it does not break a word onto different lines. This to to make the string easier to read. In this example I was generating a PDF and needed to split a title of something onto 3 different lines so the text did not s…
public function split_title($title,$maxStr)
{
$newStr = Array();
$maxLines=3;
$lineNum = 1; //to be line 1,2, or 3
$split = explode ( " ", $title);
foreach($split as $str)
{
@BenjaminAdams
BenjaminAdams / index.html
Created May 31, 2013 17:16
The iframe upload trick - How to upload files without refreshing the page by submitting the file through a hidden iframe.
<div id='status'></div>
<form id="file-upload-form" name="file-upload-form">
<input type="file" id="upload-doc-file" name="upload-doc-file">
</form>
<iframe id="postiframe" name="postiframe"></iframe>
@BenjaminAdams
BenjaminAdams / gist:5258272
Created March 27, 2013 21:40
Problem, we need to trim strings in javascript but its not implemented in all browsers Since new Browsers (IE9+) have trim() already implemented, you should only implement trim() if it is not already available on the Prototype-Object (overriding it is a huge performance hit). This is generally recommended when extending Native Objects! Note that…
if (!String.prototype.trim) {
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g, '');};
}