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

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리


반응형

jQuery Conference Asia 2012



벌써 11월 이군요.

여기는 허리케인 Sandy 가 지나간 뒤에 아주 많은 피해가 보도되고 있네요.


지금 사는 로드아일랜드 지역은 다행히 거의 피해가 없지만 몇달 전까지 살던 뉴저지 Bergen County 지역에 피해가 아주 심한 것 같습니다.


거기 계신 한인분들 모두 별 탈 없으셨으면 합니다.


이제 11일 남았네요.

jQuery Conference Asia 2012  행사가 11월 12일에 하니까요.


미국에서 프로젝트 진행하면서 회의 때 이곳 친구들이 알려주는 이런 저런 정보와 기술들을 배우는게 아주 재밌습니다.


그리고 그런 정보와 기술들을 최대한 이 블로그에 정리를 해서 되도록 많은 분들과 공유를 하려고 노력하고 있습니다.


이번에 인크로스사에서 미국의 유명한 분들을 초대해서 최신기술과 전망에 대한 콘퍼런스를 진행한다고 하니 여건되시는 분들 많은 참여 추천 드립니다.


일자는 2012년 11월 12일 08:30~18시까지이고 장소는 서울 르네상스 호텔 3층 다이아몬드 홀 입니다.


참가 등록은 www.jqueryasia.com 으로 하시면 되구요.


감사하게도 인크로스사에서 저희 블로그 이용자 분들 중 한분께 초청장을 협찬하시기로 하셨습니다.


필요하신 분은 제게 이메일(douggy.park@yahoo.com) 을 주시면 추첨해서 한분께 초청장을 드리겠습니다.


자세한 사항은 여기 를 참조해 주세요.


아래는 자세한 행사 내용 입니다.

join_auth.html










반응형

버튼 관련 예제 파일 들

2012. 10. 31. 05:46 | Posted by 솔웅


반응형
Examples of manipulation of buttons



Managing a two-state button (pressed / not pressed)


이전 예제에서 버튼이 클릭됐을 때 어떤 동작을 하도록 했었습니다. 이 버튼의 상태 (pressed / not pressed)를 관리하기 위해 <a> element에 ui-btn-active CSS class 를 사용할 수 있습니다.


Managing a two-state button


<!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-btn-inner {

      padding : 25px;

      background-color : black;

    }

    .ui-btn-text {

      font-size : 25px;

      color : white;

    }

    .ui-btn-active {

      font-style : italic;

    }

  </style>

</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 id=btn data-role=button href=#> Click here </a>

  </div>

</div>


</body>

</html>


<script>


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

{

  $(this).toggleClass ("ui-btn-active");

});


</script>

tistory435_01.html



이 소스는 버튼이 클릭되면
ui-btn-active class 를 활성화/비활성화 하는 작업을 jQuery 의 toggleClass () method 를 사용해서 구현했습니다.


Dynamically change the text and the button icon


단순히 글자 모양을 바꾼느 것 보다 클릭함에 따라서 글자 자체와 버튼의 아이콘도 바꾸는 것을 한번 해 보죠.


버튼 ON, OFF 두가지 상태가 있고 버튼이 ON 인 상태에서는 아이콘이 오른쪽에 나타나고 OFF 인 상태에서는 아이콘이 없어지도록 하겠습니다.


Volume management ON or OFF


<!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 id=btn data-role=button href=# data-icon=check 

       data-iconpos=right selected=true> Volume ON </a>

  </div>

</div>


</body>

</html>


<script>


$("#btn").attr ("select", "true");


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

{

  var selected = $(this).attr ("select");

  if (selected == "true")

  {

    $(this).attr ("select", "false");

    $(this).find (".ui-icon").hide ();

    $(this).find (".ui-btn-text").text ("Volume OFF");

  }

  else

  {

    $(this).attr ("select", "true");

    $(this).find (".ui-icon").show ();

    $(this).find (".ui-btn-text").text ("Volume ON");

  }

});


</script>

tistory435_02.html




