반응형
블로그 이미지
개발자로서 현장에서 일하면서 새로 접하는 기술들이나 알게된 정보 등을 정리하기 위한 블로그입니다. 운 좋게 미국에서 큰 회사들의 프로젝트에서 컬설턴트로 일하고 있어서 새로운 기술들을 접할 기회가 많이 있습니다. 미국의 IT 프로젝트에서 사용되는 툴들에 대해 많은 분들과 정보를 공유하고 싶습니다.
솔웅

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리

window를 생성하는 예제들...

2012. 10. 21. 02:57 | Posted by 솔웅


반응형

Examples of manipulation of windows


Switch between multiple windows thanks to swipe events


우리는 windows 들간에 이동을 하기 위해 swipe type events 를 사용합니다. Swipeleft event가 발생하면 next window 로 가도록 할 것이고 swiperight event 가 발생하면 이전 페이지로 돌아갈 겁니다. (Back button이랑 같죠)


Use the swipe events to switch between three windows


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content 1 </p>  

  </div>

</div>


<div data-role=page id=win2>

  <div data-role=header>

    <h1>Window 2</h1>

  </div>


  <div data-role=content>

    <p> Window content 2 </p>  

  </div>

</div>


<div data-role=page id=win3>

  <div data-role=header>

    <h1>Window 3</h1>

  </div>


  <div data-role=content>

    <p> Window content 3 </p>  

  </div>

</div>


</body>

</html>


<script>


$("div:jqmData(role=page)").bind ("swipeleft", function (event)

{

  var id = this.id;

  var next;   // id of the next visible window

  if (id == "home") next = "win2";

  else if (id == "win2") next = "win3";

  if (next) $.mobile.changePage ($("#" + next), 

  

    transition : "slide" 

  });

});


$("div:jqmData(role=page)").bind ("swiperight", function (event)

{

  var id = this.id;

  var next;   // id of the next visible window

  if (id == "win2") next = "home";

  else if (id == "win3") next = "win2";

  if (next) $.mobile.changePage ($("#" + next), 

  

    transition : "slide",

    reverse : true

  });

});


</script>




tistory415_01.html


swiperight event가 진행되는 중에 $.mobile.changePage ()안에 reverse option을  true로 세팅합니다.  그렇게 하면 이 swiperight event 가 발생하면 이전페이지로 갈 수 있게 되죠. 만약 우리가 slide transition 만 사용한다면 우리가 next window 로 갈 때와 같이 scrolling effect 를 사용하겠죠. 이전 페이지로 돌아가는 것처럼 화면이동이 이루어지게 하려면 reverse option을 true로 세팅해야 합니다.


Create a window and display it dynamically


이제 이전 샘플 코드를 좀 더 발전시켜 볼까요. 이전 window에서 click 이 일어났을 때 dynamic 하게 window를 생성하고 display 하는게 이전 예제였다면 이제는 이전 window 에서 click 없이 dynamic 하게 window를 생성하고 display 하도록 하겠습니다.



Directly display a window created dynamically


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content 1 </p>  

    <a href=#win2 id=link1 data-role=button> Goto Window 2 </a>

  </div>

</div>


</body>

</html>


<script>


var html = "";

html += "<div data-role=page id=win2 data-add-back-btn=true>";

html +=   "<div data-role=header>";

html +=     "<h1>Window 2</h1>";

html +=   "</div>"

html +=   "<div data-role=content>";

html +=     "<p> Window content 2 </p>";

html +=   "</div>";

html += "</div>";


$("body").append (html);


$("#home").bind ("pagecreate", function (event)

{

  $.mobile.changePage ($("#win2"));

});


</script>



두번째 window의 HTML code 는 DOM tree 안에서 application이 시작할 때 insert 됩니다. 그리고나서 첫번째 window의 생성 마지막 단계에서(pagecreate event) 두번째 window 가 display 됩니다. 첫번째 window 의 create 를 기다리지 않는다면 두 윈도우간의 transition 은 발생하지 않을 겁니다.




tistory415_02.html




반응형

content 부분 customize 하기

2012. 10. 21. 02:40 | Posted by 솔웅


반응형

Customize windows


window 는 대개 3개의 zone 으로 구성됩니다. : header, content and footer. 우리는 이 윈도우의 content part 를 어떻게 customize 하는지를 공부합니다. 다른 부분에 대한 customization 은 toolbars chapter 에서 다룰겁니다.

 

Window 의 content를 어떻게 customize 하는지를 보기 위해 아래 HTML code 를 살펴 보겠습니다.


A minimal window


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Paragraph 1 </p>  

    <p> Paragraph 2 </p>  

    <p> Paragraph 3 </p>  

    <p> Paragraph 4 </p>  

    <p> Paragraph 5 </p>  

    <p> Paragraph 6 </p>  

    <p> Paragraph 7 </p>  

    <p> Paragraph 8 </p>  

    <p> Paragraph 9 </p>  

  </div>

</div>


</body>

</html>




tistory414_01.html


한개의
header toolbar와 9개의  paragraph 가 있는 content 를 add 했습니다. 이 window 는 그냥 평범한 모습으로 display 될 겁니다.




window를 어떻게 customize 하는지 이해하기 위해 우리가 작성한 이 코드가 jQuery Mobile 에 의해 어떤 HTML 코드로 generate 되는지를 살펴보세요. 아래는 Firefox 브라우저의 Firebug 로 본 모습입니다.



window 의 content 부분에 해당하는 <div> element 를 보시면 ui-content CSS class 가 있는 걸 보실 수 있을 겁니다. (원본 소스에는 없었던 거죠) 만약 이 스타일을 우리의 HTML page에 정의해 넣는 다면 이 window contents 는 약간 다르게 보일겁니다.


Changing the style associated with the contents of the window


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

  

  <style type=text/css>

    .ui-content {

      font-style : italic;

      font-size : 20px;

      background-color : grey;

      color : red;

    }

  </style>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Paragraph 1 </p>  

    <p> Paragraph 2 </p>  

    <p> Paragraph 3 </p>  

    <p> Paragraph 4 </p>  

    <p> Paragraph 5 </p>  

    <p> Paragraph 6 </p>  

    <p> Paragraph 7 </p>  

    <p> Paragraph 8 </p>  

    <p> Paragraph 9 </p>  

  </div>

</div>


</body>

</html>





tistory414_02.html


이렇게 하면 content 부분을 여러분이 원하시는 대로 customize 하실 수 있습니다.



반응형


반응형
Manage events on windows



jQuery Mobile은 windows와 연관된 event system을 셋업합니다. 예를 들어 윈도우 생성(pagecreate) 과 연계된 이벤트를 handle 하는 것 뿐만 아니라 윈도우의 display 나 disappearance (pageshow and pagehide)와 관련된 이벤트를 처리하는 것도 가능합니다.


Creating the window


윈도우는 display 되어야 할 때 jQuery Mobile 에 의해서 생성됩니다. 윈도우를 create 하려면 initial HTML code를 스크린에 display 될 다른 HTML code로 바꾸어야 합니다. (특히 윈도우의 다른 콤포넌트마다 다른 style을 적용하는 CSS 를 추가하는 경우는 더 그렇죠.).  이 creation process는 오직 한번만 perform 됩니다. 첫번째 window 가 display 될 때죠.


Events associated with the creation of windows


Name

Signification

pagebeforecreate

Triggered in the first display of the window, before the process of creating the window.

pagecreate

Triggered at the end of the process of creating the window. The internal components of the window (radio buttons, check boxes, lists, etc..) are processed independently of the reception of the pagecreate event on the window, and thus may have been created or not (at this time there).

pageinit

Triggered after the pagecreate event when all components of the window was created.


이 이벤트의 sequence를 이해하시려면 아래 간단한 샘플을 보세요.


