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

          基于FCKEditor 開發JSI Editor裝飾器:




          組件介紹:


          JSI Editor裝飾器,是一個用于可視化html編輯的組件(當能,將來也可考慮其他格式,如ubb),在標記設計上,參照Mozilla XUL的editor標記。而具體實現上,使用FCKEditor。



          效果:




           


          裝飾器實現代碼:



           


          1. /** 

          2.  * @public 

          3.  * @decorator editor 

          4.  * @attribute src 

          5.  * @attribute contenttype text/html(默認值) text/ubb .... 

          6.  */  

          7. function Editor(){  

          8.   

          9. }  

          10. Editor.prototype = new Decorator();  

          11. Editor.prototype.decorate = function(){  

          12.   var container = this.getContainer();  

          13.   var textarea = container.getElementsByTagName('textarea')[0];  

          14.   var fckEditor = new FCKeditor(textarea.name);  

          15.   var src = this.attributes.get('src');  

          16.   if(src){  

          17.     new Request(src,  

          18.     {asynchronous:true}).setFinishListener(function(){  

          19.       textarea.value = this.getText()||textarea.value;  

          20.       fckEditor.ReplaceTextarea();  

          21.     }).send();  

          22.   }else{  

          23.     fckEditor.ReplaceTextarea();  

          24.   }  

          25. }  







          裝飾器定義代碼:


          裝飾器定義其實就是普通類庫定義,沒有任何區別。

           


          1. //選自org/xidea/decorator/__$package.js,刪除了無關信息  

          2. this.addScript("editor.js",'Editor');  

          3. this.addObjectDependence("*",  

          4.     "js.html.Decorator",true);  

          5. this.addObjectDependence("Editor",  

          6.     "js.io.Request",false);  

          7. this.addObjectDependence("Editor",  

          8.     "net.fckeditor.FCKeditor",false);   









          使用方法:


          使用JSI裝飾器,需要在頁面上做如下處理:


          1. 增加命名空間(xmlns:d="http://www.xidea.org/taglib/decorator")

          2. 加入JSI引導腳本(<script src="../scripts/boot.js"></script>)

          3. 加入所用裝飾器的標記


          簡單示例:

           


          1. <?xml version="1.0" encoding="utf-8"?>  

          2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  

          3. <html xmlns="http://www.w3.org/1999/xhtml"  

          4.   xmlns:d="http://www.xidea.org/taglib/decorator" xml:lang="zh_CN"  

          5.   lang="zh_CN">  

          6. <head>  

          7. <script src="../scripts/boot.js"></script>  

          8. <title>Editor 示例</title>  

          9. </head>  

          10. <body>  

          11. <d:editor>  

          12.   <textarea name='editorText'>  

          13.    待編輯html:<br>  

          14.   This is some <strong>sample text</strong><br>  

          15.   You are using <a href="http://www.fckeditor.net/">FCKeditor</a>.<br>  

          16.   </textarea>  

          17. </d:editor>  

          18. </body>  

          19. </html>  





          總結:


          JSI 裝飾器是一個新事物,如果要一切從零開始,是一個艱巨的任務;但是,借助于JSI無侵入的特性,我們可以集百家之長。在前人豐厚的積累上,創造出更加簡單易用的ui 組件集。



          海納百川,有容乃大。




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





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



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

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


          網站導航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          主站蜘蛛池模板: 三原县| 保山市| 隆安县| 巩留县| 涿鹿县| 雷州市| 凉城县| 道孚县| 芒康县| 定西市| 海门市| 满城县| 宁晋县| 武山县| 香港 | 高邮市| 贺兰县| 清河县| 庆元县| 达拉特旗| 盐池县| 凤山县| 石狮市| 五峰| 海口市| 朝阳县| 磐石市| 桂东县| 门头沟区| 乐山市| 额济纳旗| 玉树县| 兖州市| 墨竹工卡县| 蓬莱市| 新密市| 文登市| 陆河县| 驻马店市| 庄浪县| 工布江达县|