隨筆-57  評論-129  文章-0  trackbacks-0

          Spinner(微調器)裝飾器開發:


          組件介紹:


          仿照 window時間日期管理中,年份調節的控件,原型是一個文本輸入筐,一般用于數字輸入。筐后有上下微調按鈕,用于增減控件值。

          這種控件在
          backbase框架中也有出現,JSIspinner就是仿照其外形設計。


          顯示效果:




          在線演示見:http://www.xidea.org/project/jsi/decorator/spinner.html

          代碼:


          org/xidea/decorator/spinner.js


           


          1. /** 

          2.  * @public 

          3.  * @decorator spinner 

          4.  * @attribute start 

          5.  * @attribute end  

          6.  * @attribute step 

          7.  */  

          8. function Spinner(){  

          9. }  

          10.   

          11. Spinner.prototype = new Decorator();  

          12. Spinner.prototype.decorate = function(){  

          13.   this.start = parseInt(this.attributes.get('start'))  

          14.   this.end = parseInt(this.attributes.get('end'))  

          15.   this.step = parseInt(this.attributes.get('step'))||1;  

          16.   var container = this.getContainer();  

          17.   var table = document.createElement('table');  

          18.   var outerDiv = document.createElement("div");  

          19.   var upDiv = document.createElement("div");  

          20.   var downDiv = document.createElement("div");  

          21.   table.border = 0;  

          22.   table.cellSpacing=0;  

          23.   table.cellPadding=0;  

          24.   container.insertBefore(table,container.firstChild);  

          25.   var row = table.insertRow(0);  

          26.   var cell = row.insertCell(0);   

          27.   var ele = table.nextSibling;  

          28.   do{  

          29.     container.removeChild(ele);  

          30.     cell.appendChild(ele);  

          31.   }while(ele = table.nextSibling)  

          32.   cell = row.insertCell(1);  

          33.   cell.style.verticalAlign = 'middle',  

          34.   cell.appendChild(outerDiv);  

          35.   outerDiv.style.position = 'relative'  

          36.   outerDiv.style.top = '0px'  

          37.   outerDiv.style.left = '0px'  

          38.   outerDiv.style.height = '0px'  

          39.   outerDiv.style.width = '0px'  

          40.   outerDiv.style.zIndex= 2;  

          41.   //outerDiv.style.border= "solid 1px red";  

          42.   outerDiv.appendChild(upDiv);  

          43.   initializeHandleDiv(this,upDiv);  

          44.   outerDiv.appendChild(downDiv);  

          45.   initializeHandleDiv(this,downDiv);  

          46.   //alert(this.start+'/'+this.end+'/'+this.step+':'+(this.start<0))  

          47. }  

          48. Spinner.prototype.jump = function(offset){  

          49.   if(offset){  

          50.     var input = this.getContainer().getElementsByTagName('input')[0];  

          51.     var value = value = input.value * 1 + offset*this.step;  

          52.     if(value>this.end){  

          53.       value=this.end;  

          54.     }else if(value<this.start){  

          55.       value = this.start;  

          56.     }  

          57.     input.value = value;  

          58.   }  

          59. }  

          60. /** 

          61.  * @internal 

          62.  */  

          63. var imagePath = 'url("'+this.scriptBase + 'spinner.gif")';  

          64. /** 

          65.  * @internal 

          66.  */  

          67. function initializeHandleDiv(spinner,handleDiv){  

          68.   var position = 0;  

          69.   var style = handleDiv.style;  

          70.   style.backgroundImage=imagePath;  

          71.   style.position='absolute';  

          72.   style.width='12px';  

          73.   style.height='8px';  

          74.   style.margin='1px';  

          75.   style.left = '-14px'  

          76.   style.overflow = 'hidden'  

          77.   if(handleDiv.previousSibling){  

          78.     style.backgroundPosition = '0 -32px';  

          79.     position = -32;  

          80.     style.top = '0px'  

          81.   }else{  

          82.     style.top = '-10px'  

          83.   }  

          84.   handleDiv.onmouseout = buildMouseHandle(spinner,position,0)  

          85.   position -= 8;  

          86.   handleDiv.onmouseup=handleDiv.onmouseover = buildMouseHandle(spinner,position,0)  

          87.   position -= 8;  

          88.   handleDiv.onmousedown = buildMouseHandle(spinner,position,0)  

          89.   handleDiv.onclick = buildMouseHandle(spinner,position,position<-32?-1:1)  

          90. }  

          91. /** 

          92.  * @internal 

          93.  */  

          94. function buildMouseHandle(spinner,imagePosition,offset){  

          95.   imagePosition = '0 '+imagePosition+'px';  

          96.   return function(){  

          97.     this.style.backgroundPosition = imagePosition;  

          98.     spinner.jump(offset);  

          99.   }  

          100. }  











          使用方法見在 基于FCKEditor 開發JSI Editor裝飾器已有詳細介紹,不再敘述。


          見:http://www.javaeye.com/article/79063




          評論也很精彩,請點擊查看精彩評論。歡迎您也添加評論。查看詳細 >>





          JavaEye推薦
          杭州:外企高薪聘請系統維護工程師(10-15K)
          杭州:國內大型網絡公司高薪招聘系統架構師,資深JAVA開發工程師
          北京:優秀公司NHNChina招聘:WEB開發,系統管理,JAVA開發, DBA
          廣州:急招 JAVA開發經理/系統架構師(10-15K/月)也招聘java程序員



          文章來源: http://jindw.javaeye.com/blog/79064
          posted on 2007-05-12 11:17 金大為 閱讀(72) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 宣武区| 扎赉特旗| 天全县| 抚顺县| 南通市| 忻城县| 砀山县| 全南县| 长武县| 海林市| 闸北区| 河北省| 庄河市| 托克托县| 广昌县| 中牟县| 东乡县| 铁力市| 教育| 都匀市| 光山县| 禹城市| 永新县| 平果县| 邵武市| 阿坝| 华容县| 土默特右旗| 福安市| 谢通门县| 黄梅县| 隆化县| 尉氏县| 苍梧县| 尼勒克县| 鸡西市| 永宁县| 阿拉善盟| 大丰市| 嫩江县| 额尔古纳市|