달력

42024  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

--------------------------------------------------------------------------
ext-prototype-adapter 을 이용하여 prototype, Scriptaculous 사용하기
--------------------------------------------------------------------------

자세한 내용은 http://extjs.com/ 와 다운로드 받은 Examples 에서 봐야함
오늘은 맛보기만 ㅎㅎㅎㅎㅎ
--------------------------------------------------------------------------
테스트할 디렉토리 구조.

기본 테스트 디렉토리     ==>  d:\html\ext_test
JS 파일 디렉토리           ==>  d:\html\ext_test\common\js
CSS 파일 디렉토리        ==>  d:\html\ext_test\common\css
EXT-JS 이미지 디렉토리 ==>  d:\html\ext_test\common\images ,
                                          d:\html\ext_test\common\raw_images

1. http://script.aculo.us/downloads 에서 스크립타큘로스를 다운로드 받는다.(1.7 버전 이상)

압축을 풀면 아래와 같은 디렉토리 구조가 보인다.

----- lib  
  |-- src
  |-- test


lib 디렉토리에 있는 prototype.js 를 JS 파일 디렉토리에 복사한다.
src 에 있는 파일중 unittest.jsp 를 제외하고 JS 파일 디렉토리에 복사한다.


2. http://extjs.com/download 에서 ext-js 를 다운로드 받는다.

압축을 풀면 디렉토리가 여러개 있고 js 파일들도 보이는데 스크립타큘로스와 프로토타입을
사용할 것이기 때문에 필요한것만 복사한다.


ext-prototype-adapter.js
ext-all.js

위의 두 파일을 JS 파일 디렉토리에 복사한다.

다음으로 resource 디렉토리에 있는 images 와 raw-images 디렉토리를 common 디렉토리에 복사한다.


3. 첫번째 예제 작성

기본 테스트 디렉토리(d:/html/ext_test) 에 beginner_1.html 로 파일을 하나 만든다.

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

    <link rel="stylesheet" type="text/css" href="./common/css/ext-all.css">
    <link rel="stylesheet" type="text/css" href="./common/css/ytheme-aero.css">
    <style type="text/css">
     body {
       font-family: Tahoma,Arial,Helvetica,sans-serif;
       font-size:12px;
       color:#333;
       padding: 20px;
     }
    </style>

    <script type="text/javascript" src="./common/js/prototype.js"></script>
    <script type="text/javascript" src="./common/js/scriptaculous.js"></script>
    <script type="text/javascript" src="./common/js/ext-prototype-adapter.js"></script>
    <script type="text/javascript" src="./common/js/ext-all.js"></script>


 <script type="text/javascript" language="javascript">
 <!--
  Ext.onReady(function() {
   alert("테스트 합니다");
  });
  //-->
  </script>
 </head>

 <body>

  <input type="button" id="myButton" value="My Button" />
 
 </body>
</html>

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

위의 내용을 실행 했을 경우 ALERT 창이 뜨면 된것이다.

간단하게 버튼하나 만들어봅시다.

/*----  수정된 EXT.onReady()  시작                        -----*/
/*----  EXT.onReady() 안의 내용을 아래와 같이 수정 ---- */

 Ext.onReady(function() {
  var paragraphClicked = function(e) {  
    var paragraph = Ext.get(e.target);
    //paragraph.highlight();
    Ext.MessageBox.show({  
     title: '!!! 타이틀 !!!',  
     msg: '메세지 박스 입니다...',  
     width:800,
     buttons: Ext.MessageBox.OKCANCEL,  
     animEl: paragraph
    });
  }
 
  Ext.get('myButton').on('click', paragraphClicked);
 });
/*---- 수정된 EXT.onReady()  끝 -----*/

실행하면 ok / cancel 버튼이 있는 메세지 박스가 뜰것이다.


만약 클릭한 버튼이 어떤건지 알아내기 위해서는 아래와 같이 콜백함수를 지정하면 된다.


--------------------------------------------------------------------------
 Ext.onReady(function() {
  var paragraphClicked = function(e) {  
    var paragraph = Ext.get(e.target);
    //paragraph.highlight();
     Ext.MessageBox.show({  
     title: '!!! 타이틀 !!!',  
     msg: '메세지 박스 입니다...',  
     width:800,
     buttons: Ext.MessageBox.OKCANCEL,  
     
     animEl: paragraph,
     fn : showResult    
    });
  }
 
  Ext.get('myButton').on('click', paragraphClicked);


  function showResult(btn){
   alert("눌러진 버튼은 " + btn + " 입니다");
  };

 });
