1/* 2 * fitSidebar 0.1 - jQuery plugin 3 * written by cyokodog 4 * 5 * Copyright (c) 2014 cyokodog 6 * http://www.cyokodog.net/ 7 * http://d.hatena.ne.jp/cyokodog/) 8 * http://cyokodog.tumblr.com/ 9 * MIT LICENCE 10 * 11 * Built for jQuery library 12 * http://jquery.com 13 * 14 */ 15;(function($){ 16 var s = $.fitSidebar = function(target, option){ 17 var o = this, c = o.config = $.extend({}, s.defaults, option); 18 c.target = $(target).addClass('fit-sidebar'); 19 c.blank = $('<div/>').addClass(s.id + '-blank').insertBefore(c.target); 20 c.blank.css('border','solid 1px #fff'); 21 c.blank.css({ 22 'margin-top' : c.target.css('margin-top'), 23 'margin-right' : c.target.css('margin-right'), 24 'margin-bottom' : c.target.css('margin-bottom'), 25 'margin-left' : c.target.css('margin-left'), 26 'border-top-width' : c.target.css('border-top-width'), 27 'border-right-width' : c.target.css('border-right-width'), 28 'border-bottom-width' : c.target.css('border-bottom-width'), 29 'border-left-width' : c.target.css('border-left-width'), 30 'padding-top' : c.target.css('padding-top'), 31 'padding-right' : c.target.css('padding-right'), 32 'padding-bottom' : c.target.css('padding-bottom'), 33 'padding-left' : c.target.css('padding-left') 34 }); 35 c.wrapper = $(c.target).parents(c.wrapper); 36 c._win = $(window) 37 .on('scroll', function(){ 38 o.adjustPosition(); 39 }) 40 .on('resize', function(){ 41 c.target.hasClass('for-chrome-bug'); 42 o.adjustPosition(); 43 }); 44 setTimeout(function(){ 45 o.adjustPosition(); 46 },0); 47 } 48 $.extend($.fitSidebar.prototype, { 49 adjustPosition : function(){ 50 var o = this, c = o.config; 51 if(c._win.width() < c.responsiveWidth){ 52 c.wrapper.removeClass(c.fixedClassName); 53 c.wrapper.addClass(c.noFixedClassName); 54 c.target.removeClass(s.id + '-fixed'); 55 c.blank.hide(); 56 c.target.width('auto'); 57 c.direction = null; 58 return; 59 } 60 c.wrapper.addClass(c.fixedClassName); 61 c.wrapper.removeClass(c.noFixedClassName); 62 c.target.addClass(s.id + '-fixed'); 63 var offset = c.blank.show().offset(); 64 var scrollTop = c._win.scrollTop() 65 var outerHeight = c.target.outerHeight(); 66 var overHeight = outerHeight - c._win.height(); 67 if(overHeight < 0) overHeight = 0; 68 if(!c.direction){ 69 c.lastFixedTop = c.lastDownFixedTop = c.lastUpFixedTop = offset.top - scrollTop; 70 c.lastScrollTop = c.lastDownScrollTop = c.lastUpScrollTop = scrollTop; 71 } 72 c.target.width(c.blank.width()); 73 c.blank.height(c.target.height()); 74 c.direction = scrollTop < c.lastScrollTop ? 'up' : 'down'; 75 var adjustDown = function(){ 76 var top = c.lastUpFixedTop + (c.lastUpScrollTop - scrollTop) 77 if(top < 0){ 78 if(top + overHeight < 0){ 79 top = -overHeight; 80 var limit = c.wrapper.offset().top + c.wrapper.height(); 81 var pos = scrollTop + outerHeight + top; 82 if(pos > limit){ 83 top = (limit - scrollTop) - outerHeight; 84 } 85 } 86 } 87 c.target.css({ 88 top : top, 89 bottom : 'auto' 90 }); 91 c.lastDownFixedTop = top; 92 c.lastDownScrollTop = scrollTop; 93 } 94 var adjustUp = function(){ 95 var top = c.lastDownFixedTop + (c.lastDownScrollTop - scrollTop) 96 if(top > 0){ 97 top = offset.top-scrollTop; 98 if(top < 0) top = 0; 99 } 100 c.target.css({ 101 top : top, 102 bottom : 'auto' 103 }); 104 c.lastUpFixedTop = top; 105 c.lastUpScrollTop = scrollTop; 106 } 107 if(c.direction == 'down'){ 108 adjustDown(); 109 } 110 else{ 111 adjustUp(); 112 } 113 c.lastFixedTop = top; 114 c.lastScrollTop = scrollTop; 115 } 116 }); 117 $.fn.fitSidebar = function(option){ 118 return this.each(function(){ 119 var el = $(this); 120 el.data(s.id, new $.fitSidebar(el, option)); 121 }); 122 } 123 $.extend(s, { 124 defaults : { 125 wrapper : 'body', // åã«ã©ã ãå æ¬ãã親åã¯å ç¥è¦ç´ 126 responsiveWidth : 0, // ã¬ã¹ãã³ã·ãã®ãã¬ã¼ã¯ãã¤ã³ã 127 fixedClassName : 'fit-sidebar-fixed-now', // åºå®æã« wrapperãã©ã¡ã¼ã¿æå®è¦ç´ ã«å²ãå½ã¦ãããã¯ã©ã¹å 128 noFixedClassName : 'fit-sidebar-no-fixed-now' // éåºå®æã« wrapperãã©ã¡ã¼ã¿æå®è¦ç´ ã«å²ãå½ã¦ãããã¯ã©ã¹å 129 }, 130 id : 'fit-sidebar' 131 }); 132})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.