버튼의 상태를 select attribute에 보관해 두고 있죠? (디폴트는 true) 입니다. 그래서 이 값이 true 이면 버튼은 ON 이고 false 이면 버튼은 OFF 가 됩니다. 아이콘은 ui-icon CSS class 에서 처리되구요 텍스트는 ui-btn-text class를 통해서 처리 됩니다.


처음 페이지를 열면 아래와 같을 겁니다.




버튼을 클릭하면 글자가 OFF 로 바뀝니다.





Display a dynamically Delete button on a list item


이제 구현할 기능은 버튼을 동적으로 생성하는 겁니다. 화면에 리스트가 있고 그 리스트 중의 한 아이템을 오른쪽으로 drag 하면 delete 버튼이 생깁니다. 그리고 그 delete 버튼을 누르면 해당 아이템이 지워지는 겁니다.

아이폰의 메일에 이와 비슷한 기능이 있습니다.


Delete button added 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>

  

  <style type=text/css>

    .remove {

      position : absolute;

      right : 10px;

      top : 5px;

      font-size : 13px;

    }

  </style>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content </p>  

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

      <li> Element 1 </li>

      <li> Element 2 </li>

      <li> Element 3 </li>

      <li> Element 4 </li>

      <li> Element 5 </li>

    </ul>

  </div>

</div>


</body>

</html>


<script>


$("li").bind ("swiperight", function (event)

{

  if ($(this).find (".remove").length) return;

  $(this).append ("<input type=button value=Delete class=remove />");

  $("input.remove").unbind ().bind ("click", function (event)

  {  

    $(this).closest ("li").remove ();

    $("ul").find ("li:first").addClass ("ui-corner-top");

    $("ul").find ("li:last").addClass ("ui-corner-bottom");

  });

});


</script>

tistory435_03.html




Delete button은 해당 리스트 아이템에 버튼이 없을 경우에만 생성됩니다. 그리고 이 버튼을 누르면 해당 아이템이 delete 됩니다.




여기서 Delete button이 생겨난 이후에 꼭 버튼만 클릭하는게 아니라 해당 아이템을 클릭하면 그 아이템이 지워지게 하면 재밌을 까요? 이를 위해서는 다음 예제를 참고하세요.


Hide the Delete button by clicking outside the button


버튼 밖을 클릭해서 해당 아이템이 지워지도록 하려면 아래 코드를 자바스크립트 안에 추가하세요.


Remove the Delete button when clicking outside the button


$("li").bind ("vclick", function (event)

{

    $(this).find ("input.remove").remove ();

});



이 코드는 약간의 문제가 있습니다.


해결 방법은 리스트 아이템에 time-out 을 넣는 겁니다. 이렇게 되면 버튼을 클릭해도 제대로 작동할 겁니다.


Inclusion of a delay in the removal of the button


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

    .remove {

      position : absolute;

      right : 10px;

      top : 5px;

      font-size : 13px;

    }

  </style>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content </p>  

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

      <li> Element 1 </li>

      <li> Element 2 </li>

      <li> Element 3 </li>

      <li> Element 4 </li>

      <li> Element 5 </li>

    </ul>

  </div>

</div>


</body>

</html>


<script>


$("li").bind ("swiperight", function (event)

{

  if ($(this).find (".remove").length) return;

  $(this).append ("<input type=button value=Delete class=remove />");

  $("input.remove").unbind ().bind ("click", function (event)

  {  

    $(this).closest ("li").remove ();

    $("ul").find ("li:first").addClass ("ui-corner-top");

    $("ul").find ("li:last").addClass ("ui-corner-bottom");

  });

});


$("li").bind ("vclick", function (event)

{

  var $this = $(this);

  setTimeout (function ()

  {

    $this.find ("input.remove").remove ();

  }, 500);

});


</script>



tistory435_04.html


이 소스에서는 버튼을 클릭하는 시간을 0.5초 줬습니다. 이 시간 동안에는 리스트 아이템은 remove 되지 않을 겁니다. 그 다음에 버튼이 delete 되겠죠.







반응형

버튼 Customize 하기

2012. 10. 31. 04:30 | Posted by 솔웅


반응형
Customize buttons



General appearance of the button



이전 글에서 만들었던 소스를 firefox 의 firebug 를 통해서 jQuery 에 의해 생성된 HTML 소스를 보겠습니다.