Events associated with the creation of windows


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content 1 </p>  

    <input type=range id=slider1 min=1 max=100 />

    

    <label for=check1>checkbox</label>

    <input type=checkbox id=check1 />    

    

    <a href=#win2 id=link1> Goto window 2 </a>

  </div>

</div>


<div data-role=page id=win2 data-add-back-btn=true>

  <div data-role=header>

    <h1>Window 2</h1>

  </div>


  <div data-role=content>

    <p> Window content 2 </p>  

  </div>

</div>


</body>

</html>


<script>


$("#check1").live ("checkboxradiocreate", function (event)

{

  alert ("checkbox created");

});


$("#slider1").live ("slidercreate", function (event)

{

  alert ("slider created");

});


$("div:jqmData(role=page)").bind ("pagebeforecreate", function (event)

{

  alert ("pagebeforecreate id=" + this.id);

});


$("div:jqmData(role=page)").bind ("pagecreate", function (event)

{

  alert ("pagecreate id=" + this.id);

});


$("div:jqmData(role=page)").bind ("pageinit", function (event)

{

  alert ("pageinit id=" + this.id);

});


</script>




tistory413_01.html


여기에 두개의 window를 정의했습니다. 두번째는 첫번째 화면에서 링크를 클릭하면 display 됩니다. 이 두 윈도우의 creation 시 event를 가로챕니다. 각 이벤트는 id 이름을 화면이 표시되기 전에 alert로 보여줄 겁니다.


만약에 두번째 window 가 external file 이라면 이것과 관련된 pagebeforecreate, pagecreate and pageinit events 들은 window가 display 될 때마다 trigger 됩니다. (첫번째에만 trigger 되는 것이 아니라 매번 display 될 때마다요. 다만 그 윈도우가 data-dom-cache="true" attribute를 사용하고 있다면 이미 DOM 에 있으니까 저 이벤트들이 trigger 되지는 않겠죠.)


추가로 slidercreate and checkboxradiocreate events는 pageinit event 바로 직전에 trigger 됩니다. 그러니까 window의 모든 컴포넌트들이 생성된 다음이 되겠죠.


Loading of the window by Ajax


그 window가 아직 DOM 에 있지 않으면 jQuery Mobile은 HTML 안의 Ajax를 사용해서 그 화면을 로딩합니다. 그려면 윈도우가 로드되기 전에 pagebeforeload event 가 발생하게 되죠. 그리고 로딩이 성공적으로 이뤄지면 pageload event 가 발생할 겁니다. 실패하면 pageloadfailed event 가 발생하구요.


이 이벤트들은 event and data parameters 들을 전달 받습니다. data parameter 는 Ajax 에 의해 로드 된 파일의 full URL 이 있는  url property를 가지고 있습니다.


Events associated with loading windows by Ajax


Name

Signification

pagebeforeload

Triggered before loading the window by Ajax. The window is located in an external file, which may or may not be loaded successfully.

pageload

Triggered when loading the file containing the window was successfully completed. The window was created in the DOM tree (the pagecreate event is fired before pageload).

pageloadfailed

Triggered when loading the file containing the window failed. No window was inserted in the DOM tree.



이 이벤트들의 sequence를 이해하기 위해 여러 HTML 파일에 window 들을 생성하겠습니다.


  • Window 1 is the first window displayed, located in the index.html file.

  • Window 2 is located in the original HTML page (index.html) following Window 1.

  • Window 3 is located in the existing file index3.html.

  • Window 4 is located in the existing file index4.html. It has the data-dom-cache="true" attribute indicating to keep it in the DOM (instead of the Window 3).

  • Window 5 is located in the file index5.html nonexistent. A loading error occurs when it is displayed.


Window 1 은 다른 4개의 window들에 access 할 수 있는 link들을 가지고 있습니다. 그 중 한가지라도 event 가 발생하면 그리고
pagebeforecreate, pagecreate and pageinit events들이 trigger 되면 메세지를 display 할 겁니다.



Events for creating windows by Ajax (index.html file)


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content 1 </p>  

    <a href=#win2> Goto Window 2 (into the DOM) </a>

    <br /><br />


    <a href=index3.html> 

         Goto Window 3 in index3.html (data-dom-cache=false) </a>

    <br /><br />


    <a href=index4.html> 

         Goto Window 4 in index4.html (data-dom-cache=true) </a>

    <br /><br />


    <a href=index5.html> Goto Window 5 (index5.html nonexistent) </a>

    <br /><br />

  </div>

</div>


<div data-role=page id=win2 data-add-back-btn=true>

  <div data-role=header>

    <h1>Window 2</h1>

  </div>


  <div data-role=content>

    <p> Window content 2 </p>

  </div>

</div>


</body>

</html>


<script>


$(document).bind ("pagebeforeload", function (event, data)

{

  alert ("pagebeforeload data.url = " + data.url);

});


$(document).bind ("pageload", function (event, data)

{

  alert ("pageload data.url = " + data.url);

});


$(document).bind ("pageloadfailed", function (event, data)

{

  alert ("pageloadfailed data.url = " + data.url);

});


$("div:jqmData(role=page)").live ("pagebeforecreate", function (event)

{

  alert ("pagebeforecreate id=" + this.id);

});


$("div:jqmData(role=page)").live ("pagecreate", function (event)

{

  alert ("pagecreate id=" + this.id);

});


$("div:jqmData(role=page)").live ("pageinit", function (event)

{

  alert ("pageinit id=" + this.id);

});


</script>



Index3.html file containing the window 3


<!DOCTYPE html>

<html> 

<head> 

  <meta http-equiv=Content-Type content=text/html;charset=iso-8859-1 />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=win3 data-add-back-btn=true>

  <div data-role=header>

    <h1>Window 3</h1>

  </div>


  <div data-role=content>

    <p> Window content 3 </p>

  </div>

</div>


</body>

</html>





Index4.html file containing the window 4

<!DOCTYPE html>

<html> 

<head> 

  <meta http-equiv=Content-Type content=text/html;charset=iso-8859-1 />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=win4 data-add-back-btn=true data-dom-cache=true>

  <div data-role=header>

    <h1>Window 4</h1>

  </div>


  <div data-role=content>

    <p> Window content 4 </p>

  </div>

</div>


</body>

</html>


tistory413_02d.zip


Index5.html 파일은 없습니다. 그 링크를 클릭하면 로딩시 Ajax 에러를 의도적으로 발생시키기 위해서 입니다.


home window 와 다른 window들을 navigating 하게 되면 이벤트들이 발생합니다. 만약 그 window가 이미 메모리(DOM) 에 로드돼 있다면 이 이벤트들은(pagebeforeload, pageload and pageloadfailed) 더 이상 trigger 되지 않습니다.



Remove the window in the DOM


메모리에서 window들에 의해 점유되는 공간을 줄이기 위해 jQuery Mobile은  더이상 그 페이지가 visible 되지 않게 되면 Ajax 에 의해 로드 된 그 window들을 자동적으로 remove 하게 됩니다. ( attribute-dom-cache=true 가 설정돼 있는 윈도우는 계속 남아 있게 됩니다.)


메모리에서 그 window를 remove 하기 전에 pageremove event가 trigger 되고 그리고 나서 DOM 에서 remove 될 겁니다 . 이 pageremove event 에 의해 해당 윈도우가 remove 되지 않도록 하려면 event.preventDefault ()를 call 하시면 됩니다. pageremove event 가 진행될 때 이 함수가 call 되지 않으면 그 window는 DOM tree에서 remove 되게 됩니다.  만약 그 페이지가 나중에 반드시 다시 display 되어야 한다면 그 때 jQuery Mobile 에 의해 다른 Ajax call 이 만들어 질 겁니다.


Prohibit the removal of the windows in memory loaded by Ajax


