From 0d7d8e0cce15e525c6b9d5c57d68c36f835cefc0 Mon Sep 17 00:00:00 2001 From: Magnus Hauge Bakke Date: Fri, 9 Oct 2015 13:50:55 +0200 Subject: [PATCH] Add directive for file input change --- index.html | 1 + js/file-change.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 js/file-change.js diff --git a/index.html b/index.html index fa71eb2..c42ecae 100644 --- a/index.html +++ b/index.html @@ -33,6 +33,7 @@ + diff --git a/js/file-change.js b/js/file-change.js new file mode 100644 index 0000000..1b22359 --- /dev/null +++ b/js/file-change.js @@ -0,0 +1,23 @@ +(function() { +'use strict'; + +var weechat = angular.module('weechat'); + +weechat.directive('fileChange', ['$parse', function($parse) { + + return { + restrict: 'A', + link: function ($scope, element, attrs) { + var attrHandler = $parse(attrs.fileChange); + var handler = function (e) { + $scope.$apply(function () { + attrHandler($scope, { $event: e, files: e.target.files }); + }); + }; + element[0].addEventListener('change', handler, false); + } + }; + + }]); + +})();