2009年3月5日

浮動定位

浮動元素

可外掛於jqeury
$.markPostion(targetObj,'top'/'bottom',0,'left'/'right',50);



// jquery 1.2.6

function _Position(obj,xtype,x,ytype,y){
this._computes = {
'top':{'postion':function(pos){
t = $(pos.scrollObj).scrollTop();
nt = parseInt($(pos.obj).css('top').replace('px',''));
$(pos.obj).css('top',( t - pos.lasty + nt ) +'px' );
pos.lasty = t;}
},'bottom':{'postion':function(pos){
t = $(pos.scrollObj).scrollTop();
$(pos.obj).css('bottom',( pos.lasty - t + pos.y ) +'px' );
pos.lasty = t;}
},'left':{'postion':function(pos){
t = $(pos.scrollObj).scrollLeft();
nt = parseInt($(pos.obj).css('left').replace('px',''));
$(pos.obj).css('left',( t - pos.lastx + nt ) +'px' );
pos.lastx = t;}
},'right':{'postion':function(pos){
t = $(pos.scrollObj).scrollLeft();
$(pos.obj).css('right',( pos.lastx - t + pos.x ) +'px' );
pos.lastx = t;}
}};
this.obj = obj;
this.xtype = (xtype ? xtype : 'left');
this.x = (x ? x : 0) ;
this.lastx = 0;
this.ytype = (ytype ? ytype : 'top');
this.y = (y ? y : 0) ;
this.lasty = 0;
this.scrollObj = $(window)?$(window):$(document);
this.xcompute = this._computes[this.xtype];
this.ycompute = this._computes[this.ytype];
_Position.prototype.init = function(){
$(this.obj).css('position','absolute').css(this.xtype,this.x+'px').css(this.ytype,this.y + 'px');
this.xcompute.postion(this);
this.ycompute.postion(this);
};
_Position.prototype.postion = function(){
this.xcompute.postion(this);
this.ycompute.postion(this);
};
}

function markPostion(obj,ytype,y,xtype,x ){
var top = new _Position(obj,xtype,x,ytype,y );
top.init();
$(top.scrollObj).scroll(function(){
top.postion();
}).resize(function(){
top.postion();
});
}

$.extend({
'markPostion':markPostion
});



測試:

t1 = $('');
$(t1).append('textA111!!!');
$(t1).css('background-color','#00ff00');
$(document.body).append($(t1));

markPostion(t1);


$.markPostion($('#testC1'),'top',0,'right',50);

2009年3月3日

視窗的SIZE還有SCROLL的位置

Getting window size and scroll bars position in JavaScript/DHTML:
http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html
這篇文章分析了視窗的SIZE還有SCROLL的位置(節錄部份)





ParameterwindowdocumentElementbody
Window Widthwindow.innerWidthdocument.documentElement.clientWidthdocument.body.clientWidth
Window Heightwindow.innerHeightdocument.documentElement.clientHeightdocument.body.clientHeight
Horizontal Scrollwindow.pageXOffsetdocument.documentElement.scrollLeftdocument.body.scrollLeft
Vertical Scrollwindow.pageYOffsetdocument.documentElement.scrollTopdocument.body.scrollTop

2009年1月19日

貨幣千位符號


function addsign(value,interval,sign){
var v = $.trim(value);
if(v.length == 0 ){
return '';
}
var rs = '';
for(i = v.length -1,j=1 ;i >= 0 ; i--,j=++j%interval){
rs = ( i!=0 && j==0 ? sign : "" )+ v.charAt(i) + rs ;
}
return rs;
}

function currencyStr(value,round){
if(isNaN(value)){
return '';
}
if(!round){
round = 0;
}
v = $.trim(""+Math.abs(value)).split('.');
return (value < 0 ?"-":"")+ addsign(v[0],3,',')+(v.length > 1 && round > 0 ?"."+ v[1].substr(0,round): "" );
}

2009年1月14日

檔案下載

如果有要使用檔案下載方式
只要宣告幾個部份就可以了


public void download(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/aaa");
res.setHeader("Content-Disposition",new String("attachment;filename=中文.csv".getBytes(),"ISO8859_1"));

OutputStreamWriter out=new OutputStreamWriter(res.getOutputStream());
out.write("aaaa");
out.close();

res.setStatus(res.SC_OK );
res.flushBuffer();
}