<a> link 는 이제 ui-btn CSS class 가 됐죠? 그리고 안에 ui-btn-inner CSS class가 있는 <span> element 도 포함하고 있습니다. 그 안에는 ui-btn-text class 를 가지고 있는 <span> element가 있습니다.


이제 버튼의 style을 원하는 대로 바꿀 수 있겠죠? ui-btn-text CSS class 를 따로 override 해서 정리하면 버튼 스타일을 customize 할 수 있습니다.


Changing the style of the button


<!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-btn-inner {

      padding : 25px;

      background-color : black;

    }

    .ui-btn-text {

      font-size : 25px;

      color : white;

    }

  </style>

</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 id=btn data-role=button href=#> Click here </a>

  </div>

</div>


</body>

</html>


<script>


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

{

  alert ("click");

});


</script>



tistory434_01.html


이렇게 하면 색다른 모양의 버튼이 보일 겁니다.





Aspect of the clicked button


버튼이 눌렸을 때 jQuery Mobile은 ui-btn-down-c CSS class를 assign 합니다. 클래스 이름 끝의 "c"는 default theme button 을 말하는 겁니다. data-theme attribute 에 의해 modify 될 수 있습니다.  이 클래스도 따로 CSS 클래스로 implement 할 수 있습니다.


Adding the CSS class ui-btn-down-c in the styles of buttons


<style type=text/css>

 .ui-btn-inner {

    padding : 25px;

    background-color : black;

  }

  .ui-btn-text {

    font-size : 25px;

    color : white;

  }

  .ui-btn-down-c {

    font-style : italic;

  }

</style>

tistory434_02.html


위 코드를 적용하면 버튼이 클릭될 때 글자가 이탤릭체로 될 겁니다.


특정 CSS property를 사용할 때 주의하실 부분이 있습니다. 예를 들어 ui-btn-down-c class 정의 부분에 color property를 다시 사용하신다면 child element (the <span> with the ui-btn-text CSS class) 안에 재 정의 된 것으로 적용 되지 않을 겁니다. 제대로 처리 되게 하려면 아래와 같이 하셔야 합니다.


Changing the text color when the button is clicked


<style type=text/css>

  .ui-btn-inner {

    padding : 25px;

    background-color : black;

  }

  .ui-btn-text {

    font-size : 25px;

    color : white;

  }

  .ui-btn-down-c {

    font-style : italic;

  }

  .ui-btn-down-c .ui-btn-text {

    color : red;

  }

</style>


tistory434_03.html


이렇게 하면 버튼을 누를 때 글자가 이탤릭 체로 되면서 글자 색도 빨간색으로 바뀌도록 할 수 있습니다.






반응형


반응형
Manage events on buttons


리스트와 마찬가지로 버튼에서 발생할 수 있는 main event 는 click event 입니다. 이 이벤트는 jQuery 의 bind () method 의해 클릭 됐을 때 어떤 동작을 하도록 처리 됩니다.


Process the click on the button


<!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 id=btn data-role=button href=#> Click here </a>

  </div>

</div>


</body>

</html>


<script>


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

{

  alert ("click");

});


</script>



tistory433_01.html



jQuery Mobile은 여기서 vclick event  가 아니라 click event 를 사용할 것을 권장합니다.


반응형

Ajax 로 버튼 insert 하기

2012. 10. 30. 03:41 | Posted by 솔웅


반응형
Insert buttons by Ajax

이제 Ajax를 통해서 HTML element를 버튼으로 만들어서 화면에 그 버튼을 표시하려고 합니다. 첫번째 버튼은 링크 처럼 <a> element 이고 두번째 버튼은 type="submit" attribute 를 가지고 있는 <input> button 이 될 것입니다.


Insert buttons in a window via Ajax


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


$.ajax (

{

  url : "action.php", 

  complete : function (xhr, result)

  {

    if (result != "success") return;

    var response = xhr.responseText;

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

    $("#btn").button ();

    $("input[type=submit]").button ();

  }

});    


</script>



서버에 있는 action.php file 이 이 두개의 버튼을 만들 HTML 코드를 return 할 겁니다.


action.php file


