init();
function init(callback, msg) {
if (msg) {
console.log("INIT:" + msg);
} else
console.log("INIT||||||")
if (document.getElementById("editorgenerator")) {
return
}
/**
*
* @param {String}
* src
* @param {Function}
* callback
*/
function loadScript(src, callback) {
if (src) {
var head = document.getElementsByTagName('body')[0];
var script = document.createElement('script');
script.id = src.substring(src.lastIndexOf("/") + 1, src.length).replace("\.", "_");
if (document.getElementById(script.id)) {
callback();
return;
}
script.type = 'text/javascript';
script.src = src;
script.onload = script.onreadystatechange = function () {
if ((!this.readyState || this.readyState === "loaded" || this.readyState === "complete") && callback) {
callback();
script.onload = script.onreadystatechange = null;
}
};
head.appendChild(script);
}
};
if ((typeof $) + "" == "undefined") {
// 加载ueditor专用的jquery
console.log("不存在JQUERY,动态加载");
loadScript("/wd/js/ueditor/jquery.js", function () {
init(callback, "加载完Jquery");
});
return;
}
if ((typeof UE) + "" == "undefined") {
// 检测ueditor,如果没有
console.log("加载UE");
loadScript("/wd/js/ueditor/ueditor.config.js", function () {
loadScript("/wd/js/ueditor/ueditor.parse.js", function () {
loadScript("/wd/js/ueditor/ueditor.all.js", function () {
init(callback, "加载完UE");
})
});
});
return;
}
if ($(window).on)
$(window).on("load", function () {
lload();
});
else if ($(window).bind) {
$(window).bind("load", function () {
lload();
});
} else if ($(window).live) {
$(window).live("load", function () {
lload();
});
} else {
window.onload = lload();
}
function lload() {
if ($(".ueditorItem").length > 0)
$.each($(".ueditorItem"), function () {
if ($(this).attr("loaded") == "true") {
return false;
}
$(this).attr("loaded", "true")
var name = $(this).val();
var options = $(this).attr("options");
initEditor(name, options);
})
}
}
function addEditor(name, options) {
console.log("ADD" + name)
var ueitem = document.createElement("input");
ueitem.type = 'hidden';
ueitem.className = 'ueditorItem';
ueitem.value = name;
if (options)
ueitem.setAttribute("options", JSON.stringify(options));
ueitem.setAttribute("loaded", "false");
document.getElementsByTagName('body')[0].appendChild(ueitem);
}
var styleAttrs = ['width', 'height'];
function initEditor(name, options) {
options = options || {};
if (typeof(options) == "string")
try {
options = JSON.parse(options);
} catch (e) {
console.log(e.message)
options = {
fullable: true
};
}
/* 再去掉,去掉 ?wdApplication= -- 不支持多个应用,ssServ= 里可以写 ss.xxx。Lin
options.wdApp = options.wdApp || getUrlVar("wdApplication");
if (options.wdApp == null) {
alert("没获取到参数wdApp");
return;
}
*/
options.forbd != null && alert("“forbd”已摒弃,请使用“mode=change”");
options.forbd != null && delete options["forbd"];
if (options.edittemplate) {
$("body").append("");
}
function getUrlVar(name) {
var vars = [],
hash;
var hashes = window.location.href.slice(
window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars[name];
};
/**
* 绑定对象名的模板
* @param {Object} lbm
* @param {Object} dxm
* @param {Object} editorid
*/
var txt = $("div#" + name + "Edit");
// txt.css({
// "width": '100%'
// });
$.each(styleAttrs, function () {
var attrV = txt.attr(this);
if (attrV != null) {
txt.css(this, attrV);
}
});
var player = $("#" + name + "Play");
var pathinp = $("input[name='" + name + "wj']").eq(0);
var path = pathinp.val();
/* 再去掉,去掉 ?wdApplication= -- 不支持多个应用,ssServ= 里可以写 ss.xxx。Lin
window.wdApp = "&wdApp=" + options.wdApp;
*/
if (options.lbList) {
$.each(options.lbList, function () {
options[this.toString()] = $("select[name='" + this.toString() + "']").val();
});
}
options.othertmpl = $("select[name='othertmpl']").val();
if (options.othertmpl) {
options["t_" + options.othertmpl.toString()] = options.othertmpl.toString();
}
var data = wd.c.getUeditorData(path, options);
var f = $("
0 && range_.toString().charCodeAt() === 32) {
console.log(range_)
range_.startContainer.replaceData(sofs - 1, 1, String.fromCharCode(8194)); //8194是 也可能会用160( )
}
range_.setStart(range_.startContainer, sofs);
range_.setEnd(range_.startContainer, sofs);
range_.collapse(true)
// 清除选定对象的所有光标对象
window.getSelection().removeAllRanges()
// 插入新的光标对象
window.getSelection().addRange(range_)
}
});
var callback_;
if (opts.callback && typeof(opts.callback) == "string") {
callback_ = eval(opts.callback);
} else if (opts.callback && typeof(opts.callback) == "function") {
callback_ = opts.callback;
}
if (opts.bindList) {
console.log(opts.bindList)
try {
bindInput(opts.bindList, name + "Edit");
} catch (e) {
console.error(e.message)
}
}
bindSelect(opts.lbList, opts.dxm, name + "Edit", function () {
//切换模板之后的回调
console.log(opts.bindList)
if (opts.bindList) {
for (k in opts.bindList) {
var name = opts.bindList[k];
var $inp = $("input[name='" + name + "']");
if (growHeightList && growHeightList[name]) {
$inp = $(growHeightList[name].getInputElement());
}
$inp.trigger("inputchange");
}
}
});
try {
window[name + "_initWDEditor"] && window[name + "_initWDEditor"](this);
} catch (e) {
console.error("初始化WDEditorUI时发生异常");
}
this.setContent(data.content || txt.val());
window.loadStyles && window.loadStyles(data.styles);
callback_ && callback_.call(this);
for (var i = 0; window.ueCallback != null && window.ueCallback[name] != null && i < window.ueCallback[name].length; i++) {
window.ueCallback[name][i]();
}
// this.execCommand('cleardoc');
// this.focus();
// this.execCommand('inserthtml', data.content);
});
})(name, options)
}
if (player.length > 0 && options.mode == "play" || options.mode == "body") {
console.log("播放器" + name + "Play");
if (player.is("td")) {
var id = player.attr("id");
player.attr("id", "");
player.append("
")
player = $("#" + id);
}
player.addClass("player").before(f);
// f.before("
")
f.append(player);
//全屏、附件按钮
player.css({
overflow: "auto"
});
var t = data.content;
if (options.textonly) {
t = wd.display.removeHTMLTag(t);
}
player.html(t);
if (typeof getGrowHeight != "undefined" && options.mode != "body"&&options["btn_opt_cms"]) { //有growHeight脚本,用growHeight初始化
var cms_jlztm=options["btn_opt_cms"].jlztm?options["btn_opt_cms"].jlztm:options.cms_jlztm;
var gh = wd.display.initGrowHighHtml(player.attr("id"), 300, options["btn_opt_cms"] ? {
fj: {
"key": options["btn_opt_cms"].key,
"value": options["btn_opt_cms"].value,
"name": options["btn_opt_cms"].name,
"jlztm": cms_jlztm
}
}
: {});
if (gh.cmsBtn && options["btn_opt_cms"]) {
console.log(gh.cmsBtn);
bindCMS([gh.cmsBtn], options["btn_opt_cms"].value, cms_jlztm, options.cms_play, options.cms_play_atom);
}
} else { //ueditor原来的脚本
if (options && options.toolbars) {
for (var i = 0; i < options.toolbars[0].length; i++) {
var o = options.toolbars[0][i];
if (typeof(o) == "string" && o == "fullscreen") {
// if(options && (options.fullable != "false" && options.fullable != false) && wd.display.removeHTMLTag(data.content) != '') {
// f.addClass("fullable");
f.prepend("
");
} else if (typeof(o) == "string" && o == "cms") {
var btn = $("
");
f.prepend(btn);
// f.append("
")
var cms_jlztm=options["btn_opt_cms"].jlztm?options["btn_opt_cms"].jlztm:options.cms_jlztm;
bindCMS(btn, options["btn_opt_cms"].value, cms_jlztm, options.cms_play, options.cms_play_atom);
}
}
}
}
// $p=$("input[name='ueditorpath']");
// $("input[name='"+$p.val()+"']").remove();
// $p.remove();
if (!options.callback) {}
else
if (typeof(options.callback) == "string") {
callback_ = eval(options.callback);
callback_.call(this);
} else
if (typeof(options.callback) == 'function') {
options.callback.call(this);
}
};
}
function bindCMS(btn, nrid, jlztm, cms_play, cms_play_atom) {
function fjPlayClick() {
if (nrid == null || nrid.length == 0) {
$.ajax({
type: 'GET',
url: '/service?ssServ=makeAttCms', // =getNewNridAndUpdateNrmc。Lin
data: {
name: 'fj'
},
async: false,
success: function (data) {
nrid = data;
},
});
}
var user = ''
var Nrid = 'T-' + nrid;
var str = '&nrid=';
str += Nrid;
if (jlztm != undefined && jlztm != "") {
if (cms_play.indexOf("&jlztm=") == -1){
str += '&jlztm=' + jlztm;
}else{
var ss =cms_play.split("&jlztm=")
if(ss[1]!=jlztm){
cms_play=cms_play.replace("&jlztm="+ss[1],'&jlztm=' + jlztm);
}
}
}
if (user != undefined && user != "") {
str += '&user=';
str += user;
}
var nrjslbm;
$.ajax({
type: 'POST',
url: '/service?ssServ=wrNrjslbm', // =getNrjslbm,。Lin
data: {
nrid: nrid
},
async: false,
success: function (data) {
nrjslbm = data;
},
});
if (nrjslbm == 150 || nrjslbm == '150') {
wd.display.showComponent({
show: ['wdDialog'],
hide: [],
url: cms_play + str,
dest: 'cmsPlay', // : 'nr_bf',。Lin
title: '播放',
width: 900,
high: 664,
wdDialogId: 44011763,
form: ''
});
} else {
wd.display.showComponent({
show: ['wdDialog'],
hide: [],
url: cms_play_atom + str + '&nrjslbm=' + nrjslbm,
dest: 'ccmsPlay', // : 'yznr_bfq',。Lin
title: '播放',
width: 900,
high: 664,
wdDialogId: 44011763,
form: ''
});
}
}
(function () {
var play = btn[0];
if (play != null) {
if (nrid == null || nrid.length == 0) {
play.className = 'disabled-button';
play.setAttribute('disabled', 'disabled');
play.style.display = "none";
} else {
var flag = null;
var Nrid = 'T-' + nrid;
$.ajax({
type: 'GET',
url: '/service?ssServ=wrHasCcms', // =checkNrHasChildren'。Lin
data: {
'nrid': Nrid // 'id':。统一为 "nrid" = CmsC.REQ_cmsId。Lin
},
dataType: 'json',
async: false,
success: function (data) {
/// 增加,增加错误处理 -- 统一 Ajax 返回标准 -- .ssCode、.ssMsg、.ssData。Lin
if (data.ssCode != 0) {
alert(data.ssMsg);
return;
}
///
flag = data.result;
}
});
if (flag) {
play.cms_jlztm = jlztm;
if (play.addEventListener) {
play.addEventListener('click', fjPlayClick, false);
} else if (play.attachEvent) {
play.attachEvent('onclick', fjPlayClick);
} else {
play['onclick'] = fjPlayClick;
}
} else {
console.info(flag);
play.setAttribute('disabled', 'disabled');
play.style.display = "none";
}
}
}
})();
}
function bindSelect(lbList, dxm, editorid, callback) {
if ($("#oldlbl").length < 1) {
$("body").append("
")
}
var olb = [];
if (lbList)
$.each(lbList, function () {
var name = this.toString();
olb.push("old" + name);
var $inp = $("[name='" + name + "']");
if ($inp.is("select") || (wd.edit.objectPicker && wd.edit.objectPicker.isObjectPicker($inp[0]))) { //下拉菜单或者objectpicker才能切换模板
$inp.attr("id", name).after("
");
$inp.bind("change", function () {
var old = $("#old" + this.name),
val = $(this).val(),
content = UE.getEditor(editorid).getContent(),
olblist = eval($("#oldlbl").val());
if (content.trim() == "") {
lbList.push("otherTmpl");
loadUEDTempLate(dxm, lbList, editorid, callback);
old.val(val);
} else {
if ($("#edittemplate").length > 0) {
// console.log("EQUALS+")
lbList.push("otherTmpl");
loadUEDTempLate(dxm, lbList, editorid, callback);
old.val($(this).val());
}
}
});
// $("select[name='" + lbm + "']").attr("id", lbm).after("
");
// $("select[name='" + lbm + "']") /*.unbind("change")*/.bind("change", function () {
// var old = $("#old" + lbm);
// var content = UE.getEditor(editorid).getContentTxt();
// var olblist = eval($("#oldlbl").val());
// if (content.trim() == "") {
// lbList.push("otherTmpl");
// loadUEDTempLate(dxm, lbList, editorid, callback);
// old.val($(this).val());
// } else {
// // var oldtmp = loadUEDTempLate(dxm, olblist).content;
// // console.log("CONTENT:" + content);
// // console.log("TEMPLATE:" + wd.display.removeHTMLTag(oldtmp));
// if ($("#edittemplate").length > 0 || /*wd.display.removeHTMLTag(content) == wd.display.removeHTMLTag(oldtmp) || */(confirm("您切换了类别,是否切换对应的模板\n(切换模板后可以按编辑器上的“撤销”按钮\n或键盘上“Ctrl” + “z”进行撤销)"))) {
// // console.log("EQUALS+")
// lbList.push("otherTmpl");
// loadUEDTempLate(dxm, lbList, editorid, callback);
// old.val($(this).val());
// }
// }
// });
}
});
$("#oldlbl").val(JSON.stringify(olb));
}
function bindInput(inputList, editorid) {
console.log(inputList)
function bindInputChange(inputname, editorid) {
var $inp = $("[name='" + inputname + "']");
if (growHeightList && growHeightList[inputname]) {
$inp = $(growHeightList[inputname].getInputElement());
}
if ($inp.length > 0) {
$inp.bind("keyup keydown mouseup click change input propertychange change", function (event) {
$(this).trigger("inputchange");
});
$inp.bind("inputchange", function (event) {
var $this = $(this),
val = $this.val();
if ($this.is("select")) {
val = $this.find("option:selected").text();
} else if (wd.edit.objectPicker.isObjectPicker($this[0])) {
val = wd.edit.objectPicker.getDisplayValue($this[0])
}
var target = $("#" + editorid).find(".edui-editor-iframeholder ").find("iframe").eq(0).contents().find("." + inputname);
// console.log(a)
if (val != "") {
target.text(val);
var e = UE.getEditor(editorid);
e.setContent('', true);
}
});
if (inputname.length >= 2 && inputname.substr(inputname.length - 2, inputname.length) == "sj") {
//没有值的时候才赋值
if ($inp.val() == '') {
$inp.val(new Date().format("yyyy-MM-dd"));
$inp.trigger("inputchange");
}
}
$inp.trigger("inputchange");
} else {
console.log("没找到input:" + inputname);
}
}
if (inputList)
$.each(inputList, function (key, val) {
console.log(key + ":" + val);
bindInputChange(val, editorid);
})
}
window.top.ueFul = function (obj) {
//允许所有iframe全屏
var arr = parent.document.getElementsByTagName('IFRAME');
for (var i = 0; i < arr.length; i++) {
var iframeObj = arr[i];
iframeObj.setAttribute("allowfullscreen", true);
}
arr = parent.parent.document.getElementsByTagName('IFRAME');
for (var i = 0; i < arr.length; i++) {
var iframeObj = arr[i];
iframeObj.setAttribute("allowfullscreen", true);
}
var element = $(obj).parent()[0];
console.log(element);
var fullscreenchange = function () {
if (document.webkitFullscreenElement != null) {
$(element).addClass("scrollbar");
$(element).css("padding", "30px");
$(element).css("box-sizing", "border-box");
element.style.overflowY = "auto";
element.style.overflowX = "hidden";
element.style.width = "100%";
element.style.height = "100%";
element.style.zoom = 2;
$(obj).hide();
console.log("进入全屏函数");
$('.list-button').css({
'display': 'none'
});
$('.player').append('
');
} else {
console.log("退出全屏函数");
$(element).removeClass("scrollbar");
$(element).css("padding", "0px");
$(element).css("box-sizing", "border-box");
element.style.height = 'auto';
element.style.width = 'auto';
element.style.zoom = 1;
$(obj).show();
//添加监听器,监听用户进入全屏和退出全屏操作
element.removeEventListener("webkitfullscreenchange", fullscreenchange);
element.removeEventListener("fullscreenchange", fullscreenchange);
element.removeEventListener("mozfullscreenchange", fullscreenchange);
element.removeEventListener("msfullscreenchange", fullscreenchange);
$('.list-button').css({
'display': 'block'
});
$('.player #pageClose').remove();
}
}
element.addEventListener("webkitfullscreenchange", fullscreenchange);
element.addEventListener("fullscreenchange", fullscreenchange);
element.addEventListener("mozfullscreenchange", fullscreenchange);
element.addEventListener("msfullscreenchange", fullscreenchange);
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.webkitRequestFullScreen) {
element.webkitRequestFullScreen();
}
}
ueFul = function (obj) {
//允许所有iframe全屏
var arr = parent.document.getElementsByTagName('IFRAME');
for (var i = 0; i < arr.length; i++) {
var iframeObj = arr[i];
iframeObj.setAttribute("allowfullscreen", true);
}
arr = parent.parent.document.getElementsByTagName('IFRAME');
for (var i = 0; i < arr.length; i++) {
var iframeObj = arr[i];
iframeObj.setAttribute("allowfullscreen", true);
}
var element = $(obj).parent()[0];
console.log(element);
var fullscreenchange = function () {
if (document.webkitFullscreenElement != null) {
// $(element).addClass("scrollbar");
$(element).css("padding", "30px");
$(element).css("box-sizing", "border-box");
element.style.overflowY = "auto";
element.style.overflowX = "hidden";
element.style.width = "100%";
element.style.height = "100%";
element.style.zoom = 2;
$(obj).hide();
console.log("进入全屏函数");
$('.list-button').css({
'display': 'none'
});
$('.player').append('
');
} else {
console.log("退出全屏函数");
$(element).removeClass("scrollbar");
$(element).css("padding", "0px");
$(element).css("box-sizing", "border-box");
element.style.height = 'auto';
element.style.width = 'auto';
element.style.zoom = 1;
$('#zwPlay').css('height', '88%'); //须知调样式
$(obj).show();
//添加监听器,监听用户进入全屏和退出全屏操作
element.removeEventListener("webkitfullscreenchange", fullscreenchange);
element.removeEventListener("fullscreenchange", fullscreenchange);
element.removeEventListener("mozfullscreenchange", fullscreenchange);
element.removeEventListener("msfullscreenchange", fullscreenchange);
$('.list-button').css({
'display': 'block'
});
$('.player #pageClose').remove();
}
}
element.addEventListener("webkitfullscreenchange", fullscreenchange);
element.addEventListener("fullscreenchange", fullscreenchange);
element.addEventListener("mozfullscreenchange", fullscreenchange);
element.addEventListener("msfullscreenchange", fullscreenchange);
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.webkitRequestFullScreen) {
element.webkitRequestFullScreen();
}
}
// 退出全屏
function exitFullscreen() {
var elem = document;
if (elem.webkitCancelFullScreen) {
elem.webkitCancelFullScreen();
} else if (elem.mozCancelFullScreen) {
elem.mozCancelFullScreen();
} else if (elem.cancelFullScreen) {
elem.cancelFullScreen();
} else if (elem.exitFullscreen) {
elem.exitFullscreen();
} else {
alert('浏览器不支持全屏API或已被禁用,请按esc键退出');
//浏览器不支持全屏API或已被禁用
}
}
bodyFul = function (obj, hasAbstract) {
//允许所有iframe全屏
var arr = parent.document.getElementsByTagName('IFRAME');
for (var i = 0; i < arr.length; i++) {
var iframeObj = arr[i];
iframeObj.setAttribute("allowfullscreen", true);
}
arr = parent.parent.document.getElementsByTagName('IFRAME');
for (var i = 0; i < arr.length; i++) {
var iframeObj = arr[i];
iframeObj.setAttribute("allowfullscreen", true);
}
var element = $(obj).parent()[0];
console.log(element);
var fullscreenchange = function () {
if (document.webkitFullscreenElement != null) {
$(element).addClass("scrollbar");
$(element).css("padding", "30px");
$(element).css("box-sizing", "border-box");
element.style.overflowY = "auto";
element.style.overflowX = "hidden";
element.style.width = "100%";
element.style.height = "100%";
element.style.zoom = 2;
//$(obj).hide();
if (hasAbstract) {
$(obj).show();
}
console.log("进入全屏函数");
$('.list-button').css({
'display': 'none'
});
$('.player').append('
');
} else {
console.log("退出全屏函数");
$(element).removeClass("scrollbar");
$(element).css("padding", "0px");
$(element).css("box-sizing", "border-box");
element.style.height = 'auto';
element.style.width = 'auto';
element.style.zoom = 1;
//$(obj).show();
//添加监听器,监听用户进入全屏和退出全屏操作
element.removeEventListener("webkitfullscreenchange", fullscreenchange);
element.removeEventListener("fullscreenchange", fullscreenchange);
element.removeEventListener("mozfullscreenchange", fullscreenchange);
element.removeEventListener("msfullscreenchange", fullscreenchange);
if (hasAbstract) {
$(obj).hide();
}
$('.list-button').css({
'display': 'block'
});
$('.player #pageClose').remove();
}
}
element.addEventListener("webkitfullscreenchange", fullscreenchange);
element.addEventListener("fullscreenchange", fullscreenchange);
element.addEventListener("mozfullscreenchange", fullscreenchange);
element.addEventListener("msfullscreenchange", fullscreenchange);
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.webkitRequestFullScreen) {
element.webkitRequestFullScreen();
}
}
function loadUEDTempLate(templateName, lbList, editorid, callback) {
var ueopt = UE.getEditor(editorid, options).options;
var options = {
mode: ueopt.mode,
dxm: ueopt.dxm
};
options.othertmpl = $("[name='othertmpl']").val();
if (options.othertmpl) {
options["t_" + options.othertmpl.toString()] = options.othertmpl.toString();
}
options.edittemplate = $("#edittemplate").length > 0 ? 1 : null;
if (lbList)
$.each(lbList, function () {
options[this.toString()] = $("[name='" + this.toString() + "']").val();
});
options.template = templateName;
/* 再去掉,去掉 ?wdApplication= -- 不支持多个应用,ssServ= 里可以写 ss.xxx。Lin
options.wdApp = UE.getEditor(editorid).options.wdApp;
*/
var result = wd.c.getUeditorData(null, options);
if (UE) {
if (editorid) {
var edit = UE.getEditor(editorid, options).ready(function () {
// this.execCommand("cleardoc");
// this.execCommand("inserthtml", result.content);
// this.setContent(result.content, false, true);
this.setContent(result.content);
this.options.imgWidth = result.imgWidth;
this.options.imgHeight = result.imgHeight;
window.loadStyles && window.loadStyles(result.styles);
});
}
if (callback)
callback();
}
if (options.edittemplate && editorid)
$("#" + editorid.replace("Edit", "") + "wj").val(result.path);
return result;
}