$("div:jqmData(role=page)").live ("pageremove", function (event)

{

  alert ("pageremove id=" + this.id);

  event.preventDefault ();

});



Window display


한번 그 window가 create 되면 이제 display 될 준비가 끝난겁니다.  한번만 create 됐지만 그 window는 여러번 display 되고 hidden 되고 할 수 있습니다. (그 window 가 external file 이 아니고 data-dom-cache attribute 가 "false" 일 경우는 제외하구요.)


Events associated with the display of windows


Nom

Signification

pagebeforeshow

Triggered when the window will be displayed (it is not yet visible).

pageshow

Triggered when the window is displayed (visible).

pagebeforehide

Triggered before the window is hidden (it is still visible).

pagehide

Triggered after the window is hidden (it is no longer visible).


이 이벤트들은 그 window의 pagecreate event 이 후에 trigger 됩니다. 이것들은 jQuery class object 로서 bind () method에 의해 사용되어질 수 있습니다. 이 callback function은 uihe prevPage or nextPage property 랑 있는 객체 파라미터에서 callback (event, ui) 이벤트가 진행될 때 call 합니다.


  • If the event is of type show (pageshow or pagebeforeshow) ui.prevPage corresponds to the jQuery class object defining the window that one leaves or has left (if any), to display this one it. ui.nextPage property is not defined in this case.

  • If the event is of type hide (pagehide or pagebeforehide) ui.nextPage corresponds to the jQuery class object defining the window we are going to show or that have been displayed by leaving this one. ui.prevPage property is not defined in this case.


이제 이전에 다뤘던 예제로 다시 돌아가 봅시다. 우리가 이벤트들을 intercept 했던 그 예제로요.


Display type events on windows


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content 1 </p>  

    <a href=#win2 id=link1> Goto window 2 </a>

  </div>

</div>


<div data-role=page id=win2 data-add-back-btn=true>

  <div data-role=header>

    <h1>Window 2</h1>

  </div>


  <div data-role=content>

    <p> Window content 2 </p>  

  </div>

</div>


</body>

</html>


<script>


$("div:jqmData(role=page)").bind ("pagebeforeshow", function (event, ui)

{

  var txt = "pagebeforeshow id=" + this.id + "\n";

  if (ui.prevPage && ui.prevPage[0])

    txt += "ui.prevPage=" + ui.prevPage[0].id + "\n";

  if (ui.nextPage && ui.nextPage[0]) 

    txt += "ui.nextPage=" + ui.nextPage[0].id + "\n";

  alert (txt);

  

});


$("div:jqmData(role=page)").bind ("pageshow", function (event, ui)

{

  var txt = "pageshow id=" + this.id + "\n";

  if (ui.prevPage && ui.prevPage[0])

    txt += "ui.prevPage=" + ui.prevPage[0].id + "\n";

  if (ui.nextPage && ui.nextPage[0]) 

    txt += "ui.nextPage=" + ui.nextPage[0].id + "\n";

  alert (txt);

});


$("div:jqmData(role=page)").bind ("pagebeforehide", function (event, ui)

{

  var txt = "pagebeforehide id=" + this.id + "\n";

  if (ui.prevPage && ui.prevPage[0])

    txt += "ui.prevPage=" + ui.prevPage[0].id + "\n";

  if (ui.nextPage && ui.nextPage[0]) 

    txt += "ui.nextPage=" + ui.nextPage[0].id + "\n";

  alert (txt);

});


$("div:jqmData(role=page)").bind ("pagehide", function (event, ui)

{

  var txt = "pagehide id=" + this.id + "\n";

  if (ui.prevPage && ui.prevPage[0])

    txt += "ui.prevPage=" + ui.prevPage[0].id + "\n";

  if (ui.nextPage && ui.nextPage[0]) 

    txt += "ui.nextPage=" + ui.nextPage[0].id + "\n";

  alert (txt);

});


</script>




tistory413_03.html


Events related to the $.mobile.changePage () method


$.mobile.changePage () method 가 개발자가 직접 이용하던지 내부적으로 jQuery Mobile 에 의해 이용되던지 간에 window 가 change 되는 과정을 인식하거나 어떤 간섭을 하기 위해 jQuery Mobile 은 여러 특정 이벤트들을 발생시킵니다. 이 이벤트들은 document object에서 trigger 됩니다.


pagebeforechange event는 다른것들에 앞서서 처음 trigger 되는 것인데요. 이 이벤트의 management method는 파라미터로서 data and event arguments를 갖습니다. data.toPage property는 string (display 될 윈도우의 파일 이름. "index2.html") 이거나 jQuery class object (symbolizing 된 윈도우$("#win2"))  입니다.


이 이벤트는 두번 call 될 수 있는데요. 첫번째는 Ajax로 그 파일을 로딩하기 전이구요 (data.toPage is a string) 두번째는 메모리에 로드될 때입니다 (data.toPage is a jQuery object class). 어떤 상황에서든 최소한 두번째 call 은 이루어 집니다. (왜냐하면 윈도우는 display 되기 전에 반드시 메모리상에 있어야 하기 때문이죠.)

추가로 event.preventDefault () instruction을 사용해서 윈도우가 display 되는 과정에 interrupt 할 수 있습니다. 정확한 시기는 pagebeforechange event가 진행될 때 입니다. 이 구문은 pagebeforechange event가 만들어지는 두 상황중 한 상황에서 excute 될 수 있습니다. 그러면 display process 는 stop 되게 되죠.


Stop the window display


$(document).bind ("pagebeforechange", function (event, data)

{

   event.preventDefault ();

});



display process 가 pagebeforechange event안에서  event.preventDefault () instruction에 의해 stop 되지 않았을 경우에는 document object에 pagechange or pagechangefailed events 가 trigger 됩니다.


  • The pagechange event indicates that the window could be displayed. This is the last event issued by jQuery Mobile, indicating that a window is created and displayed. The processing function of the event uses event and data parameters, latter having the data.toPage property representing the jQuery class object associated with the active window (that is displayed).

  • The pagechangefailed event indicates that the window could not be displayed. This is due to the failure of the loading window Ajax call (pageloadfailed event was previously triggered).


Moves in the window


추가로 vclick, vmouseover, vmousedown, vmousemove, vmouseup, vmouseout and vmousecancel 같은 전통적인 이벤트들에 대해서 jQuery Mobile은 모바일 context 에 맞도록 새롭게 이벤트를 생성시킵니다.



Events associated with the moves in windows


Name

Signification

tap

Triggered when the mouse (left button), or finger, click the screen. Similar to traditional one-click.

taphold

Triggered when the mouse (left button) or the finger is pressed at least one second.

swipe

Triggered when the mouse (left button) or the finger moves horizontally across the screen.

swipeleft

Triggered when the mouse (left button) or the finger moves horizontally across the screen from right to left.

swiperight

Triggered when the mouse (left button) or the finger moves horizontally across the screen from left to right.


예를 들어서 swipe type events 들을 사용할 수 있는데요. 스크린에서 이미지를 오른쪽이나 왼쪽으로 sweeping 할 때 사용될 수 있습니다. jQuery Mobile 은 터치 스크린과 마우스를 사용하는 일반 스크린 모두에서 작동되도록 합니다.


아래 예제는 window 에서 swipe type events (and taphold)를 구현합니다.


Display swipe and taphold type events in a window


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Events : </p>  

    <div id=evt></div>

  </div>

</div>


</body>

</html>


<script>


$("#home").bind ("taphold", function (event)

{

  var txt= "taphold, ";

  $("#evt").append (txt);

});


$("#home").bind ("swipe", function (event)

{

  var txt= "swipe, ";

  $("#evt").append (txt);

});


$("#home").bind ("swipeleft", function (event)

{

  var txt= "swipeleft, ";

  $("#evt").append (txt);

});


