forked from fluxio/io-value
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio-string.html
81 lines (78 loc) · 2.3 KB
/
io-string.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!--
I/O element for string data type.
<io-string value="Hi"></io-string>
@element io-string
@extends io-base-editable
@homepage https://github.com/arodic/io-value
@demo http://akirodic.com/components/io-value/demo.html
@blurb I/O element for string data type.
@status alpha
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="_io-base-editable.html">
<polymer-element name="io-string" extends="io-base-editable">
<template>
<link rel="stylesheet" href="_io-base.css" shim-shadowdom>
<link rel="stylesheet" href="_io-base-editable.css" shim-shadowdom>
<style>
input {
border: none;
background-color: transparent;
}
</style>
<content></content>
<template if="{{disabled}}">
<span class="io-editor">{{value}}</span>
</template>
<template if="{{!disabled}}">
<input id="value"
class="io-editor qasel_io-string_{{value | makeValidClass}}"
tabindex="0"
spellcheck="false"
autocomplete="{{autocomplete}}"
value="{{immediateValue}}"
placeholder="{{placeholder}}"
flex>
</input>
</template>
</template>
<script type="text/javascript">
Polymer({
publish: {
// TODO: allow multiline input
// multiline: {value: false, reflect: true},
autocomplete: false
},
placeholder: "string",
eventDelegates: {
'keydown': 'keydownAction'
},
keydownAction: function(event) {
if (this.disabled) return;
if (event.path[0] !== this.$.value) return;
if (event.which == 13 && !this.multiline) {
event.preventDefault();
this.blur();
this.async(function() {
this.updateImmediateValue();
}.bind(this));
}
},
blurAction: function(event) {
this.updateImmediateValue();
this.super(arguments);
},
updateImmediateValue: function(event) {
this.value = this.immediateValue;
},
immediateValueChanged: function() {
if (this.updateImmediate) {
this.updateImmediateValue();
}
},
valueChanged: function() {
this.immediateValue = this.value;
}
});
</script>
</polymer-element>