2014-09-05 2 views
0

동토 및 터치 터치 기반의 포트폴리오가 포함 된 구입 한 템플릿이 포함 된 Joomla 사이트가 있습니다. 다른 게시물에 설명 된 것과 동일한 문제가 있습니다. 유일한 차이점은 fancybox를 사용하고 템플릿에 touchtouch를 사용한다는 것입니다. jQuery Isotope filtering with FancyboxjQuery 동위 원소 필터링

는 여기에 문제의 설명입니다 :

포트폴리오는 미리보기의 갤러리가 포함되어 있습니다. 축소판을 클릭 한 다음 터치 터치 플러그인을 사용하여 이미지를 순환 할 수 있습니다. 이제 갤러리가 필터링 될 때 touchtouch 플러그인은 모든 이미지를 순환합니다. 필터 적용시 나타나지 않는 사람도 있습니다.

fancybox-post의 솔루션을 변형하려고했지만 여전히 어떻게 해결할 수 있는지 잘 모릅니다.

나는 하나 gallery.php에서 다음 스크립트를 수정해야한다고 가정 :

<script type="text/javascript"> 
    jQuery(document).ready(function() { 
    (function($){ 
    $(window).load(function(){ 

    var $container = $('#isotopeContainer'); 

    // filter items when filter link is clicked 
    $('#filters a').click(function(){ 
     var selector = $(this).attr('data-filter'); 
     $container.isotope({ filter: selector }); 
     return false; 
    }); 

    var $optionSets = $('#filters li'), 
     $optionLinks = $optionSets.find('a'); 

     $optionLinks.click(function(){ 
      var $this = $(this); 
      // don't proceed if already selected 
      if ($this.hasClass('selected')) { 
       return false; 
      } 
      var $optionSet = $this.parents('#filters'); 
      $optionSet.find('.selected').removeClass('selected'); 
      $this.addClass('selected'); 

      // make option object dynamically, i.e. { filter: '.my-filter-class' } 
      var options = {}, 
       key = $optionSet.attr('data-option-key'), 
       value = $this.attr('data-option-value'); 
      // parse 'false' as false boolean 
      value = value === 'false' ? false : value; 
      options[ key ] = value; 
      if (key === 'layoutMode' && typeof changeLayoutMode === 'function') { 
       // changes in layout modes need extra logic 
       changeLayoutMode($this, options) 
      } else { 
       // otherwise, apply new options 
       $container.isotope(options); 
      } 

      return false; 
     }); 
    }); 
})(jQuery); 
}); 
</script> 

어떻게이 작업을 수행하는 어떤 생각을 가지고 있습니까?

답변

0

나는 그것을 한 것을 기쁘게 생각한다. 내 첫 번째 아이디어 (이전 게시물 참조)가 나에게 효과가 없었지만 어떻게 작동하는지 더 잘 이해했다. 그래서 다른 방법을 찾았습니다. 이제 요소에 범주를 표시하고

var overlay = $('<div id="galleryOverlay">'), 
    slider = $('<div id="gallerySlider">'), 
    prevArrow = $('<a id="prevArrow"></a>'), 
    nextArrow = $('<a id="nextArrow"></a>'), 
    overlayVisible = false; 
var gtritems = [];  

/* Creating the plugin */ 

