From 8bcea896b0f0facb42e08cca0b027a7c3973a2cc Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 17 Jun 2014 19:57:37 +0200 Subject: [PATCH] Improvements on own bindonce directives. --- app/coffee/modules/base/bindonce.coffee | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/app/coffee/modules/base/bindonce.coffee b/app/coffee/modules/base/bindonce.coffee index 62cd23fd..95f74285 100644 --- a/app/coffee/modules/base/bindonce.coffee +++ b/app/coffee/modules/base/bindonce.coffee @@ -19,20 +19,30 @@ # File: modules/base/bindonce.coffee ### +bindOnce = (scope, attr, continuation) => + val = scope.$eval(attr) + if val != undefined + return continuation(val) + + delBind = null + delBind = scope.$watch attr, (val) -> + return if val is undefined + continuation(val) + delBind() if delBind + # Html bind once directive BindHtmlDirective = -> link = (scope, element, attrs) -> - val = scope.$eval(attrs.tgBoHtml) - scope.$watch attrs.tgBoHtml, (val) -> - element.html(val) if val + bindOnce scope, attrs.tgBoHtml, (val) -> + element.html(val) return {link:link} # Object reference bind once helper. BindRefDirective = -> link = (scope, element, attrs) -> - val = scope.$eval(attrs.tgBoRef) - element.html("##{val} ") + bindOnce scope, attrs.tgBoRef, (val) -> + element.html("##{val} ") return {link:link} module = angular.module("taigaBase")