Skip to content

Commit

Permalink
beautify options
Browse files Browse the repository at this point in the history
  • Loading branch information
sjwilliams committed Feb 25, 2014
1 parent 5655752 commit fcc0d38
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 14 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
indent_size = 4
trim_trailing_whitespace = false
21 changes: 21 additions & 0 deletions .jsbeautifyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"js": {
"brace_style": "collapse", // "expand", "end-expand", "expand-strict"
"break_chained_methods": false,
"e4x": false,
"eval_code": false,
"indent_char": " ",
"indent_level": 0,
"indent_size": 2,
"indent_with_tabs": false,
"jslint_happy": false,
"keep_array_indentation": false,
"keep_function_indentation": false,
"max_preserve_newlines": 10,
"preserve_newlines": true,
"space_before_conditional": true,
"space_in_paren": false,
"unescape_strings": false,
"wrap_line_length": 0
}
}
34 changes: 20 additions & 14 deletions jquery.laziestloader.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
/*! LaziestLoader - v0.0.1 - 2014-02-23
* A responsive-aware jQuery plugin to smartly lazy load images and other elements.
* https://github.com/sjwilliams/laziestloader
* Thanks to Luís Almeida for 'unveil,' on which this project is based.
* Copyright (c) 2014 Josh Williams; Licensed MIT */
* A responsive-aware jQuery plugin to smartly lazy load images and other elements.
* https://github.com/sjwilliams/laziestloader
* Thanks to Luís Almeida for 'unveil,' on which this project is based.
* Copyright (c) 2014 Josh Williams; Licensed MIT
*/
(function($) {

var laziestLoader = function(options, callback) {

var $w = $(window),
$elements = this,
$loaded = $(), // elements with the correct source set
retina = window.devicePixelRatio > 1;
$elements = this,
$loaded = $(), // elements with the correct source set
retina = window.devicePixelRatio > 1;

options = $.extend(true, {
threshold: 0,
Expand Down Expand Up @@ -47,6 +48,7 @@
* @param {jQuery object} $el
* @return {String}
*/

function getSource($el) {
var source, slug;
var data = $el.data();
Expand Down Expand Up @@ -89,6 +91,7 @@
* allows callback to manipulate element
* exclusively.
*/

function bindLoader() {
$elements.one('laziestloader', function() {
var source;
Expand All @@ -114,6 +117,7 @@
/**
* Remove even handler from elements
*/

function unbindLoader() {
$elements.off('laziestloader');
}
Expand All @@ -125,9 +129,10 @@
* @param {Array} widths available sizes
* @return {Number}
*/

function bestFit(targetWidth, widths) {
var selectedWidth = widths[widths.length - 1],
i = widths.length;
i = widths.length;
while (i--) {
if (targetWidth <= widths[i]) {
selectedWidth = widths[i];
Expand All @@ -142,16 +147,17 @@
* source set and, if they're in the viewport within
* the threshold, load their media
*/

function laziestloader() {
var $inview = $elements.not($loaded).filter(function() {
var $el = $(this);
var th = options.threshold;
if ($el.is(':hidden')) return;

var wt = $w.scrollTop(),
wb = wt + $w.height(),
et = $el.offset().top,
eb = et + $el.height();
wb = wt + $w.height(),
et = $el.offset().top,
eb = et + $el.height();

return eb >= wt - th && et <= wb + th;
});
Expand All @@ -166,7 +172,7 @@
var data = $el.data();
var height;
if (data.heightMultiplier) {
height = Math.round( $el.width() * data.heightMultiplier );
height = Math.round($el.width() * data.heightMultiplier);
$el.css({
height: height
});
Expand All @@ -180,7 +186,7 @@
$w.scroll(laziestloader);

// reset state on resize
$w.resize(function(){
$w.resize(function() {
$loaded = $();
unbindLoader();
bindLoader();
Expand All @@ -192,6 +198,6 @@
return this;
};

$.fn.laziestloader = $.fn.laziestLoader = $.fn.LaziestLoader = laziestLoader;
$.fn.laziestloader = laziestLoader;

})(window.jQuery || window.Zepto);

0 comments on commit fcc0d38

Please sign in to comment.