umeditor-rails 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +31 -0
  6. data/Rakefile +2 -0
  7. data/app/assets/javascripts/umeditor.js +2 -0
  8. data/lib/tasks/umeditor.rake +12 -0
  9. data/lib/umeditor/rails/engine.rb +20 -0
  10. data/lib/umeditor/rails/version.rb +6 -0
  11. data/lib/umeditor/rails.rb +7 -0
  12. data/lib/umeditor-rails.rb +1 -0
  13. data/umeditor-rails.gemspec +23 -0
  14. data/vendor/assets/javascripts/umeditor/dialogs/emotion/emotion.css +87 -0
  15. data/vendor/assets/javascripts/umeditor/dialogs/emotion/emotion.js +272 -0
  16. data/vendor/assets/javascripts/umeditor/dialogs/emotion/images/0.gif +0 -0
  17. data/vendor/assets/javascripts/umeditor/dialogs/emotion/images/bface.gif +0 -0
  18. data/vendor/assets/javascripts/umeditor/dialogs/emotion/images/cface.gif +0 -0
  19. data/vendor/assets/javascripts/umeditor/dialogs/emotion/images/fface.gif +0 -0
  20. data/vendor/assets/javascripts/umeditor/dialogs/emotion/images/jxface2.gif +0 -0
  21. data/vendor/assets/javascripts/umeditor/dialogs/emotion/images/neweditor-tab-bg.png +0 -0
  22. data/vendor/assets/javascripts/umeditor/dialogs/emotion/images/tface.gif +0 -0
  23. data/vendor/assets/javascripts/umeditor/dialogs/emotion/images/wface.gif +0 -0
  24. data/vendor/assets/javascripts/umeditor/dialogs/emotion/images/yface.gif +0 -0
  25. data/vendor/assets/javascripts/umeditor/dialogs/formula/formula.css +32 -0
  26. data/vendor/assets/javascripts/umeditor/dialogs/formula/formula.html +212 -0
  27. data/vendor/assets/javascripts/umeditor/dialogs/formula/formula.js +124 -0
  28. data/vendor/assets/javascripts/umeditor/dialogs/formula/images/formula.png +0 -0
  29. data/vendor/assets/javascripts/umeditor/dialogs/image/image.css +42 -0
  30. data/vendor/assets/javascripts/umeditor/dialogs/image/image.js +445 -0
  31. data/vendor/assets/javascripts/umeditor/dialogs/image/images/close.png +0 -0
  32. data/vendor/assets/javascripts/umeditor/dialogs/image/images/upload1.png +0 -0
  33. data/vendor/assets/javascripts/umeditor/dialogs/image/images/upload2.png +0 -0
  34. data/vendor/assets/javascripts/umeditor/dialogs/link/link.js +73 -0
  35. data/vendor/assets/javascripts/umeditor/dialogs/map/map.html +148 -0
  36. data/vendor/assets/javascripts/umeditor/dialogs/map/map.js +263 -0
  37. data/vendor/assets/javascripts/umeditor/dialogs/video/images/center_focus.jpg +0 -0
  38. data/vendor/assets/javascripts/umeditor/dialogs/video/images/left_focus.jpg +0 -0
  39. data/vendor/assets/javascripts/umeditor/dialogs/video/images/none_focus.jpg +0 -0
  40. data/vendor/assets/javascripts/umeditor/dialogs/video/images/right_focus.jpg +0 -0
  41. data/vendor/assets/javascripts/umeditor/dialogs/video/video.css +59 -0
  42. data/vendor/assets/javascripts/umeditor/dialogs/video/video.js +282 -0
  43. data/vendor/assets/javascripts/umeditor/index.html +277 -0
  44. data/vendor/assets/javascripts/umeditor/lang/en/en.js +150 -0
  45. data/vendor/assets/javascripts/umeditor/lang/en/images/addimage.png +0 -0
  46. data/vendor/assets/javascripts/umeditor/lang/en/images/alldeletebtnhoverskin.png +0 -0
  47. data/vendor/assets/javascripts/umeditor/lang/en/images/alldeletebtnupskin.png +0 -0
  48. data/vendor/assets/javascripts/umeditor/lang/en/images/background.png +0 -0
  49. data/vendor/assets/javascripts/umeditor/lang/en/images/button.png +0 -0
  50. data/vendor/assets/javascripts/umeditor/lang/en/images/copy.png +0 -0
  51. data/vendor/assets/javascripts/umeditor/lang/en/images/deletedisable.png +0 -0
  52. data/vendor/assets/javascripts/umeditor/lang/en/images/deleteenable.png +0 -0
  53. data/vendor/assets/javascripts/umeditor/lang/en/images/imglabel.png +0 -0
  54. data/vendor/assets/javascripts/umeditor/lang/en/images/listbackground.png +0 -0
  55. data/vendor/assets/javascripts/umeditor/lang/en/images/localimage.png +0 -0
  56. data/vendor/assets/javascripts/umeditor/lang/en/images/music.png +0 -0
  57. data/vendor/assets/javascripts/umeditor/lang/en/images/rotateleftdisable.png +0 -0
  58. data/vendor/assets/javascripts/umeditor/lang/en/images/rotateleftenable.png +0 -0
  59. data/vendor/assets/javascripts/umeditor/lang/en/images/rotaterightdisable.png +0 -0
  60. data/vendor/assets/javascripts/umeditor/lang/en/images/rotaterightenable.png +0 -0
  61. data/vendor/assets/javascripts/umeditor/lang/en/images/upload.png +0 -0
  62. data/vendor/assets/javascripts/umeditor/lang/zh-cn/images/copy.png +0 -0
  63. data/vendor/assets/javascripts/umeditor/lang/zh-cn/images/imglabel.png +0 -0
  64. data/vendor/assets/javascripts/umeditor/lang/zh-cn/images/localimage.png +0 -0
  65. data/vendor/assets/javascripts/umeditor/lang/zh-cn/images/music.png +0 -0
  66. data/vendor/assets/javascripts/umeditor/lang/zh-cn/images/upload.png +0 -0
  67. data/vendor/assets/javascripts/umeditor/lang/zh-cn/zh-cn.js +150 -0
  68. data/vendor/assets/javascripts/umeditor/themes/default/css/umeditor.css +773 -0
  69. data/vendor/assets/javascripts/umeditor/themes/default/css/umeditor.min.css +8 -0
  70. data/vendor/assets/javascripts/umeditor/themes/default/images/caret.png +0 -0
  71. data/vendor/assets/javascripts/umeditor/themes/default/images/close.png +0 -0
  72. data/vendor/assets/javascripts/umeditor/themes/default/images/icons.gif +0 -0
  73. data/vendor/assets/javascripts/umeditor/themes/default/images/icons.png +0 -0
  74. data/vendor/assets/javascripts/umeditor/themes/default/images/ok.gif +0 -0
  75. data/vendor/assets/javascripts/umeditor/themes/default/images/pop-bg.png +0 -0
  76. data/vendor/assets/javascripts/umeditor/themes/default/images/spacer.gif +0 -0
  77. data/vendor/assets/javascripts/umeditor/themes/default/images/videologo.gif +0 -0
  78. data/vendor/assets/javascripts/umeditor/third-party/jquery.min.js +6 -0
  79. data/vendor/assets/javascripts/umeditor/third-party/mathquill/font/Symbola.eot +0 -0
  80. data/vendor/assets/javascripts/umeditor/third-party/mathquill/font/Symbola.otf +0 -0
  81. data/vendor/assets/javascripts/umeditor/third-party/mathquill/font/Symbola.svg +5102 -0
  82. data/vendor/assets/javascripts/umeditor/third-party/mathquill/font/Symbola.ttf +0 -0
  83. data/vendor/assets/javascripts/umeditor/third-party/mathquill/font/Symbola.woff +0 -0
  84. data/vendor/assets/javascripts/umeditor/third-party/mathquill/font/stixgeneral-bundle/STIXFontLicense2010.txt +103 -0
  85. data/vendor/assets/javascripts/umeditor/third-party/mathquill/font/stixgeneral-bundle/stixgeneral-webfont.eot +0 -0
  86. data/vendor/assets/javascripts/umeditor/third-party/mathquill/font/stixgeneral-bundle/stixgeneral-webfont.svg +3318 -0
  87. data/vendor/assets/javascripts/umeditor/third-party/mathquill/font/stixgeneral-bundle/stixgeneral-webfont.ttf +0 -0
  88. data/vendor/assets/javascripts/umeditor/third-party/mathquill/font/stixgeneral-bundle/stixgeneral-webfont.woff +0 -0
  89. data/vendor/assets/javascripts/umeditor/third-party/mathquill/font/stixgeneral-bundle/stixgeneralbol-webfont.eot +0 -0
  90. data/vendor/assets/javascripts/umeditor/third-party/mathquill/font/stixgeneral-bundle/stixgeneralbol-webfont.svg +1738 -0
  91. data/vendor/assets/javascripts/umeditor/third-party/mathquill/font/stixgeneral-bundle/stixgeneralbol-webfont.ttf +0 -0
  92. data/vendor/assets/javascripts/umeditor/third-party/mathquill/font/stixgeneral-bundle/stixgeneralbol-webfont.woff +0 -0
  93. data/vendor/assets/javascripts/umeditor/third-party/mathquill/font/stixgeneral-bundle/stixgeneralbolita-webfont.eot +0 -0
  94. data/vendor/assets/javascripts/umeditor/third-party/mathquill/font/stixgeneral-bundle/stixgeneralbolita-webfont.svg +1137 -0
  95. data/vendor/assets/javascripts/umeditor/third-party/mathquill/font/stixgeneral-bundle/stixgeneralbolita-webfont.ttf +0 -0
  96. data/vendor/assets/javascripts/umeditor/third-party/mathquill/font/stixgeneral-bundle/stixgeneralbolita-webfont.woff +0 -0
  97. data/vendor/assets/javascripts/umeditor/third-party/mathquill/font/stixgeneral-bundle/stixgeneralitalic-webfont.eot +0 -0
  98. data/vendor/assets/javascripts/umeditor/third-party/mathquill/font/stixgeneral-bundle/stixgeneralitalic-webfont.svg +1089 -0
  99. data/vendor/assets/javascripts/umeditor/third-party/mathquill/font/stixgeneral-bundle/stixgeneralitalic-webfont.ttf +0 -0
  100. data/vendor/assets/javascripts/umeditor/third-party/mathquill/font/stixgeneral-bundle/stixgeneralitalic-webfont.woff +0 -0
  101. data/vendor/assets/javascripts/umeditor/third-party/mathquill/mathquill.css +357 -0
  102. data/vendor/assets/javascripts/umeditor/third-party/mathquill/mathquill.js +3888 -0
  103. data/vendor/assets/javascripts/umeditor/third-party/mathquill/mathquill.min.js +2 -0
  104. data/vendor/assets/javascripts/umeditor/umeditor.config.js +249 -0
  105. data/vendor/assets/javascripts/umeditor/umeditor.js +10923 -0
  106. data/vendor/assets/javascripts/umeditor/umeditor.min.js +264 -0
  107. metadata +178 -0
