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

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리

Ajax 로 리스트 Retrieve 하기

2012. 10. 23. 21:06 | Posted by 솔웅


반응형
Retrieve a list by Ajax


Ajax에 의해 처리된 리스트를 만들겁니다. 이 리스트는 window content에 마지막 element 로서 추가 될 겁니다.


Retrieve a list by Ajax and insert into the window


<!DOCTYPE html>

<html> 

<head> 

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

  <meta name="apple-mobile-web-app-capable" content="yes" />

  <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>


$.ajax (

  url : "action.php", 

  complete : function (xhr, result)

  {

    if (result != "success") return;

    var response = xhr.responseText;

    $("#home div:jqmData(role=content)").append (response);

    $("#list").listview ();

  }

}); 


</script>



action.php file 에는 window 에 넣을 list를 return 하는 server program 이 있습니다.


action.php file



<?
$html = "";
$html .= "<ol id=list data-inset=true>";
$html .=   "<li data-role=list-divider>List retrieved by Ajax</li>";
$html .=   "<li data-icon=delete>";
$html .=      "<a href=#>Element 1</a>";
$html .=   "</li>";
$html .=   "<li data-icon=delete>";
$html .=      "<a href=#>Element 2</a>";
$html .=   "</li>";
$html .=   "<li data-icon=delete>";
$html .=      "<a href=#>Element 3</a>";
$html .=   "</li>";
$html .= "</ol>";
  
echo utf8_encode ($html);
?>



자바스크립트 코드 안에 있는 $("#list").listview () statement를 보세요. 여기서 서버로부터 HTML 코드를 받아 이것을 jQuery Mobile 의 list 로 display 하는 겁니다. 이게 없으면 이 리스트는 jQuery Mobile 의 list를 보여주지 않고 그냥 단순히 HTML list 를 보여주게 됩니다.


이 예제의 결과는 아래 화면과 같을 겁니다.




action419.php


tistory419_01.html



Window에 list 를 생성하기 위해 create event 를 사용하실 수도 있습니다.


Create the list using listview ()


$("#list").listview ();


위 코드 부분 아래에 아래 코드를 추가하세요.


Create the list using the create event


$("#home").trigger ("create");


만약 create event를 사용하신다면 이 리스트는 서버로부터 반드시 data-role="listview" attribute 를 retrieve 할 겁니다. 그렇지 않으면 jQuery Mobile은 이 HTML element를 jQuery Mobile 리스트로 전환해야 된다는 것을 알지 못합니다.  listview () method 를 사용하시면 이 attribute는 필요가 없게 되는 거죠. 이 메소드가 call 되면 jQuery Mobile list로 transform 해야 된 다는 것을 알려 주는 겁니다. (여기서는 #list1 element 임)




반응형


반응형





Turning a HTML element into a jQuery Mobile list



이번에 할 작업은 일반적인 HTML에서의 리스트 표시 방법인 <ul> or <ol>를 jQuery Mobile 식으로 display 하도록 바꾸는 작업입니다. <ul> or <ol> element 가 data-role="listview" attribute 를 사용해서 리스트를 표시할 수 있는 것은 이미 알고 계시죠? 우리는 이 attribute를 어떻게 <ul> or <ol> element 에 이 attribute를 적용하는지에 대해 알아 볼겁니다.


아래 예제를 보실텐데요 일단 고전적인 attribute들인 data-role, data-icon, etc 을 모두 제거한 코드를 먼저 보시겠습니다.


A HTML list with no jQuery Mobile conventions


<!DOCTYPE html>

<html> 

<head> 

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

  <meta name="apple-mobile-web-app-capable" content="yes" />

  <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>

    <ol id=list1>

      <li>Element 1.1</li>

      <li>Element 1.2</li>

      <li>Element 1.3</li>

    </ol>

  </div>

</div>


</body>

</html>


<script>


</script>



이 리스트는 전형적인 jQuery Mobile window를 포함하고 있습니다. 그런데 <ol> element 가 data-role="listview" attribute를 가지고 있지 않습니다.  이 리스트는 아주 기본적인 형식만 갖췄습니다.




tistory418_01.html


이제 자바스크립트로 jQuery Mobile convention을 따라서 display 하도록 무너가 작업을 해야될 것 같군요. 이를 위해서 listview jQuery Mobile component 에 있는 listview () method를 사용해서 HTML 리스트를 jQuery Mobile 리스트로 표시할 겁니다.

Add this statement in our JavaScript code:


Call to the listview () method on the list


<!DOCTYPE html>

<html> 

<head> 

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

  <meta name="apple-mobile-web-app-capable" content="yes" />

  <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>

    <ol id=list1>

      <li>Element 1.1</li>

      <li>Element 1.2</li>

      <li>Element 1.3</li>

    </ol>

  </div>

</div>


</body>

</html>


<script>


$("#list1").listview ();


</script>





tistory418_02.html



그런데 기대했던 모습은 아니네요. 우리는 이 window 가 생성될 때 그냥 거기서 jQuery Mobile component (list) 를 display 하라고 시켰습니다. 이러지 말고 이 window 가 그 transformation을 수행하기 위한 과정에서 create 될 때 까지 좀 더 기다려 줘야 할 것 같습니다.


그 윈도우의 pagecreate event 에서 listview () instruction을 집어 넣어 보겠습니다. 그러면 이 윈도우가 create 되는 것을 끝마칠 때까지 기다릴 겁니다.


Call to the listview () method in the treatment of the pagecreate event


<!DOCTYPE html>

<html> 

<head> 

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

  <meta name="apple-mobile-web-app-capable" content="yes" />

  <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>

    <ol id=list1>

      <li>Element 1.1</li>

      <li>Element 1.2</li>

      <li>Element 1.3</li>

    </ol>

  </div>

</div>


</body>

</html>


<script>


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

{

  $("#list1").listview ();

});


