Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

updating addChip to handle each render() element, when an array is returned #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 43 additions & 35 deletions dist/angular-chips.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
return obj && angular.isFunction(obj.then);
}

function isArray(obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
}

/*
* update values to ngModel reference
*/
Expand Down Expand Up @@ -106,7 +110,7 @@
} else { updatedData = data }

if (!updatedData) {
return false;
return false;
}

if (isPromiseLike(updatedData)) {
Expand All @@ -115,6 +119,10 @@
});
scope.chips.list.push(new DeferChip(data, updatedData));
scope.$apply();
} else if(isArray(updatedData)){
for(var i = 0; i < updatedData.length; i++){
update(updatedData[i]);
}
} else {
update(updatedData);
}
Expand Down Expand Up @@ -271,6 +279,40 @@
}
})();

(function() {
angular.module('angular.chips')
.factory('DomUtil', function() {
return DomUtil;
});
/*Dom related functionality*/
function DomUtil(element) {
/*
* addclass will append class to the given element
* ng-class will do the same functionality, in our case
* we don't have access to scope so we are using this util methods
*/
var utilObj = {};

utilObj.addClass = function(className) {
utilObj.removeClass(element, className);
element.attr('class', element.attr('class') + ' ' + className);
return utilObj;
};

utilObj.removeClass = function(className) {
var classes = element.attr('class').split(' ');
var classIndex = classes.indexOf(className);
if (classIndex !== -1) {
classes.splice(classIndex, 1);
}
element.attr('class', classes.join(' '));
return utilObj;
};

return utilObj;
}
})();

(function() {
angular.module('angular.chips')
.directive('chipTmpl', ChipTmpl);
Expand Down Expand Up @@ -364,40 +406,6 @@
}
})();

(function() {
angular.module('angular.chips')
.factory('DomUtil', function() {
return DomUtil;
});
/*Dom related functionality*/
function DomUtil(element) {
/*
* addclass will append class to the given element
* ng-class will do the same functionality, in our case
* we don't have access to scope so we are using this util methods
*/
var utilObj = {};

utilObj.addClass = function(className) {
utilObj.removeClass(element, className);
element.attr('class', element.attr('class') + ' ' + className);
return utilObj;
};

utilObj.removeClass = function(className) {
var classes = element.attr('class').split(' ');
var classIndex = classes.indexOf(className);
if (classIndex !== -1) {
classes.splice(classIndex, 1);
}
element.attr('class', classes.join(' '));
return utilObj;
};

return utilObj;
}
})();

(function() {
ChipControlLinkFun.$inject = ["scope", "iElement", "iAttrs", "chipsCtrl"];
angular.module('angular.chips')
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-chips.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/js/directives/chips.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
return obj && angular.isFunction(obj.then);
}

function isArray(obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
}

/*
* update values to ngModel reference
*/
Expand Down Expand Up @@ -103,7 +107,7 @@
} else { updatedData = data }

if (!updatedData) {
return false;
return false;
}

if (isPromiseLike(updatedData)) {
Expand All @@ -112,6 +116,10 @@
});
scope.chips.list.push(new DeferChip(data, updatedData));
scope.$apply();
} else if(isArray(updatedData)){
for(var i = 0; i < updatedData.length; i++){
update(updatedData[i]);
}
} else {
update(updatedData);
}
Expand Down