UNPKG

weweb-cli

Version:

微信小程序转成h5的小工具

1 lines 6.53 kB
webpackJsonp([2],{298:function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var a=i(5),o=function(e){return e&&e.__esModule?e:{default:e}}(a);t.default=!function(){window.exparser.registerElement({is:"wx-textarea",behaviors:["wx-base","wx-data-Component"],template:'<div id="wrapped">\n <div id="placeholder" parse-text-content>\n {{placeholder}}\n </div>\n <textarea id="textarea" maxlength$="{{_getMaxlength(maxlength)}}" ></textarea>\n <div id="compute" class="compute"></div>\n <div id="stylecompute" class$="{{_getPlaceholderClass(placeholderClass)}}" style$="{{_getPlaceholderStyle(placeholderStyle)}}" ></div>\n </div>\n ',properties:{value:{type:String,value:"",public:!0,coerce:"defaultValueChange"},maxlength:{type:Number,value:140,public:!0,observer:"maxlengthChanged"},placeholder:{type:String,value:"",public:!0},hidden:{type:Boolean,value:!1,public:!0},disabled:{type:Boolean,value:!1,public:!0},focus:{type:Number,value:0,public:!0,coerce:"focusChanged"},autoFocus:{type:Boolean,value:!1,public:!0},placeholderClass:{type:String,value:"textarea-placeholder",observer:"_getComputePlaceholderStyle",public:!0},placeholderStyle:{type:String,value:"",observer:"_getComputePlaceholderStyle",public:!0},autoHeight:{type:Boolean,value:!1,public:!0,observer:"autoHeightChanged"},bindinput:{type:String,value:"",public:!0}},listeners:{"textarea.input":"onTextAreaInput","textarea.focus":"onTextAreaFocus","textarea.blur":"onTextAreaBlur"},resetFormData:function(){this.$.textarea.value="",this.value=""},getFormData:function(e){var t=this;this.value=this.$.textarea.value,setTimeout(function(){"function"==typeof e&&e(t.value)},0)},couldFocus:function(e){var t=this;this.__attached&&(!this._keyboardShow&&e?this.disabled||window.requestAnimationFrame(function(){t.$.textarea.focus()}):this._keyboardShow&&!e&&this.$.textarea.blur())},focusChanged:function(e,t){return this.couldFocus(Boolean(e)),e},attached:function(){var e=this;this.__attached=!0,this.__scale=750/window.innerWidth,this.getComputedStyle(),this.checkRows(this.value),this.__updateTextArea=this.updateTextArea.bind(this),document.addEventListener("pageReRender",this.__updateTextArea),this.__routeDoneId=exparser.addListenerToElement(document,"routeDone",function(){e.checkAutoFocus()}),this.checkPlaceholderStyle(this.value)},checkAutoFocus:function(){this.__autoFocused||(this.__autoFocused=!0,this.couldFocus(this.autoFocus||this.focus))},detached:function(){document.removeEventListener("pageReRender",this.__updateTextArea),exparser.removeListenerFromElement(document,"routeDone",this.__routeDoneId)},getHexColor:function(e){try{var t,i,a=function(){if(e.indexOf("#")>=0)return{v:e};t=e.match(/\d+/g);var a=[];return t.map(function(e,t){if(t<3){var i=parseInt(e);i=i>9?i.toString(16):"0"+i,a.push(i)}}),t.length>3&&(i=parseFloat(t.slice(3).join(".")),0==i?a.push("00"):i>=1?a.push("ff"):(i=parseInt(255*i),(i=i>9)&&i.toString(16),a.push(i))),{v:"#"+a.join("")}}();if("object"===(void 0===a?"undefined":(0,o.default)(a)))return a.v}catch(e){return""}},getComputedStyle:function(){var e=this;window.requestAnimationFrame(function(){var t=window.getComputedStyle(e.$$),i=e.$$.getBoundingClientRect(),a=["Left","Right"].map(function(e){return parseFloat(t["border"+e+"Width"])+parseFloat(t["padding"+e])}),o=["Top","Bottom"].map(function(e){return parseFloat(t["border"+e+"Width"])+parseFloat(t["padding"+e])}),n=e.$.textarea;n.style.width=i.width-a[0]-a[1]+"px",n.style.height=i.height-o[0]-o[1]+"px",console.log(i.height-o[0]-o[1]+"px"),n.style.fontWeight=t.fontWeight,n.style.fontSize=t.fontSize||"16px",n.style.color=t.color,e.$.compute.style.fontSize=t.fontSize||"16px",e.$.compute.style.width=n.style.width,e.$.placeholder.style.width=n.style.width,e.$.placeholder.style.height=n.style.height,e.disabled?n.setAttribute("disabled",!0):n.removeAttribute("disabled")})},getCurrentRows:function(e){var t=window.getComputedStyle(this.$.compute),i=1.2*(parseFloat(t.fontSize)||16);return this.$.compute.innerText=e,this.$.compute.appendChild(document.createElement("br")),{height:Math.max(this.$.compute.scrollHeight,i),heightRpx:this.__scale*this.$.compute.scrollHeight,lineHeight:i,lineCount:Math.ceil(this.$.compute.scrollHeight/i)}},onTextAreaInput:function(e){if(this.value=e.target.value,this.bindinput){var t={id:this.$$.id,dataset:this.dataset,offsetTop:this.$$.offsetTop,offsetLeft:this.$$.offsetLeft};WeixinJSBridge.publish("SPECIAL_PAGE_EVENT",{eventName:this.bindinput,ext:{setKeyboardValue:!1},data:{data:{type:"input",timestamp:Date.now(),detail:{value:e.target.value},target:t,currentTarget:t,touches:[]},eventName:this.bindinput}})}return!1},onTextAreaFocus:function(e){this._keyboardShow=!0,this.triggerEvent("focus",{value:this.value})},onTextAreaBlur:function(e){this._keyboardShow=!1,this.triggerEvent("blur",{value:this.value})},updateTextArea:function(){this.checkAutoFocus(),this.getComputedStyle(),this.autoHeightChanged(this.autoHeight)},hiddenChanged:function(e,t){this.$$.style.display=e?"none":""},_getPlaceholderStyle:function(e){return e+";display:none;"},_getComputePlaceholderStyle:function(){var e=this.$.stylecompute,t=window.getComputedStyle(e),i=parseInt(t.fontWeight);isNaN(i)?i=t.fontWeight:i<500?i="normal":i>=500&&(i="bold"),this.placeholderStyle&&this.placeholderStyle.split(";");var a=this.$.placeholder;a.style.position="absolute",a.style.fontSize=(parseFloat(t.fontSize)||16)+"px",a.style.fontWeight=i,a.style.color=this.getHexColor(t.color)},defaultValueChange:function(e){return this.maxlength>0&&e.length>this.maxlength&&(e=e.slice(0,this.maxlength)),this.checkPlaceholderStyle(e),this.$.textarea.value=e,this.__attached&&this.checkRows(e),e},autoHeightChanged:function(e){if(e){var t=this.getCurrentRows(this.value),i=t.height<t.lineHeight?t.lineHeight:t.height;this.$$.style.height=i+"px",this.getComputedStyle()}},checkRows:function(e){var t=this.getCurrentRows(e);if(this.lastRows!=t.lineCount){if(this.lastRows=t.lineCount,this.autoHeight){var i=t.height<t.lineHeight?t.lineHeight:t.height;this.$$.style.height=i+"px",this.getComputedStyle()}this.triggerEvent("linechange",t)}},checkPlaceholderStyle:function(e){e?this.$.placeholder.style.display="none":(this._getComputePlaceholderStyle(),this.$.placeholder.style.display="")},_getPlaceholderClass:function(e){return"textarea-placeholder "+e},_getMaxlength:function(e){return e<=0?-1:e},maxlengthChanged:function(e){e>0&&this.value.length>e&&(this.value=this.value.slice(0,e))}})}()}});