首页 > 其他分享 >ueditor 上传图片去掉高度属性方法

ueditor 上传图片去掉高度属性方法

时间:2023-03-05 17:04:34浏览次数:39  
标签:ueditor ci img value height width var 去掉 上传


在下面代码中 查找 setsize 参数即可

将 height 属性默认添加改为自定义是否添加,勾选设置图高单选框才添加

image.html

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>ueditor图片对话框</title>
<script type="text/javascript" src="../internal.js"></script>

<!-- jquery -->
<script type="text/javascript" src="../../third-party/jquery-1.10.2.min.js"></script>

<!-- webuploader -->
<script src="../../third-party/webuploader/webuploader.min.js"></script>
<link rel="stylesheet" type="text/css" href="../../third-party/webuploader/webuploader.css">

<!-- image dialog -->
<link rel="stylesheet" href="image.css" type="text/css" />
</head>
<body>

<div class="wrapper">
<div id="tabhead" class="tabhead">
<span class="tab" data-content-id="remote"><var id="lang_tab_remote"></var></span>
<span class="tab focus" data-content-id="upload"><var id="lang_tab_upload"></var></span>
<!--<span class="tab" data-content-id="online"><var id="lang_tab_online"></var></span>
<span class="tab" data-content-id="search"><var id="lang_tab_search"></var></span>-->
</div>
<div class="alignBar">
<label class="algnLabel"><var id="lang_input_align"></var></label>
<span id="alignIcon">
<span id="noneAlign" class="none-align focus" data-align="none"></span>
<span id="leftAlign" class="left-align" data-align="left"></span>
<span id="rightAlign" class="right-align" data-align="right"></span>
<span id="centerAlign" class="center-align" data-align="center"></span>
</span>
<input id="align" name="align" type="hidden" value="none"/>
</div>
<div id="tabbody" class="tabbody">

<!-- 远程图片 -->
<div id="remote" class="panel">
<div class="top">
<div class="row">
<label for="url"><var id="lang_input_url"></var></label>
<span><input class="text" id="url" disabled="disabled" type="text"/></span>
</div>
</div>
<div class="left">
<div class="row">
<label><var id="lang_input_size"></var></label>
<span><var id="lang_input_width">  </var><input class="text" type="text" id="width"/>px </span>
<span><var id="lang_input_height">  </var><input class="text" type="text" id="height"/>px </span>
<span><input id="lock" type="checkbox" checked="checked" ><span id="lockicon"></span></span>
</div>
<div class="row">
<label><var id="lang_input_border"></var></label>
<span><input class="text" type="text" id="border"/>px </span>
</div>
<div class="row">
<label><var id="lang_input_vhspace"></var></label>
<span><input class="text" type="text" id="vhSpace"/>px </span>
</div>
<div class="row">
<label><var id="lang_input_title"></var></label>
<span><input class="text" type="text" id="title"/></span>
</div>
<div class="row">
<label><var id="lang_show_caption"></var></label>
<span><input type="checkbox" id="showCaption" checked="checked" value="1"/></span>
</div>
<div class="row">
<label><var id="lang_show_setsize">设置图高</var></label>
<span><input type="checkbox" id="setsize" value="0"/></span>
</div>
<span><input type="text" style="display:none" id="height_judge" value="" /></span>
</div>
<div class="right"><div class="text" id="preview"></div></div>
</div>

<!-- 上传图片 -->
<div id="upload" class="panel focus">
<div id="queueList" class="queueList">
<div class="statusBar element-invisible">
<div class="progress">
<span class="text">0%</span>
<span class="percentage"></span>
</div><div class="info"></div>
<div class="btns">
<div id="filePickerBtn"></div>
<div class="uploadBtn"><var id="lang_start_upload"></var></div>
</div>
</div>
<div id="dndArea" class="placeholder">
<div class="filePickerContainer">
<div id="filePickerReady"></div>
</div>
</div>
<ul class="filelist element-invisible">
<li id="filePickerBlock" class="filePickerBlock"></li>
</ul>
</div>
</div>

<!-- 在线图片 -->
<div id="online" class="panel">
<div id="imageList"><var id="lang_imgLoading"></var></div>
</div>

<!-- 搜索图片 -->
<div id="search" class="panel">
<div class="searchBar">
<input id="searchTxt" class="searchTxt text" type="text" />
<select id="searchType" class="searchType">
<option value="&s=4&z=0"></option>
<option value="&s=1&z=19"></option>
<option value="&s=2&z=0"></option>
<option value="&s=3&z=0"></option>
</select>
<input id="searchReset" type="button" />
<input id="searchBtn" type="button" />
</div>
<div id="searchList" class="searchList"><ul id="searchListUl"></ul></div>
</div>

