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

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리

Virtual Events 알아보기

2012. 9. 30. 22:54 | Posted by 솔웅


반응형

Virtual Events


virtual event들을 사용하는 이유는 HTML element를 trigger 할 수 있는 손가락이나 mouse 와 관련된 이벤트들을 표준화 하기 위해서 입니다. 이러한 이벤트들은 서로 다른 이름들을 가지고 있습니다. (eg touchstart and click for click type events, or touchmove and mousemove to move type events) jQuery Mobile 은 virtual events라고  하는 것을 만들어서 이러한 이벤트들의 이름을 표준화 했습니다.


Virtual events

Name

Signification

vclick

Idem click. Warning: jQuery Mobile developers recommend not to use the vclick event when it produces a change in the display (eg click on a link that shows a new window), because the vclick event is sometimes triggered two times - instead of one - when set on a particular element. In these cases, they recommend using click instead. Apart from these elements that can cause problems, we will use vclick.

vmousemove

Idem mousemove.

vmouseover

Idem mouseover.

vmousedown

Idem mousedown.

vmouseup

Idem mouseup.

vmouseout

Idem mouseout.

vmousecancel

Idem mousecancel.


아래 예제는 윈도우에서 어떤 이벤트가 발생 했을 때 그 이벤트의 이름을 화면에 보여 줍니다.


Detect and display the virtual events


<!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 id=home data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Events </p>

  </div>

</div>


</body>

</html>


<script>


var $content = $("#home div:jqmData(role=content)");


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

{

  $content.append (event.type + ", ");

});


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

{

  $content.append (event.type + ", ");

});


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

{

  $content.append (event.type + ", ");

});


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

{

  $content.append (event.type + ", ");

});


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

{

  $content.append (event.type + ", ");

});


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

{

  $content.append (event.type + ", ");

});


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

{

  $content.append (event.type + ", ");

});


</script>







convention04.html



반응형

네임 스페이스 사용하기

2012. 9. 30. 22:40 | Posted by 솔웅


반응형

Using NameSpace


jQuery Mobile 은 data 라는 글로 시작하는 수 많은 attributes 를 사용합니다. 예를 들어 data-role, data-icon, 등이 있습니다. 이러한 attributes들은 jQuery Mobile에서는 아주 의미 있는 것들입니다. 이러한 attribute들이 original HTML 코드를 좀 더 enhance 된  display 를 보여 주도록 합니다.


그런데 이렇게 jQuery Mobile 이 사용하고 있는 attribute들을 다른 library 도 한 두개 사용하고 있다면 어떻게 될까요? 그러면 OS에서는 혼동스럽겠죠.


이러한 문제를 해결하기 위해 jQuery Mobile은 namespaces를 사용합니다. 대부분 data 글자 다음에 추가 됩니다. 아마 data라는 글자로 시작하는 attributes를 가지고 있는 library들은 많을 겁니다. jQuery Mobile을 포함해서요. 하지만 data 뒤에 특별한 name space를 붙이면 같아지지 않겠죠. 예를 들어 data-role 이라는 이름이 중복되지 않게 하기 위해 data-my-role를  사용할 수 있겠죠. 여기서 가 나름대로의 namespace "my-"가 될 수 있을 겁니다.


Indicate the namespace in the HTML page


$.mobile.ns가 namespace로 사용됩니다.  만약 namespace 가 사용되지 않으면 jQuery Mobile은 "" 을 사용합니다. 즉 classic 한 data-role, data-icon, 등을 사용하게 되는거죠.


"ns1-" namespace를 사용하도록 할 수 있습니다.  namespace 끝에 "-"가  붙은것을 잘 봐 두세요. attributes에 space를 사용하지 않고 이것을 많이들 사용하죠.


Using the "ns1-" namespace

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

    $(document).bind ("mobileinit", function ()

    {

      $.mobile.ns = "ns1-";

    });

  </script>  

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

</head> 


<body> 


<div id=home data-ns1-role=page id=home data-ns1-theme=e>

  <div data-ns1-role=header>

    <h1>Home</h1>

  </div>


  <div data-ns1-role=content>

    <p> Window content </p>

  </div>

</div>


</body>

</html>



$.mobile.ns
의 값을 바꾸기 위해 mobileinit event를 사용했습니다. 그리고 그 값을 jQuery Mobile에서 사용하도록 만들었죠.


그리고 나서  data-ns1-role (instead of data-role) 과 data-ns1-theme (rather than data-theme) attributes 들을 사용합니다. 만약 여기서 data-roledata-theme attributes들을 사용하면 작동되지 않을 겁니다.





