2013-05-11 10:16:11 +00:00
|
|
|
/**
|
2013-08-26 00:35:53 +00:00
|
|
|
* Main JS file for Casper behaviours
|
2013-05-11 10:16:11 +00:00
|
|
|
*/
|
|
|
|
|
2014-09-07 20:21:06 +00:00
|
|
|
/* globals jQuery, document */
|
|
|
|
(function ($, sr, undefined) {
|
2013-05-11 10:16:11 +00:00
|
|
|
"use strict";
|
|
|
|
|
2014-09-07 20:21:06 +00:00
|
|
|
var $document = $(document),
|
2013-08-20 16:53:02 +00:00
|
|
|
|
2014-09-07 20:21:06 +00:00
|
|
|
// debouncing function from John Hann
|
|
|
|
// http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
|
|
|
|
debounce = function (func, threshold, execAsap) {
|
|
|
|
var timeout;
|
2013-08-26 00:35:53 +00:00
|
|
|
|
2014-09-07 20:21:06 +00:00
|
|
|
return function debounced () {
|
|
|
|
var obj = this, args = arguments;
|
|
|
|
function delayed () {
|
|
|
|
if (!execAsap) {
|
|
|
|
func.apply(obj, args);
|
|
|
|
}
|
|
|
|
timeout = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timeout) {
|
|
|
|
clearTimeout(timeout);
|
|
|
|
} else if (execAsap) {
|
|
|
|
func.apply(obj, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
timeout = setTimeout(delayed, threshold || 100);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
$document.ready(function () {
|
|
|
|
|
|
|
|
var $postContent = $(".post-content");
|
|
|
|
$postContent.fitVids();
|
|
|
|
|
|
|
|
var casperFullImg = function () {
|
|
|
|
$("img").each(function () {
|
|
|
|
var $this = $(this),
|
|
|
|
contentWidth = $postContent.outerWidth(), // Width of the content
|
|
|
|
imageWidth = $this[0].naturalWidth; // Original image resolution
|
2014-01-31 07:35:24 +00:00
|
|
|
|
|
|
|
if (imageWidth >= contentWidth) {
|
2014-09-07 20:21:06 +00:00
|
|
|
$this.addClass('full-img');
|
2014-01-31 07:35:24 +00:00
|
|
|
} else {
|
2014-09-07 20:21:06 +00:00
|
|
|
$this.removeClass('full-img');
|
2014-01-31 07:35:24 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
casperFullImg();
|
|
|
|
$(window).smartresize(casperFullImg);
|
|
|
|
|
2014-07-22 11:21:33 +00:00
|
|
|
$(".scroll-down").arctic_scroll();
|
|
|
|
|
2013-05-11 10:16:11 +00:00
|
|
|
});
|
2013-08-20 16:53:02 +00:00
|
|
|
|
2014-09-07 20:21:06 +00:00
|
|
|
// smartresize
|
|
|
|
jQuery.fn[sr] = function(fn) { return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); };
|
2014-01-31 07:35:24 +00:00
|
|
|
|
2014-09-07 20:21:06 +00:00
|
|
|
// Arctic Scroll by Paul Adam Davis
|
|
|
|
// https://github.com/PaulAdamDavis/Arctic-Scroll
|
2014-07-22 11:21:33 +00:00
|
|
|
$.fn.arctic_scroll = function (options) {
|
|
|
|
|
|
|
|
var defaults = {
|
|
|
|
elem: $(this),
|
|
|
|
speed: 500
|
2014-09-07 20:21:06 +00:00
|
|
|
},
|
2014-07-22 11:21:33 +00:00
|
|
|
|
2014-09-07 20:21:06 +00:00
|
|
|
allOptions = $.extend(defaults, options);
|
|
|
|
|
|
|
|
allOptions.elem.click(function (event) {
|
2014-07-22 11:21:33 +00:00
|
|
|
event.preventDefault();
|
2014-09-07 20:21:06 +00:00
|
|
|
var $this = $(this),
|
|
|
|
$htmlBody = $('html, body'),
|
|
|
|
offset = ($this.attr('data-offset')) ? $this.attr('data-offset') : false,
|
|
|
|
position = ($this.attr('data-position')) ? $this.attr('data-position') : false,
|
|
|
|
toMove;
|
|
|
|
|
2014-07-22 11:21:33 +00:00
|
|
|
if (offset) {
|
2014-09-07 20:21:06 +00:00
|
|
|
toMove = parseInt(offset);
|
|
|
|
$htmlBody.stop(true, false).animate({scrollTop: ($(this.hash).offset().top + toMove) }, allOptions.speed);
|
2014-07-22 11:21:33 +00:00
|
|
|
} else if (position) {
|
2014-09-07 20:21:06 +00:00
|
|
|
toMove = parseInt(position);
|
|
|
|
$htmlBody.stop(true, false).animate({scrollTop: toMove }, allOptions.speed);
|
2014-07-22 11:21:33 +00:00
|
|
|
} else {
|
2014-09-07 20:21:06 +00:00
|
|
|
$htmlBody.stop(true, false).animate({scrollTop: ($(this.hash).offset().top) }, allOptions.speed);
|
2014-07-22 11:21:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
2014-09-07 20:21:06 +00:00
|
|
|
})(jQuery, 'smartresize');
|