Skip to content

Instantly share code, notes, and snippets.

View ben-caplan's full-sized avatar

Benjamin Reif-Caplan ben-caplan

View GitHub Profile
$('select').each(function() {
var $t = $(this);
if (!$t.parent().hasClass('custom-select')) {
$t.wrap('<div class="custom-select" />').before('<div class="display-copy empty"></div>');
}
}).on('change faux_change', function() {
var $t = $(this);
$t.siblings('.displayCopy').text($t.find('option:selected').text());
//toggle "empty" class
if ($t.prop('selectedIndex') > 0) {
getTempImage : function(t, blob, cropData){
// get the CSRF token, or get out if we can't find it
var csrfToken = $("body").attr("data-csrf-token"),
ajaxArgs = {};
// show loading indicator - wait for response to continue
radius.loading.show();
//DO WE HAVE WHAT WE NEED? If we dont have a blob or csrf token get out
if (!csrfToken || typeof blob == 'undefined') return {};
#set( $currentPageURL = "http://$request.getServerName()${request.getAttribute('javax.servlet.forward.request_uri')}" )##
#set( $adWords = $dotcontent.pull("+structureName:AdwordsConversionCodes +AdwordsConversionCodes.targetPageUrl:${currentPageURL} +languageId:${currentLang}", 1, '') )##
#if( $adWords.size() < 1 )##
#set( $currentPageURL = $currentPageURL.replaceAll("((http)s?://)|(www\.)", '') )##
#set( $adWords = $dotcontent.pull("+structureName:AdwordsConversionCodes +AdwordsConversionCodes.targetPageUrl:${currentPageURL} +languageId:${currentLang}", 1, '') )##
#end##
#if( $adWords.size() > 0 )##
#set( $adWords = $adWords.get(0) )##
<input type="hidden" name="ga_ppc_conversion_id" id="ga_ppc_conversion_id" value="${adWords.conversionId}" />
<input type="hidden" name="ga_ppc_conversion_label" id="ga_ppc_conversion_label" value="${adWords.conversionLabel}" />
$desiredOrder = array('post', 'cpt1', 'cpt2', 'etc');
function reorder( $a, $b ) {
global $posts;
$ap = array_search( $a->post_type, $desiredOrder );
$bp = array_search( $b->post_type, $desiredOrder );
return ( $ap < $bp ) ? -1 : 1;
}
usort( $wp_query->posts, "reorder" );
@ben-caplan
ben-caplan / Quick-hire-honeypot-JS
Last active August 29, 2015 13:57
Quick hire Honeypot implementation code
<script>
jQuery(function($){
$('#contactForm')
.off()
.on('honeypotBeforeSend', function(e, xhr, s){
comments = $(this).find('textarea[name="comments"]');
s.data = s.data.replace( /comments=(.|\s)*?&/, 'comments='+encodeURIComponent(comments.val()+' \n\n '+ window.YOUR_VAR + ' (Request from this page: http://${request.getServerName()}${VTLSERVLET_URI}) ')+'&' );
})
.honeypot({
@ben-caplan
ben-caplan / styled-select-js
Last active October 24, 2023 18:46
Styled Select JS
//CUSTOM SELECT - prevent double wrap incase this script is include in multiple locations...
$('select').each(function(){
var t = $(this);
if( !t.parent().hasClass('customSelect') ){
t.wrap('<div class="customSelect" />').before('<div class="displayCopy empty"></div>');
}
}).on('change fauxChange', function(){
var t = $(this);
t.siblings('.displayCopy').text( t.find('option:selected').text() );
//toggle "empty" class
@ben-caplan
ben-caplan / gist:7041276
Created October 18, 2013 13:07
Add script macro
#*
ADD SCRIPT MACRO
@use #addScript( $scriptPath )
*#
#set( $scriptArray = [] )##
#macro( addScript $src )##
## CHECK TO MAKE SURE THAT VARS HAVE BEEN SET
#if( $UtilMethods.isSet($src) )##
#set( $scriptInMap = 'false' )##