Comparing version 1.0.0 to 1.0.1
@@ -1,114 +0,147 @@ | ||
(function ($) { | ||
"use strict"; | ||
$.fn.pin = function (options) { | ||
var scrollY = 0, elements = [], disabled = false, $window = $(window); | ||
options = options || {}; | ||
var $ = require('webpack-zepto'); | ||
var recalculateLimits = function () { | ||
for (var i=0, len=elements.length; i<len; i++) { | ||
var $this = elements[i]; | ||
$.fn.pin = function(options) { | ||
var scrollY = 0, | ||
elements = [], | ||
disabled = false, | ||
$window = $(window); | ||
if (options.minWidth && $window.width() <= options.minWidth) { | ||
if ($this.parent().is(".pin-wrapper")) { $this.unwrap(); } | ||
$this.css({width: "", left: "", top: "", position: ""}); | ||
if (options.activeClass) { $this.removeClass(options.activeClass); } | ||
disabled = true; | ||
continue; | ||
} else { | ||
disabled = false; | ||
} | ||
options = options || {}; | ||
var $container = options.containerSelector ? $this.closest(options.containerSelector) : $(document.body); | ||
var offset = $this.offset(); | ||
var containerOffset = $container.offset(); | ||
var parentOffset = $this.offsetParent().offset(); | ||
var recalculateLimits = function() { | ||
for (var i = 0, len = elements.length; i < len; i++) { | ||
var $this = elements[i]; | ||
if (!$this.parent().is(".pin-wrapper")) { | ||
$this.wrap("<div class='pin-wrapper'>"); | ||
} | ||
if (options.minWidth && $window.width() <= options.minWidth) { | ||
if ($this.parent().is(".pin-wrapper")) { | ||
$this.unwrap(); | ||
} | ||
$this.css({ | ||
width: "", | ||
left: "", | ||
top: "", | ||
position: "" | ||
}); | ||
if (options.activeClass) { | ||
$this.removeClass(options.activeClass); | ||
} | ||
disabled = true; | ||
continue; | ||
} else { | ||
disabled = false; | ||
} | ||
var pad = $.extend({ | ||
top: 0, | ||
bottom: 0 | ||
}, options.padding || {}); | ||
var $container = options.containerSelector ? $this.closest(options.containerSelector) : $(document.body); | ||
var offset = $this.offset(); | ||
var containerOffset = $container.offset(); | ||
var parentOffset = $this.offsetParent().offset(); | ||
$this.data("pin", { | ||
pad: pad, | ||
from: (options.containerSelector ? containerOffset.top : offset.top) - pad.top, | ||
to: containerOffset.top + $container.height() - $this.outerHeight() - pad.bottom, | ||
end: containerOffset.top + $container.height(), | ||
parentTop: parentOffset.top | ||
}); | ||
if (!$this.parent().is(".pin-wrapper")) { | ||
$this.wrap("<div class='pin-wrapper'>"); | ||
} | ||
$this.css({width: $this.outerWidth()}); | ||
$this.parent().css("height", $this.outerHeight()); | ||
} | ||
}; | ||
var pad = $.extend({ | ||
top: 0, | ||
bottom: 0 | ||
}, options.padding || {}); | ||
var onScroll = function () { | ||
if (disabled) { return; } | ||
$this.data("pin", { | ||
pad: pad, | ||
from: (options.containerSelector ? containerOffset.top : offset.top) - pad.top, | ||
to: containerOffset.top + $container.height() - $this.outerHeight() - pad.bottom, | ||
end: containerOffset.top + $container.height(), | ||
parentTop: parentOffset.top | ||
}); | ||
scrollY = $window.scrollTop(); | ||
$this.css({ | ||
width: $this.outerWidth() | ||
}); | ||
$this.parent().css("height", $this.outerHeight()); | ||
} | ||
}; | ||
var elmts = []; | ||
for (var i=0, len=elements.length; i<len; i++) { | ||
var $this = $(elements[i]), | ||
data = $this.data("pin"); | ||
var onScroll = function() { | ||
if (disabled) { | ||
return; | ||
} | ||
if (!data) { // Removed element | ||
continue; | ||
} | ||
scrollY = $window.scrollTop(); | ||
elmts.push($this); | ||
var from = data.from - data.pad.bottom, | ||
to = data.to - data.pad.top; | ||
if (from + $this.outerHeight() > data.end) { | ||
$this.css('position', ''); | ||
continue; | ||
} | ||
if (from < scrollY && to > scrollY) { | ||
!($this.css("position") == "fixed") && $this.css({ | ||
left: $this.offset().left, | ||
top: data.pad.top | ||
}).css("position", "fixed"); | ||
if (options.activeClass) { $this.addClass(options.activeClass); } | ||
} else if (scrollY >= to) { | ||
$this.css({ | ||
left: "", | ||
top: to - data.parentTop + data.pad.top | ||
}).css("position", "absolute"); | ||
if (options.activeClass) { $this.addClass(options.activeClass); } | ||
} else { | ||
$this.css({position: "", top: "", left: ""}); | ||
if (options.activeClass) { $this.removeClass(options.activeClass); } | ||
} | ||
} | ||
elements = elmts; | ||
}; | ||
var elmts = []; | ||
for (var i = 0, len = elements.length; i < len; i++) { | ||
var $this = $(elements[i]), | ||
data = $this.data("pin"); | ||
var update = function () { recalculateLimits(); onScroll(); }; | ||
if (!data) { // Removed element | ||
continue; | ||
} | ||
this.each(function () { | ||
var $this = $(this), | ||
data = $(this).data('pin') || {}; | ||
elmts.push($this); | ||
if (data && data.update) { return; } | ||
elements.push($this); | ||
$("img", this).one("load", recalculateLimits); | ||
data.update = update; | ||
$(this).data('pin', data); | ||
}); | ||
var from = data.from - data.pad.bottom, | ||
to = data.to - data.pad.top; | ||
$window.scroll(onScroll); | ||
$window.resize(function () { recalculateLimits(); }); | ||
recalculateLimits(); | ||
if (from + $this.outerHeight() > data.end) { | ||
$this.css('position', ''); | ||
continue; | ||
} | ||
$window.load(update); | ||
if (from < scrollY && to > scrollY) { | ||
!($this.css("position") == "fixed") && $this.css({ | ||
left: $this.offset().left, | ||
top: data.pad.top | ||
}).css("position", "fixed"); | ||
if (options.activeClass) { | ||
$this.addClass(options.activeClass); | ||
} | ||
} else if (scrollY >= to) { | ||
$this.css({ | ||
left: "", | ||
top: to - data.parentTop + data.pad.top | ||
}).css("position", "absolute"); | ||
if (options.activeClass) { | ||
$this.addClass(options.activeClass); | ||
} | ||
} else { | ||
$this.css({ | ||
position: "", | ||
top: "", | ||
left: "" | ||
}); | ||
if (options.activeClass) { | ||
$this.removeClass(options.activeClass); | ||
} | ||
} | ||
} | ||
elements = elmts; | ||
}; | ||
return this; | ||
}; | ||
})(jQuery); | ||
var update = function() { | ||
recalculateLimits(); | ||
onScroll(); | ||
}; | ||
this.each(function() { | ||
var $this = $(this), | ||
data = $(this).data('pin') || {}; | ||
if (data && data.update) { | ||
return; | ||
} | ||
elements.push($this); | ||
$("img", this).one("load", recalculateLimits); | ||
data.update = update; | ||
$(this).data('pin', data); | ||
}); | ||
$window.scroll(onScroll); | ||
$window.resize(function() { | ||
recalculateLimits(); | ||
}); | ||
recalculateLimits(); | ||
$window.load(update); | ||
return this; | ||
}; |
{ | ||
"name": "jquery.pin", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "jquery pin plugin", | ||
@@ -22,3 +22,6 @@ "main": "jquery.pin.js", | ||
}, | ||
"homepage": "https://github.com/koyeo/jquery.pin#readme" | ||
"homepage": "https://github.com/koyeo/jquery.pin#readme", | ||
"dependencies": { | ||
"webpack-zepto": "0.0.1" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
365
186279
1
8
+ Addedwebpack-zepto@0.0.1
+ Addedwebpack-zepto@0.0.1(transitive)