@@ -392,6 +392,75 @@ module openflow {
392392 }
393393 }
394394
395+
396+ export class textarea implements ng . IDirective {
397+ // restrict = 'E';
398+ // require = 'ngModel';
399+ replace = true ;
400+ constructor ( public $location : ng . ILocationService , public $timeout : ng . ITimeoutService ) {
401+
402+ }
403+
404+ link : ng . IDirectiveLinkFn = ( scope : ng . IScope , element : ng . IAugmentedJQuery , attr : ng . IAttributes , ngModelCtrl : any ) => {
405+ if ( ! element . hasClass ( "autogrow" ) ) {
406+ console . log ( "no autogrow for you today" ) ;
407+ // no autogrow for you today
408+ return ;
409+ }
410+
411+ // get possible minimum height style
412+ var minHeight = parseInt ( window . getComputedStyle ( element [ 0 ] ) . getPropertyValue ( "min-height" ) ) || 0 ;
413+
414+ // prevent newlines in textbox
415+ // element.on("keydown", function (evt) {
416+ // if (evt.which === 13) {
417+ // evt.preventDefault();
418+ // }
419+ // });
420+
421+ element . on ( "input" , function ( evt ) {
422+ var contentHeight2 = ( this as any ) . scrollHeight ;
423+ var firstrun = element . attr ( "firstrun" ) ;
424+ if ( contentHeight2 > 1000 ) {
425+ if ( firstrun === null || firstrun === undefined ) {
426+ element . attr ( "firstrun" , "false" ) ;
427+ } else {
428+ return ;
429+ }
430+ }
431+ element . css ( {
432+ paddingTop : 0 ,
433+ height : 0 ,
434+ minHeight : 0
435+ } ) ;
436+
437+ var contentHeight = ( this as any ) . scrollHeight ;
438+ var borderHeight = ( this as any ) . offsetHeight ;
439+
440+ element . css ( {
441+ paddingTop : ~ ~ Math . max ( 0 , minHeight - contentHeight ) / 2 + "px" ,
442+ minHeight : null , // remove property
443+ height : contentHeight + borderHeight + "px" // because we're using border-box
444+ } ) ;
445+ } ) ;
446+
447+ // watch model changes from the outside to adjust height
448+ scope . $watch ( attr . ngModel , trigger ) ;
449+
450+ // set initial size
451+ trigger ( ) ;
452+
453+ function trigger ( ) {
454+ setTimeout ( element . triggerHandler . bind ( element , "input" ) , 1 ) ;
455+ }
456+ }
457+ static factory ( ) : ng . IDirectiveFactory {
458+ const directive = ( $location : ng . ILocationService , $timeout : ng . ITimeoutService ) => new textarea ( $location , $timeout ) ;
459+ directive . $inject = [ '$location' , '$timeout' ] ;
460+ return directive ;
461+ }
462+ }
463+
395464 async function getString ( locale : any , lib : string , key : string ) : Promise < any > {
396465 return new Promise ( ( resolve ) => {
397466 try {
@@ -617,7 +686,7 @@ module openflow {
617686 public id : string = null ;
618687 public keys : string [ ] = [ ] ;
619688 public autorefresh : boolean = false ;
620- public autorefreshinterval : number = 2000 ;
689+ public autorefreshinterval : number = 30 * 1000 ;
621690 public autorefreshpromise : any = null ;
622691 public preloadData : any = null ;
623692 public postloadData : any = null ;
0 commit comments