$.fn.touchTouch = function(){ 

    var placeholders = $([]), 
     index = 0, 
     items = this; 

    // Appending the markup to the page 
    overlay.hide().appendTo('body'); 
    slider.appendTo(overlay); 

    // Creating a placeholder for each image 
    items.each(function(){ 
     placeholders = placeholders.add($('<div class="placeholder">')); 
    }); 

    $("#gallerySlider").empty(); 
    // Hide the gallery if the background is touched/clicked 
    slider.append(placeholders).on('click',function(e){ 
     if(!$(e.target).is('img')){ 
      hideOverlay(); 
     } 
    }); 

    // Listen for touch events on the body and check if they 
    // originated in #gallerySlider img - the images in the slider. 
    $('body').on('touchstart', '#gallerySlider img', function(e){ 

     var touch = e.originalEvent, 
      startX = touch.changedTouches[0].pageX; 

     slider.on('touchmove',function(e){ 

      e.preventDefault(); 

      touch = e.originalEvent.touches[0] || 
        e.originalEvent.changedTouches[0]; 

      if(touch.pageX - startX > 10){ 
       slider.off('touchmove'); 
       showPrevious(); 
      } 
      else if (touch.pageX - startX < -10){ 
       slider.off('touchmove'); 
       showNext(); 
      } 
     }); 

     // Return false to prevent image 
     // highlighting on Android 
     return false; 

    }).on('touchend',function(){ 
     slider.off('touchmove'); 
    }); 

    // Listening for clicks on the thumbnails 

    items.on('click', function(e){ 
     e.preventDefault(); 

     // Find the position of this image 
     // in the collection 

     function Gtr(obj, href, ind, itemind) { 
      this.obj=obj; 
      this.href=href; 
      this.ind=ind; 
      this.itemind=itemind; 
      return this; 
     } 
     gtritems = []; 
     var i = 0; 
     var oldindex = items.index(this); 
     $.each(items, function() { 
      if(window.selector == '*'){ 
       gtritems.push(new Gtr(this, items.eq(items.index(this)).attr('href'), items.index(this), items.index(this))); 
       if(oldindex == items.index(this)) { 
        index = oldindex; 
       } 
      } else { 
       if($(this).attr("class").split(" ",4)[3] == window.selector.substr(1)){ 
        gtritems.push(new Gtr(this, items.eq(items.index(this)).attr('href'), i, items.index(this))); 
        if(oldindex == items.index(this)) { 
         index = i; 
        } 
        i++; 
       } 
      } 
     }); 
    ... 
0

계정 필터를 사용하는 작업 탐색 방법을 찾았지만 이제는 포트폴리오가 처음 나타날 때 - 필터링 전 - 터치 터치 플러그인이 실행되지 않는다는 문제점이 있습니다. script.js에서

<?php if($this->params->get('show_filter')): ?> 

<script type="text/javascript"> 
    jQuery(document).ready(function() { 
    (function($){ 
    $(window).load(function(){ 

    var $container = $('#isotopeContainer'); 

    // filter items when filter link is clicked 
    $('#filters a').click(function(){ 
     var selector = $(this).attr('data-filter'); 
     $container.isotope({ filter: selector }); 
     if(selector == "*"){ 
     console.log(selector); 
     } else { 
     $(".touchGalleryLink").removeClass("MyCat"); 
     $(".touchGalleryLink").each(function() { 
      var tmpvar = $(this).parent().parent().attr('class').split(" ",2); 
      if(tmpvar[1] == selector.substr(1)){ 
       $(this).addClass("MyCat"); 
      } 
     }); 
     } 
     jQuery('a.touchGalleryLink.MyCat').touchTouch(); 
     return false; 
    }); 
... 

내가 줄을 주석하는 데 필요한 파일 :

Gallery.php (템플릿 재정의 일부) : 여기

나는 당신에게 관련 코드를 보여

(function($){ 

/* Private variables */ 

var overlay = $('<div id="galleryOverlay">'), 
slider = $('<div id="gallerySlider">'), 
prevArrow = $('<a id="prevArrow"></a>'), 
nextArrow = $('<a id="nextArrow"></a>'), 
overlayVisible = false; 

/* Creating the plugin */ 

$.fn.touchTouch = function(){ 

    var placeholders = $([]), 
    index = 0, 
    items = this; 
    // Appending the markup to the page 
    overlay.hide().appendTo('body'); 
    slider.appendTo(overlay); 

    // Creating a placeholder for each image 
    items.each(function(){ 
    placeholders = placeholders.add($('<div class="placeholder">')); 
}); 

... 
: 정보 touch.galery.js 파일을 heres 일부를 들어
jQuery(document).ready(function() { 
    ... 
    // Initialize the gallery touch 
    //jQuery('a.touchGalleryLink').touchTouch(); 
    ... 

누군가가이 좋을 텐데 처음으로도 작동 할 수있는 방법을 찾아야하는 데 도움 수 있다면 ... 나는 거의 내가 원하는 것을 얻을이 시점에서

0

하지만 버그가 내 코드에 존재하고 나는 그것이 어디에서 왔는지 알 수 없다.

내가 선택한 솔루션은 새로운 클래스 MyCat을 소개하는 것이며 내 수정은이 클래스가 이미지가 현재 범주에 해당하고 jquery가이 클래스를 고려하면이 클래스가 존재하는지 확인하려고합니다.

다음은이 버그에 대한 설명입니다. 이것은 처음에 x 이미지가 포함 된 범주를 필터링하고이를 통해 탐색하고 마지막 이미지의 탐색에서 벗어날 때 발생합니다. 그러면 x 이미지보다 작은 카테고리로 필터링하고 y라고 말하면됩니다. 이미지를 클릭하면 이미지가 나타나지 않거나 이미지가 손상 될 수 있습니다.) 올바른 이미지를 얻으려면 이전 이미지 링크 (y-x)를 클릭해야합니다. 현재 다음 이미지 링크를 사용할 수 없으므로 시스템이 안정화되었습니다.

내가 알지 못하면 내 설명을 이해할 수 있기를 바랍니다. 좀 더 우아한 방법이 있는지 모르겠지만 거의 효과가 있습니다. 버그를 설명 할 수있는 것이 있으면 알려주세요.

gallery.php :

... 
<?php if((!empty($this->lead_items) || (!empty($this->intro_items))) && $this->params->get('show_filter')): ?> 
     <div class="filters"> 


     <ul id="filters" class="unstyled"> 
      <li><a href="#" data-filter="*" class="selected"><?php echo JText::_('TPL_COM_CONTENT_GALLERY_FILTER_SHOW_ALL'); ?></a></li> 
      <?php 
      foreach ($galleryCategories as $key => $value) : 
      ?> 
      <li><a class="" href="#"data-filter=".<?php echo special_chars_replace($value); ?>"><?php echo ucwords(str_replace("_"," ",$value)); ?></a></li> 
      <?php endforeach; ?> 
     </ul> 

     <div class="clearfix"></div> 
     </div> 
<?php endif; ?> 
... 
<div class="row-fluid"> 
    <ul id="isotopeContainer" class="gallery items-row cols-<?php echo (int) $this->columns;?>"> 
    <?php 
     $valgtr = array(); 
     $keysgtr = array_keys($this->intro_items); 
     shuffle($keysgtr); 
     foreach($keysgtr as $keygtr) $valgtr[] = $this->intro_items[$keygtr]; 

     foreach ($valgtr as $key => &$item) : 
    ?> 
    <?php 
     $key = ($key - $leadingcount) + 1; 
     $rowcount = (((int) $key - 1) % (int) $this->columns) + 1; 

     if ($rowcount == 1) : ?>  
     <?php endif; ?> 

     <li class="gallery-item <?php echo special_chars_replace(strtolower(str_replace(" ","_",$item->category_title))); ?>"> 
      <?php 
      $this->item = &$item; 
      echo $this->loadTemplate('item'); 
... 
<script type="text/javascript"> 
    jQuery(document).ready(function() { 
    (function($){ 
    $(window).load(function(){ 
    var $cols = <?php echo $this->columns; ?>; 
    var $container = $('#isotopeContainer'); 

    $item = $('.gallery-item') 
    $item.outerWidth(Math.floor($container.width()/$cols)); 

    $container.isotope({ 
     animationEngine: 'best-available', 
     animationOptions: { 
      queue: false, 
      duration: 800 
     }, 
     containerClass : 'isotope', 
     containerStyle: { 
      position: 'relative', 
      overflow: 'hidden' 
     }, 
     hiddenClass : 'isotope-hidden', 
     itemClass : 'isotope-item', 
     resizable: true, 
     resizesContainer : true, 
     transformsEnabled: !$.browser.opera // disable transforms in Opera 
    }); 

    if($container.width() <= '767'){ 
     $item.outerWidth($container.width()); 
     $item.addClass('straightDown'); 
     $container.isotope({ 
     layoutMode: 'straightDown' 
     }); 
    } else { 
     $item.removeClass('straightDown'); 
     $container.isotope({ 
     layoutMode: 'fitRows' 
     }); 
    } 

    $(window).resize(function(){ 
     $item.outerWidth(Math.floor($container.width()/$cols)); 
     if($container.width() <= '767'){ 
     $item.outerWidth($container.width()); 
     $item.addClass('straightDown'); 
     $container.isotope({ 
      layoutMode: 'straightDown' 
     }); 
     } else { 
     $item.outerWidth(Math.floor($container.width()/$cols)); 
     $item.removeClass('straightDown'); 
     $container.isotope({ 
      layoutMode: 'fitRows' 
     }); 
     } 
    }); 
    }); 
})(jQuery); 
}); 
</script> 

<?php if($this->params->get('show_filter')): ?> 

<script type="text/javascript"> 
    jQuery(document).ready(function() { 
    (function($){ 
    $(window).load(function(){ 
    var $container = $('#isotopeContainer'); 

    // filter items when filter link is clicked 
    $('#filters a').click(function(){ 
     var selector = $(this).attr('data-filter'); 
     $container.isotope({ filter: selector }); 
     if(selector == "*"){ 
     $(".touchGalleryLink").addClass("MyCat"); 
     } else { 
     $(".touchGalleryLink").removeClass("MyCat"); 
     $(".touchGalleryLink").each(function() { 
      var tmpvar = $(this).parent().parent().attr('class').split(" ",2); 
      if(tmpvar[1] == selector.substr(1)){ 
      $(this).addClass("MyCat"); 
     } 
     }); 
    } 
    jQuery('a.touchGalleryLink.MyCat').touchTouch(); 
    return false; 
    }); 
    $("#filters a:first").trigger("click"); 

    var $optionSets = $('#filters li'), 
     $optionLinks = $optionSets.find('a'); 

     $optionLinks.click(function(){ 
      var $this = $(this); 
      // don't proceed if already selected 
      if ($this.hasClass('selected')) { 
      return false; 
      } 
      var $optionSet = $this.parents('#filters'); 
      $optionSet.find('.selected').removeClass('selected'); 
      $this.addClass('selected'); 

      // make option object dynamically, i.e. { filter: '.my-filter-class' } 
      var options = {}, 
       key = $optionSet.attr('data-option-key'), 
       value = $this.attr('data-option-value'); 
      // parse 'false' as false boolean 
      value = value === 'false' ? false : value; 
      options[ key ] = value; 
      if (key === 'layoutMode' && typeof changeLayoutMode === 'function') { 
      // changes in layout modes need extra logic 
      changeLayoutMode($this, options) 
      } else { 
      // otherwise, apply new options 
      $container.isotope(options); 
      } 

      return false; 
     }); 
    }); 
})(jQuery); 
}); 
</script> 

<?php endif; ?> 

touch.gallery.js : 여기

내가 수정이 개 중요한 파일의 코드

(function($){ 

    /* Private variables */ 
    var overlay = $('<div id="galleryOverlay">'), 
    slider = $('<div id="gallerySlider">'), 
    prevArrow = $('<a id="prevArrow"></a>'), 
    nextArrow = $('<a id="nextArrow"></a>'), 
    overlayVisible = false; 


/* Creating the plugin */ 

$.fn.touchTouch = function(){ 

    var placeholders = $([]), 
     index = 0, 
     items = this; 
     gtritems = items; 
     $.each(gtritems, function() { 
      if(!$(this).hasClass("MyCat")){ 
      $(this).remove(); 
      } 
     }); 
     console.log(gtritems); 
    // Appending the markup to the page 
    overlay.hide().appendTo('body'); 
    slider.appendTo(overlay); 

    // Creating a placeholder for each image 
    gtritems.each(function(){ 
     placeholders = placeholders.add($('<div class="placeholder">')); 
    }); 

    $("#gallerySlider").empty(); 
    // Hide the gallery if the background is touched/clicked 
    slider.append(placeholders).on('click',function(e){ 
     if(!$(e.target).is('img')){ 
     hideOverlay(); 
     } 
    }); 

    // Listen for touch events on the body and check if they 
    // originated in #gallerySlider img - the images in the slider. 
    $('body').on('touchstart', '#gallerySlider img', function(e){ 

     var touch = e.originalEvent, 
     startX = touch.changedTouches[0].pageX; 

     slider.on('touchmove',function(e){ 

     e.preventDefault(); 

     touch = e.originalEvent.touches[0] || 
      e.originalEvent.changedTouches[0]; 

     if(touch.pageX - startX > 10){ 
      slider.off('touchmove'); 
      showPrevious(); 
     } 
     else if (touch.pageX - startX < -10){ 
      slider.off('touchmove'); 
      showNext(); 
      } 
     }); 

     // Return false to prevent image 
     // highlighting on Android 
     return false; 

    }).on('touchend',function(){ 
     slider.off('touchmove'); 
    }); 

    // Listening for clicks on the thumbnails 

    gtritems.on('click', function(e){ 
     e.preventDefault(); 

     // Find the position of this image 
     // in the collection 

     index = gtritems.index(this); 
     console.log(this); 
     showOverlay(index); 
     showImage(index); 

     // Preload the next image 
     preload(index+1); 

     // Preload the previous 
     preload(index-1); 

    }); 

    // If the browser does not have support 
    // for touch, display the arrows 
    if (!("ontouchstart" in window)){ 
     overlay.append(prevArrow).append(nextArrow); 

     prevArrow.click(function(e){ 
     e.preventDefault(); 
     showPrevious(); 
     }); 

     nextArrow.click(function(e){ 
     e.preventDefault(); 
     showNext(); 
     }); 
    } 

    // Listen for arrow keys 
    $(window).bind('keydown', function(e){ 

     if (e.keyCode == 37){ 
     showPrevious(); 
     } 
     else if (e.keyCode==39){ 
     showNext(); 
     } 

    }); 


    /* Private functions */ 


    function showOverlay(index){ 

     // If the overlay is already shown, exit 
     if (overlayVisible){ 
     return false; 
     } 

     // Show the overlay 
     overlay.show(); 

     setTimeout(function(){ 
     // Trigger the opacity CSS transition 
     overlay.addClass('visible'); 
     }, 100); 

     // Move the slider to the correct image 
     offsetSlider(index); 

     // Raise the visible flag 
     overlayVisible = true; 
    } 

    function hideOverlay(){ 
     // If the overlay is not shown, exit 
     if(!overlayVisible){ 
     return false; 
     } 

     // Hide the overlay 
     overlay.hide().removeClass('visible'); 
     overlayVisible = false; 
    } 

    function offsetSlider(index){ 
     // This will trigger a smooth css transition 
     slider.css('left',(-index*100)+'%'); 
    } 

    // Preload an image by its index in the items array 
    function preload(index){ 
     setTimeout(function(){ 
     showImage(index); 
     }, 1000); 
    } 

    // Show image in the slider 
    function showImage(index){ 

     // If the index is outside the bonds of the array 
     if(index < 0 || index >= gtritems.length){ 
     return false; 
     } 

     // Call the load function with the href attribute of the item 
     loadImage(gtritems.eq(index).attr('href'), function(){ 
     placeholders.eq(index).html(this); 
     }); 
    } 

    // Load the image and execute a callback function. 
    // Returns a jQuery object 

    function loadImage(src, callback){ 
     var img = $('<img>').on('load', function(){ 
     callback.call(img); 
     }); 

     img.attr('src',src); 
     } 

     function showNext(){ 

     // If this is not the last image 
     if(index+1 < gtritems.length){ 
      index++; 
      offsetSlider(index); 
      preload(index+1); 
     } 
     else{ 
      // Trigger the spring animation 

      slider.addClass('rightSpring'); 
      setTimeout(function(){ 
      slider.removeClass('rightSpring'); 
      },500); 
     } 
     } 

    function showPrevious(){ 

     // If this is not the first image 
     if(index>0){ 
     index--; 
     offsetSlider(index); 
     preload(index-1); 
     } 
     else{ 
     // Trigger the spring animation 

     slider.addClass('leftSpring'); 
     setTimeout(function(){ 
      slider.removeClass('leftSpring'); 
     },500); 
     } 
    } 
}; 

})(jQuery); 
0

나는 확실히 아니에요 jquery expert 이 시점에서 내 솔루션의 버그는 script.js 파일에서 touchtouch 함수 호출을 이동해야한다는 사실에서 비롯된 것이라고 생각합니다. 1 ti me 페이지 로딩 시간 필터가 변경 될 때마다 실행되는 필터 클릭 기능. 변수 gtritems를 콘솔에서 관찰하고 필터 할 때마다 새로운 발생과 같은 것을 추가하고 모든 누적이 오류를 유발하는 것처럼 보일 수 있습니다.

새로운 깨끗한 코드가 실행
jQuery('a.touchGalleryLink.MyCat').touchTouch(); 

거기 : 나는 호출 할 때 있도록 정리하는 방법은 이전 발행 수 있습니까? 일부 도움은 정말 감사하겠습니다!

관련 문제