Table of Contents generated with DocToc
View UndoStack.js
function UndoItem (perform, data) { | |
this.perform = perform; | |
this.data = data; | |
} | |
/** | |
* UndoStack: | |
* Easy undo-redo in JavaScript. | |
**/ |
View functions.php
/** | |
* Auto update cart after quantity change | |
* | |
* @return string | |
**/ | |
add_action( 'woocommerce_after_cart', 'custom_after_cart' ); | |
function custom_after_cart() { | |
echo '<script> | |
jQuery(document).ready(function($) { |
View animatedScrollTo.js
document.getElementsByTagName('button')[0].onclick = function () { | |
scrollTo(document.body, 0, 1250); | |
} | |
function scrollTo(element, to, duration) { | |
var start = element.scrollTop, | |
change = to - start, | |
currentTime = 0, | |
increment = 20; | |
View es6-ajax-request.js
export default class Ajax { | |
get(url, callback) { | |
let xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); | |
xhr.open('GET', url); | |
xhr.onreadystatechange = () => { | |
if (xhr.readyState > 3 && xhr.status === 200) { | |
callback(xhr.responseText); | |
} | |
}; | |
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); |
View php-convert-color-code-from-hex-to-rgba
<?php | |
function ak_convert_hex2rgba($color, $opacity = false) { | |
$default = 'rgb(0,0,0)'; | |
if (empty($color)) | |
return $default; | |
if ($color[0] == '#') | |
$color = substr($color, 1); | |
View problems.js
/* | |
* @link https://frontendmasters.com/courses/javascript-the-good-parts/ | |
Problems 1-5 | |
A sequence of problems will be presented followed by a solution. Each problem builds on the last so if you get a problem wrong, use the solution to begin the next problem. First, a quick quiz: What is x? | |
3:19:33 - 3:32:25 | |
Problems 6-9 | |
o Problem 6: Write a function that takes a function and an argument, and returns a function that can supply a second argument. | |
o Problem 7: Without writing any new functions, show three ways to create the inc function. | |
o Problem 8: Write methodize, a function that converts a binary function to a method. | |
o Problem 9: Write demethodize, a function that converts a method to a binary function. |
View hnl.taphover.js
//taphover - a solution to the lack of hover on touch devices. | |
//more info: http://www.hnldesign.nl/work/code/mouseover-hover-on-touch-devices-using-jquery/ | |
$('a.taphover').on('touchstart', function (e) { | |
'use strict'; //satisfy the code inspectors | |
var link = $(this); //preselect the link | |
if (link.hasClass('hover')) { | |
return true; | |
} else { | |
link.addClass('hover'); | |
$('a.taphover').not(this).removeClass('hover'); |
View header.php
global $woocommerce; | |
if ( sizeof( $woocommerce->cart->cart_contents) > 0 ) : | |
echo '<a href="' . $woocommerce->cart->get_checkout_url() . '" title="' . __( 'Checkout' ) . '">' . __( 'Checkout' ) . '</a>'; | |
endif; |
View ssl-support.php
<?php | |
add_filter( 'wp_get_attachment_url', function( $url, $id ){ | |
if( is_ssl() ) | |
$url = str_replace( 'http://', 'https://', $url ); | |
return $url; | |
}); |
NewerOlder