@@ -0,0 +1,263 @@
1
+ (function () {
2
+
3
+ var widgetName = 'map';
4
+
5
+ UM.registerWidget(widgetName, {
6
+
7
+ tpl: "<style type=\"text/css\">" +
8
+ ".edui-dialog-map .edui-map-content{width:530px; height: 350px;margin: 10px auto;}" +
9
+ ".edui-dialog-map .edui-map-content table{width: 100%}" +
10
+ ".edui-dialog-map .edui-map-content table td{vertical-align: middle;}" +
11
+ ".edui-dialog-map .edui-map-button { border: 1px solid #ccc; float: left; cursor: default; height: 23px; width: 70px; cursor: pointer; margin: 0; font-size: 12px; line-height: 24px; text-align: center; }" +
12
+ ".edui-dialog-map .edui-map-button:hover {background:#eee;}" +
13
+ ".edui-dialog-map .edui-map-city,.edui-dialog-map .edui-map-address{height:21px;background: #FFF;border:1px solid #d7d7d7; line-height: 21px;}" +
14
+ ".edui-dialog-map .edui-map-city{width:90px}" +
15
+ ".edui-dialog-map .edui-map-address{width:150px}" +
16
+ ".edui-dialog-map .edui-map-dynamic-label span{vertical-align:middle;margin: 3px 0px 3px 3px;}" +
17
+ ".edui-dialog-map .edui-map-dynamic-label input{vertical-align:middle;margin: 3px;}" +
18
+ "</style>" +
19
+ "<div class=\"edui-map-content\">" +
20
+ "<table>" +
21
+ "<tr>" +
22
+ "<td><%=lang_city%>:</td>" +
23
+ "<td><input class=\"edui-map-city\" type=\"text\" value=\"<%=city.value%>\"/></td>" +
24
+ "<td><%=lang_address%>:</td>" +
25
+ "<td><input class=\"edui-map-address\" type=\"text\" value=\"\" /></td>" +
26
+ "<td><a class=\"edui-map-button\"><%=lang_search%></a></td>" +
27
+ "<td><label class=\"edui-map-dynamic-label\"><input class=\"edui-map-dynamic\" type=\"checkbox\" name=\"edui-map-dynamic\" /><span><%=lang_dynamicmap%></span></label></td>"+
28
+ "</tr>" +
29
+ "</table>" +
30
+ "<div style=\"width:100%;height:340px;margin:5px auto;border:1px solid gray\" class=\"edui-map-container\"></div>" +
31
+ "</div>" +
32
+ "<script class=\"edui-tpl-container\" type=\"text/plain\">" +
33
+ "<!DOCTYPE html>" +
34
+ "<html>" +
35
+ "<head>" +
36
+ "<title></title>" +
37
+ "</head>" +
38
+ "<body>" +
39
+ "<scr_ipt>" +
40
+ "window.onload = function(){" +
41
+ "var scripts = document.scripts || document.getElementsByTagName(\"script\")," +
42
+ "src = [];" +
43
+ "for( var i = 1, len = scripts.length; i<len; i++ ) {" +
44
+ "src.push( scripts[i].src );" +
45
+ "}" +
46
+ "parent.UM.getEditor(<<id>>).getWidgetData(\'map\').requestMapApi( src );" +
47
+ "};" +
48
+ "function mapReadyStateChange ( state ) { " +
49
+ " if ( state === 'complete' || state === 'loaded' ) {" +
50
+ " document.close(); " +
51
+ " } }" +
52
+ "</scr_ipt>" +
53
+ "<scr_ipt onreadystatechange='mapReadyStateChange(this.readyState);' onload='mapReadyStateChange(\"loaded\");' src=\"http://api.map.baidu.com/api?v=2.0&ak=6b6c1a67eaa7db1ca6d6da28e590e343&services=true\"></scr_ipt>" +
54
+ "</body>" +
55
+ "</html>" +
56
+ "</script>",
57
+ initContent: function (editor, $widget) {
58
+
59
+ var me = this,
60
+ lang = editor.getLang(widgetName),
61
+ theme_url = editor.options.themePath + editor.options.theme;
62
+
63
+ if( me.inited ) {
64
+ me.preventDefault();
65
+ return false;
66
+ }
67
+
68
+ me.inited = true;
69
+
70
+ me.lang = lang;
71
+ me.editor = editor;
72
+
73
+ me.root().html($.parseTmpl(me.tpl, $.extend({}, lang['static'], {
74
+ 'theme_url': theme_url
75
+ })));
76
+
77
+ me.initRequestApi();
78
+
79
+ },
80
+ /**
81
+ * 初始化请求API
82
+ */
83
+ initRequestApi: function () {
84
+
85
+ var $ifr = null;
86
+
87
+ //已经初始化过, 不用再次初始化
88
+ if (window.BMap && window.BMap.Map) {
89
+ this.initBaiduMap();
90
+ } else {
91
+
92
+ $ifr = $('<iframe style="display: none;"></iframe>');
93
+ $ifr.appendTo( this.root() );
94
+
95
+ $ifr = $ifr[ 0 ].contentWindow.document;
96
+
97
+ $ifr.open();
98
+ $ifr.write( this.root().find(".edui-tpl-container").html().replace( /scr_ipt/g, 'script').replace('<<id>>',"'" + this.editor.id + "'") );
99
+
100
+ }
101
+
102
+ },
103
+ requestMapApi: function (src) {
104
+
105
+ var me = this;
106
+
107
+ if (src.length) {
108
+
109
+ var _src = src[0];
110
+
111
+ src = src.slice(1);
112
+
113
+ if (_src) {
114
+ $.getScript(_src, function () {
115
+ me.requestMapApi(src);
116
+ });
117
+ } else {
118
+ me.requestMapApi(src);
119
+ }
120
+
121
+ } else {
122
+
123
+ me.initBaiduMap();
124
+
125
+ }
126
+
127
+
128
+ },
129
+ initBaiduMap: function () {
130
+
131
+ var $root = this.root(),
132
+ map = new BMap.Map($root.find(".edui-map-container")[0]),
133
+ me = this,
134
+ marker,
135
+ point,
136
+ imgcss,
137
+ img = $(me.editor.selection.getRange().getClosedNode());
138
+
139
+ map.enableInertialDragging();
140
+ map.enableScrollWheelZoom();
141
+ map.enableContinuousZoom();
142
+
143
+ if (img.length && /api[.]map[.]baidu[.]com/ig.test(img.attr("src"))) {
144
+ var url = img.attr("src"),
145
+ centerPos = me.getPars(url, "center").split(","),
146
+ markerPos = me.getPars(url, "markers").split(",");
147
+ point = new BMap.Point(Number(centerPos[0]), Number(centerPos[1]));
148
+ marker = new BMap.Marker(new BMap.Point(Number(markerPos[0]), Number(markerPos[1])));
149
+ map.addControl(new BMap.NavigationControl());
150
+ map.centerAndZoom(point, Number(me.getPars(url, "zoom")));
151
+ imgcss = img.attr('style');
152
+ } else {
153
+ point = new BMap.Point(116.404, 39.915); // 创建点坐标
154
+ marker = new BMap.Marker(point);
155
+ map.addControl(new BMap.NavigationControl());
156
+ map.centerAndZoom(point, 10); // 初始化地图,设置中心点坐标和地图级别。
157
+ }
158
+ marker.enableDragging();
159
+ map.addOverlay(marker);
160
+
161
+ me.map = map;
162
+ me.marker = marker;
163
+ me.imgcss = imgcss;
164
+ },
165
+ doSearch: function () {
166
+ var me = this,
167
+ city = me.root().find('.edui-map-city').val(),
168
+ address = me.root().find('.edui-map-address').val();
169
+
170
+ if (!city) {
171
+ alert(me.lang.cityMsg);
172
+ return;
173
+ }
174
+ var search = new BMap.LocalSearch(city, {
175
+ onSearchComplete: function (results) {
176
+ if (results && results.getNumPois()) {
177
+ var points = [];
178
+ for (var i = 0; i < results.getCurrentNumPois(); i++) {
179
+ points.push(results.getPoi(i).point);
180
+ }
181
+ if (points.length > 1) {
182
+ me.map.setViewport(points);
183
+ } else {
184
+ me.map.centerAndZoom(points[0], 13);
185
+ }
186
+ point = me.map.getCenter();
187
+ me.marker.setPoint(point);
188
+ } else {
189
+ alert(me.lang.errorMsg);
190
+ }
191
+ }
192
+ });
193
+ search.search(address || city);
194
+ },
195
+ getPars: function (str, par) {
196
+ var reg = new RegExp(par + "=((\\d+|[.,])*)", "g");
197
+ return reg.exec(str)[1];
198
+ },
199
+ reset: function(){
200
+ this.map && this.map.reset();
201
+ },
202
+ initEvent: function () {
203
+ var me = this,
204
+ $root = me.root();
205
+
206
+ $root.find('.edui-map-address').on('keydown', function (evt) {
207
+ evt = evt || event;
208
+ if (evt.keyCode == 13) {
209
+ me.doSearch();
210
+ return false;
211
+ }
212
+ });
213
+
214
+ $root.find(".edui-map-button").on('click', function (evt) {
215
+ me.doSearch();
216
+ });
217
+
218
+ $root.find(".edui-map-address").focus();
219
+
220
+ $root.on( "mousewheel DOMMouseScroll", function ( e ) {
221
+ return false;
222
+ } );
223
+
224
+ },
225
+ width: 580,
226
+ height: 408,
227
+ buttons: {
228
+ ok: {
229
+ exec: function (editor) {
230
+ var widget = editor.getWidgetData(widgetName),
231
+ center = widget.map.getCenter(),
232
+ zoom = widget.map.getZoom(),
233
+ size = widget.map.getSize(),
234
+ point = widget.marker.P;
235
+
236
+ if (widget.root().find(".edui-map-dynamic")[0].checked) {
237
+ var URL = editor.getOpt('UMEDITOR_HOME_URL'),
238
+ url = [URL + (/\/$/.test(URL) ? '':'/') + "dialogs/map/map.html" +
239
+ '#center=' + center.lng + ',' + center.lat,
240
+ '&zoom=' + zoom,
241
+ '&width=' + size.width,
242
+ '&height=' + size.height,
243
+ '&markers=' + point.lng + ',' + point.lat].join('');
244
+ editor.execCommand('inserthtml', '<iframe class="ueditor_baidumap" src="' + url + '" frameborder="0" width="' + (size.width+4) + '" height="' + (size.height+4) + '"></iframe>');
245
+ } else {
246
+ url = "http://api.map.baidu.com/staticimage?center=" + center.lng + ',' + center.lat +
247
+ "&zoom=" + zoom + "&width=" + size.width + '&height=' + size.height + "&markers=" + point.lng + ',' + point.lat;
248
+ editor.execCommand('inserthtml', '<img width="' + size.width + '"height="' + size.height + '" src="' + url + '"' + (widget.imgcss ? ' style="' + widget.imgcss + '"' : '') + '/>', true);
249
+ }
250
+
251
+ widget.reset();
252
+ }
253
+ },
254
+ cancel: {
255
+ exec: function(editor){
256
+ editor.getWidgetData(widgetName).reset();
257
+ }
258
+ }
259
+ }
260
+ });
261
+
262
+ })();
263
+
@@ -0,0 +1,59 @@
1
+ @charset "utf-8";
2
+ .edui-dialog-video .edui-video-wrapper{ width: 570px;_width:575px;margin: 10px auto; zoom:1;position: relative}
3
+ .edui-dialog-video .edui-video-tabbody{height:335px;}
4
+ .edui-dialog-video .edui-video-panel { position: absolute;width:100%; height:100%;background: #fff;}
5
+ .edui-dialog-video .edui-video-panel table td{vertical-align: middle;}
6
+ .edui-dialog-video #eduiVideoUrl {
7
+ width: 470px;
8
+ height: 21px;
9
+ line-height: 21px;
10
+ margin: 8px 5px;
11
+ background: #FFF;
12
+ border: 1px solid #d7d7d7;
13
+ }
14
+ .edui-dialog-video #eduiVideoSearchTxt{margin-left:15px;background: #FFF;width:200px;height:21px;line-height:21px;border: 1px solid #d7d7d7;}
15
+ .edui-dialog-video #searchList{width: 570px;overflow: auto;zoom:1;height: 270px;}
16
+ .edui-dialog-video #searchList div{float: left;width: 120px;height: 135px;margin: 5px 15px;}
17
+ .edui-dialog-video #searchList img{margin: 2px 8px;cursor: pointer;border: 2px solid #fff} /*不用缩略图*/
18
+ .edui-dialog-video #searchList p{margin-left: 10px;}
19
+ .edui-dialog-video #eduiVideoType{
20
+ width: 65px;
21
+ height: 23px;
22
+ line-height: 22px;
23
+ border: 1px solid #d7d7d7;
24
+ }
25
+ .edui-dialog-video #eduiVideoSearchBtn,.edui-dialog-video #eduiVideoSearchReset{
26
+ /*width: 80px;*/
27
+ height: 25px;
28
+ line-height: 25px;
29
+ background: #eee;
30
+ border: 1px solid #d7d7d7;
31
+ cursor: pointer;
32
+ padding: 0 5px;
33
+ }
34
+
35
+
36
+
37
+ .edui-dialog-video #eduiVideoPreview{width: 420px; margin-left: 10px; _margin-left:5px; height: 280px;background-color: #ddd;float: left}
38
+ .edui-dialog-video #eduiVideoInfo {width: 120px;float: left;margin-left: 10px;_margin-left:7px;}
39
+ .edui-dialog-video .edui-video-wrapper fieldset{
40
+ border: 1px solid #ddd;
41
+ padding-left: 5px;
42
+ margin-bottom: 20px;
43
+ padding-bottom: 5px;
44
+ width: 115px;
45
+ }
46
+ .edui-dialog-video .edui-video-wrapper fieldset legend{font-weight: bold;}
47
+ .edui-dialog-video .edui-video-wrapper fieldset p{line-height: 30px;}
48
+ .edui-dialog-video .edui-video-wrapper fieldset input.edui-video-txt{
49
+ width: 65px;
50
+ height: 21px;
51
+ line-height: 21px;
52
+ margin: 8px 5px;
53
+ background: #FFF;
54
+ border: 1px solid #d7d7d7;
55
+ }
56
+ .edui-dialog-video .edui-video-wrapper label.edui-video-url{font-weight: bold;margin-left: 5px;color: #06c;}
57
+ .edui-dialog-video #eduiVideoFloat div{cursor:pointer;opacity: 0.5;filter: alpha(opacity = 50);margin:9px;_margin:5px;width:38px;height:36px;float:left;}
58
+ .edui-dialog-video #eduiVideoFloat .edui-video-focus{opacity: 1;filter: alpha(opacity = 100)}
59
+ .edui-dialog-video .edui-video-wrapper span.edui-video-view{display: inline-block;width: 30px;float: right;cursor: pointer;color: blue}
@@ -0,0 +1,282 @@
1
+
2
+ (function(){
3
+ var domUtils = UM.dom.domUtils;
4
+ var widgetName = 'video';
5
+
6
+ UM.registerWidget( widgetName,{
7
+
8
+ tpl: "<link rel=\"stylesheet\" type=\"text/css\" href=\"<%=video_url%>video.css\" />" +
9
+ "<div class=\"edui-video-wrapper\">" +
10
+ "<div id=\"eduiVideoTab\">" +
11
+ "<div id=\"eduiVideoTabHeads\" class=\"edui-video-tabhead\">" +
12
+ "<span tabSrc=\"video\" class=\"edui-video-focus\"><%=lang_tab_insertV%></span>" +
13
+ "</div>" +
14
+ "<div id=\"eduiVideoTabBodys\" class=\"edui-video-tabbody\">" +
15
+ "<div id=\"eduiVideoPanel\" class=\"edui-video-panel\">" +
16
+ "<table><tr><td><label for=\"eduiVideoUrl\" class=\"edui-video-url\"><%=lang_video_url%></label></td><td><input id=\"eduiVideoUrl\" type=\"text\"></td></tr></table>" +
17
+ "<div id=\"eduiVideoPreview\"></div>" +
18
+ "<div id=\"eduiVideoInfo\">" +
19
+ "<fieldset>" +
20
+ "<legend><%=lang_video_size%></legend>" +
21
+ "<table>" +
22
+ "<tr><td><label for=\"eduiVideoWidth\"><%=lang_videoW%></label></td><td><input class=\"edui-video-txt\" id=\"eduiVideoWidth\" type=\"text\"/></td></tr>" +
23
+ "<tr><td><label for=\"eduiVideoHeight\"><%=lang_videoH%></label></td><td><input class=\"edui-video-txt\" id=\"eduiVideoHeight\" type=\"text\"/></td></tr>" +
24
+ "</table>" +
25
+ "</fieldset>" +
26
+ "<fieldset>" +
27
+ "<legend><%=lang_alignment%></legend>" +
28
+ "<div id=\"eduiVideoFloat\"></div>" +
29
+ "</fieldset>" +
30
+ "</div>" +
31
+ "</div>" +
32
+ "</div>" +
33
+ "</div>" +
34
+ "</div>",
35
+ initContent:function( editor, $widget ){
36
+
37
+ var me = this,
38
+ lang = editor.getLang( widgetName),
39
+ video_url = UMEDITOR_CONFIG.UMEDITOR_HOME_URL + 'dialogs/video/';
40
+
41
+ me.lang = lang;
42
+ me.editor = editor;
43
+ me.$widget = $widget;
44
+ me.root().html( $.parseTmpl( me.tpl, $.extend( { video_url: video_url }, lang['static'] ) ) );
45
+
46
+ me.initController( lang );
47
+
48
+ },
49
+ initEvent:function(){
50
+
51
+ var me = this,
52
+ url = $("#eduiVideoUrl", me.$widget)[0];
53
+
54
+ if( 'oninput' in url ) {
55
+ url.oninput = function(){
56
+ me.createPreviewVideo( this.value );
57
+ };
58
+ } else {
59
+ url.onpropertychange = function () {
60
+ me.createPreviewVideo( this.value );
61
+ }
62
+ }
63
+
64
+ },
65
+ initController: function( lang ){
66
+
67
+ var me = this,
68
+ img = me.editor.selection.getRange().getClosedNode(),
69
+ url;
70
+
71
+ me.createAlignButton( ["eduiVideoFloat"] );
72
+
73
+ //编辑视频时初始化相关信息
74
+ if(img && img.className == "edui-faked-video"){
75
+ $("#eduiVideoUrl", me.$widget)[0].value = url = img.getAttribute("_url");
76
+ $("#eduiVideoWidth", me.$widget)[0].value = img.width;
77
+ $("#eduiVideoHeight", me.$widget)[0].value = img.height;
78
+ var align = domUtils.getComputedStyle(img,"float"),
79
+ parentAlign = domUtils.getComputedStyle(img.parentNode,"text-align");
80
+ me.updateAlignButton(parentAlign==="center"?"center":align);
81
+ }
82
+ me.createPreviewVideo(url);
83
+
84
+ },
85
+ /**
86
+ * 根据url生成视频预览
87
+ */
88
+ createPreviewVideo: function(url){
89
+
90
+ if ( !url )return;
91
+
92
+ var me = this,
93
+ lang = me.lang,
94
+ conUrl = me.convert_url(url);
95
+
96
+ if(!me.endWith(conUrl,[".swf",".flv",".wmv"])){
97
+ $("#eduiVideoPreview", me.$widget).html( lang.urlError );
98
+ return;
99
+ }
100
+ $("#eduiVideoPreview", me.$widget)[0].innerHTML = '<embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
101
+ ' src="' + url + '"' +
102
+ ' width="' + 420 + '"' +
103
+ ' height="' + 280 + '"' +
104
+ ' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" ></embed>';
105
+
106
+ },
107
+ /**
108
+ * 将单个视频信息插入编辑器中
109
+ */
110
+ insertSingle: function(){
111
+
112
+ var me = this,
113
+ width = $("#eduiVideoWidth", me.$widget)[0],
114
+ height = $("#eduiVideoHeight", me.$widget)[0],
115
+ url=$('#eduiVideoUrl', me.$widget)[0].value,
116
+ align = this.findFocus("eduiVideoFloat","name");
117
+
118
+ if(!url) return false;
119
+ if ( !me.checkNum( [width, height] ) ) return false;
120
+ this.editor.execCommand('insertvideo', {
121
+ url: me.convert_url(url),
122
+ width: width.value,
123
+ height: height.value,
124
+ align: align
125
+ });
126
+
127
+ },
128
+ /**
129
+ * URL转换
130
+ */
131
+ convert_url: function(url){
132
+ if ( !url ) return '';
133
+ var matches = url.match(/youtu.be\/(\w+)$/) ||
134
+ url.match(/youtube\.com\/watch\?v=(\w+)/) ||
135
+ url.match(/youtube.com\/v\/(\w+)/),
136
+ youku = url.match(/youku\.com\/v_show\/id_(\w+)/),
137
+ youkuPlay = /player\.youku\.com/ig.test(url);
138
+
139
+ if(youkuPlay){
140
+ url = url.replace(/\?f=.*/, "");
141
+ } else if (matches){
142
+ url = "https://www.youtube.com/v/" + matches[1] + "?version=3&feature=player_embedded";
143
+ }else if(youku){
144
+ url = "http://player.youku.com/player.php/sid/"+youku[1]+"/v.swf"
145
+ } else {
146
+ url = url.replace(/http:\/\/www\.tudou\.com\/programs\/view\/([\w\-]+)\/?/i, "http://www.tudou.com/v/$1")
147
+ .replace(/http:\/\/www\.youtube\.com\/watch\?v=([\w\-]+)/i, "http://www.youtube.com/v/$1")
148
+ .replace(/http:\/\/v\.youku\.com\/v_show\/id_([\w\-=]+)\.html/i, "http://player.youku.com/player.php/sid/$1")
149
+ .replace(/http:\/\/www\.56\.com\/u\d+\/v_([\w\-]+)\.html/i, "http://player.56.com/v_$1.swf")
150
+ .replace(/http:\/\/www.56.com\/w\d+\/play_album\-aid\-\d+_vid\-([^.]+)\.html/i, "http://player.56.com/v_$1.swf")
151
+ .replace(/http:\/\/v\.ku6\.com\/.+\/([^.]+)\.html/i, "http://player.ku6.com/refer/$1/v.swf")
152
+ .replace(/\?f=.*/, "");
153
+ }
154
+ return url;
155
+ },
156
+ /**
157
+ * 检测传入的所有input框中输入的长宽是否是正数
158
+ */
159
+ checkNum: function checkNum( nodes ) {
160
+
161
+ var me = this;
162
+
163
+ for ( var i = 0, ci; ci = nodes[i++]; ) {
164
+ var value = ci.value;
165
+ if ( !me.isNumber( value ) && value) {
166
+ alert( me.lang.numError );
167
+ ci.value = "";
168
+ ci.focus();
169
+ return false;
170
+ }
171
+ }
172
+ return true;
173
+ },
174
+ /**
175
+ * 数字判断
176
+ * @param value
177
+ */
178
+ isNumber: function( value ) {
179
+ return /(0|^[1-9]\d*$)/.test( value );
180
+ },
181
+ updateAlignButton: function( align ) {
182
+ var aligns = $( "#eduiVideoFloat", this.$widget )[0].children;
183
+
184
+ for ( var i = 0, ci; ci = aligns[i++]; ) {
185
+ if ( ci.getAttribute( "name" ) == align ) {
186
+ if ( ci.className !="edui-video-focus" ) {
187
+ ci.className = "edui-video-focus";
188
+ }
189
+ } else {
190
+ if ( ci.className =="edui-video-focus" ) {
191
+ ci.className = "";
192
+ }
193
+ }
194
+ }
195
+
196
+ },
197
+ /**
198
+ * 创建图片浮动选择按钮
199
+ * @param ids
200
+ */
201
+ createAlignButton: function( ids ) {
202
+ var lang = this.lang,
203
+ vidoe_home = UMEDITOR_CONFIG.UMEDITOR_HOME_URL + 'dialogs/video/';
204
+
205
+ for ( var i = 0, ci; ci = ids[i++]; ) {
206
+ var floatContainer = $( "#" + ci, this.$widget ) [0],
207
+ nameMaps = {"none":lang['default'], "left":lang.floatLeft, "right":lang.floatRight};
208
+ for ( var j in nameMaps ) {
209
+ var div = document.createElement( "div" );
210
+ div.setAttribute( "name", j );
211
+ if ( j == "none" ) div.className="edui-video-focus";
212
+ div.style.cssText = "background:url("+ vidoe_home +"images/" + j + "_focus.jpg);";
213
+ div.setAttribute( "title", nameMaps[j] );
214
+ floatContainer.appendChild( div );
215
+ }
216
+ this.switchSelect( ci );
217
+ }
218
+ },
219
+ /**
220
+ * 选择切换
221
+ */
222
+ switchSelect: function( selectParentId ) {
223
+ var selects = $( "#" + selectParentId, this.$widget )[0].children;
224
+ for ( var i = 0, ci; ci = selects[i++]; ) {
225
+ $(ci).on("click", function () {
226
+ for ( var j = 0, cj; cj = selects[j++]; ) {
227
+ cj.className = "";
228
+ cj.removeAttribute && cj.removeAttribute( "class" );
229
+ }
230
+ this.className = "edui-video-focus";
231
+ } )
232
+ }
233
+ },
234
+ /**
235
+ * 找到id下具有focus类的节点并返回该节点下的某个属性
236
+ * @param id
237
+ * @param returnProperty
238
+ */
239
+ findFocus: function( id, returnProperty ) {
240
+ var tabs = $( "#" + id , this.$widget)[0].children,
241
+ property;
242
+ for ( var i = 0, ci; ci = tabs[i++]; ) {
243
+ if ( ci.className=="edui-video-focus" ) {
244
+ property = ci.getAttribute( returnProperty );
245
+ break;
246
+ }
247
+ }
248
+ return property;
249
+ },
250
+ /**
251
+ * 末尾字符检测
252
+ */
253
+ endWith: function(str,endStrArr){
254
+ for(var i=0,len = endStrArr.length;i<len;i++){
255
+ var tmp = endStrArr[i];
256
+ if(str.length - tmp.length<0) return false;
257
+
258
+ if(str.substring(str.length-tmp.length)==tmp){
259
+ return true;
260
+ }
261
+ }
262
+ return false;
263
+ },
264
+ width:610,
265
+ height:498,
266
+ buttons: {
267
+ ok: {
268
+ exec: function( editor, $w ){
269
+ $("#eduiVideoPreview", $w).html("");
270
+ editor.getWidgetData(widgetName).insertSingle();
271
+ }
272
+ },
273
+ cancel: {
274
+ exec: function(){
275
+ //清除视频
276
+ $("#eduiVideoPreview").html("");
277
+ }
278
+ }
279
+ }
280
+ });
281
+
282
+ })();