반응형
블로그 이미지
개발자로서 현장에서 일하면서 새로 접하는 기술들이나 알게된 정보 등을 정리하기 위한 블로그입니다. 운 좋게 미국에서 큰 회사들의 프로젝트에서 컬설턴트로 일하고 있어서 새로운 기술들을 접할 기회가 많이 있습니다. 미국의 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


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






반응형