<?
$html = "";
$html .= "<a id=btn href=#>Menu 1</a>";
$html .= "<input type=submit value=Submit />";
  
echo utf8_encode ($html);

?>


action3.php


tistory431_01.html



서버로부터 소스를 받을 시간동안 약간 기다리면 두개의 버튼이 화면에 뜨시는 것을 보실 겁니다.

자바스크립트 부분을 잘 보세요. button () method를 사용했습니다. 이 메소드는 서버로부터 받은 두개의 HTML element들을 jQuery Mobile 에 의해 standard button들로 화면에 뿌려주도록 합니다. 만약 소스가 잘 못됐던가 해서 이 과정이 실패하면 화면에는 링크와 일반적인 HTML 버튼이 뿌려질겁니다.




다른 jQuery Mobile component들과 같이 component를 생성하는 standard method 는 (button () method 같은) 그 버튼을 포함한 element에서trigger ("create") method를 call 함으로서 구현할 수도 있습니다. 아래에 예제를 보시겠습니다.


Use the create event to create the button


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


$.ajax (

  url : "action.php", 

  complete : function (xhr, result)

  {

    if (result != "success") return;

    var response = xhr.responseText;

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

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

  }

});


</script>



하나의 create event로 두개의 버튼을 생성할 수 있습니다. 여기서 첫번째 버튼에다가 이것을 button component로 바꿀 거라는 것을 알리기 위해 data-role="button" attribute를 추가 해야 합니다 두번째 버튼에는 <input> element 이기 때문에 필요없습니다.


action.php file


<?
$html = "";
$html .= "<a id=btn data-role=button href=#>Menu 1</a>";
$html .= "<input type=submit value=Submit />";
  
echo utf8_encode ($html);
?>

action4.php


tistory432_02.html




반응형


반응형

Turning a HTML element into a jQuery Mobile button


For an element to be transformed into a button, use the button () method on the HTML element.

Using the button () 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 </p>  

  </div>

</div>


</body>

</html>


<script>


var html = "";

html += "<a id=btn href=#>";

html +=     "Click the button";

html += "</a>";

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


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

  $("#btn").button ();

});


</script>


Note that the window is expected to be created to transform the link into button (pagecreate event). However, in the case of buttons, it is not necessary, unlike the lists that we have previously studied. But for the sake of thoroughness, we try to write similar code in both cases ...





tistory430_02.html



반응형


반응형

버튼을 다루는 것도 리스트를 다루는 것하고 비슷합니다. 여기서는 button () method를 사용해서 HTML element를 jQuery Mobile button으로 바꾸게 됩니다. 이 버튼들은 button standard component 에 맞게 display 됩니다.


Dynamically create a button


HTML 페이지에서 버튼을 dynamically 생성하는 것을 알아 보겠습니다.  그것을 하기 위해서 <a> element 를 만들고 거기에 data-role="button" attribute 를 달겠습니다. 버튼의 다른 기능들도 (data-inline, data-icon, etc..) 그 element의 attributes에서 정해줄 수 있습니다.


Dynamic creation of a button


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


var html = "";

html += "<a id=btn href=# data-role=button data-icon=check data-iconpos=right>";

html +=     "Click the button";

html += "</a>";

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


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

{

  alert ("click");

});


</script>



tistory430_01.html


이 코드를 실행하고 버튼을 누르면 아래와 같이 될 겁니다.




<a> element 는 다이나믹하게 들어갔습니다. 그리고 jQuery Mobile 버튼을 만들도록 하고 있죠. 다이나믹하게 들어간 <a> element 에 jQuery Mobile 버튼이 만들어지게 되는 겁니다.

반응형

리스트 다루기 예제

2012. 10. 29. 05:08 | Posted by 솔웅


반응형
Examples of list manipulation


Create lists containing sub-lists


이 글에서 우리는 리스트의 아이템을 클릭하면 리스트 안에 sublist 가 나오도록 할 겁니다. sub-list 는 클릭 된 아이템 밑에 나오겠죠. 그리고 한번 더 그 아이템을 클릭하면 sub-list를 숨기겠습니다. 이 기능은 accordion menu 의 핵심이죠.


