반응형
반응형
사용자 정의 플러그인으로 jQeury 확장하기

jQuery를 사용하면 페이지에 특정코드 스타일을 사용하게 되는데, 엘리먼트를 확장 집합의
형태로 표현하고 jQuery 커맨드나 커맨드체인을 확장 집합에 사용하는 코드 스타일을 자주 쓰게 된다. 물론 자신만의 코드를 작성할 때는 마음대로 코드를 작성할 수 있다.

자신만의 코드를 패턴화하여 jQuery 확장으로 만들면 좋은 이유는 사이트 전체에 일관된 코드 스타일을 유지하는데 도움을 주고, 재사용이 가능하며, jQuery 가 제공하는 기반코드를 확용할 수 있다.

플러그인이 다른 jQuery 플러그인이나 자바스크립트 라이브러리와 충돌하지 않고 잘 동작하는지가 확실하게 보장되기 위해 알려진 일반적인 지침을 사용한다.

이름을 충돌하지 않도록 만드는 방법은
* 접두어로 jquery. 를 사용한다.
* 이어서 플러그인 이름을 적는다.
* .js 로 파일 이름을 끝맺는다.
예를 들어서 jquery.ngio.js

 그리고, jQuery 대신 $ 를 사용하는 편이 훨씬 편한데, 충돌을 피하기 위해 $ 대신 jQuery를
사용하는 것이다.  하지만 $ 쪽이 훨신 편리하기에 포기하고 싶지 않다.
그래서, $ 라는 매개변수를 정의한 함수에 jQuery를 전달하면  $는 함수 안에서 jQuery의 참조임이 보장된다.
(function($) {
//
//
//  여시에 플러그인을 정의한다.
//
})(jQuery);'

