1(function($) { 2 //the class 3 var crpFullScreenViewer = function(element, options){ 4 var target = "#" + $(element).attr("id"); 5 var plugin = this; 6 7 //set default images view mode 8 var $defaultViewMode=CRP_DEFAULT_FS_MODE; //full, normal, original 9 var $tsMargin=30; //first and last thumbnail margin (for better cursor interaction) 10 var $scrollEasing=600; //scroll easing amount (0 for no easing) 11 var $scrollEasingType="easeOutCirc"; //scroll easing type 12 var $thumbnailsContainerOpacity=0.8; //thumbnails area default opacity 13 var $thumbnailsContainerMouseOutOpacity=0; //thumbnails area opacity on mouse out 14 var $thumbnailsOpacity=0.6; //thumbnails default opacity 15 var $nextPrevBtnsInitState="show"; //next/previous image buttons initial state ("hide" or "show") 16 var $keyboardNavigation="on"; //enable/disable keyboard navigation ("on" or "off") 17 18 //cache vars 19 var $thumbnails_wrapper=$(target + " #thumbnails_wrapper"); 20 var $outer_container=$(target + " #outer_container"); 21 var $thumbScroller=$(target + " .thumbScroller"); 22 var $thumbScroller_container=$(target + " .thumbScroller .container"); 23 var $thumbScroller_content=$(target + " .thumbScroller .content"); 24 var $thumbScroller_thumb=$(target + " .thumbScroller .thumb"); 25 var $preloader=$(target + " #preloader"); 26 var $toolbar=$(target + " #toolbar"); 27 var $toolbar_a=$(target + " #toolbar a"); 28 var $bgimg=$(target + " #bgimg"); 29 var $img_title=$(target + " #img_title"); 30 var $nextImageBtn=$(target + " .nextImageBtn"); 31 var $prevImageBtn=$(target + " .prevImageBtn"); 32 var $viewModeBtn=$(target + " .viewModeBtn"); 33 34 var $nextViewMode="normal"; //full, normal, original 35 36 var $totalContent=0; 37 var $fadeSpeed=200; 38 39 var the1stImg = null; 40 var the1stImgSrc = ""; 41 42 if(options.bgsrc){ 43 the1stImgSrc = options.bgsrc; 44 } 45 46 $(window).load(function() { 47 $toolbar.data("imageViewMode",$defaultViewMode); //default view mode 48 if($defaultViewMode=="full"){ 49 $nextViewMode = "normal"; 50 $viewModeBtn.removeClass("maximize"); 51 $viewModeBtn.addClass("minimize"); 52 $viewModeBtn.attr("title", "Restore"); 53 } else { 54 $nextViewMode = "full"; 55 $viewModeBtn.removeClass("minimize"); 56 $viewModeBtn.addClass("maximize"); 57 $viewModeBtn.attr("title", "Maximize"); 58 } 59 60 ShowHideNextPrev($nextPrevBtnsInitState); 61 //thumbnail scroller 62 $thumbScroller_container.css("marginLeft",$tsMargin+"px"); //add margin 63 var sliderLeft=$thumbScroller_container.position().left; 64 var sliderWidth=$outer_container.width(); 65 $thumbScroller.css("width",sliderWidth); 66 67 var $the_outer_container= $( target + " #outer_container" ).get( 0 ); //document.getElementById("outer_container"); 68 var $placement=findPos($the_outer_container); 69 70 calcScrollerWidth(); 71 72 var idleTimer = null; 73 var idleState = false; 74 var idleWait = 600; 75 76 $thumbScroller.mousemove(function(e){ 77 if($thumbScroller_container.width()>sliderWidth){ 78 var mouseCoords=(e.pageX - $placement[1]); 79 var mousePercentX=mouseCoords/sliderWidth; 80 var destX=-(((($totalContent+($tsMargin*2))-(sliderWidth))-sliderWidth)*(mousePercentX)); 81 var thePosA=mouseCoords-destX; 82 var thePosB=destX-mouseCoords; 83 if(mouseCoords>
83destX){ 84 $thumbScroller_container.stop().animate({left: -thePosA}, $scrollEasing,$scrollEasingType); //with easing 85 } else if(mouseCoords<destX){ 86 $thumbScroller_container.stop().animate({left: thePosB}, $scrollEasing,$scrollEasingType); //with easing 87 } else { 88 $thumbScroller_container.stop(); 89 } 90 } 91 92 //Recalculate content width 93 clearTimeout(idleTimer); 94 if (idleState == true) { 95 // Reactivated event 96 calcScrollerWidth(); 97 } 98 idleState = false; 99 idleTimer = setTimeout(function () { 100 // Idle Event 101 idleState = true; 102 }, idleWait); 103 }); 104 105 $thumbnails_wrapper.fadeTo($fadeSpeed, $thumbnailsContainerOpacity); 106 $thumbnails_wrapper.hover( 107 function(){ //mouse over 108 var $this=$(this); 109 $this.stop().fadeTo("slow", 1); 110 }, 111 function(){ //mouse out 112 var $this=$(this); 113 $this.stop().fadeTo("slow", $thumbnailsContainerMouseOutOpacity); 114 } 115 ); 116 117 $thumbScroller_thumb.hover( 118 function(){ //mouse over 119 var $this=$(this); 120 $this.stop().fadeTo($fadeSpeed, 1); 121 }, 122 function(){ //mouse out 123 var $this=$(this); 124 $this.stop().fadeTo($fadeSpeed, $thumbnailsOpacity); 125 } 126 ); 127 128 //on window resize scale image and reset thumbnail scroller 129 $(window).resize(function() { 130 if($(target).parent().css("display") == "none"){ 131 return; 132 } 133 134 calcScrollerWidth(); 135 136 FullScreenBackground(target + " #bgimg",$bgimg.data("newImageW"),$bgimg.data("newImageH")); 137 $thumbScroller_container.stop().animate({left: sliderLeft}, 400,"easeOutCirc"); 138 var newWidth=$outer_container.width(); 139 $thumbScroller.css("width",newWidth); 140 sliderWidth=newWidth; 141 $placement=findPos($the_outer_container); 142 }); 143 144 //load 1st image 145 the1stImg = new Image(); 146 the1stImg.onload = CreateDelegate(the1stImg, theNewImg_onload); 147 //the1stImg.src = $($bgimg).attr("src"); 148 $outer_container.data("nextImage",$(target + " .content").first().next().find("a").attr("href")); 149 $outer_container.data("prevImage",$(target + " .content").last().find("a").attr("href")); 150 151 if(!$outer_container.data("nextImage") && !$outer_container.data("prevImage")) 152 $thumbScroller.css("display","none"); 153 }); 154 155 function calcScrollerWidth(){ 156 $totalContent = 0; 157 $thumbScroller_content.each(function () { 158 var $this=$(this); 159 $totalContent+=$this.innerWidth(); 160 $thumbScroller_container.css("width",$totalContent); 161 $this.children().children().children(target + " .thumb").fadeTo($fadeSpeed, $thumbnailsOpacity); 162 }); 163 } 164 165 function loadFirstImage(){ 166 167 } 168 169 function resetScroller(){ 170 171 } 172
173 function updateBackground(){ 174 175 } 176 177 this.loadThumbnails = function(){ 178 $thumbScroller_content.each(function () { 179 var $this=$(this); 180 181 var thumbSrc = $this.children().children(target + " .crp-thumb-a").attr("data-thumb"); 182 var thumb = $this.children().children().children(target + " .thumb"); 183 thumb.attr("src",thumbSrc); 184 }); 185 } 186 187 function BackgroundLoad($this,imageWidth,imageHeight,imgSrc){ 188 $this.fadeOut("fast",function(){ 189 $this.attr("src", "").attr("src", imgSrc); //change image source 190 FullScreenBackground($this,imageWidth,imageHeight); //scale background image 191 $preloader.fadeOut("fast",function(){$this.fadeIn("slow");}); 192 193 //Note: This functionality is disabled 194 /* 195 var imageTitle=$img_title.data("imageTitle"); 196 if(imageTitle){ 197 $this.attr("alt", imageTitle).attr("title", imageTitle); 198 $img_title.fadeOut("fast",function(){ 199 $img_title.html(imageTitle).fadeIn(); 200 }); 201 } else { 202 $img_title.fadeOut("fast",function(){ 203 $img_title.html($this.attr("title")).fadeIn(); 204 }); 205 } 206 */ 207 }); 208 } 209 210 //mouseover toolbar 211 if($toolbar.css("display")!="none"){ 212 $toolbar.fadeTo("fast", 0.4); 213 } 214 $toolbar.hover( 215 function(){ //mouse over 216 var $this=$(this); 217 $this.stop().fadeTo("fast", 1); 218 }, 219 function(){ //mouse out 220 var $this=$(this); 221 $this.stop().fadeTo("fast", 0.4); 222 } 223 ); 224 225 //Clicking on thumbnail changes the background image 226 $(target + " #outer_container a").click(function(event){ 227 event.preventDefault(); 228 var $this=$(this); 229 GetNextPrevImages($this); 230 GetImageTitle($this); 231 SwitchImage(this); 232 ShowHideNextPrev("show"); 233 }); 234 235 //next/prev images buttons 236 $nextImageBtn.click(function(event){ 237 event.preventDefault(); 238 if(!$outer_container.data("nextImage")) 239 return; 240 241 SwitchImage($outer_container.data("nextImage")); 242 var $this=$(target + " #outer_container a[href='"+$outer_container.data("nextImage")+"']"); 243 GetNextPrevImages($this); 244 GetImageTitle($this); 245 }); 246 247 $prevImageBtn.click(function(event){ 248 event.preventDefault(); 249 if(!$outer_container.data("prevImage")) 250 return; 251 252 SwitchImage($outer_container.data("prevImage")); 253 var $this=$(target + " #outer_container a[href='"+$outer_container.data("prevImage")+"']"); 254 GetNextPrevImages($this); 255 GetImageTitle($this); 256 }); 257 258 $viewModeBtn.click(function(event){ 259 event.preventDefault(); 260 ImageViewMode($nextViewMode); 261 }); 262 263 //next/prev images keyboard arrows 264 if($keyboardNavigation=="on"){ 265 $(document).keydown(function(ev) { 266 if(ev.keyCode == 39) { //right arrow 267 SwitchImage($outer_container.data("nextImage")); 268 var $this=$(target + " #outer_container a[href='"+$outer_container.data("nextImage")+"']"); 269 GetNextPrevImages($this); 270 GetImageTitle($this); 271 return false; // don't execute the default action (scrolling or whatever) 272 } else if(ev.keyCode == 37) { //left arrow 273 SwitchImage($outer_container.data("prevImage")); 274 var $this=$(target + " #outer_container a[href='"+$outer_container.data("prevImage")+"']"); 275 GetNextPrevImages($this); 276 GetImageTitle($this); 277 return false; // don't execute the default action (scrolling or whatever) 278 } 279 }); 280 } 281 282 function ShowHideNextPrev(state){ 283 if(state=="hide"){ 284 $nextImageBtn.fadeOut(); 285 $prevImageBtn.fadeOut(); 286 } else { 287 $nextImageBtn.fadeIn(); 288 $prevImageBtn.fadeIn(); 289 } 290 } 291 292 //get image title 293 function GetImageTitle(elem){ 294 //Note: This funciotnality is disabled 295 /* 296 var title_attr=elem.children("img").attr("title"); //get image title attribute 297 $img_title.data("imageTitle", title_attr); //store image title 298 */ 299 } 300 301 //get next/prev images 302 function GetNextPrevImages(curr){ 303 var nextImage=curr.parents(target + " .content").next().find("a").attr("href"); 304 if(nextImage==null){ //if last image, next is first 305 var nextImage=$(target + " .content").first().find("a").attr("href"); 306 } 307 $outer_container.data("nextImage",nextImage); 308 var prevImage=curr.parents(target + " .content").prev().find("a").attr("href"); 309 if(prevImage==null){ //if first image, previous is last 310 var prevImage=$(target + " .content").last().find("a").attr("href"); 311 } 312 $outer_container.data("prevImage",prevImage); 313 } 314 315 //switch image 316 function SwitchImage(img){ 317 $preloader.fadeIn("fast"); //show preloader 318 var theNewImg = new Image(); 319 theNewImg.onload = CreateDelegate(theNewImg, theNewImg_onload); 320 theNewImg.src = img; 321 } 322 323 //get new image dimensions 324 function CreateDelegate(contextObject, delegateMethod){ 325 return function(){ 326 return delegateMethod.apply(contextObject, arguments); 327 } 328 } 329 330 //new image on load 331 function theNewImg_onload(){ 332 $bgimg.data("newImageW",this.width).data("newImageH",this.height);
333 BackgroundLoad($bgimg,this.width,this.height,this.src); 334 } 335 336 //Image scale function 337 function FullScreenBackground(theItem,imageWidth,imageHeight){ 338 var winWidth=$(window).width(); 339 var winHeight=$(window).height(); 340 if($toolbar.data("imageViewMode")!="original"){ //scale 341 var picHeight = imageHeight / imageWidth; 342 var picWidth = imageWidth / imageHeight; 343 if($toolbar.data("imageViewMode")=="full"){ //fullscreen size image mode 344 if ((winHeight / winWidth) < picHeight) { 345 $(theItem).attr("width", winWidth); 346 $(theItem).attr("height",picHeight*winWidth); 347 } else { 348 $(theItem).attr("height",winHeight); 349 $(theItem).attr("width",picWidth*winHeight); 350 }; 351 } else { //normal size image mode 352 if ((winHeight / winWidth) > picHeight) { 353 $(theItem).attr("width",winWidth); 354 $(theItem).attr("height",picHeight*winWidth); 355 } else { 356 $(theItem).attr("height",winHeight); 357 $(theItem).attr("width",picWidth*winHeight); 358 }; 359 } 360 361 $(theItem).css("margin-left",(winWidth-$(theItem).width())/2); 362 $(theItem).css("margin-top",(winHeight-$(theItem).height())/2); 363 } else { //no scale 364 $(theItem).attr("width",imageWidth); 365 $(theItem).attr("height",imageHeight); 366 $(theItem).css("margin-left",(winWidth-imageWidth)/2); 367 $(theItem).css("margin-top",(winHeight-imageHeight)/2); 368 } 369 } 370 371 //Image view mode function - fullscreen or normal size 372 function ImageViewMode(theMode){ 373 $toolbar.data("imageViewMode", theMode); 374 FullScreenBackground($bgimg,$bgimg.data("newImageW"),$bgimg.data("newImageH")); 375 if(theMode=="full"){ 376 $nextViewMode = "normal"; 377 $viewModeBtn.removeClass("maximize"); 378 $viewModeBtn.addClass("minimize"); 379 $viewModeBtn.attr("title", "Restore"); 380 } else { 381 $nextViewMode = "full"; 382 $viewModeBtn.removeClass("minimize"); 383 $viewModeBtn.addClass("maximize"); 384 $viewModeBtn.attr("title", "Maximize"); 385 } 386 } 387 388 //function to find element Position 389 function findPos(obj) { 390 var curleft = curtop = 0; 391 if (obj.offsetParent) { 392 curleft = obj.offsetLeft 393 curtop = obj.offsetTop 394 while (obj = obj.offsetParent) { 395 curleft += obj.offsetLeft 396 curtop += obj.offsetTop 397 } 398 } 399 return [curtop, curleft]; 400 } 401 402 return { 403 prepareToShow: function() { 404 if(!the1stImg.src){ 405 the1stImg.src = the1stImgSrc; 406 }else{ 407 $($bgimg).fadeOut(0,0); 408 $($bgimg).fadeIn("slow"); 409 } 410 411 plugin.loadThumbnails(); 412 413 //Important FS bug fix 414 jQuery(window).trigger("resize"); 415 } 416 } 417 } 418 419 $.fn.crpFullScreenViewer = function (options) { 420 //NOTE: single plugin with the same identifier 421 var plugin = $(this).data('crpFullScreenViewer'); 422 if (undefined == plugin) { 423 plugin = new crpFullScreenViewer(this, options); 424 $(this).data('crpFullScreenViewer', plugin); 425 } 426 return plugin; 427 } 428})(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.