rails_kindeditor 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (206) hide show
  1. data/README.rdoc +14 -99
  2. data/lib/generators/rails_kindeditor/install/install_generator.rb +2 -2
  3. data/lib/generators/rails_kindeditor/install/templates/kindeditor/kindeditor-min.js +165 -158
  4. data/lib/generators/rails_kindeditor/install/templates/kindeditor/lang/en.js +210 -208
  5. data/lib/generators/rails_kindeditor/install/templates/kindeditor/lang/zh_CN.js +214 -210
  6. data/lib/generators/rails_kindeditor/install/templates/kindeditor/lang/zh_TW.js +212 -210
  7. data/lib/generators/rails_kindeditor/install/templates/kindeditor/plugins/anchor/anchor.js +46 -0
  8. data/lib/generators/rails_kindeditor/install/templates/kindeditor/plugins/clearhtml/clearhtml.js +29 -28
  9. data/lib/generators/rails_kindeditor/install/templates/kindeditor/plugins/filemanager/filemanager.js +185 -189
  10. data/lib/generators/rails_kindeditor/install/templates/kindeditor/plugins/flash/flash.js +145 -128
  11. data/lib/generators/rails_kindeditor/install/templates/kindeditor/plugins/image/image.js +242 -226
  12. data/lib/generators/rails_kindeditor/install/templates/kindeditor/plugins/insertfile/insertfile.js +109 -104
  13. data/lib/generators/rails_kindeditor/install/templates/kindeditor/plugins/link/link.js +65 -59
  14. data/lib/generators/rails_kindeditor/install/templates/kindeditor/plugins/map/map.js +137 -135
  15. data/lib/generators/rails_kindeditor/install/templates/kindeditor/plugins/media/media.js +153 -136
  16. data/lib/generators/rails_kindeditor/install/templates/kindeditor/plugins/pagebreak/pagebreak.js +26 -26
  17. data/lib/generators/rails_kindeditor/install/templates/kindeditor/plugins/table/table.js +715 -661
  18. data/lib/generators/rails_kindeditor/install/templates/kindeditor/plugins/wordpaste/wordpaste.js +51 -57
  19. data/lib/generators/rails_kindeditor/install/templates/kindeditor/themes/common/anchor.gif +0 -0
  20. data/lib/generators/rails_kindeditor/install/templates/kindeditor/themes/default/default.css +980 -941
  21. data/lib/generators/rails_kindeditor/install/templates/kindeditor/themes/default/default.gif +0 -0
  22. data/lib/rails_kindeditor/helper.rb +9 -10
  23. data/lib/rails_kindeditor/version.rb +1 -1
  24. metadata +29 -231
  25. data/vendor/assets/javascripts/kindeditor.js +0 -158
  26. data/vendor/assets/javascripts/lang/en.js +0 -208
  27. data/vendor/assets/javascripts/lang/zh_CN.js +0 -210
  28. data/vendor/assets/javascripts/lang/zh_TW.js +0 -210
  29. data/vendor/assets/javascripts/plugins/clearhtml/clearhtml.js +0 -28
  30. data/vendor/assets/javascripts/plugins/code/code.js +0 -57
  31. data/vendor/assets/javascripts/plugins/code/prettify.css +0 -13
  32. data/vendor/assets/javascripts/plugins/code/prettify.js +0 -28
  33. data/vendor/assets/javascripts/plugins/emoticons/emoticons.js +0 -129
  34. data/vendor/assets/javascripts/plugins/emoticons/images/0.gif +0 -0
  35. data/vendor/assets/javascripts/plugins/emoticons/images/1.gif +0 -0
  36. data/vendor/assets/javascripts/plugins/emoticons/images/10.gif +0 -0
  37. data/vendor/assets/javascripts/plugins/emoticons/images/100.gif +0 -0
  38. data/vendor/assets/javascripts/plugins/emoticons/images/101.gif +0 -0
  39. data/vendor/assets/javascripts/plugins/emoticons/images/102.gif +0 -0
  40. data/vendor/assets/javascripts/plugins/emoticons/images/103.gif +0 -0
  41. data/vendor/assets/javascripts/plugins/emoticons/images/104.gif +0 -0
  42. data/vendor/assets/javascripts/plugins/emoticons/images/105.gif +0 -0
  43. data/vendor/assets/javascripts/plugins/emoticons/images/106.gif +0 -0
  44. data/vendor/assets/javascripts/plugins/emoticons/images/107.gif +0 -0
  45. data/vendor/assets/javascripts/plugins/emoticons/images/108.gif +0 -0
  46. data/vendor/assets/javascripts/plugins/emoticons/images/109.gif +0 -0
  47. data/vendor/assets/javascripts/plugins/emoticons/images/11.gif +0 -0
  48. data/vendor/assets/javascripts/plugins/emoticons/images/110.gif +0 -0
  49. data/vendor/assets/javascripts/plugins/emoticons/images/111.gif +0 -0
  50. data/vendor/assets/javascripts/plugins/emoticons/images/112.gif +0 -0
  51. data/vendor/assets/javascripts/plugins/emoticons/images/113.gif +0 -0
  52. data/vendor/assets/javascripts/plugins/emoticons/images/114.gif +0 -0
  53. data/vendor/assets/javascripts/plugins/emoticons/images/115.gif +0 -0
  54. data/vendor/assets/javascripts/plugins/emoticons/images/116.gif +0 -0
  55. data/vendor/assets/javascripts/plugins/emoticons/images/117.gif +0 -0
  56. data/vendor/assets/javascripts/plugins/emoticons/images/118.gif +0 -0
  57. data/vendor/assets/javascripts/plugins/emoticons/images/119.gif +0 -0
  58. data/vendor/assets/javascripts/plugins/emoticons/images/12.gif +0 -0
  59. data/vendor/assets/javascripts/plugins/emoticons/images/120.gif +0 -0
  60. data/vendor/assets/javascripts/plugins/emoticons/images/121.gif +0 -0
  61. data/vendor/assets/javascripts/plugins/emoticons/images/122.gif +0 -0
  62. data/vendor/assets/javascripts/plugins/emoticons/images/123.gif +0 -0
  63. data/vendor/assets/javascripts/plugins/emoticons/images/124.gif +0 -0
  64. data/vendor/assets/javascripts/plugins/emoticons/images/125.gif +0 -0
  65. data/vendor/assets/javascripts/plugins/emoticons/images/126.gif +0 -0
  66. data/vendor/assets/javascripts/plugins/emoticons/images/127.gif +0 -0
  67. data/vendor/assets/javascripts/plugins/emoticons/images/128.gif +0 -0
  68. data/vendor/assets/javascripts/plugins/emoticons/images/129.gif +0 -0
  69. data/vendor/assets/javascripts/plugins/emoticons/images/13.gif +0 -0
  70. data/vendor/assets/javascripts/plugins/emoticons/images/130.gif +0 -0
  71. data/vendor/assets/javascripts/plugins/emoticons/images/131.gif +0 -0
  72. data/vendor/assets/javascripts/plugins/emoticons/images/132.gif +0 -0
  73. data/vendor/assets/javascripts/plugins/emoticons/images/133.gif +0 -0
  74. data/vendor/assets/javascripts/plugins/emoticons/images/134.gif +0 -0
  75. data/vendor/assets/javascripts/plugins/emoticons/images/14.gif +0 -0
  76. data/vendor/assets/javascripts/plugins/emoticons/images/15.gif +0 -0
  77. data/vendor/assets/javascripts/plugins/emoticons/images/16.gif +0 -0
  78. data/vendor/assets/javascripts/plugins/emoticons/images/17.gif +0 -0
  79. data/vendor/assets/javascripts/plugins/emoticons/images/18.gif +0 -0
  80. data/vendor/assets/javascripts/plugins/emoticons/images/19.gif +0 -0
  81. data/vendor/assets/javascripts/plugins/emoticons/images/2.gif +0 -0
  82. data/vendor/assets/javascripts/plugins/emoticons/images/20.gif +0 -0
  83. data/vendor/assets/javascripts/plugins/emoticons/images/21.gif +0 -0
  84. data/vendor/assets/javascripts/plugins/emoticons/images/22.gif +0 -0
  85. data/vendor/assets/javascripts/plugins/emoticons/images/23.gif +0 -0
  86. data/vendor/assets/javascripts/plugins/emoticons/images/24.gif +0 -0
  87. data/vendor/assets/javascripts/plugins/emoticons/images/25.gif +0 -0
  88. data/vendor/assets/javascripts/plugins/emoticons/images/26.gif +0 -0
  89. data/vendor/assets/javascripts/plugins/emoticons/images/27.gif +0 -0
  90. data/vendor/assets/javascripts/plugins/emoticons/images/28.gif +0 -0
  91. data/vendor/assets/javascripts/plugins/emoticons/images/29.gif +0 -0
  92. data/vendor/assets/javascripts/plugins/emoticons/images/3.gif +0 -0
  93. data/vendor/assets/javascripts/plugins/emoticons/images/30.gif +0 -0
  94. data/vendor/assets/javascripts/plugins/emoticons/images/31.gif +0 -0
  95. data/vendor/assets/javascripts/plugins/emoticons/images/32.gif +0 -0
  96. data/vendor/assets/javascripts/plugins/emoticons/images/33.gif +0 -0
  97. data/vendor/assets/javascripts/plugins/emoticons/images/34.gif +0 -0
  98. data/vendor/assets/javascripts/plugins/emoticons/images/35.gif +0 -0
  99. data/vendor/assets/javascripts/plugins/emoticons/images/36.gif +0 -0
  100. data/vendor/assets/javascripts/plugins/emoticons/images/37.gif +0 -0
  101. data/vendor/assets/javascripts/plugins/emoticons/images/38.gif +0 -0
  102. data/vendor/assets/javascripts/plugins/emoticons/images/39.gif +0 -0
  103. data/vendor/assets/javascripts/plugins/emoticons/images/4.gif +0 -0
  104. data/vendor/assets/javascripts/plugins/emoticons/images/40.gif +0 -0
  105. data/vendor/assets/javascripts/plugins/emoticons/images/41.gif +0 -0
  106. data/vendor/assets/javascripts/plugins/emoticons/images/42.gif +0 -0
  107. data/vendor/assets/javascripts/plugins/emoticons/images/43.gif +0 -0
  108. data/vendor/assets/javascripts/plugins/emoticons/images/44.gif +0 -0
  109. data/vendor/assets/javascripts/plugins/emoticons/images/45.gif +0 -0
  110. data/vendor/assets/javascripts/plugins/emoticons/images/46.gif +0 -0
  111. data/vendor/assets/javascripts/plugins/emoticons/images/47.gif +0 -0
  112. data/vendor/assets/javascripts/plugins/emoticons/images/48.gif +0 -0
  113. data/vendor/assets/javascripts/plugins/emoticons/images/49.gif +0 -0
  114. data/vendor/assets/javascripts/plugins/emoticons/images/5.gif +0 -0
  115. data/vendor/assets/javascripts/plugins/emoticons/images/50.gif +0 -0
  116. data/vendor/assets/javascripts/plugins/emoticons/images/51.gif +0 -0
  117. data/vendor/assets/javascripts/plugins/emoticons/images/52.gif +0 -0
  118. data/vendor/assets/javascripts/plugins/emoticons/images/53.gif +0 -0
  119. data/vendor/assets/javascripts/plugins/emoticons/images/54.gif +0 -0
  120. data/vendor/assets/javascripts/plugins/emoticons/images/55.gif +0 -0
  121. data/vendor/assets/javascripts/plugins/emoticons/images/56.gif +0 -0
  122. data/vendor/assets/javascripts/plugins/emoticons/images/57.gif +0 -0
  123. data/vendor/assets/javascripts/plugins/emoticons/images/58.gif +0 -0
  124. data/vendor/assets/javascripts/plugins/emoticons/images/59.gif +0 -0
  125. data/vendor/assets/javascripts/plugins/emoticons/images/6.gif +0 -0
  126. data/vendor/assets/javascripts/plugins/emoticons/images/60.gif +0 -0
  127. data/vendor/assets/javascripts/plugins/emoticons/images/61.gif +0 -0
  128. data/vendor/assets/javascripts/plugins/emoticons/images/62.gif +0 -0
  129. data/vendor/assets/javascripts/plugins/emoticons/images/63.gif +0 -0
  130. data/vendor/assets/javascripts/plugins/emoticons/images/64.gif +0 -0
  131. data/vendor/assets/javascripts/plugins/emoticons/images/65.gif +0 -0
  132. data/vendor/assets/javascripts/plugins/emoticons/images/66.gif +0 -0
  133. data/vendor/assets/javascripts/plugins/emoticons/images/67.gif +0 -0
  134. data/vendor/assets/javascripts/plugins/emoticons/images/68.gif +0 -0
  135. data/vendor/assets/javascripts/plugins/emoticons/images/69.gif +0 -0
  136. data/vendor/assets/javascripts/plugins/emoticons/images/7.gif +0 -0
  137. data/vendor/assets/javascripts/plugins/emoticons/images/70.gif +0 -0
  138. data/vendor/assets/javascripts/plugins/emoticons/images/71.gif +0 -0
  139. data/vendor/assets/javascripts/plugins/emoticons/images/72.gif +0 -0
  140. data/vendor/assets/javascripts/plugins/emoticons/images/73.gif +0 -0
  141. data/vendor/assets/javascripts/plugins/emoticons/images/74.gif +0 -0
  142. data/vendor/assets/javascripts/plugins/emoticons/images/75.gif +0 -0
  143. data/vendor/assets/javascripts/plugins/emoticons/images/76.gif +0 -0
  144. data/vendor/assets/javascripts/plugins/emoticons/images/77.gif +0 -0
  145. data/vendor/assets/javascripts/plugins/emoticons/images/78.gif +0 -0
  146. data/vendor/assets/javascripts/plugins/emoticons/images/79.gif +0 -0
  147. data/vendor/assets/javascripts/plugins/emoticons/images/8.gif +0 -0
  148. data/vendor/assets/javascripts/plugins/emoticons/images/80.gif +0 -0
  149. data/vendor/assets/javascripts/plugins/emoticons/images/81.gif +0 -0
  150. data/vendor/assets/javascripts/plugins/emoticons/images/82.gif +0 -0
  151. data/vendor/assets/javascripts/plugins/emoticons/images/83.gif +0 -0
  152. data/vendor/assets/javascripts/plugins/emoticons/images/84.gif +0 -0
  153. data/vendor/assets/javascripts/plugins/emoticons/images/85.gif +0 -0
  154. data/vendor/assets/javascripts/plugins/emoticons/images/86.gif +0 -0
  155. data/vendor/assets/javascripts/plugins/emoticons/images/87.gif +0 -0
  156. data/vendor/assets/javascripts/plugins/emoticons/images/88.gif +0 -0
  157. data/vendor/assets/javascripts/plugins/emoticons/images/89.gif +0 -0
  158. data/vendor/assets/javascripts/plugins/emoticons/images/9.gif +0 -0
  159. data/vendor/assets/javascripts/plugins/emoticons/images/90.gif +0 -0
  160. data/vendor/assets/javascripts/plugins/emoticons/images/91.gif +0 -0
  161. data/vendor/assets/javascripts/plugins/emoticons/images/92.gif +0 -0
  162. data/vendor/assets/javascripts/plugins/emoticons/images/93.gif +0 -0
  163. data/vendor/assets/javascripts/plugins/emoticons/images/94.gif +0 -0
  164. data/vendor/assets/javascripts/plugins/emoticons/images/95.gif +0 -0
  165. data/vendor/assets/javascripts/plugins/emoticons/images/96.gif +0 -0
  166. data/vendor/assets/javascripts/plugins/emoticons/images/97.gif +0 -0
  167. data/vendor/assets/javascripts/plugins/emoticons/images/98.gif +0 -0
  168. data/vendor/assets/javascripts/plugins/emoticons/images/99.gif +0 -0
  169. data/vendor/assets/javascripts/plugins/emoticons/images/static.gif +0 -0
  170. data/vendor/assets/javascripts/plugins/filemanager/filemanager.js +0 -189
  171. data/vendor/assets/javascripts/plugins/filemanager/images/file-16.gif +0 -0
  172. data/vendor/assets/javascripts/plugins/filemanager/images/file-64.gif +0 -0
  173. data/vendor/assets/javascripts/plugins/filemanager/images/folder-16.gif +0 -0
  174. data/vendor/assets/javascripts/plugins/filemanager/images/folder-64.gif +0 -0
  175. data/vendor/assets/javascripts/plugins/filemanager/images/go-up.gif +0 -0
  176. data/vendor/assets/javascripts/plugins/flash/flash.js +0 -128
  177. data/vendor/assets/javascripts/plugins/image/image.js +0 -226
  178. data/vendor/assets/javascripts/plugins/image/images/align_left.gif +0 -0
  179. data/vendor/assets/javascripts/plugins/image/images/align_right.gif +0 -0
  180. data/vendor/assets/javascripts/plugins/image/images/align_top.gif +0 -0
  181. data/vendor/assets/javascripts/plugins/image/images/refresh.gif +0 -0
  182. data/vendor/assets/javascripts/plugins/insertfile/insertfile.js +0 -104
  183. data/vendor/assets/javascripts/plugins/lineheight/lineheight.js +0 -38
  184. data/vendor/assets/javascripts/plugins/link/link.js +0 -59
  185. data/vendor/assets/javascripts/plugins/map/map.html +0 -57
  186. data/vendor/assets/javascripts/plugins/map/map.js +0 -135
  187. data/vendor/assets/javascripts/plugins/media/media.js +0 -136
  188. data/vendor/assets/javascripts/plugins/pagebreak/pagebreak.js +0 -26
  189. data/vendor/assets/javascripts/plugins/plainpaste/plainpaste.js +0 -41
  190. data/vendor/assets/javascripts/plugins/preview/preview.js +0 -31
  191. data/vendor/assets/javascripts/plugins/quickformat/quickformat.js +0 -71
  192. data/vendor/assets/javascripts/plugins/table/table.js +0 -661
  193. data/vendor/assets/javascripts/plugins/template/html/1.html +0 -14
  194. data/vendor/assets/javascripts/plugins/template/html/2.html +0 -42
  195. data/vendor/assets/javascripts/plugins/template/html/3.html +0 -36
  196. data/vendor/assets/javascripts/plugins/template/template.js +0 -58
  197. data/vendor/assets/javascripts/plugins/wordpaste/wordpaste.js +0 -57
  198. data/vendor/assets/stylesheets/bg.gif +0 -0
  199. data/vendor/assets/stylesheets/default.gif +0 -0
  200. data/vendor/assets/stylesheets/kindeditor.css +0 -942
  201. data/vendor/assets/stylesheets/themes/common/blank.gif +0 -0
  202. data/vendor/assets/stylesheets/themes/common/flash.gif +0 -0
  203. data/vendor/assets/stylesheets/themes/common/loading.gif +0 -0
  204. data/vendor/assets/stylesheets/themes/common/media.gif +0 -0
  205. data/vendor/assets/stylesheets/themes/common/rm.gif +0 -0
  206. data/vendor/assets/stylesheets/themes/simple/simple.css +0 -148
