video.js
6.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
var $=require('jquery');
require("../util/jquery-ui.min");
(function () {
var Base = {
scale: function (img, max, oWidth, oHeight) {
var width = 0, height = 0, percent, ow = img.width || oWidth, oh = img.height || oHeight;
if (ow > max || oh > max) {
if (ow >= oh) {
if (width = ow - max) {
percent = (width / ow).toFixed(2);
img.height = oh - oh * percent;
img.width = max;
}
} else {
if (height = oh - max) {
percent = (height / oh).toFixed(2);
img.width = ow - ow * percent;
img.height = max;
}
}
}
return this;
},
close: function ($img) {
$img.css({
//top: ($img.parent().height() - $img.height()) / 2,
left: ($img.parent().width()-$img.width())/2
});
return this;
},
callback: function (editor, $w, url, state) {
}
};
var Product={
init: function (editor, $w) {
var me = this;
me.editor = editor;
me.dialog = $w;
me.initEvt();
},
initEvt: function () {
var me = this,
$ele = $(".edui-image-product .edui-product-content", me.dialog);
if($.trim($('#productSkn').val())){
$.ajax({
url:"/productVideo/queryProductVideoList",
data:{
skn:$('#productSkn').val()
},
dataType: 'json',
method:'post',
success:function(res){
var data = res;
if (res.code == 200 && data.data instanceof Array){
var defaultUrl = UMEDITOR_CONFIG.UMEDITOR_HOME_URL + "static/assets/images/defaultvideo.png";
$.each(data.data, function (index, video) {
var url = video.url;
var name = video.videoName;
if (url) {
$(".edui-tab-content").html("<div class='edui-image-product edui-tab-pane edui-active'><div class='edui-product-content'></div></div>");
$("<img src='" + defaultUrl + "' data-src='" + url + "' class='edui-image-pic' />").on("load", function () {
var $item = $("<div class='edui-image-item'></div>").append(this);
$item.append($("<span class='namelabel'>" + name + "</span><label>宽 </label><input class='widthinput' type='text' maxlength='5' placeholder='750' value=''><label>高 </label><input class='heightinput' type='text' maxlength='5' placeholder='420' value=''>"));
$(".edui-image-product .edui-product-content", me.dialog).append($item);
Base.scale(this, 120);
$item.width(120);
$item.height(165);
Base.close($(this));
});
}
});
}
}
});
$(document).on("click",".edui-image-product .edui-product-content .edui-image-pic",function(){
if ($(this).parent().hasClass("active-product")) {
$(this).parent().removeClass("active-product");
}
else {
$(this).parent().addClass("active-product");
}
});
}
}
}
var $tab = null,
currentDialog = null;
UM.registerWidget('video', {
tpl:
"<div class=\"edui-image-wrapper\">" +
"<div class=\"edui-tab-content\">" +
"</div>" +
"</div>",
initContent: function (editor, $dialog) {
var lang = editor.getLang('image')["static"],
opt = $.extend({}, lang, {
image_url: UMEDITOR_CONFIG.UMEDITOR_HOME_URL + 'dialogs/image/'
});
//Upload.showCount = 0;
if (lang) {
var html = $.parseTmpl(this.tpl, opt);
}
currentDialog = $dialog.edui();
this.root().html(html);
// 禁止滚动
$(document.body).css("overflow", "hidden");
$(".fileinput-button").hide();
},
initEvent: function (editor, $w) {
$tab = $.eduitab({selector: ".edui-image-wrapper"})
.edui().on("beforeshow", function (e) {
e.stopPropagation();
});
Product.init(editor, $w);
},
/**
* 将单个视频信息插入编辑器中
*/
insertSingle: function(editor){
$('.active-product').each(function() {
var img = $(this).find(".edui-image-pic")[0],
widthinput = $(this).find(".widthinput")[0],
heightinput = $(this).find(".heightinput")[0];
editor.execCommand('insertvideo', {
url: $(img).attr('data-src'),
width: $(widthinput).val() || 750 ,
height: $(heightinput).val() || 420 ,
align: null
});
});
},
buttons: {
'ok': {
exec: function (editor, $w) {
// 允许滚动
$(document.body).css("overflow", "scroll");
$(".fileinput-button").show();
editor.getWidgetData("video").insertSingle(editor);
}
},
'cancel': {
exec: function() {
// 允许滚动
$(document.body).css("overflow", "scroll");
$(".fileinput-button").show();
$(document).off("click",".edui-image-product .edui-product-content .edui-image-pic");
}
}
},
width: 700,
height: 408
}, function (editor, $w, url, state) {
Base.callback(editor, $w, url, state)
})
})();