Permalink
Browse files

Added jQuery back to keep demo working. Added jQuery namespace to plu…

…gin and removed plugin code from HTML file.
  • Loading branch information...
1 parent 4803b95 commit ffcf1bceb3b63d74ff76508d3ee27b3e723763ce @polarblau committed Oct 6, 2010
Showing with 60 additions and 40 deletions.
  1. +2 −40 index.html
  2. +58 −0 jquery.stickysectionheaders.js
View
@@ -5,6 +5,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="jquery.js" type="text/javascript" charset="utf-8"></script>
+ <script src="jquery.stickysectionheaders.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css" media="screen">
* { margin: 0; padding: 0; }
@@ -53,49 +54,10 @@
border-bottom: 1px solid #ccc;
}
- ul.sections .ui-selecting { background: #FECA40; }
- ul.sections .ui-selected { background: #F39814; color: white; }
-
</style>
<script type="text/javascript" charset="utf-8">
-
- $.fn.stickySectionHeaders = function(options) {
-
- var settings = $.extend({
- stickyClass: 'sticky',
- headlineSelector: 'strong'
- },
- options);
-
- return $(this).each(function() {
- var $this = $(this);
- $this.find('ul:first').scroll(function(e) {
- $this.find('ul:first > li').each(function() {
- var t = $(this).position().top;
- var h = $(this).outerHeight();
- var $s = $(this).find(settings.headlineSelector);
- var sh = $s.outerHeight();
- if (t < 0) {
- $(this).addClass(settings.stickyClass).css('paddingTop', sh);
- $s.css({
- 'width': $(this).outerWidth() - $s.cssSum('paddingLeft', 'paddingRight'),
- 'top': (h + t < sh) ? (sh - (t + h)) * -1 : ''
- });
- } else $(this).removeClass(settings.stickyClass).css('paddingTop', '');
- });
- });
- });
- };
-
- $.fn.cssSum = function() {
- var $self = $(this), sum = 0;
- $(arguments).each(function(i, e) {
- sum += parseInt($self.css(e), 10);
- });
- return sum;
- };
-
+
$(function() {
$('#container').stickySectionHeaders();
});
@@ -0,0 +1,58 @@
+/*!
+ * jQuery UI 1.8.2
+ *
+ * Copyright (c) 2010 Florian Plank (http://www.polarblau.com/)
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
+ * and GPL (GPL-LICENSE.txt) licenses.
+ *
+ * USAGE:
+ *
+ *
+ * $('#container').stickySectionHeaders({
+ * stickyClass : 'sticky',
+ * headlineSelector : 'strong'
+ * });
+ */
+
+(function($){
+ $.fn.stickySectionHeaders = function(options) {
+
+ var settings = $.extend({
+ stickyClass: 'sticky',
+ headlineSelector: 'strong'
+ }, options);
+
+ return $(this).each(function() {
+ var $this = $(this);
+ $this.find('ul:first').scroll(function(e) {
+ $this.find('ul:first > li').each(function() {
+ var t = $(this).position().top;
+ var h = $(this).outerHeight();
+ var $s = $(this).find(settings.headlineSelector);
+ var sh = $s.outerHeight();
+ if (t < 0) {
+ $(this).addClass(settings.stickyClass).css('paddingTop', sh);
+ $s.css({
+ 'width': $(this).outerWidth() - $s.cssSum('paddingLeft', 'paddingRight'),
+ 'top': (h + t < sh) ? (sh - (t + h)) * -1 : ''
+ });
+ } else $(this).removeClass(settings.stickyClass).css('paddingTop', '');
+ });
+ });
+ });
+ };
+
+ /* A little helper to calculate the sum of different
+ * CSS properties
+ *
+ * EXAMPLE:
+ * $('#my-div').cssSum('paddingLeft', 'paddingRight');
+ */
+ $.fn.cssSum = function() {
+ var $self = $(this), sum = 0;
+ $(arguments).each(function(i, e) {
+ sum += parseInt($self.css(e), 10);
+ });
+ return sum;
+ };
+})(jQuery);

0 comments on commit ffcf1bc

Please sign in to comment.