RdmApp.directive("select2",["$timeout","$parse",function(e,n){return{restrict:"A",scope:{selectWidth:"@",ngModel:"=",ngDisabled:"="},link:function(e,n,t){e.selectWidth=e.selectWidth||"100%",n.select2({width:e.selectWidth,height:33,disabled:e.ngDisabled}),e.$watch("ngModel",(function(e,t){window.setTimeout((function(){n.select2("val",e)}))}))}}}]),RdmApp.directive("onSizeChanged",["$window",function(e){return{restrict:"A",scope:{onSizeChanged:"&"},link:function(n,t,i){var o=t[0];!function(e,n){e.cachedElementWidth=n.offsetWidth,e.cachedElementHeight=n.offsetHeight}(n,o),e.addEventListener("resize",(function(){if(n.cachedElementWidth!=o.offsetWidth||n.cachedElementHeight!=o.offsetHeight){n.onSizeChanged()()}}))}}}]),RdmApp.directive("ngBindHtmlUnsafe",[function(){return function(e,n,t){n.addClass("ng-binding").data("$binding",t.ngBindHtmlUnsafe),e.$watch(t.ngBindHtmlUnsafe,(function(e){"0"==e?n.html("0"):n.html(e||"")}))}}]),RdmApp.directive("bDatepicker",(function(){return{restrict:"A",require:"ngModel",scope:{ngModel:"=",minDate:"=",maxDate:"="},link:function(e,n,t,i){var o={format:"yyyy-mm-dd",autoclose:!0,onSelect:function(n){!function(n){console.log(n),""!==n&&e.$apply((function(){i.$setViewValue(n)}))}(n),this.focus()},onClose:function(e){this.blur()}};e.$watch("maxDate",(function(e,t){$(n).datepicker("option","endDate",e)})),e.$watch("minDate",(function(e,t){$(n).datepicker("option","startDate",e),$(n).datepicker("option","defaultDate",e)})),e.$watch("ngModel",(function(e){n.datepicker("setDate",new Date(e))})),n.datepicker(o)}}})),RdmApp.directive("timeAgo",["timeAgo","nowTime",function(e,n){return{restrict:"EA",link:function(t,i,o){var c;o.$observe("fromTime",(function(n){c=e.parse(n)})),t.$watch((function(){return n()-c}),(function(n){$(i).text(e.inWords(n))}))}}}]),RdmApp.directive("whenScrolled",(function(){return{restrict:"A",link:function(e,n,t){raw=n[0],console.log(n),n.bind("scroll",(function(){console.log("scroll"),raw.scrollTop+raw.offsetHeight+5>=raw.scrollHeight&&(e.loading=!0,e.$apply(t.whenScrolled))}))}}})),RdmApp.factory("httpPostFactory",["$http",function(e){return function(n,t,i){e({url:n,method:"POST",data:t,headers:{"Content-Type":void 0}}).then((function(e){console.log(e),i(e.data)}))}}]),RdmApp.directive("bnLazySrc",["$window","$document",function(e,n){var t=function(){var t=[],i=null,o=$(e),c=n,r=c.height(),l=null,a=!1;function u(){if(!i){var e=c.height();e!==r&&(r=e,s())}}function f(){console.log("Checking for visible images...");for(var e=[],n=[],i=o.height(),c=o.scrollTop(),r=c+i,l=0;l<t.length;l++){var a=t[l];a.isVisible(c,r)?e.push(a):n.push(a)}for(l=0;l<e.length;l++)e[l].render();t=n,d(),t.length||h()}function d(){clearTimeout(i),i=null}function s(){i=setTimeout(f,100)}function h(){a=!1,o.off("resize.bnLazySrc"),o.off("scroll.bnLazySrc"),clearInterval(l)}function g(){i||s()}return{addImage:function(e){t.push(e),i||s(),a||(a=!0,o.on("resize.bnLazySrc",g),o.on("scroll.bnLazySrc",g),l=setInterval(u,2e3))},removeImage:function(e){for(var n=0;n<t.length;n++)if(t[n]===e){t.splice(n,1);break}t.length||(d(),h())}}}();function i(e){var n=null,t=!1,i=null;function o(){e[0].src=n}return{isVisible:function(n,t){if(!e.is(":visible"))return!1;null===i&&(i=e.height());var o=e.offset().top,c=o+i;return o<=t&&o>=n||c<=t&&c>=n||o<=n&&c>=t},render:function(){t=!0,o()},setSource:function(e){n=e,t&&o()}}}return{link:function(e,n,o){var c=new i(n);t.addImage(c),o.$observe("bnLazySrc",(function(e){c.setSource(e)})),e.$on("$destroy",(function(){t.removeImage(c)}))},restrict:"A"}}]);