From 0f490f4d366f97b83e05997d71f1e34c3f3f2441 Mon Sep 17 00:00:00 2001 From: Raymond Julin Date: Mon, 12 Jan 2015 11:05:28 +0100 Subject: [PATCH] Autofocus search field on browsing media in entry edit --- resources/mediaflow-ng.js | 10 ++++++++++ templates/input.html | 1 + 2 files changed, 11 insertions(+) diff --git a/resources/mediaflow-ng.js b/resources/mediaflow-ng.js index 79f83c3..343a5c9 100644 --- a/resources/mediaflow-ng.js +++ b/resources/mediaflow-ng.js @@ -76,6 +76,16 @@ mediaflow.controller('MediaFlowCtrl', function ($scope, $http, $upload) { } }); +mediaflow.directive('showFocus', ['$timeout', function($timeout) { + return function(scope, element, attrs) { + scope.$watch(attrs.showFocus, function(showing) { + $timeout(function() { + showing && element[0].focus(); + }); + }, true); + }; +}]); + mediaflow.controller('MediaFlowFieldCtrl', function ($scope, $http, $upload) { $scope.showMedia = false; $scope.selected = false; diff --git a/templates/input.html b/templates/input.html index eb344f8..108b4b4 100644 --- a/templates/input.html +++ b/templates/input.html @@ -48,6 +48,7 @@