2013-06-12 1 views
0

내 응용 프로그램에는 두 개의 패널이 마스터 레이아웃으로되어 있으므로 모든 하위 페이지에는이 두 개의 패널이 있습니다. 이제 사용자가 어디에서나 두 패널에 액세스 할 수 있도록 응용 프로그램의 모든 내 페이지에 대해 스 와이프 이벤트를 등록하려고합니다. 난 그냥 다른 장소에서 등록이를 호출 할 수 있도록 여기에이 기능을 만들었습니다 (한 번만 스크립트를 실행) 나는 pageinit에서이 함수를 호출 시도JQM 앱의 모든 페이지에 스 와이프 이벤트를 등록하는 방법은 무엇입니까?

function registerSwipeEvents() { 
    //panel swipe from left and right for categories, favs. 
    $(document).on("swipeleft swiperight", '[data-role=page]', function (e) { 
     // We check if there is no open panel on the page because otherwise 
     // a swipe to close the left panel would also open the right panel. 
     // We do this by checking the data that the framework stores on the page element (panel: open). 
     if ($.mobile.activePage.jqmData("panel") !== "open") { 
      if (e.type === "swipeleft") { 
       $(".right-panel").panel("open"); 
      } else if (e.type === "swiperight") { 
       $(".left-panel").panel("open"); 
      } 
     } 
    }); 
} 

, pagebeforeshow와의 pageshow처럼 (항상 실행) 이 :

$('#HomePage').on('pageshow', function() { 
    getFavouritesFromClient(); 

}); 

두 번째 한 페이지에서 다른 페이지로 이동할 때 이벤트가 모든 페이지에서 작동하지 않습니다! 어쩌면 내가 제대로 이벤트를 사용하지 않고 있지만 탐색의 첫 번째 라운드에서 지금까지 작동 한 최고의 페이지는 페이지 쇼입니다.

+0

단일 파일 또는 다중 파일을 사용하고 있습니까? – Omar

+0

@Omar 여러 파일이지만 홈페이지 ID는 내 마스터 '[data-role = page]'의 주 ID이며 들어오는 모든 콘텐츠가 콘텐츠에 삽입됩니다. –

+0

'$ (document) .on ('pageshow', '#HomePage', function() { '이 트릭을 수행합니다. 또한이 답변을 통해 도움이됩니다. http://stackoverflow.com/a/15806954/1771795 – Omar

답변

0

이 코드는 모든 페이지에 스 와이프 이벤트를 등록하는 데 도움을줍니다.

pagecreate 이벤트는 모든 페이지에 적용됩니다 ([data-role=page] 사용). 이 이벤트에서 특정 페이지의 ID는 $(this).attr('id')입니다. 그리고 우리가 혼자

"#"+thisPageId를 사용하여 특정 페이지에 대한 swipeleftswiperight 이벤트에 등록 (I 나를 알아 도왔 그 코드에 몇 줄을 포함했다 - 알고에 관심이있는 사람들을 위해 그)

//var glbl; // this helped me find the attribute - global variable for accessing via the console 
$(document).on("pagecreate", "[data-role=page]", function() { 
    //console.log($(this)); // uncomment this line to see this DIV 
    //glbl = $(debug); //uncomment this line to assign this DIV to global variable "glbl", which you can then access via the console 
    var thisPageId = $(this).attr('id'); 
    $(document).on("swipeleft swiperight", "#"+thisPageId, function(e) { 
     // We check if there is no open panel on the page because otherwise 
     // a swipe to close the left panel would also open the right panel (and v.v.). 
     // We do this by checking the data that the framework stores on the page element (panel: open). 
     if ($(".ui-page-active").jqmData("panel") !== "open") { 
      if (e.type === "swipeleft") { 
       $("#panelRight").panel("open"); 
      } else if (e.type === "swiperight") { 
       $("#panelLeft").panel("open"); 
      } 
     } 
     console.log('on swipes'); 
    }); 
    console.log('on pagecreate'); 
}); 
+0

코드 블록을 게시하지 마십시오. – dimo414

관련 문제