1//console.log('strx-floating-sidebar/js/main.js loaded ok'); 2strx = {}; 3if (typeof console === 'undefined') { 4 console = { 5 log: function () {}, 6 dir: function () {} 7 }; 8} 9 10(function () { 11 strx.start = function (opts) { 12 jQuery(function () { 13 opts = jQuery.extend({}, { 14 content: '#content', 15 sidebar: '#sidebar', 16 wait: 3000, 17 debounce: 500, 18 animate: 3000, 19 offsetTop: 0, 20 offsetBottom: 0, 21 debug: 0, 22 outline: 0, 23 findids: 0, 24 minHDiff:0 25 }, opts); 26 27 setTimeout(function(){ 28 29 var $w = jQuery(window), 30 $c = jQuery(opts.content), 31 $ss = jQuery(opts.sidebar), 32 $b = jQuery('body'); 33 34 if (opts.outline) { 35 $ss.add($c).css('outline', '3px dashed red'); 36 } 37 38 if (opts.findids) { 39 strx.findids(); 40 } 41 42 console.dir(opts); 43 44 if ($c.length && $ss.length) { 45 $ss.each(function () { 46 (function ($s) { 47 // console.log($c.height() - $s.height()); 48 if ( $c.height() - $s.height() > opts.minHDiff || opts.dynamicTop) { 49 $s.parent().css('position', 'relative'); 50 var initialSPos=$s.position(), 51 initialSOff=$s.offset(); 52 53 //Recupero Top e Left iniziali di tutte le sidebar prima di iniziare il posizionamento 54 setTimeout(function(){ 55 $s.css({ 56 position: 'absolute', 57 left: initialSPos.left + 'px', 58 top: initialSPos.top + 'px' 59 }).find('.widget').css('position', 'relative'); 60 61 var lastScrollY = -1, 62 sidebarTop = initialSPos.top, 63 offsetTop = initialSOff.top - sidebarTop, 64 maxTop = sidebarTop + $c.height() - $s.outerHeight(), 65 onScroll = function (e) { 66 var scrollY = $w.scrollTop(), 67 t, scrollingDown = scrollY > lastScrollY; 68 69 if ((scrollingDown && scrollY > sidebarTop + offsetTop && scrollY + $w.height() > $s.position().top + $s.height() + offsetTop - sidebarTop) || (!scrollingDown && scrollY < $s.position().top + offsetTop)) { 70 if (e.type === 'scroll' && ($w.height() > $s.height() || !scrollingDown)) { 71 //Scorrimento verso l'alto 72 t = Math.max(sidebarTop, scrollY - (offsetTop) + (~~opts.offsetTop)); 73 } else { 74 //Scorrimento verso il basso o resize 75 t = Math.max(sidebarTop, scrollY + $w.height() - $s.outerHeight() - offsetTop - (~~opts.offsetBottom)); 76 } 77 78 t = Math.min(t, opts.dynamicTop ? (sidebarTop + $c.height() - $s.outerHeight()) : maxTop); 79 $s.stop().animate({ 80 top: t + 'px' 81 }, ~~opts.animate); 82 83 if (opts.debug) { 84 window.scrollY = scrollY; 85 console.log('top=' + t + ', scrollY=' + scrollY); 86 } 87 } 88 lastScrollY = scrollY; 89 }; 90 if (opts.debug) { 91 window.$w = $w; 92 window.$c = $c; 93 window.$s = $s; 94 window.$b = $b; 95 window.offsetTop = offsetTop; 96 window.sidebarTop = sidebarTop; 97 window.maxTop = maxTop; 98 console.log('windowHeight=' + $w.height() + ', sidebarOuterHeight=' + $s.outerHeight() + ', sidebarTop=' + sidebarTop + ', offsetTop=' + offsetTop + ', maxTop=' + maxTop); 99 } 100 101 if (opts.debounce && Function.prototype.debounce) { 102 onScroll = onScroll.debounce(opts.debounce); 103 } 104 105 $w.scroll(onScroll).resize(onScroll); 106 onScroll({ 107 type: 'scroll' 108 }); 109 110 $w.scroll(function(){ 111 $s.stop(); 112 }); 113 },0); 114 115 } 116 })(jQuery(this)); 117 }); 118 119 } else { 120 if ($c.length === 0) { 121 console.log(opts.content + ' not found'); 122 } 123 if ($ss.length === 0) { 124 console.log(opts.sidebar + ' not found'); 125 } 126 } 127 128 }, opts.wait); 129 130 }); 131 }; 132 //Help user find the correct content and sidebar divs 133 strx.findids = function () { 134 var divs = jQuery('div[id]').get(); 135 divs = jQuery.map(divs, function (d) { 136 return '<span class="strx-mfsm-findids" style="cursor:pointer; font-weight:bold;">' + d.id + '</span>'; 137 }); 138 var $divs = jQuery('<span>' + divs.join(' ') + '</span>').appendTo('body').click(function (e) { 139 var $t = jQuery('#' + jQuery(e.target).html()); 140 //console.log($t.html()); 141 var origbg = $t.css('background-color'); 142 $t.css({ 143 backgroundColor: 'red' 144 }); 145 setTimeout(function () { 146 $t.css({ 147 backgroundColor: 'green' 148 }); 149 }, 3000); 150 setTimeout(function () { 151 $t.css({ 152 backgroundColor: 'blue' 153 }); 154 }, 6000); 155 setTimeout(function () { 156 $t.css({ 157 backgroundColor: origbg 158 }); 159 }, 9000); 160 161 alert('If the main content background color change, write \n#' + jQuery(e.target).html() + '\n in the Content Selector field' + '\n\n' + 'If the sidebar background color change, write \n#' + jQuery(e.target).html() + '\n in the Sidebar Selector field'); 162 163 }); 164 }; 165})();
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.