$("#home").bind ("swiperight", function (event)

{

  var txt= "swiperight, ";

  $("#evt").append (txt);

});


</script>



화면을 몇번 sweeping 하고 나면 아래같은 화면이 될 겁니다.




Swipe type events 는 horizontal direction 움직임을 감지합니다. jQuery Mobile 은 vertical direction 움직임을 감지하기 위해 scroll type events 를 생성합니다.


Events associated with vertical movements in the window


Name

Signification

scrollstart

Triggered when the mouse (left button) or the finger moves vertically on the screen up or down.

scrollstop

Triggered when the mouse (left button) or the finger is removed from the screen (end of vertical displacement).


View events of scroll type in a window


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Events : </p>  

    <div id=evt></div>

  </div>

</div>


</body>

</html>


<script>


$("#home").bind ("scrollstart", function (event)

{

  var txt= "scrollstart, ";

  $("#evt").append (txt);

});


$("#home").bind ("scrollstop", function (event)

{

  var txt= "scrollstop, ";

  $("#evt").append (txt);

});


</script>






tistory413_05.html


Change screen orientation


jQuery Mobile 은 스크린의 orientation 변화를 감지하기 위해 orientationchange event 를 사용합니다. 이 event parameter 는 callback 함수 안에 있는데요. 화면의 orientation 에 따라 "portrait" or "landscape" 라는 orientation property 가 있습니다.


Events associated with the change in orientation of the screen


Name

Signification

orientationchange

Triggered upon a change of screen orientation. The event.orientation property indicates "portrait" or "landscape" according to screen orientation.


아래 예제는 화면의 orientation 이 바뀔 때마다 warning 을 보여 줍니다.


Display the change in orientation of a window


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content </p>  

  </div>

</div>


</body>

</html>


<script>


$("#home").bind ("orientationchange", function (event)

{

  alert (event.orientation);

});


</script>







화면을 바꾸지 않을 떄에도 현재의 orientation 을 표시할 수 있는데요. $.event.special.orientationchange.orientation () method 를 사용해서 "portrait" or "landscape"를 화면에 표시할 수 있습니다.


tistory413_06.html


Retrieve the current orientation


alert ($.event.special.orientationchange.orientation ());

                                      // "portrait" or "landscape"






반응형


반응형
Other methods and properties


$.mobile.changePage () 이외에 jQuery Mobile은 추가적인 메소드와 프로퍼티들을 제공합니다. 이것도 $.mobile object에  set 됩니다.


Methods defined on the $.mobile object


Method / Property

Signification

showPageLoadingMsg ()

Method to display a waiting message indicating a page is loading. The message is defined in $.mobile.loadingMessage string ("loading" by default).

hidePageLoadingMsg ()

Method to hide the waiting message previously shown by showPageLoadingMsg ().

activePage

Property representing the jQuery class object for the window currently displayed on the screen.

firstPage

Property representing the jQuery class object corresponding to the first window described in the HTML page (which will normally be displayed first).

pageContainer

Property representing the jQuery class object corresponding to the element in which the windows are inserted. By default the parent element of the first window, corresponding generally to the <body> element. Note that jQuery Mobile assigns the ui-mobile-viewport CSS class to this element.
The value of this property can be changed only during processing of the $ (document).ready () event or after it. New displayed windows will then be inserted in this element.


현재 active window의 HTML content 를 알기 위해 $.mobile.activePage property 를 사용합니다. 우리는 alert 안에 이 content를 display 하는 window에 link를 insert 합니다.


View HTML content of the active window


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content </p>  

    <a href=# id=link1> View the contents of the active window </a>

  </div>

</div>


</body>

</html>


<script>


$("#link1").bind ("click", function (event)

{

  alert ($.mobile.activePage.html ());

});




tistory412_01.html





반응형

Dialog windows 사용하기

2012. 10. 17. 08:28 | Posted by 솔웅


반응형
Dialog windows


Display a dialog window


$.mobile.changePage () method는 overlapping windows를 display 하기 위해서 사용 될 수도 있습니다. 이 overlay 윈도우는 그 작업을 위해 data-role="dialog" attribute 를 가지고 있어야 합니다.


Use the $.mobile.changePage () to display a layered window


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content 1 </p>  

    <a href=# id=link1> Goto window 2 </a>

  </div>

</div>


<div data-role=dialog id=win2>

  <div data-role=header>

    <h1>Window 2</h1>

  </div>


  <div data-role=content>

    <p> Window content 2 </p>  

  </div>

</div>

</body>

</html>


<script>


$("#link1").bind ("click", function (event)

{

  $.mobile.changePage ($("#win2"), { transition : "pop" });

});


</script>






tistory410_01.html


Close a dialog window


dialog 윈도우를 닫는것은 대개 jQuery Mobile에 의해 추가된 close button 을 클릭해서 닫게 됩니다. 그 외에도 윈도우의 content 안에 버튼을 넣어서 이 closing 메카니즘을 만들어서 사용해도 상관없습니다. 그러려면 button 을 처리하는 어떤 과정이 필요합니다. 윈도우에 연관된 <div>에서 dialog ("close") method를 call 하는 부분을 코딩해야 합니다.


Use a close button in the dialog window


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content 1 </p>  

    <a href=# id=link1> Goto window 2 </a>

  </div>

</div>


<div data-role=dialog id=win2>

  <div data-role=header>

    <h1>Window 2</h1>

  </div>


  <div data-role=content>

    <p> Window content 2 </p>  

    <a id=close data-role=button> Close window </a>

  </div>

</div>

</body>

</html>


<script>


$("#link1").bind ("click", function (event)

{

  $.mobile.changePage ($("#win2"), { transition : "pop" });

});


$("#close").bind ("click", function (event)

{

  $("#win2").dialog ("close");

});


</script>






tistory410_02.html


Remove the close button in the dialog window


마지막으로 overlay window의 title bar 안에 jQuery Mobile 에 의해 add 된 close 버튼을 어떻게 remove 하는지에 대해 알아보겠습니다. 이것은 title bar에 있는 <a> element 와 관련이 있습니다. 그리고 selector $(this).find ("div: jqmData (role=header) a")를 통해서 접근될 수 있습니다. (만약 이것이 overlay window 라면요.)


우리는 이 element를 jQUery Mobile에 의해 overlay window 가 transforme 되기 위한 HTML 코드 이후에 접근할 수 있습니다. 이 때 dialogcreate event 와 견결 됩니다. 왜냐하면 overlay window 는 jQuery Mobile standard component dialog에 의해 handle 되기 때문입니다.


So we write:


Remove the close button in the dialog window


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content 1 </p>  

    <a href=#win2 id=link1> Goto window 2 </a>

  </div>

</div>


<div data-role=dialog id=win2>

  <div data-role=header>

    <h1>Window 2</h1>

  </div>


  <div data-role=content>

    <p> Window content 2 </p>  

  </div>

</div>

</body>

</html>


<script>


$("#win2").bind ("dialogcreate", function ()

{

  $(this).find ("div:jqmData(role=header) a").hide ();

});


</script>



dialog window 도 (다른 윈도우들과 마찬가지로) pagecreate event를 받습니다.  하지만 이 이벤트는 dialogcreate event 이전에 받게 됩니다. jQuery Mobile 에 의해 HTML 이 transform 된것을 inform 하지 않는 거죠. 그래서 dialogcreate event 를 사용해야 되는 겁니다.




tistory410_03.html



이제 dialog 윈도우는 더 이상 close button 이 없습니다.




반응형

윈도우 생성 과정 이해하기

2012. 10. 16. 21:29 | Posted by 솔웅


반응형


Process of creating windows