--------------------------------------------------------------------------

방대한 기능들을 자세히 다 알려면 시간좀 걸리겠군.

Posted by tornado
|
사용자 삽입 이미지


내용이 좋을것 같은 느낌 ^^

아래는 강컴에서 발췌한 도서소개 임

도서특징
Web 2.0 시대의 Ajax 애플리케이션 개발자, 설계자, 분석가를 위한 필독서 객체지향 Ajax 애플리케이션 구현 방법을 상세하게 제시 prototype.js 소스 코드 완전 분석
Ajax는 그 자체는 물론이고 Web 2.0 실현의 초석이 된다. 이 책은 이런 시대적 흐름을 주도하고 미래 지향적인 개발자, 설계자, 분석가의 요구를 충족시키기 위해 쓰여졌다.

객체지향 방법으로 애플리케이션을 개발하는 것은 필요충분조건이다. 하지만 객체지향 방법은 서버 사이드 애플리케이션의 전유물이었고, 어긋난 개발 환경과 접근으로 인해 정작 중요한 클라이언트 사이드 애플리케이션은 보조 역할을 하였다. 하지만 Ajax는 이런 형태에 새로운 패러다임을 제시하였으며 prototype.js가 이를 증명하였다. 이 책은 prototype.js 프레임웍을 이용하여 객체지향 방법으로 Ajax 애플리케이션을 구현할 수 있는 방법을 밑바탕부터 제시한다.

prototype.js는 세계적으로 인정받는 Ajax 프레임웍이다. 이에 대해서는 이미 많은 전 세계 개발자들에 의해 검증이 끝난 상태이다. 그렇다면 어떤 점이 개발자들의 마음을 사로잡게 되었는지 속을 들여다보고 파헤쳐봐야 한다. 이 과정을 통해 자연스럽게 실력이 향상됨은 물론이고, Ajax 애플리케이션 구현의 새로운 세계도 접할 수 있다. 이 책은 prototype.js 소스 코드를 라인 단위로 분석하였다. 코드의 작성 목적 및 이유를 분석하였고 아울러 기술적인 밑바탕을 제시하였다.


[머리말]

『Ajax prototype.js: 프로토타입 완전분석』은 새로운 패러다임의 Ajax 애플리케이션 구현을 위해 빠르고 쉬운 지름길로 여러분을 안내할 것이다.

『Ajax prototype.js: 프로토타입 완전분석』은 선택이 아니라 필수가 될 것이다. 이 책을 안보고 Ajax 애플리케이션을 논해서는 곤란하다. 자바스크립트가 객체지향 언어가 아니므로 객체지향을 구현할 수 없다고 한다면, 이 또한 곤란하다. 이런 말들은 이 책을 읽고 난 후에는 필요없는 말이 될 것이다. 필자는 이를 확신한다. 책을 다 읽고 난 후 필자가 왜 이렇게 강하게 주장했는가를 독자는 이해하게 될 것이다.

prototype.js가 현존하는 Ajax 프레임웍 중에서 가장 좋다고 하는 것은 이미 전 세계 개발자들에 의해 검증이 끝났다. 이제 prototype.js는 Ajax 애플리케이션을 개발할 때 없어서는 안될 존재가 되었다. prototype.js는 자바스크립트로 만들어져 있지만, 그 동안 자바스크립트로 구현하기에 어려움이 있다고 생각했던 객체지향 방법을 제시하고 증명하였다.

이 책의 목적은 prototype.js를 이해하는 것이며, 이를 통해 객체지향 방법으로 자바스크립트 코드를 작성하는 것이다. prototype.js를 이해하기 위해서는 자바스크립트 코드를 분석해야 하며, 분석하기 위해서는 코드를 작성한 논리적 배경을 이해해야 한다. 이 책은 이러한 흐름으로 구성돼 있다.

