File tree Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ IonicModule
3
+ . directive ( 'itemFloatingLabel' , function ( ) {
4
+ return {
5
+ restrict : 'C' ,
6
+ link : function ( scope , element ) {
7
+ var el = element [ 0 ] ;
8
+ var input = el . querySelector ( 'input, textarea' ) ;
9
+ var inputLabel = el . querySelector ( '.input-label' ) ;
10
+
11
+ if ( ! input || ! inputLabel ) return ;
12
+
13
+ var onInput = function ( ) {
14
+ var hasInput = inputLabel . classList . contains ( 'has-input' ) ;
15
+ if ( input . value && ! hasInput ) {
16
+ inputLabel . classList . add ( 'has-input' ) ;
17
+ }
18
+ else if ( ! input . value && hasInput ) {
19
+ inputLabel . classList . remove ( 'has-input' ) ;
20
+ }
21
+ } ;
22
+
23
+ input . addEventListener ( 'input' , onInput ) ;
24
+
25
+ var ngModelCtrl = angular . element ( input ) . controller ( 'ngModel' ) ;
26
+ if ( ngModelCtrl ) {
27
+ ngModelCtrl . $render = function ( ) {
28
+ input . value = ngModelCtrl . $viewValue || '' ;
29
+ if ( ngModelCtrl . $viewValue ) input . value = ngModelCtrl . $viewValue ;
30
+ else input . value = '' ;
31
+ onInput ( ) ;
32
+ } ;
33
+ }
34
+
35
+ scope . $on ( '$destroy' , function ( ) {
36
+ input . removeEventListener ( 'input' , onInput ) ;
37
+ } ) ;
38
+ }
39
+ } ;
40
+ } ) ;
Original file line number Diff line number Diff line change @@ -155,6 +155,26 @@ textarea {
155
155
height : $line-height-computed + $font-size-base + 12px ;
156
156
}
157
157
158
+ .item-floating-label {
159
+ display : block ;
160
+ background-color : transparent ;
161
+ box-shadow : none ;
162
+
163
+ .input-label {
164
+ position : relative ;
165
+ padding : 5px 0 0 0 ;
166
+ opacity : 0 ;
167
+ top : 10px ;
168
+ @include transition (opacity .2s ease-in , top .2s linear );
169
+
170
+ & .has-input {
171
+ opacity : 1 ;
172
+ top : 0 ;
173
+ @include transition (opacity .2s ease-in , top .2s linear );
174
+ }
175
+ }
176
+ }
177
+
158
178
159
179
// Form Controls
160
180
// -------------------------------
You can’t perform that action at this time.
0 commit comments