From 2ce9bfb5b7806c20966ad86f73d20272ed92da2c Mon Sep 17 00:00:00 2001 From: Jonathan Hornung Date: Sat, 23 Apr 2016 22:24:15 +0200 Subject: [PATCH] added redraw functionality --- src/angular-bricklayer.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/angular-bricklayer.js b/src/angular-bricklayer.js index d07fda3..3824b2f 100644 --- a/src/angular-bricklayer.js +++ b/src/angular-bricklayer.js @@ -1,25 +1,33 @@ angular.module('jtt_bricklayer', []) - .directive('bricklayer', function () { + .directive('bricklayer', ['$timeout', function ($timeout) { return { restrict: 'C', replace: 'false', link: function (scope, element, attrs) { var bricklayer = new Bricklayer(element[0]); + $timeout(function () { + bricklayer.reorderElements(bricklayer.columnCount); + }, 0); + scope.$on('bricklayer.append', function (event, element) { - setTimeout(function () { - bricklayer.append(element) - }, 0) + bricklayer.append(element); + bricklayer.reorderElements(bricklayer.columnCount); + $timeout(function () { + bricklayer.reorderElements(bricklayer.columnCount); + }, 0); }); scope.$on('bricklayer.prepend', function (event, element) { - setTimeout(function () { - bricklayer.prepend(element) - }, 0) + bricklayer.prepend(element); + bricklayer.reorderElements(bricklayer.columnCount); + $timeout(function () { + bricklayer.reorderElements(bricklayer.columnCount); + }, 0); }); } } - }) + }]) .directive('bricklayerAppend', function () { return { require: '?bricklayer',