1 2jQuery(document).ready(function($) { 3 4 // gallery faded layer and container elements 5 var overlay, comments, gallery, container, nextButton, previousButton, info, title, 6 caption, resizeTimeout, mouseTimeout, photo_info, close_hint, commentInterval, buttons, 7 screenPadding = 110, originalOverflow = $('body').css('overflow'), originalHOverflow = $('html').css('overflow'), proportion = 85, isMobile; 8 9 isMobile = /Android|iPhone|iPod/i.test(navigator.userAgent); 10 11 if (isMobile) 12 screenPadding = 0; 13 14 var keyListener = function(e){ 15 switch(e.which){ 16 case 38: // up 17 e.preventDefault(); 18 container.scrollTop(container.scrollTop() - 100); 19 break; 20 case 40: // down 21 e.preventDefault(); 22 container.scrollTop(container.scrollTop() + 100); 23 break; 24 case 39: // right 25 e.preventDefault(); 26 gallery.jp_carousel('clearCommentTextAreaValue'); 27 gallery.jp_carousel('next'); 28 break; 29 case 37: // left 30 e.preventDefault(); 31 gallery.jp_carousel('clearCommentTextAreaValue'); 32 gallery.jp_carousel('previous'); 33 break; 34 case 27: // escape 35 e.preventDefault(); 36 gallery.jp_carousel('clearCommentTextAreaValue'); 37 container.jp_carousel('close'); 38 break; 39 default: 40 // making jslint happy 41 break; 42 } 43 }; 44 45 var resizeListener = function(e){ 46 clearTimeout(resizeTimeout); 47 resizeTimeout = setTimeout(function(){ 48 gallery 49 .jp_carousel('slides') 50 .jp_carousel('fitSlide', true); 51 gallery 52 .jp_carousel('fitInfo', true) 53 .jp_carousel('fitMeta', true); 54 }, 200); 55 }; 56 57 // For each image in the carousel, emit likes widget markup 58 var getCarouselLikeWidgets = function( dataCarouselExtra ) { 59 60 // Only do this if likes is enabled 61 if ( "undefined" === typeof jetpackLikesWidgetQueue ) 62 return ""; 63 64 var blogId = dataCarouselExtra.likes_blog_id; 65 var attachmentId = 0; 66 var protocol = 'http'; 67 var originDomain = 'http://wordpress.com'; 68 69 if ( dataCarouselExtra.permalink.length ) { 70 var parts = dataCarouselExtra.permalink.split( ':' ); 71 var protocol = parts[0]; 72 if ( ( protocol != 'http' ) && ( protocol != 'https' ) ) { 73 protocol = 'http'; 74 } 75 76 parts = dataCarouselExtra.permalink.split( '/' ); 77 if ( parts.length >= 2 ) { 78 originDomain = protocol + "://" + parts[2]; 79 } 80 } 81 82 var likesWidgetContainer = $("<div class='likes-widget-container'></div>"); 83 84 $( 'div.gallery, div.tiled-gallery' ).find( 'img' ).each( function() { 85 86 attachmentId = $( this ).attr( "data-attachment-id" ); 87 var dataSource = protocol + "://widgets.wp.com/likes/#blog_id=" + blogId + "&post_id=" + attachmentId + "&slim=1&origin=" + originDomain; 88 89 if ( 'en' !== jetpackCarouselStrings.lang ) { 90 dataSource += "&lang=" + jetpackCarouselStrings.lang; 91 } 92 93 var likesWidgetWrapper = $( "<div></div>" ); 94 likesWidgetWrapper.addClass( "jetpack-likes-widget-wrapper" ) 95 .addClass( "jetpack-likes-widget-unloaded" ) 96 .addClass( "slim-likes-widget" ) 97 .attr( "id", "like-post-wrapper-" + blogId + "-" + attachmentId ) 98 .attr( "data-src", dataSource ) 99 .attr( "data-name", "like-post-frame-" + blogId + "-" + attachmentId ) 100 .attr( "data-attachment-id", attachmentId ) 101 .css( "display", "none" ) 102 .css( "vertical-align", "middle" ); 103 104 var likesWidget = $( "<iframe class='post-likes-widget jetpack-likes-widget jetpack-resizeable'></iframe>" ); 105 likesWidget.attr( "name", "like-post-frame-" + blogId + "-" + attachmentId ) 106 .attr( "src", dataSource ); 107 likesWidget.css( "display", "inline-block" ); 108 likesWidgetWrapper.append( likesWidget ); 109 110 likesWidgetWrapper.append( "<div class='post-likes-widget-placeholder'></div>" ); 111 112 likesWidgetContainer.append( likesWidgetWrapper ); 113 }); 114 115 return likesWidgetContainer.html(); 116 }; 117 118 var prepareGallery = function( dataCarouselExtra ){ 119 buttons =''; 120 if (!overlay) { 121 overlay = $('<div></div>') 122 .addClass('jp-carousel-overlay') 123 .css({ 124 'position' : 'absolute', 125 'top' : 0, 126 'right' : 0, 127 'bottom' : 0, 128 'left' : 0 129 }); 130if (jetpackCarouselStrings.comment ) { 131 buttons = '<a class="jp-carousel-commentlink" href="#">
131' + jetpackCarouselStrings.comment + '</a>'; 132 133 }else{ 134 buttons =''; 135 } 136 if ( 1 == jetpackCarouselStrings.is_logged_in ) { 137 } 138 buttons += getCarouselLikeWidgets( dataCarouselExtra ); 139 if(buttons){ 140 141 buttons = $('<div class="jp-carousel-buttons">' + buttons + '</div>'); 142} 143 caption = $('<h2></h2>'); 144 photo_info = $('<div class="jp-carousel-photo-info"></div>').append(caption); 145 146 147 148 imageMeta = $('<div></div>') 149 .addClass('jp-carousel-image-meta') 150 .css({ 151 'float' : 'right', 152 'margin-top' : '20px', 153 'width' : '250px' 154 }); 155 imageMeta.append( buttons ); 156 157 158 imageMeta.append( "<ul class='jp-carousel-image-exif' style='display:none;'></ul>" ); 159 imageMeta.append( "<a class='jp-carousel-image-download' style='display:none;'></a>" ); 160 imageMeta.append( "<div class='jp-carousel-image-map' style='display:none;'></div>" ); 161 162 if(jetpackCarouselStrings.display_exif == '0' && jetpackCarouselStrings.display_comments == '0' && jetpackCarouselStrings.fullsize_display == '0' ){ 163 imageMeta.hide(); 164 } 165 166 167 titleAndDescription = $('<div></div>') 168 .addClass('jp-carousel-titleanddesc') 169 .css({ 170 'width' : '100%', 171 'margin-top' : imageMeta.css('margin-top') 172 }); 173 174 var commentFormMarkup = ''; 175 var iframeSrc = ''; 176 177 commentFormMarkup = '<div id="jp-carousel-comment-form-container">'; 178 if (iframeSrc && iframeSrc.length) { 179 // We're using Jetpack comments! 180 var iframeHeight = (jetpackCarouselStrings.is_logged_in || iframeSrc.match('comment_registration=1')) ? 220 : 340; 181 iframeSrc = iframeSrc.replace(/(blogid=\d+)/, '$1&postid='+window.location.hash.replace(/#jp-carousel-/,'')); // get initial attachment id from URL hash 182 commentFormMarkup += '<iframe src="'+iframeSrc+'" width="100%" height="'+iframeHeight+'" style="width:100%;height:'+iframeHeight+'px;" allowtransparency="true" frameBorder="0" scrolling="no" name="jp-carousel-comment-iframe" id="jp-carousel-comment-iframe"></iframe>'; 183 } else if ( jetpackCarouselStrings.local_comments_commenting_as && jetpackCarouselStrings.local_comments_commenting_as.length ) { 184 // Jetpack comments not enabled, fallback to local comments 185 186 if ( 1 != jetpackCarouselStrings.is_logged_in && 1 == jetpackCarouselStrings.comment_registration ) { 187 commentFormMarkup += '<div id="jp-carousel-comment-form-commenting-as">' + jetpackCarouselStrings.local_comments_commenting_as + '</div>'; 188 } else { 189 commentFormMarkup += '<form id="jp-carousel-comment-form">'; 190 commentFormMarkup += '<textarea name="comment" class="jp-carousel-comment-form-field jp-carousel-comment-form-textarea" id="jp-carousel-comment-form-comment-field" placeholder="Write a comment…"></textarea>'; 191 commentFormMarkup += '<div id="jp-carousel-comment-form-submit-and-info-wrapper">'; 192 commentFormMarkup += '<div id="jp-carousel-comment-form-commenting-as">' + jetpackCarouselStrings.local_comments_commenting_as + '</div>'; 193 commentFormMarkup += '<input type="submit" name="submit" class="jp-carousel-comment-form-button" id="jp-carousel-comment-form-button-submit" value="'+jetpackCarouselStrings.post_comment+'" />'; 194 commentFormMarkup += '<span id="jp-carousel-comment-form-spinner"> </span>'; 195 commentFormMarkup += '<div id="jp-carousel-comment-post-results"></div>'; 196 commentFormMarkup += '</div>'; 197 commentFormMarkup += '</form>'; 198 } 199 } 200 commentFormMarkup += '</div>'; 201 202 commentForm = $(commentFormMarkup) 203 .css({ 204 'width' : '100%', 205 'margin-top' : '20px', 206 'color' : '#999' 207 }); 208 209 comments = $('<div></div>') 210 .addClass('jp-carousel-comments') 211 .css({ 212 'width' : '100%', 213 'bottom' : '10px', 214 'margin-top' : '20px' 215 }); 216 217 commentsLoading = $('<div id="jp-carousel-comments-loading"><span>'+jetpackCarouselStrings.loading_comments+'</span></div>') 218 .css({ 219 'width' : '100%', 220 'bottom' : '10px', 221 'margin-top' : '20px' 222 }); 223 224 leftWidth = ( $(window).width() - ( screenPadding * 2 ) ) - (imageMeta.width() + 40);
225 leftWidth += 'px'; 226 227 if (isMobile) 228 leftWidth = '100%'; 229 230 leftColWrapper = $('<div></div>') 231 .addClass('jp-carousel-left-column-wrapper') 232 .css({ 233 'width' : leftWidth 234 }) 235 .append(titleAndDescription) 236 .append(commentForm) 237 .append(comments) 238 .append(commentsLoading); 239 240 fadeaway = $('<div></div>') 241 .addClass('jp-carousel-fadeaway'); 242 243 info = $('<div></div>') 244 .addClass('jp-carousel-info') 245 .css({ 246 'top' : ($(window).height() / 100) * proportion, 247 'left' : screenPadding, 248 'right' : screenPadding 249 }) 250 .append(photo_info) 251 .append(imageMeta) 252 .append(leftColWrapper); 253 254 if (isMobile) 255 info.prepend(leftColWrapper); 256 else 257 info.append(leftColWrapper); 258 259 targetBottomPos = ( $(window).height() - parseInt( info.css('top'), 10 ) ) + 'px'; 260 261 nextButton = $("<div><span></span></div>") 262 .addClass('jp-carousel-next-button') 263 .css({ 264 'position' : 'fixed', 265 'top' : 0, 266 'right' : '15px', 267 'bottom' : 0, 268 'width' : screenPadding 269 }); 270 271 $('span', nextButton).css({ 272 'top' : '40px', 273 'bottom' : targetBottomPos 274 }); 275 276 previousButton = $("<div><span></span></div>") 277 .addClass('jp-carousel-previous-button') 278 .css({ 279 'position' : 'fixed', 280 'top' : 0, 281 'left' : 0, 282 'bottom' : 0, 283 'width' : screenPadding 284 }); 285 286 $('span', previousButton).css({ 287 'top' : '40px', 288 'bottom' : targetBottomPos 289 }); 290 291 gallery = $('<div></div>') 292 .addClass('jp-carousel') 293 .css({ 294 'position' : 'absolute', 295 'top' : 0, 296 'bottom' : targetBottomPos, 297 'left' : 0, 298 'right' : 0 299 }); 300 301 close_hint = $('<div class="jp-carousel-close-hint"><span>×</span></div>') 302 .css({ 303 position : 'fixed' 304 }); 305 306 container = $("<div></div>") 307 .addClass('jp-carousel-wrap'); 308 309 if ( 'white' == jetpackCarouselStrings.background_color ) 310 container.addClass('jp-carousel-light'); 311 312 container.css({ 313 'position' : 'fixed', 314 'top' : 0, 315 'right' : 0, 316 'bottom' : 0, 317 'left' : 0, 318 'z-index' : 2147483647, 319 'overflow-x' : 'hidden', 320 'overflow-y' : 'auto', 321 'direction' : 'ltr' 322 }) 323 .hide() 324 .append(overlay) 325 .append(gallery) 326 .append(fadeaway) 327 .append(info) 328 .append(nextButton) 329 .append(previousButton) 330 .append(close_hint) 331 .appendTo($('body')) 332 .click(function(e){ 333 var target = $(e.target), wrap = target.parents('div.jp-carousel-wrap'), data = wrap.data('carousel-extra'), 334 slide = wrap.find('div.selected'), attachment_id = slide.data('attachment-id'); 335 data = data || []; 336 337 if ( target.is(gallery) || target.parents().add(target).is(close_hint) ) { 338 container.jp_carousel('close'); 339 } else if ( target.hasClass('jp-carousel-commentlink') ) { 340 e.preventDefault(); 341 e.stopPropagation(); 342 $(window).unbind('keydown', keyListener); 343 container.animate({scrollTop: parseInt(info.position()['top'], 10)}, 'fast'); 344 $('#jp-carousel-comment-form-submit-and-info-wrapper').slideDown('fast'); 345 $('#jp-carousel-comment-form-comment-field').focus(); 346 } else if ( target.hasClass('jp-carousel-comment-login') ) { 347 var url = jetpackCarouselStrings.login_url + '%23jp-carousel-' + attachment_id; 348 349 document.location.href = url; 350 } else if ( target.parents('#jp-carousel-comment-form-container').length ) { 351 var textarea = $('#jp-carousel-comment-form-comment-field') 352 .blur(function(){ 353 $(window).bind('keydown', keyListener); 354 }) 355 .focus(function(){ 356 $(window).unbind('keydown', keyListener); 357 }); 358 359 var emailField = $('#jp-carousel-comment-form-email-field') 360 .blur(function(){ 361 $(window).bind('keydown', keyListener); 362 }) 363 .focus(function(){ 364 $(window).unbind('keydown', keyListener); 365 }); 366 367 var authorField = $('#jp-carousel-comment-form-author-field') 368 .blur(function(){ 369 $(window).bind('keydown', keyListener); 370 }) 371 .focus(function(){ 372 $(window).unbind('keydown', keyListener); 373 }); 374 375 var urlField = $('#jp-carousel-comment-form-url-field') 376 .blur(function(){ 377 $(window).bind('keydown', keyListener); 378 }) 379 .focus(function(){ 380 $(window).unbind('keydown', keyListener); 381 }); 382 383 if ( textarea && textarea.attr('id') == target.attr('id')) { 384 // For first page load 385 $(window).unbind('keydown', keyListener); 386 $('#jp-carousel-comment-form-submit-and-info-wrapper').slideDown('fast'); 387 } else if ( target.is( 'input[type="submit"]' ) ) { 388 e.preventDefault(); 389 e.stopPropagation(); 390 391 $('#jp-carousel-comment-form-spinner').spin('small', 'white'); 392 393 var ajaxData = { 394 action: 'post_attachment_comment', 395 nonce: jetpackCarouselStrings.nonce, 396 blog_id: data['blog_id'], 397 id: attachment_id, 398 comment: textarea.val() 399 }; 400 401 if ( ! ajaxData['comment'].length ) { 402 gallery.jp_carousel('postCommentError', {'field': 'jp-carousel-comment-form-comment-field', 'error': jetpackCarouselStrings.no_comment_text}); 403 return; 404 } 405 406 if ( 1 != jetpackCarouselStrings.is_logged_in ) { 407 ajaxData['email'] = emailField.val(); 408 ajaxData['author'] = authorField.val(); 409 ajaxData['url'] = urlField.val(); 410 411 if ( 1 == jetpackCarouselStrings.require_name_email ) { 412 if ( ! ajaxData['email'].length || ! ajaxData['email'].match('@') ) { 413 gallery.jp_carousel('postCommentError', {'field': 'jp-carousel-comment-form-email-field', 'error': jetpackCarouselStrings.no_comment_email}); 414 return; 415 } else if ( ! ajaxData['author'].length ) { 416 gallery.jp_carousel('postCommentError', {'field': 'jp-carousel-comment-form-author-field', 'error': jetpackCarouselStrings.no_comment_author}); 417 return; 418 } 419 } 420 } 421 422 $.ajax({ 423 type: 'POST', 424 url: jetpackCarouselStrings.ajaxurl, 425 data: ajaxData, 426 dataType: 'json', 427 success: function(response, status, xhr) { 428 if ( 'approved' == response.comment_status ) {
429 $('#jp-carousel-comment-post-results').slideUp('fast').html('<span class="jp-carousel-comment-post-success">' + jetpackCarouselStrings.comment_approved + '</span>').slideDown('fast'); 430 } else if ( 'unapproved' == response.comment_status ) { 431 $('#jp-carousel-comment-post-results').slideUp('fast').html('<span class="jp-carousel-comment-post-success">' + jetpackCarouselStrings.comment_unapproved + '</span>').slideDown('fast'); 432 } else { 433 // 'deleted', 'spam', false 434 $('#jp-carousel-comment-post-results').slideUp('fast').html('<span class="jp-carousel-comment-post-error">' + jetpackCarouselStrings.comment_post_error + '</span>').slideDown('fast'); 435 } 436 gallery.jp_carousel('clearCommentTextAreaValue'); 437 gallery.jp_carousel('getComments', {attachment_id: attachment_id, offset: 0, clear: true}); 438 $('#jp-carousel-comment-form-button-submit').val(jetpackCarouselStrings.post_comment); 439 $('#jp-carousel-comment-form-spinner').spin(false); 440 }, 441 error: function(xhr, status, error) { 442 // TODO: Add error handling and display here 443 gallery.jp_carousel('postCommentError', {'field': 'jp-carousel-comment-form-comment-field', 'error': jetpackCarouselStrings.comment_post_error}); 444 return; 445 } 446 }); 447 } 448 } else if ( ! target.parents( '.jp-carousel-info' ).length ) { 449 container.jp_carousel('next'); 450 } 451 }) 452 .bind('jp_carousel.afterOpen', function(){ 453 $(window).bind('keydown', keyListener); 454 $(window).bind('resize', resizeListener); 455 gallery.opened = true; 456 }) 457 .bind('jp_carousel.beforeClose', function(){ 458 var scroll = $(window).scrollTop(); 459 460 $(window).unbind('keydown', keyListener); 461 $(window).unbind('resize', resizeListener); 462 $(window).scrollTop(scroll); 463 }) 464 .bind('jp_carousel.afterClose', function(){ 465 if ( history.pushState ) { 466 history.pushState("", document.title, window.location.pathname + window.location.search); 467 } else { 468 document.location.hash = ''; 469 } 470 gallery.opened = false; 471 }); 472 473 $('.jp-carousel').touchwipe({ 474 wipeLeft: function() { gallery.jp_carousel('next'); }, 475 wipeRight: function() { gallery.jp_carousel('previous'); }, 476 min_move_x: 20, 477 min_move_y: 20, 478 preventDefaultEvents: true 479 }); 480 481 $( '.jetpack-likes-widget-unloaded' ).each( function() { 482 jetpackLikesWidgetQueue.push( this.id ); 483 }); 484 485 nextButton.add(previousButton).click(function(e){ 486 e.preventDefault(); 487 e.stopPropagation(); 488 if ( nextButton.is(this) ) { 489 gallery.jp_carousel('next'); 490 } else { 491 gallery.jp_carousel('previous'); 492 } 493 }); 494 } 495 }; 496 497 var methods = { 498 testForData: function(gallery) { 499 gallery = $( gallery ); // make sure we have it as a jQuery object. 500 if ( ! gallery.length || undefined == gallery.data( 'carousel-extra' ) ) { 501 return false; 502 } 503 return true; 504 }, 505 506 testIfOpened: function() { 507 if ( 'undefined' != typeof(gallery) && 'undefined' != typeof(gallery.opened) && true == gallery.opened ) 508 return true; 509 return false; 510 }, 511 512 open: function(options) { 513 var settings = { 514 'items_selector' : ".gallery-item [data-attachment-id], .tiled-gallery-item [data-attachment-id]", 515 'start_index': 0 516 }, 517 data = $(this).data('carousel-extra'); 518 519 if ( !data ) 520 return; // don't run if the default gallery functions weren't used 521 522 prepareGallery( data ); 523 524 if ( gallery.jp_carousel( 'testIfOpened' ) ) 525 return; // don't open if already opened 526 527 // make sure to stop the page from scrolling behind the carousel overlay, so we don't trigger 528 // infiniscroll for it when enabled (Reader, theme infiniscroll, etc). 529 originalOverflow = $('body').css('overflow'); 530 $('body').css('overflow', 'hidden'); 531 // prevent html from overflowing on some of the new themes. 532 originalHOverflow = $('html').css('overflow'); 533 $('html').css('overflow', 'hidden'); 534 535 // Re-apply inline-block style here and give an initial value for the width 536 // This value will get replaced with a more appropriate value once the slide is loaded 537 // This avoids the likes widget appearing initially full width below the comment button and then shuffling up 538 jQuery( '.slim-likes-widget' ).find( 'iframe' ).css( 'display', 'inline-block' ).css( 'width', '60px' ); 539 540 container.data('carousel-extra', data); 541 542 return this.each(function() { 543 // If options exist, lets merge them 544 // with our default settings 545 var $this = $(this); 546 547 if ( options ) 548 $.extend( settings, options ); 549 if ( -1 == settings.start_index ) 550 settings.start_index = 0; //-1 returned if can't find index, so start from beginning 551 552 container.trigger('jp_carousel.beforeOpen').fadeIn('fast',function(){ 553 container.trigger('jp_carousel.afterOpen'); 554 gallery 555 .jp_carousel('initSlides', $this.find(settings.items_selector), settings.start_index) 556 .jp_carousel('start', settings.start_index); 557 }); 558 gallery.html(''); 559 }); 560 }, 561 562 start : function(start_index){ 563 var slides = this.jp_carousel('slides'), selected = slides.eq(start_index); 564 565 if ( 0 === selected.length ) 566 selected = slides.eq(0); 567 568 gallery.jp_carousel('selectSlide', selected, false); 569 return this; 570 }, 571 572 close : function(){ 573 // make sure to let the page scroll again 574 $('body').css('overflow', originalOverflow); 575 $('html').css('overflow', originalHOverflow); 576 return container 577 .trigger('jp_carousel.beforeClose') 578 .fadeOut('fast', function(){ 579 container.trigger('jp_carousel.afterClose'); 580 }); 581 582 }, 583 584 next : function(){ 585 var selected = this.jp_carousel('selectedSlide'), slide; 586 container.animate({scrollTop:0}, 'fast'); 587 if ( 0 === selected.length ) { // no selection return first item 588 slide = this.jp_carousel('slides').first(0); 589 } else if( selected.is( this.jp_carousel('slides').last() ) ) { 590 gallery.jp_carousel('loopSlides'); 591 } else { 592 slide = selected.next(); 593 } 594 if (!slide) { 595 return this; 596 } else { 597 return this.jp_carousel('selectSlide', slide); 598 } 599 }, 600 601 previous : function(){ 602 var selected = this.jp_carousel('selectedSlide'), slide; 603 container.animate({scrollTop:0}, 'fast'); 604 if ( 0 === selected.length ) { // no selection return first item 605 slide = this.jp_carousel('slides').first(); 606 } else if ( selected.is( this.jp_carousel('slides').first() ) ) { // if it's the last slide 607 gallery.jp_carousel('loopSlides', true); 608 } else { 609 slide = selected.prev(); 610 } 611 if (!slide) { 612 return this; 613 } else { 614 return this.jp_carousel('selectSlide', slide); 615 } 616 }, 617 618 resetButtons : function(current) { 619 if ( current.data('liked') ) 620 $('.jp-carousel-buttons a.jp-carousel-like').addClass('liked').text(jetpackCarouselStrings.unlike); 621 else 622 $('.jp-carousel-buttons a.jp-carousel-like').removeClass('liked').text(jetpackCarouselStrings.like); 623 }, 624 625 loopSlides : function(reverse){ 626 var slides = gallery.jp_carousel('slides'), last, first; 627 gallery.jp_carousel('selectedSlide').removeClass('selected').css({'position': 'fixed'}); 628 if (reverse !== true ) { 629 last = slides.last(); 630 slides.first().nextAll().not(last).jp_carousel('setSlidePosition', gallery.width()+slides.first().width()).hide(); 631 last.jp_carousel('setSlidePosition', -last.width()); 632 last.prev().jp_carousel('setSlidePosition', -last.width() - last.prev().width()); 633 slides.first().jp_carousel('setSlidePosition', gallery.width()); 634 setTimeout(function(){ 635 gallery.jp_carousel('selectSlide', slides.show().first()); 636 }, 400); 637 638 } else { 639 first = slides.first();
640 first.jp_carousel('setSlidePosition', gallery.width()); 641 first.next().jp_carousel('setSlidePosition', gallery.width() + first.width()); 642 first.next().nextAll().hide().jp_carousel('setSlidePosition', -slides.last().width()); 643 slides.last().jp_carousel('setSlidePosition', -slides.last().width()); 644 slides.last().prevAll().not(first, first.next()).hide().jp_carousel('setSlidePosition', -slides.last().width()-slides.last().prev().width()); 645 setTimeout(function(){ 646 gallery.jp_carousel('selectSlide', slides.show().last()); 647 }, 400); 648 649 } 650 }, 651 652 selectedSlide : function(){ 653 return this.find('.selected'); 654 }, 655 656 setSlidePosition : function(x) { 657 return this.css({ 658 '-webkit-transform':'translate3d(' + x + 'px,0,0)', 659 '-moz-transform':'translate3d(' + x + 'px,0,0)', 660 '-ms-transform':'translate(' + x + 'px,0)', 661 '-o-transform':'translate(' + x + 'px,0)', 662 'transform':'translate3d(' + x + 'px,0,0)' 663 }); 664 }, 665 666 selectSlide : function(slide, animate){ 667 var last = this.find('.selected').removeClass('selected'), 668 slides = gallery.jp_carousel('slides').css({'position': 'fixed'}), 669 current = $(slide).addClass('selected').css({'position': 'relative'}), 670 previous = current.prev(), 671 next = current.next(), 672 width = $(window).width(), 673 previous_previous = previous.prev(), 674 next_next = next.next(), 675 left = (gallery.width() - current.width()) * 0.5, 676 info_left, 677 animated, 678 info_min; 679 // center the main image 680 681 caption.hide(); 682 683 method = 'css'; 684 animated = current 685 .add(previous) 686 .add(previous.prev()) 687 .add(next) 688 .add(next.next()) 689 .jp_carousel('loadSlide'); 690 // slide the whole view to the x we want 691 slides.not(animated).hide(); 692 693 current.jp_carousel('setSlidePosition', left).show(); 694 695 // minimum width 696 gallery.jp_carousel('fitInfo', animate); 697 698 // prep the slides 699 var direction = last.is(current.prevAll()) ? 1 : -1; 700 if ( 1 == direction ) { 701 next_next.jp_carousel('setSlidePosition', gallery.width() + next.width()).show(); 702 next.hide().jp_carousel('setSlidePosition', gallery.width() + current.width()).show(); 703 previous_previous.jp_carousel('setSlidePosition', -previous_previous.width() - current.width()).show(); 704 } else { 705 previous.jp_carousel('setSlidePosition', -previous.width() - current.width()).show(); 706 next_next.jp_carousel('setSlidePosition', gallery.width() + current.width()).show(); 707 } 708 709 // if advancing prepare the slide that will enter the screen 710 previous.jp_carousel('setSlidePosition', -previous.width() + (screenPadding * 0.75)).show(); 711 next.jp_carousel('setSlidePosition', gallery.width() - (screenPadding * 0.75)).show(); 712 next.css({'position': ''}); 713 document.location.href = document.location.href.replace(/#.*/, '') + '#jp-carousel-' + current.data('attachment-id'); 714 gallery.jp_carousel('resetButtons', current); 715 container.trigger('jp_carousel.selectSlide', [current]); 716 717 gallery.jp_carousel( 'getTitleDesc', { title: current.data( 'title' ), desc: current.data( 'desc' ) } ); 718 gallery.jp_carousel( 'updateLikesWidgetVisibility', current.data( 'attachment-id' ) ) 719 gallery.jp_carousel( 'updateExif', current.data( 'image-meta' ) ); 720 gallery.jp_carousel( 'updateFullSizeLink', current ); 721 gallery.jp_carousel( 'updateMap', current.data( 'image-meta' ) ); 722 gallery.jp_carousel( 'testCommentsOpened', current.data( 'comments-opened' ) ); 723 gallery.jp_carousel( 'getComments', { 'attachment_id': current.data( 'attachment-id' ), 'offset': 0, 'clear': true } ); 724 725 $('#jp-carousel-comment-post-results').slideUp(); 726 727 // $('<div />').text(sometext).html() is a trick to go to HTML to plain text (including HTML entities decode, etc) 728 if ( current.data('caption') ) { 729 if ( $('<div />').text(current.data('caption')).html() == $('<div />').text(current.data('title')).html() ) 730 $('.jp-carousel-titleanddesc-title').fadeOut('fast').empty(); 731 if ( $('<div />').text(current.data('caption')).html() == $('<div />').text(current.data('desc')).html() ) 732 $('.jp-carousel-titleanddesc-desc').fadeOut('fast').empty(); 733 caption.html( current.data('caption') ).fadeIn('slow'); 734 } else { 735 caption.fadeOut('fast').empty(); 736 } 737 738 }, 739 740 slides : function(){ 741 return this.find('.jp-carousel-slide'); 742 }, 743 744 slideDimensions : function(){ 745 return { 746 width: $(window).width() - (screenPadding * 2), 747 height: $(window).height() / 100 * proportion - 60 748 }; 749 }, 750 751 loadSlide : function() { 752 return this.each(function(){ 753 var slide = $(this); 754 slide.find('img') 755 .one('load', function(){ 756 // set the width/height of the image if it's too big 757 slide 758 .jp_carousel('fitSlide',false); 759 }); 760 }); 761 }, 762 763 bestFit : function(){ 764 var max = gallery.jp_carousel('slideDimensions'), 765 orig = this.jp_carousel('originalDimensions'), 766 orig_ratio = orig.width / orig.height, 767 w_ratio = 1, 768 h_ratio = 1; 769 770 if ( orig.width > max.width ) 771 w_ratio = max.width / orig.width; 772 if ( orig.height > max.height ) 773 h_ratio = max.height / orig.height; 774 775 if ( w_ratio < h_ratio ) { 776 width = max.width; 777 height = width / orig_ratio; 778 } else if ( h_ratio < w_ratio ) { 779 height = max.height; 780 width = height * orig_ratio; 781 } else { 782 width = orig.width; 783 height = orig.height; 784 } 785 786 return { 787 width: width, 788 height: height 789 }; 790 }, 791 792 fitInfo : function(animated){ 793 var current = this.jp_carousel('selectedSlide'), 794 size = current.jp_carousel('bestFit'); 795 796 photo_info.css({ 797 'left' : (info.width() - size.width) * 0.5, 798 'width' : size.width 799 }); 800 801 if (isMobile){ 802 photo_info.css('left', '0px'); 803 photo_info.css('top', '-20px'); 804 } 805 806 return this; 807 }, 808 809 fitMeta : function(animated){ 810 var newInfoTop = { top: ( $(window).height() / 100 * proportion + 5 ) + 'px' }; 811 var newLeftWidth = { width: ( info.width() - (imageMeta.width() + 80) ) + 'px' }; 812
813 if (animated) { 814 info.animate(newInfoTop); 815 leftColWrapper.animate(newLeftWidth); 816 } else { 817 info.animate(newInfoTop); 818 leftColWrapper.css(newLeftWidth); 819 } 820 }, 821 822 fitSlide : function(animated){ 823 return this.each(function(){ 824 var selected = gallery.jp_carousel('selectedSlide'), 825 $this = $(this), 826 dimensions = $this.jp_carousel('bestFit'), 827 method = 'css', 828 max = gallery.jp_carousel('slideDimensions'); 829 830 dimensions.left = 0; 831 dimensions.top = ( (max.height - dimensions.height) * 0.5 ) + 40; 832 $this[method](dimensions); 833 }); 834 }, 835 836 texturize : function(text) { 837 text = new String(text); // make sure we get a string. Title "1" came in as int 1, for example, which did not support .replace(). 838 text = text.replace(/'/g, '’').replace(/'/g, '’').replace(/[\u2019]/g, '’'); 839 text = text.replace(/"/g, '”').replace(/"/g, '”').replace(/"/g, '”').replace(/[\u201D]/g, '”'); 840 text = text.replace(/([\w]+)=&#[\d]+;(.+?)&#[\d]+;/g, '$1="$2"'); // untexturize allowed HTML tags params double-quotes 841 return $.trim(text); 842 }, 843 844 initSlides : function(items, start_index){ 845 var width = this.jp_carousel('slideDimensions').width, 846 x = 0; 847 848 // Calculate the new src. 849 items.each(function(i){ 850 var src_item = $(this), 851 orig_size = src_item.data('orig-size') || '', 852 max = gallery.jp_carousel('slideDimensions'), 853 parts = orig_size.split(','); 854 orig_size = {width: parseInt(parts[0], 10), height: parseInt(parts[1], 10)}, 855 medium_file = src_item.data('medium-file') || '', 856 large_file = src_item.data('large-file') || ''; 857 858 src = src_item.data('orig-file'); 859 860 src = gallery.jp_carousel('selectBestImageSize', { 861 orig_file : src, 862 orig_width : orig_size.width, 863 orig_height : orig_size.height, 864 max_width : max.width, 865 max_height : max.height, 866 medium_file : medium_file, 867 large_file : large_file 868 }); 869 870 // Set the final src 871 $(this).data( 'gallery-src', src ); 872 }); 873 874 // If the start_index is not 0 then preload the clicked image first. 875 if ( 0 !== start_index ) 876 $('<img/>')[0].src = $(items[start_index]).data('gallery-src'); 877 878 // create the 'slide' 879 items.each(function(i){ 880 var src_item = $(this), 881 attachment_id = src_item.data('attachment-id') || 0, 882 comments_opened = src_item.data('comments-opened') || 0, 883 image_meta = src_item.data('image-meta') || {}, 884 orig_size = src_item.data('orig-size') || '', 885 title = src_item.data('image-title') || '', 886 description = src_item.data('image-description') || '', 887 caption = src_item.parents('dl').find('dd.gallery-caption').html() || '', 888 src = src_item.data('gallery-src') || '', 889 medium_file = src_item.data('medium-file') || '', 890 large_file = src_item.data('large-file') || '', 891 orig_file = src_item.data('orig-file') || ''; 892 893 var tiledCaption = src_item.parents('div.tiled-gallery-item').find('div.tiled-gallery-caption').html(); 894 if ( tiledCaption ) 895 caption = tiledCaption; 896 897 if ( attachment_id && orig_size.length ) { 898 title = gallery.jp_carousel('texturize', title); 899 description = gallery.jp_carousel('texturize', description); 900 caption = gallery.jp_carousel('texturize', caption); 901 902 var slide = $('<div class="jp-carousel-slide"></div>') 903 .hide() 904 .css({ 905 //'position' : 'fixed', 906 'left' : i < start_index ? -1000 : gallery.width() 907 }) 908 .append($('<img>')) 909 .appendTo(gallery) 910 .data('src', src ) 911 .data('title', title) 912 .data('desc', description) 913 .data('caption', caption) 914 .data('attachment-id', attachment_id) 915 .data('permalink', src_item.parents('a').attr('href')) 916 .data('orig-size', orig_size) 917 .data('comments-opened', comments_opened) 918 .data('image-meta', image_meta) 919 .data('medium-file', medium_file) 920 .data('large-file', large_file) 921 .data('orig-file', orig_file) 922 .jp_carousel('fitSlide', false); 923 924 // Preloading all images 925 slide.find('img').first().attr('src', src ); 926 } 927 }); 928 return this; 929 }, 930 931 selectBestImageSize: function(args) { 932 if ( 'object' != typeof args ) 933 args = {}; 934 935 if ( 'undefined' == typeof args.orig_file ) 936 return ''; 937 938 if ( 'undefined' == typeof args.orig_width || 'undefined' == typeof args.max_width ) 939 return args.orig_file; 940 941 if ( 'undefined' == typeof args.medium_file || 'undefined' == typeof args.large_file ) 942 return args.orig_file; 943 944 var medium_size = args.medium_file.replace(/-([\d]+x[\d]+)\..+$/, '$1'), 945 medium_size_parts = (medium_size != args.medium_file) ? medium_size.split('x') : [args.orig_width, 0], 946 medium_width = parseInt( medium_size_parts[0], 10 ), 947 medium_height = parseInt( medium_size_parts[1], 10 ), 948 large_size = args.large_file.replace(/-([\d]+x[\d]+)\..+$/, '$1'), 949 large_size_parts = (large_size != args.large_file) ? large_size.split('x') : [args.orig_width, 0], 950 large_width = parseInt( large_size_parts[0], 10 ), 951 large_height = parseInt( large_size_parts[1], 10 ); 952 953 // Give devices with a higher devicePixelRatio higher-res images (Retina display = 2, Android ph
953ones = 1.5, etc) 954 if ('undefined' != typeof window.devicePixelRatio && window.devicePixelRatio > 1) { 955 args.max_width = args.max_width * window.devicePixelRatio; 956 args.max_height = args.max_height * window.devicePixelRatio; 957 } 958 959 if ( large_width >= args.max_width || large_height >= args.max_height ) 960 return args.large_file; 961 962 if ( medium_width >= args.max_width || medium_height >= args.max_height ) 963 return args.medium_file; 964 965 return args.orig_file; 966 }, 967 968 969 originalDimensions: function() { 970 var splitted = $(this).data('orig-size').split(','); 971 return {width: parseInt(splitted[0], 10), height: parseInt(splitted[1], 10)}; 972 }, 973 974 format: function( args ) { 975 if ( 'object' != typeof args ) 976 args = {}; 977 if ( ! args.text || 'undefined' == typeof args.text ) 978 return; 979 if ( ! args.replacements || 'undefined' == typeof args.replacements ) 980 return args.text; 981 return args.text.replace(/{(\d+)}/g, function(match, number) { 982 return typeof args.replacements[number] != 'undefined' ? args.replacements[number] : match; 983 }); 984 }, 985 986 shutterSpeed: function(d) { 987 if (d >= 1) 988 return Math.round(d) + 's'; 989 var df = 1, top = 1, bot = 1; 990 var limit = 1e5; //Increase for greater precision. 991 while (df != d && limit-- > 0) { 992 if (df < d) { 993 top += 1; 994 } 995 else { 996 bot += 1; 997 top = parseInt(d * bot, 10); 998 } 999 df = top / bot; 1000 } 1001 if (top > 1) { 1002 bot = Math.round(bot / top); 1003 top = 1; 1004 } 1005 if (bot <= 1) 1006 return '1s'; 1007 return top + '/' + bot + 's'; 1008 }, 1009 1010 parseTitleDesc: function( value ) { 1011 if ( !value.match(' ') && value.match('_') ) 1012 return ''; 1013 // Prefix list originally based on http://commons.wikimedia.org/wiki/MediaWiki:Filename-prefix-blacklist 1014 var prefixes = $([ 1015 'CIMG', // Casio 1016 'DSC_', // Nikon 1017 'DSCF', // Fuji 1018 'DSCN', // Nikon 1019 'DUW', // some mobile phones 1020 'GEDC', // GE 1021 'IMG', // generic 1022 'JD', // Jenoptik 1023 'MGP', // Pentax 1024 'PICT', // misc. 1025 'Imagen', // misc. 1026 'Foto', // misc. 1027 'DSC', // misc. 1028 'Scan', // Scanners 1029 'SANY', // Sanyo 1030 'SAM', // Samsung 1031 'Screen Shot [0-9]+' // Mac screenshots 1032 ]) 1033 .each(function(key, val){ 1034 regex = new RegExp('^' + val); 1035 if ( regex.test(value) ) { 1036 value = ''; 1037 return; 1038 } 1039 }); 1040 return value; 1041 }, 1042 1043 getTitleDesc: function( data ) { 1044 var title ='', desc = '', markup = '', target, commentWrappere; 1045 1046 target = $( 'div.jp-carousel-titleanddesc', 'div.jp-carousel-wrap' ); 1047 target.hide(); 1048 1049 title = gallery.jp_carousel('parseTitleDesc', data.title) || ''; 1050 desc = gallery.jp_carousel('parseTitleDesc', data.desc) || ''; 1051 1052 if ( title.length || desc.length ) { 1053 // $('<div />').text(sometext).html() is a trick to go to HTML to plain text (including HTML entities decode, etc) 1054 if ( $('<div />').text(title).html() == $('<div />').text(desc).html() ) 1055 title = ''; 1056 1057 markup = ( title.length ) ? '<div class="jp-carousel-titleanddesc-title">' + title + '</div>' : ''; 1058 markup += ( desc.length ) ? '<div class="jp-carousel-titleanddesc-desc">' + desc + '</div>' : ''; 1059 1060 target.html( markup ).fadeIn('slow'); 1061 } 1062 1063 $( 'div#jp-carousel-comment-form-container' ).css('margin-top', '20px'); 1064 $( 'div#jp-carousel-comments-loading' ).css('margin-top', '20px'); 1065 }, 1066 1067 updateLikesWidgetVisibility: function( attachmentId ) { 1068 // Hide all likes widgets except for the one for the attachmentId passed in 1069 1070 $( '.jp-carousel-buttons' ).find( '.jetpack-likes-widget-wrapper' ).each( function() { 1071 var widgetWrapper = $( this ); 1072 if ( widgetWrapper.attr('data-attachment-id') == attachmentId ) { 1073 widgetWrapper.css( 'display', 'inline-block' ); 1074 } else { 1075 widgetWrapper.css( 'display', 'none' ); 1076 } 1077 }); 1078 }, 1079 1080 // updateExif updates the contents of the exif UL (.jp-carousel-image-exif) 1081 updateExif: function( meta ) { 1082 if ( !meta || 1 != jetpackCarouselStrings.display_exif ){ 1083 return false;
1084 } 1085 1086 1087 var $ul = $( "<ul class='jp-carousel-image-exif'></ul>" ); 1088 $.each( meta, function( key, val ) { 1089 if ( 0 === parseFloat(val) || !val.length || -1 === $.inArray( key, [ 'camera', 'aperture', 'shutter_speed', 'focal_length' ] ) ) 1090 return; 1091 1092 switch( key ) { 1093 case 'focal_length': 1094 val = val + 'mm'; 1095 break; 1096 case 'shutter_speed': 1097 val = gallery.jp_carousel('shutterSpeed', val); 1098 break; 1099 case 'aperture': 1100 val = 'f/' + val; 1101 break; 1102 default: 1103 // making jslint happy 1104 break; 1105 } 1106 1107 $ul.append( '<li><h5>' + jetpackCarouselStrings[key] + '</h5>' + val + '</li>' ); 1108 }); 1109 1110 // Update (replace) the content of the ul 1111 $( 'div.jp-carousel-image-meta ul.jp-carousel-image-exif' ).replaceWith( $ul ); 1112 1113 }, 1114 1115 // updateFullSizeLink updates the contents of the jp-carousel-image-download link 1116 updateFullSizeLink: function(current) { 1117 if(!current || !current.data) 1118 return false; 1119 var original = current.data('orig-file').replace(/\?.+$/, ''), 1120 origSize = current.data('orig-size').split(','), 1121 permalink = $( '<a>'+gallery.jp_carousel('format', {'text': jetpackCarouselStrings.download_original, 'replacements': origSize})+'</a>' ) 1122 .addClass( 'jp-carousel-image-download' ) 1123 .attr( 'href', original ) 1124 .attr( 'target', '_blank' ); 1125 1126 // Update (replace) the content of the anchor 1127if(jetpackCarouselStrings.fullsize_display == 1){ 1128 $( 'div.jp-carousel-image-meta a.jp-carousel-image-download' ).replaceWith( permalink ); 1129 1130} 1131 1132 }, 1133 1134 updateMap: function( meta ) { 1135 if ( !meta.latitude || !meta.longitude || 1 != jetpackCarouselStrings.display_geo ) 1136 return; 1137 1138 var latitude = meta.latitude, 1139 longitude = meta.longitude, 1140 $metabox = $( 'div.jp-carousel-image-meta', 'div.jp-carousel-wrap' ), 1141 $mapbox = $( '<div></div>' ), 1142 style = '&scale=2&style=feature:all|element:all|invert_lightness:true|hue:0x0077FF|saturation:-50|lightness:-5|gamma:0.91'; 1143 1144 $mapbox 1145 .addClass( 'jp-carousel-image-map' ) 1146 .html( '<img width="154" height="154" src="https://maps.googleapis.com/maps/api/staticmap?\ 1147 center=' + latitude + ',' + longitude + '&\ 1148 zoom=8&\ 1149 size=154x154&\ 1150 sensor=false&\ 1151 markers=size:medium%7Ccolor:blue%7C' + latitude + ',' + longitude + style +'" class="gmap-main" />\ 1152 \ 1153 <div class="gmap-topright"><div class="imgclip"><img width="175" height="154" src="https://maps.googleapis.com/maps/api/staticmap?\ 1154 center=' + latitude + ',' + longitude + '&\ 1155 zoom=3&\ 1156 size=175x154&\ 1157 sensor=false&\ 1158 markers=size:small%7Ccolor:blue%7C' + latitude + ',' + longitude + style + '"c /></div></div>\ 1159 \ 1160 ' ) 1161 .prependTo( $metabox ); 1162 }, 1163 1164 testCommentsOpened: function( opened ) { 1165 if ( 1 == parseInt( opened, 10 ) ) { 1166 $('.jp-carousel-buttons').fadeIn('fast'); 1167 commentForm.fadeIn('fast'); 1168 } else { 1169 $('.jp-carousel-buttons').fadeOut('fast'); 1170 commentForm.fadeOut('fast'); 1171 } 1172 }, 1173 1174 getComments: function( args ) { 1175 if ( 'object' != typeof args ) 1176 args = {}; 1177 1178 if ( ! args.attachment_id || 'undefined' == typeof args.attachment_id ) 1179 return; 1180 1181 if ( ! args.offset || 'undefined' == typeof args.offset || args.offset < 1 ) 1182 args.offset = 0; 1183 1184 var comments = $('.jp-carousel-comments'), 1185 commentsLoading = $('#jp-carousel-comments-loading'); 1186 1187 commentsLoading.show(); 1188 1189 if ( args.clear ) { 1190 comments.hide(); 1191 comments.empty(); 1192 } 1193 1194 $.ajax({ 1195 type: 'GET', 1196 url: jetpackCarouselStrings.ajaxurl, 1197 dataType: 'json', 1198 data: { 1199 action: 'get_attachment_comments', 1200 nonce: jetpackCarouselStrings.nonce, 1201 id: args.attachment_id, 1202 offset: args.offset 1203 }, 1204 success: function(data, status, xhr) { 1205 if ( args.clear ) { 1206 comments.fadeOut('fast'); 1207 comments.empty(); 1208 } 1209 1210 $( data ).each(function(){ 1211 var comment = $('<div></div>') 1212 .addClass('jp-carousel-comment') 1213 .attr('id', 'jp-carousel-comment-' + this['id']) 1214 .css({}) 1215 .html( 1216 '<div class="comment-gravatar">' 1217 + this['gravatar_markup'] 1218 + '</div>' 1219 + '<div class="comment-author">' 1220 + this['author_markup'] 1221 + '</div>' 1222 + '<div class="comment-date">' 1223 + this['date_gmt'] 1224 + '</div>' 1225 + '<div class="comment-content">' 1226 + this['content'] 1227 + '</div>' 1228 ); 1229 comments.append(comment); 1230 1231 // Set the interval to check for a new page of comments. 1232 clearInterval( commentInterval ); 1233 commentInterval = setInterval( function() { 1234 if ( ( $('.jp-carousel-overlay').height() - 150 ) < $('.jp-carousel-wrap').scrollTop() + $(window).height() ) { 1235 gallery.jp_carousel('getComments',{ attachment_id: args.attachment_id, offset: args.offset + 10, clear: false }); 1236 clearInterval( commentInterval ); 1237 } 1238 }, 150 ); 1239 }); 1240 1241 // Verify (late) that the user didn't repeatldy click the arrows really fast, in which case the requested 1242 // attachment id might no longer match the current attachment id by the time we get the data back or a now 1243 // registered infiniscroll event kicks in, so we don't ever display comments for the wrong image by mistake. 1244 var current = $('.jp-carousel div.selected'); 1245 if ( current && current.data && current.data('attachment-id') != args.attachment_id ) { 1246 comments.fadeOut('fast'); 1247 comments.empty(); 1248 return; 1249 } 1250 1251 // Increase the height of the background, semi-transparent overlay to match the new length of the comments list. 1252 $('.jp-carousel-overlay').height( $(window).height() + titleAndDescription.height() + commentForm.height() + ( (comments.height() > 0) ? comments.height() : imageMeta.height() ) + 200 ); 1253 1254 comments.show(); 1255 commentsLoading.hide(); 1256 }, 1257 error: function(xhr, status, error) { 1258 // TODO: proper error handling 1259 console.log( 'Comment get fail...', xhr, status, error ); 1260 comments.fadeIn('fast'); 1261 commentsLoading.fadeOut('fast'); 1262 } 1263 }); 1264 }, 1265 1266 postCommentError: function(args) { 1267 if ( 'object' != typeof args ) 1268 args = {}; 1269 if ( ! args.field || 'undefined' == typeof args.field || ! args.error || 'undefined' == typeof args.error ) 1270 return;
1271 $('#jp-carousel-comment-post-results').slideUp('fast').html('<span class="jp-carousel-comment-post-error">'+args.error+'</span>').slideDown('fast'); 1272 $('#jp-carousel-comment-form-spinner').spin(false); 1273 }, 1274 1275 setCommentIframeSrc: function(attachment_id) { 1276 var iframe = $('#jp-carousel-comment-iframe'); 1277 // Set the proper irame src for the current attachment id 1278 if (iframe && iframe.length) { 1279 iframe.attr('src', iframe.attr('src').replace(/(postid=)\d+/, '$1'+attachment_id) ); 1280 iframe.attr('src', iframe.attr('src').replace(/(%23.+)?$/, '%23jp-carousel-'+attachment_id) ); 1281 } 1282 }, 1283 1284 clearCommentTextAreaValue: function() { 1285 var commentTextArea = $('#jp-carousel-comment-form-comment-field'); 1286 if ( commentTextArea ) 1287 commentTextArea.val(''); 1288 } 1289 }; 1290 1291 $.fn.jp_carousel = function(method){ 1292 // ask for the HTML of the gallery 1293 // Method calling logic 1294 if ( methods[method] ) { 1295 return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); 1296 } else if ( typeof method === 'object' || ! method ) { 1297 return methods.open.apply( this, arguments ); 1298 } else { 1299 $.error( 'Method ' + method + ' does not exist on jQuery.jp_carousel' ); 1300 } 1301 1302 }; 1303 1304 // register the event listener for starting the gallery 1305 $( document.body ).on( 'click', 'div.gallery,div.tiled-gallery', function(e) { 1306 if ( ! $(this).jp_carousel( 'testForData', e.currentTarget ) ) 1307 return; 1308 if ( $(e.target).parent().hasClass('gallery-caption') ) 1309 return; 1310 e.preventDefault(); 1311 $(this).jp_carousel('open', {start_index: $(this).find('.gallery-item, .tiled-gallery-item').index($(e.target).parents('.gallery-item, .tiled-gallery-item'))}); 1312 }); 1313 1314 // Set an interval on page load to load the carousel if hash exists and not already opened. 1315 // Makes carousel work on page load and when back button leads to same URL with carousel hash (ie: no actual document.ready trigger) 1316 $(document).ready(function(){ 1317 last_known_location_hash = ''; 1318 1319 var jp_carousel_open_interval = window.setInterval(function(){ 1320 // We should have a URL hash by now. 1321 if ( ! document.location.hash || ! document.location.hash.match(/jp-carousel-(\d+)/) ) 1322 return; 1323 1324 if ( document.location.hash == last_known_location_hash ) 1325 return; 1326 1327 last_known_location_hash = document.location.hash; 1328 1329 var gallery = $('div.gallery, div.tiled-gallery'), index = -1, n = document.location.hash.match(/jp-carousel-(\d+)/); 1330 1331 if ( ! $(this).jp_carousel( 'testForData', gallery ) ) 1332 return; 1333 1334 n = parseInt(n[1], 10); 1335 1336 gallery.find('img').each(function(num, el){ 1337 if ( n && $(el).data('attachment-id') == n ) { // n cannot be 0 (zero) 1338 index = num; 1339 return false; 1340 } 1341 }); 1342 1343 if ( index != -1 ) 1344 gallery.jp_carousel('open', {start_index: index}); // open method checks if already opened 1345 }, 1000); 1346 }); 1347}); 1348 1349// Swipe gesture detection 1350(function($){$.fn.touchwipe=function(settings){var config={min_move_x:20,min_move_y:20,wipeLeft:function(){},wipeRight:function(){},wipeUp:function(){},wipeDown:function(){},preventDefaultEvents:true};if(settings)$.extend(config,settings);this.each(function(){var startX;var startY;var isMoving=false;function cancelTouch(){this.removeEventListener('touchmove',onTouchMove);startX=null;isMoving=false}function onTouchMove(e){if(config.preventDefaultEvents){e.preventDefault()}if(isMoving){var x=e.touches[0].pageX;var y=e.touches[0].pageY;var dx=startX-x;var dy=startY-y;if(Math.abs(dx)>=config.min_move_x){cancelTouch();if(dx>0){config.wipeLeft()}else{config.wipeRight()}}else if(Math.abs(dy)>=config.min_move_y){cancelTouch();if(dy>0){config.wipeDown()}else{config.wipeUp()}}}}function onTouchStart(e){if(e.touches.length==1){startX=e.touches[0].pageX;startY=e.touches[0].pageY;isMoving=true;this.addEventListener('touchmove',onTouchMove,false)}}if('ontouchstart'in document.documentElement){this.addEventListener('touchstart',onTouchStart,false)}});return this}})(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.