Skip to content

Instantly share code, notes, and snippets.

View NathanQ's full-sized avatar

Nathan Victor NathanQ

View GitHub Profile
@NathanQ
NathanQ / Django filer template with google analytics
Created December 27, 2013 21:50
just a django template. If you use django filer / github.com/stefanfoulis/django-filer and google analytics on your web site and want to see those file clicks on the analytics reports, use this trackable link template. (formatting for legibility)
{% if object.file.url %}
<a href="{{ object.file.url }}" onclick="_gaq.push(['_trackEvent', 'File Downloads', 'Downloaded', '{{ object.file }}']);">
{% if object.title %}
{{ object.title|safe }}
{% else %}
<img src="{% file_icon object %}" alt="Download File" />
{% endif %}
</a>
{% endif %}
@NathanQ
NathanQ / Jquery Cookie example
Last active December 18, 2015 15:59
If cookie does not exist, do something and add cookie using jQuery-cookie. https://code.google.com/p/cookies/
var firstlocationli = $('.location li:first').position();
$('.location li').click(function(){
$(this).addClass('selected');
$(this).siblings('li').removeClass('selected');
$(".locations").hide();
$(".locations#" + $(this).attr("id") + "_list").show();
var position = $(this).position();
@NathanQ
NathanQ / jQuery Scroll to add or remove class
Last active June 2, 2016 21:17
jQuery window scroll fx to add or remove a class based on the div's position from top or bottom of the page.
function activeToggle ($theDiv) {
var divTop = $theDiv.offset().top - windowTop;
if (divTop > cutoffTop && divTop < cutoffBottom ) {
$theDiv.addClass('active');
}
else {
$theDiv.removeClass('active');
}
@NathanQ
NathanQ / Sticky Header
Created May 5, 2013 16:42
jQuery stick to the top of the page header
$(function() {
var schtickm = $("header"), pos = schtickm.offset();
$(window).scroll(function() {
if($(this).scrollTop() > (pos.top + 10) &&
schtickm.css('position') == 'static') { schtickm.addClass('fixed'); }
else if($(this).scrollTop() <= pos.top &&