@@ -1,136 +1,153 @@
1
- /*******************************************************************************
2
- * KindEditor - WYSIWYG HTML Editor for Internet
3
- * Copyright (C) 2006-2011 kindsoft.net
4
- *
5
- * @author Roddy <luolonghao@gmail.com>
6
- * @site http://www.kindsoft.net/
7
- * @licence http://www.kindsoft.net/license.php
8
- *******************************************************************************/
9
-
10
- KindEditor.plugin('media', function(K) {
11
- var self = this, name = 'media', lang = self.lang(name + '.'),
12
- allowMediaUpload = K.undef(self.allowMediaUpload, true),
13
- allowFileManager = K.undef(self.allowFileManager, false),
14
- uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
15
- self.plugin.media = {
16
- edit : function() {
17
- var html = [
18
- '<div style="padding:10px 20px;">',
19
- //url
20
- '<div class="ke-dialog-row">',
21
- '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
22
- '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
23
- '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
24
- '<span class="ke-button-common ke-button-outer">',
25
- '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
26
- '</span>',
27
- '</div>',
28
- //width
29
- '<div class="ke-dialog-row">',
30
- '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
31
- '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" />',
32
- '</div>',
33
- //height
34
- '<div class="ke-dialog-row">',
35
- '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
36
- '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" />',
37
- '</div>',
38
- //autostart
39
- '<div class="ke-dialog-row">',
40
- '<label for="keAutostart">' + lang.autostart + '</label>',
41
- '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
42
- '</div>',
43
- '</div>'
44
- ].join('');
45
- var dialog = self.createDialog({
46
- name : name,
47
- width : 450,
48
- height : 230,
49
- title : self.lang(name),
50
- body : html,
51
- yesBtn : {
52
- name : self.lang('yes'),
53
- click : function(e) {
54
- var url = urlBox.val(),
55
- html = K.mediaImg(self.themesPath + 'common/blank.gif', {
56
- src : url,
57
- type : K.mediaType(url),
58
- width : widthBox.val(),
59
- height : heightBox.val(),
60
- autostart : autostartBox[0].checked ? 'true' : 'false',
61
- loop : 'true'
62
- });
63
- self.insertHtml(html).hideDialog().focus();
64
- }
65
- }
66
- }),
67
- div = dialog.div,
68
- urlBox = K('[name="url"]', div),
69
- viewServerBtn = K('[name="viewServer"]', div),
70
- widthBox = K('[name="width"]', div),
71
- heightBox = K('[name="height"]', div),
72
- autostartBox = K('[name="autostart"]', div);
73
- urlBox.val('http://');
74
-
75
- if (allowMediaUpload) {
76
- var uploadbutton = K.uploadbutton({
77
- button : K('.ke-upload-button', div)[0],
78
- fieldName : 'imgFile',
79
- url : uploadJson + '?dir=media',
80
- afterUpload : function(data) {
81
- if (data.error === 0) {
82
- var url = K.formatUrl(data.url, 'absolute');
83
- urlBox.val(url);
84
- if (self.afterUpload) {
85
- self.afterUpload.call(self, url);
86
- }
87
- alert(self.lang('uploadSuccess'));
88
- } else {
89
- alert(data.message);
90
- }
91
- }
92
- });
93
- uploadbutton.fileBox.change(function(e) {
94
- uploadbutton.submit();
95
- });
96
- } else {
97
- K('.ke-upload-button', div).hide();
98
- urlBox.width(250);
99
- }
100
-
101
- if (allowFileManager) {
102
- viewServerBtn.click(function(e) {
103
- self.loadPlugin('filemanager', function() {
104
- self.plugin.filemanagerDialog({
105
- viewType : 'LIST',
106
- dirName : 'media',
107
- clickFn : function(url, title) {
108
- if (self.dialogs.length > 1) {
109
- K('[name="url"]', div).val(url);
110
- self.hideDialog();
111
- }
112
- }
113
- });
114
- });
115
- });
116
- } else {
117
- viewServerBtn.hide();
118
- }
119
-
120
- var img = self.plugin.getSelectedMedia();
121
- if (img) {
122
- var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
123
- urlBox.val(attrs.src);
124
- widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
125
- heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
126
- autostartBox[0].checked = (attrs.autostart === 'true');
127
- }
128
- urlBox[0].focus();
129
- urlBox[0].select();
130
- },
131
- 'delete' : function() {
132
- self.plugin.getSelectedMedia().remove();
133
- }
134
- };
135
- self.clickToolbar(name, self.plugin.media.edit);
136
- });
1
+ /*******************************************************************************
2
+ * KindEditor - WYSIWYG HTML Editor for Internet
3
+ * Copyright (C) 2006-2011 kindsoft.net
4
+ *
5
+ * @author Roddy <luolonghao@gmail.com>
6
+ * @site http://www.kindsoft.net/
7
+ * @licence http://www.kindsoft.net/license.php
8
+ *******************************************************************************/
9
+
10
+ KindEditor.plugin('media', function(K) {
11
+ var self = this, name = 'media', lang = self.lang(name + '.'),
12
+ allowMediaUpload = K.undef(self.allowMediaUpload, true),
13
+ allowFileManager = K.undef(self.allowFileManager, false),
14
+ uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
15
+ self.plugin.media = {
16
+ edit : function() {
17
+ var html = [
18
+ '<div style="padding:10px 20px;">',
19
+ //url
20
+ '<div class="ke-dialog-row">',
21
+ '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
22
+ '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
23
+ '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
24
+ '<span class="ke-button-common ke-button-outer">',
25
+ '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
26
+ '</span>',
27
+ '</div>',
28
+ //width
29
+ '<div class="ke-dialog-row">',
30
+ '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
31
+ '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" />',
32
+ '</div>',
33
+ //height
34
+ '<div class="ke-dialog-row">',
35
+ '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
36
+ '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" />',
37
+ '</div>',
38
+ //autostart
39
+ '<div class="ke-dialog-row">',
40
+ '<label for="keAutostart">' + lang.autostart + '</label>',
41
+ '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
42
+ '</div>',
43
+ '</div>'
44
+ ].join('');
45
+ var dialog = self.createDialog({
46
+ name : name,
47
+ width : 450,
48
+ height : 230,
49
+ title : self.lang(name),
50
+ body : html,
51
+ yesBtn : {
52
+ name : self.lang('yes'),
53
+ click : function(e) {
54
+ var url = K.trim(urlBox.val()),
55
+ width = widthBox.val(),
56
+ height = heightBox.val();
57
+ if (url == 'http://' || K.invalidUrl(url)) {
58
+ alert(self.lang('invalidUrl'));
59
+ urlBox[0].focus();
60
+ return;
61
+ }
62
+ if (!/^\d*$/.test(width)) {
63
+ alert(self.lang('invalidWidth'));
64
+ widthBox[0].focus();
65
+ return;
66
+ }
67
+ if (!/^\d*$/.test(height)) {
68
+ alert(self.lang('invalidHeight'));
69
+ heightBox[0].focus();
70
+ return;
71
+ }
72
+ var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
73
+ src : url,
74
+ type : K.mediaType(url),
75
+ width : width,
76
+ height : height,
77
+ autostart : autostartBox[0].checked ? 'true' : 'false',
78
+ loop : 'true'
79
+ });
80
+ self.insertHtml(html).hideDialog().focus();
81
+ }
82
+ }
83
+ }),
84
+ div = dialog.div,
85
+ urlBox = K('[name="url"]', div),
86
+ viewServerBtn = K('[name="viewServer"]', div),
87
+ widthBox = K('[name="width"]', div),
88
+ heightBox = K('[name="height"]', div),
89
+ autostartBox = K('[name="autostart"]', div);
90
+ urlBox.val('http://');
91
+
92
+ if (allowMediaUpload) {
93
+ var uploadbutton = K.uploadbutton({
94
+ button : K('.ke-upload-button', div)[0],
95
+ fieldName : 'imgFile',
96
+ url : K.addParam(uploadJson, 'dir=media'),
97
+ afterUpload : function(data) {
98
+ if (data.error === 0) {
99
+ var url = K.formatUrl(data.url, 'absolute');
100
+ urlBox.val(url);
101
+ if (self.afterUpload) {
102
+ self.afterUpload.call(self, url);
103
+ }
104
+ alert(self.lang('uploadSuccess'));
105
+ } else {
106
+ alert(data.message);
107
+ }
108
+ }
109
+ });
110
+ uploadbutton.fileBox.change(function(e) {
111
+ uploadbutton.submit();
112
+ });
113
+ } else {
114
+ K('.ke-upload-button', div).hide();
115
+ urlBox.width(250);
116
+ }
117
+
118
+ if (allowFileManager) {
119
+ viewServerBtn.click(function(e) {
120
+ self.loadPlugin('filemanager', function() {
121
+ self.plugin.filemanagerDialog({
122
+ viewType : 'LIST',
123
+ dirName : 'media',
124
+ clickFn : function(url, title) {
125
+ if (self.dialogs.length > 1) {
126
+ K('[name="url"]', div).val(url);
127
+ self.hideDialog();
128
+ }
129
+ }
130
+ });
131
+ });
132
+ });
133
+ } else {
134
+ viewServerBtn.hide();
135
+ }
136
+
137
+ var img = self.plugin.getSelectedMedia();
138
+ if (img) {
139
+ var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
140
+ urlBox.val(attrs.src);
141
+ widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
142
+ heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
143
+ autostartBox[0].checked = (attrs.autostart === 'true');
144
+ }
145
+ urlBox[0].focus();
146
+ urlBox[0].select();
147
+ },
148
+ 'delete' : function() {
149
+ self.plugin.getSelectedMedia().remove();
150
+ }
151
+ };
152
+ self.clickToolbar(name, self.plugin.media.edit);
153
+ });
@@ -1,26 +1,26 @@
1
- /*******************************************************************************
2
- * KindEditor - WYSIWYG HTML Editor for Internet
3
- * Copyright (C) 2006-2011 kindsoft.net
4
- *
5
- * @author Roddy <luolonghao@gmail.com>
6
- * @site http://www.kindsoft.net/
7
- * @licence http://www.kindsoft.net/license.php
8
- *******************************************************************************/
9
-
10
- KindEditor.plugin('pagebreak', function(K) {
11
- var self = this, name = 'pagebreak';
12
- self.clickToolbar(name, function() {
13
- var cmd = self.cmd, range = cmd.range;
14
- self.focus();
15
- range.enlarge(true);
16
- cmd.split(true);
17
- var tail = self.newlineTag == 'br' ? '' : '<p id="__kindeditor_tail_tag__"></p>';
18
- self.insertHtml('<hr class="ke-pagebreak" style="page-break-after: always;" />' + tail);
19
- if (self.newlineTag != 'br') {
20
- var p = K('#__kindeditor_tail_tag__', self.edit.doc);
21
- range.selectNodeContents(p[0]);
22
- p.removeAttr('id');
23
- cmd.select();
24
- }
25
- });
26
- });
1
+ /*******************************************************************************
2
+ * KindEditor - WYSIWYG HTML Editor for Internet
3
+ * Copyright (C) 2006-2011 kindsoft.net
4
+ *
5
+ * @author Roddy <luolonghao@gmail.com>
6
+ * @site http://www.kindsoft.net/
7
+ * @licence http://www.kindsoft.net/license.php
8
+ *******************************************************************************/
9
+
10
+ KindEditor.plugin('pagebreak', function(K) {
11
+ var self = this, name = 'pagebreak';
12
+ self.clickToolbar(name, function() {
13
+ var cmd = self.cmd, range = cmd.range;
14
+ self.focus();
15
+ range.enlarge(true);
16
+ cmd.split(true);
17
+ var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<p id="__kindeditor_tail_tag__"></p>';
18
+ self.insertHtml('<hr class="ke-pagebreak" style="page-break-after: always;" />' + tail);
19
+ if (tail !== '') {
20
+ var p = K('#__kindeditor_tail_tag__', self.edit.doc);
21
+ range.selectNodeContents(p[0]);
22
+ p.removeAttr('id');
23
+ cmd.select();
24
+ }
25
+ });
26
+ });
@@ -1,661 +1,715 @@
1
- /*******************************************************************************
2
- * KindEditor - WYSIWYG HTML Editor for Internet
3
- * Copyright (C) 2006-2011 kindsoft.net
4
- *
5
- * @author Roddy <luolonghao@gmail.com>
6
- * @site http://www.kindsoft.net/
7
- * @licence http://www.kindsoft.net/license.php
8
- *******************************************************************************/
9
-
10
- KindEditor.plugin('table', function(K) {
11
- var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
12
- // 取得下一行cell的index
13
- function _getCellIndex(table, row, cell) {
14
- var rowSpanCount = 0;
15
- for (var i = 0, len = row.cells.length; i < len; i++) {
16
- if (row.cells[i] == cell) {
17
- break;
18
- }
19
- rowSpanCount += row.cells[i].rowSpan - 1;
20
- }
21
- return cell.cellIndex - rowSpanCount;
22
- }
23
- self.plugin.table = {
24
- //insert or modify table
25
- prop : function(isInsert) {
26
- var html = [
27
- '<div style="padding:10px 20px;">',
28
- //rows, cols
29
- '<div class="ke-dialog-row">',
30
- '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
31
- lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
32
- lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
33
- '</div>',
34
- //width, height
35
- '<div class="ke-dialog-row">',
36
- '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
37
- lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
38
- '<select name="widthType">',
39
- '<option value="%">' + lang.percent + '</option>',
40
- '<option value="px">' + lang.px + '</option>',
41
- '</select> &nbsp; ',
42
- lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
43
- '<select name="heightType">',
44
- '<option value="%">' + lang.percent + '</option>',
45
- '<option value="px">' + lang.px + '</option>',
46
- '</select>',
47
- '</div>',
48
- //space, padding
49
- '<div class="ke-dialog-row">',
50
- '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
51
- lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
52
- lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
53
- '</div>',
54
- //align
55
- '<div class="ke-dialog-row">',
56
- '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
57
- '<select id="keAlign" name="align">',
58
- '<option value="">' + lang.alignDefault + '</option>',
59
- '<option value="left">' + lang.alignLeft + '</option>',
60
- '<option value="center">' + lang.alignCenter + '</option>',
61
- '<option value="right">' + lang.alignRight + '</option>',
62
- '</select>',
63
- '</div>',
64
- //border
65
- '<div class="ke-dialog-row">',
66
- '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
67
- lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
68
- lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
69
- '</div>',
70
- //background color
71
- '<div class="ke-dialog-row">',
72
- '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
73
- '<span class="ke-inline-block ke-input-color"></span>',
74
- '</div>',
75
- '</div>'
76
- ].join('');
77
- var picker, currentElement;
78
- function removePicker() {
79
- if (picker) {
80
- picker.remove();
81
- picker = null;
82
- currentElement = null;
83
- }
84
- }
85
- var dialog = self.createDialog({
86
- name : name,
87
- width : 500,
88
- height : 300,
89
- title : self.lang(name),
90
- body : html,
91
- beforeDrag : removePicker,
92
- beforeRemove : function() {
93
- removePicker();
94
- colorBox.unbind();
95
- },
96
- yesBtn : {
97
- name : self.lang('yes'),
98
- click : function(e) {
99
- var rows = rowsBox.val(),
100
- cols = colsBox.val(),
101
- width = widthBox.val(),
102
- height = heightBox.val(),
103
- widthType = widthTypeBox.val(),
104
- heightType = heightTypeBox.val(),
105
- padding = paddingBox.val(),
106
- spacing = spacingBox.val(),
107
- align = alignBox.val(),
108
- border = borderBox.val(),
109
- borderColor = K(colorBox[0]).html() || '',
110
- bgColor = K(colorBox[1]).html() || '';
111
- //modify table
112
- if (table) {
113
- if (width !== '') {
114
- table.width(width + widthType);
115
- } else {
116
- table.css('width', '');
117
- }
118
- if (table[0].width !== undefined) {
119
- table.removeAttr('width');
120
- }
121
- if (height !== '') {
122
- table.height(height + heightType);
123
- } else {
124
- table.css('height', '');
125
- }
126
- if (table[0].height !== undefined) {
127
- table.removeAttr('height');
128
- }
129
- table.css('background-color', bgColor);
130
- if (table[0].bgColor !== undefined) {
131
- table.removeAttr('bgColor');
132
- }
133
- if (padding !== '') {
134
- table[0].cellPadding = padding;
135
- } else {
136
- table.removeAttr('cellPadding');
137
- }
138
- if (spacing !== '') {
139
- table[0].cellSpacing = spacing;
140
- } else {
141
- table.removeAttr('cellSpacing');
142
- }
143
- if (align !== '') {
144
- table[0].align = align;
145
- } else {
146
- table.removeAttr('align');
147
- }
148
- if (border !== '') {
149
- table.attr('border', border);
150
- } else {
151
- table.removeAttr('border');
152
- }
153
- if (border === '' || border === '0') {
154
- table.addClass(zeroborder);
155
- } else {
156
- table.removeClass(zeroborder);
157
- }
158
- if (borderColor !== '') {
159
- table.attr('borderColor', borderColor);
160
- } else {
161
- table.removeAttr('borderColor');
162
- }
163
- self.hideDialog().focus();
164
- return;
165
- }
166
- //insert new table
167
- var style = '';
168
- if (width !== '') {
169
- style += 'width:' + width + widthType + ';';
170
- }
171
- if (height !== '') {
172
- style += 'height:' + height + heightType + ';';
173
- }
174
- if (bgColor !== '') {
175
- style += 'background-color:' + bgColor + ';';
176
- }
177
- var html = '<table';
178
- if (style !== '') {
179
- html += ' style="' + style + '"';
180
- }
181
- if (padding !== '') {
182
- html += ' cellpadding="' + padding + '"';
183
- }
184
- if (spacing !== '') {
185
- html += ' cellspacing="' + spacing + '"';
186
- }
187
- if (align !== '') {
188
- html += ' align="' + align + '"';
189
- }
190
- if (border !== '') {
191
- html += ' border="' + border + '"';
192
- }
193
- if (border === '' || border === '0') {
194
- html += ' class="' + zeroborder + '"';
195
- }
196
- if (borderColor !== '') {
197
- html += ' bordercolor="' + borderColor + '"';
198
- }
199
- html += '>';
200
- for (var i = 0; i < rows; i++) {
201
- html += '<tr>';
202
- for (var j = 0; j < cols; j++) {
203
- html += '<td>' + (K.IE ? '' : '<br />') + '</td>';
204
- }
205
- html += '</tr>';
206
- }
207
- html += '</table>';
208
- self.insertHtml(html).select().hideDialog().focus();
209
- self.addBookmark();
210
- }
211
- }
212
- }),
213
- div = dialog.div,
214
- rowsBox = K('[name="rows"]', div).val(3),
215
- colsBox = K('[name="cols"]', div).val(2),
216
- widthBox = K('[name="width"]', div).val(100),
217
- heightBox = K('[name="height"]', div),
218
- widthTypeBox = K('[name="widthType"]', div),
219
- heightTypeBox = K('[name="heightType"]', div),
220
- paddingBox = K('[name="padding"]', div).val(2),
221
- spacingBox = K('[name="spacing"]', div).val(0),
222
- alignBox = K('[name="align"]', div),
223
- borderBox = K('[name="border"]', div).val(1),
224
- colorBox = K('.ke-input-color', div);
225
- function setColor(box, color) {
226
- color = color.toUpperCase();
227
- box.css('background-color', color);
228
- box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
229
- box.html(color);
230
- }
231
- setColor(K(colorBox[0]), '#000000');
232
- setColor(K(colorBox[1]), '');
233
- function clickHandler(e) {
234
- removePicker();
235
- if (!picker || this !== currentElement) {
236
- var box = K(this),
237
- pos = box.pos();
238
- picker = K.colorpicker({
239
- x : pos.x,
240
- y : pos.y + box.height(),
241
- z : 811214,
242
- selectedColor : K(this).html(),
243
- colors : self.colorTable,
244
- noColor : self.lang('noColor'),
245
- click : function(color) {
246
- setColor(box, color);
247
- removePicker();
248
- }
249
- });
250
- currentElement = this;
251
- }
252
- }
253
- colorBox.click(clickHandler);
254
- // foucs and select
255
- rowsBox[0].focus();
256
- rowsBox[0].select();
257
- var table;
258
- if (isInsert) {
259
- return;
260
- }
261
- //get selected table node
262
- table = self.plugin.getSelectedTable();
263
- if (table) {
264
- rowsBox.val(table[0].rows.length);
265
- colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
266
- rowsBox.attr('disabled', true);
267
- colsBox.attr('disabled', true);
268
- var match,
269
- tableWidth = table[0].style.width || table[0].width,
270
- tableHeight = table[0].style.height || table[0].height;
271
- if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
272
- widthBox.val(match[1]);
273
- widthTypeBox.val(match[2]);
274
- } else {
275
- widthBox.val('');
276
- }
277
- if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
278
- heightBox.val(match[1]);
279
- heightTypeBox.val(match[2]);
280
- }
281
- paddingBox.val(table[0].cellPadding || '');
282
- spacingBox.val(table[0].cellSpacing || '');
283
- alignBox.val(table[0].align || '');
284
- borderBox.val(table[0].border === undefined ? '' : table[0].border);
285
- setColor(K(colorBox[0]), K.toHex(table.attr('borderColor') || ''));
286
- setColor(K(colorBox[1]), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
287
- widthBox[0].focus();
288
- widthBox[0].select();
289
- }
290
- },
291
- //modify cell
292
- cellprop : function() {
293
- var html = [
294
- '<div style="padding:10px 20px;">',
295
- //width, height
296
- '<div class="ke-dialog-row">',
297
- '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
298
- lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
299
- '<select name="widthType">',
300
- '<option value="%">' + lang.percent + '</option>',
301
- '<option value="px">' + lang.px + '</option>',
302
- '</select> &nbsp; ',
303
- lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
304
- '<select name="heightType">',
305
- '<option value="%">' + lang.percent + '</option>',
306
- '<option value="px">' + lang.px + '</option>',
307
- '</select>',
308
- '</div>',
309
- //align
310
- '<div class="ke-dialog-row">',
311
- '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
312
- lang.textAlign + ' <select id="keAlign" name="textAlign">',
313
- '<option value="">' + lang.alignDefault + '</option>',
314
- '<option value="left">' + lang.alignLeft + '</option>',
315
- '<option value="center">' + lang.alignCenter + '</option>',
316
- '<option value="right">' + lang.alignRight + '</option>',
317
- '</select> ',
318
- lang.verticalAlign + ' <select name="verticalAlign">',
319
- '<option value="">' + lang.alignDefault + '</option>',
320
- '<option value="top">' + lang.alignTop + '</option>',
321
- '<option value="middle">' + lang.alignMiddle + '</option>',
322
- '<option value="bottom">' + lang.alignBottom + '</option>',
323
- '<option value="baseline">' + lang.alignBaseline + '</option>',
324
- '</select>',
325
- '</div>',
326
- //border
327
- '<div class="ke-dialog-row">',
328
- '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
329
- lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
330
- lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
331
- '</div>',
332
- //background color
333
- '<div class="ke-dialog-row">',
334
- '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
335
- '<span class="ke-inline-block ke-input-color"></span>',
336
- '</div>',
337
- '</div>'
338
- ].join('');
339
- var picker, currentElement;
340
- function removePicker() {
341
- if (picker) {
342
- picker.remove();
343
- picker = null;
344
- currentElement = null;
345
- }
346
- }
347
- var dialog = self.createDialog({
348
- name : name,
349
- width : 500,
350
- height : 220,
351
- title : self.lang('tablecell'),
352
- body : html,
353
- beforeDrag : removePicker,
354
- beforeRemove : function() {
355
- removePicker();
356
- colorBox.unbind();
357
- },
358
- yesBtn : {
359
- name : self.lang('yes'),
360
- click : function(e) {
361
- var width = widthBox.val(),
362
- height = heightBox.val(),
363
- widthType = widthTypeBox.val(),
364
- heightType = heightTypeBox.val(),
365
- padding = paddingBox.val(),
366
- spacing = spacingBox.val(),
367
- textAlign = textAlignBox.val(),
368
- verticalAlign = verticalAlignBox.val(),
369
- border = borderBox.val(),
370
- borderColor = K(colorBox[0]).html() || '',
371
- bgColor = K(colorBox[1]).html() || '';
372
- cell.css({
373
- width : width !== '' ? (width + widthType) : '',
374
- height : height !== '' ? (height + heightType) : '',
375
- 'background-color' : bgColor,
376
- 'text-align' : textAlign,
377
- 'vertical-align' : verticalAlign,
378
- 'border-width' : border,
379
- 'border-style' : border !== '' ? 'solid' : '',
380
- 'border-color' : borderColor
381
- });
382
- self.hideDialog().focus();
383
- self.addBookmark();
384
- }
385
- }
386
- }),
387
- div = dialog.div,
388
- widthBox = K('[name="width"]', div).val(100),
389
- heightBox = K('[name="height"]', div),
390
- widthTypeBox = K('[name="widthType"]', div),
391
- heightTypeBox = K('[name="heightType"]', div),
392
- paddingBox = K('[name="padding"]', div).val(2),
393
- spacingBox = K('[name="spacing"]', div).val(0),
394
- textAlignBox = K('[name="textAlign"]', div),
395
- verticalAlignBox = K('[name="verticalAlign"]', div),
396
- borderBox = K('[name="border"]', div).val(1),
397
- colorBox = K('.ke-input-color', div);
398
- function setColor(box, color) {
399
- color = color.toUpperCase();
400
- box.css('background-color', color);
401
- box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
402
- box.html(color);
403
- }
404
- setColor(K(colorBox[0]), '#000000');
405
- setColor(K(colorBox[1]), '');
406
- function clickHandler(e) {
407
- removePicker();
408
- if (!picker || this !== currentElement) {
409
- var box = K(this),
410
- pos = box.pos();
411
- picker = K.colorpicker({
412
- x : pos.x,
413
- y : pos.y + box.height(),
414
- z : 811214,
415
- selectedColor : K(this).html(),
416
- colors : self.colorTable,
417
- noColor : self.lang('noColor'),
418
- click : function(color) {
419
- setColor(box, color);
420
- removePicker();
421
- }
422
- });
423
- currentElement = this;
424
- }
425
- }
426
- colorBox.click(clickHandler);
427
- // foucs and select
428
- widthBox[0].focus();
429
- widthBox[0].select();
430
- // get selected cell
431
- var cell = self.plugin.getSelectedCell();
432
- var match,
433
- cellWidth = cell[0].style.width || cell[0].width || '',
434
- cellHeight = cell[0].style.height || cell[0].height || '';
435
- if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
436
- widthBox.val(match[1]);
437
- widthTypeBox.val(match[2]);
438
- } else {
439
- widthBox.val('');
440
- }
441
- if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
442
- heightBox.val(match[1]);
443
- heightTypeBox.val(match[2]);
444
- }
445
- textAlignBox.val(cell[0].style.textAlign || '');
446
- verticalAlignBox.val(cell[0].style.verticalAlign || '');
447
- var border = cell[0].style.borderWidth || '';
448
- if (border) {
449
- border = parseInt(border);
450
- }
451
- borderBox.val(border);
452
- setColor(K(colorBox[0]), K.toHex(cell[0].style.borderColor || ''));
453
- setColor(K(colorBox[1]), K.toHex(cell[0].style.backgroundColor || ''));
454
- widthBox[0].focus();
455
- widthBox[0].select();
456
- },
457
- insert : function() {
458
- this.prop(true);
459
- },
460
- 'delete' : function() {
461
- var table = self.plugin.getSelectedTable();
462
- self.cmd.range.setStartBefore(table[0]).collapse(true);
463
- self.cmd.select();
464
- table.remove();
465
- self.addBookmark();
466
- },
467
- colinsert : function(offset) {
468
- var table = self.plugin.getSelectedTable()[0],
469
- row = self.plugin.getSelectedRow()[0],
470
- cell = self.plugin.getSelectedCell()[0],
471
- index = cell.cellIndex + offset;
472
- for (var i = 0, len = table.rows.length; i < len; i++) {
473
- var newRow = table.rows[i],
474
- newCell = newRow.insertCell(index);
475
- newCell.innerHTML = K.IE ? '' : '<br />';
476
- // 调整下一行的单元格index
477
- index = _getCellIndex(table, newRow, newCell);
478
- }
479
- self.cmd.range.selectNodeContents(cell).collapse(true);
480
- self.cmd.select();
481
- self.addBookmark();
482
- },
483
- colinsertleft : function() {
484
- this.colinsert(0);
485
- },
486
- colinsertright : function() {
487
- this.colinsert(1);
488
- },
489
- rowinsert : function(offset) {
490
- var table = self.plugin.getSelectedTable()[0],
491
- row = self.plugin.getSelectedRow()[0],
492
- cell = self.plugin.getSelectedCell()[0],
493
- newRow;
494
- if (offset === 1) {
495
- newRow = table.insertRow(row.rowIndex + (cell.rowSpan - 1) + offset);
496
- } else {
497
- newRow = table.insertRow(row.rowIndex);
498
- }
499
- for (var i = 0, len = row.cells.length; i < len; i++) {
500
- var newCell = newRow.insertCell(i);
501
- // copy colspan
502
- if (offset === 1 && row.cells[i].colSpan > 1) {
503
- newCell.colSpan = row.cells[i].colSpan;
504
- }
505
- newCell.innerHTML = K.IE ? '' : '<br />';
506
- }
507
- self.cmd.range.selectNodeContents(cell).collapse(true);
508
- self.cmd.select();
509
- self.addBookmark();
510
- },
511
- rowinsertabove : function() {
512
- this.rowinsert(0);
513
- },
514
- rowinsertbelow : function() {
515
- this.rowinsert(1);
516
- },
517
- rowmerge : function() {
518
- var table = self.plugin.getSelectedTable()[0],
519
- row = self.plugin.getSelectedRow()[0],
520
- cell = self.plugin.getSelectedCell()[0],
521
- rowIndex = row.rowIndex, // 当前行的index
522
- nextRowIndex = rowIndex + cell.rowSpan, // 下一行的index
523
- nextRow = table.rows[nextRowIndex]; // 下一行
524
- // 最后一行不能合并
525
- if (table.rows.length <= nextRowIndex) {
526
- return;
527
- }
528
- var cellIndex = _getCellIndex(table, row, cell); // 下一行单元格的index
529
- if (nextRow.cells.length <= cellIndex) {
530
- return;
531
- }
532
- var nextCell = nextRow.cells[cellIndex]; // 下一行单元格
533
- // 上下行的colspan不一致时不能合并
534
- if (cell.colSpan !== nextCell.colSpan) {
535
- return;
536
- }
537
- cell.rowSpan += nextCell.rowSpan;
538
- nextRow.deleteCell(cellIndex);
539
- self.cmd.range.selectNodeContents(cell).collapse(true);
540
- self.cmd.select();
541
- self.addBookmark();
542
- },
543
- colmerge : function() {
544
- var table = self.plugin.getSelectedTable()[0],
545
- row = self.plugin.getSelectedRow()[0],
546
- cell = self.plugin.getSelectedCell()[0],
547
- rowIndex = row.rowIndex, // 当前行的index
548
- cellIndex = cell.cellIndex,
549
- nextCellIndex = cellIndex + 1;
550
- // 最后一列不能合并
551
- if (row.cells.length <= nextCellIndex) {
552
- return;
553
- }
554
- var nextCell = row.cells[nextCellIndex];
555
- // 左右列的rowspan不一致时不能合并
556
- if (cell.rowSpan !== nextCell.rowSpan) {
557
- return;
558
- }
559
- cell.colSpan += nextCell.colSpan;
560
- row.deleteCell(nextCellIndex);
561
- self.cmd.range.selectNodeContents(cell).collapse(true);
562
- self.cmd.select();
563
- self.addBookmark();
564
- },
565
- rowsplit : function() {
566
- var table = self.plugin.getSelectedTable()[0],
567
- row = self.plugin.getSelectedRow()[0],
568
- cell = self.plugin.getSelectedCell()[0],
569
- rowIndex = row.rowIndex;
570
- // 不是可分割单元格
571
- if (cell.rowSpan === 1) {
572
- return;
573
- }
574
- var cellIndex = _getCellIndex(table, row, cell);
575
- for (var i = 1, len = cell.rowSpan; i < len; i++) {
576
- var newRow = table.rows[rowIndex + i],
577
- newCell = newRow.insertCell(cellIndex);
578
- if (cell.colSpan > 1) {
579
- newCell.colSpan = cell.colSpan;
580
- }
581
- newCell.innerHTML = K.IE ? '' : '<br />';
582
- // 调整下一行的单元格index
583
- cellIndex = _getCellIndex(table, newRow, newCell);
584
- }
585
- K(cell).removeAttr('rowSpan');
586
- self.cmd.range.selectNodeContents(cell).collapse(true);
587
- self.cmd.select();
588
- self.addBookmark();
589
- },
590
- colsplit : function() {
591
- var table = self.plugin.getSelectedTable()[0],
592
- row = self.plugin.getSelectedRow()[0],
593
- cell = self.plugin.getSelectedCell()[0],
594
- cellIndex = cell.cellIndex;
595
- // 不是可分割单元格
596
- if (cell.colSpan === 1) {
597
- return;
598
- }
599
- for (var i = 1, len = cell.colSpan; i < len; i++) {
600
- var newCell = row.insertCell(cellIndex + i);
601
- if (cell.rowSpan > 1) {
602
- newCell.rowSpan = cell.rowSpan;
603
- }
604
- newCell.innerHTML = K.IE ? '' : '<br />';
605
- }
606
- K(cell).removeAttr('colSpan');
607
- self.cmd.range.selectNodeContents(cell).collapse(true);
608
- self.cmd.select();
609
- self.addBookmark();
610
- },
611
- coldelete : function() {
612
- var table = self.plugin.getSelectedTable()[0],
613
- row = self.plugin.getSelectedRow()[0],
614
- cell = self.plugin.getSelectedCell()[0],
615
- index = cell.cellIndex;
616
- for (var i = 0, len = table.rows.length; i < len; i++) {
617
- var newRow = table.rows[i],
618
- newCell = newRow.cells[index];
619
- if (newCell.colSpan > 1) {
620
- newCell.colSpan -= 1;
621
- if (newCell.colSpan === 1) {
622
- K(newCell).removeAttr('colSpan');
623
- }
624
- } else {
625
- newRow.deleteCell(index);
626
- }
627
- // 跳过不需要删除的行
628
- if (newCell.rowSpan > 1) {
629
- i += newCell.rowSpan - 1;
630
- }
631
- }
632
- if (row.cells.length === 0) {
633
- self.cmd.range.setStartBefore(table).collapse(true);
634
- self.cmd.select();
635
- K(table).remove();
636
- } else {
637
- self.cmd.selection(true);
638
- }
639
- self.addBookmark();
640
- },
641
- rowdelete : function() {
642
- var table = self.plugin.getSelectedTable()[0],
643
- row = self.plugin.getSelectedRow()[0],
644
- cell = self.plugin.getSelectedCell()[0],
645
- rowIndex = row.rowIndex;
646
- // 从下到上删除
647
- for (var i = cell.rowSpan - 1; i >= 0; i--) {
648
- table.deleteRow(rowIndex + i);
649
- }
650
- if (table.rows.length === 0) {
651
- self.cmd.range.setStartBefore(table).collapse(true);
652
- self.cmd.select();
653
- K(table).remove();
654
- } else {
655
- self.cmd.selection(true);
656
- }
657
- self.addBookmark();
658
- }
659
- };
660
- self.clickToolbar(name, self.plugin.table.prop);
661
- });
1
+ /*******************************************************************************
2
+ * KindEditor - WYSIWYG HTML Editor for Internet
3
+ * Copyright (C) 2006-2011 kindsoft.net
4
+ *
5
+ * @author Roddy <luolonghao@gmail.com>
6
+ * @site http://www.kindsoft.net/
7
+ * @licence http://www.kindsoft.net/license.php
8
+ *******************************************************************************/
9
+
10
+ KindEditor.plugin('table', function(K) {
11
+ var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
12
+ // 取得下一行cell的index
13
+ function _getCellIndex(table, row, cell) {
14
+ var rowSpanCount = 0;
15
+ for (var i = 0, len = row.cells.length; i < len; i++) {
16
+ if (row.cells[i] == cell) {
17
+ break;
18
+ }
19
+ rowSpanCount += row.cells[i].rowSpan - 1;
20
+ }
21
+ return cell.cellIndex - rowSpanCount;
22
+ }
23
+ self.plugin.table = {
24
+ //insert or modify table
25
+ prop : function(isInsert) {
26
+ var html = [
27
+ '<div style="padding:10px 20px;">',
28
+ //rows, cols
29
+ '<div class="ke-dialog-row">',
30
+ '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
31
+ lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
32
+ lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
33
+ '</div>',
34
+ //width, height
35
+ '<div class="ke-dialog-row">',
36
+ '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
37
+ lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
38
+ '<select name="widthType">',
39
+ '<option value="%">' + lang.percent + '</option>',
40
+ '<option value="px">' + lang.px + '</option>',
41
+ '</select> &nbsp; ',
42
+ lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
43
+ '<select name="heightType">',
44
+ '<option value="%">' + lang.percent + '</option>',
45
+ '<option value="px">' + lang.px + '</option>',
46
+ '</select>',
47
+ '</div>',
48
+ //space, padding
49
+ '<div class="ke-dialog-row">',
50
+ '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
51
+ lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
52
+ lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
53
+ '</div>',
54
+ //align
55
+ '<div class="ke-dialog-row">',
56
+ '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
57
+ '<select id="keAlign" name="align">',
58
+ '<option value="">' + lang.alignDefault + '</option>',
59
+ '<option value="left">' + lang.alignLeft + '</option>',
60
+ '<option value="center">' + lang.alignCenter + '</option>',
61
+ '<option value="right">' + lang.alignRight + '</option>',
62
+ '</select>',
63
+ '</div>',
64
+ //border
65
+ '<div class="ke-dialog-row">',
66
+ '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
67
+ lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
68
+ lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
69
+ '</div>',
70
+ //background color
71
+ '<div class="ke-dialog-row">',
72
+ '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
73
+ '<span class="ke-inline-block ke-input-color"></span>',
74
+ '</div>',
75
+ '</div>'
76
+ ].join('');
77
+ var picker, currentElement;
78
+ function removePicker() {
79
+ if (picker) {
80
+ picker.remove();
81
+ picker = null;
82
+ currentElement = null;
83
+ }
84
+ }
85
+ var dialog = self.createDialog({
86
+ name : name,
87
+ width : 500,
88
+ height : 300,
89
+ title : self.lang(name),
90
+ body : html,
91
+ beforeDrag : removePicker,
92
+ beforeRemove : function() {
93
+ removePicker();
94
+ colorBox.unbind();
95
+ },
96
+ yesBtn : {
97
+ name : self.lang('yes'),
98
+ click : function(e) {
99
+ var rows = rowsBox.val(),
100
+ cols = colsBox.val(),
101
+ width = widthBox.val(),
102
+ height = heightBox.val(),
103
+ widthType = widthTypeBox.val(),
104
+ heightType = heightTypeBox.val(),
105
+ padding = paddingBox.val(),
106
+ spacing = spacingBox.val(),
107
+ align = alignBox.val(),
108
+ border = borderBox.val(),
109
+ borderColor = K(colorBox[0]).html() || '',
110
+ bgColor = K(colorBox[1]).html() || '';
111
+ if (rows == 0 || !/^\d+$/.test(rows)) {
112
+ alert(self.lang('invalidRows'));
113
+ rowsBox[0].focus();
114
+ return;
115
+ }
116
+ if (cols == 0 || !/^\d+$/.test(cols)) {
117
+ alert(self.lang('invalidRows'));
118
+ colsBox[0].focus();
119
+ return;
120
+ }
121
+ if (!/^\d*$/.test(width)) {
122
+ alert(self.lang('invalidWidth'));
123
+ widthBox[0].focus();
124
+ return;
125
+ }
126
+ if (!/^\d*$/.test(height)) {
127
+ alert(self.lang('invalidHeight'));
128
+ heightBox[0].focus();
129
+ return;
130
+ }
131
+ if (!/^\d*$/.test(padding)) {
132
+ alert(self.lang('invalidPadding'));
133
+ paddingBox[0].focus();
134
+ return;
135
+ }
136
+ if (!/^\d*$/.test(spacing)) {
137
+ alert(self.lang('invalidSpacing'));
138
+ spacingBox[0].focus();
139
+ return;
140
+ }
141
+ if (!/^\d*$/.test(border)) {
142
+ alert(self.lang('invalidBorder'));
143
+ borderBox[0].focus();
144
+ return;
145
+ }
146
+ //modify table
147
+ if (table) {
148
+ if (width !== '') {
149
+ table.width(width + widthType);
150
+ } else {
151
+ table.css('width', '');
152
+ }
153
+ if (table[0].width !== undefined) {
154
+ table.removeAttr('width');
155
+ }
156
+ if (height !== '') {
157
+ table.height(height + heightType);
158
+ } else {
159
+ table.css('height', '');
160
+ }
161
+ if (table[0].height !== undefined) {
162
+ table.removeAttr('height');
163
+ }
164
+ table.css('background-color', bgColor);
165
+ if (table[0].bgColor !== undefined) {
166
+ table.removeAttr('bgColor');
167
+ }
168
+ if (padding !== '') {
169
+ table[0].cellPadding = padding;
170
+ } else {
171
+ table.removeAttr('cellPadding');
172
+ }
173
+ if (spacing !== '') {
174
+ table[0].cellSpacing = spacing;
175
+ } else {
176
+ table.removeAttr('cellSpacing');
177
+ }
178
+ if (align !== '') {
179
+ table[0].align = align;
180
+ } else {
181
+ table.removeAttr('align');
182
+ }
183
+ if (border !== '') {
184
+ table.attr('border', border);
185
+ } else {
186
+ table.removeAttr('border');
187
+ }
188
+ if (border === '' || border === '0') {
189
+ table.addClass(zeroborder);
190
+ } else {
191
+ table.removeClass(zeroborder);
192
+ }
193
+ if (borderColor !== '') {
194
+ table.attr('borderColor', borderColor);
195
+ } else {
196
+ table.removeAttr('borderColor');
197
+ }
198
+ self.hideDialog().focus();
199
+ return;
200
+ }
201
+ //insert new table
202
+ var style = '';
203
+ if (width !== '') {
204
+ style += 'width:' + width + widthType + ';';
205
+ }
206
+ if (height !== '') {
207
+ style += 'height:' + height + heightType + ';';
208
+ }
209
+ if (bgColor !== '') {
210
+ style += 'background-color:' + bgColor + ';';
211
+ }
212
+ var html = '<table';
213
+ if (style !== '') {
214
+ html += ' style="' + style + '"';
215
+ }
216
+ if (padding !== '') {
217
+ html += ' cellpadding="' + padding + '"';
218
+ }
219
+ if (spacing !== '') {
220
+ html += ' cellspacing="' + spacing + '"';
221
+ }
222
+ if (align !== '') {
223
+ html += ' align="' + align + '"';
224
+ }
225
+ if (border !== '') {
226
+ html += ' border="' + border + '"';
227
+ }
228
+ if (border === '' || border === '0') {
229
+ html += ' class="' + zeroborder + '"';
230
+ }
231
+ if (borderColor !== '') {
232
+ html += ' bordercolor="' + borderColor + '"';
233
+ }
234
+ html += '>';
235
+ for (var i = 0; i < rows; i++) {
236
+ html += '<tr>';
237
+ for (var j = 0; j < cols; j++) {
238
+ html += '<td>' + (K.IE ? '' : '<br />') + '</td>';
239
+ }
240
+ html += '</tr>';
241
+ }
242
+ html += '</table>';
243
+ if (!K.IE) {
244
+ html += '<br />';
245
+ }
246
+ self.insertHtml(html);
247
+ self.select().hideDialog().focus();
248
+ self.addBookmark();
249
+ }
250
+ }
251
+ }),
252
+ div = dialog.div,
253
+ rowsBox = K('[name="rows"]', div).val(3),
254
+ colsBox = K('[name="cols"]', div).val(2),
255
+ widthBox = K('[name="width"]', div).val(100),
256
+ heightBox = K('[name="height"]', div),
257
+ widthTypeBox = K('[name="widthType"]', div),
258
+ heightTypeBox = K('[name="heightType"]', div),
259
+ paddingBox = K('[name="padding"]', div).val(2),
260
+ spacingBox = K('[name="spacing"]', div).val(0),
261
+ alignBox = K('[name="align"]', div),
262
+ borderBox = K('[name="border"]', div).val(1),
263
+ colorBox = K('.ke-input-color', div);
264
+ function setColor(box, color) {
265
+ color = color.toUpperCase();
266
+ box.css('background-color', color);
267
+ box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
268
+ box.html(color);
269
+ }
270
+ setColor(K(colorBox[0]), '#000000');
271
+ setColor(K(colorBox[1]), '');
272
+ function clickHandler(e) {
273
+ removePicker();
274
+ if (!picker || this !== currentElement) {
275
+ var box = K(this),
276
+ pos = box.pos();
277
+ picker = K.colorpicker({
278
+ x : pos.x,
279
+ y : pos.y + box.height(),
280
+ z : 811214,
281
+ selectedColor : K(this).html(),
282
+ colors : self.colorTable,
283
+ noColor : self.lang('noColor'),
284
+ click : function(color) {
285
+ setColor(box, color);
286
+ removePicker();
287
+ }
288
+ });
289
+ currentElement = this;
290
+ }
291
+ }
292
+ colorBox.click(clickHandler);
293
+ // foucs and select
294
+ rowsBox[0].focus();
295
+ rowsBox[0].select();
296
+ var table;
297
+ if (isInsert) {
298
+ return;
299
+ }
300
+ //get selected table node
301
+ table = self.plugin.getSelectedTable();
302
+ if (table) {
303
+ rowsBox.val(table[0].rows.length);
304
+ colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
305
+ rowsBox.attr('disabled', true);
306
+ colsBox.attr('disabled', true);
307
+ var match,
308
+ tableWidth = table[0].style.width || table[0].width,
309
+ tableHeight = table[0].style.height || table[0].height;
310
+ if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
311
+ widthBox.val(match[1]);
312
+ widthTypeBox.val(match[2]);
313
+ } else {
314
+ widthBox.val('');
315
+ }
316
+ if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
317
+ heightBox.val(match[1]);
318
+ heightTypeBox.val(match[2]);
319
+ }
320
+ paddingBox.val(table[0].cellPadding || '');
321
+ spacingBox.val(table[0].cellSpacing || '');
322
+ alignBox.val(table[0].align || '');
323
+ borderBox.val(table[0].border === undefined ? '' : table[0].border);
324
+ setColor(K(colorBox[0]), K.toHex(table.attr('borderColor') || ''));
325
+ setColor(K(colorBox[1]), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
326
+ widthBox[0].focus();
327
+ widthBox[0].select();
328
+ }
329
+ },
330
+ //modify cell
331
+ cellprop : function() {
332
+ var html = [
333
+ '<div style="padding:10px 20px;">',
334
+ //width, height
335
+ '<div class="ke-dialog-row">',
336
+ '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
337
+ lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
338
+ '<select name="widthType">',
339
+ '<option value="%">' + lang.percent + '</option>',
340
+ '<option value="px">' + lang.px + '</option>',
341
+ '</select> &nbsp; ',
342
+ lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
343
+ '<select name="heightType">',
344
+ '<option value="%">' + lang.percent + '</option>',
345
+ '<option value="px">' + lang.px + '</option>',
346
+ '</select>',
347
+ '</div>',
348
+ //align
349
+ '<div class="ke-dialog-row">',
350
+ '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
351
+ lang.textAlign + ' <select id="keAlign" name="textAlign">',
352
+ '<option value="">' + lang.alignDefault + '</option>',
353
+ '<option value="left">' + lang.alignLeft + '</option>',
354
+ '<option value="center">' + lang.alignCenter + '</option>',
355
+ '<option value="right">' + lang.alignRight + '</option>',
356
+ '</select> ',
357
+ lang.verticalAlign + ' <select name="verticalAlign">',
358
+ '<option value="">' + lang.alignDefault + '</option>',
359
+ '<option value="top">' + lang.alignTop + '</option>',
360
+ '<option value="middle">' + lang.alignMiddle + '</option>',
361
+ '<option value="bottom">' + lang.alignBottom + '</option>',
362
+ '<option value="baseline">' + lang.alignBaseline + '</option>',
363
+ '</select>',
364
+ '</div>',
365
+ //border
366
+ '<div class="ke-dialog-row">',
367
+ '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
368
+ lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
369
+ lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
370
+ '</div>',
371
+ //background color
372
+ '<div class="ke-dialog-row">',
373
+ '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
374
+ '<span class="ke-inline-block ke-input-color"></span>',
375
+ '</div>',
376
+ '</div>'
377
+ ].join('');
378
+ var picker, currentElement;
379
+ function removePicker() {
380
+ if (picker) {
381
+ picker.remove();
382
+ picker = null;
383
+ currentElement = null;
384
+ }
385
+ }
386
+ var dialog = self.createDialog({
387
+ name : name,
388
+ width : 500,
389
+ height : 220,
390
+ title : self.lang('tablecell'),
391
+ body : html,
392
+ beforeDrag : removePicker,
393
+ beforeRemove : function() {
394
+ removePicker();
395
+ colorBox.unbind();
396
+ },
397
+ yesBtn : {
398
+ name : self.lang('yes'),
399
+ click : function(e) {
400
+ var width = widthBox.val(),
401
+ height = heightBox.val(),
402
+ widthType = widthTypeBox.val(),
403
+ heightType = heightTypeBox.val(),
404
+ padding = paddingBox.val(),
405
+ spacing = spacingBox.val(),
406
+ textAlign = textAlignBox.val(),
407
+ verticalAlign = verticalAlignBox.val(),
408
+ border = borderBox.val(),
409
+ borderColor = K(colorBox[0]).html() || '',
410
+ bgColor = K(colorBox[1]).html() || '';
411
+ if (!/^\d*$/.test(width)) {
412
+ alert(self.lang('invalidWidth'));
413
+ widthBox[0].focus();
414
+ return;
415
+ }
416
+ if (!/^\d*$/.test(height)) {
417
+ alert(self.lang('invalidHeight'));
418
+ heightBox[0].focus();
419
+ return;
420
+ }
421
+ if (!/^\d*$/.test(border)) {
422
+ alert(self.lang('invalidBorder'));
423
+ borderBox[0].focus();
424
+ return;
425
+ }
426
+ cell.css({
427
+ width : width !== '' ? (width + widthType) : '',
428
+ height : height !== '' ? (height + heightType) : '',
429
+ 'background-color' : bgColor,
430
+ 'text-align' : textAlign,
431
+ 'vertical-align' : verticalAlign,
432
+ 'border-width' : border,
433
+ 'border-style' : border !== '' ? 'solid' : '',
434
+ 'border-color' : borderColor
435
+ });
436
+ self.hideDialog().focus();
437
+ self.addBookmark();
438
+ }
439
+ }
440
+ }),
441
+ div = dialog.div,
442
+ widthBox = K('[name="width"]', div).val(100),
443
+ heightBox = K('[name="height"]', div),
444
+ widthTypeBox = K('[name="widthType"]', div),
445
+ heightTypeBox = K('[name="heightType"]', div),
446
+ paddingBox = K('[name="padding"]', div).val(2),
447
+ spacingBox = K('[name="spacing"]', div).val(0),
448
+ textAlignBox = K('[name="textAlign"]', div),
449
+ verticalAlignBox = K('[name="verticalAlign"]', div),
450
+ borderBox = K('[name="border"]', div).val(1),
451
+ colorBox = K('.ke-input-color', div);
452
+ function setColor(box, color) {
453
+ color = color.toUpperCase();
454
+ box.css('background-color', color);
455
+ box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
456
+ box.html(color);
457
+ }
458
+ setColor(K(colorBox[0]), '#000000');
459
+ setColor(K(colorBox[1]), '');
460
+ function clickHandler(e) {
461
+ removePicker();
462
+ if (!picker || this !== currentElement) {
463
+ var box = K(this),
464
+ pos = box.pos();
465
+ picker = K.colorpicker({
466
+ x : pos.x,
467
+ y : pos.y + box.height(),
468
+ z : 811214,
469
+ selectedColor : K(this).html(),
470
+ colors : self.colorTable,
471
+ noColor : self.lang('noColor'),
472
+ click : function(color) {
473
+ setColor(box, color);
474
+ removePicker();
475
+ }
476
+ });
477
+ currentElement = this;
478
+ }
479
+ }
480
+ colorBox.click(clickHandler);
481
+ // foucs and select
482
+ widthBox[0].focus();
483
+ widthBox[0].select();
484
+ // get selected cell
485
+ var cell = self.plugin.getSelectedCell();
486
+ var match,
487
+ cellWidth = cell[0].style.width || cell[0].width || '',
488
+ cellHeight = cell[0].style.height || cell[0].height || '';
489
+ if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
490
+ widthBox.val(match[1]);
491
+ widthTypeBox.val(match[2]);
492
+ } else {
493
+ widthBox.val('');
494
+ }
495
+ if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
496
+ heightBox.val(match[1]);
497
+ heightTypeBox.val(match[2]);
498
+ }
499
+ textAlignBox.val(cell[0].style.textAlign || '');
500
+ verticalAlignBox.val(cell[0].style.verticalAlign || '');
501
+ var border = cell[0].style.borderWidth || '';
502
+ if (border) {
503
+ border = parseInt(border);
504
+ }
505
+ borderBox.val(border);
506
+ setColor(K(colorBox[0]), K.toHex(cell[0].style.borderColor || ''));
507
+ setColor(K(colorBox[1]), K.toHex(cell[0].style.backgroundColor || ''));
508
+ widthBox[0].focus();
509
+ widthBox[0].select();
510
+ },
511
+ insert : function() {
512
+ this.prop(true);
513
+ },
514
+ 'delete' : function() {
515
+ var table = self.plugin.getSelectedTable();
516
+ self.cmd.range.setStartBefore(table[0]).collapse(true);
517
+ self.cmd.select();
518
+ table.remove();
519
+ self.addBookmark();
520
+ },
521
+ colinsert : function(offset) {
522
+ var table = self.plugin.getSelectedTable()[0],
523
+ row = self.plugin.getSelectedRow()[0],
524
+ cell = self.plugin.getSelectedCell()[0],
525
+ index = cell.cellIndex + offset;
526
+ for (var i = 0, len = table.rows.length; i < len; i++) {
527
+ var newRow = table.rows[i],
528
+ newCell = newRow.insertCell(index);
529
+ newCell.innerHTML = K.IE ? '' : '<br />';
530
+ // 调整下一行的单元格index
531
+ index = _getCellIndex(table, newRow, newCell);
532
+ }
533
+ self.cmd.range.selectNodeContents(cell).collapse(true);
534
+ self.cmd.select();
535
+ self.addBookmark();
536
+ },
537
+ colinsertleft : function() {
538
+ this.colinsert(0);
539
+ },
540
+ colinsertright : function() {
541
+ this.colinsert(1);
542
+ },
543
+ rowinsert : function(offset) {
544
+ var table = self.plugin.getSelectedTable()[0],
545
+ row = self.plugin.getSelectedRow()[0],
546
+ cell = self.plugin.getSelectedCell()[0],
547
+ newRow;
548
+ if (offset === 1) {
549
+ newRow = table.insertRow(row.rowIndex + (cell.rowSpan - 1) + offset);
550
+ } else {
551
+ newRow = table.insertRow(row.rowIndex);
552
+ }
553
+ for (var i = 0, len = row.cells.length; i < len; i++) {
554
+ var newCell = newRow.insertCell(i);
555
+ // copy colspan
556
+ if (offset === 1 && row.cells[i].colSpan > 1) {
557
+ newCell.colSpan = row.cells[i].colSpan;
558
+ }
559
+ newCell.innerHTML = K.IE ? '' : '<br />';
560
+ }
561
+ self.cmd.range.selectNodeContents(cell).collapse(true);
562
+ self.cmd.select();
563
+ self.addBookmark();
564
+ },
565
+ rowinsertabove : function() {
566
+ this.rowinsert(0);
567
+ },
568
+ rowinsertbelow : function() {
569
+ this.rowinsert(1);
570
+ },
571
+ rowmerge : function() {
572
+ var table = self.plugin.getSelectedTable()[0],
573
+ row = self.plugin.getSelectedRow()[0],
574
+ cell = self.plugin.getSelectedCell()[0],
575
+ rowIndex = row.rowIndex, // 当前行的index
576
+ nextRowIndex = rowIndex + cell.rowSpan, // 下一行的index
577
+ nextRow = table.rows[nextRowIndex]; // 下一行
578
+ // 最后一行不能合并
579
+ if (table.rows.length <= nextRowIndex) {
580
+ return;
581
+ }
582
+ var cellIndex = _getCellIndex(table, row, cell); // 下一行单元格的index
583
+ if (nextRow.cells.length <= cellIndex) {
584
+ return;
585
+ }
586
+ var nextCell = nextRow.cells[cellIndex]; // 下一行单元格
587
+ // 上下行的colspan不一致时不能合并
588
+ if (cell.colSpan !== nextCell.colSpan) {
589
+ return;
590
+ }
591
+ cell.rowSpan += nextCell.rowSpan;
592
+ nextRow.deleteCell(cellIndex);
593
+ self.cmd.range.selectNodeContents(cell).collapse(true);
594
+ self.cmd.select();
595
+ self.addBookmark();
596
+ },
597
+ colmerge : function() {
598
+ var table = self.plugin.getSelectedTable()[0],
599
+ row = self.plugin.getSelectedRow()[0],
600
+ cell = self.plugin.getSelectedCell()[0],
601
+ rowIndex = row.rowIndex, // 当前行的index
602
+ cellIndex = cell.cellIndex,
603
+ nextCellIndex = cellIndex + 1;
604
+ // 最后一列不能合并
605
+ if (row.cells.length <= nextCellIndex) {
606
+ return;
607
+ }
608
+ var nextCell = row.cells[nextCellIndex];
609
+ // 左右列的rowspan不一致时不能合并
610
+ if (cell.rowSpan !== nextCell.rowSpan) {
611
+ return;
612
+ }
613
+ cell.colSpan += nextCell.colSpan;
614
+ row.deleteCell(nextCellIndex);
615
+ self.cmd.range.selectNodeContents(cell).collapse(true);
616
+ self.cmd.select();
617
+ self.addBookmark();
618
+ },
619
+ rowsplit : function() {
620
+ var table = self.plugin.getSelectedTable()[0],
621
+ row = self.plugin.getSelectedRow()[0],
622
+ cell = self.plugin.getSelectedCell()[0],
623
+ rowIndex = row.rowIndex;
624
+ // 不是可分割单元格
625
+ if (cell.rowSpan === 1) {
626
+ return;
627
+ }
628
+ var cellIndex = _getCellIndex(table, row, cell);
629
+ for (var i = 1, len = cell.rowSpan; i < len; i++) {
630
+ var newRow = table.rows[rowIndex + i],
631
+ newCell = newRow.insertCell(cellIndex);
632
+ if (cell.colSpan > 1) {
633
+ newCell.colSpan = cell.colSpan;
634
+ }
635
+ newCell.innerHTML = K.IE ? '' : '<br />';
636
+ // 调整下一行的单元格index
637
+ cellIndex = _getCellIndex(table, newRow, newCell);
638
+ }
639
+ K(cell).removeAttr('rowSpan');
640
+ self.cmd.range.selectNodeContents(cell).collapse(true);
641
+ self.cmd.select();
642
+ self.addBookmark();
643
+ },
644
+ colsplit : function() {
645
+ var table = self.plugin.getSelectedTable()[0],
646
+ row = self.plugin.getSelectedRow()[0],
647
+ cell = self.plugin.getSelectedCell()[0],
648
+ cellIndex = cell.cellIndex;
649
+ // 不是可分割单元格
650
+ if (cell.colSpan === 1) {
651
+ return;
652
+ }
653
+ for (var i = 1, len = cell.colSpan; i < len; i++) {
654
+ var newCell = row.insertCell(cellIndex + i);
655
+ if (cell.rowSpan > 1) {
656
+ newCell.rowSpan = cell.rowSpan;
657
+ }
658
+ newCell.innerHTML = K.IE ? '' : '<br />';
659
+ }
660
+ K(cell).removeAttr('colSpan');
661
+ self.cmd.range.selectNodeContents(cell).collapse(true);
662
+ self.cmd.select();
663
+ self.addBookmark();
664
+ },
665
+ coldelete : function() {
666
+ var table = self.plugin.getSelectedTable()[0],
667
+ row = self.plugin.getSelectedRow()[0],
668
+ cell = self.plugin.getSelectedCell()[0],
669
+ index = cell.cellIndex;
670
+ for (var i = 0, len = table.rows.length; i < len; i++) {
671
+ var newRow = table.rows[i],
672
+ newCell = newRow.cells[index];
673
+ if (newCell.colSpan > 1) {
674
+ newCell.colSpan -= 1;
675
+ if (newCell.colSpan === 1) {
676
+ K(newCell).removeAttr('colSpan');
677
+ }
678
+ } else {
679
+ newRow.deleteCell(index);
680
+ }
681
+ // 跳过不需要删除的行
682
+ if (newCell.rowSpan > 1) {
683
+ i += newCell.rowSpan - 1;
684
+ }
685
+ }
686
+ if (row.cells.length === 0) {
687
+ self.cmd.range.setStartBefore(table).collapse(true);
688
+ self.cmd.select();
689
+ K(table).remove();
690
+ } else {
691
+ self.cmd.selection(true);
692
+ }
693
+ self.addBookmark();
694
+ },
695
+ rowdelete : function() {
696
+ var table = self.plugin.getSelectedTable()[0],
697
+ row = self.plugin.getSelectedRow()[0],
698
+ cell = self.plugin.getSelectedCell()[0],
699
+ rowIndex = row.rowIndex;
700
+ // 从下到上删除
701
+ for (var i = cell.rowSpan - 1; i >= 0; i--) {
702
+ table.deleteRow(rowIndex + i);
703
+ }
704
+ if (table.rows.length === 0) {
705
+ self.cmd.range.setStartBefore(table).collapse(true);
706
+ self.cmd.select();
707
+ K(table).remove();
708
+ } else {
709
+ self.cmd.selection(true);
710
+ }
711
+ self.addBookmark();
712
+ }
713
+ };
714
+ self.clickToolbar(name, self.plugin.table.prop);
715
+ });