복잡한 매개변수 목록을 단순하게 만들기.
플러그인은 대부분 매개변수를 몇 개만 요구할 정도로 단순하다. 선택적인 매개변수가 생략되면 적절한 기본값이 제공되며,매개변수가 생략되면 매개변수의 순서에 내포된의미도 변경된다.

    function complex(p1,p2,p3,p4,p5){
이 함수는 매개변수가 5개인데, 이 중에 첫 매개변수를 제외한 모든 매개변수가 선택사항일 경우, 선택적인 매개변수가 너무 많다면 매개변수가 생략되었을 때 호출자의 의도를 합리적으로 추측하기가 어려워진다. 이 함수의 호출자가 마지막 매개변수만 생력했다면 마지막 선택적 인수를 null 값으로 확인할수 있기 때문에 문제되지 않지만,
but 호출자가 p5를 명시하고 p2~p4 까지는 기본값으로 지정하고 싶은 경우엔 호출자는 생략된 매개변수 부분에 생략표시를 하고 다음과 같이 작성해야 한다.
     complex(valueA, null, null, null, valueB);

위와 같은 경우 null 과 매개변수의 순서를 주의깊게 봐야하는 단점이 있다.
일반적으로 이러한 문제를 해결하는 데 선택사항의 해기(option hash)를 많이 사용한다.
 선택사항의 해시를 사용하면 선택적인 매개변수 정보를 이름/값 쌍 형식의 프로퍼티로
가지는 자바스크립트의 Object 인스턴스로 전달한다.
    complex( valueA, { p5:valueB } );
  또는
    comlplex( valueA, {
       p3 : valueC,
       p5 : valueD
    } );

위와 같은 방법을 사용하면 null을 사용하여 생략된 매개변수를 표시할 필요가 없고 매개변수의 개수를 세지 않아도 된다.
필수 매개변수 하나와 선택항목을 여섯 개 가진 복잡한 함수 예제를 다시 살펴보자
    complex(p1, options)
함수 내에서 $.extend() 유틸리티 함수를 사용해 기본값에 전달된 옵션을 합칠 수 있다.
    function comlex( p1, options ){
        var settings = $.extend({
            option1: defaultValue1 ,
           option2: defaultValue2 ,
           option3: defaultValue3 ,
           option4: defaultValue4 ,
           option5: defaultValue5 ,
           option6: defaultValue6 
         , options || { } );
         // 함수의 나머지 부분
    }
settings 변수는 페이지 개발자가 options 매개변수로 전달한 값과 기본값을 합친 값을 가진다. 주목할 점은 ||{}를 사용하여 options 객체가 null이거나 undefined 인지를 확인하고 있다는 것이다. 만약 options 변수가 false라면 (null과 undefined는 조건식에서 false이다) 빈 객체가 사용된다.

ex)
 $.say = function(what) { alert( 'I say ' + what ); }

jQuery.say = function(what) { alert( 'I say ' + what ); }

(function($) {
    $.say = function(what) { alert( 'I say ' + what ); }
}) (jQuery);

## 데이터를 조작하는 유틸 함수 만들기
고정폭으로 숫자 값을 표시하려면 숫자 값과 고정폭 필드(폭은 문자의 수로 정의)에 맞는 형식이 필요하다. 대개 이러함 형식은 값을 고정폭 필드에 우측 정렬시키고 값의 길이와 필드의 길이 차이를 조정하기 위해 채움 문자( fill character )로 앞 여백을 채운다.

함수 문법 : $.toFixedWidth
$.toFixedWidth( value, length, fill )
 : 매개변수 - value (Number) 형식화될 값
                   - length (Number) 결과 필드의 길이
                   - fill (String) 앞 단의 값을 채울 채움 문자, 생략하면 0을 사용한다.

(function($){
    $.toFixedWidth = function( value, length, fill ){
        var result = value.toString();
        if( !fill ) fill = 0;
        var padding = length - result.length;
        if( padding < 0 ){
            result = result.substr(-padding);
        }
        else{
            for(var n = 0; n < padding; n++)
                result = fill + result;
        }
        return result;
    };
})(jQuery);






반응형
반응형

jQuery Alert Dialogs (Alert, Confirm, & Prompt Replacements)

http://abeautifulsite.net/blog/2008/12/jquery-alert-dialogs/

Overview

This jQuery plugin aims to replace the basic functionality provided by the standard JavaScript alert(), confirm(), and prompt() functions. What’s the benefit of using custom methods? Well, a few good reasons, really.

Implementation

Include the following in the <head> section of your HTML document(s):

<!-- Dependencies -->
<script src="/path/to/jquery.js" type="text/javascript"></script>
<script src="/path/to/jquery.ui.draggable.js" type="text/javascript"></script>
<!-- Core files -->
<script src="/path/to/jquery.alerts.js" type="text/javascript"></script>
<link href="/path/to/jquery.alerts.css" rel="stylesheet" type="text/css" media="screen" />

Make sure you update the path to the respective files. If you are already using the jQuery UI Draggable plugin (including the UI core), simply omit the link to jquery.ui.draggable.js.

For IE to display the dialogs properly, you’ll also need to make sure that you’re using Standards Mode.  Just add the appropriate DTD at the very top of your page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Usage

This plugin utilizes the $.alerts namespace, but there are three built-in shortcut functions that make implementation easier:

  • jAlert(message, [title, callback])
  • jConfirm(message, [title, callback])
  • jPrompt(message, [value, title, callback])

Unlike their native JavaScript counterparts, you can use HTML in the message parameter. To specify a newline, you can use either \n or <br />.

These methods do not return the same values as confirm() and prompt(). You must access the resulting values using a callback function. (See the demo for more details.)

Compatibility

This plugin requires jQuery 1.2.6 or above and has been tested to work in the following browsers:

  • Internet Explorer 6 & 7
  • Firefox 2 & 3
  • Safari 3
  • Chrome
  • Opera 9

Known Issues

  • ENTER and ESC keys (to accept/cancel) don’t work in WebKit browsers
  • The draggable plugin doesn’t currently work in Opera
  • IE6 acts a bit differently as position: fixed isn’t supported.
반응형
반응형
jQuery는 HTML 문서, 보다 정확하게는 문서 개체 모델(DOM)과 자바스크립트 사이의 상호작용을 간단하게 해주는 오픈 소스 자바스크립트 라이브러리이다.

jQuery는 오픈소스이고, 작으며(최소화버전 18KB),  웹브라우저 간의 차이를 표준화하고, 깔끔한 플러그인 아키텍처를 사용하여 경량으로 제작되었고, 플러그인의 자료실(http://plugin.jquery.com)은 광범위하며, 출시 이후 꾸준히 성장하고 있다.
API는 인라인 코드 예제를 포함하여 완전하게 문서화되어 있고, 몇년동안이나 훌륭하게 유지되고 있으며, 상당히 친화적(다른 자바스크립트 라이브러리와의 충돌을 피하는 여러방법을 제공한다. ) 이다.
커뮤니티 지원은 여러 메일링 목록, IRC 채널 그리고 jQuery 커뮤니티의 수 많은 튜토리얼, 아티클, 그리고 플로그의 포스트들을 포함하기에 실제로 꽤 유용하다.
공개적으로 개발되고 있으며, jQuery 개발팀이 업데이트에 대한 출시를 두려워하지 않기 때문에 꾸준하고 일관적이다.
큰 조직(예를 들어 Microsoft, Dell, CBS...)에서 jQuery를 사용하는 것은 꾸준히 늘어날 것이며, 오래도록 지속될 것이다.
브라우저보다도 앞서 W3C의 명세를 수용하고 있다. 일례로 CSS3 셀렉터의 대부분을 지원한다.
최신 브라우저에서 개발을 위한 테스트 및 최적화를 수행하였다.
개발자뿐만 아니라 디자이너에게도 상당히 강력하다. 차별적이지 않다.
자바스크립트의 작성 방식을 바꾸고 있는 jQuery의 간결함, 방법론 그리고 철학은 그 자체가 표준이 되어가고 있다.

jQuery 철학
- "Write less, do more(적게 작성하고, 보다 많이 한다. )"
* 몇몇 요소를 찾아서 (CSS Selector 를 이용해서)  그들로 어떤 작업을 수행한다.(jQuery 메서드를 사용하여).
* 요소의 집합에 대해 여러 jQuery  메서드를 체인으로 연결한다.
* jQuery 래퍼와 암시적인 반복을 사용한다.
반응형
반응형

Definition and Usage

The ctrlKey event attribute returns a Boolean value that indicates whether or not the "CTRL" key was pressed when an event was triggered.

Syntax

event.ctrlKey=true|false|1|0


<html>
<head>
<script type="text/javascript">
function isKeyPressed(event)
{
if (event.ctrlKey==1)
  {
  alert("The CTRL key was pressed!");
  }
else
  {
  alert("The CTRL key was NOT pressed!");
  }
}

</script>
</head>
<body onmousedown="isKeyPressed(event)">

<p>Click somewhere in the document. An alert box will tell you if you pressed the CTRL key or not.</p>

</body>
</html>

반응형
반응형

loopedSlider


https://github.com/nathansearles/loopedSlider
http://slidesjs.com/

loopedSlider 0.5.7 – No longer in development

Check out the next version of loopedSlider, now called Slides https://github.com/nathansearles/Slides

loopedSlider is a plugin made for jQuery that solves a simple problem, the looping of slide content. It was created to be easy to implement, smooth and most of all end the “content rewind” that most other content sliders suffer from.


Info

Check out the next version of loopedSlider, now called Slides http://slidesjs.com

Developed by Nathan Searles, http://nathansearles.com

Complete instructions can be found at http://nathansearles.com/plugin/loopedslider/

For updates, follow Nathan Searles on Twitter

Examples

Markup

<div id="loopedSlider">
	<div class="container">
	        <div class="slides">
	                <div><img src="01.jpg" alt="" /></div>
	                <div><img src="02.jpg" alt="" /></div>
	                <div><img src="03.jpg" alt="" /></div>
	                <div><img src="04.jpg" alt="" /></div>
	        </div>
	</div>
	<a href="#" class="previous">previous</a>
	<a href="#" class="next">next</a>
</div>

CSS

.container { width:500px; height:375px; overflow:hidden; position:relative; cursor:pointer; }
.slides { position:absolute; top:0; left:0; }
.slides div { position:absolute; top:0; width:500px; display:none; }

Initialize

<script type="text/javascript" charset="utf-8">
        $(function(){
                $('#loopedSlider').loopedSlider();
        });
</script>

Defaults

container: ".container", //Class/id of main container. You can use "#container" for an id.
slides: ".slides", //Class/id of slide container. You can use "#slides" for an id.
pagination: "pagination", //Class name of parent ul for numbered links. Don't add a "." here.
containerClick: true, //Click slider to goto next slide? true/false
autoStart: 0, //Set to positive number for true. This number will be the time between transitions.
restart: 0, //Set to positive number for true. Sets time until autoStart is restarted.
hoverPause: false, //Set to true to pause on hover, if autoStart is also true
slidespeed: 300, //Speed of slide animation, 1000 = 1second.
fadespeed: 200, //Speed of fade animation, 1000 = 1second.
autoHeight: 0, //Set to positive number for true. This number will be the speed of the animation.
addPagination: false //Add pagination links based on content? true/false

Defining Local Defaults

<script type="text/javascript" charset="utf-8">
        $(function(){
			$('#loopedSlider').loopedSlider({
				addPagination: true,
				slidespeed: 500
			});
        });
</script>

Defining Global Defaults

<script type="text/javascript" charset="utf-8">
        $(function(){
			$.fn.loopedSlider.defaults.addPagination = true;
			$.fn.loopedSlider.defaults.slidespeed = 500;
        });
</script>
반응형
반응형
Episode - 아이패드용 매거진 Pleiades Corp.
 [펌] 웹앱을 만드는 사람들의 모임

Native 가 아닌 HTML5/CSS3/jQuery 로 만든 저희 어플을 소개 합니다.

실력있는 디자이너분들과 다양한 시도를 하면서 이번호를 내게 되었습니다.


특집은 일본대지진에 관해서 다루었고,

그 이외에 일러스트아트, 미디어아트, 마린블루스. 등의 다양한 꼭지들로 컨텐츠가 구성되었습니다.


webview로 모든 컨텐츠를 보여주기에 제약사항도 많았고

아직 불안한 요소도 많지만 보시면서 냉정한 평가를 해주시면,

다음달에는 조금 더 나은 모습으로 만들 수 있을거라고 생각합니다.

http://itunes.apple.com/kr/app/id401413450?mt=8#

http://cafe.naver.com/webappdev.cafe?iframe_url=/ArticleRead.nhn%3Farticleid=4630&

---------------------------------------------------------

소개동영상

http://youtu.be/_UGFtnoYCsw
-------------------------------------------------------------------
주소링크!!!
http://itunes.apple.com/kr/app/id401413450?mt=8

설명

한국 최초의 아이패드 전용 잡지 입니다.


 새롭게 선보이는 매체인《EPISODE》의 모토는 새로움입니다. 터치 인터페이스라는 새로운 환경에 맞게 컨텐츠, UX, 컨텐츠와 독자와의 관계를 완전히 새롭게 재정의하고자 합니다. 한국을 넘어 아시아 시장에서 아이패드 컨텐츠의 선도적 역할을 해 나가는《EPISODE》가 되겠습니다.





이번호에서는 일본의 대재앙에 대해 살펴보고자 합니다. 데이터와 인포그래픽 그리고 아이패드에서만 가능한 UX를 통해 일본의 대재앙이 일본만의 문제가 아닌 전세계의 문제이며 바로 우리의 문제임을 알아보고자 했습니다. 


트위터에서 최고의 미디어 파워를 자랑하는 독설닷컴 고재열 시사인 기자와의 인터뷰 기사도 있습니다. 트위터와 인터넷에서 많은 논쟁을 통해 다듬어진 고재열 기자의 생각과 입장을 들어보시기 바랍니다.

특히 이번호는 디자인이 확 바뀌었습니다. 터치 인터페이스라는 새로운 매체에서 발행되지만 책 혹은 잡지의 기본을 다시 생각하며 디자인에 많은 신경을 썼습니다.


《EPISODE》는 앞으로도 꾸준하게 UX 분야에서의 실험을 진행할 예정입니다. 독자의 움직임에 반응하는 디자인, 사용자와 커뮤니케이션하는 컨텐츠, 그리고 밀도 있고 창조적인 새로운 형식의 미디어를 경험해보시기 바랍니다.


iPad 스크린샷 1
iPad 스크린샷 2
iPad 스크린샷 3
iPad 스크린샷 4
iPad 스크린샷 5
반응형

'프로그래밍 > Script' 카테고리의 다른 글

[javascript] Ctrl key  (0) 2011.06.27
[javascript] loopedSlider  (0) 2011.06.24
[javascript] Creating a Mobile Touch Slide Panel with JQuery  (0) 2011.05.19
[javascript] iScroll-js  (0) 2011.05.10
[jQuery] jquery - carousel  (0) 2011.05.10

+ Recent posts