</script>





tistory418_03.html



이제 기대했던 대로 나왔네요.....





반응형


반응형

jQuery Mobile에 의해서 display 되는 리스트 만들기는 jQuery 에 그 기본을 둡니다. jQuery Mobile 은 그것을 사용하기 위해 listview () method를 implement합니다. 이 리스트들은 listview standard component와 연계가 있습니다.



Dynamically create a list



리스트는 HTML 코드 안에서 생성할 수 있습니다. jQuery Mobile 은 이 리스트 아이템들을 좀 더 예쁘게 보이도록 새로운 CSS 클래스를 적용해서 HTML을 convert 할 수 있습니다.


그리고 새로운 리스트를 jQuery 의 메소드를 사용해서  dynamic 하게 생성하는 것도 가능합니다.


List without images


아래 예제에서는 페이지에 HTML 코드로 list 를 만들고 두번쨰로는 JavaScript code로 dynamic 하게 list를 생성했습니다. 마지막으로 이 두 리스트의 view를 일관되게 표현했습니다.


Dynamic creation of a list


<!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>

    <ol id=list1 data-role=listview data-inset=true>

      <li data-role=list-divider>Static list</li>

      <li data-icon=delete>

        <a href=#>Element 1.1</a>

      </li>

      <li data-icon=delete>

        <a href=#>Element 1.2</a>

      </li>

      <li data-icon=delete>

        <a href=#>Element 1.3</a>

      </li>

    </ol>

  </div>

</div>


</body>

</html>


<script>


var html = "";

html += "<ol id=list2 data-role=listview data-inset=true>";

html +=   "<li data-role=list-divider>Dynamic list</li>";

html +=   "<li data-icon=delete>";

html +=      "<a href=#>Element 2.1</a>";

html +=   "</li>";

html +=   "<li data-icon=delete>";

html +=      "<a href=#>Element 2.2</a>";

html +=   "</li>";

html +=   "<li data-icon=delete>";

html +=      "<a href=#>Element 2.3</a>";

html +=   "</li>";

html += "</ol>";


$("#home div:jqmData(role=content)").append (html);


</script>



첫번째 리스트는 전통적인 방법으로 HTML을 사용해서 생성했고 (static list) 두번째는 JavaScript 로 자동으로 생성해서 append (html) instruction을 사용해서 DOM tree에 insert 했습니다(dynamic list).




tistory417_01.html


List with images


이번에는 위와 같은 예제인데요 다른 점은 리스트 아이템 안에 이미지가 들어가는 겁니다. static list 는 두개의 리스트 아이템이 있고 dynamic list에는 한개의 아이템이 있습니다.


Dynamic creation of a list with images


<!DOCTYPE html>

<html> 

<head> 

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

  <meta name="apple-mobile-web-app-capable" content="yes" />

  <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>

    <ul id=list1 data-role=listview data-inset=true>

      <li data-role=list-divider>Static list</li>

      <li>

        <img src=images/html.jpg />

        <h1> HTML & CSS</h1>

        <p> Eric Sarrion</p>

      </li>

      <li>

        <img src="images/j2ee.jpg" />

        <h3>J2EE</h3>

        <p> Eric Sarrion</p>

      </li>

    </ul>

  </div>

</div>


</body>

</html>


<script>


var html = "";

html += "<ul id=list2 data-role=listview data-inset=true>";

html +=   "<li data-role=list-divider>Dynamic list</li>";

html +=   "<li>";

html +=     "<img src=images/jquery.jpg />";

html +=     "<h3>JQuery & jQuery UI</h3>";

html +=     "<p> Eric Sarrion</p>";

html +=   "</li>";

html += "</ul>";


$("#home div:jqmData(role=content)").append (html);


</script>





tistory417_02.zip




반응형

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 되는 겁니다.


반응형