Skip to content

Instantly share code, notes, and snippets.

@quawn
quawn / img-resizer.js
Last active January 4, 2016 03:19
JS: Image resizing using jQuery
$(window).bind("load", function() {
// IMAGE RESIZE
$('#product_cat_list img').each(function() {
var maxWidth = 120;
var maxHeight = 120;
var ratio = 0;
var width = $(this).width();
var height = $(this).height();
if(width > maxWidth){
@quawn
quawn / clone-table-header.js
Last active January 4, 2016 03:19
JS: Clone table header to the bottom of table
var $tfoot = $('<tfoot></tfoot>');
$($('thead').clone(true, true).children().get().reverse()).each(function(){
$tfoot.append($(this));
});
$tfoot.insertAfter('table thead');
@quawn
quawn / div-viewport.js
Last active January 4, 2016 03:19
JS: Div full Width/Height of viewport with jQuery
// global vars
var winWidth = $(window).width();
var winHeight = $(window).height();
// set initial div height / width
$('div').css({
'width': winWidth,
'height': winHeight,
});
@quawn
quawn / ext-link-opener.js
Last active January 4, 2016 03:19
JS: Open external links in a new tab/window
@quawn
quawn / page-refresher.js
Last active January 4, 2016 03:19
JS: Partial page refresh
setInterval(function() {
$("#refresh").load(location.href+" #refresh>*","");
}, 10000); // milliseconds to wait
@quawn
quawn / smooth-scroller.js
Last active January 4, 2016 03:19
JS: Smooth scrolling to top of page
$("a[href='#top']").click(function() {
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
});
@quawn
quawn / max_width_email.html
Created January 16, 2014 22:04 — forked from elidickinson/max_width_email.html
HTML: Max-width in Email
<!--[if mso]>
<center>
<table><tr><td width="580">
<![endif]-->
<div style="max-width:580px; margin:0 auto;">
<p>This text will be centered and constrained to 580 pixels even on Outlook which does not support max-width CSS</p>
</div>
<!--[if mso]>
@quawn
quawn / function.php
Last active December 28, 2015 18:59
WP: Notification to Admin or Author upon status change
<?php
function authorNotification( $new_status, $old_status, $post ) {
if ( $new_status == 'publish' && $old_status != 'publish' ) {
$author = get_userdata($post->post_author);
$message = "
Hi ".$author->display_name.",
New post, ".$post->post_title." has just been published at ".get_permalink( $post->ID ).".
";
wp_mail($author->user_email, "New Post Published", $message);
@quawn
quawn / no-js-img-preloading.html
Last active December 28, 2015 03:09
HTML: No-JS Image preloading
<!-- ADD THIS TO XHTML -->
<div id="preloaded-images">
<img src="http://perishablepress.com/image-01.png" width="1" height="1" alt="Image 01" />
<img src="http://perishablepress.com/image-02.png" width="1" height="1" alt="Image 02" />
<img src="http://perishablepress.com/image-03.png" width="1" height="1" alt="Image 03" />
</div>
@quawn
quawn / style.less
Last active December 28, 2015 03:09
CSS: Background image for Retina
@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
.box{
background:url('images/box-bg@2x.png') no-repeat top left;
background-size: 200px 200px;
}
}