SlideShare a Scribd company logo
Kissy editor 介绍

            何一鸣(承玉@taobao)
About me
 2003 - 2010 Fudan CS
 2010.07 -   F2E @ Taobao



   目前开发维护 kissy editor
大纲
   1. 编辑器的分类

   2. 编辑器的实现

   3. KISSY Editor的设计

   4. 打包与部署

   5. 总结与前景展望
1. 编辑器的分类
1.1 所想即所得
1.2 所见即所得
Web 可视化编辑器
2. 编辑器的实现
   创建 iframe 元素,设置 body 属性
    contenteditable为 true

   方法
    ◦ 调用 execCommand
    ◦ Range 自主实现

   实现注意
2.1 调用 execCommand

   ie 4.0 引入

   bSuccess = object.execCommand(sCommand[,bUserInterface][,vValue])



    ◦ sCommand : 命令名

    ◦ bUserInterface : 用户界面提示

    ◦ vValue : 命令参数
execCommand 例子
   加粗当前选择文字

    ◦ document.execCommand("bold",null,false);


   添加链接
    ◦ 直接添加
      document.execCommand("createlink",
       null,"http://www.g.cn");
    ◦ 弹窗提示用户输入
      document.execCommand("createlink",
       true);
execCommand 问题
 ◦ 代码生成不一致
  行内格式化
    ie 会生成 font 标签
      <font color=“#ff0000”>x</font>
    safari 生成私有 class
      <span
        class=“Apple-style-span”
        style=“font-weight:bold;”>x</span>


 ◦ 能力不一致
  Createlink
    Firefox 不支持用户界面提示
      自己 window.prompt
execCommand 兼容性
execCommand
2.2 Range 自主实现
   使用 range 实现 execCommand 对等
    功能。




    ◦ Range api (w3c , ie)
W3c Range
   用来获取光标或选择区域信息

 W3c api
 Interface Range {
    ◦   Node startContainer
    ◦   Long startOffset
    ◦   Node endContainer
    ◦   Long endOffset
   }
IE Range
   ControlRange
    ◦ 选取整个元素 (div,img,object)
    ◦ Item (index) : 获取选中元素节点

   TextRange
    ◦   获取选中的文本区域
    ◦   Text : 选中的文本串值
    ◦   parentElement() :
    ◦   compareEndPoints()
    ◦   moveToElementText()
Do not hurt web
实现 execCommand
   Range + Dom2 + Dtd = execCommand
Dtd 的作用

   标签格式化系统需要考虑标签嵌套规则



   根据 dtd 以及格式标签进行 Range 的
    拆分!
Dtd 例子
   加粗
    ◦ ^<p>line</p><p>line2</p>^

    ◦ 错误:
      <strong><p>line</p><p>line2</p>
       </strong>


    ◦ 正确:
      <p><strong>line<strong></p>
       <p><strong>line2</strong></p>
2.3 常见问题
   换行代码生成差异

   ie 选择区域丢失问题

   Firefox 不可编辑问题

   光标定位问题…..
Enter 换行差异
 ◦ <h1>bla bla^</h1> 末尾换行

   ie
     <h1>bla bla</h1>
      <p>|</p>


   Safari
     <h1>bla bla</h1>
      <h1>|</h1>


   Firefox
     <h1>bla bla</h1>
      |<br><br>
ie 选择区域丢失
   ie 编辑器内 iframe文档失去焦点后,
    其选择区域/光标位置也随之丢失 。

   解决:
    ◦ 随时存储当前 range
    ◦ 即将获取焦点前(focusin)立即恢复
      range
Firefox 不可编辑问题
   Firefox 编辑器内 iframe 移动后(最
    大化),不可再编辑。

   解决:

    ◦ 重置 contenteditable 属性
3. KISSY Editor 的设计
 3.1 功能简介与 demo 演示
 3.2 总体架构
 3.3 插件机制
 3.4 动态加载机制
 3.5 定制插件开发
 3.6 设计模式的应用
3.1 功能介绍
功能介绍
3.2 总体架构

        Custom
        plugins


         Core
        plugins



       Editor core




       Kissy core
架构介绍
3.3 插件机制




   editor.addCommand(“image”,imageSupportObj);