jQuery Mobile내에서 윈도우 생성 과정을 이해하는 것은 아주 중요한 일입니다. 윈도우는 $.mobile.changePage ()$.mobile.loadPage () methods 가 calling 됐을 때 생성됩니다. 이 두 메소드는 모두 enhancePage () internal method를 call 합니다. 이 메소드는 해당 윈도우가 이미 생성된 윈도우가 아니라면 윈도우를 생성하는 작업을 진행합니다.


Processing of the pagecreate event


윈도우를 생성하기 위해 enhancePage () method 는 jQuery Mobile page component와 연관 돼 있는 page () method를 call 합니다. 이 page () method는 page component 를 생성하죠. 지난 번 글에서 봤듯이 컴포넌트의 메인 메소드를 call 하는 것은 이벤트를 발생시킵니다. "create"  과 연결된 컴포넌트 이름이 그 이름입니다. (여기서는  pagecreate event). jQuery Mobile 소스코드에서 보실 수 있듯이 pagecreate event는 코드의 다른 부분으로 다뤄집니다.


pagecreate event processing to create the window (in jquery.mobile.js)


$( ":jqmData(role='page'), :jqmData(role='dialog')" )

 .live( "pagecreate", function( e ) {

    var $page = $( this ),
        o = $page.data( "page" ).options,
        pageTheme = o.theme;

    $( ":jqmData(role='header'), 

        :jqmData(role='footer'), 

        :jqmData(role='content')", this ).each(function() {


        /* … */ 
       
        //apply theming and markup modifications to page,header,content,footer
        if ( role === "header" || role === "footer" ) {


            /* … */

 
        } else if ( role === "content" ) {


            /* … */

 
        }
    });

});

  

이 코드 블럭은 data-role="page"data-role="dialog" attributes들과 함께 있는 element를 jQuery Mobile windows 에서 style 로 바꿔 줍니다. title bar 가 header, footer, content 인 HTML element들이 CSS 클래스가 추가 됨으로서 다른 모습으로 바뀌는 것을 잘 봐 두실 필요가 있습니다.



jQuery Mobile source code를 다시 살펴 보면 pagecreate event 에 대해 논의 할 수 있는 다른 코드 부분을 보실 수 있을 겁니다. 예를 들어...


Creation of input fields having jQuery Mobile styled way (in jquery.mobile.js)


//auto self-init widgets
$( document ).bind( "pagecreate create", function( e ){

    $( $.mobile.textinput.prototype.options.initSelector, e.target )
        .not( ":jqmData(role='none'), :jqmData(role='nojs')" )
        .textinput();

});



이 코드 블럭은 document object가 이 이벤트를 listening 하고 있는 것을 보여 줍니다. 그것을 receive 하면 jQuery Mobile textinput () method 는  (input field들을 managing 하고 있는 textinput component 로부터) 모든 HTML elements 들을 matching 되는 selector ($.mobile.textinput.prototype.options.initSelector에서 정의 된)에 apply 합니다.  그리고 e.target element의 descendants 에 위치 됩니다. 이 메소드를 call 하면 이전 글에서 봤듯이 textInput component의 생성을 진행합니다.


이 element 의 descendants 내에 있는 HTML elements 들에 대해서만 search 하기 위해 e.target parameter를 사용하는 것에 대해 주목해 주세요. 그래야지만 좀 더 빨리 작업을 할 수 있겠죠. 마지막으로는 selector에 의해 정의된 input field들에 해당하는 모든 element들이 jQuery Mobile 스럽게 보이는 input fields 들로 transform 될 겁니다. 바로 document object 가 pagecreate event 를 받은 거죠.


이 윈도우에서의 컴포넌트 생성 프로세스는 jQuery Mobile component 와 연결된 모든 HTML elements 에 대해 implement 됩니다. 그 관계는 아래 표와 같습니다.



jQuery Mobile standard components


Name

Signification

page

Windows management in the page

checkboxradio

Checkboxes and radio buttons management

textinput

Input texts management

selectmenu

Select menus management

button

Buttons management

slider

Sliders management

collapsible

Accordion menus management

listview

Listviews management

dialog

Overlapped windows management


이 프로세스로 인해 우리는 radio buttons, check boxes, input fields, etc. 등을 style 할 수 있는거죠.


어플리케이션에서 display 된 첫번째 윈도우는 $.mobile.initializePage () method 가 실행되는 동안 jQuery Mobile에 의해 자동적으로 생성됩니다 .그리고 위에 설명드린 transformation 작읍을 할 $.mobile.changePage () method를 call 하는 것이죠.


Creation of standard components in jQuery Mobile


위 코드 블럭은 어떻게 jQuery Mobile standard component 가 윈도우를 생성할 때 pagecreate event 가 보내지면서 무슨 일을 하게 되는지를 잘 보여줍니다. 그 컴포넌트와 연관된 이 메소드(previously textinput ())는 slector 와 연결돼 있는 HTML element에서 call 됩니다. 그럼으로서 그 컴포넌트를 생성하게 되는겁니다.


또한 이 작업은 HTML elements들이 create event를 receive 할 때 진행되는 것도 보있습니다. bind () method의 파라미터에 그것이 표현돼 있죠. 이 의미는 jQuery Mobile standard components들을 두가지 방법으로 생성할 수 있다는 것을 말합니다.


  • Either by triggering a create event on the window containing the HTML element, which leads to the creation of the component via the processing performed in the received event;

  • Or by directly calling on the HTML element, the method for creating the component (eg method textinput () to create the input field).


이 두가지 방법들은 같은 동작을 하게 되구요 같은 결과를 보여 줍니다. 그 컴포넌트는 그것을 포함하고 있는 윈도우안에 생성되게 되는 것이죠. 이 글 다음에 이어지는 글들에서 이 jQuery Mobile 이 제공하는 standard components들을 다이나믹하게 생성하는 방법들에 대해 다룰 것입니다.


Synchronization of the creation of components in the window


pagecreate event는 윈도우가 생성되는 동안에 보내 집니다. 그리고 the document object가 그것을 받게 되죠. jQuery Mobile treatment는 윈도우 내에서 그 컴포넌트들을 각각 생성하기 위해 활용됩니다. 이 컴포넌트들을 생성하는 것은 이러한 컴포넌트들과 관련된 create type 의 새로운 이벤트를 발생시킵니다.

예를 들어


  • checkboxradiocreate for a checkboxradio component corresponding to a checkbox or radio button,

  • textinputcreate for a textinput component corresponding to an input field,

  • slidercreate for a slider component corresponding to a slider,

  • Etc..


그러므로 한 윈도우를 생성함으로서 윈도우와 관련된 여러 이벤트들이 발생되게 됩니다.
(pagecreate) 또한 컴포넌트들에는 (checkboxradiocreate, textinputcreate, etc.) 것들도 포함되는 거죠. 이러한 이벤트들은 각각 독립적입니다. 그러므로 pagecreate event의 도입부는 윈도우의 content 가 이미 생성되었다는 것을 의미하지는 않습니다. 정확하게는 그 윈도우의 컴포넌트가 생성되는 jQuery Mobile에 의해 이 이벤트의 프로세스가 진행되고 있다는 의미죠.



반응형


반응형
$.mobile.loadPage (url, options) method



$.mobile.loadPage (url, options) method 는 $.mobile.changePage (toPage, options) method 에 의해 내부적으로(internally) 사용됩니다. 이것은 설정된 URL의 HTML 페이지를 수집(retrieves) 하고 메모리 내에 해당 윈도우를 load 합니다. 현재 보여지고 있는 윈도우는 바뀌지 않습니다. 그냥 다음 페이지를 내부적으로 다음 윈도우에 넣어서 메모리에 담아두고 있는거죠.


