2012-04-18 4 views
0

나는 지금 다른 사람 안쪽에 적합하도록 고쳐 쓸 필요없이 2 개의 wordpress plugins를 결합하는 것을 시도하고있다.플러그인 내부에서 함수 호출. Wordpress 작풍

내 가장 기본적인 질문 : 다른 플러그인 외부에있는 함수를 어떻게 호출합니까? 예 :

1) JS/

2 N_Rotator.js

) JS/layerSlider.js

그 중 두 가지가 제대로 작동

: 나는 두 개의 파일이 있습니다. 첫 번째 이미지는 배경에서 회전하는 이미지입니다. 두 번째 것은 회전하는 내용 (예 : 제목, 이미지 링크 등)입니다.

내가해야 할 일은 둘 다 동기화하는 것입니다. 슬라이더 2가 회전하면 슬라이더 1도 회전합니다.() 종료를하지 않습니다, 그 ANIM을

a('#carousel').infiniteCarousel({ anim('next'); }); 

하지만 오류가 발생합니다 :

는 뒷조사를하고 후, 나는이 같은 슬라이더 2에서 슬라이더 1을 시작할 수 있다는 것을 발견했다. 그래서 슬라이더 1 js 안에, 나는 그것을 변수 안에 두었습니다.
if(o.play) { 
    anim('next'); 
} 

그런 다음 슬라이더 2에서 지금처럼 전화 :

a('#carousel').infiniteCarousel({ play:1 }); 

그러나 않는 모든 그것의 시작 때마다 처음부터 시작하게됩니다. 한 번 미끄러 져서 처음으로 되돌아 가게됩니다.

그래서 제가 스스로 기능을 호출 할 수있는 방법이 있습니까? 이것은 anim()의 구조입니다. (이전에 만든 infiniteCarousel 플러그인에서 가져온 것).

function anim(direction,dist) 
      { 
       // Fade left/right arrows out when transitioning 
       $('#btn_rt'+randID).fadeOut(500); 
       $('#btn_lt'+randID).fadeOut(500); 

       // animate textholder out of frame 
       $('#textholder'+randID).animate({marginBottom:(-imgHeight*o.textholderHeight)-(correctTHHeight * 2)+'px'},500);     

       //?? Fade out play/pause? 
       $('#pause_btn'+randID).fadeOut(250); 
       $('#play_btn'+randID).fadeOut(250); 



       if(direction == "next") 
       { 
        if(curr==numImages) curr=0; 
        if(dist>1) 
        { 
         borderpatrol($('#thumb'+randID+'_'+(curr+dist))); 
         $('li:lt(2)', obj).clone().insertAfter($('li:last', obj)); 
         $('ul', obj).animate({left:-imgWidth*(dist+1)},o.transitionSpeed,function(){ 
          $('li:lt(2)', obj).remove(); 
          for(j=1;j<=dist-2;j++) 
          { 
           $('li:first', obj).clone().insertAfter($('li:last', obj)); 
           $('li:first', obj).remove(); 
          } 

          $(this).css({'left':-imgWidth}); 
          curr = curr+dist; 
          $('#thumbs'+randID+' div').bind('click', thumbclick).css({'cursor':'pointer'}); 
         }); 
        } 
        else 
        { 
         borderpatrol($('#thumb'+randID+'_'+(curr+1))); 
         $('#thumbs'+randID+' div').css({'cursor':'default'}).unbind('click'); // Unbind the thumbnail click event until the transition has ended 
         // Copy leftmost (first) li and insert it after the last li 
         $('li:first', obj).clone().insertAfter($('li:last', obj)); 
         // Update width and left position of ul and animate ul to the left 
         $('ul', obj) 
          .animate({left:-imgWidth-960},o.transitionSpeed,function(){ 
           $('li:first', obj).remove(); 
           $('ul', obj).css('left',-imgWidth+'px'); 
           $('#btn_rt'+randID).fadeIn(500); 
           $('#btn_lt'+randID).fadeIn(500); 
           if(autopilot) $('#pause_btn'+randID).fadeIn(250); 
           if(autopilot) 
           { 
            $('#progress'+randID).width(imgWidth).height(pbarHeight).fadeIn(500); 
            $('#progress'+randID).fadeIn(500).animate({'width':0},o.displayTime,function(){ 
             $('#pause_btn'+randID).fadeOut(50); 
             setTimeout(function(){$('#pause_btn'+randID).fadeIn(250)},o.transitionSpeed) 
            }); 
           } 
           curr=curr+1; 
           $('#thumbs'+randID+' div').bind('click', thumbclick).css({'cursor':'pointer'}); 
          }); 
        } 
       } 
       if(direction == "prev") 
       { 
        if(dist>1) 
        { 
         borderpatrol($('#thumb'+randID+'_'+(curr-dist))); 
         $('li:gt('+(numImages-(dist+1))+')', obj).clone().insertBefore($('li:first', obj)); 
         $('ul', obj).css({'left':(-imgWidth*(dist+1))}).animate({left:-imgWidth},o.transitionSpeed,function(){ 
          $('li:gt('+(numImages-1)+')', obj).remove(); 
          curr = curr - dist; 
          $('#thumbs'+randID+' div').bind('click', thumbclick).css({'cursor':'pointer'}); 
         }); 
        } 
        else 
        { 
         borderpatrol($('#thumb'+randID+'_'+(curr-1))); 
         $('#thumbs'+randID+' div').css({'cursor':'default'}).unbind('click'); // Unbind the thumbnail click event until the transition has ended 
         // Copy rightmost (last) li and insert it after the first li 
         $('li:last', obj).clone().insertBefore($('li:first', obj)); 
         // Update width and left position of ul and animate ul to the right 
         $('ul', obj) 
          .css('left',-imgWidth*2+'px') 
          .animate({left:-imgWidth},o.transitionSpeed,function(){ 
           $('li:last', obj).remove(); 
           $('#btn_rt'+randID).fadeIn(500); 
           $('#btn_lt'+randID).fadeIn(500); 
           if(autopilot) $('#pause_btn'+randID).fadeIn(250); 
           curr=curr-1; 
           if(curr==0) curr=numImages; 
           $('#thumbs'+randID+' div').bind('click', thumbclick).css({'cursor':'pointer'}); 
          }); 
        } 
       } 
      } 

그리고 플러그인은 다음과 같이 구성되어있다 :

(function($) { 

$.fn.extend({ 
    infiniteCarousel: function(options) { 
     var defaults = { 
      defaults... 
     }; 
    var options = $.extend(defaults, options); 

     return this.each(function() { ...anim is inside here... } }); })(jQuery); 

내가 플러그인을 다시 시작하지 않고 함수를 호출 할 수있는 방법에 어떤 아이디어가?

참고 : 사이트 링크를 공유 할 수 없으며 아직 개발 중이며 클라이언트는 이름이없는 채로 있어야합니다. 실례를 보여 주면 좋을 것입니다.

답변

0

JavaScript 코드 내에서 어떤 일이 일어나는지 확실하지 않지만 한 스크립트를 다른 스크립트에 종속 시키려면 wp_register_script() 함수의 종속성으로 추가하십시오.