Access to the attribute in JavaScript code


data-role attribute 가 namespace "ns1-"를 사용해서 data-ns1-role로 사용되는 것을 위에서 보셨습니다. 그렇게 하면 자바스크립트 안에서 data-ns1-role attribute name을 사용할 수 있게 되는 건데요.  아래와 같이도 사용할 수 있습니다.


First form of writing (to be avoided)

alert ($("div#home").attr ("data-ns1-role"));

위와 같이 namespace를 사용할 수도 있고,


Second form of writing (best)

alert ($("div#home").attr ("data-" + $.mobile.ns + "role"));

위와 같이 원래의 $.mobile.ns 를 사용할 수 있습니다.


두번째 것은 namespace 값을 사용하지 않은 거죠. 이렇게 하면 나중에 namespace를 한꺼번에 바꾸어야 될 때 유용하겠죠. 즉 유지, 관리가 용이하게 됩니다.


또한 jQuery Mobile 에서는 이 writing 을 좀 더 간편하게 사용하도록 하는 메소드를 제공하고 있습니다. jqmData (name) method가 그것입니다.


Third form of writing (optimal)

alert ($("div#home").jqmData ("role"));


jqmData (name) method는 "data-"name스트링과 함께 namespace의 연속성을 허용하고 해당 attribute의 값을 retrieve 합니다.  그 attribute 값의 retrieve를 위한 attr () jQuery method는 더이상 사용하지 않습니다.  jqmData () method로 교체 됐죠.


jqmData (name) and jqmData (name, value) methods


jqmData () methods를 사용하는 목적은 jQuery attr () method를 사용하지 않고 해당 attribute들을 관리할 수 있도록 하기 위함 입니다.


Methods managing attributes

Method

Signification

jqmData (name)

Get the value of the data-xxx-name attribute, for example data-ns1-role.

jqmData (name, value)

Set the value of the data-xxx-name attribute, for example data-ns1-role.


Get the theme associated with the window

alert ($("div#home").jqmData ("theme"));


Set the theme associated with the window

$("div#home").jqmData ("theme", "a");


Access to the attribute in selectors


attribute들의 관리를 제대로 하기 위해 jQuery Mobile은 selector들을 사용할 때 이것을 manage 할 수 있도록 방법을 제공하고 있습니다. 여기에 jqmData (value) pseudo-class를 생성하는 이유입니다.


First form of writing (to be avoided)

alert ($("div[data-ns1-role=page]").html ());

위와 같이 하는 대신에 아래와 같이 할 수 있습니다.


Second form of writing (best)

alert ($("div[data-" + $.mobile.ns + "role=page]").html ());


jqmData (value) pseudo class와 같이 사용하면 아래와 같이 됩니다.


Third form of writing (optimal)

alert ($("div:jqmData(role=page)").html ());


여기서 value parameter는 "role=page" 입니다. data-role attribute (including any namespace)가 "page"<div> elements 를 get 하기 위함이죠.


만약 "role" string 만 사용한다면 data-role attribute가 있는 모든 <div> elements 들을 retrieve 할 겁니다.


All <div> elements with the data-role attribute set to any value

alert ($("div:jqmData(role)").length); // 3 elements: page, header, content


All <div> elements with the data-role attribute set to "page"

alert ($("div:jqmData(role=page)").length); // 1 element: page


반응형

Configuration Options

2012. 9. 29. 05:43 | Posted by 솔웅


반응형

Configuration Options



mobileinit event는 jQuery Mobile configuration options를 바꿀 수 있는 마지막 instant 입니다. 대부분의 옵션들에 대해 이 때 수정할 수 있습니다. 일부 이벤트들은 이 mobileinit event가 지나도 바꿀 수 있는 것들이 있습니다면 어쨌든 그 값들을 바꾸기 위해서는 항상 mobileinit event를 사용합니다. 만약 이 기간동안에 어떤 option의 값이 바뀌지 않으면 jQuery Mobile은 디폴트 값을 할당 합니다.


대부분의 이 option들은 jQuery Mobile에 의해 attribute들로 정의 됩니다.  예를 들어 data-icon, data-transition, data-back-btn-text, etc.. 같은 것 들이죠. HTML 코드에 이 attribute 값들이 정의되어 있지 않다면 디폴트 값이 할당 됩니다. 이 디폴트 값들이 mobileinit event이 진행되는 동안에 수정되어 질 수 있는 값들입니다.


General options


이 option들은 $.mobile object의 프로퍼티들입니다. 예를 들어 ns option은 $.mobile.ns 로 연결 되는 식이죠.


