2010-05-11 5 views
18

좋아, 내가 jQuery를이 jQuery를 스크립트의 상단에이를 추가하여 하나의 스크립트 Mootools의 함께 가야 :jQuery를하고 Mootools의 충돌

var $j = jQuery.noConflict(); 

후 모든 교체 :

$(

$j(

하지만 어떻게 당신이 얻을 것이다 Mootools의와

는 jQuery를 사용하는 다음 스크립트를 좋아하는? 모든 입력에 미리

감사합니다,

트레이시

//Fade In Content Viewer: By JavaScript Kit: http://www.javascriptkit.com 

var fadecontentviewer={ 
csszindex: 100, 
fade:function($allcontents, togglerid, selected, speed){ 
    var selected=parseInt(selected) 
    var $togglerdiv=$("#"+togglerid) 
    var $target=$allcontents.eq(selected) 
    if ($target.length==0){ //if no content exists at this index position (ie: stemming from redundant pagination link) 
    alert("No content exists at page number "+selected+"!") 
    return 
    } 
    if ($togglerdiv.attr('lastselected')==null || parseInt($togglerdiv.attr('lastselected'))!=selected){ 
    var $toc=$("#"+togglerid+" .toc") 
    var $selectedlink=$toc.eq(selected) 
    $("#"+togglerid+" .next").attr('nextpage', (selected<$allcontents.length-1)? selected+1+'pg' : 0+'pg') 
    $("#"+togglerid+" .prev").attr('previouspage', (selected==0)? $allcontents.length-1+'pg' : selected-1+'pg') 
    $target.css({zIndex: this.csszindex++, visibility: 'visible'}) 
    $target.hide() 
    $target.fadeIn(speed) 
    $toc.removeClass('selected') 
    $selectedlink.addClass('selected') 
    $togglerdiv.attr('lastselected', selected+'pg') 
    } 
}, 

setuptoggler:function($allcontents, togglerid, speed){ 
    var $toc=$("#"+togglerid+" .toc") 
    $toc.each(function(index){ 
    $(this).attr('pagenumber', index+'pg') 
    }) 

    var $next=$("#"+togglerid+" .next") 
    var $prev=$("#"+togglerid+" .prev") 
    $next.click(function(){ 
    fadecontentviewer.fade($allcontents, togglerid, $(this).attr('nextpage'), speed) 
    return false 
    }) 
    $prev.click(function(){ 
    fadecontentviewer.fade($allcontents, togglerid, $(this).attr('previouspage'), speed) 
    return false 
    }) 
    $toc.click(function(){ 
    fadecontentviewer.fade($allcontents, togglerid, $(this).attr('pagenumber'), speed) 
    return false 
    }) 
}, 

init:function(fadeid, contentclass, togglerid, selected, speed){ 
    $(document).ready(function(){ 
    var faderheight=$("#"+fadeid).height() 
    var $fadecontents=$("#"+fadeid+" ."+contentclass) 
    $fadecontents.css({top: 0, left: 0, height: faderheight, visibility: 'hidden'}) 
    fadecontentviewer.setuptoggler($fadecontents, togglerid, speed) 
    setTimeout(function(){fadecontentviewer.fade($fadecontents, togglerid, selected, speed)}, 100) 
    $(window).bind('unload', function(){ //clean up 
    $("#"+togglerid+" .toc").unbind('click') 
    $("#"+togglerid+" .next", "#"+togglerid+" .prev").unbind('click') 
    }) 
    }) 
} 
} 
+1

'$ ('. $ j ('. –

+0

) $를 모두 $처럼 설정하지 않아서 작동하지 않습니다. (그래서 "j "두 개 사이에 있습니다 : 일부는 $ toc $ target $ selectedlink.ect ... 달러 기호/여는 괄호 대신 달러 기호/이름이 있습니다."j "를 거기에 붙이면 실제로 나사못이 생깁니 다. – flipflopmedia

+0

Dimitar Christoff의 대답이 없으면이 기능이 작동하지 않았을 것입니다. 왜냐하면 관계없이 무시하는 것이기 때문입니다. MooTools : 1 개의 MooTools 스크립트로 2 개의 jQuery 스크립트를 즐겁게 사용할 수있는 유일한 방법은 모든 3 개의 스크립트에서 $를 재 할당하는 것입니다! – flipflopmedia

답변

5

내가 Mootools의에서 제공하는 호환성 모드에 대해 잘 모르지만, 쉬운 방법은에서 $(의 모든 항목을 대체하는 것 스크립트 $j( 또는 jQuery(. 당신이 $을 사용하고 jQuery를 특정 코드가있을 때

+0

쉽고 더러움. –

26

는, 가장 간단한 방법은 다음과 같이 코드를 래핑하는 것입니다 :

// Disable the $ global alias completely 
jQuery.noConflict(); 

// For jQuery scripts 
(function($){ 

// set a local $ variable only available in this block as an alias to jQuery 
... here is your jQuery specific code ... 

})(jQuery); 

// For Mootols scripts 
(function($){ 

// set a local $ variable only available in this block as an alias 
// to Mootools document.id 
... here is your Mootools specific code ... 

})(document.id); 

noConflict documentation에 두 번째 예를 참조하십시오.

+1

동일한 것이 반대로 적용됩니다. 즉, mootools는 이미 정의 된 경우 $를 사용하지 않지만 v1.2.1부터 document.id로 되돌아갑니다. 그런 다음 같은 클로저를 적용 할 수 있지만 $ –

+1

Dimitar의 매개 변수로 jQuery 대신'document.id'를 사용하십시오. 나는 3 개의 스크립트를 모두 변경하여 스크립트를 변경해야했습니다 (단 하나의 스크립트 만 변경하면 작동하지 않습니다). var $ j = jQuery.noConflict()를 JQuery 스크립트에 추가하고 var $ = document.id를 추가합니다. MooTools 스크립트에 & 이제 그들은 모두 함께 행복하게 작업합니다. 그것은 당신의 코멘트를 써서 w/out 해본 적이 없으며 v1.2.1을 제안합니다. Vincent는 어떤 이유로 든 위에 붙여 넣은 스크립트에서 작동하지 않았습니다. 그것은 내가 추가 한 다른 1에서 작동했습니다 $ j = jQuery.noConflict(); 하지만 위의 1에 없습니다. 그러나 그것이 작동 할 때를위한 짧은 팁을 알고있어서 기쁩니다. – flipflopmedia

+0

Mootools 개발자를위한 약간의 설명을 위해 Dimitar 솔루션이 포함되어 있습니다. –

1

$$jQuery으로 바꾸면 제대로 작동합니다.