Manage sub-lists in 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>

    <p> Window content </p>  

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

      <li data-role=list-divider data-icon=arrow-d>

        <a href=#> List 1 </a></li>

      <li> Element 1.1 </li>

      <li> Element 1.2 </li>

      <li> Element 1.3 </li>

      <li> Element 1.4 </li>

      <li> Element 1.5 </li>

      <li data-role=list-divider data-icon=arrow-d>

        <a href=#> List 2 </a></li>

      <li> Element 2.1 </li>

      <li> Element 2.2 </li>

      <li> Element 2.3 </li>

      <li> Element 2.4 </li>

      <li> Element 2.5 </li>

      <li data-role=list-divider data-icon=arrow-d>

        <a href=#> List 3 </a></li>

      <li> Element 3.1 </li>

      <li> Element 3.2 </li>

      <li> Element 3.3 </li>

      <li> Element 3.4 </li>

      <li> Element 3.5 </li>

    </ul>

  </div>

</div>


</body>

</html>


<script>


$("li:not(:jqmData(role=list-divider))").hide ();


$("li:jqmData(role=list-divider)").bind ("vclick", function (event)

{

  $(this).nextUntil ("li:jqmData(role=list-divider)").toggle ();

});


</script>



tistory429_01.html


이 소스를 브라우저에서 열면 처음에는 리스트의 title들만 보입니다. 그리고 sub-list 들은 보이지 않죠. 이 리스트의 title들은 <li> elements 에 data-role="list-divider" attribute 를 가지고 있습니다.  바로 이 부분을 스크립트에서 처음 부분에서 받아서 사용하게 되는 겁니다.



Hide list items that are not titles of list


$("li:not(:jqmData(role=list-divider))").hide ();


bind () statement 는 title element들에서 click events 가 발생하는 것을 observe 하는데 사용합니다. 그 다음에는 sub-title 을 숨기고 보이고 하는 기능들을 진행하게 되죠.

프로그램이 처음 실행 될 때는 모든 list 들이 close 된 상태입니다.




Click on the first element (List 1):




sub-list 는 list 안에 있습니다. 이 리스트를 클릭하면 그 sub-list 가 보이기도 하고 숨기도 하죠.


Change the icon for a list item


이전 프로그램을 조금 더 발전시킬까요. 리스트가 open 인 상태에서 title에 있는 icon 을 바꾸고 싶습니다. 화살표 방향이 다른걸로 표시하고 싶습니다. close 되면 다시 원래 화살표 방향으로 돌아오구요.

To achieve this, we must look in more detail, how is designed the HTML code created by jQuery Mobile to display a list item containing the icon.

이를 위해서는 jQuery Mobile 에 의해 생성된 HTML 코드를 봐야 합니다.





위에 코드를 보시면 icon은 <span> element 의 ui-icon class 에 의해 표시됩니다. 또한 ui-icon-arrow-d class도 아이콘을 표시하는데 영향을 미칩니다. up arrow 아이콘을 표시하기 위해 ui-icon-arrow-u class를 바꾸겠습니다.


data-icon attribute 가 리스트 아이템 내의 아이콘을 표시하는데 별 역할을 안 하고 있는 부분을 잘 보세요. 이 attribute는 리스트 아이템을 생성할 때에만 사용됩니다. 그리고 그 이후의 modification은 영향을 미치지 않습니다.


Change the icon displayed in a list item when clicking it


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

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

      <li data-role=list-divider data-icon=arrow-d>

        <a href=#> List 1 </a></li>

      <li> Element 1.1 </li>

      <li> Element 1.2 </li>

      <li> Element 1.3 </li>

      <li> Element 1.4 </li>

      <li> Element 1.5 </li>

      <li data-role=list-divider data-icon=arrow-d>

        <a href=#> List 2 </a></li>

      <li> Element 2.1 </li>

      <li> Element 2.2 </li>

      <li> Element 2.3 </li>

      <li> Element 2.4 </li>

      <li> Element 2.5 </li>

      <li data-role=list-divider data-icon=arrow-d>

        <a href=#> List 3 </a></li>

      <li> Element 3.1 </li>

      <li> Element 3.2 </li>

      <li> Element 3.3 </li>

      <li> Element 3.4 </li>

      <li> Element 3.5 </li>

    </ul>

  </div>