jQuery Mobile은 우리가 이 메소드를 사용하면 현재 display 되는 HTML 과 Load 되는 HTML 을 각각 분리할 수 있도록 처리해 줍니다. 이 메소드를 사용하면 예를 들어 pre-load 윈도우들의 경우 유저의 요구가 있었을 때 기다리는 시간 없이 즉시 표시해 줄 수 있도록 해 줍니다.  jQuery Mobile 은 data-prefetch attribute를 통해서 이런 작업을 합니다.


$.mobile.loadPage (url, options) method parameters


Parameter

Signification

url

Specifies the URL of the page you want to load into memory.

options.
pageContainer

jQuery class object indicating the element within which the new window will be displayed. Default $.mobile.pageContainer.

options.
data

The data option is an object or a string, corresponding to transmitted parameters.
- If using a string, it must be of the form name1=value1&name2=value2 etc., each name is the name of a parameter, and value the corresponding value encoded in UTF-8.
- If you use an object, jQuery Mobile itself encodes UTF-8 each value, and sends the server a string of the form name1=value1&name2=value2 etc.

options.
type

Method describing how to transmit parameters ("post" or "get"). The default is "get".

options.
reloadPage

If true, specifies to reload the window in the DOM, each viewing the page. Default false (the window is loaded into the DOM at the first display and is used as is).


Simulating the data-prefetch attribute using the $.mobile.loadPage ()


링크 내에 data-prefetch attribute 가 설정 되면 jQuery Mobile은 그 링크의 href attribute 에 해당하는 HTML 페이지를 백그라운드로 로딩합니다. 이 작업을 하기 위해 jQuery Mobile은 $.mobile.loadPage () method를 이용해서 메모리에 해당 윈도우를 저장하는 것이죠.


아래에 $.mobile.loadPage () method를 사용해서 윈도우를 preload 하는 예제를 보시겠습니다.



Preload a window with $.mobile.loadPage () method


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content 1 </p>  

    <a href=# id=link1> Goto window 2 </a>

  </div>

</div>


</body>

</html>


<script>


$("#home").bind ("pagecreate", function ()

{

  $.mobile.loadPage ("index2.html");

});


$("#link1").bind ("click", function (event)

{

  $.mobile.changePage ("index2.html");

});


</script>



index2.html file containing the second window


<!DOCTYPE html>

<html> 

<head> 

  <meta http-equiv=Content-Type content=text/html;charset=iso-8859-1 />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=win2 data-add-back-btn=true data-dom-cache=true>

  <div data-role=header>

    <h1>Window 2</h1>

  </div>


  <div data-role=content>

    <p> Window content 2</p>

  </div>

</div>


</body>

</html>


convention181.html


convention182.html



두번째 윈도우는 index2.html 파일을 포함하게 됩니다. 일단 첫번째 윈도우가 생성되면 (pagecreate event) 곧바로 두번째 윈도우가 DOM tree 에 include 되겠죠.




일단 두번째 윈도우가 로드되면 유저가 링크를 클릭하면 $.mobile.changePage () method를 사용해서 두번째 윈도우를 display 할 겁니다.

이 때 유저는 jQuery Mobile의 waiting message (Loading) 를 보지 않아도 됩니다. 왜냐하면 그 페이지가 이미 DOM 에 있으니까요. 두번째 윈도우에서 data-dom-cache=true attribute를 세팅해서 DOM 내에 두번째 윈도우가 계속 머물러 있게 됩니다. 그러면 첫번째 윈도우에서 링크를 클릭하면 곧바로 두번째 윈도우가 display 되는 겁니다.


반응형


반응형

$.mogile.changePage(toPage,options) method



이전 글에서 HTML 페이지내에서 링크를 거는 간단한 방법을 보여드렸습니다. 이 링크는 두개의 윈도우간의 transition을 가능하게 하죠. 그 윈도우가 같은 HTML 페이지 안에 있던 아니면 다른 HTML 안에 있던 상관없습니다.


이 두개의 윈도우간 transition을 좀 manage 하고 싶은 경우에 어떻게 할까요? jQuery Mobile 은  이를 위해 $.mobile.changePage (toPage, options)를 제공하고 있습니다. 이름에서 알 수 있듯이 이것은 $.mobile object 상에 정의된 changePage () 메소드 입니다.



toPage parameter (required)는 여러분이 display 하기를 원하는 윈도우나 페이지를 말하는 겁니다. options parameter (optional)는 이 윈도우를 display 하기 위해 사용되는 옵션들을 가리키는 객체입니다.


$.mobile.changePage (toPage, options) method parameters


Parameter

Signification

toPage

Indicates the window or the URL of the page you want displayed.
- For a window, it is a jQuery class object (eg $("#win2") to display the window with this id). In this case, the window must already exist in the DOM.
- For a URL, it is a string (eg "index2.html"). In this case, the first window in the file is displayed.

options.
transition

One of the values slide, slideup, slidedown, pop, fade or flip, corresponding to the transition effect between the two windows (slide by default). See details below.

options.
reverse

If true, specifies to reverse the direction of the transition effect. Default false.

options.
changeHash

Indicates whether the URL in the address bar should be changed to reflect the URL of the new page or window displayed (if changeHash is true, default), or must retain the old value (if changeHash is false).

options.
pageContainer

jQuery class object indicating the element within which the new window will be displayed. Default $.mobile.pageContainer.

options.
data

The data option is an object or a string, corresponding to transmitted parameters.
- If using a string, it must be of the form name1=value1&name2=value2 ..., each name is the name of a parameter, and value the corresponding value encoded in UTF-8.
- If you use an object, jQuery Mobile itself encodes UTF-8 each value, and sends the server a string of the form name1=value1&name2=value2 etc.

options.
type

Method describing how to transmit parameters ("post" or "get"). The default is "get".

options.
reloadPage

If true, specifies to reload the window in the DOM, each viewing the page. Default false (the window is loaded into the DOM at the first display and is used as is). This option is only used if the argument toPage refers to a URL (the window is loaded by jQuery Mobile with Ajax).

options.
showLoadMsg

Boolean indicating to display the message saying that an HTML page is being loaded. The message is described in $.mobile.loadingMessage ("loading" by default).


Possible values of the data-transition attribute


data-transition

Signification

slide

Moving from one window to another by a horizontal movement from right to left. This is the default.

slideup

The second window appears at the bottom, gradually covering the first.

slidedown

The second window appears at the top, gradually covering the first.

pop

The second window is the center of the first, widening to cover it.

fade

The first window disappears by reducing its opacity (from 1 to 0), while the second appears through an increase in opacity (from 0 to 1).

flip

The second window appears with a rotation effect on a vertical axis, and by removing the first window.


링크를 클릭했을 때 $.mobile.changePage ()과  jQuery Mobile 이 만든 href attribute 사이에는 어떤 일이 일어 날까요? 어떤게 더 우선일까요? 


헛갈릴 필요가 없는게요 jQuery Mobile은 자바스크립트 코드에서 어떤 일이 발생할 때는 <a> link의 href attribute에 "#" value를 할당하라고 하거든요. 링크 내의 href="#"는 jQuery Mobile에게 일반적인 프로세스로 진행하지 않을거라고 얘기하는 거거든요. (그러니까 이럴 경우에는 자바스크립트 내에 있는 우리의 코드가 우선으로 적용되게 되는 겁니다.)


$.mobile.changePage (toPage, options) method를 사용한 아래 샘플들을 보세요.


Display a window in the same HTML page


하나의 HTML 페이지에 두개의 윈도우가 있다고 가정하죠. 첫번째 윈도우에서 두번째 윈도우로 움직이고 싶구요 이것을 $.mobile.changePage () method를 사용해서 링크를 관리할 겁니다. (링크의 href attribute를 사용하는 대신에요.)


Use the $. Mobile.changePage () method to display a window in the same HTML page


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content 1 </p>  

    <a href=# id=link1> Goto window 2 </a>

  </div>

</div>