General options


Option

Signification

ns

Defines the namespace (see next section). Default "" (no namespace).

activePageClass

CSS class added to the <div> defining the window when it becomes active. Default "ui-page-active".

ajaxEnabled

Boolean indicating whether the HTML pages are retrieved by Ajax (if true) or not (if false). Default true. If the pages are not retrieved by Ajax, the previous windows are removed from the DOM.

defaultPageTransition

Default transition between two windows. Default "slide".

defaultDialogTransition

Default transition between two windows, one of which is superimposed. Default "pop".

loadingMessage

Message displayed to indicate that a HTML page is being loaded. Default "loading". This option can be changed outside the mobileinit event processing.

pageLoadErrorMessage

Message displayed to indicate an HTML page could not be loaded successfully. Default "Error Loading Page".

autoInitializePage

Boolean indicating if we let jQuery Mobile make himself the first window display. If true (default) the $.mobile.initializePage () is automatically called by jQuery Mobile allowing to display the first window. If false, it will be in our program to do this first viewing (calling ourselves the $.mobile.initializePage ()).


Options managing windows


이 옵션들은  $.mobile.page.prototype.options의 프로퍼티 들입니다. 예를 들어 backBtnText option은  $.mobile.page.prototype.options.backBtnText로 연결 되는 식이죠


Options managing windows


Option

Signification

backBtnText

Sets the text displayed on the Back button. Default "Back".

addBackBtn

Boolean indicating whether the Back button will be displayed in the window. Default false (not displayed).

backBtnTheme

Theme ("a", ..., "e") associated with the Back button. Default null, indicating to use the theme of the enclosing element.

keepNative

Selector specifying the HTML elements that should not be changed by jQuery Mobile into another HTML code. By default those whose data-role attribute is "none" or "nojs".

domCache

Boolean indicating whether the window should be stored in the DOM tree after it is no longer visible. This option only manages the windows that are not already present in the HTML page, ie those recovered by jQuery Mobile via Ajax. Default false (the windows loaded later are removed from the DOM when they become hidden).

theme

Theme ("a", ..., "e") associated with the window. Default "c".

headerTheme

Theme ("a", ..., "e") associated with the title bar. Default "a".

footerTheme

Theme ("a", ..., "e") associated with the bar at the bottom of page. Default "a".

contentTheme

Theme ("a", ..., "e") associated with the contents of the window. Default "".


Options managing lists


이 옵션들은 $.mobile.listview.prototype.options의 프로퍼티들입니다. theme option 같은 경우엔 $.mobile.listview.prototype.options.theme 이런 식으로 사용하시면 됩니다.


Options managing lists


Option

Signification

initSelector

Selector for finding lists in the HTML page. Default "jqmData (role='listview')".

theme

Theme ("a", ..., "e") associated with list items. Default "c".

countTheme

Theme ("a", ..., "e") associated with HTML elements with "ui-li-count" CSS class. Default "c".

dividerTheme

Theme ("a", ..., "e") associated to list items with the data-role="list-divider" attribute. Default "b".

filterTheme

Theme ("a", ..., "e") associated with the search field in the list.

inset

Boolean indicating whether the lists should be displayed with rounded edges. Default false.

filter

Boolean indicating whether to display a search field for list items. Default false.

filterPlaceHolder

String displayed in the search field of a list with the attribute data-filter="true". Default "Filter items ...".


Options managing navigation bars


이 옵션들은 $.mobile.navbar.prototype.options의 프로퍼티 들입니다. iconpos option 같은 경우엔 $.mobile.navbar.prototype.options.iconpos 이런 식으로 사용하시면 됩니다.


Options managing navigation bars


Option

Signification

initSelector

Selector for finding navigation bars in the HTML page. Default "jqmData (role='navbar')".

iconpos

Indicates the position of the icon ("top", "right ","bottom","left") when present in the buttons on the navigation bar. By default "top".

grid