</div>


</body>

</html>


<script>


$("li:not(:jqmData(role=list-divider))").hide ();


$("li:jqmData(role=list-divider)").bind ("vclick", function (event)

{

  $(this).nextUntil ("li:jqmData(role=list-divider)").toggle ();

  var $span = $(this).find ("span.ui-icon");

  if ($span.hasClass ("ui-icon-arrow-d")) 

  {

    $span.removeClass ("ui-icon-arrow-d");

    $span.addClass ("ui-icon-arrow-u");

  }

  else 

  {

    $span.removeClass ("ui-icon-arrow-u");

    $span.addClass ("ui-icon-arrow-d");

  }

});


</script>



tistory429_02.html

(그대로 따라 했는데 왜 제 브라우저에서는 화살표 아이콘이 안 나올까요?

혹시 화살표 아이콘 나오시는 분은 저에게 방법 좀 알려 주세요.)

For example, when List 3 is open:





Managing the click on the icon of an item in a static list


이제 static 리스트 아이템에서 아이콘을 클릭했을 때 처리하는 방법을 알아보겠습니다. 예를 들어 한 리스트에 5개의 아이템을 넣었습니다. 각 element는 각각 delete icon이 있고 이 delete icon을 클릭 하면 해당 element를 delete 합니다.


그러려면 각 <li> item 의 아이콘에 클릭이 일어날 경우 이를 다룰 수 있어야 겠죠. 위의 예제에서 보았듯이 이 아이콘은 <span> element 의 ui-icon CSS class에 의해 표시됩니다.  아래 샘플 코드를 보세요.


Manage click on the delete icon of list items


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

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

      <li data-icon=delete> <a href=#>Element 1 </a></li>

      <li data-icon=delete> <a href=#>Element 2 </a></li>

      <li data-icon=delete> <a href=#>Element 3 </a></li>

      <li data-icon=delete> <a href=#>Element 4 </a></li>

      <li data-icon=delete> <a href=#>Element 5 </a></li>

    </ul>

  </div>

</div>


</body>

</html>


<script>


$("li .ui-icon").bind ("click", function (event)

{

  $(this).closest ("li").remove ();

});


</script>






위와 같이 표시 되는데 제대로 작동되지는 않습니다. 그 이유는 아직 리스트의 HTML 이 jQuery Mobile code 로 transform 하지 않았기 때문이죠. 제대로 하기 위해서는 리스트가 finalize 되기까지 기다려야 합니다. 그러니까 bind () method 는 리스트가 finalize 한 이후에 나와야겠죠.


So we write:


Wait until the list was created to manage the click on the delete icon


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

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

      <li data-icon=delete> <a href=#>Element 1 </a></li>

      <li data-icon=delete> <a href=#>Element 2 </a></li>

      <li data-icon=delete> <a href=#>Element 3 </a></li>

      <li data-icon=delete> <a href=#>Element 4 </a></li>

      <li data-icon=delete> <a href=#>Element 5 </a></li>

    </ul>

  </div>

</div>


</body>

</html>


<script>


$("ul").bind ("listviewcreate", function (event)

{

  $("li .ui-icon").bind ("click", function (event)

  {

    $(this).closest ("li").remove ();

  }).css ("z-index", 10);

});


</script>

tistory429_03.html




Manage the click on the icon of an item in a dynamically created list (solution 1)


이제 리스트는 원래 HTML 내에서 존재하지는 않고 JavaScript 에 의해서 dynamically 생성된다는 것을 알 수 있습니다.


그러면 두번째 방법도 고려해 볼 수 있습니다. (물론 이전 방법도 훌륭한 방법입니다) 두번째 방법은 listviewcreate event를 사용해서 리스트가 생성되기를 기다리는 대신 jQuery Mobile listview () method를 사용해서 오리지널 HTML 코드를 transform 하도록 하는 겁니다. 그러면 jQuery Mobile conventions에 맞게 display 할 수 있습니다.


The program becomes:


Direct use of the listview () 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 </p>  

  </div>

</div>


</body>

</html>