<div data-role=page id=win2 data-add-back-btn=true>

  <div data-role=header>

    <h1>Window 2</h1>

  </div>


  <div data-role=content>

    <p> Window content 2 </p>

  </div>

</div>


</body>

</html>


<script>


$("#link1").bind ("click", function (event)

{

  $.mobile.changePage ($("#win2"));

});


</script>



Window 2 에는 win2 라는 id 가 있습니다. 이것은 jQuery class 객체  $("#win2")로 다뤄질 수 있습니다. link attributes의 href="#" click event (instead of vclick)의 용도를 잘 생각해 보세요.  (이 이벤트는 link 에 position 돼 있어서 click 을 사용한 겁니다. 자세한 내용은 이전 글을 보세요.)






Display a window in another HTML page


이제는 두번째 윈도우가 다른 HTML 페이지에 있을 경우입니다. 두번째 윈도우를 보기위해 $.mobile.changePage () method를 사용합니다. 이 메소드의 첫번째 파라미터로 HTML 페이지의 URL 을 넣습니다.


Use the $.mobile.changePage () method to display a window in a new HTML page


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content 1 </p>  

    <a href=# id=link1> Goto window 2 </a>

  </div>

</div>


<div data-role=page id=win2 data-add-back-btn=true>

  <div data-role=header>

    <h1>Window 2</h1>

  </div>


  <div data-role=content>

    <p> Window content 2 </p>

  </div>

</div>


</body>

</html>


<script>


$("#link1").bind ("click", function (event)

{

  $.mobile.changePage ("index2.html");

});


</script>



Index2.html file


<!DOCTYPE html>

<html> 

<head> 

  <meta http-equiv=Content-Type content=text/html;charset=iso-8859-1 />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=win2 data-add-back-btn=true>

  <div data-role=header>

    <h1>Window 2</h1>

  </div>


  <div data-role=content>

    <p> Window content 2</p>

  </div>

</div>


</body>

</html>



결과는 이전 예제와 거의 같습니다. 첫번째 링크에서는 약간 다를겁니다. 왜냐하면 처음에는 그 HTML 페이지가 로드되지 않았을 것이기 때문에요. 아마 속도가 느리면 두번째 윈도우가 열릴 때까지  Loading 이라는 메세지가 뜰 겁니다.


만약 index2.html file안에 여러개의 윈도우가 있다면? 이럴 경우에는 첫번째 윈도우면 DOM 에 적재 됩니다. 다른 윈도우들은 접근하지 못하는 상황이 됩니다.


Transmit data when displaying the window


만약에 첫번째 윈도우가 두번째 윈도우에 어떤 정보를 전달해야 될 경우를 가정해 보죠. 이것은 $.mobile.changePage () call의 data option을 사용하게 됩니다. 이렇게 되면 두번째 윈도우에 파라미터를 전달할 수가 있습니다.


Use the $.mobile.changePage () method to transmit information


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content 1 </p>  

    <a href=# id=link1> Goto window 2 </a>

  </div>

</div>


</body>

</html>


<script>


$("#link1").bind ("click", function (event)

{

  $.mobile.changePage ("action.php", 

  {

    data : { fname : "Eric", lname : "Sarrion" }

  });

});


</script>


Display the new window (action.php file)


<?
  $fname = $_REQUEST["fname"];
  $lname = $_REQUEST["lname"];
  $fname= utf8_decode ($fname);
  $lname= utf8_decode ($lname);
  
  $html = "";
  $html .= "<div data-role=page data-add-back-btn=true>";
  $html .=   "<div data-role=header>";
  $html .=     "<h1>Window 2</h1>";
  $html .=   "</div>";
  $html .=   "<div data-role=content>";
  $html .=   "<p>Window content 2</p>";
  $html .=   "<p>First name : $fname</p>";
  $html .=   "<p>Last name : $lname</p>";
  $html .=   "</div>";
  $html .= "</div>";
  echo utf8_encode ($html);
?>



아래 이미지를 보시면 두번째 윈도우에 파라미터가 display 되고 있습니다.




Modify the transition to display the window


지금 까지는 두 윈도우간 이동시 디폴트 transition 만 사용했습니다. jQuery Mobile은 $.mobile.changePage () call에서 transition option을 사용해서 특정 transition을 설정할 수 있는 기능을 제공합니다.


이전 예제에 transition option을 추가 하겠습니다.


Use slideup to transition between the two windows


$.mobile.changePage ("action.php",

{

  data : { fname : "Eric", lname : "Sarrion" },

  transition : "slideup"

});




두번째 윈도우가 나타날 때 이전과는 다르게 나타날 겁니다.


Create a window and then dynamically display when a click occurs


HTML 안에 이미 만들어진 윈도우를 display 하는 대신에 링크를 클릭하면 $.mobile.changePage () method로 dynamic 하게 새로운 윈도우를 만들어서 display 하고 싶습니다.


Creating window dynamically


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content 1 </p>  

    <a href=# id=link1> Goto window 2 </a>

  </div>

</div>


</body>

</html>


<script>


var html = "";

html += "<div data-role=page id=win2 data-add-back-btn=true>";

html +=   "<div data-role=header>";

html +=     "<h1>Window 2</h1>";

html +=   "</div>"

html +=   "<div data-role=content>";

html +=     "<p> Window content 2 </p>";

html +=   "</div>";

html += "</div>";


$(html).insertAfter ("#home");


$("#link1").bind ("click", function (event)

{

  $.mobile.changePage ($("#win2"));

});


</script>



이럴 경우에 insertAfter (selector) jQuery method를 사용해서 표현하시면 됩니다. (DOM 안에 첫번째 윈도우에 이어서 만들어진 윈도우가 삽입되겠죠. 그 다음에 링크를 누르면 그 새로운 윈도우가 display 되는 겁니다.)


반응형


반응형

Construction of the window by the PHP server


이전 글에서 다룬 예제에서 조금 더 나아가서 디스플레이 될 윈도우를 생성하는 소스를 가지고 있는 (같은 서버 내에서) PHP page로 링크럴 걸 경우에 대해 알아보겠습니다.


Index.html file that contains the first window


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content 1 </p>

    <a href=action.php> Goto window 2 built with action.php </a>

  </div>

</div>


</body>

</html>



action.php file constructing the second window


<?
  $html = "";
  $html .= "<div data-role=page data-add-back-btn=true>";
  $html .=   "<div data-role=header>";
  $html .=     "<h1>Window 2</h1>";
  $html .=   "</div>";
  $html .=   "<div data-role=content>Window content 2</div>";
  $html .= "</div>";
  echo utf8_encode ($html);
?>


jQuery Mobile은 action.php file안에 include 된 두번째 윈도우를 retrieve 하기 위해 Ajax를 사용할 겁니다. 이를 위해 우리는 반드시 utf8_encode ()를 사용해야 합니다.


만약 server 코드가 여러개의 윈도우를 return 한다면 오직 첫번째 윈도우만 윈도우들의 stream 안에 놓여지게 될 겁니다.


action2.php


convention14.html



Link to another HTML page located on another server


