카테고리 없음

impromptu쓰기

zican 2008. 7. 10. 17:15

http://trentrichardson.com/Impromptu/index.php

alert, prompt, confirm을 좀 더 이쁘게 구현해놓은것
단 modal한 방식으로 구현한게 아니기때문에
$.prompt를 호출한 다음에 바로 아래행을 수행한다. 주의할것

$.prompt(message, options)
message에는 text나 html이 들어갈 수 있다.
option에는 다양한 것들을 지정할 수 있는데
주로 버튼설정,  css어떤것을 사용할지 한정하는 prefix,
submit callback을 지정할 수 있다.
다른 옵션사항은 홈페이지 참조
submit callback에 건내지는 인자는 v, m이 있는데
v는 어떤 버튼이 클릭되었는지 값이 넘어오고
m은 메시지가 넘어온다. m에 html input을 썼다면 필요한 정보를 뽑아 올 수 있다.
callback에서 true를 리턴하지 않으면 진행이 안된다.
false면 계속 그 상태로 머물러 있음 validation할때 사용할 수 있음


실제 예)

function delcomment(commentNo, passwd_needed){
 var message;
 if ( passwd_needed )
  message = "<h3>주 의</h3><p>삭제하시겠습니까?<br/><input style='ime-mode:disabled' id='pass' type='password' name='passwd' value=''/></p>";
 else
  message = "<h3>주 의</h3><p>삭제하시겠습니까?</p>";
 
 $.prompt(message, { buttons: { OK: '1', CANCEL: '0' }
   , prefix:'brownJqi'
   , submit: function(v,m) {
    if ( v == '1' ) {
     var passwd = m.find('#pass').val() || '';
     alert(passwd);
     var url = '/comment.zul?m=delete';
     $.post(url, {'commentNo': commentNo, 'password':passwd}, delCallback);
    }
    return true;
   }
  });
}
 
function delCallback(data, status){
 var ret = eval("("+data+")");
 if ( ret.success ) loadComment()
 else $.prompt("<h3>알 림</h3><p>password가 일치하지 않습니다</p>", {prefix:'brownJqi'});
}