2014-05-25 4 views
2

사용자가 자바 스크립트를 삽입 할 수있는 플랫폼 용 스크립트를 만들려고합니다. 그들은 YUI를 사용하여 특별히 Y.one('body).delegate('click',...)을 사용하여 버튼에 이벤트를 첨부합니다. 이 버튼을 가로 채고 싶지만 이벤트 처리기를 시작, 차단, 제거 또는 중지하는 방법을 파악할 수 없습니다.YUI 위임 이벤트를 제거하려면 어떻게해야합니까?

참고 : 내가 Y.delegate`에 의해 반환 된 핸들러()에 직접 액세스 할 수없는

지금까지 내가 아무 소용

Y.detachAll('click'); 
Y.unsubscribeAll('click'); 
Y.one('body').detachAll('click'); 
Y.one('body').unsubscribeAll('click'); 
Y.one('.the-delegated-class').detachAll('click'); 
Y.one('.the-delegated-class').unsubscribeAll('click'); 

모든 시도했습니다. 사실 내가 가지고있는 유일한 성공은 완전히 제거하고 바디 HTML을 대체하는 것입니다.이 HTML은 명백히 제거하려는 이벤트 핸들러와 반대로 모든 이벤트 핸들러를 가져옵니다.

통찰력이 있으십니까?

+0

그 플랫폼은 우연히 스퀘어 공간이 아닙니다. 그렇습니까? : P – cregox

+1

@ 카와 스 예, 왜 그렇게 모호했는지 모르겠다. : -/ – KTastrophy

+0

그렇다면, 나는'destroy (true)'를 사용하고있다 : http://stackoverflow.com/a/9405055/ 274502 – cregox

답변

1

내 시도 중 하나가 올바른 방법이었다하지만 내 사용이 잘못 밝혀졌습니다. 나는 (무의식적으로) 처음에 그 사건이 붙기 전에 사건을 분리하려고 시도했다. 이 작품 Y.one('body).delegate('click',...)

:의 경우 말했다

이상적으로 위임 호출에 의해 반환 된 EventHandle에 직접 분리 호출 거라고하지만 Y.one('body').detach('click')

.

0

대리자 이벤트 메서드가 핸들을 어디에도 저장하지 못하는 경우 대리자 요소에 대한 핸들을 저장하는 Event.delegate에 대한 패치 대체품을 만들 수 있습니다. 패치 YUI의 기본 예제 : https://gist.github.com/tivac/1424351

테스트되지 않은 코드 :

var config = { 
    groups : { 
     patches : { 
      base : "/js/patches/", 
      modules : { 
       "node-event-delegate-patches" : { 
        path : "node-event-delegate.js", 
        condition : { 
         name : "node-event-delegate-patches", 
         trigger : "node-event-delegate", 
         test : function() { return true; } 
        } 
       } 
      } 
     } 
    } 
}; 

YUI.add("node-event-delegate-patches", function(Y) { 
    var L = Y.Lang; 

    Y.Node.prototype.delegate = function(type) { 
     var args = Y.Array(arguments, 0, true), 
      handle, 
      index = (L.isObject(type) && !L.isArray(type)) ? 1 : 2; 
     args.splice(index, 0, this._node); 

     if (!L.isArray(this._node._delegate_event_handles)){ 
      this._node._delegate_event_handles = []; 
     } 
     handle = Y.delegate.apply(Y, args); 
     this._node._delegate_event_handles.push(handle); 
     return handle; 
    }; 

    Y.Node.prototype.detachDelegates = function(){ 
     Y.Array.each(this._node._delegate_event_handles, function(handle){ 
      handle.detach(); 
     }); 
    } 
}); 
관련 문제