</div>
</div>
<script type="text/javascript" src="image.js"></script>
<script>
$(window).load(function(){
var judge = document.getElementById("height_judge").value;
var setsize = document.getElementById("setsize");
if(judge) {
setsize.setAttribute("checked","checked");
setsize.value="1";
}
});
</script>
</body>
</html>

ueditor.all.js

UE.commands['insertimage'] = {
execCommand:function (cmd, opt) {

opt = utils.isArray(opt) ? opt : [opt];
if (!opt.length) {
return;
}
var me = this,
range = me.selection.getRange(),
img = range.getClosedNode();

if(me.fireEvent('beforeinsertimage', opt) === true){
return;
}

if (img && /img/i.test(img.tagName) && (img.className != "edui-faked-video" || img.className.indexOf("edui-upload-video")!=-1) && !img.getAttribute("word_img")) {
var first = opt.shift();
var floatStyle = first['floatStyle'];
var showCaption = first['showCaption'];
var setsize = first['setsize'];
if (setsize == 1) {
var height = first['height'];
var height1 = first['style.height'];
}
delete first['floatStyle'];
img.style.border = (first.border||0) +"px solid #000";
//// img.style.margin = (first.margin||0) +"px";
// img.style.cssText += ';margin:' + (first.margin||0) +"px;" + 'border:' + (first.border||0) +"px solid #000";
delete first['showCaption'];
delete first['setsize'];
domUtils.setAttributes(img, first);

common = range.getCommonAncestor();
//console.log(common);
var childs = domUtils.getElementsByTagName(common,'span');
if (childs.length > 0) {
console.log(childs[0]);
domUtils.remove(childs[0]);
}

if(setsize == 0) {
var childsimg = domUtils.getElementsByTagName(common,'img');
if (childsimg[0]['height'] > 0) {
domUtils.removeAttributes( childsimg[0], 'height' );
}
if (childsimg[0]['style']['height']) {
domUtils.removeStyle(childsimg[0],'height');
}
}

if (showCaption == 1) {
var tempTitle = range.document.createElement('span');
domUtils.setAttributes(tempTitle, {'class':'m-pic-article'});
tempTitle.innerHTML = first.title;
range.setCursor('toEnd');
range.insertNode(tempTitle);
}

me.execCommand('imagefloat', floatStyle);
if (opt.length > 0) {
range.setStartAfter(img).setCursor(false, true);
me.execCommand('insertimage', opt);
}

} else {
var html = [], str = '', ci;
ci = opt[0];
if (opt.length == 1) {
str = '<img src="' + ci.src + '" ' + (ci._src ? ' _src="' + ci._src + '" ' : '') +
(ci.width ? 'width="' + ci.width + '" ' : '') +
(ci.height ? ' height="' + ci.height + '" ' : '') +
(ci['floatStyle'] == 'left' || ci['floatStyle'] == 'right' ? ' style="float:' + ci['floatStyle'] + ';"' : '') +
(ci.title && ci.title != "" ? ' title="' + ci.title + '"' : '') +
(ci.border && ci.border != "0" ? ' border="' + ci.border + '"' : '') +
(ci.alt && ci.alt != "" ? ' alt="' + ci.alt + '"' : '') +
(ci.hspace && ci.hspace != "0" ? ' hspace = "' + ci.hspace + '"' : '') +
(ci.vspace && ci.vspace != "0" ? ' vspace = "' + ci.vspace + '"' : '') + '/>';
if (ci['floatStyle'] == 'center') {
str = '<p style="text-align: center">' + str + '</p>';
}
html.push(str);

} else {
for (var i = 0; ci = opt[i++];) {
str = '<p ' + (ci['floatStyle'] == 'center' ? 'style="text-align: center" ' : '') + '><img src="' + ci.src + '" ' +
(ci.width ? 'width="' + ci.width + '" ' : '') + (ci._src ? ' _src="' + ci._src + '" ' : '') +
(ci.height ? ' height="' + ci.height + '" ' : '') +
' style="' + (ci['floatStyle'] && ci['floatStyle'] != 'center' ? 'float:' + ci['floatStyle'] + ';' : '') +
(ci.border || '') + '" ' +
(ci.title ? ' title="' + ci.title + '"' : '') + ' /></p>';
html.push(str);
}
}

me.execCommand('insertHtml', html.join(''));
}

me.fireEvent('afterinsertimage', opt)
}
};

image.js