這個部份主要改掉預設值 text/html ,只要改成不是'text/html',就可以出現檔案下載的畫面:

res.setContentType("text/aaa");




這個部份主要是提供下載檔名,將檔案名稱使用ISO8859_1編碼即可:

res.setHeader("Content-Disposition",new String("attachment;filename=中文.csv".getBytes(),"ISO8859_1"));







ContentType 參考列表
application/andrew-inset ez
application/mac-binhex40 hqx
application/mac-compactpro cpt
application/mathml+xml mathml
application/msword doc
application/octet-stream bin dms lha lzh exe class so dll
application/oda oda
application/ogg ogg
application/pdf pdf
application/postscript ai eps ps
application/rdf+xml rdf
application/smil smi smil
application/srgs gram
application/srgs+xml grxml
application/vnd.mif mif
application/vnd.mozilla.xul+xml xul
application/vnd.ms-excel xls
application/vnd.ms-powerpoint ppt
application/vnd.wap.wbxml wbxml
application/vnd.wap.wmlc .wmlc wmlc
application/vnd.wap.wmlscriptc .wmlsc wmlsc
application/voicexml+xml vxml
application/x-bcpio bcpio
application/x-cdlink vcd
application/x-chess-pgn pgn
application/x-cpio cpio
application/x-csh csh
application/x-director dcr dir dxr
application/x-dvi dvi
application/x-futuresplash spl
application/x-gtar gtar
application/x-hdf hdf
application/x-httpd-php .php .php4 .php3 .phtml
application/x-httpd-php-source .phps
application/x-javascript js
application/x-koan skp skd skt skm
application/x-latex latex
application/x-netcdf nc cdf
application/x-pkcs7-crl .crl
application/x-sh sh
application/x-shar shar
application/x-shockwave-flash swf
application/x-stuffit sit
application/x-sv4cpio sv4cpio
application/x-sv4crc sv4crc
application/x-tar .tgz tar
application/x-tcl tcl
application/x-tex tex
application/x-texinfo texinfo texi
application/x-troff t tr roff
application/x-troff-man man
application/x-troff-me me
application/x-troff-ms ms
application/x-ustar ustar
application/x-wais-source src
application/x-x509-ca-cert .crt
application/xhtml+xml xhtml xht
application/xml xml xsl
application/xml-dtd dtd
application/xslt+xml xslt
application/zip zip
audio/basic au snd
audio/midi mid midi kar
audio/mpeg mpga mp2 mp3
audio/x-aiff aif aiff aifc
audio/x-mpegurl m3u
audio/x-pn-realaudio ram rm
audio/x-pn-realaudio-plugin rpm
audio/x-realaudio ra
audio/x-wav wav
chemical/x-pdb pdb
chemical/x-xyz xyz
image/bmp bmp
image/cgm cgm
image/gif gif
image/ief ief
image/jpeg jpeg jpg jpe
image/png png
image/svg+xml svg
image/tiff tiff tif
image/vnd.djvu djvu djv
image/vnd.wap.wbmp .wbmp wbmp
image/x-cmu-raster ras
image/x-icon ico
image/x-portable-anymap pnm
image/x-portable-bitmap pbm
image/x-portable-graymap pgm
image/x-portable-pixmap ppm
image/x-rgb rgb
image/x-xbitmap xbm
image/x-xpixmap xpm
image/x-xwindowdump xwd
model/iges igs iges
model/mesh msh mesh silo
model/vrml wrl vrml
text/calendar ics ifb
text/css css
text/html .shtml html htm
text/plain asc txt
text/richtext rtx
text/rtf rtf
text/sgml sgml sgm
text/tab-separated-values tsv
text/vnd.wap.wml .wml wml
text/vnd.wap.wmlscript .wmls wmls
text/x-setext etx
video/mpeg mpeg mpg mpe
video/quicktime qt mov
video/vnd.mpegurl mxu
video/x-msvideo avi
video/x-sgi-movie movie
x-conference/x-cooltalk ice

2009年1月11日

StrUtil



2009年1月10日

WordTemplate

類似word 匯入功能
因為看不到MSDN有關於WORD的API
所以就自己弄了個可以當作樣板的word以供大量產生相同格式的word


Logger

自己弄得logger
為在執行目錄下建立log目錄並且有檔案數目限制