| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965 |
- window.growHeightList = window.growHeightList || {};
- function getGrowHeight(id, maxHeight, buttons, type, acceptEnter) {
- var gh = growHeightList[id];
- if (!gh) {
- if (maxHeight != null) {
- gh = new GrowHeight(id, maxHeight, buttons, type, acceptEnter);
- } else {
- console.info("找不到GrowHeight:" + id);
- }
- }
- return gh;
- }
- var GrowHeight = GrowHeight = function (id, maxHeight, buttons, type, acceptEnter) {
- var ele = document.getElementById(id);
- if (ele) {
- this.showPadding = 0;
- this.name = id;
- this.id = id;
- this.maxHeight = parseFloat(maxHeight) || 300;
- this.type = type;
- this.acceptEnter = new Boolean(acceptEnter) == true;
- this.srcElement = ele;
- this.fj = buttons.fj;
- this.init();
- window.growHeightList[id] = this;
- } else {
- console.log("找不到元素:" + id);
- }
- }
- GrowHeight.prototype.getName = function () {
- return this.name;
- }
- GrowHeight.prototype.val = function (value) {
- if (this.container.tagName.toLowerCase() == "textarea") {
- if (arguments.length == 0) {
- value = this.input.value;
- } else {
- this.container.value = value;
- this.onInput();
- }
- } else {
- if (arguments.length == 0) {
- value = this.input.value;
- } else {
- this.container.innerHTML = value;
- this.onInput();
- }
- }
- if (this.isFocus != true) {
- this.container.initDot && this.container.initDot();
- }
- return value;
- }
- GrowHeight.prototype.setOnInput = function (callback) {
- this.onInputCallback = callback;
- }
- GrowHeight.prototype.setOnfocus = function (callback) {
- this.onFocusCallback = callback;
- }
- GrowHeight.prototype.setOnblur = function (callback) {
- this.onBlurCallback = callback;
- }
- GrowHeight.prototype.show = function () {
- if (this.shadow)
- return;
- //缓存旧数据
- var ori = this.oriInfo = {
- wrapper: this.wrapper.style.cssText,
- container: this.container.style.cssText,
- parent_: this.wrapper.parentNode.style.cssText
- };
- var e = $HIDDENOVERFLOW(this.wrapper);
- var eb = e.getBoundingClientRect();
- var pB = this.wrapper.parentNode.getBoundingClientRect();
- var bound = this.wrapper.getBoundingClientRect();
- //创建站位空格
- var shadow = this.shadow = this.wrapper.cloneNode();
- shadow.id = "shadow_" + (this.wrapper.name || this.wrapper.id || "");
- shadow.name = "";
- shadow.style.display="inline-block";
- shadow.style.overflowY = "hidden";
- shadow.style.visibility = "hidden";
- var csstxt = this.wrapper.style.cssText;
- var csss=csstxt.split(";");
- var hasCssWidth=false,hasCssHeight=false;
- for (var ci=0;ci<csss.length;ci++){
- if(csss[ci].startsWith("width:")){
- hasCssWidth=true;
- }else if(csss[ci].startsWith("height:")){
- hasCssHeight=true;
- }
- }
- if (!hasCssWidth) {
- $(shadow).css("width", $W(this.wrapper));
- }
- if (!hasCssHeight) {
- $(shadow).css("height", $H(this.wrapper));
- }
- // var w = this.wrapper.style.width,
- // h = this.wrapper.style.height;
- // if (w == "" || !w.startsWith("calc")) {
- // w = $W(this.wrapper) + "px";
- // }
- // if (h == "" || !h.startsWith("calc")) {
- // h = $H(this.wrapper) + "px";
- // }
- // console.log(w, h);
- // $(shadow).css({
- // width: w,
- // height: h
- // })
- // shadow.style.display = "inline-block";
- //先浮出来以免影响坐标计算
- this.wrapper.parentNode.style.position = "relative";
- this.wrapper.style.position = "absolute";
- this.wrapper.parentNode.insertBefore(shadow, this.wrapper.nextSibling);
- $(this.wrapper).addClass("input-div-selected");
- // this.wrapper.style.overflow = "hidden";
- this.wrapper.style.width = bound.width + "px";
- this.wrapper.style.height = "unset";
- // var height_ = $REALHEIGHT(this.wrapper);
- var marginTop=parseInt($(this.wrapper).css("margin-top"))||0;
- var marginBottom=parseInt($(this.wrapper).css("margin-bottom"))||0;
- this.wrapper.style.background = "white";
- this.wrapper.style.left = bound.left - pB.left - $ML(this.wrapper) - 1 + "px";
- this.wrapper.style.zIndex = 1;
- //判断够不够位置,调整最大高度
- var maxHeight_ = this.maxHeight;
- if (bound.top + maxHeight_ < eb.bottom) {
- this.wrapper.style.top = bound.top - pB.top - 1-marginTop + "px";
- this.wrapper.style.bottom = "";
- } else { //如果向下不够位置展开,尝试向上,并且判断尽可能的放大
- //如果向上高度大于向下高度
- var b_ = eb.bottom - bound.bottom; //底部距离
- var t_ = bound.top - eb.top; //顶部距离
- maxHeight_ = Math.min(Math.max(b_, t_) + bound.height - $PB(this.wrapper) - $PT(this.wrapper), maxHeight_);
- this.wrapper.style.bottom = pB.bottom - bound.bottom - $MB(this.wrapper)-marginBottom + "px";
- this.wrapper.style.top = "";
- }
- this.wrapper.style.maxHeight = maxHeight_ + "px";
- this.updateWrapperPosition();
- this.updateContainerHeight();
- if (this.cmsBtn) {
- this.cmsBtn.updateButtonSize();
- }
- loadSmallScorll($(this.wrapper).find(".smallScrollbar"));
- }
- GrowHeight.prototype.updateWrapperPosition = function () {
- if (this.shadow) {
- var s = this.shadow.getBoundingClientRect(),
- w = this.wrapper.getBoundingClientRect(),
- wb = parseFloat(this.wrapper.style.bottom),
- wt = parseFloat(this.wrapper.style.top),
- left = parseFloat(this.wrapper.style.left);
- this.wrapper.style.left = left + s.left - w.left + "px";
- }
- }
- GrowHeight.prototype.updateContainerHeight = function () {
- var h = $minHeight100(this.container);
- if (this.shadow) { //
- var pd = this.showPadding;
- if (pd > 0) {
- this.wrapper.style.left = parseFloat(this.wrapper.style.left) - pd + "px"; //x左移
- this.wrapper.style.width = $REALWIDTH(this.shadow) + pd * 2 + "px"; //y右移
- this.wrapper.style.padding = pd + "px";
- var b = this.wrapper.style.bottom;
- if (b != "") {
- this.wrapper.style.bottom = parseFloat(b) - pd + "px";
- } else {
- b = this.wrapper.style.top;
- this.wrapper.style.top = parseFloat(b) - pd + "px";
- }
- var maxH = $MAH(this.wrapper) /* this.maxHeight */ + pd;
- // var se=$HIDDENOVERFLOW(this.wrapper);
- //计算maxheight
- this.wrapper.style.maxHeight = maxH + "px";
- }
- this.container.style.height = h + "px";
- var sh = this.container.scrollHeight,
- mh = $MAH(this.wrapper) - ($ISBOX(this.wrapper) ? ($PT(this.wrapper) + $PB(this.wrapper)) : 0);
- h = Math.min(sh, mh);
- this.container.style.overflow = "hidden";
- this.container.scrollTop = this.lastScrollTop;
- } else {}
- this.container.style.height = h + "px";
- }
- GrowHeight.prototype.hide = function () {
- $(this.wrapper).removeClass("input-div-selected");
- $(this.wrapper).addClass("input-s");
- $(this.wrapper).find(".smallScrollbar").getNiceScroll().remove();
- if (this.shadow) {
- if (this.shadow.parentNode != this.wrapper.parentNode)
- this.shadow.parentNode.insertBefore(this.wrapper, this.shadow);
- this.shadow.parentNode.removeChild(this.shadow);
- this.shadow = null;
- }
- var ori = this.oriInfo;
- if (ori) {
- this.wrapper.style.cssText = ori.wrapper;
- this.container.style.cssText = ori.container;
- this.wrapper.parentNode.style.cssText = ori.parent_;
- this.oriInfo = null;
- }
- if (this.cmsBtn) {
- //更新CMS按钮的位置
- this.cmsBtn.updateButtonSize();
- }
- }
- GrowHeight.prototype.initAsDiv = function () {
- if (this.inited === true)
- return;
- function _focus() {
- this.GrowHeight.show();
- this.focus();
- this.addEventListener("blur", _blur);
- this.GrowHeight.onFocus();
- // this.innerHTML = this.GrowHeight.input.value;
- }
- function _blur() {
- this.GrowHeight.hide();
- this.removeEventListener("blur", _blur);
- this.GrowHeight.onBlur();
- this.GrowHeight.updateInputValue();
- }
- // this.onInputCallback = function (container) {
- // this.updateInputValue();
- // }
- var onDivInput = function (e) {
- if (!this.GrowHeight.acceptEnter) {
- var et = e || window.event;
- var keycode = et.charCode || et.keyCode;
- if (keycode == 13) {
- if (window.event) {
- window.event.returnValue = false;
- } else {
- e.preventDefault(); //for firefox
- }
- return;
- }
- }
- this.GrowHeight.onInput();
- }
- this.initDot = null;
- this.container = this.srcElement;
- this.container.style.height = $height100(this.container) + "px";
- this.container.style.overflow = "hidden";
- this.container.setAttribute("contenteditable", "true");
- this.container.addEventListener("focus", _focus);
- var inputEventNames = ["input", "propertychange", "keydown", "keyup", "DOMSubtreeModified"];
- for (var iiii = 0; iiii < inputEventNames.length; iiii++) {
- this.container.addEventListener(inputEventNames[iiii], onDivInput);
- }
- this.input = document.createElement("textarea");
- this.input.style.display = "none";
- this.input.name = this.id;
- this.container.parentNode.appendChild(this.input);
- }
- GrowHeight.prototype.initPlay = function () {
- if (this.inited === true)
- return;
- this.showPadding = 6;
- function onmouseenter() {
- this.GrowHeight.val(this.GrowHeight.srcText);
- this.GrowHeight.show();
- this.oriResize = this.style.resize;
- if (this.GrowHeight.cmsBtn)
- this.GrowHeight.cmsBtn.updateButtonSize();
- this.addEventListener("mouseleave", onmouseleave);
- }
- function onmouseleave(event) {
- if (this.clicked || (event.ctrlKey && event.altKey))
- return;
- this.style.resize = this.oriResize || "";
- this.GrowHeight.val(this.GrowHeight.viewText);
- this.removeEventListener("mouseleave", onmouseleave);
- this.GrowHeight.hide();
- }
- function onclick_() {
- this.clicked = !(this.clicked || false);
- if (this.clicked) {
- this.oriOutline = this.style.outline;
- this.oriResize = this.style.resize;
- this.style.outline = "1px blue auto";
- this.style.resize = "both";
- this.GrowHeight.onFocus();
- } else {
- this.style.outline = this.oriOutline;
- this.style.resize = this.oriResize;
- this.GrowHeight.onBlur();
- }
- }
- this.container = this.srcElement;
- // this.container.initDot = function () {
- // this.innerText = this.GrowHeight.srcText;
- // this.GrowHeight.viewText = wd.display.ellipsisContent(this, $maxHeight100(this));
- // }
- this.container.style.minHeight = this.minHeight + "px";
- //....
- this.srcText = this.container.innerText;
- // this.innerHTML = "";
- var ses = this.srcElement.style;
- var od = {
- wrapper: this.wrapper.style.cssText,
- container: this.container.style.cssText
- };
- var initHeight = $maxHeight100(this.container)
- //平铺开,强制换行
- // ses.visibility = "hidden";
- // ses.height = "";
- ses.wordBreak = "break-all";
- ses.wordWrap = "break-word";
- //弄成最大宽度,若么有,忽略
- this.wrapper.style.width = $MAWS(this.srcElement, 0) + "px";
- ses.width = $W(this.wrapper);
- var th = $MIH(this.container) || this.minHeight,
- h = $H(this.container);
- if (h > th) {
- var lh = $LH(this.container);
- if (lh > th) {
- console.info("注意,行高已经超过元素高度,导致元素被撑大")
- }
- // this.container.initDot();
- this.container.innerText = this.srcText;
- this.viewText = wd.display.ellipsisContent(this.container, initHeight);
- this.wrapper.addEventListener("mouseenter", onmouseenter);
- this.wrapper.addEventListener("dblclick", onclick_)
- }
- this.wrapper.style.cssText = od.wrapper;
- this.container.style.cssText = od.container;
- this.input = document.createElement("input");
- this.input.value = this.wrapper.innerHTML;
- this.input.type = "hidden";
- this.wrapper.parentNode.insertBefore(this.input, this.wrapper);
- }
- GrowHeight.prototype.onInput = function () {
- this.lastScrollTop = this.container.scrollTop;
- this.updateContainerHeight();
- if (this.cmsBtn) {
- //更新CMS按钮的位置
- this.cmsBtn.updateButtonSize();
- }
- this.updateInputValue && this.updateInputValue();
- this.onInputCallback && this.onInputCallback.call(this, this.container);
- }
- GrowHeight.prototype.onFocus = function () { //
- {
- var textDom = this.container;
- if (textDom.setSelectionRange) {
- // IE Support
- textDom.focus();
- textDom.setSelectionRange(this.cursorPos, this.cursorPos);
- } else if (textDom.createTextRange) {
- // Firefox support
- var range = textDom.createTextRange();
- range.collapse(true);
- range.moveEnd('character', this.cursorPos);
- range.moveStart('character', this.cursorPos);
- range.select();
- }
- this.isFocus = true;
- }
- if (this.cmsBtn) {
- //更新CMS按钮的位置
- this.cmsBtn.updateButtonSize();
- }
- this.onFocusCallback && this.onFocusCallback.call(this.GrowHeight, this);
- }
- GrowHeight.prototype.onBlur = function () { //
- {
- var textDom = this.container;
- if (document.selection) {
- // IE Support
- // 有bug,先注释了,IE会不断获取焦点
- // textDom.focus();
- var selectRange = document.selection.createRange();
- selectRange.moveStart('character', -textDom.value.length);
- this.cursorPos = selectRange.text.length;
- } else if (textDom.selectionStart || textDom.selectionStart == '0') {
- // Firefox support
- this.cursorPos = textDom.selectionStart;
- }
- this.isFocus = false;
- }
- if (this.cmsBtn) {
- //更新CMS按钮的位置
- this.cmsBtn.updateButtonSize();
- }
- this.onBlurCallback && this.onBlurCallback.call(this.GrowHeight, this);
- }
- GrowHeight.prototype.updateInputValue = function () {
- function getText() {
- var nn = this.nodeName;
- if (nn == "TEXTAREA" || nn == "INPUT") {
- return this.value;
- } else if (nn == "DIV") {
- return this.innerHTML;
- } else {
- return this.innerText;
- }
- }
- if (this.input && this.container) {
- var value = getText.call(this.container);
- if (this.acceptEnter || this.type > 1) { //接受回车,或者是播放
- this.input.value = value;
- } else {
- if (this.container.nodeName == 'DIV') {
- value = value.replace('<br>', "");
- }
- value = value.replace(/\n/g, '');
- this.input.value = value;
- }
- }
- }
- GrowHeight.prototype.initAsInput = function () {
- if (this.inited === true)
- return;
- var gh = this;
- var editorOninput = function (e) {
- if (!this.GrowHeight.acceptEnter) {
- var et = e || window.event;
- var keycode = et.charCode || et.keyCode;
- if (keycode == 13) {
- if (window.event) {
- window.event.returnValue = false;
- } else {
- e.preventDefault(); //for firefox
- }
- return;
- }
- }
- this.GrowHeight.onInput();
- this.GrowHeight.updateInputValue();
- }
- // this.onInputCallback = function (container) {
- // this.updateInputValue();
- // }
- function editorOnfocus() {
- this.isFocus = true;
- //浮出来
- this.value = this.GrowHeight.input.value;
- this.GrowHeight.show();
- this.focus();
- this.addEventListener("blur", editorOnblur);
- this.GrowHeight.onFocus();
- editorOninput.call(this);
- }
- function editorOnblur() {
- this.isFocus = false;
- //弄回去
- this.GrowHeight.updateInputValue();
- this.GrowHeight.hide();
- this.removeEventListener("blur", editorOnblur);
- this.GrowHeight.onBlur();
- this.initDot();
- }
- var container = this.container = document.createElement("textarea");
- this.wrapper.insertBefore(this.container, this.srcElement);
- //placeholder支持
- if (this.srcElement.getAttribute("placeholder"))
- container.setAttribute("placeholder", this.srcElement.getAttribute("placeholder"));
- container.GrowHeight = this;
- //克隆样式
- container.className = "form-text";
- container.style.width = "100%";
- container.style.paddingLeft = "5px";
- container.style.paddingTop = "5px";
- container.style.resize = "none";
- container.style.overflowY = "hidden";
- container.style.height = $minHeight100(this.container) + "px";
- container.style.minHeight = $minHeight100(this.container) + "px";
- var stn = []; //["border", "border-radius"];
- for (var i = 0; i < stn.length; i++) {
- container.style[stn[i]] = $CSS(this.srcElement, stn[i]);
- }
- if (this.srcElement.getAttribute("placeholder"))
- this.container.setAttribute("placeholder", this.srcElement.getAttribute("placeholder"));
- var inputEventNames = ["input", "propertychange", "keydown", "keyup"];
- for (var i = 0; i < inputEventNames.length; i++) {
- (function (evname) {
- container.addEventListener(evname, editorOninput);
- })(inputEventNames[i]);
- }
- container.addEventListener("focus", editorOnfocus);
- container.initDot = function () {
- wd.display.ellipsisContent(this, $maxHeight100(this));
- }
- this.input = document.createElement("textarea");
- this.input.name = this.id;
- // this.input.style.cssText = container.style.cssText;
- this.input.style.display = "none";
- this.input.GrowHeight = this;
- this.wrapper.insertBefore(this.input, this.container);
- this.val(this.srcElement.innerHTML);
- this.wrapper.removeChild(this.srcElement);
- this.updateContainerHeight();
- }
- GrowHeight.prototype.getInputElement = function () {
- return this.container;
- }
- GrowHeight.prototype.getInput = function () {
- return this.container;
- }
- GrowHeight.prototype.initPlayHtml = function () {
- if (this.inited === true)
- return;
- this.showPadding = 6;
- var container = this.container = this.srcElement,
- that = this;
- this.minHeight = $minHeight100(container);
- container.style.height = $maxHeight100(container) + "px";
- container.style.overflowY = "auto";
- function enter(event) {
- this.GrowHeight.show();
- this.GrowHeight.wrapper.style.overflow = "hidden";
- }
- function leave(event) {
- this.GrowHeight.hide();
- }
- this.wrapper.addEventListener("mouseenter", enter);
- this.wrapper.addEventListener("mouseleave", leave);
- }
- GrowHeight.prototype.getCmsBtn = function (mode) {
- if (this.fj == null || (mode == "play" && (this.fj.value == null || this.fj.value == "")))
- return;
- if(mode=="edit"&&this.fj.value == ""){
- this.fj.jlztm=1;
- }
- var fj = this.fj;
- var attachment = document.createElement("span");
- var attachmentText = document.createTextNode("附件");
- attachment.appendChild(attachmentText);
- this.wrapper.insertBefore(attachment, this.container.nextSibling);
- attachment.className = 'icon-attachment builtinButton';
- //上浮。找到目标的样式修改当前的样式名
- if ($(attachment).parents("abc").length > 0) {
- attachment.className = "123456789";
- }
- var fjidHidden = document.querySelector("[name='" + fj.key + "']");
- if (!fjidHidden) {
- fjidHidden = document.createElement("input");
- fjidHidden.type = "hidden";
- fjidHidden.name = fj.key;
- fjidHidden.value = fj.value;
- attachment.style.display = "none";
- attachment.parentNode.insertBefore(fjidHidden, attachment);
- }
- var editor = attachment.editor = this.container;
- var oriTop = $MT(attachment),
- oriBottom = $MB(attachment),
- oriLeft = $ML(attachment);
- attachment.updateButtonSize = function () {
- var editor = attachment.editor;
- editor.style.resize = "none";
- editor.style.width = $INNERWIDTH(editor.parentNode) - $ML(editor) - $MR(editor) - ($ISBOX(editor) ? 0 : ($BOXWIDTH(editor))) - $REALWIDTH(attachment) - $ML(attachment) - $MR(attachment) + "px";
- var editor = attachment.editor;
- attachment.style.display = "none";
- attachment.style.height = $INNERHEIGHT(attachment.parentNode) - oriTop - oriBottom + "px";
- attachment.style.verticalAlign = "top";
- attachment.style.lineHeight = $INNERHEIGHT(attachment.parentNode) - oriTop - oriBottom + 22 + "px";
- attachment.style.display = "inline-block";
- attachment.style.position = '';
- if ($DSP(editor).indexOf("inline") > -1) { //行内元素
- } else { //块元素,浮动在他身边
- editor.style.display = "inline-block";
- }
- }
- //编辑框去掉附件按钮的宽度
- function updateCount() {
- var fjidInput = document.getElementsByName(fj.key)[0];
- if (fjidInput == null)
- return;
- var fjid = fjidInput.value;
- if (fjid != null && fjid != "")
- $.ajax({
- type: "post",
- url: "/service?ssServ=wrCcmsList", // =getSubNrCount",。Lin
- data: {
- nrid: "T-" + fjid,
- jlztm: fj.jlztm
- },
- dataType: "json", // 增加,统一 Ajax 返回标准 -- .ssCode、.ssMsg、.ssData。Lin
- success: function (data) {
- /* 改,增加错误处理 -- 统一 Ajax 返回标准 -- .ssCode、.ssMsg、.ssData。Lin
- * 去掉 JSON.parse(,改为用 Map<String, Object> 传输
- var names = JSON.parse(data);
- */
- if (data.ssCode != 0) {
- alert(data.ssMsg);
- return;
- }
- var names = data.ssData;
- var count = names.length;
- //if (count > 0) {
- var num = attachment.querySelector(".icon-num");
- if (!num) {
- num = document.createElement("span");
- num.className = "icon-num";
- num.style.float = "right";
- num.style.position = "absolute";
- num.style.right = "2px";
- num.style.top = "2px";
- attachment.appendChild(num);
- }
- num.innerText = count;
- if (count == 0) {
- $(num).hide();
- } else {
- $(num).show();
- }
- var datas = [];
- for (var iii = 0; iii < names.length; iii++) {
- datas.push({
- name: iii,
- value: names[iii]
- })
- }
- $(attachment).off("mouseenter").on("mouseenter", function () {
- var menuelement = wd.display.initCmsMenu("cms" + fjid, fj.jlztm, datas);
- if (menuelement) {
- menuelement.showAt(attachment);
- $(attachment).off("mouseleave").on("mouseleave", function () {
- menuelement.hide();
- });
- }
- });
- },
- error: function (data) {
- console.log(data);
- }
- });
- };
- if ("play" == mode) {
- attachment.addEventListener("click", function (e) {
- var fn = window[fj.key + "fjPlay"];
- fn && fn.call(this);
- e.stopPropagation()
- });
- } else if ("edit" == mode) {
- var fnName = fj.key + "CallbackName";
- var fnName = window[fnName] = fj.key + "mouseover";
- window[fnName] = updateCount;
- attachment.addEventListener("mouseenter", window[fnName]);
- attachment.addEventListener("click", function (e) {
- var fn = window[fj.key + "fjEdit"];
- fn && fn.call(this);
- e.stopPropagation()
- });
- }
- attachment.updateButtonSize();
- editor.initDot && editor.initDot();
- updateCount();
- return attachment;
- }
- GrowHeight.prototype.getElement = function () {
- return this.wrapper;
- }
- GrowHeight.prototype.init = function () {
- if (!this.inited) {
- var styleAttrNames = {
- "width": "width",
- "height": "height"
- };
- for (var key in styleAttrNames) {
- var attrV = this.srcElement.getAttribute(key);
- if (attrV != null) {
- var styleName = styleAttrNames[key];
- this.srcElement.style[styleName] = attrV;
- }
- this.srcElement.removeAttribute(key);
- }
- var h = $REALHEIGHT(this.srcElement);
- var lh = $LH(this.srcElement);
- this.minHeight = Math.max(lh || 28, h);
- this.oriWidth = $REALWIDTH(this.srcElement);
- this.wrapper = document.createElement("div");
- this.wrapper.style.cssText = this.srcElement.style.cssText;
- this.wrapper.style.minHeight = this.minHeight + "px";
- this.wrapper.className = this.srcElement.className;
- this.srcElement.GrowHeight = this;
- this.srcElement.className = "";
- this.srcElement.style.width = "";
- this.srcElement.style.maxWidth = "";
- this.srcElement.style.cssText = "";
- this.srcElement.parentNode.insertBefore(this.wrapper, this.srcElement);
- this.wrapper.appendChild(this.srcElement);
- this.wrapper.GrowHeight = this;
- this.wrapper.setAttribute("growHeight", this.name);
- this.id = this.srcElement.id;
- switch (this.type) {
- case 0:
- this.wrapper.className += " input-div";
- this.initAsInput();
- this.cmsBtn = this.getCmsBtn("edit");
- break;
- case 1:
- this.wrapper.className += " input-div";
- this.initAsDiv();
- this.cmsBtn = this.getCmsBtn("edit");
- break;
- case 2:
- this.initPlayHtml();
- this.cmsBtn = this.getCmsBtn("play");
- break;
- case 3:
- default:
- this.initPlay();
- this.cmsBtn = this.getCmsBtn("play");
- break;
- }
- if (this.container) {
- var that = this;
- this.container.id = this.id;
- this.container.className += " smallScrollbar";
- var passiveSupported = false;
- try {
- var options = Object.defineProperty({}, "passive", {
- get: function () {
- passiveSupported = true;
- }
- });
- window.addEventListener("test", null, options);
- } catch (err) {}
- this.container.addEventListener("mousewheel", function (e) {
- that.lastScrollTop = that.container.scrollTop;
- }, passiveSupported ? {
- passive: true
- }
- : false);
- this.container.addEventListener('paste', function (e) {
- console.log("paste")
- if (!this.GrowHeight.acceptEnter) {
- var vvv = (e.clipboardData || window.clipboardData).getData('text/plain').replace(/\n/g, "");
- this.focus();
- if (document.all) {
- var r = document.selection.createRange();
- document.selection.empty();
- r.text = vvv;
- r.collapse();
- r.select();
- } else {
- var newstart = this.selectionStart + vvv.length;
- var pfx = this.value.substr(0, this.selectionStart);
- var sfx = this.value.substring(this.selectionEnd);
- this.value = pfx + vvv + sfx;
- this.selectionStart = newstart;
- this.selectionEnd = newstart;
- }
- e.preventDefault();
- e.stopPropagation();
- return false;
- this.GrowHeight.onInput();
- }
- });
- }
- this.inited = true;
- this.hide();
- }
- // loadSmallScorll($(this.wrapper).find(".smallScrollbar")); // 初始化伪滚动条
- }
- function $ISBOX(element) {
- return $CSS(element, "box-sizing") == "border-box";
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function $PT(element) {
- $ISBOX(element);
- return $NUMOFCSS(element, "padding-top", 0);
- }
- function $PR(element) {
- return $NUMOFCSS(element, "padding-right", 0);
- }
- function $PB(element) {
- return $NUMOFCSS(element, "padding-bottom", 0);
- }
- function $PL(element) {
- return $NUMOFCSS(element, "padding-left", 0);
- }
- function $CSS(element, name) {
- if (typeof(window.getComputedStyle) == 'undefined') {
- return element.currentStyle[name];
- }
- return window.getComputedStyle(element)[name];
- }
- function $DSP(element) {
- return $CSS(element, "display");
- }
- function $NUMOFCSS(element, name, def) {
- var v = parseFloat($CSS(element, name));
- v = isNaN(v) ? def : v;
- return v;
- }
- function $W(element) {
- return $NUMOFCSS(element, "width");
- }
- function $H(element) {
- return $NUMOFCSS(element, "height");
- }
- function $R(element) {
- return $NUMOFCSS(element, "right");
- }
- function $MAH(element) {
- return $NUMOFCSS(element, "max-height");
- }
- function $MIH(element) {
- return $NUMOFCSS(element, "min-height");
- }
- function $MT(element) {
- return $NUMOFCSS(element, "margin-top", 0);
- }
- function $MB(element) {
- return $NUMOFCSS(element, "margin-bottom", 0);
- }
- function $ML(element) {
- return $NUMOFCSS(element, "margin-left", 0);
- }
- function $MR(element) {
- return $NUMOFCSS(element, "margin-right", 0);
- }
- function $BL(element) {
- return $NUMOFCSS(element, "border-left", 0);
- }
- function $BR(element) {
- return $NUMOFCSS(element, "border-right", 0);
- }
- function $BOXWIDTH(element) {
- return $PL(element) + $PR(element) + $BL(element) + $BR(element);
- }
- function $BOXHEIGHT(element) {
- return $PT(element) + $PB(element) + $BT(element) + $BB(element);
- }
- function $MAWS(element, def) {
- var va = $CSS(element, "max-width");
- va = isNaN(parseFloat(va)) ? $CSS(element, "width") : va;
- return isNaN(parseFloat(va)) ? def : va;
- }
- function $REALHEIGHT(element) {
- var b = $ISBOX(element);
- var height = $NUMOFCSS(element, "height");
- if (height == null || typeof(height) == 'undefined') {
- //兼容IE8
- console.log("兼容IE8");
- height = 35;
- }
- if (!b) {
- height += $BOXHEIGHT(element);
- }
- return height;
- }
- function $REALWIDTH(element) {
- var b = $ISBOX(element);
- var width = $NUMOFCSS(element, "width");
- if (!b) {
- width += $BOXWIDTH(element);
- }
- return width;
- }
- function $INNERWIDTH(element) {
- var b = $ISBOX(element),
- width = $NUMOFCSS(element, "width");
- if (b) {
- width -= $BOXWIDTH(element);
- }
- return width;
- }
- function $INNERHEIGHT(element) {
- var b = $ISBOX(element),
- height = $NUMOFCSS(element, "height");
- if (height == null || typeof(height) == 'undefined') {
- //兼容IE8
- height = 38
- }
- if (b) {
- height -= $BOXHEIGHT(element);
- }
- return height;
- }
- function $LH(element, default_) {
- return $NUMOFCSS(element, "line-height", default_);
- }
- function $HIDDENOVERFLOW(element) {
- var h = [];
- var a = [];
- var p = element;
- while (p.parentNode && p.parentNode.nodeType == 1) {
- p = p.parentNode;
- if (p.parentNode.nodeType != 1)
- break;
- var ofy = $CSS(p, "overflow-y");
- if ((ofy.indexOf("auto") > -1 || ofy.indexOf("scroll") > -1) && p.scrollHeight != p.clientHeight) {
- //滚动高度等于元素高度的就算了
- a.push(p);
- } else if (ofy == "hidden") {
- h.push(p);
- var eb = element.getBoundingClientRect();
- var pb = p.getBoundingClientRect();
- var ph = $height100(p),
- eh = $maxHeight100(element) - pb.top + eb.top;
- if (ph < eh) {
- return p;
- }
- }
- }
- p = h.length > 0 ? h[0] : (a.length > 0 ? a[0] : document.body.parentNode);
- return p;
- }
- function $BT(element) {
- return $NUMOFCSS(element, "border-top", 0);
- }
- function $BB(element) {
- return $NUMOFCSS(element, "border-bottom", 0);
- }
- function debugLog() {
- event && event.ctrlKey && console.trace.apply(this, arguments);
- }
- function $innerHeight(element, height) {
- var p = element.parentNode;
- if ($ISBOX(p)) { //父级是box,要减掉padding,border
- height -= $BOXHEIGHT(p);
- }
- return height;
- }
- function $height100(element) {
- return $innerHeight(element, $INNERHEIGHT(element.parentNode));
- }
- function $minHeight100(element) {
- return $innerHeight(element, element.GrowHeight.minHeight);
- }
- function $maxHeight100(element) {
- return $innerHeight(element, $INNERHEIGHT(element.parentNode));
- }
- function $scrollHeight100(element) {
- return $innerHeight(element, element.scrollHeight);
- }
|