Fixes grid auto-resizing fields on hidden tabs

This commit is contained in:
per ploug
2014-11-20 13:39:28 +01:00
parent 9190930f49
commit 6265354327
4 changed files with 52 additions and 12 deletions

View File

@@ -0,0 +1,16 @@
angular.module("umbraco.directives")
.directive('umbAutoFocus', function($timeout) {
return function(scope, element, attr){
var update = function() {
//if it uses its default naming
if(element.val() === ""){
element.focus();
}
};
$timeout(function() {
update();
});
};
});

View File

@@ -0,0 +1,32 @@
angular.module("umbraco.directives")
.directive('umbAutoResize', function($timeout) {
return function(scope, element, attr){
var domEl = element[0];
var update = function(force) {
if(force === true){
element.height(0);
}
if(domEl.scrollHeight !== domEl.clientHeight){
element.height(domEl.scrollHeight);
}
};
element.bind('keyup keydown keypress change', update);
element.bind('blur', function(){ update(true); });
$timeout(function() {
update();
}, 100);
//I hate bootstrap tabs
$('a[data-toggle="tab"]').on('shown', update);
scope.$on('$destroy', function() {
$('a[data-toggle="tab"]').unbind("shown", update);
});
};
});

View File

@@ -2,17 +2,7 @@ angular.module("umbraco")
.controller("Umbraco.PropertyEditors.Grid.TextStringController",
function ($scope, $rootScope, $timeout, dialogService) {
$scope.adjustSize = function(ev){
if(ev.target.scrollHeight > ev.target.clientHeight){
$(ev.target).height(ev.target.scrollHeight);
}
};
if($scope.control.value === null){
$timeout(function(){
$("#" + $scope.control.uniqueId +"_text").focus();
}, 200);
}
});

View File

@@ -1,7 +1,9 @@
<div ng-controller="Umbraco.PropertyEditors.Grid.TextStringController">
<textarea
rows="1"
umb-auto-resize
umb-auto-focus
class="textstring input-block-level" id="{{control.uniqueId}}_text"
ng-keyup="adjustSize($event)" ng-model="control.value"
ng-model="control.value"
ng-attr-style="{{control.editor.config.style}}" placeholder="Write here..."></textarea>
</div>