/* 初始化onok事件 */
function initButtons() {

dialog.onok = function () {
var remote = false, list = [], id, tabs = $G('tabhead').children;
for (var i = 0; i < tabs.length; i++) {
if (domUtils.hasClass(tabs[i], 'focus')) {
id = tabs[i].getAttribute('data-content-id');
break;
}
}

switch (id) {
case 'remote':
list = remoteImage.getInsertList();
break;
case 'upload':
list = uploadImage.getInsertList();
var count = uploadImage.getQueueCount();
if (count) {
$('.info', '#queueList').html('<span style="color:red;">' + '还有2个未上传文件'.replace(/[\d]/, count) + '</span>');
return false;
}
break;
case 'online':
list = onlineImage.getInsertList();
break;
case 'search':
list = searchImage.getInsertList();
remote = true;
break;
}

if(list) {
editor.execCommand('insertimage', list);
remote && editor.fireEvent("catchRemoteImage");
}
};
}


/* 初始化对其方式的点击事件 */
function initAlign(){
/* 点击align图标 */
domUtils.on($G("alignIcon"), 'click', function(e){
var target = e.target || e.srcElement;
if(target.className && target.className.indexOf('-align') != -1) {
setAlign(target.getAttribute('data-align'));
}
});
}

/* 设置对齐方式 */
function setAlign(align){
align = align || 'none';
var aligns = $G("alignIcon").children;
for(i = 0; i < aligns.length; i++){
if(aligns[i].getAttribute('data-align') == align) {
domUtils.addClass(aligns[i], 'focus');
$G("align").value = aligns[i].getAttribute('data-align');
} else {
domUtils.removeClasses(aligns[i], 'focus');
}
}
}
/* 获取对齐方式 */
function getAlign(){
var align = $G("align").value || 'none';
return align == 'none' ? '':align;
}


/* 在线图片 */
function RemoteImage(target) {
this.container = utils.isString(target) ? document.getElementById(target) : target;
this.init();
}
RemoteImage.prototype = {
init: function () {
this.initContainer();
this.initEvents();
},
initContainer: function () {
this.dom = {
'url': $G('url'),
'width': $G('width'),
'height': $G('height'),
'border': $G('border'),
'vhSpace': $G('vhSpace'),
'title': $G('title'),
'align': $G('align'),
'showCaption': $G('showCaption'),
'setsize' : $G('setsize')
};
var img = editor.selection.getRange().getClosedNode();
if (img) {
this.setImage(img);
}
},
initEvents: function () {
var _this = this,
locker = $G('lock');
showCaption = $G('showCaption');
setsize = $G('setsize');

//console.log($G('showCaption'));

/* 改变url */
domUtils.on($G("url"), 'keyup', updatePreview);
domUtils.on($G("border"), 'keyup', updatePreview);
domUtils.on($G("title"), 'keyup', updatePreview);

domUtils.on($G("width"), 'keyup', function(){
updatePreview();
if(locker.checked) {
var proportion =locker.getAttribute('data-proportion');
$G('height').value = Math.round(this.value / proportion);
} else {
_this.updateLocker();
}
});
domUtils.on($G("height"), 'keyup', function(){
updatePreview();
if(locker.checked) {
var proportion =locker.getAttribute('data-proportion');
$G('width').value = Math.round(this.value * proportion);
} else {
_this.updateLocker();
}
});
domUtils.on($G("lock"), 'change', function(){
var proportion = parseInt($G("width").value) /parseInt($G("height").value);
locker.setAttribute('data-proportion', proportion);
});

domUtils.on($G('showCaption'), 'change', function(){
if (showCaption.checked) {
$G('showCaption').value = 1;
} else {
$G('showCaption').value = 0;
}
});

domUtils.on($G('setsize'), 'change', function(){
if ($G('setsize').checked) {
$G('setsize').value = 1;
} else {
$G('setsize').value = 0;
}

});

function updatePreview(){
_this.setPreview();
}
},
updateLocker: function(){
var width = $G('width').value,
height = $G('height').value,
locker = $G('lock');

if(width && height && width == parseInt(width) && height == parseInt(height)) {
locker.disabled = false;
locker.title = '';
} else {
locker.checked = false;
locker.disabled = 'disabled';
locker.title = lang.remoteLockError;
}
},
setImage: function(img){
/* 不是正常的图片 */
if (!img.tagName || img.tagName.toLowerCase() != 'img' && !img.getAttribute("src") || !img.src) return;

var wordImgFlag = img.getAttribute("word_img"),
src = wordImgFlag ? wordImgFlag.replace("&", "&") : (img.getAttribute('_src') || img.getAttribute("src", 2).replace("&", "&")),
align = editor.queryCommandValue("imageFloat");

/* 防止onchange事件循环调用 */
if (src !== $G("url").value) $G("url").value = src;
if(src) {
/* 设置表单内容 */
$G("width").value = img.width || '';
$G("height").value = img.height || '';
$G("border").value = img.getAttribute("border") || '0';
$G("vhSpace").value = img.getAttribute("vspace") || '0';
$G("title").value = img.title || img.alt || '';
if(img.getAttribute('height')) {
$G("height_judge").value = img.getAttribute('height');
}
setAlign(align);
this.setPreview();
this.updateLocker();
}
},
getData: function(){
var data = {};
for(var k in this.dom){
data[k] = this.dom[k].value;
}
return data;
},
setPreview: function(){
var url = $G('url').value,
ow = $G('width').value,
oh = $G('height').value,
border = $G('border').value,
title = $G('title').value,
preview = $G('preview'),
width,
height;
//setsize;

width = ((!ow || !oh) ? preview.offsetWidth:Math.min(ow, preview.offsetWidth));
width = width+(border*2) > preview.offsetWidth ? width:(preview.offsetWidth - (border*2));
height = (!ow || !oh) ? '':width*oh/ow;

if(url) {
preview.innerHTML = '<img src="' + url + '" width="' + width + '" height="' + height + '" border="' + border + 'px solid #000" title="' + title + '" />';
}
},
getInsertList: function () {
var data = this.getData();
//console.log(data);
if(data['url']) {
return [{
src: data['url'],
_src: data['url'],
width: data['width'] || '',
height: data['height'] || '',
border: data['border'] || '',
floatStyle: data['align'] || '',
vspace: data['vhSpace'] || '',
title: data['title'] || '',
alt: data['title'] || '',
showCaption: data['showCaption'] || '',
setsize: data['setsize'] || '',
//控制图片style
style: "width:" + data['width'] + "px;height:" + data['height'] + "px;"
}];
} else {
return [];
}


}
}