링크를 같은 서버가 아니라 다른 서버로 즉 href attribute 가 external URL이 되는 경우도 있습니다. 이 경우는 full URL 을 사용하겠죠. (http://로 시작하는). 이 경우에는 이전의 페이지 대신에 새로운 페이지가 display 될 겁니다. (jQuery Mobile 의 windows flow 와 맞지 않게 됩니다.)


Link to http://amazon.com


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content 1 </p>

    <a href=http://amazon.com> Goto Amazon </a>

  </div>

</div>


</body>

</html>




convention15.html



이 링크를 클릭하면 Amazon.com page가 open 될 겁니다.





Disable the loading of an HTML page with Ajax



디폴트로 href attribute의 value는 jQuery Mobile이 만드는 Ajax call 에서는 같은 서버의 HTML page를 가리킵니다. 이렇게 해서 어플리케이션 윈도우의 flow 안에서 HTML 페이지들을 표시하게 되고 그래서 두번째 페이지에 있는 Back button을 누르면 다시 첫번째 페이지로 돌아갈 수 있게 됩니다.



It is possible, indicating certain attributes in the link, to change this behavior.

이 behavior를 변경하기 위해 링크의 특정 attribute들을 수정 할 수 있습니다.


  • data-ajax="false"로 하면  Ajax call 을 만들지 않습니다. 새로운 HTML 페이지는 이전의 페이지들을 모두 lost 하게 되죠.
  • rel="external"data-ajax="false" 와 비슷합니다.

  • target="a_value"라고하면 새로운 브라우저를 엽니다.


이런 메카니즘을 이용하는것은 아주 드믑니다. 왜냐하면 여러 페이지들을 Ajax 에 의해서 한 HTML page 처럼 사용하는 디폴트 방법이 훨씬 유용하기 때문입니다.


Dialog windows


여기서는 다른 HTML 페이지에서 layered window 가 정의 될 수 있다는 걸 보여 드리겠습니다.


Index.html file containing the first window


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content 1 </p>

    <a href=index2.html data-rel=dialog data-transition=pop> 

      Goto window 2 located in an another HTML page </a>

  </div>

</div>


</body>

</html>



Index2.html file containing the second window


<!DOCTYPE html>

<html> 

<head> 

  <meta http-equiv=Content-Type content=text/html;charset=iso-8859-1 />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=win2>

  <div data-role=header>

    <h1>Window 2</h1>

  </div>


  <div data-role=content>

    <p> Window content 2</p>

  </div>

</div>


</body>

</html>



이 dialog window는 첫번째 윈도우에서 링크를 클릭하면 열립니다.





convention161.html


convention162.html


반응형


반응형

jQuery Mobile에서는 두가지 방법으로 다른 페이지들과 연결을 하는데요.

첫번째는 <a> links attributes 를 사용해서 다른 페이지들과 연결을 하는 방법이 있구요.

두번째는 $.mobile object 로 정의된 changePatge() 메소드를 사용하는 방법이 있습니다.


이 두가지 방법과 관련해서 공부해 보겠습니다.


Manage the attributes of links



윈도우(페이지)에서 다른 윈도우로 transition 하는 것은 a link 를 통해서 이루어 집니다. 버튼 같은데에 이 a link를 적용해서 사용하거나 하죠. 이 link의 attributes들은 클릭 했을 때 어떤 동작이 일어나도록 합니다.


Link to an email address or phone number


아주 간단한 예제를 보죠. 우리의 애플리케이션 창에서 email, SMS, 전화걸기 등을 할 수 있도록 하겠습니다. <a> link의 href attribute 값을 지정함으로서 이러한 action들이 이루어 지도록 할 수 있습니다.


Links to an email address and telephone number


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Talk to Eric Sarrion : </p>

    <a href=mailto:ericsarrion@gmail.com>By mail</a><br /><br />

    <a href=tel:0625570924>By phone</a><br /><br />

    <a href=sms:0625570924>By SMS</a><br /><br />

  </div>

</div>


</body>





convention11.html


Link to a window in the same HTML page


이건 이전부터 많이 사용하던 고전적인 방법이죠.  링크에 href를 넣는 겁니다. 새로운 윈도우에 대해서는 <div> element의 id 를 사용하구요. 아까 그 href에는 "#" character를 넣습니다. (eg href="#win2")


An HTML page containing two windows


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content 1 </p>

    <a href=#win2> Goto window 2 located in the same page </a>

  </div>

</div>


<div data-role=page id=win2 data-add-back-btn=true>

  <div data-role=header>

    <h1>Window 2</h1>

  </div>


  <div data-role=content>

    <p> Window content 2 </p>

  </div>

</div>


</body>

</html>



convention12.html


Link to a window in another HTML page on the same server


다른 HTML 페이지가 같은 서버의 다른 위치에 있다면 jQuery Mobile 은 내부적으로 Ajax call 을 사용해서 다른 HTML 의 내용을 load 합니다. 두개의 파일은 반드시 같은 서버에 있어야 합니다. 그렇지 않으면 jQuery Mobile에 의한 Ajax call 이 제대로 작동되지 않을 겁니다.


Index.html file that contains the first window


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content 1 </p>

    <a href=index2.html> Goto window 2 located in index2.html </a>

  </div>

</div>


</body>

</html>


index2.html file containing the second window


<!DOCTYPE html>

<html> 

<head> 

  <meta http-equiv=Content-Type content=text/html;charset=iso-8859-1 />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=win2 data-add-back-btn=true>

  <div data-role=header>

    <h1>Window 2</h1>

  </div>


  <div data-role=content>

    <p> Window content 2</p>

  </div>

</div>


</body>

</html>



convention131.html


convention132.html

(Firefox 브라우저에서 테스트 해 보세요.)


여기서 주의해야 할 점은 Ajax 에 의해 로드되는 페이지의 encoding을 가리키기 위해 <meta> tag를 사용했다는 겁니다. 별도의 HTML 파일에 페이지가 있게 되면 jQuery Mobile에 의해 내부적으로 만들어지는 Ajax request는 디폴트로 UTF-8을 사용합니다. iso-8859-1 encoding을 사용하면 외국어를 사용할 때 활용될 수 있습니다.





링크를 클릭하면 두번째 HTML 페이지가 나타납니다.





어떻게 jQuery Mobile이 새로운 HTML 페이지를 로딩하는지를 이해하기 위해 firfox에 있는 Firebug를 사용해보도록 하겠습니다.


클릭하기 전의 HTML 은 아래와 같습니다.




클릭하고 난 후의 HTML 은 아래와 같습니다.



두번째 <div> element (with id win2)가 HTML 페이지의 DOM tree elements의 한 부분이 되는 것을 볼 수 있습니다. 이것은 index2.html page 안에 포함돼 있는 두번째 윈도우와 연관이있습니다. jQuery Mobile이 사용하는 Ajax technique들에 의해 내부적으로 일어난 일입니다. 그렇기 때문에 첫번째 클릭이 일어나면 내용을 표시하기 위해 약간의 시간이 더 걸리게 되는 겁니다. (서버로부터 새로운 HTML 코드를 새로 retrieve 하고 이것을 현재 표시돼 있는 HTML code에 insert 하기 위한 시간이죠.) 이제 새로운 HTML 코드는 final page로 서 로드 됩니다. 이제 이후에 일어나는 클릭에 대해서는 이러한 시간을 필요로 하지 않습니다. 그러니까 좀 더 빨리 화면이 표시 될 수 있겠죠.


두번째 HTML 페이지 내부에 여러개의 윈도우가 있다면 이 경우에는 첫번째 윈도우만 insert 되게 됩니다.


이제 다시 Back button을 사용해서 이전 페이지로 돌아가 보죠. Firebug에 표시되는 HTML code는 아래와 같습니다.



이제 DOM tree에서 두번째 윈도우가 사라진 걸 볼 수 있습니다. jQuery Mobile은 메모리 공간을 절약하기 위해 그 부분을 메모리로부터 remove 합니다. 만약 이 경우에도 메모리에 계속 저장돼 있게 하려면 <div> element안에 data-dom-cache=true attribute 를 넣어주면 됩니다.


Index2.html file containing the second window, which will be stored in memory despite its disappearance of the display


<!DOCTYPE html>

<html> 

<head> 

  <meta http-equiv=Content-Type content=text/html;charset=iso-8859-1 />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=win2 data-add-back-btn=true data-dom-cache=true>

  <div data-role=header>

    <h1>Window 2</h1>

  </div>


  <div data-role=content>

    <p> Window content 2 </p>

  </div>

</div>


</body>

</html>









반응형