插件实现分离机制
   插件的功能定义在 KISSY.Editor

    ◦ 插件功能类:
      KISSY.Editor.ColorDef.prototype.do=function(){}


    ◦ UI插件类
      KISSY.Editor.Overlay=function(){
      }
插件的实例应用
   插件最终要使用在实例上
    ◦ KISSY.Editor.use(“colordef”,function(){
       editor.addButton({
        click:function(){
         colorInstance.do();
        }
      });
  ◦ });
 实例的use即是应用插件的过程
    ◦ editor.use(“color”);
3.4 动态加载机制
   1. 插件窗口按需动态加载

   2.配置插件间的依赖关系图插件按需动
    态加载
3.5 定制插件开发
定制插件开发例子
   Sourcearea 与 bangpai-sourcearea



   调用execCommand
    editor.execCommand(“modeChange”
        ,”source”);
3.6 设计模式应用

   Do not repeat yourself !

   scalability
Template method
            Flash


   +gen()
   +getUrl() : string
   +getDemision() : object




            music


   +getUrl() : string
   +getDemision() : object
Visitor / filter

                      HtmlParser


    +parse(in html : string, in fragment : object)




                             Fragment


                  +onNode(in node : object)
                  +onElement(in el : object)
                  +onAttribute(in attr : object)
Observer-listener
   最常见
                                    Editor                 -subject
                -selectionChangeHanlders : object
                +on(in selectionChangeHanlder : object)
                                                           1
                +fire(in selectionChangeEvent : object)




                           *        -observer


                   SelectionChangeHanlder


    +onSelectionChange(in selectionChangeEvent : object)




                           Plugin


    +onSelectionChange(in selectionChangeEvent : object)
Command

                            Editor


        +addCommand(in cmd : string, in func : object)
        +execCommand(in cmd : string)




   复杂的操作用命令封装
   editor.addCommand(“align”,alignCmdObj);

   editor.execCommand(“align”,”left”);
4. 打包与部署
   4.1 源码概况

   4.2 使用工具

   4.3 最终部署
4.1 源码概况
   结构
4.2 使用工具




   Ant 粘合剂
4.3 部署
   静态引入