标签:ueditor,ci,img,value,height,width,var,去掉,上传
From: https://blog.51cto.com/sdwml/6101528

相关文章

  • DVWA 之 File Upload-文件上传
    五、FileUpload-文件上传文件上传漏洞,通常是由于对上传文件的类型、内容没有进行严格的过滤、检查,使得攻击者可以通过上传木马获取服务器的webshell权限,因此文件上传漏洞......
  • SpringMVC:文件上传下载如何实现?
      一、文件下载如果在响应时候没有设置响应头中的Content-Disposition属性,则会使用默认值inline,此时客户端访问静态资源的时候,能解析显示的就会解析显示,不能解析......
  • docker搭建maven私服(nexus3),整合springboot上传下载依赖
    一、前言我们在JavaWeb开发中必不可少的就是jar包管理-maven,在没有maven之前,都是自己手动下载jar包导入到项目中,非常的繁琐。maven出现之后,又迎来新的问题,对于仓库里人家......
  • 图片和base64有什么关系啊,上传图片要转?什么时候转?
    图片的base64编码主要是为了用在网页上减少请求次数我们都知道,我们的网站采用的都是http协议,而http协议是一种无状态的连接,就是连接和传输后都会断开连接节省资源。此时解......
  • 【Android】如何去掉默认标题栏
      1、在AndroidManifest.xml文件中修改并添加以下代码android:theme="@style/Theme.AppCompat.NoActionBar"2、在你想要去掉标题栏的页面Java文件添加相应代码(注......
  • 使用element-ui+vue2实现oss直传上传图片
    <template><div><el-upload:action="dataObj.host":data="dataObj"list-type="picture":multiple="false":show-file-list="showFile......
  • php上传文件
    下面的代码放在一个名为UploadFile.class.php文件内<?phpclassUploadFile{private$max_size='2000000';//设置上传文件的大小,此为2Mprivate$rand_......
  • 一文网尽关于大文件(分片)上传你需要知道的所有前置知识点
    分片上传知识点一.XMLHttpRequest.uploadXMLHttpRequest.upload属性返回一个XMLHttpRequestUpload对象,用来表示上传的进度。这个对象是不透明的,但是作为一个XMLHttpRe......
  • SiteFactory支持Word图文自动上传
    ​ ueditor粘贴不能粘贴word中的图片是一个很头疼的问题,在我们的业务场景中客户要求必须使用ueditor并且支持word的图片粘贴,因为这个需求头疼了半个月,因为前端方面因为安......
  • (typora)markdown文件 上传博客园流程
    1、电脑左下角,搜索cmd,打开cmd,管理员方式运行2、输入dotnet-cnblog,回车3、复制需要上传的markdown文件所在的文件夹位置3、在cmd输入cd/d(粘贴位置),回车4、复制dotne......