prototype.js의 클래스, 오브젝트, 메서드 등을 이해하기 위해서 사전 이해가 필요한 부분이 있다면 먼저 이를 설명하고 prototype.js 소스 코드를 설명하였다. 또 prototype.js 소스 코드를 설명한 후 이를 보충 설명하는 반대의 경우도 있다. 이러한 형태는 prototype.js 소스 코드에 대해 보다 논리적이고 합리적으로 접근하기 위함이다.

자바스크립트에 대한 개념이 전혀 없는 초급자라면 자바스크립트에 대한 책을 먼저 본 후 이 책을 볼 것을 권한다. 왜냐하면 자바스크립트의 아주 기초적인 내용은 다루지 않기 때문이다.

창조는 모방으로부터 시작된다는 말이 있다. 유아기에 엄마의 말을 따라 하면서 자연스럽게 말을 배우듯이 객체지향 방법으로 작성된 prototype.js 소스 코드를 분석하면서 자연스럽게 객체지향 방법으로 접근할 수 있으며, prototype.js에서 제공하는 프레임웍을 이용하여 보다 유려한 Ajax 애플리케이션을 개발할 수 있다.

이 책은 크게 두 가지 관점에서 접근할 수 있다. prototype.js에서 제공하는 클래스와 메서드를 사용하여 Ajax 애플리케이션을 개발하는 측면과 한발 더 나아가 prototype.js 소스 코드를 내 것으로 만드는 측면이다. 전자는 즉시 Ajax 애플리케이션을 구현할 수 있는 반면, 다소 밑바탕이 약한 행보가 될 수 있다. 후자는 더욱 기반이 튼튼하고 유려한 Ajax 애플리케이션을 개발할 수 있는 반면 시간이 좀 더 필요하다. 이 책을 어떤 관점으로 읽을 것인가에 대한 판단은 독자의 몫이다.

저자소개
김영보 http://cafe.naver.com/requirements.cafe
1979년 코오롱 전산실에 입사한 후 28년 동안 소프트웨어를 개발해온 베테랑 개발자이며 분석가이다. 장인 정신을 추구하며 아직도 시스템 개발 현장에 있는 희귀한 사람이기도 하다. 현재는 시스템 개발, 개발자를 위한 기고, 강의/세미나 등을 하고 있으며, 네이버에서 “Ajax와 요구공학” 카페를 운영하고 있다. 저서로는『요구분석을 위한 Event Process 모델링』(2005.11 가메출판사), 『Ajax 활용』(2006.4 가메출판사)이 있다.
Posted by tornado
|



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

 <script language="javascript" type="text/javascript" src="http://www.javarush.com/common/js/prototype.js"></script>
 <script language="javascript" type="text/javascript" src="http://www.javarush.com/common/js/scriptaculous.js"></script>



 


<div style="margin-top: 20px; height: 580px;">
 <div id="photoPanel1" style="position: absolute; "><img src="http://www.javarush.com/images/img1.jpg"  /></div>
 <div id="photoPanel2" style="position: absolute; display: none; "><img src="http://www.javarush.com/images/img2.jpg"  /></div>
 <div id="photoPanel3" style="position: absolute; display: none; "><img src="http://www.javarush.com/images/img3.jpg" /></div>
 <div style="position: absolute; margin-top: 450px;">
 <table border="0" cellpadding="10" cellspacing="5" >
 <tr>
  <td style="background-color: red; width: 70px; height: 7px; cursor: hand;" onmouseover="changeMainImage('photopanel1');"></td>
  <td style="background-color: green; width: 70px; height: 7px; cursor: hand;" onmouseover="changeMainImage('photopanel2');"></td>
  <td style="background-color: blue; width: 70px; height: 7px; cursor: hand;" onmouseover="changeMainImage('photopanel3');"></td>
   </tr>
 </table>
  </div>
</div>


<script language="javascript" type="text/javascript">
<!--

 var choicePanel = document.getElementById('photopanel1');
 
 function changeMainImage(arg1){
  var obj = document.getElementById(arg1);
 
  if(obj){
   if(obj.id != choicePanel.id){
    new Effect.Fade(choicePanel, { duration : 0.8 , afterFinishInternal : function() {
     new Effect.Appear(obj, { duration : 0.8 } )
    }
   } );
   }
  
   choicePanel = obj;
  }
 } 
 
 var cnt = 1;
 
 function autoChange(){
  changeMainImage('photopanel' + cnt);
 
  setTimeout("autoChange()", 5000);
  cnt++;
  if(cnt >= 4){
   cnt = 1;
  }
 }
 autoChange();
