Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform-ui
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
youjj
cloud-platform-ui
Commits
d7265ae2
Commit
d7265ae2
authored
Sep 10, 2019
by
libin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
图片与视频上传配置修改 actionUrl='/'+ ....
parent
726055c1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1840 additions
and
1824 deletions
+1840
-1824
image.js
static/utf8-jsp/dialogs/image/image.js
+1092
-1083
video.js
static/utf8-jsp/dialogs/video/video.js
+748
-741
No files found.
static/utf8-jsp/dialogs/image/image.js
View file @
d7265ae2
This source diff could not be displayed because it is too large. You can
view the blob
instead.
static/utf8-jsp/dialogs/video/video.js
View file @
d7265ae2
...
@@ -6,786 +6,793 @@
...
@@ -6,786 +6,793 @@
* To change this template use File | Settings | File Templates.
* To change this template use File | Settings | File Templates.
*/
*/
(
function
(){
(
function
()
{
var
video
=
{},
var
video
=
{},
uploadVideoList
=
[],
uploadVideoList
=
[],
isModifyUploadVideo
=
false
,
isModifyUploadVideo
=
false
,
uploadFile
;
uploadFile
;
window
.
onload
=
function
(){
window
.
onload
=
function
()
{
$focus
(
$G
(
"videoUrl"
));
$focus
(
$G
(
"videoUrl"
));
initTabs
();
initTabs
();
initVideo
();
initVideo
();
initUpload
();
initUpload
();
};
};
/* 初始化tab标签 */
/* 初始化tab标签 */
function
initTabs
(){
function
initTabs
()
{
var
tabs
=
$G
(
'tabHeads'
).
children
;
var
tabs
=
$G
(
'tabHeads'
).
children
;
for
(
var
i
=
0
;
i
<
tabs
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
tabs
.
length
;
i
++
)
{
domUtils
.
on
(
tabs
[
i
],
"click"
,
function
(
e
)
{
domUtils
.
on
(
tabs
[
i
],
"click"
,
function
(
e
)
{
var
j
,
bodyId
,
target
=
e
.
target
||
e
.
srcElement
;
var
j
,
bodyId
,
target
=
e
.
target
||
e
.
srcElement
;
for
(
j
=
0
;
j
<
tabs
.
length
;
j
++
)
{
for
(
j
=
0
;
j
<
tabs
.
length
;
j
++
)
{
bodyId
=
tabs
[
j
].
getAttribute
(
'data-content-id'
);
bodyId
=
tabs
[
j
].
getAttribute
(
'data-content-id'
);
if
(
tabs
[
j
]
==
target
){
if
(
tabs
[
j
]
==
target
)
{
domUtils
.
addClass
(
tabs
[
j
],
'focus'
);
domUtils
.
addClass
(
tabs
[
j
],
'focus'
);
domUtils
.
addClass
(
$G
(
bodyId
),
'focus'
);
domUtils
.
addClass
(
$G
(
bodyId
),
'focus'
);
}
else
{
}
else
{
domUtils
.
removeClasses
(
tabs
[
j
],
'focus'
);
domUtils
.
removeClasses
(
tabs
[
j
],
'focus'
);
domUtils
.
removeClasses
(
$G
(
bodyId
),
'focus'
);
domUtils
.
removeClasses
(
$G
(
bodyId
),
'focus'
);
}
}
}
});
}
}
});
}
}
}
function
initVideo
(){
createAlignButton
(
[
"videoFloat"
,
"upload_alignment"
]
);
function
initVideo
()
{
addUrlChangeListener
(
$G
(
"videoUrl"
));
createAlignButton
([
"videoFloat"
,
"upload_alignment"
]);
addOkListener
();
addUrlChangeListener
(
$G
(
"videoUrl"
));
addOkListener
();
//编辑视频时初始化相关信息
(
function
(){
//编辑视频时初始化相关信息
var
img
=
editor
.
selection
.
getRange
().
getClosedNode
(),
url
;
(
function
()
{
if
(
img
&&
img
.
className
){
var
img
=
editor
.
selection
.
getRange
().
getClosedNode
(),
url
;
var
hasFakedClass
=
(
img
.
className
==
"edui-faked-video"
),
if
(
img
&&
img
.
className
)
{
hasUploadClass
=
img
.
className
.
indexOf
(
"edui-upload-video"
)
!=-
1
;
var
hasFakedClass
=
(
img
.
className
==
"edui-faked-video"
),
if
(
hasFakedClass
||
hasUploadClass
)
{
hasUploadClass
=
img
.
className
.
indexOf
(
"edui-upload-video"
)
!=
-
1
;
$G
(
"videoUrl"
).
value
=
url
=
img
.
getAttribute
(
"_url"
);
if
(
hasFakedClass
||
hasUploadClass
)
{
$G
(
"videoWidth"
).
value
=
img
.
width
;
$G
(
"videoUrl"
).
value
=
url
=
img
.
getAttribute
(
"_url"
);
$G
(
"videoHeight"
).
value
=
img
.
height
;
$G
(
"videoWidth"
).
value
=
img
.
width
;
var
align
=
domUtils
.
getComputedStyle
(
img
,
"float"
),
$G
(
"videoHeight"
).
value
=
img
.
height
;
parentAlign
=
domUtils
.
getComputedStyle
(
img
.
parentNode
,
"text-align"
);
var
align
=
domUtils
.
getComputedStyle
(
img
,
"float"
),
updateAlignButton
(
parentAlign
===
"center"
?
"center"
:
align
);
parentAlign
=
domUtils
.
getComputedStyle
(
img
.
parentNode
,
"text-align"
);
}
updateAlignButton
(
parentAlign
===
"center"
?
"center"
:
align
);
if
(
hasUploadClass
)
{
isModifyUploadVideo
=
true
;
}
}
createPreviewVideo
(
url
);
})();
}
/**
* 监听确认和取消两个按钮事件,用户执行插入或者清空正在播放的视频实例操作
*/
function
addOkListener
(){
dialog
.
onok
=
function
(){
$G
(
"preview"
).
innerHTML
=
""
;
var
currentTab
=
findFocus
(
"tabHeads"
,
"tabSrc"
);
switch
(
currentTab
){
case
"video"
:
return
insertSingle
();
break
;
case
"videoSearch"
:
return
insertSearch
(
"searchList"
);
break
;
case
"upload"
:
return
insertUpload
();
break
;
}
};
dialog
.
oncancel
=
function
(){
$G
(
"preview"
).
innerHTML
=
""
;
};
}
/**
* 依据传入的align值更新按钮信息
* @param align
*/
function
updateAlignButton
(
align
)
{
var
aligns
=
$G
(
"videoFloat"
).
children
;
for
(
var
i
=
0
,
ci
;
ci
=
aligns
[
i
++
];
)
{
if
(
ci
.
getAttribute
(
"name"
)
==
align
)
{
if
(
ci
.
className
!=
"focus"
)
{
ci
.
className
=
"focus"
;
}
}
else
{
if
(
ci
.
className
==
"focus"
)
{
ci
.
className
=
""
;
}
}
}
}
}
if
(
hasUploadClass
)
{
isModifyUploadVideo
=
true
;
/**
* 将单个视频信息插入编辑器中
*/
function
insertSingle
(){
var
width
=
$G
(
"videoWidth"
),
height
=
$G
(
"videoHeight"
),
url
=
$G
(
'videoUrl'
).
value
,
align
=
findFocus
(
"videoFloat"
,
"name"
);
if
(
!
url
)
return
false
;
if
(
!
checkNum
(
[
width
,
height
]
)
)
return
false
;
editor
.
execCommand
(
'insertvideo'
,
{
url
:
convert_url
(
url
),
width
:
width
.
value
,
height
:
height
.
value
,
align
:
align
},
isModifyUploadVideo
?
'upload'
:
null
);
}
/**
* 将元素id下的所有代表视频的图片插入编辑器中
* @param id
*/
function
insertSearch
(
id
){
var
imgs
=
domUtils
.
getElementsByTagName
(
$G
(
id
),
"img"
),
videoObjs
=
[];
for
(
var
i
=
0
,
img
;
img
=
imgs
[
i
++
];){
if
(
img
.
getAttribute
(
"selected"
)){
videoObjs
.
push
({
url
:
img
.
getAttribute
(
"ue_video_url"
),
width
:
420
,
height
:
280
,
align
:
"none"
});
}
}
}
editor
.
execCommand
(
'insertvideo'
,
videoObjs
);
}
}
createPreviewVideo
(
url
);
})();
/**
}
* 找到id下具有focus类的节点并返回该节点下的某个属性
* @param id
/**
* @param returnProperty
* 监听确认和取消两个按钮事件,用户执行插入或者清空正在播放的视频实例操作
*/
*/
function
findFocus
(
id
,
returnProperty
)
{
function
addOkListener
()
{
var
tabs
=
$G
(
id
).
children
,
dialog
.
onok
=
function
()
{
property
;
$G
(
"preview"
).
innerHTML
=
""
;
for
(
var
i
=
0
,
ci
;
ci
=
tabs
[
i
++
];
)
{
var
currentTab
=
findFocus
(
"tabHeads"
,
"tabSrc"
);
if
(
ci
.
className
==
"focus"
)
{
switch
(
currentTab
)
{
property
=
ci
.
getAttribute
(
returnProperty
);
case
"video"
:
break
;
return
insertSingle
();
}
break
;
case
"videoSearch"
:
return
insertSearch
(
"searchList"
);
break
;
case
"upload"
:
return
insertUpload
();
break
;
}
};
dialog
.
oncancel
=
function
()
{
$G
(
"preview"
).
innerHTML
=
""
;
};
}
/**
* 依据传入的align值更新按钮信息
* @param align
*/
function
updateAlignButton
(
align
)
{
var
aligns
=
$G
(
"videoFloat"
).
children
;
for
(
var
i
=
0
,
ci
;
ci
=
aligns
[
i
++
];)
{
if
(
ci
.
getAttribute
(
"name"
)
==
align
)
{
if
(
ci
.
className
!=
"focus"
)
{
ci
.
className
=
"focus"
;
}
}
return
property
;
}
else
{
if
(
ci
.
className
==
"focus"
)
{
ci
.
className
=
""
;
}
}
}
}
function
convert_url
(
url
){
}
if
(
!
url
)
return
''
;
url
=
utils
.
trim
(
url
)
/**
.
replace
(
/v
\.
youku
\.
com
\/
v_show
\/
id_
([\w\-
=
]
+
)\.
html/i
,
'player.youku.com/player.php/sid/$1/v.swf'
)
* 将单个视频信息插入编辑器中
.
replace
(
/
(
www
\.)?
youtube
\.
com
\/
watch
\?
v=
([\w\-]
+
)
/i
,
"www.youtube.com/v/$2"
)
*/
.
replace
(
/youtu.be
\/(\w
+
)
$/i
,
"www.youtube.com/v/$1"
)
function
insertSingle
()
{
.
replace
(
/v
\.
ku6
\.
com
\/
.+
\/([\w\.]
+
)\.
html.*$/i
,
"player.ku6.com/refer/$1/v.swf"
)
var
width
=
$G
(
"videoWidth"
),
.
replace
(
/www
\.
56
\.
com
\/
u
\d
+
\/
v_
([\w\-]
+
)\.
html/i
,
"player.56.com/v_$1.swf"
)
height
=
$G
(
"videoHeight"
),
.
replace
(
/www.56.com
\/
w
\d
+
\/
play_album
\-
aid
\-\d
+_vid
\-([^
.
]
+
)\.
html/i
,
"player.56.com/v_$1.swf"
)
url
=
$G
(
'videoUrl'
).
value
,
.
replace
(
/v
\.
pps
\.
tv
\/
play_
([\w]
+
)\.
html.*$/i
,
"player.pps.tv/player/sid/$1/v.swf"
)
align
=
findFocus
(
"videoFloat"
,
"name"
);
.
replace
(
/www
\.
letv
\.
com
\/
ptv
\/
vplay
\/([\d]
+
)\.
html.*$/i
,
"i7.imgs.letv.com/player/swfPlayer.swf?id=$1&autoplay=0"
)
if
(
!
url
)
return
false
;
.
replace
(
/www
\.
tudou
\.
com
\/
programs
\/
view
\/([\w\-]
+
)\/?
/i
,
"www.tudou.com/v/$1"
)
if
(
!
checkNum
([
width
,
height
]))
return
false
;
.
replace
(
/v
\.
qq
\.
com
\/
cover
\/[\w]
+
\/[\w]
+
\/([\w]
+
)\.
html/i
,
"static.video.qq.com/TPout.swf?vid=$1"
)
editor
.
execCommand
(
'insertvideo'
,
{
.
replace
(
/v
\.
qq
\.
com
\/
.+
[\?\&]
vid=
([^
&
]
+
)
.*$/i
,
"static.video.qq.com/TPout.swf?vid=$1"
)
url
:
convert_url
(
url
),
.
replace
(
/my
\.
tv
\.
sohu
\.
com
\/[\w]
+
\/[\d]
+
\/([\d]
+
)\.
shtml.*$/i
,
"share.vrs.sohu.com/my/v.swf&id=$1"
);
width
:
width
.
value
,
height
:
height
.
value
,
return
url
;
align
:
align
},
isModifyUploadVideo
?
'upload'
:
null
);
}
/**
* 将元素id下的所有代表视频的图片插入编辑器中
* @param id
*/
function
insertSearch
(
id
)
{
var
imgs
=
domUtils
.
getElementsByTagName
(
$G
(
id
),
"img"
),
videoObjs
=
[];
for
(
var
i
=
0
,
img
;
img
=
imgs
[
i
++
];)
{
if
(
img
.
getAttribute
(
"selected"
))
{
videoObjs
.
push
({
url
:
img
.
getAttribute
(
"ue_video_url"
),
width
:
420
,
height
:
280
,
align
:
"none"
});
}
}
}
editor
.
execCommand
(
'insertvideo'
,
videoObjs
);
/**
}
* 检测传入的所有input框中输入的长宽是否是正数
* @param nodes input框集合,
/**
*/
* 找到id下具有focus类的节点并返回该节点下的某个属性
function
checkNum
(
nodes
)
{
* @param id
for
(
var
i
=
0
,
ci
;
ci
=
nodes
[
i
++
];
)
{
* @param returnProperty
var
value
=
ci
.
value
;
*/
if
(
!
isNumber
(
value
)
&&
value
)
{
function
findFocus
(
id
,
returnProperty
)
{
alert
(
lang
.
numError
);
var
tabs
=
$G
(
id
).
children
,
ci
.
value
=
""
;
property
;
ci
.
focus
();
for
(
var
i
=
0
,
ci
;
ci
=
tabs
[
i
++
];)
{
return
false
;
if
(
ci
.
className
==
"focus"
)
{
}
property
=
ci
.
getAttribute
(
returnProperty
);
}
break
;
return
true
;
}
}
/**
* 数字判断
* @param value
*/
function
isNumber
(
value
)
{
return
/
(
0|^
[
1-9
]\d
*$
)
/
.
test
(
value
);
}
}
return
property
;
/**
}
* 创建图片浮动选择按钮
* @param ids
function
convert_url
(
url
)
{
*/
if
(
!
url
)
return
''
;
function
createAlignButton
(
ids
)
{
url
=
utils
.
trim
(
url
)
for
(
var
i
=
0
,
ci
;
ci
=
ids
[
i
++
];
)
{
.
replace
(
/v
\.
youku
\.
com
\/
v_show
\/
id_
([\w\-
=
]
+
)\.
html/i
,
'player.youku.com/player.php/sid/$1/v.swf'
)
var
floatContainer
=
$G
(
ci
),
.
replace
(
/
(
www
\.)?
youtube
\.
com
\/
watch
\?
v=
([\w\-]
+
)
/i
,
"www.youtube.com/v/$2"
)
nameMaps
=
{
"none"
:
lang
[
'default'
],
"left"
:
lang
.
floatLeft
,
"right"
:
lang
.
floatRight
,
"center"
:
lang
.
block
};
.
replace
(
/youtu.be
\/(\w
+
)
$/i
,
"www.youtube.com/v/$1"
)
for
(
var
j
in
nameMaps
)
{
.
replace
(
/v
\.
ku6
\.
com
\/
.+
\/([\w\.]
+
)\.
html.*$/i
,
"player.ku6.com/refer/$1/v.swf"
)
var
div
=
document
.
createElement
(
"div"
);
.
replace
(
/www
\.
56
\.
com
\/
u
\d
+
\/
v_
([\w\-]
+
)\.
html/i
,
"player.56.com/v_$1.swf"
)
div
.
setAttribute
(
"name"
,
j
);
.
replace
(
/www.56.com
\/
w
\d
+
\/
play_album
\-
aid
\-\d
+_vid
\-([^
.
]
+
)\.
html/i
,
"player.56.com/v_$1.swf"
)
if
(
j
==
"none"
)
div
.
className
=
"focus"
;
.
replace
(
/v
\.
pps
\.
tv
\/
play_
([\w]
+
)\.
html.*$/i
,
"player.pps.tv/player/sid/$1/v.swf"
)
div
.
style
.
cssText
=
"background:url(images/"
+
j
+
"_focus.jpg);"
;
.
replace
(
/www
\.
letv
\.
com
\/
ptv
\/
vplay
\/([\d]
+
)\.
html.*$/i
,
"i7.imgs.letv.com/player/swfPlayer.swf?id=$1&autoplay=0"
)
div
.
setAttribute
(
"title"
,
nameMaps
[
j
]
);
.
replace
(
/www
\.
tudou
\.
com
\/
programs
\/
view
\/([\w\-]
+
)\/?
/i
,
"www.tudou.com/v/$1"
)
floatContainer
.
appendChild
(
div
);
.
replace
(
/v
\.
qq
\.
com
\/
cover
\/[\w]
+
\/[\w]
+
\/([\w]
+
)\.
html/i
,
"static.video.qq.com/TPout.swf?vid=$1"
)
}
.
replace
(
/v
\.
qq
\.
com
\/
.+
[\?\&]
vid=
([^
&
]
+
)
.*$/i
,
"static.video.qq.com/TPout.swf?vid=$1"
)
switchSelect
(
ci
);
.
replace
(
/my
\.
tv
\.
sohu
\.
com
\/[\w]
+
\/[\d]
+
\/([\d]
+
)\.
shtml.*$/i
,
"share.vrs.sohu.com/my/v.swf&id=$1"
);
}
}
return
url
;
}
/**
* 选择切换
/**
* @param selectParentId
* 检测传入的所有input框中输入的长宽是否是正数
*/
* @param nodes input框集合,
function
switchSelect
(
selectParentId
)
{
*/
var
selects
=
$G
(
selectParentId
).
children
;
function
checkNum
(
nodes
)
{
for
(
var
i
=
0
,
ci
;
ci
=
selects
[
i
++
];
)
{
for
(
var
i
=
0
,
ci
;
ci
=
nodes
[
i
++
];)
{
domUtils
.
on
(
ci
,
"click"
,
function
()
{
var
value
=
ci
.
value
;
for
(
var
j
=
0
,
cj
;
cj
=
selects
[
j
++
];
)
{
if
(
!
isNumber
(
value
)
&&
value
)
{
cj
.
className
=
""
;
alert
(
lang
.
numError
);
cj
.
removeAttribute
&&
cj
.
removeAttribute
(
"class"
);
ci
.
value
=
""
;
}
ci
.
focus
();
this
.
className
=
"focus"
;
return
false
;
}
)
}
}
}
}
return
true
;
/**
}
* 监听url改变事件
* @param url
/**
*/
* 数字判断
function
addUrlChangeListener
(
url
){
* @param value
if
(
browser
.
ie
)
{
*/
url
.
onpropertychange
=
function
()
{
function
isNumber
(
value
)
{
createPreviewVideo
(
this
.
value
);
return
/
(
0|^
[
1-9
]\d
*$
)
/
.
test
(
value
);
}
}
}
else
{
url
.
addEventListener
(
"input"
,
function
()
{
/**
createPreviewVideo
(
this
.
value
);
* 创建图片浮动选择按钮
},
false
);
* @param ids
}
*/
function
createAlignButton
(
ids
)
{
for
(
var
i
=
0
,
ci
;
ci
=
ids
[
i
++
];)
{
var
floatContainer
=
$G
(
ci
),
nameMaps
=
{
"none"
:
lang
[
'default'
],
"left"
:
lang
.
floatLeft
,
"right"
:
lang
.
floatRight
,
"center"
:
lang
.
block
};
for
(
var
j
in
nameMaps
)
{
var
div
=
document
.
createElement
(
"div"
);
div
.
setAttribute
(
"name"
,
j
);
if
(
j
==
"none"
)
div
.
className
=
"focus"
;
div
.
style
.
cssText
=
"background:url(images/"
+
j
+
"_focus.jpg);"
;
div
.
setAttribute
(
"title"
,
nameMaps
[
j
]);
floatContainer
.
appendChild
(
div
);
}
switchSelect
(
ci
);
}
}
}
/**
* 根据url生成视频预览
/**
* @param url
* 选择切换
*/
* @param selectParentId
function
createPreviewVideo
(
url
){
*/
if
(
!
url
)
return
;
function
switchSelect
(
selectParentId
)
{
var
selects
=
$G
(
selectParentId
).
children
;
var
conUrl
=
convert_url
(
url
);
for
(
var
i
=
0
,
ci
;
ci
=
selects
[
i
++
];)
{
domUtils
.
on
(
ci
,
"click"
,
function
()
{
conUrl
=
utils
.
unhtmlForUrl
(
conUrl
);
for
(
var
j
=
0
,
cj
;
cj
=
selects
[
j
++
];)
{
cj
.
className
=
""
;
$G
(
"preview"
).
innerHTML
=
'<div class="previewMsg"><span>'
+
lang
.
urlError
+
'</span></div>'
+
cj
.
removeAttribute
&&
cj
.
removeAttribute
(
"class"
);
'<embed class="previewVideo" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"'
+
' src="'
+
conUrl
+
'"'
+
' width="'
+
420
+
'"'
+
' height="'
+
280
+
'"'
+
' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >'
+
'</embed>'
;
}
/* 插入上传视频 */
function
insertUpload
(){
var
videoObjs
=
[],
uploadDir
=
editor
.
getOpt
(
'videoUrlPrefix'
),
width
=
parseInt
(
$G
(
'upload_width'
).
value
,
10
)
||
420
,
height
=
parseInt
(
$G
(
'upload_height'
).
value
,
10
)
||
280
,
align
=
findFocus
(
"upload_alignment"
,
"name"
)
||
'none'
;
for
(
var
key
in
uploadVideoList
)
{
var
file
=
uploadVideoList
[
key
];
videoObjs
.
push
({
url
:
uploadDir
+
file
.
url
,
width
:
width
,
height
:
height
,
align
:
align
});
}
var
count
=
uploadFile
.
getQueueCount
();
if
(
count
)
{
$
(
'.info'
,
'#queueList'
).
html
(
'<span style="color:red;">'
+
'还有2个未上传文件'
.
replace
(
/
[\d]
/
,
count
)
+
'</span>'
);
return
false
;
}
else
{
editor
.
execCommand
(
'insertvideo'
,
videoObjs
,
'upload'
);
}
}
this
.
className
=
"focus"
;
})
}
}
}
/*初始化上传标签*/
function
initUpload
(){
/**
uploadFile
=
new
UploadFile
(
'queueList'
);
* 监听url改变事件
* @param url
*/
function
addUrlChangeListener
(
url
)
{
if
(
browser
.
ie
)
{
url
.
onpropertychange
=
function
()
{
createPreviewVideo
(
this
.
value
);
}
}
else
{
url
.
addEventListener
(
"input"
,
function
()
{
createPreviewVideo
(
this
.
value
);
},
false
);
}
}
/**
* 根据url生成视频预览
* @param url
*/
function
createPreviewVideo
(
url
)
{
if
(
!
url
)
return
;
var
conUrl
=
convert_url
(
url
);
conUrl
=
utils
.
unhtmlForUrl
(
conUrl
);
$G
(
"preview"
).
innerHTML
=
'<div class="previewMsg"><span>'
+
lang
.
urlError
+
'</span></div>'
+
'<embed class="previewVideo" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"'
+
' src="'
+
conUrl
+
'"'
+
' width="'
+
420
+
'"'
+
' height="'
+
280
+
'"'
+
' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >'
+
'</embed>'
;
}
/* 插入上传视频 */
function
insertUpload
()
{
var
videoObjs
=
[],
uploadDir
=
editor
.
getOpt
(
'videoUrlPrefix'
),
width
=
parseInt
(
$G
(
'upload_width'
).
value
,
10
)
||
420
,
height
=
parseInt
(
$G
(
'upload_height'
).
value
,
10
)
||
280
,
align
=
findFocus
(
"upload_alignment"
,
"name"
)
||
'none'
;
for
(
var
key
in
uploadVideoList
)
{
var
file
=
uploadVideoList
[
key
];
videoObjs
.
push
({
url
:
uploadDir
+
file
.
url
,
width
:
width
,
height
:
height
,
align
:
align
});
}
}
var
count
=
uploadFile
.
getQueueCount
();
/* 上传附件 */
if
(
count
)
{
function
UploadFile
(
target
)
{
$
(
'.info'
,
'#queueList'
).
html
(
'<span style="color:red;">'
+
'还有2个未上传文件'
.
replace
(
/
[\d]
/
,
count
)
+
'</span>'
);
this
.
$wrap
=
target
.
constructor
==
String
?
$
(
'#'
+
target
)
:
$
(
target
);
return
false
;
this
.
init
();
}
else
{
editor
.
execCommand
(
'insertvideo'
,
videoObjs
,
'upload'
);
}
}
UploadFile
.
prototype
=
{
}
init
:
function
()
{
this
.
fileList
=
[];
/*初始化上传标签*/
this
.
initContainer
();
function
initUpload
()
{
this
.
initUploader
();
uploadFile
=
new
UploadFile
(
'queueList'
);
},
}
initContainer
:
function
()
{
this
.
$queue
=
this
.
$wrap
.
find
(
'.filelist'
);
/* 上传附件 */
function
UploadFile
(
target
)
{
this
.
$wrap
=
target
.
constructor
==
String
?
$
(
'#'
+
target
)
:
$
(
target
);
this
.
init
();
}
UploadFile
.
prototype
=
{
init
:
function
()
{
this
.
fileList
=
[];
this
.
initContainer
();
this
.
initUploader
();
},
initContainer
:
function
()
{
this
.
$queue
=
this
.
$wrap
.
find
(
'.filelist'
);
},
/* 初始化容器 */
initUploader
:
function
()
{
var
_this
=
this
,
$
=
jQuery
,
// just in case. Make sure it's not an other libaray.
$wrap
=
_this
.
$wrap
,
// 图片容器
$queue
=
$wrap
.
find
(
'.filelist'
),
// 状态栏,包括进度和控制按钮
$statusBar
=
$wrap
.
find
(
'.statusBar'
),
// 文件总体选择信息。
$info
=
$statusBar
.
find
(
'.info'
),
// 上传按钮
$upload
=
$wrap
.
find
(
'.uploadBtn'
),
// 上传按钮
$filePickerBtn
=
$wrap
.
find
(
'.filePickerBtn'
),
// 上传按钮
$filePickerBlock
=
$wrap
.
find
(
'.filePickerBlock'
),
// 没选择文件之前的内容。
$placeHolder
=
$wrap
.
find
(
'.placeholder'
),
// 总体进度条
$progress
=
$statusBar
.
find
(
'.progress'
).
hide
(),
// 添加的文件数量
fileCount
=
0
,
// 添加的文件总大小
fileSize
=
0
,
// 优化retina, 在retina下这个值是2
ratio
=
window
.
devicePixelRatio
||
1
,
// 缩略图大小
thumbnailWidth
=
113
*
ratio
,
thumbnailHeight
=
113
*
ratio
,
// 可能有pedding, ready, uploading, confirm, done.
state
=
''
,
// 所有文件的进度信息,key为file id
percentages
=
{},
supportTransition
=
(
function
()
{
var
s
=
document
.
createElement
(
'p'
).
style
,
r
=
'transition'
in
s
||
'WebkitTransition'
in
s
||
'MozTransition'
in
s
||
'msTransition'
in
s
||
'OTransition'
in
s
;
s
=
null
;
return
r
;
})(),
// WebUploader实例
uploader
,
actionUrl
=
'/'
+
editor
.
getActionUrl
(
editor
.
getOpt
(
'videoActionName'
)),
fileMaxSize
=
editor
.
getOpt
(
'videoMaxSize'
),
acceptExtensions
=
(
editor
.
getOpt
(
'videoAllowFiles'
)
||
[]).
join
(
''
).
replace
(
/
\.
/g
,
','
).
replace
(
/^
[
,
]
/
,
''
);
;
if
(
!
WebUploader
.
Uploader
.
support
())
{
$
(
'#filePickerReady'
).
after
(
$
(
'<div>'
).
html
(
lang
.
errorNotSupport
)).
hide
();
return
;
}
else
if
(
!
editor
.
getOpt
(
'videoActionName'
))
{
$
(
'#filePickerReady'
).
after
(
$
(
'<div>'
).
html
(
lang
.
errorLoadConfig
)).
hide
();
return
;
}
uploader
=
_this
.
uploader
=
WebUploader
.
create
({
pick
:
{
id
:
'#filePickerReady'
,
label
:
lang
.
uploadSelectFile
},
},
/* 初始化容器 */
swf
:
'../../third-party/webuploader/Uploader.swf'
,
initUploader
:
function
()
{
server
:
actionUrl
,
var
_this
=
this
,
fileVal
:
editor
.
getOpt
(
'videoFieldName'
),
$
=
jQuery
,
// just in case. Make sure it's not an other libaray.
duplicate
:
true
,
$wrap
=
_this
.
$wrap
,
fileSingleSizeLimit
:
fileMaxSize
,
// 图片容器
compress
:
false
$queue
=
$wrap
.
find
(
'.filelist'
),
});
// 状态栏,包括进度和控制按钮
uploader
.
addButton
({
$statusBar
=
$wrap
.
find
(
'.statusBar'
),
id
:
'#filePickerBlock'
// 文件总体选择信息。
});
$info
=
$statusBar
.
find
(
'.info'
),
uploader
.
addButton
({
// 上传按钮
id
:
'#filePickerBtn'
,
$upload
=
$wrap
.
find
(
'.uploadBtn'
),
label
:
lang
.
uploadAddFile
// 上传按钮
});
$filePickerBtn
=
$wrap
.
find
(
'.filePickerBtn'
),
// 上传按钮
setState
(
'pedding'
);
$filePickerBlock
=
$wrap
.
find
(
'.filePickerBlock'
),
// 没选择文件之前的内容。
// 当有文件添加进来时执行,负责view的创建
$placeHolder
=
$wrap
.
find
(
'.placeholder'
),
function
addFile
(
file
)
{
// 总体进度条
var
$li
=
$
(
'<li id="'
+
file
.
id
+
'">'
+
$progress
=
$statusBar
.
find
(
'.progress'
).
hide
(),
'<p class="title">'
+
file
.
name
+
'</p>'
+
// 添加的文件数量
'<p class="imgWrap"></p>'
+
fileCount
=
0
,
'<p class="progress"><span></span></p>'
+
// 添加的文件总大小
'</li>'
),
fileSize
=
0
,
// 优化retina, 在retina下这个值是2
$btns
=
$
(
'<div class="file-panel">'
+
ratio
=
window
.
devicePixelRatio
||
1
,
'<span class="cancel">'
+
lang
.
uploadDelete
+
'</span>'
+
// 缩略图大小
'<span class="rotateRight">'
+
lang
.
uploadTurnRight
+
'</span>'
+
thumbnailWidth
=
113
*
ratio
,
'<span class="rotateLeft">'
+
lang
.
uploadTurnLeft
+
'</span></div>'
).
appendTo
(
$li
),
thumbnailHeight
=
113
*
ratio
,
$prgress
=
$li
.
find
(
'p.progress span'
),
// 可能有pedding, ready, uploading, confirm, done.
$wrap
=
$li
.
find
(
'p.imgWrap'
),
state
=
''
,
$info
=
$
(
'<p class="error"></p>'
).
hide
().
appendTo
(
$li
),
// 所有文件的进度信息,key为file id
percentages
=
{},
showError
=
function
(
code
)
{
supportTransition
=
(
function
()
{
switch
(
code
)
{
var
s
=
document
.
createElement
(
'p'
).
style
,
case
'exceed_size'
:
r
=
'transition'
in
s
||
text
=
lang
.
errorExceedSize
;
'WebkitTransition'
in
s
||
break
;
'MozTransition'
in
s
||
case
'interrupt'
:
'msTransition'
in
s
||
text
=
lang
.
errorInterrupt
;
'OTransition'
in
s
;
break
;
s
=
null
;
case
'http'
:
return
r
;
text
=
lang
.
errorHttp
;
})(),
break
;
// WebUploader实例
case
'not_allow_type'
:
uploader
,
text
=
lang
.
errorFileType
;
actionUrl
=
editor
.
getActionUrl
(
editor
.
getOpt
(
'videoActionName'
)),
break
;
fileMaxSize
=
editor
.
getOpt
(
'videoMaxSize'
),
default
:
acceptExtensions
=
(
editor
.
getOpt
(
'videoAllowFiles'
)
||
[]).
join
(
''
).
replace
(
/
\.
/g
,
','
).
replace
(
/^
[
,
]
/
,
''
);;
text
=
lang
.
errorUploadRetry
;
break
;
if
(
!
WebUploader
.
Uploader
.
support
())
{
$
(
'#filePickerReady'
).
after
(
$
(
'<div>'
).
html
(
lang
.
errorNotSupport
)).
hide
();
return
;
}
else
if
(
!
editor
.
getOpt
(
'videoActionName'
))
{
$
(
'#filePickerReady'
).
after
(
$
(
'<div>'
).
html
(
lang
.
errorLoadConfig
)).
hide
();
return
;
}
uploader
=
_this
.
uploader
=
WebUploader
.
create
({
pick
:
{
id
:
'#filePickerReady'
,
label
:
lang
.
uploadSelectFile
},
swf
:
'../../third-party/webuploader/Uploader.swf'
,
server
:
actionUrl
,
fileVal
:
editor
.
getOpt
(
'videoFieldName'
),
duplicate
:
true
,
fileSingleSizeLimit
:
fileMaxSize
,
compress
:
false
});
uploader
.
addButton
({
id
:
'#filePickerBlock'
});
uploader
.
addButton
({
id
:
'#filePickerBtn'
,
label
:
lang
.
uploadAddFile
});
setState
(
'pedding'
);
// 当有文件添加进来时执行,负责view的创建
function
addFile
(
file
)
{
var
$li
=
$
(
'<li id="'
+
file
.
id
+
'">'
+
'<p class="title">'
+
file
.
name
+
'</p>'
+
'<p class="imgWrap"></p>'
+
'<p class="progress"><span></span></p>'
+
'</li>'
),
$btns
=
$
(
'<div class="file-panel">'
+
'<span class="cancel">'
+
lang
.
uploadDelete
+
'</span>'
+
'<span class="rotateRight">'
+
lang
.
uploadTurnRight
+
'</span>'
+
'<span class="rotateLeft">'
+
lang
.
uploadTurnLeft
+
'</span></div>'
).
appendTo
(
$li
),
$prgress
=
$li
.
find
(
'p.progress span'
),
$wrap
=
$li
.
find
(
'p.imgWrap'
),
$info
=
$
(
'<p class="error"></p>'
).
hide
().
appendTo
(
$li
),
showError
=
function
(
code
)
{
switch
(
code
)
{
case
'exceed_size'
:
text
=
lang
.
errorExceedSize
;
break
;
case
'interrupt'
:
text
=
lang
.
errorInterrupt
;
break
;
case
'http'
:
text
=
lang
.
errorHttp
;
break
;
case
'not_allow_type'
:
text
=
lang
.
errorFileType
;
break
;
default
:
text
=
lang
.
errorUploadRetry
;
break
;
}
$info
.
text
(
text
).
show
();
};
if
(
file
.
getStatus
()
===
'invalid'
)
{
showError
(
file
.
statusText
);
}
else
{
$wrap
.
text
(
lang
.
uploadPreview
);
if
(
'|png|jpg|jpeg|bmp|gif|'
.
indexOf
(
'|'
+
file
.
ext
.
toLowerCase
()
+
'|'
)
==
-
1
)
{
$wrap
.
empty
().
addClass
(
'notimage'
).
append
(
'<i class="file-preview file-type-'
+
file
.
ext
.
toLowerCase
()
+
'"></i>'
+
'<span class="file-title">'
+
file
.
name
+
'</span>'
);
}
else
{
if
(
browser
.
ie
&&
browser
.
version
<=
7
)
{
$wrap
.
text
(
lang
.
uploadNoPreview
);
}
else
{
uploader
.
makeThumb
(
file
,
function
(
error
,
src
)
{
if
(
error
||
!
src
||
(
/^data:/
.
test
(
src
)
&&
browser
.
ie
&&
browser
.
version
<=
7
))
{
$wrap
.
text
(
lang
.
uploadNoPreview
);
}
else
{
var
$img
=
$
(
'<img src="'
+
src
+
'">'
);
$wrap
.
empty
().
append
(
$img
);
$img
.
on
(
'error'
,
function
()
{
$wrap
.
text
(
lang
.
uploadNoPreview
);
});
}
},
thumbnailWidth
,
thumbnailHeight
);
}
}
percentages
[
file
.
id
]
=
[
file
.
size
,
0
];
file
.
rotation
=
0
;
/* 检查文件格式 */
if
(
!
file
.
ext
||
acceptExtensions
.
indexOf
(
file
.
ext
.
toLowerCase
())
==
-
1
)
{
showError
(
'not_allow_type'
);
uploader
.
removeFile
(
file
);
}
}
file
.
on
(
'statuschange'
,
function
(
cur
,
prev
)
{
if
(
prev
===
'progress'
)
{
$prgress
.
hide
().
width
(
0
);
}
else
if
(
prev
===
'queued'
)
{
$li
.
off
(
'mouseenter mouseleave'
);
$btns
.
remove
();
}
// 成功
if
(
cur
===
'error'
||
cur
===
'invalid'
)
{
showError
(
file
.
statusText
);
percentages
[
file
.
id
][
1
]
=
1
;
}
else
if
(
cur
===
'interrupt'
)
{
showError
(
'interrupt'
);
}
else
if
(
cur
===
'queued'
)
{
percentages
[
file
.
id
][
1
]
=
0
;
}
else
if
(
cur
===
'progress'
)
{
$info
.
hide
();
$prgress
.
css
(
'display'
,
'block'
);
}
else
if
(
cur
===
'complete'
)
{
}
$li
.
removeClass
(
'state-'
+
prev
).
addClass
(
'state-'
+
cur
);
});
$li
.
on
(
'mouseenter'
,
function
()
{
$btns
.
stop
().
animate
({
height
:
30
});
});
$li
.
on
(
'mouseleave'
,
function
()
{
$btns
.
stop
().
animate
({
height
:
0
});
});
$btns
.
on
(
'click'
,
'span'
,
function
()
{
var
index
=
$
(
this
).
index
(),
deg
;
switch
(
index
)
{
case
0
:
uploader
.
removeFile
(
file
);
return
;
case
1
:
file
.
rotation
+=
90
;
break
;
case
2
:
file
.
rotation
-=
90
;
break
;
}
if
(
supportTransition
)
{
deg
=
'rotate('
+
file
.
rotation
+
'deg)'
;
$wrap
.
css
({
'-webkit-transform'
:
deg
,
'-mos-transform'
:
deg
,
'-o-transform'
:
deg
,
'transform'
:
deg
});
}
else
{
$wrap
.
css
(
'filter'
,
'progid:DXImageTransform.Microsoft.BasicImage(rotation='
+
(
~~
((
file
.
rotation
/
90
)
%
4
+
4
)
%
4
)
+
')'
);
}
});
$li
.
insertBefore
(
$filePickerBlock
);
}
// 负责view的销毁
function
removeFile
(
file
)
{
var
$li
=
$
(
'#'
+
file
.
id
);
delete
percentages
[
file
.
id
];
updateTotalProgress
();
$li
.
off
().
find
(
'.file-panel'
).
off
().
end
().
remove
();
}
function
updateTotalProgress
()
{
var
loaded
=
0
,
total
=
0
,
spans
=
$progress
.
children
(),
percent
;
$
.
each
(
percentages
,
function
(
k
,
v
)
{
total
+=
v
[
0
];
loaded
+=
v
[
0
]
*
v
[
1
];
});
percent
=
total
?
loaded
/
total
:
0
;
spans
.
eq
(
0
).
text
(
Math
.
round
(
percent
*
100
)
+
'%'
);
spans
.
eq
(
1
).
css
(
'width'
,
Math
.
round
(
percent
*
100
)
+
'%'
);
updateStatus
();
}
}
$info
.
text
(
text
).
show
();
};
function
setState
(
val
,
files
)
{
if
(
file
.
getStatus
()
===
'invalid'
)
{
showError
(
file
.
statusText
);
if
(
val
!=
state
)
{
}
else
{
$wrap
.
text
(
lang
.
uploadPreview
);
var
stats
=
uploader
.
getStats
();
if
(
'|png|jpg|jpeg|bmp|gif|'
.
indexOf
(
'|'
+
file
.
ext
.
toLowerCase
()
+
'|'
)
==
-
1
)
{
$wrap
.
empty
().
addClass
(
'notimage'
).
append
(
'<i class="file-preview file-type-'
+
file
.
ext
.
toLowerCase
()
+
'"></i>'
+
$upload
.
removeClass
(
'state-'
+
state
);
'<span class="file-title">'
+
file
.
name
+
'</span>'
);
$upload
.
addClass
(
'state-'
+
val
);
}
else
{
if
(
browser
.
ie
&&
browser
.
version
<=
7
)
{
switch
(
val
)
{
$wrap
.
text
(
lang
.
uploadNoPreview
);
}
else
{
/* 未选择文件 */
uploader
.
makeThumb
(
file
,
function
(
error
,
src
)
{
case
'pedding'
:
if
(
error
||
!
src
||
(
/^data:/
.
test
(
src
)
&&
browser
.
ie
&&
browser
.
version
<=
7
))
{
$queue
.
addClass
(
'element-invisible'
);
$wrap
.
text
(
lang
.
uploadNoPreview
);
$statusBar
.
addClass
(
'element-invisible'
);
$placeHolder
.
removeClass
(
'element-invisible'
);
$progress
.
hide
();
$info
.
hide
();
uploader
.
refresh
();
break
;
/* 可以开始上传 */
case
'ready'
:
$placeHolder
.
addClass
(
'element-invisible'
);
$queue
.
removeClass
(
'element-invisible'
);
$statusBar
.
removeClass
(
'element-invisible'
);
$progress
.
hide
();
$info
.
show
();
$upload
.
text
(
lang
.
uploadStart
);
uploader
.
refresh
();
break
;
/* 上传中 */
case
'uploading'
:
$progress
.
show
();
$info
.
hide
();
$upload
.
text
(
lang
.
uploadPause
);
break
;
/* 暂停上传 */
case
'paused'
:
$progress
.
show
();
$info
.
hide
();
$upload
.
text
(
lang
.
uploadContinue
);
break
;
case
'confirm'
:
$progress
.
show
();
$info
.
hide
();
$upload
.
text
(
lang
.
uploadStart
);
stats
=
uploader
.
getStats
();
if
(
stats
.
successNum
&&
!
stats
.
uploadFailNum
)
{
setState
(
'finish'
);
return
;
}
break
;
case
'finish'
:
$progress
.
hide
();
$info
.
show
();
if
(
stats
.
uploadFailNum
)
{
$upload
.
text
(
lang
.
uploadRetry
);
}
else
{
$upload
.
text
(
lang
.
uploadStart
);
}
break
;
}
state
=
val
;
updateStatus
();
}
if
(
!
_this
.
getQueueCount
())
{
$upload
.
addClass
(
'disabled'
)
}
else
{
}
else
{
$upload
.
removeClass
(
'disabled'
)
var
$img
=
$
(
'<img src="'
+
src
+
'">'
);
$wrap
.
empty
().
append
(
$img
);
$img
.
on
(
'error'
,
function
()
{
$wrap
.
text
(
lang
.
uploadNoPreview
);
});
}
}
},
thumbnailWidth
,
thumbnailHeight
);
}
}
}
percentages
[
file
.
id
]
=
[
file
.
size
,
0
];
file
.
rotation
=
0
;
/* 检查文件格式 */
if
(
!
file
.
ext
||
acceptExtensions
.
indexOf
(
file
.
ext
.
toLowerCase
())
==
-
1
)
{
showError
(
'not_allow_type'
);
uploader
.
removeFile
(
file
);
}
}
function
updateStatus
()
{
file
.
on
(
'statuschange'
,
function
(
cur
,
prev
)
{
var
text
=
''
,
stats
;
if
(
prev
===
'progress'
)
{
$prgress
.
hide
().
width
(
0
);
if
(
state
===
'ready'
)
{
}
else
if
(
prev
===
'queued'
)
{
text
=
lang
.
updateStatusReady
.
replace
(
'_'
,
fileCount
).
replace
(
'_KB'
,
WebUploader
.
formatSize
(
fileSize
));
$li
.
off
(
'mouseenter mouseleave'
);
}
else
if
(
state
===
'confirm'
)
{
$btns
.
remove
();
stats
=
uploader
.
getStats
();
}
if
(
stats
.
uploadFailNum
)
{
// 成功
text
=
lang
.
updateStatusConfirm
.
replace
(
'_'
,
stats
.
successNum
).
replace
(
'_'
,
stats
.
successNum
);
if
(
cur
===
'error'
||
cur
===
'invalid'
)
{
}
showError
(
file
.
statusText
);
}
else
{
percentages
[
file
.
id
][
1
]
=
1
;
stats
=
uploader
.
getStats
();
}
else
if
(
cur
===
'interrupt'
)
{
text
=
lang
.
updateStatusFinish
.
replace
(
'_'
,
fileCount
).
showError
(
'interrupt'
);
replace
(
'_KB'
,
WebUploader
.
formatSize
(
fileSize
)).
}
else
if
(
cur
===
'queued'
)
{
replace
(
'_'
,
stats
.
successNum
);
percentages
[
file
.
id
][
1
]
=
0
;
}
else
if
(
cur
===
'progress'
)
{
if
(
stats
.
uploadFailNum
)
{
$info
.
hide
();
text
+=
lang
.
updateStatusError
.
replace
(
'_'
,
stats
.
uploadFailNum
);
$prgress
.
css
(
'display'
,
'block'
);
}
}
else
if
(
cur
===
'complete'
)
{
}
}
$li
.
removeClass
(
'state-'
+
prev
).
addClass
(
'state-'
+
cur
);
});
$li
.
on
(
'mouseenter'
,
function
()
{
$btns
.
stop
().
animate
({
height
:
30
});
});
$li
.
on
(
'mouseleave'
,
function
()
{
$btns
.
stop
().
animate
({
height
:
0
});
});
$btns
.
on
(
'click'
,
'span'
,
function
()
{
var
index
=
$
(
this
).
index
(),
deg
;
switch
(
index
)
{
case
0
:
uploader
.
removeFile
(
file
);
return
;
case
1
:
file
.
rotation
+=
90
;
break
;
case
2
:
file
.
rotation
-=
90
;
break
;
}
if
(
supportTransition
)
{
deg
=
'rotate('
+
file
.
rotation
+
'deg)'
;
$wrap
.
css
({
'-webkit-transform'
:
deg
,
'-mos-transform'
:
deg
,
'-o-transform'
:
deg
,
'transform'
:
deg
});
}
else
{
$wrap
.
css
(
'filter'
,
'progid:DXImageTransform.Microsoft.BasicImage(rotation='
+
(
~~
((
file
.
rotation
/
90
)
%
4
+
4
)
%
4
)
+
')'
);
}
});
$li
.
insertBefore
(
$filePickerBlock
);
}
// 负责view的销毁
function
removeFile
(
file
)
{
var
$li
=
$
(
'#'
+
file
.
id
);
delete
percentages
[
file
.
id
];
updateTotalProgress
();
$li
.
off
().
find
(
'.file-panel'
).
off
().
end
().
remove
();
}
function
updateTotalProgress
()
{
var
loaded
=
0
,
total
=
0
,
spans
=
$progress
.
children
(),
percent
;
$
.
each
(
percentages
,
function
(
k
,
v
)
{
total
+=
v
[
0
];
loaded
+=
v
[
0
]
*
v
[
1
];
});
percent
=
total
?
loaded
/
total
:
0
;
spans
.
eq
(
0
).
text
(
Math
.
round
(
percent
*
100
)
+
'%'
);
spans
.
eq
(
1
).
css
(
'width'
,
Math
.
round
(
percent
*
100
)
+
'%'
);
updateStatus
();
}
function
setState
(
val
,
files
)
{
if
(
val
!=
state
)
{
var
stats
=
uploader
.
getStats
();
$upload
.
removeClass
(
'state-'
+
state
);
$upload
.
addClass
(
'state-'
+
val
);
switch
(
val
)
{
/* 未选择文件 */
case
'pedding'
:
$queue
.
addClass
(
'element-invisible'
);
$statusBar
.
addClass
(
'element-invisible'
);
$placeHolder
.
removeClass
(
'element-invisible'
);
$progress
.
hide
();
$info
.
hide
();
uploader
.
refresh
();
break
;
/* 可以开始上传 */
case
'ready'
:
$placeHolder
.
addClass
(
'element-invisible'
);
$queue
.
removeClass
(
'element-invisible'
);
$statusBar
.
removeClass
(
'element-invisible'
);
$progress
.
hide
();
$info
.
show
();
$upload
.
text
(
lang
.
uploadStart
);
uploader
.
refresh
();
break
;
/* 上传中 */
case
'uploading'
:
$progress
.
show
();
$info
.
hide
();
$upload
.
text
(
lang
.
uploadPause
);
break
;
/* 暂停上传 */
case
'paused'
:
$progress
.
show
();
$info
.
hide
();
$upload
.
text
(
lang
.
uploadContinue
);
break
;
case
'confirm'
:
$progress
.
show
();
$info
.
hide
();
$upload
.
text
(
lang
.
uploadStart
);
stats
=
uploader
.
getStats
();
if
(
stats
.
successNum
&&
!
stats
.
uploadFailNum
)
{
setState
(
'finish'
);
return
;
}
break
;
case
'finish'
:
$progress
.
hide
();
$info
.
show
();
if
(
stats
.
uploadFailNum
)
{
$upload
.
text
(
lang
.
uploadRetry
);
}
else
{
$upload
.
text
(
lang
.
uploadStart
);
}
break
;
}
state
=
val
;
updateStatus
();
$info
.
html
(
text
);
}
}
uploader
.
on
(
'fileQueued'
,
function
(
file
)
{
if
(
!
_this
.
getQueueCount
())
{
fileCount
++
;
$upload
.
addClass
(
'disabled'
)
fileSize
+=
file
.
size
;
}
else
{
$upload
.
removeClass
(
'disabled'
)
}
if
(
fileCount
===
1
)
{
}
$placeHolder
.
addClass
(
'element-invisible'
);
$statusBar
.
show
();
}
addFile
(
file
);
function
updateStatus
()
{
})
;
var
text
=
''
,
stats
;
uploader
.
on
(
'fileDequeued'
,
function
(
file
)
{
if
(
state
===
'ready'
)
{
fileCount
--
;
text
=
lang
.
updateStatusReady
.
replace
(
'_'
,
fileCount
).
replace
(
'_KB'
,
WebUploader
.
formatSize
(
fileSize
));
fileSize
-=
file
.
size
;
}
else
if
(
state
===
'confirm'
)
{
stats
=
uploader
.
getStats
();
if
(
stats
.
uploadFailNum
)
{
text
=
lang
.
updateStatusConfirm
.
replace
(
'_'
,
stats
.
successNum
).
replace
(
'_'
,
stats
.
successNum
);
}
}
else
{
stats
=
uploader
.
getStats
();
text
=
lang
.
updateStatusFinish
.
replace
(
'_'
,
fileCount
).
replace
(
'_KB'
,
WebUploader
.
formatSize
(
fileSize
)).
replace
(
'_'
,
stats
.
successNum
);
removeFile
(
file
);
if
(
stats
.
uploadFailNum
)
{
updateTotalProgress
();
text
+=
lang
.
updateStatusError
.
replace
(
'_'
,
stats
.
uploadFailNum
);
});
}
}
uploader
.
on
(
'filesQueued'
,
function
(
file
)
{
$info
.
html
(
text
);
if
(
!
uploader
.
isInProgress
()
&&
(
state
==
'pedding'
||
state
==
'finish'
||
state
==
'confirm'
||
state
==
'ready'
))
{
}
setState
(
'ready'
);
}
updateTotalProgress
();
});
uploader
.
on
(
'all'
,
function
(
type
,
files
)
{
uploader
.
on
(
'fileQueued'
,
function
(
file
)
{
switch
(
type
)
{
fileCount
++
;
case
'uploadFinished'
:
fileSize
+=
file
.
size
;
setState
(
'confirm'
,
files
);
break
;
case
'startUpload'
:
/* 添加额外的GET参数 */
var
params
=
utils
.
serializeParam
(
editor
.
queryCommandValue
(
'serverparam'
))
||
''
,
url
=
utils
.
formatUrl
(
actionUrl
+
(
actionUrl
.
indexOf
(
'?'
)
==
-
1
?
'?'
:
'&'
)
+
'encode=utf-8&'
+
params
);
uploader
.
option
(
'server'
,
url
);
setState
(
'uploading'
,
files
);
break
;
case
'stopUpload'
:
setState
(
'paused'
,
files
);
break
;
}
});
uploader
.
on
(
'uploadBeforeSend'
,
function
(
file
,
data
,
header
)
{
if
(
fileCount
===
1
)
{
//这里可以通过data对象添加POST参数
$placeHolder
.
addClass
(
'element-invisible'
);
header
[
'X_Requested_With'
]
=
'XMLHttpRequest'
;
$statusBar
.
show
()
;
});
}
uploader
.
on
(
'uploadProgress'
,
function
(
file
,
percentage
)
{
addFile
(
file
);
var
$li
=
$
(
'#'
+
file
.
id
),
});
$percent
=
$li
.
find
(
'.progress span'
);
$percent
.
css
(
'width'
,
percentage
*
100
+
'%'
);
uploader
.
on
(
'fileDequeued'
,
function
(
file
)
{
percentages
[
file
.
id
][
1
]
=
percentage
;
fileCount
--
;
updateTotalProgress
();
fileSize
-=
file
.
size
;
});
uploader
.
on
(
'uploadSuccess'
,
function
(
file
,
ret
)
{
removeFile
(
file
);
var
$file
=
$
(
'#'
+
file
.
id
);
updateTotalProgress
();
try
{
});
var
responseText
=
(
ret
.
_raw
||
ret
),
json
=
utils
.
str2json
(
responseText
);
if
(
json
.
state
==
'SUCCESS'
)
{
uploadVideoList
.
push
({
'url'
:
json
.
url
,
'type'
:
json
.
type
,
'original'
:
json
.
original
});
$file
.
append
(
'<span class="success"></span>'
);
}
else
{
$file
.
find
(
'.error'
).
text
(
json
.
state
).
show
();
}
}
catch
(
e
)
{
$file
.
find
(
'.error'
).
text
(
lang
.
errorServerUpload
).
show
();
}
});
uploader
.
on
(
'uploadError'
,
function
(
file
,
code
)
{
uploader
.
on
(
'filesQueued'
,
function
(
file
)
{
});
if
(
!
uploader
.
isInProgress
()
&&
(
state
==
'pedding'
||
state
==
'finish'
||
state
==
'confirm'
||
state
==
'ready'
))
{
uploader
.
on
(
'error'
,
function
(
code
,
file
)
{
setState
(
'ready'
);
if
(
code
==
'Q_TYPE_DENIED'
||
code
==
'F_EXCEED_SIZE'
)
{
}
addFile
(
file
);
updateTotalProgress
();
}
});
});
uploader
.
on
(
'uploadComplete'
,
function
(
file
,
ret
)
{
uploader
.
on
(
'all'
,
function
(
type
,
files
)
{
switch
(
type
)
{
case
'uploadFinished'
:
setState
(
'confirm'
,
files
);
break
;
case
'startUpload'
:
/* 添加额外的GET参数 */
var
params
=
utils
.
serializeParam
(
editor
.
queryCommandValue
(
'serverparam'
))
||
''
,
url
=
utils
.
formatUrl
(
actionUrl
+
(
actionUrl
.
indexOf
(
'?'
)
==
-
1
?
'?'
:
'&'
)
+
'encode=utf-8&'
+
params
);
uploader
.
option
(
'server'
,
url
);
setState
(
'uploading'
,
files
);
break
;
case
'stopUpload'
:
setState
(
'paused'
,
files
);
break
;
}
});
uploader
.
on
(
'uploadBeforeSend'
,
function
(
file
,
data
,
header
)
{
//这里可以通过data对象添加POST参数
header
[
'X_Requested_With'
]
=
'XMLHttpRequest'
;
});
uploader
.
on
(
'uploadProgress'
,
function
(
file
,
percentage
)
{
var
$li
=
$
(
'#'
+
file
.
id
),
$percent
=
$li
.
find
(
'.progress span'
);
$percent
.
css
(
'width'
,
percentage
*
100
+
'%'
);
percentages
[
file
.
id
][
1
]
=
percentage
;
updateTotalProgress
();
});
uploader
.
on
(
'uploadSuccess'
,
function
(
file
,
ret
)
{
var
$file
=
$
(
'#'
+
file
.
id
);
try
{
var
responseText
=
(
ret
.
_raw
||
ret
),
json
=
utils
.
str2json
(
responseText
);
if
(
json
.
state
==
'SUCCESS'
)
{
uploadVideoList
.
push
({
'url'
:
json
.
url
,
'type'
:
json
.
type
,
'original'
:
json
.
original
});
});
$file
.
append
(
'<span class="success"></span>'
);
}
else
{
$file
.
find
(
'.error'
).
text
(
json
.
state
).
show
();
}
}
catch
(
e
)
{
$file
.
find
(
'.error'
).
text
(
lang
.
errorServerUpload
).
show
();
}
});
$upload
.
on
(
'click'
,
function
()
{
uploader
.
on
(
'uploadError'
,
function
(
file
,
code
)
{
if
(
$
(
this
).
hasClass
(
'disabled'
))
{
});
return
false
;
uploader
.
on
(
'error'
,
function
(
code
,
file
)
{
}
if
(
code
==
'Q_TYPE_DENIED'
||
code
==
'F_EXCEED_SIZE'
)
{
addFile
(
file
);
}
});
uploader
.
on
(
'uploadComplete'
,
function
(
file
,
ret
)
{
});
if
(
state
===
'ready'
)
{
$upload
.
on
(
'click'
,
function
()
{
uploader
.
upload
();
if
(
$
(
this
).
hasClass
(
'disabled'
))
{
}
else
if
(
state
===
'paused'
)
{
return
false
;
uploader
.
upload
();
}
}
else
if
(
state
===
'uploading'
)
{
uploader
.
stop
();
}
});
$upload
.
addClass
(
'state-'
+
state
);
if
(
state
===
'ready'
)
{
updateTotalProgress
();
uploader
.
upload
();
},
}
else
if
(
state
===
'paused'
)
{
getQueueCount
:
function
()
{
uploader
.
upload
();
var
file
,
i
,
status
,
readyFile
=
0
,
files
=
this
.
uploader
.
getFiles
();
}
else
if
(
state
===
'uploading'
)
{
for
(
i
=
0
;
file
=
files
[
i
++
];
)
{
uploader
.
stop
();
status
=
file
.
getStatus
();
if
(
status
==
'queued'
||
status
==
'uploading'
||
status
==
'progress'
)
readyFile
++
;
}
return
readyFile
;
},
refresh
:
function
(){
this
.
uploader
.
refresh
();
}
}
};
});
$upload
.
addClass
(
'state-'
+
state
);
updateTotalProgress
();
},
getQueueCount
:
function
()
{
var
file
,
i
,
status
,
readyFile
=
0
,
files
=
this
.
uploader
.
getFiles
();
for
(
i
=
0
;
file
=
files
[
i
++
];)
{
status
=
file
.
getStatus
();
if
(
status
==
'queued'
||
status
==
'uploading'
||
status
==
'progress'
)
readyFile
++
;
}
return
readyFile
;
},
refresh
:
function
()
{
this
.
uploader
.
refresh
();
}
};
})();
})();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment