Clean Code that Works.

http://old.nabble.com/jQuery.ajax%28%29-not-calling-beforeSend--td26001880s27240.html

$.ajax({
url: serviceUrl,
dataType: "jsonp",
data: params,
beforeSend: function(req) {
alert("inside!");
}
});

이 경우 beforeSend는 동작 하지 않는다.
왜 그럴까?

If serviceUrl is on a different domain then your jsonp request will
not use ajax, and so beforeSend will not be called.  x-domain jsonp
requests inject script tags into the document head.

하하하하하!!
다른 도메인으로 jsonp요청할땐 ajax가 아니라서
header에서 request정보가 없단다.
그래서 beforeSend를 사용할 수 없다.
ㅋㅋ
complete는 잘 동작함.

http://code.google.com/p/jquery-aop/wiki/Reference

jQuery로 구현된 자바스크립트 AOP.
이거 구현에 관해서는 조금 더 살펴봐야겠다.
어떻게 구현했는지..

다른 일반 JS AOP들을 보니깐 프로토타입 확장해서 어쩌구 하던데..
이거 관련해서는 자바스크립트 완벽 가이드 책 볼 것!!

AOP 관련해서, ajax 관련 메서드들을 실행할 때
ajax 옵션에 async: false 로 줘서 비동기를 동기 실행으로 바꿔서 실행 할 수 있도록 한다.
헙~~~이러면 ajax 의미와 일치하지 않네.. ㅋ
요청시간이 긴 것에는 사용하지 않도록 하자.


사내 멘토링 진행하면서 했던것 정리 용 'ㅁ'

원본은 http://codesign.verse.jp/jquery/2009/09/stringball.html
위 사이트에서 확인 하실 수 있습니다.
http://codesign.verse.jp/jquery/ 여기를 방문하면 다양한 jQuery 플러그인을 볼 수 있습니다.
 
저기서 제공하는 플러그인은 단순히 태그 클라우드 구성만 해주기 때문에,
이 플러그인에다가 두 가지 기능을 추가했습니다.
  1. 태그에 마우스를 올릴 경우 회전 중지
  2. 태그를 클릭할 경우 태그명을 가지고 액션을 수행할 수 있도록 함
간단하게 플러그인에 대한 설명을 하면
(사이트의 설명을 펌질 했습니다.)

・headへの記述

<script type="text/javascript" src="jquery-1.3.2.min.jsへのパス"></script>
<script type="text/javascript" src="jquery.stringball.jsへのパス"></script>
<script type="text/javascript">
$(function(){
	$("ul#stringball").stringball({
		camd:800,  //ボールまでの距離です。
		radi:250, //ボールの半径です。
		speed:20  //回転スピードです。
});
});
</script>

・bodyへの記述

<ul id="stringball">
	<li><a href="#">text1</a></li>
	<li><a href="#">text2</a></li>
	<li><a href="#">text4</a></li>
      <!--必要分liタグを繰り返し-->
</ul>
 
ul로 구성된 html에다가 js에서 $("ul#stringball").stringball()을 지정해 주기만 하면 태그 클라우드가 구성 됩니다. 만약 태그를 동적으로 구성하고 싶다면 ul에다가 li를 동적으로 append 해줘야 겠죠.
ex :)
$.ajax({
    url : 'someUrl',
    type: 'post',
    dataType : 'json',
    success : function( data) {
        $.each( data, function( val) {
            $( '#stringball').append('<li><a href="#">val<a/></li>');
        }
    }
});
 
이렇게 태그 클라우드는 간단하게 구성 할 수 있습니다.
참 쉽죠잉~ 태그 플러그인 소스를 살펴 보아도...
사실 별다른 내용은 없고, 위치를 계산 하기 위한 소스가 대부분 입니다.
게다가 주석은 모두 일본어!!! 쿠왁!!
히라가나면 어찌 좀 보겠지만 한문은 무리.. ;
 
플러그인 안에는 두개의 함수가 있습니다.
  • setini() - 초기 태그의 위치 값 들을 설정
  • setpos() - 태그들의 위치를 설정
그리고 마우스가 태그 클라우드에 hover 했을때 동작하도록 하는 이벤트가 있습니다.
 
여기까지가 기본적인 StringBall에 대한 설명이고
추가로 들어간 기능에 대해서 알아 보도록 하겠습니다.
 
1. 태그에 마우스 올라간 경우 회전 중지
이 경우는 setini()에서 각 태그들의 위치를 설정 할 때,
해당 태그에 mouseover 했을 경우 태그의 스피드를 0으로 설정 하면 됩니다.
ex :)
//태그 위에 마우스 올라왔을때 회전 중지
    $( elem[i]).mouseover(
     function() {
      speed = 0;
    }).mouseout(
     function() {
      speed = realSpeed;
    });