//-->
</script>


Posted by tornado
|

Javascript로 구현한 UTF-8 URLEncoding


<SCRIPT LANGUAGE="JavaScript">

 

/*  Function Equivalent to java.net.URLEncoder.encode(String, "UTF-8")

    Copyright (C) 2002, Cresc Corp.

    Version: 1.0

*/

function encodeURL(str){

    var s0, i, s, u;

    s0 = "";                // encoded str

    for (i = 0; i < str.length; i++){   // scan the source

        s = str.charAt(i);

        u = str.charCodeAt(i);          // get unicode of the char

        if (s == " "){s0 += "+";}       // SP should be converted to "+"

        else {

            if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a))){       // check for escape

                s0 = s0 + s;            // don't escape

            }

            else {                  // escape

                if ((u >= 0x0) && (u <= 0x7f)){     // single byte format

                    s = "0"+u.toString(16);

                    s0 += "%"+ s.substr(s.length-2);

                }

                else if (u > 0x1fffff){     // quaternary byte format (extended)

                    s0 += "%" + (oxf0 + ((u & 0x1c0000) >> 18)).toString(16);

                    s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);

                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);

                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);

                }

                else if (u > 0x7ff){        // triple byte format

                    s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);

                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);

                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);

                }

                else {                      // double byte format

                    s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);

                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);

                }

            }

        }

    }

    return s0;

}

 

/*  Function Equivalent to java.net.URLDecoder.decode(String, "UTF-8")

    Copyright (C) 2002, Cresc Corp.

    Version: 1.0

*/

function decodeURL(str){

    var s0, i, j, s, ss, u, n, f;

    s0 = "";                // decoded str

    for (i = 0; i < str.length; i++){   // scan the source str

        s = str.charAt(i);

        if (s == "+"){s0 += " ";}       // "+" should be changed to SP

        else {

            if (s != "%"){s0 += s;}     // add an unescaped char

            else{               // escape sequence decoding

                u = 0;          // unicode of the character

                f = 1;          // escape flag, zero means end of this sequence

                while (true) {

                    ss = "";        // local str to parse as int

                        for (j = 0; j < 2; j++ ) {  // get two maximum hex characters for parse

                            sss = str.charAt(++i);

                            if (((sss >= "0") && (sss <= "9")) || ((sss >= "a") && (sss <= "f"))  || ((sss >= "A") && (sss <= "F"))) {

                                ss += sss;      // if hex, add the hex character

                            } else {--i; break;}    // not a hex char., exit the loop

                        }

                    n = parseInt(ss, 16);           // parse the hex str as byte

                    if (n <= 0x7f){u = n; f = 1;}   // single byte format

                    if ((n >= 0xc0) && (n <= 0xdf)){u = n & 0x1f; f = 2;}   // double byte format

                    if ((n >= 0xe0) && (n <= 0xef)){u = n & 0x0f; f = 3;}   // triple byte format

                    if ((n >= 0xf0) && (n <= 0xf7)){u = n & 0x07; f = 4;}   // quaternary byte format (extended)

                    if ((n >= 0x80) && (n <= 0xbf)){u = (u << 6) + (n & 0x3f); --f;}         // not a first, shift and add 6 lower bits

                    if (f <= 1){break;}         // end of the utf byte sequence

                    if (str.charAt(i + 1) == "%"){ i++ ;}                   // test for the next shift byte

                    else {break;}                   // abnormal, format error

                }

            s0 += String.fromCharCode(u);           // add the escaped character

            }

        }

    }

    return s0;

}

</SCRIPT>

Posted by tornado
|
Posted by tornado
|

javascript Logger

DHTML/Javascript 2006. 5. 25. 09:40

이번 프로젝에서 javascript가 많아서 하나 만들어 봤음..

자바스크립 맨처음위치에

<script type='text/javascript' src='./Logger.js'></script>

만 삽입하고, 코드에서

Logger.debug( String );

Logger.error( String, Exception );

Logger.info( String );

이렇게 사용하면 됨


>소스


Posted by tornado
|