You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
713 lines
106 KiB
713 lines
106 KiB
4 years ago
|
/**
|
||
|
* Created by JetBrains PhpStorm.
|
||
|
* User: taoqili
|
||
|
* Date: 12-01-08
|
||
|
* Time: 下午2:52
|
||
|
* To change this template use File | Settings | File Templates.
|
||
|
*/
|
||
|
var imageUploader = {},
|
||
|
flashObj = null,
|
||
|
postConfig=[];
|
||
|
(function () {
|
||
|
var g = $G,
|
||
|
ajax = parent.baidu.editor.ajax,
|
||
|
maskIframe = g("maskIframe"); //tab遮罩层,用来解决flash和其他dom元素的z-index层级不一致问题
|
||
|
// flashObj; //flash上传对象
|
||
|
|
||
|
var flagImg = null, flashContainer;
|
||
|
imageUploader.init = function (opt, callbacks) {
|
||
|
switchTab("imageTab");
|
||
|
createAlignButton(["remoteFloat", "localFloat"]);
|
||
|
createFlash(opt, callbacks);
|
||
|
var srcImg = editor.selection.getRange().getClosedNode();
|
||
|
if (srcImg) {
|
||
|
showImageInfo(srcImg);
|
||
|
showPreviewImage(srcImg, true);
|
||
|
var tabElements = g("imageTab").children,
|
||
|
tabHeads = tabElements[0].children,
|
||
|
tabBodys = tabElements[1].children;
|
||
|
for (var i = 0, ci; ci = tabHeads[i++];) {
|
||
|
if (ci.getAttribute("tabSrc") == "remote") {
|
||
|
clickHandler(tabHeads, tabBodys, ci);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
addUrlChangeListener();
|
||
|
addOKListener();
|
||
|
addScrollListener();
|
||
|
addSearchListener();
|
||
|
$focus(g("url"));
|
||
|
};
|
||
|
imageUploader.setPostParams = function(obj,index){
|
||
|
if(index===undefined){
|
||
|
utils.each(postConfig,function(config){
|
||
|
config.data = obj;
|
||
|
})
|
||
|
}else{
|
||
|
postConfig[index].data = obj;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
function insertImage(imgObjs) {
|
||
|
editor.fireEvent('beforeInsertImage', imgObjs);
|
||
|
editor.execCommand("insertImage", imgObjs);
|
||
|
}
|
||
|
|
||
|
function searchImage() {
|
||
|
var imgSearchInput = $G("imgSearchTxt");
|
||
|
if (!imgSearchInput.getAttribute("hasClick") || !imgSearchInput.value) {
|
||
|
selectTxt(imgSearchInput);
|
||
|
return;
|
||
|
}
|
||
|
g("searchList").innerHTML = "<p class='msg'>" + lang.imageLoading + "</p>";
|
||
|
var key = imgSearchInput.value,
|
||
|
type = $G("imgType").value,
|
||
|
url = "http://image.baidu.com/i?ct=201326592&cl=2&lm=-1&st=-1&tn=baiduimagejson&istype=2&rn=32&fm=index&pv=&word=" + encodeToGb2312(key) + type + "&" + +new Date;
|
||
|
var reqCallBack = function (data) {
|
||
|
try {
|
||
|
var imgObjs = data.data;
|
||
|
} catch (e) {
|
||
|
return;
|
||
|
}
|
||
|
var frg = document.createDocumentFragment();
|
||
|
if (imgObjs.length < 2) {
|
||
|
g("searchList").innerHTML = "<p class='msg'>" + lang.tryAgain + "</p>";
|
||
|
return;
|
||
|
}
|
||
|
for (var i = 0, len = imgObjs.length; i < len - 1; i++) {
|
||
|
var img = document.createElement("img"), obj = imgObjs[i], div = document.createElement("div");
|
||
|
img.src = obj.objURL; //obj.thumbURL 为缩略图,只能针对百度内部使用
|
||
|
img.setAttribute("sourceUrl", obj.objURL);
|
||
|
var title = obj.fromPageTitleEnc.replace(/^\.\.\./i, "");
|
||
|
img.setAttribute("title", lang.toggleSelect + obj.width + "X" + obj.height);
|
||
|
img.onclick = function () {
|
||
|
changeSelected(this);
|
||
|
};
|
||
|
scale(img, 100, obj.width, obj.height);
|
||
|
div.appendChild(img);
|
||
|
var p = document.createElement("p");
|
||
|
p.innerHTML = "<a target='_blank' href='" + obj.fromURL + "'>" + title + "</a>";
|
||
|
div.appendChild(p);
|
||
|
//setTimeout(function(){
|
||
|
frg.appendChild(div);
|
||
|
//},0);
|
||
|
|
||
|
}
|
||
|
g("searchList").innerHTML = "";
|
||
|
g("searchList").appendChild(frg);
|
||
|
};
|
||
|
baidu.sio.callByServer(url, reqCallBack, {charset:"GB18030"});
|
||
|
}
|
||
|
|
||
|
function selectTxt(node) {
|
||
|
if (node.select) {
|
||
|
node.select();
|
||
|
} else {
|
||
|
var r = node.createTextRange && node.createTextRange();
|
||
|
r.select();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function addSearchListener() {
|
||
|
g("imgSearchTxt").onclick = function () {
|
||
|
selectTxt(this);
|
||
|
this.setAttribute("hasClick", true);
|
||
|
if (this.value == lang.searchInitInfo) {
|
||
|
this.value = "";
|
||
|
}
|
||
|
};
|
||
|
g("imgSearchTxt").onkeyup = function () {
|
||
|
this.setAttribute("hasClick", true);
|
||
|
//只触发一次
|
||
|
this.onkeyup = null;
|
||
|
};
|
||
|
|
||
|
g("imgSearchBtn").onclick = function () {
|
||
|
searchImage();
|
||
|
};
|
||
|
g("imgSearchReset").onclick = function () {
|
||
|
var txt = g("imgSearchTxt");
|
||
|
txt.value = "";
|
||
|
txt.focus();
|
||
|
g("searchList").innerHTML = "";
|
||
|
};
|
||
|
g("imgType").onchange = function () {
|
||
|
searchImage();
|
||
|
};
|
||
|
domUtils.on(g("imgSearchTxt"), "keyup", function (evt) {
|
||
|
if (evt.keyCode == 13) {
|
||
|
searchImage();
|
||
|
}
|
||
|
})
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 延迟加载
|
||
|
*/
|
||
|
function addScrollListener() {
|
||
|
|
||
|
g("imageList").onscroll = function () {
|
||
|
var imgs = this.getElementsByTagName("img"),
|
||
|
top = Math.ceil(this.scrollTop / 100) - 1;
|
||
|
top = top < 0 ? 0 : top;
|
||
|
for (var i = top * 5; i < (top + 5) * 5; i++) {
|
||
|
var img = imgs[i];
|
||
|
if (img && !img.getAttribute("src")) {
|
||
|
img.src = img.getAttribute("lazy_src");
|
||
|
img.removeAttribute("lazy_src");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 绑定确认按钮
|
||
|
*/
|
||
|
function addOKListener() {
|
||
|
dialog.onok = function () {
|
||
|
var currentTab = findFocus("tabHeads", "tabSrc");
|
||
|
switch (currentTab) {
|
||
|
case "remote":
|
||
|
return insertSingle();
|
||
|
break;
|
||
|
case "local":
|
||
|
return insertBatch();
|
||
|
break;
|
||
|
case "imgManager":
|
||
|
return insertSearch("imageList");
|
||
|
break;
|
||
|
case "imgSearch":
|
||
|
return insertSearch("searchList", true);
|
||
|
break;
|
||
|
}
|
||
|
};
|
||
|
dialog.oncancel = function () {
|
||
|
hideFlash();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function hideFlash() {
|
||
|
flashObj = null;
|
||
|
flashContainer.innerHTML = "";
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 将元素id下的所有图片文件插入到编辑器中。
|
||
|
* @param id
|
||
|
* @param catchRemote 是否需要替换远程图片
|
||
|
*/
|
||
|
function insertSearch(id, catchRemote) {
|
||
|
var imgs = $G(id).getElementsByTagName("img"), imgObjs = [];
|
||
|
for (var i = 0, ci; ci = imgs[i++];) {
|
||
|
if (ci.getAttribute("selected")) {
|
||
|
var url = ci.getAttribute("src", 2).replace(/(\s*$)/g, ""), img = {};
|
||
|
img.src = url;
|
||
|
img._src = url;
|
||
|
imgObjs.push(img);
|
||
|
}
|
||
|
}
|
||
|
insertImage(imgObjs);
|
||
|
catchRemote && editor.fireEvent("catchRemoteImage");
|
||
|
hideFlash();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 插入单张图片
|
||
|
*/
|
||
|
function insertSingle() {
|
||
|
var url = g("url"),
|
||
|
width = g("width"),
|
||
|
height = g("height"),
|
||
|
border = g("border"),
|
||
|
vhSpace = g("vhSpace"),
|
||
|
title = g("title"),
|
||
|
align = findFocus("remoteFloat", "name"),
|
||
|
imgObj = {};
|
||
|
if (!url.value) return;
|
||
|
if (!flagImg) return; //粘贴地址后如果没有生成对应的预览图,可以认为本次粘贴地址失败
|
||
|
if (!checkNum([width, height, border, vhSpace])) return false;
|
||
|
imgObj.src = url.value;
|
||
|
imgObj._src = url.value;
|
||
|
imgObj.width = width.value;
|
||
|
imgObj.height = height.value;
|
||
|
imgObj.border = border.value;
|
||
|
imgObj.floatStyle = align;
|
||
|
imgObj.vspace = imgObj.hspace = vhSpace.value;
|
||
|
imgObj.title = title.value;
|
||
|
imgObj.style = "width:" + width.value + "px;height:" + height.value + "px;";
|
||
|
insertImage(imgObj);
|
||
|
editor.fireEvent("catchRemoteImage");
|
||
|
hideFlash();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 检测传入的所有input框中输入的长宽是否是正数
|
||
|
* @param nodes input框集合,
|
||
|
*/
|
||
|
function checkNum(nodes) {
|
||
|
for (var i = 0, ci; ci = nodes[i++];) {
|
||
|
if (!isNumber(ci.value) || ci.value < 0) {
|
||
|
alert(lang.numError);
|
||
|
ci.value = "";
|
||
|
ci.focus();
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 数字判断
|
||
|
* @param value
|
||
|
*/
|
||
|
function isNumber(value) {
|
||
|
return /(0|^[1-9]\d*$)/.test(value);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 插入多张图片
|
||
|
*/
|
||
|
function insertBatch() {
|
||
|
if (imageUrls.length < 1) return;
|
||
|
var imgObjs = [],
|
||
|
align = findFocus("localFloat", "name");
|
||
|
|
||
|
for (var i = 0, ci; ci = imageUrls[i++];) {
|
||
|
var tmpObj = {};
|
||
|
tmpObj.title = ci.title;
|
||
|
tmpObj.floatStyle = align;
|
||
|
//修正显示时候的地址数据,如果后台返回的是图片的绝对地址,那么此处无需修正
|
||
|
tmpObj._src = tmpObj.src = editor.options.imagePath + ci.url;
|
||
|
imgObjs.push(tmpObj);
|
||
|
}
|
||
|
insertImage(imgObjs);
|
||
|
hideFlash();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 找到id下具有focus类的节点并返回该节点下的某个属性
|
||
|
* @param id
|
||
|
* @param returnProperty
|
||
|
*/
|
||
|
function findFocus(id, returnProperty) {
|
||
|
var tabs = g(id).children,
|
||
|
property;
|
||
|
for (var i = 0, ci; ci = tabs[i++];) {
|
||
|
if (ci.className == "focus") {
|
||
|
property = ci.getAttribute(returnProperty);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
return property;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 绑定地址框改变事件
|
||
|
*/
|
||
|
function addUrlChangeListener() {
|
||
|
var value = g("url").value;
|
||
|
if (browser.ie) {
|
||
|
g("url").onpropertychange = function () {
|
||
|
var v = this.value;
|
||
|
if (v != value) {
|
||
|
createPreviewImage(v);
|
||
|
value = v;
|
||
|
}
|
||
|
};
|
||
|
} else {
|
||
|
g("url").addEventListener("input", function () {
|
||
|
var v = this.value;
|
||
|
if (v != value) {
|
||
|
createPreviewImage(v);
|
||
|
value = v;
|
||
|
}
|
||
|
}, false);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 绑定图片等比缩放事件
|
||
|
* @param percent 缩放比例
|
||
|
*/
|
||
|
function addSizeChangeListener(percent) {
|
||
|
var width = g("width"),
|
||
|
height = g("height"),
|
||
|
lock = g('lock');
|
||
|
width.onkeyup = function () {
|
||
|
if (!isNaN(this.value) && lock.checked) {
|
||
|
height.value = Math.round(this.value / percent) || this.value;
|
||
|
}
|
||
|
};
|
||
|
height.onkeyup = function () {
|
||
|
if (!isNaN(this.value) && lock.checked) {
|
||
|
width.value = Math.round(this.value * percent) || this.value;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 依据url中的地址创建一个预览图片并将对应的信息填入信息框和预览框
|
||
|
*/
|
||
|
function createPreviewImage(url) {
|
||
|
if (!url) {
|
||
|
flagImg = null;
|
||
|
g("preview").innerHTML = "";
|
||
|
g("width").value = "";
|
||
|
g("height").value = "";
|
||
|
g("border").value = "";
|
||
|
g("vhSpace").value = "";
|
||
|
g("title").value = "";
|
||
|
$focus(g("url"));
|
||
|
return;
|
||
|
}
|
||
|
var img = document.createElement("img"),
|
||
|
preview = g("preview");
|
||
|
|
||
|
var imgTypeReg = /\.(png|gif|jpg|jpeg)$/gi, //格式过滤
|
||
|
urlFilter = ""; //地址过滤
|
||
|
if (!imgTypeReg.test(url) || url.indexOf(urlFilter) == -1) {
|
||
|
preview.innerHTML = "<span style='color: red'>" + lang.imageUrlError + "</span>";
|
||
|
flagImg = null;
|
||
|
return;
|
||
|
}
|
||
|
preview.innerHTML = lang.imageLoading;
|
||
|
img.onload = function () {
|
||
|
flagImg = this;
|
||
|
showImageInfo(this);
|
||
|
showPreviewImage(this,true);
|
||
|
this.onload = null;
|
||
|
};
|
||
|
img.onerror = function () {
|
||
|
preview.innerHTML = "<span style='color: red'>" + lang.imageLoadError + "</span>";
|
||
|
flagImg = null;
|
||
|
this.onerror = null;
|
||
|
};
|
||
|
img.src = url;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 显示图片对象的信息
|
||
|
* @param img
|
||
|
*/
|
||
|
function showImageInfo(img) {
|
||
|
if (!img.getAttribute("src") || !img.src) return;
|
||
|
var wordImgFlag = img.getAttribute("word_img");
|
||
|
g("url").value = wordImgFlag ? wordImgFlag.replace("&", "&") : (img.getAttribute('_src') || img.getAttribute("src", 2).replace("&", "&"));
|
||
|
g("width").value = img.width || 0;
|
||
|
g("height").value = img.height || 0;
|
||
|
g("border").value = img.getAttribute("border") || 0;
|
||
|
g("vhSpace").value = img.getAttribute("vspace") || 0;
|
||
|
g("title").value = img.title || "";
|
||
|
var align = editor.queryCommandValue("imageFloat") || "none";
|
||
|
updateAlignButton(align);
|
||
|
|
||
|
//保存原始比例,用于等比缩放
|
||
|
var percent = (img.width / img.height).toFixed(2);
|
||
|
addSizeChangeListener(percent);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 将img显示在预览框,
|
||
|
* @param img
|
||
|
* @param needClone 是否需要克隆后显示
|
||
|
*/
|
||
|
function showPreviewImage(img, needClone) {
|
||
|
var tmpWidth = img.width, tmpHeight = img.height;
|
||
|
var maxWidth = 262,maxHeight = 262,
|
||
|
target = scaling(tmpWidth,tmpHeight,maxWidth,maxHeight);
|
||
|
target.border = img.border||0;
|
||
|
target.src = img.src;
|
||
|
flagImg = true;
|
||
|
if ((target.width + 2 * target.border) > maxWidth) {
|
||
|
target.width = maxWidth - 2 * target.border;
|
||
|
}
|
||
|
if ((target.height + 2 * target.border) > maxWidth) {
|
||
|
target.height = maxWidth - 2 * target.border;
|
||
|
}
|
||
|
var preview = g("preview");
|
||
|
preview.innerHTML = '<img src="' + target.src + '" width="' + target.width + '" height="' + target.height + '" border="' + target.border + 'px solid #000" />';
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 图片缩放
|
||
|
* @param img
|
||
|
* @param max
|
||
|
*/
|
||
|
function scale(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;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function scaling(width,height,maxWidth,maxHeight){
|
||
|
if(width<maxWidth && height<maxHeight) return {width:width,height:height};
|
||
|
var srcRatio = (width/height).toFixed(2),
|
||
|
tarRatio = (maxWidth/maxHeight).toFixed(2),
|
||
|
w,h;
|
||
|
if(srcRatio<tarRatio){
|
||
|
h = maxHeight;
|
||
|
w = h*srcRatio;
|
||
|
}else{
|
||
|
w = maxWidth;
|
||
|
h = w/srcRatio;
|
||
|
}
|
||
|
return {width:w.toFixed(0),height:h.toFixed(0)}
|
||
|
}
|
||
|
/**
|
||
|
* 创建flash实例
|
||
|
* @param opt
|
||
|
* @param callbacks
|
||
|
*/
|
||
|
function createFlash(opt, callbacks) {
|
||
|
var i18n = utils.extend({}, lang.flashI18n);
|
||
|
//处理图片资源地址的编码,补全等问题
|
||
|
for (var i in i18n) {
|
||
|
if (!(i in {"lang":1, "uploadingTF":1, "imageTF":1, "textEncoding":1}) && i18n[i]) {
|
||
|
i18n[i] = encodeURIComponent(editor.options.langPath + editor.options.lang + "/images/" + i18n[i]);
|
||
|
}
|
||
|
}
|
||
|
opt = utils.extend(opt, i18n, false);
|
||
|
var option = {
|
||
|
createOptions:{
|
||
|
id:'flash',
|
||
|
url:opt.flashUrl,
|
||
|
width:opt.width,
|
||
|
height:opt.height,
|
||
|
errorMessage:lang.flashError,
|
||
|
wmode:browser.safari ? 'transparent' : 'window',
|
||
|
ver:'10.0.0',
|
||
|
vars:opt,
|
||
|
container:opt.container
|
||
|
}
|
||
|
};
|
||
|
flashContainer = $G(opt.container);
|
||
|
option = utils.extend(option, callbacks, false);
|
||
|
flashObj = new baidu.flash.imageUploader(option);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 依据传入的align值更新按钮信息
|
||
|
* @param align
|
||
|
*/
|
||
|
function updateAlignButton(align) {
|
||
|
var aligns = g("remoteFloat").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 = "";
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 创建图片浮动选择按钮
|
||
|
* @param ids
|
||
|
*/
|
||
|
function createAlignButton(ids) {
|
||
|
for (var i = 0, ci; ci = ids[i++];) {
|
||
|
var floatContainer = g(ci),
|
||
|
nameMaps = {"none":lang.floatDefault, "left":lang.floatLeft, "right":lang.floatRight, "center":lang.floatCenter};
|
||
|
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);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function toggleFlash(show) {
|
||
|
if (flashContainer && browser.webkit) {
|
||
|
flashContainer.style.left = show ? "0" : "-10000px";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* tab点击处理事件
|
||
|
* @param tabHeads
|
||
|
* @param tabBodys
|
||
|
* @param obj
|
||
|
*/
|
||
|
function clickHandler(tabHeads, tabBodys, obj) {
|
||
|
//head样式更改
|
||
|
for (var k = 0, len = tabHeads.length; k < len; k++) {
|
||
|
tabHeads[k].className = "";
|
||
|
}
|
||
|
obj.className = "focus";
|
||
|
//body显隐
|
||
|
var tabSrc = obj.getAttribute("tabSrc");
|
||
|
for (var j = 0, length = tabBodys.length; j < length; j++) {
|
||
|
var body = tabBodys[j],
|
||
|
id = body.getAttribute("id");
|
||
|
body.onclick = function () {
|
||
|
this.style.zoom = 1;
|
||
|
};
|
||
|
if (id != tabSrc) {
|
||
|
body.style.zIndex = 1;
|
||
|
} else {
|
||
|
body.style.zIndex = 200;
|
||
|
//当切换到本地图片上传时,隐藏遮罩用的iframe
|
||
|
if (id == "local") {
|
||
|
toggleFlash(true);
|
||
|
maskIframe.style.display = "none";
|
||
|
//处理确定按钮的状态
|
||
|
if (selectedImageCount) {
|
||
|
dialog.buttons[0].setDisabled(true);
|
||
|
}
|
||
|
} else {
|
||
|
toggleFlash(false);
|
||
|
maskIframe.style.display = "";
|
||
|
dialog.buttons[0].setDisabled(false);
|
||
|
}
|
||
|
var list = g("imageList");
|
||
|
list.style.display = "none";
|
||
|
//切换到图片管理时,ajax请求后台图片列表
|
||
|
if (id == "imgManager") {
|
||
|
list.style.display = "";
|
||
|
//已经初始化过时不再重复提交请求
|
||
|
if (!list.children.length) {
|
||
|
ajax.request(editor.options.imageManagerUrl, {
|
||
|
timeout:100000,
|
||
|
action:"get",
|
||
|
onsuccess:function (xhr) {
|
||
|
//去除空格
|
||
|
var tmp = utils.trim(xhr.responseText),
|
||
|
imageUrls = !tmp ? [] : tmp.split("ue_separate_ue"),
|
||
|
length = imageUrls.length;
|
||
|
g("imageList").innerHTML = !length ? " " + lang.noUploadImage : "";
|
||
|
for (var k = 0, ci; ci = imageUrls[k++];) {
|
||
|
var img = document.createElement("img");
|
||
|
|
||
|
var div = document.createElement("div");
|
||
|
div.appendChild(img);
|
||
|
div.style.display = "none";
|
||
|
g("imageList").appendChild(div);
|
||
|
img.onclick = function () {
|
||
|
changeSelected(this);
|
||
|
};
|
||
|
img.onload = function () {
|
||
|
this.parentNode.style.display = "";
|
||
|
var w = this.width, h = this.height;
|
||
|
scale(this, 100, 120, 80);
|
||
|
this.title = lang.toggleSelect + w + "X" + h;
|
||
|
this.onload = null;
|
||
|
};
|
||
|
img.setAttribute(k < 35 ? "src" : "lazy_src", editor.options.imageManagerPath + ci.replace(/\s+|\s+/ig, ""));
|
||
|
img.setAttribute("_src", editor.options.imageManagerPath + ci.replace(/\s+|\s+/ig, ""));
|
||
|
|
||
|
}
|
||
|
},
|
||
|
onerror:function () {
|
||
|
g("imageList").innerHTML = lang.imageLoadError;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
if (id == "imgSearch") {
|
||
|
selectTxt(g("imgSearchTxt"));
|
||
|
}
|
||
|
if (id == "remote") {
|
||
|
$focus(g("url"));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* TAB切换
|
||
|
* @param tabParentId tab的父节点ID或者对象本身
|
||
|
*/
|
||
|
function switchTab(tabParentId) {
|
||
|
var tabElements = g(tabParentId).children,
|
||
|
tabHeads = tabElements[0].children,
|
||
|
tabBodys = tabElements[1].children;
|
||
|
|
||
|
for (var i = 0, length = tabHeads.length; i < length; i++) {
|
||
|
var head = tabHeads[i];
|
||
|
if (head.className === "focus")clickHandler(tabHeads, tabBodys, head);
|
||
|
head.onclick = function () {
|
||
|
clickHandler(tabHeads, tabBodys, this);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 改变o的选中状态
|
||
|
* @param o
|
||
|
*/
|
||
|
function changeSelected(o) {
|
||
|
if (o.getAttribute("selected")) {
|
||
|
o.removeAttribute("selected");
|
||
|
o.style.cssText = "filter:alpha(Opacity=100);-moz-opacity:1;opacity: 1;border: 2px solid #fff";
|
||
|
} else {
|
||
|
o.setAttribute("selected", "true");
|
||
|
o.style.cssText = "filter:alpha(Opacity=50);-moz-opacity:0.5;opacity: 0.5;border:2px solid blue;";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 选择切换,传入一个container的ID
|
||
|
* @param selectParentId
|
||
|
*/
|
||
|
function switchSelect(selectParentId) {
|
||
|
var select = g(selectParentId),
|
||
|
children = select.children;
|
||
|
domUtils.on(select, "click", function (evt) {
|
||
|
var tar = evt.srcElement || evt.target;
|
||
|
for (var j = 0, cj; cj = children[j++];) {
|
||
|
cj.className = "";
|
||
|
cj.removeAttribute && cj.removeAttribute("class");
|
||
|
}
|
||
|
tar.className = "focus";
|
||
|
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* gb2312编码
|
||
|
* @param str
|
||
|
*/
|
||
|
function encodeToGb2312(str) {
|
||
|
var strOut = "";
|
||
|
for (var i = 0; i < str.length; i++) {
|
||
|
var c = str.charAt(i),
|
||
|
code = str.charCodeAt(i);
|
||
|
if (c == " ") strOut += "+";
|
||
|
else if (code >= 19968 && code <= 40869) {
|
||
|
var index = code - 19968;
|
||
|
strOut += "%" + z.substr(index * 4, 2) + "%" + z.substr(index * 4 + 2, 2);
|
||
|
} else {
|
||
|
strOut += "%" + str.charCodeAt(i).toString(16);
|
||
|
}
|
||
|
}
|
||
|
return strOut;
|
||
|
}
|
||
|
|
||
|
var z = 'D2BBB6A18140C6DF814181428143CDF2D5C9C8FDC9CFCFC2D8A2B2BBD3EB8144D8A4B3F38145D7A8C7D2D8A7CAC08146C7F0B1FBD2B5B4D4B6ABCBBFD8A9814781488149B6AA814AC1BDD1CF814BC9A5D8AD814CB8F6D1BEE3DCD6D0814D814EB7E1814FB4AE8150C1D98151D8BC8152CDE8B5A4CEAAD6F78153C0F6BED9D8AF815481558156C4CB8157BEC38158D8B1C3B4D2E58159D6AECEDAD5A7BAF5B7A6C0D6815AC6B9C5D2C7C7815BB9D4815CB3CBD2D2815D815ED8BFBEC5C6F2D2B2CFB0CFE7815F816081618162CAE981638164D8C081658166816781688169816AC2F2C2D2816BC8E9816C816D816E816F817081718172817381748175C7AC8176817781788179817A817B817CC1CB817DD3E8D5F9817ECAC2B6FED8A1D3DABFF78180D4C6BBA5D8C1CEE5BEAE81818182D8A88183D1C7D0A9818481858186D8BDD9EFCDF6BFBA8187BDBBBAA5D2E0B2FABAE0C4B68188CFEDBEA9CDA4C1C18189818A818BC7D7D9F1818CD9F4818D818E818F8190C8CBD8E9819181928193D2DACAB2C8CAD8ECD8EAD8C6BDF6C6CDB3F08194D8EBBDF1BDE98195C8D4B4D381968197C2D88198B2D6D7D0CACBCBFBD5CCB8B6CFC98199819A819BD9DAD8F0C7AA819CD8EE819DB4FAC1EED2D4819E819FD8ED81A0D2C7D8EFC3C781A181A281A3D1F681A4D6D9D8F281A5D8F5BCFEBCDB81A681A781A8C8CE81A9B7DD81AAB7C281ABC6F381AC81AD81AE81AF81B081B181B2D8F8D2C181B381B4CEE9BCBFB7FCB7A5D0DD81B581B681B781B881B9D6DAD3C5BBEFBBE1D8F181BA81BBC9A1CEB0B4AB81BCD8F381BDC9CBD8F6C2D7D8F781BE81BFCEB1D8F981C081C181C2B2AEB9C081C3D9A381C4B0E981C5C1E681C6C9EC81C7CBC581C8CBC6D9A481C981CA81CB81CC81CDB5E881CE81CFB5AB81D081D181D281D381D481D5CEBBB5CDD7A1D7F4D3D381D6CCE581D7BACE81D8D9A2D9DCD3E0D8FDB7F0D7F7D8FED8FAD9A1C4E381D981DAD3B6D8F4D9DD81DBD8FB81DCC5E581DD81DEC0D081DF81E0D1F0B0DB81E181E2BCD1D9A681E3D9A581E481E581E681E7D9ACD9AE81E8D9ABCAB981E981EA81EBD9A9D6B681EC81ED81EEB3DED9A881EFC0FD81F0CACC81F1D9AA81F2D9A781F381F4D9B081F581F6B6B181F781F881F9B9A981FAD2C081FB81FCCFC081FD81FEC2C28240BDC4D5ECB2E0C7C8BFEBD9AD8241D9AF8242CEEABAEE82438244824582468247C7D682488249824A824B824C824D824E824F8250B1E3825182528253B4D9B6EDD9B48254825582568257BFA182588259825AD9DEC7CEC0FED9B8825B825C825D825E825FCBD7B7FD8260D9B58261D9B7B1A3D3E1D9B98262D0C58263D9B682648265D9B18266D9B2C1A9D9B382678268BCF3D0DEB8A98269BEE3826AD9BD826B826C826D826ED9BA826FB0B3827082718272D9C28273827482758276827782788279827A827B827C827D827E8280D9C4B1B68281D9BF82828283B5B98284BEF3828582868287CCC8BAF2D2D08288D9C38289828ABDE8828BB3AB828C828D828ED9C5BEEB828FD9C6D9BBC4DF8290D9BED9C1D9C0829182928293829482958296829782988299829A829BD5AE829CD6B5829DC7E3829E829F82A082A1D9C882A282A382A4BCD9D9CA82A582A682A7D9BC82A8D9CBC6AB82A982AA82AB82AC82ADD9C982AE82AF82B082B1D7F682B2CDA382B382B482B582B682B782B882B982BABDA182BB82BC82BD82BE82BF82C0D9CC82C182C282C382C482C582C682C782C882C9C5BCCDB582CA82CB82CCD9CD82CD82CED9C7B3A5BFFE82CF82D082D182D2B8B582D382D4C0FC82D582D682D782D8B0F882D982DA82DB82DC82DD82DE82DF82E082E182E282E382E482E582E682E782E882E982EA82EB82EC82EDB4F682EED9CE82EFD9CFB4A2D9D082F082F1B4DF82F282F382F482F582F6B0C182F782F882F982FA82FB82FC82FDD9D1C9B582FE8340834183428343834483458346834783488349834A834B834C834D834E834F83508351CFF1835283538354835583568357D9D283588359835AC1C5835B835C835D835E835F836083618362836383648365D9D6C9AE8366836783688369D9D5D9D4D9D7836A836B836C836DCBDB836EBDA9836F8370837183728373C6A7837483758376837783788379837A837B837C837DD9D3D9D8837E83808381D9D9838283838384838583868387C8E583888389838A838B838C838D838E838F839083918392839383948395C0DC8396839783988399839A839B839C839D839E839F83A083A183A283A383A483A583A683A783A883A983AA83AB83AC83AD83AE83AF83B083B183B2B6F9D8A3D4CA83B3D4AAD0D6B3E4D5D783B4CFC8B9E283B5BFCB83B6C3E283B783B883B9B6D283BA83BBCDC3D9EED9F083BC83BD83BEB5B383BFB6B583C083C183C283C383C4BEA483C583C6C8EB83C783C8C8AB83C983CAB0CBB9ABC1F9D9E283CBC0BCB9B283CCB9D8D0CBB1F8C6E4BEDFB5E4D7C883CDD1F8BCE6CADE83CE83CFBCBDD9E6D8E783D083D1C4DA83D283D3B8D4C8BD83D483D5B2E1D4D983D683D783D883D9C3B083DA83DBC3E1DAA2C8DF83DCD0B483DDBEFCC5A983DE83DF83E0B9DA83E1DAA383E2D4A9DAA483E383E483E583E683E7D9FBB6AC83E883E9B7EBB1F9D9FCB3E5BEF683EABFF6D2B1C0E483EB83EC83EDB6B3D9FED9FD83EE83EFBEBB83F083F183F2C6E083F3D7BCDAA183F4C1B983F5B5F2C1E883F683F7BCF583F8B4D583F983FA83FB83FC83FD83FE844084418442C1DD8443C4FD84448445BCB8B7B284468447B7EF84488449844A844B844C844DD9EC844EC6BE844FBFADBBCB84508451B5CA8452DBC9D0D78453CDB9B0BCB3F6BBF7DB
|
||
|
})();
|