Specifies the maximum number of buttons that may appear in a line of the navigation bar ("a" for 2 buttons max, "b" for 3, "c" for 4 and "d" for 5. By default null, indicating the place buttons at best.


Options managing buttons


이 옵션들은 $.mobile.button.prototype.options의 프로퍼티 들입니다. theme option 같은 경우엔 $.mobile.button.prototype.options.theme이런식으로 사용하

Warning: 이 옵션들은 button() method 를 사용해서 버튼을 생성하면 해당 account 에 적용 됩니다.


Options managing buttons


Option

Signification

initSelector

Selector for finding buttons in the HTML page. Default "button, [type='button'], [type='submit'], [type='reset'], [type='image']".

theme

Theme ("a", ..., "e") associated with buttons. Default null, indicating to use the theme associated with the enclosing element.

icon

Icon associated with buttons. Default null (no icon).

iconpos

Position of the icon in buttons, when present. Default "left".

inline

Boolean indicating whether the width of the button adapts to its contents (if true), or falls of the width of the window (if false). Default false.

corners

Defines if the buttons have rounded edges (if true) or rectangular (if false). Default true (rounded edges).

shadow

Boolean indicating whether a shadow is associated with buttons. Default true (shaded buttons).

iconshadow

Boolean indicating whether a shadow is associated with the icons on the buttons. Default true (has shadow).


Options managing input fields


이 옵션들은 $.mobile.textinput.prototype.options의 프로퍼티 들입니다. theme option의 경우 $.mobile.textinput.prototype.options.theme이렇게 사용하시면 됩니다.


Options managing input fields


Option

Signification

initSelector

Selector for finding input fields in the HTML page. Default "input[type='text'], input[type='search'], :jqmData(type='search'), input[type='number'], :jqmData(type='number'), input[type='password'], input[type='email'], input[type='url'], input[type='tel'], textarea".

theme

Theme ("a", ..., "e") associated with input fields. Default null, indicating to use the theme associated with the enclosing element.


Options managing checkboxes and radio buttons


이 옵션들은 $.mobile.checkboxradio.prototype.options의 프로퍼티 들입니다. theme option의 경우 $.mobile.checkboxradio.prototype.options.theme 이렇게 사용하시면 됩니다.


Options managing checkboxes and radio buttons


Option

Signification

initSelector

Selector for finding checkboxes and radio buttons in the HTML page. Default "input[type='checkbox'], input[type='radio']".

theme

Theme ("a", ..., "e") associated with checkboxes and radio buttons. Default null, indicating to use the theme associated with the enclosing element.



Options managing selection list



이 옵션들은 $.mobile.selectmenu.prototype.options의 프로퍼티 들입니다. theme option의 경우 $.mobile.selectmenu.prototype.options.theme 이렇게 사용하시면 됩니다.


Options managing selection lists


Option

Signification

initSelector

Selector for finding selection lists in the HTML page. Default "select:not(:jqmData( role='slider'))".

theme

Theme ("a", ..., "e") associated with elements of the selection list. Default null, indicating to use the theme associated with the enclosing element.

icon

Icon in the button associated with the selection list. Default "arrow-d" (arrow down).

iconpos

Position of the icon in the button associated with the selection list ("top", "rght", "bottom", "left"). Default "right".

inline

Boolean indicating whether the button for the selection list adjusts in width to its contents (if true) or spreads over the width of the window (if false). Default false.

corners

Defines if the buttons associated with the selection lists have rounded edges (if true) or rectangular (if false). Default true (rounded edges).

shadow

Boolean indicating whether a shadow is associated with the buttons associated with selection lists. Default true (shaded buttons).

overlayTheme

Theme ("a", ..., "e") associated with the border around the elements of the selection list. Default "a".

nativeMenu

Boolean indicating whether the selection list is displayed natively (if true) or so improved by jQuery Mobile (if false). Default true (selection list displayed natively).


Options managing sliders


이 옵션들은 $.mobile.slider.prototype.options의 프로퍼티 들입니다. theme option의 경우 $.mobile.slider.prototype.options.theme 이렇게 사용하시면 됩니다.


Options managing sliders


Option

Signification

initSelector

Selector for finding sliders in the HTML page. Default "input[type='range'], :jqmData(type='range'), :jqmData(role='slider')".

theme

Theme ("a", ..., "e") associated with the cursor moves on the slider. Default null, indicating to use the theme associated with the enclosing element.

trackTheme

Theme ("a", ..., "e") associated with the axis on which the cursor moves. Default null, indicating to use the theme associated with the enclosing element.


Options managing accordion menus


이 옵션들은 $.mobile.collapsible.prototype.options의 프로퍼티 들입니다. theme option 의 경우 $.mobile.collapsible.prototype.options.theme 이렇게 사용하시면 됩니다.


Options managing accordion menus


Option

Signification

initSelector

Selector for finding accordion menus in the HTML page. Default ":jqmData(role='collapsible')".

theme

Theme ("a", ..., "e") associated with the accordion menu. Default null, indicating to use the theme associated with the enclosing element.

iconTheme

Theme ("a", ..., "e") associated with the icons in the accordion menu. Default "d".

collapsed

Boolean indicating whether the menu should be closed or open at startup. Default true (closed menu).


반응형


반응형


jQuery Mobile initialisation



자바스크립트로 jQuery Mobile file을 include 하면 in it 이 실행 됩니다.  그리고 $.mobile object 가 생성되죠. $.mobile object 는 이전 글에서 보셨듯이 method들과 프로퍼티들을 가지고 있습니다. 그리고 다양한 객체들에 디폴트 값들이 할당되게 되죠. 예를 들어

  • The text on the Back button.

  • The CSS theme associated with this button ("a" to "e").

  • The icon displayed by default in the selection lists (ie set to arrow-d by default).

  • Etc..


이 옵션들에 대한 디폴트 값들은 바꿀 수 있습니다. 그런데 아무때나 바꿀 수 있는 것은 아니고 처음 시작될 때 특정 기간 안에 바꾸도록 해야 합니다. 그 기간을 놓쳐 버리면 그 디폴트 값들을 바꿀 수 있는 시간을 놓쳐 버리게 됩니다. 그 한정된 기간은 document object에 의해 mobileinit 이벤트가 reveived 될 때 시작합니다. 그러니까 우리는 이 이벤트의 treatment 내에 jQuery Mobile configuration option들의 디폴트 값을 바꿀 수가 있ㅅ브니다. 이 configuration option들에 대해서는 다음 글에서 다루겠습니다.

Let's see how to handle the mobileinit event:

그럼 어떻게 이 mobileinit 이벤트를 다루는지 볼까요?


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

    $(document).bind ("mobileinit", function ()

    {

      alert ("mobileinit");

    });

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


$(document).ready (function ()

{

  alert ("DOM ready");

});


</script>



mobileinit 이벤트를 핸들링하는 코드 블럭의 위치를 잘 보세요. 이 코드는 반드시 jQuery Mobile Javascript 소스 (jquery.mobile-1.1.1.min.js, jquery.mobile.js ...) 를 넣기 전에 있어야 합니다. 만약 이 소스 다음에 mobileinit을 넣으면 jQuery Mobile은 mobileinit을 trigger는 하지만 그 코드를 위치한 그곳에서 그 trigger 가 일어나지 않습니다.

즉 위 코드에서 보면 alert 가 일어나지 않게 됩니다.



convention02.html



위 파일을 실행시켜 보면 mobileinit alert 가 먼저 뜨고 그 다음에 DOM ready alert 가 뜰 겁니다. 즉 mobileinit 이벤트가 먼저 실행 되고 나서 DOM 이 준비 된다는 얘기죠.






반응형


반응형

$.mobile object



오늘은 단순히 JQM을만이 아니라 Javascript로 동적으로 프로그래밍 하는 부분을 간단히 공부해 보겠습니다.


우선 기본 <html> 소스부터 봅니다.


<!DOCTYPE html>
<html>
<head>
  <meta name=viewport content="user-scalable=no,width=device-width" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
  <style type=text/css>
    p {
      font-style : italic;
      margin-bottom : 0px;
      text-align : center;
      text-transform : uppercase;
    }
  </style>
</head>

<body>
<div data-role=page id=home>
  <div data-role=header>
    <h1>Home</h1>
  </div>
  <div data-role=content>
  </div>
</div>
</body>

</html>


보면 헤더에 Home 이라는 글자가 있고 content는 있는데 그 안에는 아무런 내용이 없죠.

그리고 body 안에 보면 <p> 태그는 하나도 없는데 위에 <p> 태그에 적용되는 스타일링이 정의 돼 있습니다.


딱 보면 content 부분에 뭘 넣을 건데 거기에 <p> 태그가 들어가나 보네요.

하여간 위의 소스로 html을 만들어서 실행시키면 아래 화면을 보실 수 있습니다.




그럼 이제 자바 스크립트 부분을 볼까요?

이 JavaScript 는  </html> 다음에 붙여 넣습니다.


<script>

var $content = $("[data-role=content]");
var obj = $.mobile;

$content.append ("<p> Properties </p>");
for (var prop in obj)
  if (!$.isFunction (obj[prop])) $content.append (
          "<b>" + prop + "</b>  = " + obj[prop] + "<br />");

$content.append ("<p> Methods </p>");
for (var prop in obj)
  if ($.isFunction (obj[prop])) $content.append (
          "<b>" + prop + "</b>  () " + "<br />");

</script>


불까요? 변수 $content에 data-role=content를 넣었습니다.

그리고 obj라는 변수에는 $.mobile; JQM 함수를 넣었습니다.


그 다음을 보면 $content 에 문자를 append 하죠?

즉 data-role=content에 문자를 append 하는 겁니다.


그리고 $.mobile 에 있는 prop 들을 화면에 출력하는 for 문이 있습니다.


그 다음에는 $content에 Methods 라는 문자를 추가 합니다.


그리고 $.mobile에 있는 메소드들을 출력합니다.


그러면 아래와 같은 화면을 보실 수 있을 겁니다.



화면에 보시는 것들이 바로 $.mobile object에 세팅돼 있는 프로퍼티들 입니다.


저 프로퍼티들과 메소드들을 다 알 필요는 없지만 그래도 자주 쓰이는 것들은 눈에 익어야 될 텐데요.


꾸준히 그리고 많이 Practice를 하는 방법밖에는 없겠죠?



convention01.html


반응형


반응형

Layout Grid


여러 컬럼을 가진 레이아웃을 사용하는 것은 모바일 기기쪽에서는 별로 권장되지 않는 방법입니다. 화면 크기가 작기 때문이죠. 하지만 작은 것들을 차례대로 좌우로 표시해야 될 때가 있습니다. (버튼이나 탭같은...)

jQuery Mobile framework은 CSS-based 컬럼들을 만드는 간단한 방법을 제공하고 있습니다. ui-grid 클래스를 call 하면 block 스타일 컬럼을 만들 수있습니다.


  • two-column (using the ui-grid-a class)
  • three-column (using the ui-grid-b class)
  • four-column (using the ui-grid-c class)
  • five-column (using the ui-grid-d class)


Grid는 100% width 에다 border나 배경이 없어서 보이지 않습니다. 그리고 padding이나 margin도 없죠. 그래서 그 안에 어떤 style과 함께 서로 간섭할 수가 없습니다.

Grid 콘테이너에는 ui-block-a/b/c/d/e 라는 child element들이 할당됩니다. 각 block element들을 side-by-side로 정렬하도록 만드는 거죠. ui-block-a 는 새로운 줄을 시작할 때 사용할 수 있습니다.


Two column grids


2개의 컬럼이 있는 레이아웃을 만드려면 ui-grid-a 클래스를 div에 넣습니다. 그리고 그 안에 두개의 child 콘테이너를 넣는데요. ui-block-a 는 첫번째 컬럼이 되고 ui-block-b 는 두번째 컬럼이 됩니다.


<div class="ui-grid-a">
	<div class="ui-block-a"><strong>I'm Block A</strong> 
and text inside will wrap</div> <div class="ui-block-b"><strong>I'm Block B</strong>
and text inside will wrap</div> </div><!-- /grid-a -->


위 예제를 실행하면 아래처럼 보일 겁니다.


I'm Block A and text inside will wrap.      I'm Block B and text inside will wrap.


위에서 보듯이 grid block은 디폴트로 아무런 visual styling이 없습니다. 단지 그 내용을 side-by-side로 보여 줄 뿐입니다.


Grid 클래스는 어떤 컨테이너에든지 apply 될 수 있습니다. 다음 예제에서는 ui-grid-a 를 fieldset에 넣을 겁니다. 그리고 두개의 버튼의 컨테이너 안에 각각 ui-block classes 를 넣을 거구요. 이 두개의 버튼들은 나란히 화면의 50%를 차지하게 될 겁니다.


<fieldset class="ui-grid-a">
	<div class="ui-block-a"><button type="submit" data-theme="c">
Cancel</button></div> <div class="ui-block-b"><button type="submit" data-theme="b">
Submit</button></div> </fieldset>




framework은 그리드 안에서 버튼들에 각각 왼쪽, 오른쪽 마진을 넣게 됩니다. 버튼이 한개라면 class ui-grid-solo 를 사용하고 버튼에 ui-block-a 를 추가하면 됩니다. 그러면 이 버튼은 위의 두 버튼과 동일한 마진을 갖게 될 겁니다. 아래처럼요.


<div class="ui-grid-a">
	<div class="ui-block-a"><button type="button" data-theme="c">
Previous</button></div> <div class="ui-block-b"><button type="button" data-theme="c">
Next</button></div> </div> <div class="ui-grid-solo"> <div class="ui-block-a"><button type="v" data-theme="b">More</button></div> </div>





grid를 포함해서 theme 클래스를 추가할 수도 있습니다. 아래에 우리는 두개의

클래스를 추가했습니다. 
ui-bar클래스를 추가함으로서 default bar 패딩이 추가 됐고 ui-bar-e를 추가함으로서 
e 툴바 theme swatch에 background gradient와 폰트 스타일을 적용했습니다.
inline style="height:120px" attribute 도 각 grid에 추가해서 각 grid에 높이를
주었습니다.



소스는 이 글 마지막에 올린 샘플 파일을 참조하세요.


Three-column grids


다른 grid 레이아웃은 parent에 class=ui-grid-b 를 사용해서 만들 수 있습니다. 이렇게 하면 3개의 child 콘테이너 element들을 만들게 됩니다. 3개의 child는 각각 ui-block-a/b/c class를 갖게 됩니다. 그러면 각각 33%의 width를 갖는 grid가 나타날 겁니다. Note: 샘플 파일에는 style을 적용했습니다. 그래서 각 grid를 구분해 놔서 눈으로 확인 하실 수 있으실 겁니다.


<div class="ui-grid-b">
	<div class="ui-block-a">Block A</div>
	<div class="ui-block-b">Block B</div>
	<div class="ui-block-c">Block C</div>
</div><!-- /grid-b -->






각 grid 안에 버튼을 넣을 수도 있습니다. (샘플파일 참조)




Four-column grids


25/25/25/25% grid 로 4개의 컬럼을 만들 수있는데 이것은 parent에 class=ui-grid-c를 넣어서 만들 수 있습니다.



Five-column grids


20/20/20/20/20% 이렇게 5개의 컬럼은 class=ui-grid-d 로 만들 수 있습니다.




Multiple row grids


여러줄로 된 grid를 만들 수도 있습니다. 예를 들어 3개 컬럼 grid를 container에 지정하고 (ui-grid-b) 그 안에 9개의 child block이 있다고 생각해 봅시다. 그러면 각 블럭들이 3줄로 표시 될 겁니다. 한 줄을 끝내고 다른 줄을 시작하기 위해 CSS 룰을 따라야 합니다. class=ui-block-a 는 새로운 줄을 시작하는 신호가 될 겁니다. (a, b, c, a, b, c, etc.) 이렇게 반복하면 여러줄을 만들 수 있습니다.

자세한 것은 샘플 파일을 참조하세요.



Grids in toolbars


Grid는 툴바에 layout을 만드는데 유용하게 활용할 수 있습니다. 아래는 footer에 4개의 컬럼을 가진 grid를 넣어서 활용한 예입니다. 소스는 샘플파일을 참조하세요.




layoutGrid.html




반응형

JQuery Mobile - Basic HTML Styles

2012. 8. 14. 20:42 | Posted by 솔웅


반응형

HTML Formatting


jQuery Mobile에서 content를 styling 하는 기본 접근 방법은 아주 간단합니다. 손쉬운 방법을 사용하죠. 우리의 목표는 브라우저의 native rendering이 우선하도록 한다 입니다. 저희는 그냥 좀 더 읽기 편하도록 약간의 padding만 추가 합니다. 그리고 폰트 family와 색을 적용하기 위해 theming system를 사용합니다.

content styling을 하는 손쉬운 방법을 사용하면 디자이너나 개발자에게 아주 복잡한 style들을 분석하고 수정하도록 하는 대신 간단하고 깨끗한 clean slate를 제공하죠.



Default HTML markup styling


디폴트로 jQuery Mobile themes는 headers, paragraph content, block quotes, anchor links, standard ordered, unordered and definition lists, and tables 같은 표준 markup element들을 위한 스탠다드 HTML style과 size를 사용합니다. 아래에 그 예제들이 있습니다.



H1 Heading

H2 Heading

H3 Heading

H4 Heading

H5 Heading
H6 Heading


이것들은 strong, emphasized 그리고 linked text를 가지고 있는 paragraph 입니다. 아래에 좀 더 많은 text 가 있습니다. 여러분들은 어떻게 HTML markup이 content내에서 역할을 하는지 보실 수 있을 겁니다.


How about some blockquote action with a cite


This is another paragraph of text so you can see how HTML markup works in content. This is another paragraph of text so you can see how HTML markup works in content. This is another paragraph of text so you can see how HTML markup works in content.


저희는 테이블과 fieldset들에 좀 더 가독성 있도록 하기 위해 몇개의 style들을 추가했습니다. 이것들은 또한 쉽게 customs style들에 의해 override 될 수 있습니다.


  • Unordered list item 1
  • Unordered list item 1
  • Unordered list item 1
  1. Ordered list item 1
  2. Ordered list item 1
  3. Ordered list item 1

Definition term
I'm the definition text
Definition term
I'm the definition text

Travel Itinerary

Flight: From: To:
Total: 3 flights
JetBlue 983 Boston (BOS) New York (JFK)
JetBlue 354 San Francisco (SFO) Los Angeles (LAX)
JetBlue 465 New York (JFK) Portland (PDX)


반응형

JQuery Mobile - Theming buttons

2012. 8. 14. 05:39 | Posted by 솔웅


반응형


Theming buttons



jQuery Mobile은 아주 훌륭한 theming system 을 가지고 있습니다. 이  시스템을 이용하면 어떻게 버튼을 style 할 지 정한 후 쉽게 그것을 구현할 수 있도록 도와줍니다.

container에 link가 add 되면 버튼 안의 텍스트 색은 자동적으로 그 버튼 bar나 content box의 색에 따라 시각적으로 구별될 수 있는 색으로 할당 됩니다.  버튼이 theme a 가 적용된 container에 위치되게 되면 버튼의 색은 자동적으로 theme a 가 됩니다. 





Assigning theme swatches


버튼 markup에 data-theme attribute를 추가하면 원하는 button color swatch를 적용할 수 있습니다.

			
<a href="index.html" data-role="button" data-theme="a">Swatch a</a>			


아래에 data-theme attribute를 통해 assign된 여러 버튼이 있습니다.






Theme variations


Swatch "a" on container with themed buttons inside



ButtonThemes.html


반응형

JQuery Mobile -Grouped buttons

2012. 8. 14. 05:17 | Posted by 솔웅


반응형

Grouped buttons



가끔 몇개의 버튼을 시각적으로 그룹화 해서 한 block 에 넣어야 할 때가 있습니다. 


이런 효과를 주기 위해서는 그 버튼들의 set를 container에 wrap 하시면 되고 방법은 data-role="controlgroup" attribute를 이용하시면 됩니다. 그러면 framework는 vertical 버튼 그룹을 생성할 겁니다.


그리고 버튼들 사이의 margin이나 그림자 효과 같은 것을 없애게 되고 첫번째와 마지막 버튼에만 round 효과를 줍니다. 그러면 하나의 그룹안에 있는 버튼들이라는 시각적인 효과를 주게 되죠.



<div data-role="controlgroup">
<a href="index.html" data-role="button">Yes</a>
<a href="index.html" data-role="button">No</a>
<a href="index.html" data-role="button">Maybe</a>
</div>



디폴트로 그룹화된 버튼들은 vertical list로 보여 집니다.





data-type="horizontal" attribute를 controlgroup container에 추가하면 버튼들이 한 줄에 나란히 놓여지면서 그룹화 되는 horizontal-style group을 만들 수 있습니다. 버튼의 크기는 안의 텍스트 크기에 맞게 설정 됩니다. (버튼의 수가 너무 많거나 텍스트가 아주 길 경우 여러 줄로 표시 될 수도 있습니다.)




GroupedButtons.html


반응형

JQuery Mobile - inline buttons

2012. 8. 13. 20:50 | Posted by 솔웅


반응형


Inline buttons


디폴트로 body 내에 있는 모든 버튼들은 block-level element 로 스타일 돼 있습니다. 그래서 전체 화면 width를 꽉 채우게 되죠.




그런데 버튼 안의 텍스트 만큼만 버튼 크기를 만들고 싶을 때가 있습니다. 그럴 경우 버튼에 data-inline="true" attribute를 추가해 주시면 해결하실 수 있습니다.




좌우로 이어지는 여러개의 버튼이 있으면 data-inline="true" attribute를 각각의 버튼에 모두 추가하세요. 그렇게 하면 버튼크기는 버튼 안의 텍스트 크기만큼 정해 질겁니다. 그리고 버튼들이 같은 줄에서 좌우로 정렬 될 겁니다.


<a href="index.html" data-role="button" data-inline="true">Cancel</a>
<a href="index.html" data-role="button" data-inline="true" data-theme="b">Save</a>


결과는 아래와 같습니다.





inline 버튼에 data-mini="true" 를 추가하면 좀 더 compact 한 버전의 버튼이 생성됩니다.




만약 버튼이 한줄에 나란히 표시 되면서도 width를 screen 크기만큼 차지하도록 하고 싶다면 content column grids를 사용해서 화면의 컬럼을 2개 또는 3개 만드신 후 일반적인 full-width 버튼을 사용하시면 됩니다.


Icon example

inline 버튼에 icon이 추가되면 그 버튼은 그 아이콘 크기만큼 사이즈가 조금 더 커질 겁니다.


mini 버전도 같습니다.





inlineButtons.html


반응형