1jQuery(document).ready(function($) { 2 //get variables 3 var $wrap = $('#wtr-content'); 4 if($wrap.length > 0) { 5 wtrDebug('#wtr-content found'); 6 var $touch = $wrap.data('touch'); 7 var $non_touch = $wrap.data('non-touch'); 8 if((!isTouchDevice() && $non_touch) || (isTouchDevice() && $touch)) { 9 wtrDebug('touch device check passed'); 10 var $fg = $wrap.data('fg'), 11 $bg = $wrap.data('bg'), 12 $placement = $wrap.data('placement'), 13 $placement_offset = $wrap.data('placement-offset'), 14 $content_offset = $wrap.data('content-offset'), 15 $placement_touch = $wrap.data('placement-touch'), 16 $placement_offset_touch = $wrap.data('placement-offset-touch'), 17 $width = $wrap.data('width'), 18 $transparent = $wrap.data('transparent'), 19 $shadow = $wrap.data('shadow'), 20 $comments = $wrap.data('comments'), 21 $comments_bg = $wrap.data('commentsbg'), 22 $enable = $wrap.data('enable'), 23 $mute = $wrap.data('mute'), 24 $fgopacity = $wrap.data('fgopacity'), 25 $mutedopacity = $wrap.data('mutedopacity'), 26 $loc = $wrap.data('location'), 27 $end = $('.wtr-end'), 28 $rtl = $wrap.data('rtl'); 29 30 //set some defaults 31 if($fg === null || $fg === '') $fg = '#ef490f'; 32 if($bg === null || $bg === '') $bg = '#CCCCCC'; 33 if($width === null || $width === '') $width = 4; 34 if($comments_bg === null || $comments_bg === '') $comments_bg = '#999999'; 35 if($fgopacity === null || $fgopacity === '') $fgopacity = '.6'; 36 if($mutedopacity === null || $mutedopacity === '') $mutedopacity = '.5'; 37 if($transparent) { 38 $bg = 'none'; 39 $comments_bg = 'none'; 40 } 41 //get touch vs non-touch options 42 $placement = isTouchDevice() ? $placement_touch : $placement; 43 $placement_offset = isTouchDevice() ? $placement_offset_touch : $placement_offset; 44 var $placement_offset_admin = $placement_offset + getTopOffset(); 45 //setup dom elements and add to page 46 var $progress_bg = $('<div>', {id: 'wtr-progress', class: $placement}); 47 var $progress_fg = $('<div>', {id: 'wtr-slider'}); 48 $progress_bg.addClass('mute'); 49 //add rtl to wrapper element 50 if($rtl) $progress_bg.addClass('wtr-rtl'); 51 52 $progress_bg.css('background', $bg); 53 if($mute) $progress_bg.css('opacity', $mutedopacity); 54 55 $progress_fg.css('background', $fg); 56 $progress_fg.css('opacity', $fgopacity); 57 58 //determine end of content 59 var $contentHeight = $wrap.outerHeight(true) - $content_offset; 60 var $endOffset = $end.length > 0 ? $end.offset().top : 0; 61 var $shorter = $endOffset !== 0 ? ($contentHeight + $wrap.offset().top - $endOffset) : 0; 62 63 if($shorter) { 64 wtrDebug('content height is less than window height - progress bar will not be shown on this page'); 65 } else { 66 wtrDebug('content height is greater than window height - progress bar will be shown on this page'); 67 } 68 69 if($comments && !$shorter) { 70 wtrDebug('comments check passed'); 71 var $progress_comments = $('<div>', {id: 'wtr-progress-comments'}), 72 $commentsEnd = $('#wtr-comments-end'), 73 $progress = $('#wtr-progress'), 74 $wrap = $loc==='home' ? $('body') : $('#wtr-content'), 75 winHeight = $(window).height(), 76 totalHeight = $commentsEnd.offset().top - ($wrap.offset().top + $content_offset - $shorter), 77 commentsHeight = totalHeight - $contentHeight - (winHeight * .25), 78 orientation = 'left', 79 percentage = (100 - ((commentsHeight / totalHeight) * 100)); 80 //if position is right or left then our relative orientation is from the top 81 if($placement=='left' || $placement=='right') orientation = 'top'; 82 //change orientation to right if rtl option is selected 83 if($rtl && orientation=='left') orientation = 'right'; 84 //console.log('orientation=' + orientation); 85 $progress_comments.css(orientation, percentage + '%'); 86 $progress_comments.css('background', $comments_bg); 87 $progress_bg.append($progress_comments); 88 } 89 $progress_bg.append($progress_fg); 90 if($transparent) $progress_bg.addClass('transparent'); 91 if(!$shadow) $progress_bg.addClass('noshadow'); 92 $('body').append($progress_bg); 93 wtrDebug('progress bar added to DOM'); 94 95 //adjust style after it's loaded to the DOM 96 $hidden_by = $width + 6; 97 $hidden_by_admin = -$hidden_by + getTopOffset(); 98 $width = $width + 'px'; 99 $hidden_by = '-' + $hidden_by + 'px'; 100 $hidden_by_admin = '-' + $hidden_by_admin + 'px'; 101 102 $('#wtr-progress.left').css({'width': $width, 'left': $hidden_by}); 103 $('#wtr-progress.right').css({'width': $width, 'right': $hidden_by}); 104 $('#wtr-progress.bottom').css({'height': $width, 'bottom': $hidden_by}); 105 $('#wtr-progress.top').css({'height': $width, 'top': $hidden_by}); 106 $('.admin-bar #wtr-progress.top').css({'height': $width, 'top': $hidden_by_admin}); 107 108 //if there is an offset, update the "shown" class 109 if($placement_offset) { 110 wtrDebug('placement_offset check passed, .shown classes updated'); 111 var $showncss = '<style>' + 112 '#wtr-progress.top.shown {top:' + $placement_offset + 'px!important;}' + 113 '.admin-bar #wtr-progress.top.shown {top:' + $placement_offset_admin + 'px!important;}' + 114 '#wtr-progress.bottom.shown {bottom:' + $placement_offset + 'px!important;}' + 115 '#wtr-progress.left.shown {left:' + $placement_offset + 'px!important;}' + 116 '#wtr-progress.right.shown {right:' + $placement_offset + 'px!important;}' + 117 '</style>'; 118 $($showncss).appendTo('body'); 119 } 120 } 121 } else { 122 wtrDebug('#wtr-content not found'); 123 } 124 wtrDebug('preparing to call wtrProgress()'); 125 wtrProgress(); 126}); 127 128function wtrDebug(msg) { 129 if(jQuery('body').hasClass('wtr-debug-bar')) { 130 jQuery('#wtr-debug-bar').append('<span class="wtr-debug-message">' + msg + '</span>'); 131 } 132} 133 134//utility for determining touch devices 135function isTouchDevice() { 136 return 'ontouchstart' in window // works on most browsers 137 || window.navigator.msMaxTouchPoints > 0; // works on ie10 138} 139 140//finds whether the bottom of the element is in the viewport 141function bottomVisible(obj,offset){ 142 var a = obj.offset().top + offset, 143 b = obj.outerHeight(true), 144 c = jQuery(window).height(), 145 d = jQuery(window).scrollTop(); 146 return ((c+d) >= (a+b)); 147} 148//finds whether the top of the element is in the viewport
149function topVisible(obj,offset){ 150 var viewportHeight = jQuery(window).height(), 151 documentScrollTop = jQuery(document).scrollTop(), 152 minTop = documentScrollTop + offset, 153 maxTop = documentScrollTop + viewportHeight, 154 objOffset = obj.offset().top; 155 return (objOffset >= minTop && objOffset <= maxTop); 156} 157// check how much admin bar is showing 158function getTopOffset() { 159 topOffset = 0; 160 var $win = jQuery(window).width(); 161 if(jQuery('#wpadminbar').length > 0) { 162 if($win < 601) { 163 topOffset += 0; 164 } else if($win < 783) { 165 topOffset += 46; 166 } else { 167 topOffset += 32; 168 } 169 } 170 return topOffset; 171} 172 173function wtrProgress() { 174 var $win = jQuery(window), 175 $wrap = jQuery('#wtr-content'), 176 $progress = jQuery('#wtr-progress'), 177 $progress_comments = jQuery('#wtr-progress-comments'), 178 $slider = jQuery('#wtr-slider'), 179 $end = jQuery('.wtr-end'); 180 181 if($wrap.length > 0) { 182 183 var $touch = $wrap.data('touch'); 184 var $non_touch = $wrap.data('non-touch'); 185 var $mutedfg = $wrap.data('mutedfg'); 186 var $endfg = $wrap.data('endfg'); 187 var $fg = $wrap.data('fg'); 188 var $rtl = $wrap.data('rtl'); 189 var $endreached = false; 190 191 if((!isTouchDevice() && $non_touch) || (isTouchDevice() && $touch)) { 192 193 var $loc = $wrap.data('location'), 194 $contentOffset = $wrap.data('content-offset'), 195 $wrap = $loc==='home' ? jQuery('body') : jQuery('#wtr-content'), 196 wrapHeight = $wrap.outerHeight(true) - $contentOffset, 197 winHeight = $win.height(), 198 $endOffset = $end.length > 0 ? $end.offset().top : 0, 199 $shorter = $endOffset !== 0 ? (wrapHeight + $wrap.offset().top - $endOffset) : 0; 200 201 //reduce total wrap height if wtr-end shortcode is in place 202 //console.log($shorter); 203 wrapHeight -= $shorter; 204 205 //we only want to do this if the content is greater than the window height 206 //thus necessitating a visual progress indicator 207 if(wrapHeight > winHeight) { 208 var winScroll = $win.scrollTop(), 209 wrapOffset = $wrap.offset().top + $contentOffset, 210 beyond = winScroll - wrapOffset + winHeight * .75, 211 percentage = 0, 212 topOffset = getTopOffset(), 213 orientation = 'left', 214 $rel = $wrap; 215 //if position is right or left then our relative orientation is from the top 216 if($progress.hasClass('left') || $progress.hasClass('right')) orientation = 'top'; 217 //change orientation to right if rtl option is selected 218 if($rtl && orientation=='left') orientation = 'right'; 219 //do we need to account for comments? 220 if($progress_comments.length > 0) { 221 var $commentsEnd = jQuery('#wtr-comments-end'), 222 totalHeight = $commentsEnd.offset().top - wrapOffset, 223 commentsHeight = totalHeight - $wrap.outerHeight(true); 224 wrapHeight = totalHeight; 225 $rel = $commentsEnd; 226 } 227 //use wtr-end shortcode as bottom visible rel if it exists 228 if($shorter > 0) $rel = $end; 229 //we are into the content 230 if(bottomVisible($rel, winHeight * .25)) { 231 $slider.css(orientation, '0'); 232 $progress.addClass('mute'); 233 $slider.css('background', $endfg); 234 $endreached = true; 235 wtrDebug('end of content reached'); 236 } else if(beyond > 0 && winScroll > 0) { 237 $progress.addClass('shown').removeClass('mute'); 238 $slider.css('background', $fg); 239 //how far past the start are we? 240 percentage = -(100 - ((beyond / wrapHeight) * 100)); //get a negative percentage 241 $slider.css(orientation, percentage + '%'); 242 wtrDebug('progress bar percentage: ' + percentage); 243 } else { 244 //console.log('winScroll=' + winScroll + '\nwrapOffset=' + wrapOffset); 245 $slider.css(orientation, '-100%'); 246 $progress.removeClass('shown').removeClass('mute'); 247 $slider.css('background', $fg); 248 wtrDebug('content has not been scrolled into yet - hide progress bar'); 249 } 250 251 //mute progress bar after inactivity 252 if(!$endreached) { 253 clearTimeout(jQuery.data(this, 'scrollTimer')); 254 jQuery.data(this, 'scrollTimer', setTimeout(function() { 255 $progress.addClass('mute'); 256 $slider.delay(200).queue(function (next) { 257 wtrDebug('progress bar muted'); 258 jQuery(this).css('background', $mutedfg); 259 next(); 260 }); 261 }, 200)); 262 } 263 } else { 264 wtrDebug('content height is less than window height - no need to show progress bar'); 265 } 266 } 267 } 268} 269 270jQuery(window).scroll(function() { 271 wtrProgress(); 272});
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.