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

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리

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




반응형