<script>


var html = "";

html += "<ul data-inset=true>";

html += "<li data-icon=delete> <a href=#>Element 1 </a></li>";

html += "<li data-icon=delete> <a href=#>Element 2 </a></li>";

html += "<li data-icon=delete> <a href=#>Element 3 </a></li>";

html += "<li data-icon=delete> <a href=#>Element 4 </a></li>";

html += "<li data-icon=delete> <a href=#>Element 5 </a></li>";

html += "</ul>";

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


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

{

  $("ul").listview ();

  

  $("li .ui-icon").bind ("click", function (event)

  {

    $(this).closest ("li").remove ();

  });

});


</script>



tistory429_04.html

이 소스도 제 경우엔 제대로 동작하지 않네요. 혹시 되시는 분 저에게 정보 좀 부탁드립니다.


listview () method call은 생성된 리스트를 jQuery Mobile 리스트로 dynamically convert 해 줍니다. 이 메소드는 window 가 이미 생성된 상태에서 call 될 수 있습니다. 그래서 여전히 pagecreate event를 사용하고 있는 겁니다.


Manage the click on the icon of an item in a dynamically created list (solution 2)


바로 전 샘플 코드에 대해 더 알아보죠. 리스트의 HTML 에 data-role="listview" attribute를 넣었습니다. 이것은 콤포넌트를 생성하기 위해 listview () method 를 call 하는 것을 막아 주는 겁니다.


어쨌든 리스트 아이템에 있는 아이콘에 click event가 일어나는 여부를 observation 하는 것은 리스트가 생성된 이후에나 가능합니다. 그래서 리스트에 listviewcreate event 를 사용해야 하는 겁니다.


Using the listviewcreate event


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


var html = "";

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

html += "<li data-icon=delete> <a href=#>Element 1 </a></li>";

html += "<li data-icon=delete> <a href=#>Element 2 </a></li>";

html += "<li data-icon=delete> <a href=#>Element 3 </a></li>";

html += "<li data-icon=delete> <a href=#>Element 4 </a></li>";

html += "<li data-icon=delete> <a href=#>Element 5 </a></li>";

html += "</ul>";

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


$("ul").bind ("listviewcreate", function ()

{

  $("li .ui-icon").bind ("click", function (event)

  {

    $(this).closest ("li").remove ();

  });

});


</script>



만약 listviewcreate event를 사용하지 않으면 이 리스트는 생성되지만 아이콘을 클릭해도 제대로 기능을 하지 않을 겁니다.


Allow deletion of a list item by clicking and holding


각 리스트 아이템마다 delete icon을 표시하는 것 보다 long click 을 감지해서 처리할 수도 있을 겁니다. 여기에 해당하는 이벤트가 taphold 입니다.


Delete an item from the list after a long click on the item


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

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

      <li> Element 1 </li>

      <li> Element 2 </li>

      <li> Element 3 </li>

      <li> Element 4 </li>

      <li> Element 5 </li>

    </ul>

  </div>

</div>


</body>

</html>


<script>


$("li").bind ("taphold", function (event)

{

  $(this).remove ();

});


</script>

tistory429_06.html




Allow deletion of a list item with a swipe


이제 오른쪽으로 swipe 했을 경우 아이템을 지우도록 해 보죠.


The event is managed by swiperight. Here is the program:


Manage swiperight events on the elements to remove


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

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

      <li> Element 1 </li>

      <li> Element 2 </li>

      <li> Element 3 </li>

      <li> Element 4 </li>

      <li> Element 5 </li>

    </ul>

  </div>

</div>


</body>

</html>


<script>


$("li").bind ("swiperight", function (event)

{

  $(this).remove ();

});


</script>



tistory429_07.html


Keep the rounded edges appearance to the list


이전 예제에서 리스트 블럭의 모서리가 rounding 처리 된 걸 보셨을 겁니다. 이 모서리들은 <ul> 에서 data-inset attribute 를 "true"로 세팅해서 처리한 겁니다.