mouseout 했을 때는 이전 스피드로 복구하는걸 잊으시면 안되구요

 

2. 태그를 클릭할 경우 태그명을 가지고 액션을 수행할 수 있도록 함

이것도 setini()에서 태그를 클릭 할 때 수행말 함수를 지정해 주면 됩니다.

ex :)

//태그 클릭했을 때
    $( elem[i]).click( function() {
     clickFunction( $( this).text());
    });

태그를 클릭 했을 때 clickFunction 을 수행하도록 되어 있는데

clickFunction에 동작할 function을 지정해 주기 위해서는

ex :)

var target=$(this),
  elem=$("li" ,target),
  scrz=500,
  radi=options.radi,
  camd=options.camd,
  speed=options.speed, realSpeed=options.speed, clickFunction = options.clickFunction;

이렇게 StringBall 소스를 수정 해야 합니다.

이렇게 수정 한 후, StringBall을 생성 할 때 사용할 함수를 지정해 주면 됩니다.

ex:)

// Tag cloud 생성
   $( target).stringball({
    camd:  850,
    radi:  100,
    speed:  10,
    clickFunction: getTagInfo
   });

이렇게 하면 clickFunction에 getTagInfo라는 함수가 지정 됩니다.

 

여기까지 해서 간단하게 태그클라우드 플러그인을 사용하고 확장 하는 방법을 알아봤습니다.

예제소스를 첨부하오니 확인하시기 바랍니다. ^^


참고 할 것.
http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery

Plug me: Writing your own plugins

Writing your own plugins for jQuery is quite easy. If you stick to the following rules, it is easy for others to integrate your plugin, too.

Plugin Naming

Find a name for your plugin, lets call our example "foobar". Create a file named jquery.[yourpluginname].js, eg. jquery.foobar.js

Adding a Custom Method

Create one or more plugin methods by extending the jQuery object, eg.:

 jQuery.fn.foobar = function() {
// do something
};

Which will then be accessible by performing:

 $(...).foobar();

Default Settings:

Create default settings that can be changed by the user, eg.:

 jQuery.fn.foobar = function(options) {
var settings = jQuery.extend({
value: 5, name: "pete", bar: 655
}, options);
};

You can then call the plugin without options, using the defaults:

 $("...").foobar();

Or with some options:

 $("...").foobar({ value: 123, bar: 9 });

Documentation

If you release your plugin, you should provide some examples and documentation, too. There are lots of plugins available as a great reference.

Now you should have the basic idea of plugin writing. Lets use this knowledge and write one of our own.

Checkbox Plugin

Something lots of people, trying to manipulate forms with jQuery, ask for, is checking and unchecking of radio buttons or checkboxes. They end up with code like this:

 $(":checkbox").each(function() {
this.checked = true;
this.checked = false; // or, to uncheck
this.checked = !this.checked; // or, to toggle
});

Whenever you have an each in your code, you might want to rewrite that as a plugin, pretty straightforward:

 jQuery.fn.check = function() {
return this.each(function() {
this.checked = true;
});
};

This plugin can now be used:

 $(":checkbox").check();

Now you could write plugins for both uncheck() and toggleCheck(), too. But instead we extend our plugin to accept some options.

 jQuery.fn.check = function(mode) {
// if mode is undefined, use 'on' as default
var mode = mode || 'on';

return this.each(function() {
switch(mode) {
case 'on':
this.checked = true;
break;
case 'off':
this.checked = false;
break;
case 'toggle':
this.checked = !this.checked;
break;
}
});
};

By providing a default for the option, the user can omit the option or pass one of "on", "off", and "toggle", eg.:

 $(":checkbox").check();
$(":checkbox").check('on');
$(":checkbox").check('off');
$(":checkbox").check('toggle');

Optional Settings

With more than one optional setting, this approach gets complicated, because the user must pass null values if he wants to omit the first parameter and only use the second.

The use of the tablesorter in the last chapter demonstrates the use of an object literal to solve this problem. The user can omit all parameters or pass an object with a key/value pair for every setting he wants to override.

For an exercise, you could try to rewrite the Voting code from the fourth section as a plugin. The plugin skeleton should look like this:

 jQuery.fn.rateMe = function(options) {
// instead of selecting a static container with
// $("#rating"), we now use the jQuery context
var container = this;

var settings = jQuery.extend({
url: "rate.php"
// put more defaults here
}, options);

// ... rest of the code ...

// if possible, return "this" to not break the chain
return this;
});

And allowing you to run the plugin like so:

 $(...).rateMe({ url: "test.php" });

결과를 json으로 받아서 js로 html작성 하여 이벤트를 붙일 경우..

