Skip to content

Instantly share code, notes, and snippets.

View johnbocook's full-sized avatar
💯
I come here for the dark theme.

John Bocook johnbocook

💯
I come here for the dark theme.
View GitHub Profile
@johnbocook
johnbocook / DrupalUploadRename.php
Created January 31, 2015 06:27
Rename Files on Upload in Drupal 7
/**
* Implements hook_file_insert().
*/
function MYMODULE_file_insert($file) {
$hash = 'public://' . md5($file->filename) . '.' . pathinfo($file->filename, PATHINFO_EXTENSION);
file_move($file, $hash, 'FILE_EXIST_REPLACE');
}
@johnbocook
johnbocook / DynamicBackground.js
Created January 31, 2015 02:04
Gets pathname (domain.com/pathname) and add's background image of same name.
//Get Pathname and Add background image of path for dynamic backgrounds.
var loc = window.location.pathname.substring(1);
if (loc === '') {
$( "#marketing-header" ).css('background-image', 'url(/img/default-bg.jpg)');
} else {
$( "#marketing-header" ).css('background-image', 'url(/img/'+loc+'.jpg)');
};
@johnbocook
johnbocook / ProgramInjector.js
Created January 31, 2015 01:01
Populates Drupal 7 Webform select options based on Json object from another system
/* Author Note:
* Uses a Json object to populate Drupal 7's webform select options. You have to modify webform to accept external select options to be posted.
* On remote Json failure, A local Json object is loaded. I have a cron script that updates the Local Json object daily from remote server.
*/
//Remove required webform select option
$("#edit-submitted-programs-list option[value='NA']").each(function() {
$(this).remove();
});
//Get list of programs from Server
@johnbocook
johnbocook / urlParms.js
Created January 31, 2015 00:53
Takes parameters passed via URL and places them into Drupal 7 webform fields
/* Author Note:
* Captures URL parameters and inputs into Drupal webform
* Used for PPC Landing Page marketing. Passing SourceId, Adid, KwId to converted leads and submiting to database with lead.
* URL Ussage http://www.domain.com/?sid=Adwords&cmid=CampainID&adgid=AdGroupID&adid=AdID&kwid=KeyworkID
*/
//Split apart URL and extract Parameters
var parseQueryString = function() {
var str = window.location.search;
var objURL = {};
@johnbocook
johnbocook / drupal_mail.php
Last active August 29, 2015 13:56
Module that will send email using drupal_mail. Drupal 7
<?php
/**
*
* Implements hook_menu()
* Call a custom form as menu callback
* @return
* $items array of menu items created programmatically
*/
function test_menu() {
@johnbocook
johnbocook / ScreenSizeCheck.js
Last active August 29, 2015 13:56
The easy way to find out your screen's dimensions -- with jQuery -- (works with PhoneGap).
console.log( "window=" + $(document).width() + "x" + $(document).height() );
@johnbocook
johnbocook / div-height.js
Last active January 4, 2016 03:39
jQuery - Makes two div's the same height
$(‘.div').css('min-height', $(‘.main-div').height());
@johnbocook
johnbocook / back-to-top.js
Last active January 4, 2016 03:39
jQuery Back to top button
// Back To Top
$('a.top').click(function(){
$(document.body).animate({scrollTop : 0},800);
return false;
});
//Create an anchor tag
<a class=”top” href=”#”>Back to top</a>
@johnbocook
johnbocook / 404images.js
Created January 20, 2014 01:47
Handle Missing Image Errors with jQuery
// Hide the image on error
$("img").error(function(){
$(this).hide();
});
// Change the image to a missing image
$('img').error(function(){
$(this).attr('src', 'no-image.jpg');
});
@johnbocook
johnbocook / BPT-Donation-Hider.js
Last active January 3, 2016 15:19
Hides Brown Paper Tickets Donation text - Placed in the event's custom header section, it searches for the donation text on the checkout page and hides it.
<script type="text/javascript">
$(document).ready(function() {
var url = window.location.href;
if (url.search("checkout.html") >= 0) {
$('td:contains("A portion of Brown Paper Tickets profits"):last').hide();
$('td:contains("This sale should benefit "):last').parent().hide();
}
});
</script>