아이템을 delete 했을 때 우리는 jQuery Mobile 에게 리스트의 첫번째 아이템과 마지막 아이템에 이 rounding 처리를 하라고 얘기해야 합니다. 첫번째나 마지막 아이템이 지워지면 그 자리를 차지하는 아이템에 rounding 처리가 되야 되겠죠. 이렇게 하기 위해 jQuery Mobile 은 첫번째 리스트 아이템에 ui-corner-top CSS class를 사용하고 마지막 리스트 아이템에 ui-corner-bottom CSS class를 사용합니다.

아이


이전 예제를 사용해서 여기에 CSS class를 추가 하겠습니다.


Keep the rounded edges appearance to the 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>

    <p> Window content </p>  

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

      <li> Element 1 </li>

      <li> Element 2 </li>

      <li> Element 3 </li>

      <li> Element 4 </li>

      <li> Element 5 </li>

    </ul>

  </div>

</div>


</body>

</html>


<script>


$("li").bind ("swiperight", function (event)

{

  $(this).remove ();

  $("ul").find ("li:first").addClass ("ui-corner-top");

  $("ul").find ("li:last").addClass ("ui-corner-bottom");

});


</script>


tistory429_08.html



이제 첫번째와 마지막 element 가 지워져도 계속 rounding 효과는 유지 됩니다.






다른 방법도 있는데요. 더 쉽습니다. jQuery Mobile 이 이 CSS 를 자동으로 관리하도록 하면 됩니다. listview ("refresh") method 를 사용하면 되요. 이를 위해 아래 두 라인을 맨 밑의 예제코드로 바꿔주면 됩니다.


Management of rounded edges on the lists (with CSS classes)


$("ul").find ("li:first").addClass ("ui-corner-top");

$("ul").find ("li:last").addClass ("ui-corner-bottom");


For this:


Management of rounded edges on the lists (with the listview ("refresh") method)


$("ul").listview ("refresh");






반응형


반응형

요즘 여기 미국도 어딜가나 강남스타일이예요.


어쩌다가 택시를 타도 운전기사가 강남스타일 듣고 있고


라디오를 켜도 강남스타일이 나오고


파티를 가도 강남스타일을 틀어 놓고


어제는 동네에서 하는 할로윈 행사장에 갔는데


여기서도 역시나 강남스타일......



한국에서 멀리 떨어져 살면서도 이렇게 한국 노래를 쉽고 자주 접할 수 있는 상황이 신기하고 너무 좋아요.


강남스타일 개인적으로 연말 그래미상도 기대해 봅니다.


너무 좋아서 태어나서 처음으로 찍은 동영상을 유튜브에 올렸어요.


이것도 기분 좋고.....


근데 이걸 모바일로 보려면 아래와 같이 메세지가 나오네요.





이거 어떻게 하면 모바일 폰에서도 나오게 할 수 있죠? ;;


반응형

리스트 Customization 하기

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


반응형
Customize lists


이전 글에 있는 소스를 이용하겠습니다.  5개의 element들이 있죠. 이것을 firefox 브라우저에 있는 firebug로 jQuery Mobile에 의해 생성된 HTML 을 보겠습니다.




각각의 list item은 ui-li CSS class 를 가지고 있습니다. <ul> 가 감싸고 있는 리스트는 ui-listview CSS class를 가지고 있습니다. 이 두개의 클래스를 지난번 작업했던 HTML 소스 안에 코딩해 넣어서 새로운 리스트 모양을 꾸미겠습니다.


Change the style of list items


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

      color : #0099FF;

      font-size : 20px;

      font-style : italic;

    }

    .ui-listview {

      padding : 10px;

      background-color : black;

    }

  </style>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content </p>  

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

      <li> Element 1.1 </li>

      <li> Element 1.2 </li>

      <li> Element 1.3 </li>

      <li> Element 1.4 </li>

      <li> Element 1.5 </li>

    </ul>

  </div>

</div>


</body>

</html>


<script>


$("li").bind ("vclick", function (event)

{

  alert (this.innerHTML);

});


</script>







tistory426_01.html


리스트의 각 element의 높이가 커졌습니다. (새 글자 폰트에 맞게 조정이 된거죠.) 그리고 이 리스트는 검은 border로 감싸져 있습니다. 이것은 ui-listview CSS class 에서 정의한 것입니다.




반응형