Posted on 2010/03/12 18:14
Filed Under Development/AJAX

줴이쿼리 북마크입니다~

모든 브라우저에서 동작하고, 안되는 브라우저에서는 메세지를 띄워주네요~

주소는
http://www.dummwiam.com/jFav
이고 사용법은

// 줴이쿼리로드
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1");
</script>

// jFav 로드~
<script src="../libraries/jquery/plugins/jFav_v1.0.js"></script>
<script>
$(function() {
 $('.add-favorite').jFav();
});
</script>

// 이미지
<span class="add-favorite">북마크추가<span>


개인적으로는 북마크정도의 기능은 제이쿼리의 기본기능으로 들어가도 될것같네요 ㅎㅎ

2010/03/12 18:14 2010/03/12 18:14

Posted on 2010/02/17 15:08
Filed Under Development/AJAX

일반적으로 웹사이트 작업을 하다보면 노이미지 처리가 필요한경우가 있습니다. 쇼핑몰을 예를 들면 해당 이미지가 없거나 하는경우의 처리인데요 이게 몇개 정도면 문제가 없지만 많을경우 성능에 심각한 영향을 줍니다. 하지만 자바스크립트로 오류를 체크할수 있는데 jQuery로 하면 매우 간단합니다.
다음을 보시면
$(function() {
	$('img').error(function() {
		alert('before');
		$(this).attr('src', 'no-image.png');
	});
});
이미지가 오류가 있는경우 no-image.png로 대체하라 입니다. 머 텍스트등으로 대체할수도 있구요 그경우
$(this).replaceWith('
no image
');
으로 처리할수 있습니다. 한방에 처리할수있으니 편리하죠 ^_^
2010/02/17 15:08 2010/02/17 15:08

Posted on 2010/01/21 10:27
Filed Under Development/AJAX


엄청나게 많은 사람들이 새로운 웹사이트에서jQuery 1.4
가 릴리즈되는것에 대하여 jQuery가 14일째를 맞는것을 축하해줄것이다.

많은 새로운 기능이 있고, 평소처럼 퍼포먼스의 향상을 모았다

  • 쉬운 세터 함수 : 현재는 .attr() 를 통해서 값을 넣는것이 가능했다. 이 기능을 모든 세터 메소드로 확장했다.
  • Ajax : 기능이 향상된 다양한 원격 함수들이 포함되었고 네이티브 JSON 파싱, etags, 컨텍스트 요청, 그외에 .css 와 .attr 가 개선되었다
  • 속성별 easing 효과
  • 만약 당신이 함수안의 "this" 를 영구적으로 특정값으로 바인딩하고 싶다면 당신은 jQuery.proxy 를 이용하여 새로운 함수의 스코프를 받을수 있다.
  • 새로운 이벤트 : focusin 과 focusout
그리고 Joe Walker 가 dojo.create이 제출되었다는것을 보면 매우 기뻐할것이다! :)
jQuery("
", { id: "foo", css: { height: "50px", width: "50px", color: "blue", backgroundColor: "#ccc" }, click: function() { $(this).css("backgroundColor", "red"); } }).appendTo("body");
Congrats to the jQuery team. I look forward to seeing posts over the next
2 weeks that go into more detail on the new coolness.

2010/01/21 10:27 2010/01/21 10:27
TAG :

Posted on 2009/11/11 16:29
Filed Under Development/AJAX

주소창에
javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.images; DIL=DI.length; function A(){for(i=0; i-DIL; i++){DIS=DI[ i ].style; DIS.position='absolute'; DIS.left=(Math.sin(R*x1+i*x2+x3)*x4+x5)+"px"; DIS.top=(Math.cos(R*y1+i*y2+y3)*y4+y5)+"px"}R++}setInterval('A()',5); void(0);
를 입력한후 엔터!

당황하지 마세요^^
2009/11/11 16:29 2009/11/11 16:29

Posted on 2009/02/08 15:32
Filed Under Development/AJAX

프로그래밍에서 프레임워크는 필수적이라고 할 수 있다. 거의 모든 작업들이 비슷한 경우가 많아 같은 작업을 두번 세번 하게 되는경우가 많기 때문이다. 이를 모아놓은것을 라이브러리라 하는데 이런 코드에 방법론까지 더한것이 프레임워크이다.

ajax 개발을 하다보면 여기 자바스크립트 프레임워크의 필요성을 절실히 느끼게된다. 기존에 수많은 노가다와 오류를 감당할수 없기때문이다. 이에 Prototype 을 필두로 많은 프레임워크들이 존재한다.  다음 링크는 구글이 호스팅하는 ajax 프레임워크다. 플래시 오프젝트를 표현하기 위한 swfobject도 보인다.

http://code.google.com/intl/ko/apis/ajaxlibs/

조금 된 이야기지만 구글에서 그런 프레임워크들에 대해 호스팅 서비스를 시작했다. 필자도 애용하고 있지만 이를 이용할 경우 장점은 다음글에서 볼수 있다.

http://enzine.tistory.com/entry/Google-AJAX-라이브러리-API

여하튼 구글에서 제공하는 리스트들이 바로 자바 프레임워크 들이다. 2009년 2월 현재 구글에서 제공하는 리스트들을 살펴보면

주요 ajax 프레임워크는 jquery와 prototype, dojo, mootools YUI 정도가 되겠다.
jquery UI 는 jquery의 UI 쪽을 담당하는 프레임워크인고 script.aculo.us 는 움직임 효과를 담당하는 prototype 계열의 프로젝트 이다.

이중 가장 대중화 되어있는것은 아무래도 prototype 이다. 매우 간결하고 직관적으로 표현할수있고 또 어떤 프로젝트든지 빠르게 적용할수 있다.  실제로 웹사이트에서 가장많이 차지하고 있다. 실제로 예전 자료지만 1위와 2위가 prototype과 script.aculo.us 이다.

http://firejune.com/969

jquery 는 최근에 무서운 속도로 상승하고 있고 또 다른 프로젝트들에 비해 빠르게 업데이트 되고 있다. 최근 버전(1.3) 에는 기존의 다른 프레임워크들의 셀렉터 엔진에 비해 3배( 실제로 테스트도 해볼수 있다.) 이상 빠르다는 셀렉트 엔진을 탑재했다. 또 각 메소드들의 리턴값이 jquery 로 되어있기때문에 연결해서 코드를 작성할 수 있다.

dojo는 굉장히 방대한 내용을 담고 있다.  위에서 말한 prototype이나 jquery와는 비교도 안될정도로 방대한 기능과 UI 를 제공하고 있다. 다만 실무에 바로 쓰이려면 기획 당시부터 dojo에 대한것이 함께 들어가야 제대로된 web application을 만들 수 있다. 기본 개념도 자바에서 가져온 것이 많아서 매우 '자바틱' 한 프레임워크이다. 최근에는 PHP의 프레임워크인 Zend Framework 와도 연동 되어 많은 시너지를 낼 것으로 보인다.

마지막으로 YUI 도 매우 방대하고 멋진것들을 가지고 있다. Yahoo라는 대형 회사를 백으로 두고 있기때문에 조만간 크게 성장 할것으로는 보이지만, 역시 큰 프레임워크들은 실무에 바로 적용하는데 한계가 있어서 많이 쓰이지는 않고 있다.

또 우리나라에서 개발된 method chain 이라는 프레임워크도 있는데 Mathod Chain이라는 개념을 통해 자바스크립트 코딩을 간소화 할  있다.
http://www.methodchain.com/
2009/02/08 15:32 2009/02/08 15:32

Posted on 2008/05/15 15:38
Filed Under Development/AJAX

목차

  1. id로 특정 요소 가져오기[1]
  2. 폼 컨트롤러의 값을 가져오기[2]
  3. 스타일 변경하기[3]
  4. html 내용 변경하기[4]
  5. Ajax Request의 파라미터 셋팅하기[5]
  6. Ajax Request 생성하기[6]
  7. Event 추가하기[7]
  8. 각 요소별로 함수 실행하기[8]
  9. 이벤트 핸들링[9]
  10. 호출 체이닝[10]
  11. 테이블 형태의 html 내용변경하기[11]
  12. key 이벤트 감지하기[12]
  13. 이벤트 가로채기[13]
  14. insert() 메소드 제대로 사용하기[14]
  15. form 다루기[15]

id로 특정 요소 가져오기[#1]

이전의 방법
document.getElementById('foo')

추천하는 방법

$('foo')

폼 컨트롤러의 값을 가져오기[#2]

이전의 방법
var woot = document.getElementById('bar').value
var woot = $('bar').value

추천하는 방법

var woot = $F('bar')

스타일 변경하기[#3]

이전의 방법
$('footer').style.height = '100px';
$('footer').style.background = '#ffc';  

추천하는 방법

$('footer').setStyle({
  height: '100px',
  background: '#ffc'
})

html 내용 변경하기[#4]

이전의 방법
$('coolestWidgetEver').innerHTML = 'some nifty content'

추천하는 방법

$('coolestWidgetEver').update('some nifty content')

Ajax Request의 파라미터 셋팅하기[#5]

이전의 방법
new Ajax.Request('ninja.php?weapon1=foo&weapon2=bar')

추천하는 방법

new Ajax.Request('ninja.php', {
  parameters: {
    weapon1: 'foo',
    weapon2: 'bar'
  }
})

Ajax Request 생성하기[#6]

이전의 방법
new Ajax.Request('blah.php', {
  method: 'POST',
  asynchronous: true,
  contentType: 'application/x-www-form-urlencoded',
  encoding: 'UTF-8',
})

추천하는 방법

new Ajax.Request('blah.php')

여기서 위 방법이 잘못된게 아니다. 하지만 사용된 값이 모두 디폴트 값이기 때문에 굳이 표기할 필요가 없다는 것이다.

Event 추가하기[#7]

이전의 방법
Event.observe('myContainer', 'click', doSomeMagic)

추천하는 방법

$('myContainer').observe('click', doSomeMagic)

뒤의 방법이 좀더 객체 지향적이고 다른 이벤트를 추가하기가 용이하다.

각 요소별로 함수 실행하기[#8]

이전의 방법
$$('div.hidden').each(function(el){
  el.show();
})

추천하는 방법

$$('div.hidden').invoke('show')

같은 기능을 하기 위해 첫번째 방법처럼 지나치게 많은 함수를 사용할 필요가 없다.

이벤트 핸들링[#9]

이전의 방법
$$('div.collapsed').each(function(el){
  el.observe('click', expand);
})

추천하는 방법

$$('div.collapsed').invoke('observe', 'click', expand)

호출 체이닝[#10]

이전의 방법
$$('input.date').invoke('observe', 'focus', onFocus);
$$('input.date').invoke('observe', 'blur', onBlur);

추천하는 방법

$$('input.date')
  .invoke('observe', 'focus', onFocus)
    .invoke('observe', 'blur', onBlur)

위 두가지 모두 같은 기능을 실행하게 되지만 앞의 예제처럼 $$() 함수를 두번이나 호출해서 처리할 필요가 없다. 아래의 경우처럼 체이닝(chaining nirvana)를 사용하면 된다.

테이블 형태의 html 내용변경하기[#11]

이전의 방법
$('productTable').innerHTML = 
  $('productTable').innerHTML + 
  '<tr><td>' + productId + ' '
  + productName + '</td></tr><tr><td>'
  + productId + ' ' + productPrice + 
  '</td></tr>'

추천하는 방법

var rowTemplate = new Template('<tr><td>#{id} #{name}</td></tr><tr><td>#{id} #{price}</td></tr>');
$('productTable').insert(
  rowTemplate.evaluate({
    id: productId,
    name: productName,
    price: productPrice
  }))
)

위 두가지 모두 같은 기능을 실행하게 되지만 앞의 예제처럼 $$() 함수를 두번이나 호출해서 처리할 필요가 없다. 아래의 경우처럼 체이닝(chaining nirvana)를 사용하면 된다.

key 이벤트 감지하기[#12]

$('myInput').observe('keyup', function(e){
  if (e.keyCode == Event.KEY_TAB)
    doSomethingCoolWhenTabIsPressed();
})

keyCode는 KEY_RETURN, KEY_ESC, KEY_TAB, KEY_LEFT, KEY_UP, KEY_RIGHT, KEY_DOWN 과 같은 값들이 있다.

이벤트 가로채기[#13]

기본적인 방법
Event.observe('productInfo', 'click', displayProductInfo, false); // 'false' could be skipped
Event.observe('productInfo', 'click', displayProductInfo);

간단한 방법

$('productInfo').observe('click', displayProductInfo, false); // 'false' could be skipped
$('productInfo').observe('click', displayProductInfo);

insert() 메소드 제대로 사용하기[#14]

new Insertion.Bottom('blogEntry',
  new Template('<div><h2>#{name}</h2><p>#{content}</p></div>')
    .evaluate({
      name: blogEntry.name,
      content: blogEntry.content
    }));
 
// Insertion class is deprecated - it's recommended to use Element's insert method:
 
$('blogEntry').insert(new Template('<div><h2>#{name}</h2><p>#{content}</p></div>')
    .evaluate({
      name: blogEntry.name,
      content: blogEntry.content
    }), 'bottom' ); // "bottom" can be skipped
 
$('blogEntry').insert(new Template('<div><h2>#{name}</h2><p>#{content}</p></div>')
    .evaluate({
      name: blogEntry.name,
      content: blogEntry.content
    }));

위치값은 top, bottom, before, after 를 사용할수 있다. 이 값을 생략한다면 디폴트는 bottom이다.

form 다루기[#15]

다음은 .request를 사용하는 일반적인 form이다.
$('register').observe('submit', function(e){
  Event.stop(e);
  $(this).request();
})

.getInputs 는 type과 name속성에 기초하여 요소를 필터링하기 쉬도록 해준다. 여기서는 "email" 이라는 이름의 요소를 직렬화하고 폼의 "action" 이라는 속성내 포함된 URI에 결과를 서브밋한다.

$('register').observe('submit', function(e){
  Event.stop(e);
  new Ajax.Request($(this).readAttribute('action'), {
    parameters: Form.serializeElements($(this).getInputs('', 'email'))
  })
})

앞서 본 .getInputs가 대부분의 경우 유용하지만 일부 속성을 제외하고자 할때는 .reject를 사용한다.

$('register').observe('submit', function(e){
  Event.stop(e);
  new Ajax.Request(this.readAttribute('action'), {
    parameters: Form.serializeElements($(this).getElements()
      .reject(function(el){return el.hasAttribute('multiple')})
    );
  })
})

2008/05/15 15:38 2008/05/15 15:38

Posted on 2008/05/15 15:35
Filed Under Development/AJAX

1
 The wrong way:
  document.getElementById('foo')

 The right way:
  $('foo')

 Surprisingly some people actually don't know about this one ( including ~100KB file just to use Ajax.Request family )

2
 The wrong way:
  var woot = document.getElementById('bar').value
  var woot = $('bar').value
 The right way:
  var woot = $F('bar')
 
 Handy shortcut for reading a value of a form control

3
 The wrong way:
  $('footer').style.height = '100px';
  $('footer').style.background = '#ffc';

 The right way:
  $('footer').setStyle({
   height: '100px',
   background: '#ffc'
  })

Dreaming about IE behaving W3C way?
Not happenning! (but second construct will make you forget about cross-browser glitches)

4
 The wrong way:
  $('coolestWidgetEver').innerHTML = 'some nifty content'

 The right way:
  $('coolestWidgetEver').update('some nifty content')

One of those simple ones yet quite often forgotten.
Yes, I know they are almost the same
but I want to see you doing THIS with the first one
(isn't chaining just cool?)

 $('coolestWidgetEver').update('some nifty content').addClassName('highlight').next().hide()

5
 The wrong way:
  new Ajax.Request('ninja.php?weapon1=foo&weapon2=bar')

 The right way:
  new Ajax.Request('ninja.php', {
   parameters: {
    weapon1: 'foo',
    weapon2: 'bar'
   }
  })

 Cleaner and better structured parameters definition

6
 The wrong way:
  new Ajax.Request('blah.php', {
   method: 'POST',
   asynchronous: true,
   contentType: 'application/x-www-form-urlencoded',
   encoding: 'UTF-8',
  })

 The right way:

 new Ajax.Request('blah.php')

 All of these options are in Ajax.Request by default!
 "method: 'POST'" happens to be on every second pastie page I've seen
 (Still don't believe in JS inheritance? You don't have to. Just take advantage of it)

7
 The wrong way:
  Event.observe('myContainer', 'click', doSomeMagic)

 The right way:
  $('myContainer').observe('click', doSomeMagic)
  This one is debatable
  but second way is more Object Oriented (well... sort of)
  and easier to chain (So decide for yourself)

8
 The wrong way:
  $$('div.hidden').each(function(el){
   el.show();
  })

 The right way:
  $$('div.hidden').invoke('show')

 Here's a typical "each overuse". We have invoke for such things, folks! Sadly not many people know about it.

9
 The wrong way:
  $$('div.collapsed').each(function(el){
   el.observe('click', expand);
  })

 The right way:
  $$('div.collapsed').invoke('observe', 'click', expand)

 Ha! Take this!
 Invoke can also be used for event handling when iterating over a collection of elements.
 It's really easy, isn't it?

10
 The wrong way:
  $$('input.date').invoke('observe', 'focus', onFocus);
  $$('input.date').invoke('observe', 'blur', onBlur);

 The right way:

  $$('input.date')
   .invoke('observe', 'focus', onFocus)
    .invoke('observe', 'blur', onBlur)

 Somehow people tend to forget about "chaining nirvana".
 Don't like the way it looks? Think about saving some time by NOT invoking $$ twice!

11
 The wrong way:

 $('productTable').innerHTML =
  $('productTable').innerHTML +
  '<tr><td>' + productId + ' '
  + productName + '</td></tr><tr><td>'
  + productId + ' ' + productPrice +
  '</td></tr>'

 The right way:

 var rowTemplate = new Template('<tr><td>#{id} #{name}</td></tr><tr><td>#{id} #{price}</td></tr>');
 $('productTable').insert(
  rowTemplate.evaluate({
   id: productId,
   name: productName,
   price: productPrice
  }))
 )

2008/05/15 15:35 2008/05/15 15:35
TAG : ,

Counter

· Total
: 361644
· Today
: 92
· Yesterday
: 110