UNPKG

@haxtheweb/haxcms-nodejs

Version:

HAXcms single and multisite nodejs server, api, and administration

76 lines (67 loc) 5.08 kB
/** @license Copyright (c) 2015 The Polymer Project Authors. All rights reserved. This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as part of the polymer project is also subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt */ import"../polymer/polymer-legacy.js";import"../iron-flex-layout/iron-flex-layout.js";import{IronControlState as e}from"../iron-behaviors/iron-control-state.js";import{IronValidatableBehavior as t}from"../iron-validatable-behavior/iron-validatable-behavior.js";import{Polymer as a}from"../polymer/lib/legacy/polymer-fn.js";import{dom as i}from"../polymer/lib/legacy/polymer.dom.js";import{html as r}from"../polymer/lib/utils/html-tag.js";a({_template:r` <style> :host { display: inline-block; position: relative; width: 400px; border: 1px solid; padding: 2px; -moz-appearance: textarea; -webkit-appearance: textarea; overflow: hidden; } .mirror-text { visibility: hidden; word-wrap: break-word; @apply --iron-autogrow-textarea; } .fit { @apply --layout-fit; } textarea { position: relative; outline: none; border: none; resize: none; background: inherit; color: inherit; /* see comments in template */ width: 100%; height: 100%; font-size: inherit; font-family: inherit; line-height: inherit; text-align: inherit; @apply --iron-autogrow-textarea; } textarea::-webkit-input-placeholder { @apply --iron-autogrow-textarea-placeholder; } textarea:-moz-placeholder { @apply --iron-autogrow-textarea-placeholder; } textarea::-moz-placeholder { @apply --iron-autogrow-textarea-placeholder; } textarea:-ms-input-placeholder { @apply --iron-autogrow-textarea-placeholder; } </style> <!-- the mirror sizes the input/textarea so it grows with typing --> <!-- use &#160; instead &nbsp; of to allow this element to be used in XHTML --> <div id="mirror" class="mirror-text" aria-hidden="true">&nbsp;</div> <!-- size the input/textarea with a div, because the textarea has intrinsic size in ff --> <div class="textarea-container fit"> <textarea id="textarea" name$="[[name]]" aria-label$="[[label]]" autocomplete$="[[autocomplete]]" autofocus$="[[autofocus]]" autocapitalize$="[[autocapitalize]]" inputmode$="[[inputmode]]" placeholder$="[[placeholder]]" readonly$="[[readonly]]" required$="[[required]]" disabled$="[[disabled]]" rows$="[[rows]]" minlength$="[[minlength]]" maxlength$="[[maxlength]]"></textarea> </div> `,is:"iron-autogrow-textarea",behaviors:[t,e],properties:{value:{observer:"_valueChanged",type:String,notify:!0},bindValue:{observer:"_bindValueChanged",type:String,notify:!0},rows:{type:Number,value:1,observer:"_updateCached"},maxRows:{type:Number,value:0,observer:"_updateCached"},autocomplete:{type:String,value:"off"},autofocus:{type:Boolean,value:!1},autocapitalize:{type:String,value:"none"},inputmode:{type:String},placeholder:{type:String},readonly:{type:String},required:{type:Boolean},minlength:{type:Number},maxlength:{type:Number},label:{type:String}},listeners:{input:"_onInput"},get textarea(){return this.$.textarea},get selectionStart(){return this.$.textarea.selectionStart},get selectionEnd(){return this.$.textarea.selectionEnd},set selectionStart(e){this.$.textarea.selectionStart=e},set selectionEnd(e){this.$.textarea.selectionEnd=e},attached:function(){navigator.userAgent.match(/iP(?:[oa]d|hone)/)&&!navigator.userAgent.match(/OS 1[3456789]/)&&(this.$.textarea.style.marginLeft="-3px")},validate:function(){var e=this.$.textarea.validity.valid;return e&&(this.required&&""===this.value?e=!1:this.hasValidator()&&(e=t.validate.call(this,this.value))),this.invalid=!e,this.fire("iron-input-validate"),e},_bindValueChanged:function(e){this.value=e},_valueChanged:function(e){var t=this.textarea;t&&(t.value!==e&&(t.value=e||0===e?e:""),this.bindValue=e,this.$.mirror.innerHTML=this._valueForMirror(),this.fire("bind-value-changed",{value:this.bindValue}))},_onInput:function(e){var t=i(e).path;this.value=t?t[0].value:e.target.value},_constrain:function(e){var t;for(e=e||[""],t=this.maxRows>0&&e.length>this.maxRows?e.slice(0,this.maxRows):e.slice(0);this.rows>0&&t.length<this.rows;)t.push("");return t.join("<br/>")+"&#160;"},_valueForMirror:function(){var e=this.textarea;if(e)return this.tokens=e&&e.value?e.value.replace(/&/gm,"&amp;").replace(/"/gm,"&quot;").replace(/'/gm,"&#39;").replace(/</gm,"&lt;").replace(/>/gm,"&gt;").split("\n"):[""],this._constrain(this.tokens)},_updateCached:function(){this.$.mirror.innerHTML=this._constrain(this.tokens)}});