From e51b4727649b16725cd990131cf0bd5d6bd6664f Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 6 May 2016 15:49:15 -0700 Subject: [PATCH] Added function() wrapper for safety in concatenation, removed unnecessary redrawing of the footable and added checks for loadWhen attribute presence and watch for data loading (currently supports array object), removed unnecessary timeout --- dist/angular-footable.js | 106 +++++++++++++++++++---------------- dist/angular-footable.min.js | 2 +- src/angular-footable.js | 106 +++++++++++++++++++---------------- 3 files changed, 117 insertions(+), 97 deletions(-) diff --git a/dist/angular-footable.js b/dist/angular-footable.js index 08ec352..fe5bc61 100755 --- a/dist/angular-footable.js +++ b/dist/angular-footable.js @@ -1,65 +1,75 @@ -'use strict'; - -angular - .module('ui.footable', []) - .directive('footable', ['$timeout', function($timeout) { - var events = { - beforeFiltering: 'footable_filtering' - }; - var extractSpecOpts = function(opts, attrs) { - var extracted = {}, - k; - for (k in opts) { - if (k !== 'filter' && (!angular.isUndefined(events[k]))) { - if(!angular.isFunction(scope.$eval(attrs[k]))) { - extracted[k] = attrs[k]; +/** + * License: MIT + */ +(function(angular) { + 'use strict'; + angular + .module('ui.footable', []) + .directive('footable', function() { + var events = { + beforeFiltering: 'footable_filtering' + }; + var extractSpecOpts = function(opts, attrs) { + var extracted = {}, + k; + for (k in opts) { + if (k !== 'filter' && (!angular.isUndefined(events[k]))) { + if(!angular.isFunction(scope.$eval(attrs[k]))) { + extracted[k] = attrs[k]; + } } } - } - return extracted; - }; + return extracted; + }; - var bindEventHandler = function(tableObj, scope, attrs) { - var k; - for (k in attrs) { - if (k !== 'filter' && (!angular.isUndefined(events[k]))) { - var targetEventName = events[k]; - if(angular.isFunction(scope.$eval(attrs[k]))) { - tableObj.bind(targetEventName, scope.$eval(attrs[k])); + var bindEventHandler = function(tableObj, scope, attrs) { + var k; + for (k in attrs) { + if (k !== 'filter' && (!angular.isUndefined(events[k]))) { + var targetEventName = events[k]; + if(angular.isFunction(scope.$eval(attrs[k]))) { + tableObj.bind(targetEventName, scope.$eval(attrs[k])); + } } } - } - }; + }; - return { - restrict: 'C', - link: function(scope, element, attrs) { - var tableOpts = { - 'event-filtering': null - }; - $timeout(function(){ + return { + restrict: 'C', + scope: { + loadWhen: '=' + }, + link: function(scope, element, attrs) { + var tableOpts = { + 'event-filtering': null + }; angular.extend( tableOpts, footable.options ); - angular.extend( tableOpts, extractSpecOpts(tableOpts, attrs) ); var tableObj = {}; - if(typeof element.footable === 'function'){ - tableObj = element.footable(tableOpts); + var initTable = function(){ + if(typeof element.footable === 'function'){ + tableObj = element.footable(tableOpts); + } else { + tableObj = jQuery(element).footable(tableOpts); + } + bindEventHandler(tableObj, scope, attrs); + }; + if(typeof attrs.loadWhen !== 'undefined'){ + scope.$watch(function(){return scope.loadWhen; }, function(data){ + if(typeof data!== 'undefined'&&data.length){ + initTable(); + } + }); } else { - tableObj = jQuery(element).footable(tableOpts); + initTable(); } - bindEventHandler(tableObj, scope, attrs); - scope.$watch(function() {return attrs.loadWhen; }, function(){ - $timeout(function(){ - element.triggerHandler('footable_redraw'); - }); - }); - },1000); - } - }; - }]); + } + }; + }); +})(angular); diff --git a/dist/angular-footable.min.js b/dist/angular-footable.min.js index 3592305..830f72d 100755 --- a/dist/angular-footable.min.js +++ b/dist/angular-footable.min.js @@ -1 +1 @@ -"use strict";angular.module("ui.footable",[]).directive("footable",["$timeout",function(n){var e={beforeFiltering:"footable_filtering"},t=function(n,t){var i,o={};for(i in n)"filter"===i||angular.isUndefined(e[i])||angular.isFunction(scope.$eval(t[i]))||(o[i]=t[i]);return o},i=function(n,t,i){var o;for(o in i)if("filter"!==o&&!angular.isUndefined(e[o])){var r=e[o];angular.isFunction(t.$eval(i[o]))&&n.bind(r,t.$eval(i[o]))}};return{restrict:"C",link:function(e,o,r){var a={"event-filtering":null};n(function(){angular.extend(a,footable.options),angular.extend(a,t(a,r));var l={};l="function"==typeof o.footable?o.footable(a):jQuery(o).footable(a),i(l,e,r),e.$watch(function(){return r.loadWhen},function(){n(function(){o.triggerHandler("footable_redraw")})})},1e3)}}}]); \ No newline at end of file +!function(n){"use strict";n.module("ui.footable",[]).directive("footable",function(){var e={beforeFiltering:"footable_filtering"},t=function(t,o){var i,f={};for(i in t)"filter"===i||n.isUndefined(e[i])||n.isFunction(scope.$eval(o[i]))||(f[i]=o[i]);return f},o=function(t,o,i){var f;for(f in i)if("filter"!==f&&!n.isUndefined(e[f])){var r=e[f];n.isFunction(o.$eval(i[f]))&&t.bind(r,o.$eval(i[f]))}};return{restrict:"C",scope:{loadWhen:"="},link:function(e,i,f){var r={"event-filtering":null};n.extend(r,footable.options),n.extend(r,t(r,f));var l={},a=function(){l="function"==typeof i.footable?i.footable(r):jQuery(i).footable(r),o(l,e,f)};"undefined"!=typeof f.loadWhen?e.$watch(function(){return e.loadWhen},function(n){"undefined"!=typeof n&&n.length&&a()}):a()}}})}(angular); \ No newline at end of file diff --git a/src/angular-footable.js b/src/angular-footable.js index 08ec352..fe5bc61 100644 --- a/src/angular-footable.js +++ b/src/angular-footable.js @@ -1,65 +1,75 @@ -'use strict'; - -angular - .module('ui.footable', []) - .directive('footable', ['$timeout', function($timeout) { - var events = { - beforeFiltering: 'footable_filtering' - }; - var extractSpecOpts = function(opts, attrs) { - var extracted = {}, - k; - for (k in opts) { - if (k !== 'filter' && (!angular.isUndefined(events[k]))) { - if(!angular.isFunction(scope.$eval(attrs[k]))) { - extracted[k] = attrs[k]; +/** + * License: MIT + */ +(function(angular) { + 'use strict'; + angular + .module('ui.footable', []) + .directive('footable', function() { + var events = { + beforeFiltering: 'footable_filtering' + }; + var extractSpecOpts = function(opts, attrs) { + var extracted = {}, + k; + for (k in opts) { + if (k !== 'filter' && (!angular.isUndefined(events[k]))) { + if(!angular.isFunction(scope.$eval(attrs[k]))) { + extracted[k] = attrs[k]; + } } } - } - return extracted; - }; + return extracted; + }; - var bindEventHandler = function(tableObj, scope, attrs) { - var k; - for (k in attrs) { - if (k !== 'filter' && (!angular.isUndefined(events[k]))) { - var targetEventName = events[k]; - if(angular.isFunction(scope.$eval(attrs[k]))) { - tableObj.bind(targetEventName, scope.$eval(attrs[k])); + var bindEventHandler = function(tableObj, scope, attrs) { + var k; + for (k in attrs) { + if (k !== 'filter' && (!angular.isUndefined(events[k]))) { + var targetEventName = events[k]; + if(angular.isFunction(scope.$eval(attrs[k]))) { + tableObj.bind(targetEventName, scope.$eval(attrs[k])); + } } } - } - }; + }; - return { - restrict: 'C', - link: function(scope, element, attrs) { - var tableOpts = { - 'event-filtering': null - }; - $timeout(function(){ + return { + restrict: 'C', + scope: { + loadWhen: '=' + }, + link: function(scope, element, attrs) { + var tableOpts = { + 'event-filtering': null + }; angular.extend( tableOpts, footable.options ); - angular.extend( tableOpts, extractSpecOpts(tableOpts, attrs) ); var tableObj = {}; - if(typeof element.footable === 'function'){ - tableObj = element.footable(tableOpts); + var initTable = function(){ + if(typeof element.footable === 'function'){ + tableObj = element.footable(tableOpts); + } else { + tableObj = jQuery(element).footable(tableOpts); + } + bindEventHandler(tableObj, scope, attrs); + }; + if(typeof attrs.loadWhen !== 'undefined'){ + scope.$watch(function(){return scope.loadWhen; }, function(data){ + if(typeof data!== 'undefined'&&data.length){ + initTable(); + } + }); } else { - tableObj = jQuery(element).footable(tableOpts); + initTable(); } - bindEventHandler(tableObj, scope, attrs); - scope.$watch(function() {return attrs.loadWhen; }, function(){ - $timeout(function(){ - element.triggerHandler('footable_redraw'); - }); - }); - },1000); - } - }; - }]); + } + }; + }); +})(angular);