4.3 部署
     动态引入(combo加载)
      ◦ Kissy-seed.js

      KISSY.use(“editor”,function(S) {
           S.Editor(“#e”).use(“font,image,music”);
      });


Cdn combo 两阶段

http://a.tbcdn.cn/??kissy-core.js,editor/editor-core.js

http://a.tbcdn.cn/??
editor/plugins/font/plugin.js,editor/plugins/image/plugin.js
5.总结

   1. 再次回顾

   2. 与其他编辑器的比较

   3. 前景与展望
回顾
其他编辑器
   站在巨人肩上
    ◦ ckeditor , tinymce,google doc
前景与展望
   1. 更少代码完成80%的功能

   2. 触摸事件支持,加强Mobile设备

   3. Html5 代码生成,使用 video ,
    audio . 生成 header , nav , section ,
    加强标签语义 .
感谢
   Kissy editor 1.0 :玉伯

   视觉: 书安倾情奉献

   产品经理:向秋

   测试:小菊,南玲,周坤,黛霁
特别感谢
FAQ




 Email:yiminghe@gmail.com
 Blog: http://yiminghe.javaeye.com

More Related Content

PDF
05 MapKit and Text Input
Tom Fan
 
PDF
02 Objective-C
Tom Fan
 
PDF
合久必分,分久必合
Qiangning Hong
 
PDF
深入淺出 Web 容器 - Tomcat 原始碼分析
Justin Lin
 
PPTX
Script with engine
Webrebuild
 
PDF
OpenEJB - 另一個選擇
Justin Lin
 
PPTX
ES5 introduction
otakustay
 
DOC
Java华为面试题
yiditushe
 
05 MapKit and Text Input
Tom Fan
 
02 Objective-C
Tom Fan
 
合久必分,分久必合
Qiangning Hong
 
深入淺出 Web 容器 - Tomcat 原始碼分析
Justin Lin
 
Script with engine
Webrebuild
 
OpenEJB - 另一個選擇
Justin Lin
 
ES5 introduction
otakustay
 
Java华为面试题
yiditushe
 

What's hot (19)

PDF
论 Python 与设计模式。
勇浩 赖
 
PDF
14 Saving Loading and Application States
Tom Fan
 
PPT
页游开发中的 Python 组件与模式
勇浩 赖
 
PPT
J Query Learn
guestfb42fc
 
PPT
Osgi Intro
Ching Yi Chan
 
ODP
JavaScript Advanced Skill
firestoke
 
PDF
JCConf2015: groovy to gradle
Ching Yi Chan
 
PPTX
JavaScript 80+ Programming and Optimization Skills
Ho Kim
 
PDF
Java Thread
艾鍗科技
 
PDF
I os 09
信嘉 陳
 
PDF
Python 于 webgame 的应用
勇浩 赖
 
PPT
Underscore
cazhfe
 
PDF
16 CoreData
Tom Fan
 
PDF
Uliweb框架思想与编程
modou li
 
PPTX
前端测试
frontwindysky
 
PDF
Ejb工作原理学习笔记
yiditushe
 
PDF
JavaScript 教程
Bobby Zhou
 
PDF
潜力无限的编程语言Javascript
jay li
 
论 Python 与设计模式。
勇浩 赖
 
14 Saving Loading and Application States
Tom Fan
 
页游开发中的 Python 组件与模式
勇浩 赖
 
J Query Learn
guestfb42fc
 
Osgi Intro
Ching Yi Chan
 
JavaScript Advanced Skill
firestoke
 
JCConf2015: groovy to gradle
Ching Yi Chan
 
JavaScript 80+ Programming and Optimization Skills
Ho Kim
 
Java Thread
艾鍗科技
 
I os 09
信嘉 陳
 
Python 于 webgame 的应用
勇浩 赖
 
Underscore
cazhfe
 
16 CoreData
Tom Fan
 
Uliweb框架思想与编程
modou li
 
前端测试
frontwindysky
 
Ejb工作原理学习笔记
yiditushe
 
JavaScript 教程
Bobby Zhou
 
潜力无限的编程语言Javascript
jay li
 
Ad

Similar to Kissy editor开发与设计 (20)

PDF
KISSY Editor Design 2
yiming he
 
PDF
编辑器设计Kissy editor
taobao.com
 
PDF
编辑器设计2
yiming he
 
PDF
KISSY for starter
yiming he
 
PPT
编辑器设计U editor
taobao.com
 
PDF
Kind editor设计思路
taobao.com
 
PDF
Dive into kissy
jay li
 
PPT
Kindeditor 设计思路
luolonghao
 
PDF
Kissy简介
jay li
 
PDF
Kissy in-progress
yiming he
 
PDF
Kindeditor设计思路v2
luolonghao
 
PPT
富文本编辑器在互联网上的应用
luolonghao
 
PDF
Kissy design
yiming he
 
PPT
前端开发之Js
fangdeng
 
PDF
Browser Object Model
jay li
 
PDF
KISSY 1.3-released
yiming he
 
PDF
Kissy模块化实践
yiming he
 
PPTX
HTML5 介绍
S S
 
DOC
淘宝网前端开发面试题
Lumend
 
PDF
Inspector&j query slide
Ronald Hsu
 
KISSY Editor Design 2
yiming he
 
编辑器设计Kissy editor
taobao.com
 
编辑器设计2
yiming he
 
KISSY for starter
yiming he
 
编辑器设计U editor
taobao.com
 
Kind editor设计思路
taobao.com
 
Dive into kissy
jay li
 
Kindeditor 设计思路
luolonghao
 
Kissy简介
jay li
 
Kissy in-progress
yiming he
 
Kindeditor设计思路v2
luolonghao
 
富文本编辑器在互联网上的应用
luolonghao
 
Kissy design
yiming he
 
前端开发之Js
fangdeng
 
Browser Object Model
jay li
 
KISSY 1.3-released
yiming he
 
Kissy模块化实践
yiming he
 
HTML5 介绍
S S
 
淘宝网前端开发面试题
Lumend
 
Inspector&j query slide
Ronald Hsu
 
Ad

More from yiming he (20)

PDF
kissy 1.5 progress
yiming he
 
PDF
kissy at alibaba
yiming he
 
PDF
kissy modularization part2
yiming he
 
PDF
kissy modularization part1
yiming he
 
PDF
KISSY @ 2013-2
yiming he
 
PDF
KISSY 1.4.0 released
yiming he
 
PDF
callSuper in kissy
yiming he
 
PDF
KISSY XTemplate
yiming he
 
PDF
Introduction to kissy for adc 2013
yiming he
 
PDF
Kissy component system
yiming he
 
PDF
kissy@2013
yiming he
 
PDF
Simple kissy1.3
yiming he
 
PDF
Hujs 总结
yiming he
 
PDF
Kissy dpl-practice
yiming he
 
PDF
KISSY Component API Design
yiming he
 
PDF
Kissy autocomplete
yiming he
 
PDF
KISSY_Component
yiming he
 
PDF
kissy-past-now-future
yiming he
 
kissy 1.5 progress
yiming he
 
kissy at alibaba
yiming he
 
kissy modularization part2
yiming he
 
kissy modularization part1
yiming he
 
KISSY @ 2013-2
yiming he
 
KISSY 1.4.0 released
yiming he
 
callSuper in kissy
yiming he
 
KISSY XTemplate
yiming he
 
Introduction to kissy for adc 2013
yiming he
 
Kissy component system
yiming he
 
kissy@2013
yiming he
 
Simple kissy1.3
yiming he
 
Hujs 总结
yiming he
 
Kissy dpl-practice
yiming he
 
KISSY Component API Design
yiming he
 
Kissy autocomplete
yiming he
 
KISSY_Component
yiming he
 
kissy-past-now-future
yiming he
 

Kissy editor开发与设计

  • 1. Kissy editor 介绍 何一鸣(承玉@taobao)
  • 2. About me  2003 - 2010 Fudan CS  2010.07 - F2E @ Taobao  目前开发维护 kissy editor
  • 3. 大纲  1. 编辑器的分类  2. 编辑器的实现  3. KISSY Editor的设计  4. 打包与部署  5. 总结与前景展望
  • 8. 2. 编辑器的实现  创建 iframe 元素,设置 body 属性 contenteditable为 true  方法 ◦ 调用 execCommand ◦ Range 自主实现  实现注意
  • 9. 2.1 调用 execCommand  ie 4.0 引入  bSuccess = object.execCommand(sCommand[,bUserInterface][,vValue]) ◦ sCommand : 命令名 ◦ bUserInterface : 用户界面提示 ◦ vValue : 命令参数
  • 10. execCommand 例子  加粗当前选择文字 ◦ document.execCommand("bold",null,false);  添加链接 ◦ 直接添加  document.execCommand("createlink", null,"http://www.g.cn"); ◦ 弹窗提示用户输入  document.execCommand("createlink", true);
  • 11. execCommand 问题 ◦ 代码生成不一致  行内格式化  ie 会生成 font 标签  <font color=“#ff0000”>x</font>  safari 生成私有 class  <span class=“Apple-style-span” style=“font-weight:bold;”>x</span> ◦ 能力不一致  Createlink  Firefox 不支持用户界面提示  自己 window.prompt
  • 14. 2.2 Range 自主实现  使用 range 实现 execCommand 对等 功能。 ◦ Range api (w3c , ie)
  • 15. W3c Range  用来获取光标或选择区域信息  W3c api  Interface Range { ◦ Node startContainer ◦ Long startOffset ◦ Node endContainer ◦ Long endOffset  }
  • 16. IE Range  ControlRange ◦ 选取整个元素 (div,img,object) ◦ Item (index) : 获取选中元素节点  TextRange ◦ 获取选中的文本区域 ◦ Text : 选中的文本串值 ◦ parentElement() : ◦ compareEndPoints() ◦ moveToElementText()
  • 17. Do not hurt web
  • 18. 实现 execCommand  Range + Dom2 + Dtd = execCommand
  • 19. Dtd 的作用  标签格式化系统需要考虑标签嵌套规则  根据 dtd 以及格式标签进行 Range 的 拆分!
  • 20. Dtd 例子  加粗 ◦ ^<p>line</p><p>line2</p>^ ◦ 错误:  <strong><p>line</p><p>line2</p> </strong> ◦ 正确:  <p><strong>line<strong></p> <p><strong>line2</strong></p>
  • 21. 2.3 常见问题  换行代码生成差异  ie 选择区域丢失问题  Firefox 不可编辑问题  光标定位问题…..
  • 22. Enter 换行差异 ◦ <h1>bla bla^</h1> 末尾换行  ie  <h1>bla bla</h1> <p>|</p>  Safari  <h1>bla bla</h1> <h1>|</h1>  Firefox  <h1>bla bla</h1> |<br><br>
  • 23. ie 选择区域丢失  ie 编辑器内 iframe文档失去焦点后, 其选择区域/光标位置也随之丢失 。  解决: ◦ 随时存储当前 range ◦ 即将获取焦点前(focusin)立即恢复 range
  • 24. Firefox 不可编辑问题  Firefox 编辑器内 iframe 移动后(最 大化),不可再编辑。  解决: ◦ 重置 contenteditable 属性
  • 25. 3. KISSY Editor 的设计  3.1 功能简介与 demo 演示  3.2 总体架构  3.3 插件机制  3.4 动态加载机制  3.5 定制插件开发  3.6 设计模式的应用
  • 28. 3.2 总体架构 Custom plugins Core plugins Editor core Kissy core
  • 30. 3.3 插件机制  editor.addCommand(“image”,imageSupportObj);
  • 31. 插件实现分离机制  插件的功能定义在 KISSY.Editor ◦ 插件功能类:  KISSY.Editor.ColorDef.prototype.do=function(){} ◦ UI插件类  KISSY.Editor.Overlay=function(){  }
  • 32. 插件的实例应用  插件最终要使用在实例上 ◦ KISSY.Editor.use(“colordef”,function(){  editor.addButton({  click:function(){  colorInstance.do();  }  }); ◦ });  实例的use即是应用插件的过程 ◦ editor.use(“color”);
  • 33. 3.4 动态加载机制  1. 插件窗口按需动态加载  2.配置插件间的依赖关系图插件按需动 态加载
  • 35. 定制插件开发例子  Sourcearea 与 bangpai-sourcearea  调用execCommand editor.execCommand(“modeChange” ,”source”);
  • 36. 3.6 设计模式应用  Do not repeat yourself !  scalability
  • 37. Template method Flash +gen() +getUrl() : string +getDemision() : object music +getUrl() : string +getDemision() : object
  • 38. Visitor / filter HtmlParser +parse(in html : string, in fragment : object) Fragment +onNode(in node : object) +onElement(in el : object) +onAttribute(in attr : object)
  • 39. Observer-listener  最常见 Editor -subject -selectionChangeHanlders : object +on(in selectionChangeHanlder : object) 1 +fire(in selectionChangeEvent : object) * -observer SelectionChangeHanlder +onSelectionChange(in selectionChangeEvent : object) Plugin +onSelectionChange(in selectionChangeEvent : object)
  • 40. Command Editor +addCommand(in cmd : string, in func : object) +execCommand(in cmd : string)  复杂的操作用命令封装  editor.addCommand(“align”,alignCmdObj);  editor.execCommand(“align”,”left”);
  • 41. 4. 打包与部署  4.1 源码概况  4.2 使用工具  4.3 最终部署
  • 43. 4.2 使用工具  Ant 粘合剂
  • 44. 4.3 部署  静态引入
  • 45. 4.3 部署  动态引入(combo加载) ◦ Kissy-seed.js KISSY.use(“editor”,function(S) { S.Editor(“#e”).use(“font,image,music”); }); Cdn combo 两阶段 http://a.tbcdn.cn/??kissy-core.js,editor/editor-core.js http://a.tbcdn.cn/?? editor/plugins/font/plugin.js,editor/plugins/image/plugin.js
  • 46. 5.总结  1. 再次回顾  2. 与其他编辑器的比较  3. 前景与展望
  • 48. 其他编辑器  站在巨人肩上 ◦ ckeditor , tinymce,google doc
  • 49. 前景与展望  1. 更少代码完成80%的功能  2. 触摸事件支持,加强Mobile设备  3. Html5 代码生成,使用 video , audio . 生成 header , nav , section , 加强标签语义 .
  • 50. 感谢  Kissy editor 1.0 :玉伯  视觉: 书安倾情奉献  产品经理:向秋  测试:小菊,南玲,周坤,黛霁
  • 52. FAQ  Email:[email protected]  Blog: http://yiminghe.javaeye.com