1 2function RBParallaxControllerItem(mediastate, section, layer, property, from, to, unit, mode, specclass, delay, offsetpos, offsetposY) { 3 this.mediastate = mediastate; 4 this.section = section; 5 this.layer = layer; 6 this.property = property; 7 this.from = from; 8 this.to = to; 9 this.unit = unit; 10 this.mode = mode; 11 this.init = true; 12 this.duration = 2000; 13 this.specclass = specclass; 14 this.delay = delay; 15 this.offsetpos = offsetpos; 16 this.offsetposY = offsetposY; 17 return this; 18} 19 20function RBParallaxController() { 21 var items = new Array(); 22 /*var base = this; 23 var id = base[0].id; 24 var $root = $(this);*/ 25 var msg = ""; 26 var direction = 1; 27 var directionlength = 0; 28 var lastY = 0; 29 30 this.initialize = function () { 31 32 initCSS(); 33 34 initEvent(); 35 } 36 function initCSS() { 37 } 38 39 function initEvent() { 40 $(window).bind('scroll', function (e) { 41 ParallaxScroll(); 42 }); 43 $(window).on('touchmove', function (e) { 44 ParallaxScroll(); 45 }); 46 $(window).on('resize', ParallaxScroll); 47 $(document).on("mediastatechanged", ParallaxScroll); 48 } 49 50 this.AddItem = function (mediastate, section, layer, property, from, to, unit, delay) { 51 var item = new RBParallaxControllerItem(mediastate, section, layer, property, from, to, unit, "", "", delay, 0); 52 items.push(item); 53 54 ParallaxScrollItem(item); 55 56 return item; 57 } 58 59 this.AddStayTopItem = function (mediastate, section, layer, from) { 60 var item = new RBParallaxControllerItem(mediastate, section, layer, "", from, "", "", "stayontop", "", "", 0); 61 items.push(item); 62 63 ParallaxScrollItem(item); 64 65 return item; 66 } 67 68 this.AddItemOnce = function (mediastate, section, layer, property, from, to, unit, duration, delay) { 69 var item = new RBParallaxControllerItem(mediastate, section, layer, property, from, to, unit, "once", "", delay, 0); 70 if (duration) 71 item.duration = duration; 72 items.push(item); 73 74 ParallaxScrollItem(item); 75 76 return item; 77 } 78 79 this.AddTopClassItem = function (mediastate, property, from, specclass, offsetposY) { 80 var item = new RBParallaxControllerItem(mediastate, "", "", property, from, "", "", "topclass", specclass, "", 0, offsetposY); 81 items.push(item); 82 83 ParallaxScrollItem(item); 84 85 return item; 86 } 87 88 function ParallaxScroll() { 89 CheckParallaxScrollDirection(); 90 for (i = 0; i < items.length; ++i) { 91 ParallaxScrollItem(items[i]); 92 } 93 } 94 95 function CheckParallaxScrollDirection() { 96 var scrolledY = $(window).scrollTop(); 97 if (scrolledY == lastY) 98 return; 99 if (scrolledY > lastY) { 100 if (direction != 1) { 101 direction = 1; 102 directionlength = 0; 103 $('body').removeClass("rb-parallax_direction-up").removeClass("rb-parallax_direction-down"); 104 } 105 directionlength = directionlength + (scrolledY - lastY); 106 if (directionlength > 100) 107 if (!$('body').hasClass("rb-parallax_direction-down")) 108 $('body').addClass("rb-parallax_direction-down"); 109 } 110 else { 111 if (direction != -1) { 112 direction = -1; 113 directionlength = 0; 114 $('body').removeClass("rb-parallax_direction-up").removeClass("rb-parallax_direction-down"); 115 } 116 directionlength = directionlength + (lastY - scrolledY); 117 if (directionlength > 100) 118 if (!$('body').hasClass("rb-parallax_direction-up")) 119 $('body').addClass("rb-parallax_direction-up"); 120 } 121 lastY = scrolledY; 122 } 123 124 function ParallaxScrollItem(item) { 125 if (item.mediastate != "") 126 if (item.mediastate.indexOf(RBMediaState) == -1) 127 return; 128 129 var scrolledY = $(window).scrollTop(); 130 if (item.mode == "topclass") { 131 if (item.from) { 132 if (scrolledY > item.from) { 133 $(item.property).addClass(item.specclass); 134 } 135 else { 136 $(item.property).removeClass(item.specclass); 137 } 138 } 139 else { 140 var offsetpos = item.offsetpos; 141 if (offsetpos == 0) { 142 var itemposition = $(item.property).offset(); 143 if (itemposition) 144 offsetpos = itemposition.top - $(window).height() + item.offsetposY; 145 } 146 if (scrolledY > offsetpos) { 147 $(item.property).addClass(item.specclass); 148 } 149 else { 150 $(item.property).removeClass(item.specclass); 151 } 152 } 153 return; 154 } 155 156 var windowheight = $(window).height(); 157 var itemsection = $("#" + item.section); 158 if (!itemsection) 159 return; 160 if (itemsection.length == 0) 161 return; 162 var sectionposition = itemsection.position(); 163 var top = sectionposition.top; 164 var height = itemsection.height(); 165 if (item.delay) { 166 top += item.delay; 167 height -= item.delay; 168 } 169 170 var worktop = top - windowheight; 171 var workbottom = worktop + height + windowheight; 172 if (item.delay) { 173 workbottom += item.delay; 174 } 175 var sectionBottom = worktop + height; 176 177 var log = false; 178 if (log) { 179 var message = item.section; 180 if (item.layer) 181 message += "/" + item.layer; 182 if (item.mode) 183 message += "(" + item.mode + ")"; 184 message += ":"; 185 message += " scrolledY:" + parseInt(scrolledY); 186 message += ", " + "worktop:" + parseInt(worktop); 187 message += ", " + "workbottom:" + parseInt(workbottom); 188 189 RBLogger(message); 190 } 191 192 var result = 0; 193 var layerItem = "#" + item.section; 194 if (item.layer) 195 layerItem += " ." + item.layer; 196 if (item.mode == "stayontop") { 197 if (scrolledY > top) { 198 $(layerItem).addClass("parallaxsection_fixed"); 199 var maxheight = height - (scrolledY - top) - item.from; 200 if (maxheight < 0) 201 maxheight = 0; 202 $(layerItem).css("max-height", maxheight + "px"); 203 } 204 else { 205 $(layerItem).removeClass("parallaxsection_fixed"); 206 $(layerItem).css("max-height", ""); 207 } 208 return; 209 } 210 if (item.mode == "once") { 211 if ((scrolledY <= worktop) || (scrolledY >= workbottom)) { 212 if (!item.init) { 213 item.init = true; 214 $(layerItem).css(item.property, item.from + item.unit); 215 } 216 } 217 else { 218 if (item.init) { 219 item.init = false; 220 $(layerItem).css(item.property, item.from + item.unit); 221 var animationProperties = {}; 222 animationProperties[item.property] = item.to + item.unit; 223 $(layerItem).animate(animationProperties, { duration: item.duration, queue: false }); 224 } 225 } 226 return; 227 } 228 if (scrolledY <= worktop) { 229 result = item.from; 230 } 231 else { 232 if (scrolledY >= workbottom) 233 result = item.to; 234 else { 235 result = item.from; 236 if (height > 0) { 237 if (item.mode == "fixed") { 238 result = (scrolledY - worktop) - height; 239 } 240 else { 241 var heightdiff = height * 2; 242 var workscroll = scrolledY - worktop; 243 var scale = (workscroll / heightdiff); 244 var resultdiff = item.to - item.from; 245 result = (resultdiff * scale) + parseInt(item.from); 246 } 247 } 248 } 249 } 250 $(layerItem).css(item.property, result + item.unit); 251 } 252 253 /* 254 Start 255 */ 256 this.initialize(); 257 258 return this; 259}
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.