일반적으로 생각하면
for ( var i = 0; i < data.length; i++)
로 결과만큼 돌면서
$( '#element'+i).live( 'click', function() {
     여기에 $( '#target'+i).hide()
     이렇게 적용하면 될것 같지만 안된다..
});

맨 마지막꺼나 맨 처음것에만 적용이 되는데..
이런때는
$( '#target'+i).hide()이렇게 하지 말고
$( this).parent().parent().parent().parent().find( '#target').hide()
로 selector를 사용해서 타겟을 찾아낸 다음에 적용할 수 있도록 하자.

어우~~ css레이아웃은 머리 아파 ~_~

추가로.. ID는 고유한 것이기 때문에 반복문에서 target element를 생성하고 $( '#target').hide()이렇게 효과를 주지 말고 css class를 지정해서 selector로 css class를 검색 하여, 효과를 주자.

http://codesign.verse.jp/jquery/

일본인 개발자의 jQuery플러그인.
오우. 깔끔하고 좋네!!!!!

멋지다!!

굿굿굿.!

It's awesome!!


jQuery를 이용한 링크가 죽었는 살았는지 체크하는 라이브러리입니다.
원본 주소 : http://plugins.jquery.com/project/linkchecker

원본은 예제가 php기준으로 되어 있어서 jsp로 바꾸었습니다.
이걸 쓰실려면 사이트에 맞게 바꿔 주어야 합니다.
한시간동안 날림으로 만든거라서..-,.-;;

그냥 jsp로 요청을 날려서 사이트가 살아 있으면 200, 죽으면 404를 가지고 있는 html을 리턴 합니다.
이걸 가지고 찾아서 링크의 css클래스를 변경하는 방법입니다.

이걸 쓸려면 아마 서버단에서 처리하고 json 형태로 결과를 리턴 받아서 이걸 가지고 처리하는게 더 좋겠죠 'ㅁ'
==============
조금 수정해서 json으로 값 리턴하게 변경.
function checkLinks(urls, settings, jLinks) {
  $.getJSON(settings.checkScript, {'links':urls, 'timeout':settings.timeout}, function(data)
  {
  for ( var i = 0; i < data.length; i++)
   {
    jLinks.filter('[href^='+ data[i].url + ']').addClass(data[i].code == 200 ? settings.activeClass : settings.inactiveClass);
   }  });
 }




네이버 용어 사전에서는
프로그램에서 처리해야 할 기능을 구체적으로 세분하여 그 기능을 정의하고, 입출력 요건과 프로그램 작성에 필요한 논리 개념을 정리하는 문서. 프로그램 구조의 설계 단계에서 작성된다.
위키 백과 에서는
A functional specification (also, functional spec, specs, functional specifications document (FSD), or Program specification) in systems engineering and software development, is the set of documentation that describes the requested behavior of an engineering system. The documentation typically describes what is needed by the system user as well as requested properties of inputs and outputs (e.g. of the software system).
블로그 에서는
기능 명세란 1) 사용자의 관점에서 2) 최종 제품이 3) 어떤 모습이며 4) 어떻게 동작할 것인지를 기술한 문서를 말한다. 기능 명세란 어디까지나 최종 사용자의 입장에서 기술한 문서이기 때문에 내부 구현이나 설계 이슈를 포함하지 않는다. 또한 최종 제품에 대해서 이야기하기 때문에 각 소프트웨어 컴포넌트들이 어떻게 상호 작용하는지도 중요하지 않다. 그저 이 프로젝트가 끝나면 나오는 최종 산출물이 어떤 모습이며 어떤 일을 수행하는지를 자세히 기술하는 것이다

기능 명세 작성 궈궈싱.

Context Menu.

프로그래밍2009. 4. 22. 10:18
어렴 풋이 알고 있었던 용어에 대한 확실한 정의가 필요 할 것 같다.

Context Menu는 무엇인가.
A context menu (also called contextual, shortcut, and popup or pop-up menu) is a menu in a graphical user interface (GUI) that appears upon user interaction, such as a right mouse click.

헙. 뭔 말인고.
그냥 GUI 화면에서 마우스 오른쪽 클릭에 반응하는 팝업 메뉴숏컷 등을 컨텍스트 메뉴라고 한다.

Window Xp


GNOME


마일스톤

프로그래밍2009. 4. 21. 15:51
마일스톤  :  마일스톤이란 ‘이정표’를 의미하는 것으로 프로젝트 일정 가운데 중요시점으로 생각하면 된다. 예를 들어 요구사항 분석 완료 시점, 각각 컴포넌트 완성 시점, 릴리즈 시점, 알파, 베타 테스트 시기 등이 이에 속한다.

http://goodoi.springnote.com/pages/610392