Skip to content
This repository has been archived by the owner on May 21, 2021. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/0.3.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Burgmer committed Apr 9, 2014
2 parents 1a9f6b5 + 26db06e commit f4aa7f2
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons).
"laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
"laxcomma" : true, // Tolerate line breaking before ','
"bitwise" : true, // Prohibit bitwise operators (&, |, ^, etc.).
"bitwise" : false, // Prohibit bitwise operators (&, |, ^, etc.).
"boss" : false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
"curly" : true, // Require {} for every new block or scope.
"eqeqeq" : true, // Require triple equals i.e. `===`.
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
<a name="0.3.4"></a>
## 0.3.4 (2014-04-09)


### Bug Fixes

* **options:** do not identify options by index, otherwise changing options won't work ([0cb34def](https://github.com/pburgmer/w11k-select/commit/0cb34def4f357fe9b967b2f69a96dd2dd883ba64))


### Features

* **performance:** improve performance by not watching options deeply ([45428c6c](https://github.com/pburgmer/w11k-select/commit/45428c6c770c0ddee6b8e50a0b08f8ff613c471e))


<a name="0.3.3"></a>
## 0.3.3 (2014-04-08)

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "w11k-select",
"version": "0.3.3",
"version": "0.3.4",

"dependencies": {
"angular": "1.2.x",
Expand Down
6 changes: 4 additions & 2 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ angular.module('demo').controller('DemoCtrl', function ($scope) {

var amount = 10000;

var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0 1 2 3 4 5 6 7 8 9';
var chars = possible.split('');

function randomText(length) {
var text = '';
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0 1 2 3 4 5 6 7 8 9';

for (var i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
text += chars[Math.floor(Math.random() * chars.length)];
}

return text;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "w11k-select",
"version": "0.3.3",
"version": "0.3.4",

"description": "single- and multi-select directive for angularjs",
"keywords": [ "angular", "angularjs", "directive", "select", "multi-select", "bootstrap" ],
Expand Down
63 changes: 57 additions & 6 deletions src/w11k-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ angular.module('w11k.select').directive('w11kSelect', [

function filterOptions() {
if (hasBeenOpened) {
// false as third parameter: use contains to compare
optionsFiltered = filter(options, scope.filter.values, false);
scope.optionsToShow = limitTo(optionsFiltered, initialLimitTo);
}
Expand All @@ -274,9 +275,9 @@ angular.module('w11k.select').directive('w11kSelect', [
}
});

scope.$watch('filter.values', function () {
scope.$watch('filter.values.label', function () {
filterOptions();
}, true);
});

scope.clearFilter = function () {
scope.filter.values = {};
Expand Down Expand Up @@ -348,7 +349,7 @@ angular.module('w11k.select').directive('w11kSelect', [
var optionsExpParsed = optionParser.parse(optionsExp);

function collection2options(collection, viewValue) {
return collection.map(function (option, index) {
return collection.map(function (option) {
var optionValue = modelElement2value(option);
var optionLabel = modelElement2label(option);

Expand All @@ -361,7 +362,7 @@ angular.module('w11k.select').directive('w11kSelect', [
}

return {
index: index,
hash: hashCode(option).toString(36),
label: optionLabel,
model: option,
selected: selected
Expand Down Expand Up @@ -401,8 +402,7 @@ angular.module('w11k.select').directive('w11kSelect', [
if (angular.isDefined(newVal)) {
updateOptions();
}
},
true
}
);

// called on click to a checkbox of an option
Expand Down Expand Up @@ -552,6 +552,57 @@ angular.module('w11k.select').directive('w11kSelect', [

return optionsExpParsed.label(context);
}

// inspired by https://github.com/stuartbannerman/hashcode
var hashCode = (function () {
var stringHash = function (string) {
var result = 0;
for (var i = 0; i < string.length; i++) {
result = (((result << 5) - result) + string.charCodeAt(i)) | 0;
}
return result;
};

var primitiveHash = function (primitive) {
var string = primitive.toString();
return stringHash(string);
};

var objectHash = function (obj) {
var result = 0;
for (var property in obj) {
if (obj.hasOwnProperty(property)) {
result += primitiveHash(property + hash(obj[property]));
}
}
return result;
};

var hash = function (value) {
var typeHashes = {
'string' : stringHash,
'number' : primitiveHash,
'boolean' : primitiveHash,
'object' : objectHash
// functions are excluded because they are not representative of the state of an object
// types 'undefined' or 'null' will have a hash of 0
};

var type = typeof value;

if (value === null || value === undefined) {
return 0;
}
else if (typeHashes[type] !== undefined) {
return typeHashes[type](value) + primitiveHash(type);
}
else {
return 0;
}
};

return hash;
})();
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/w11k-select.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</div>
<div class="content" infinite-scroll="showMoreOptions()" infinite-scroll-distance="0.5">
<ul class="items list-unstyled">
<li bindonce="option" ng-repeat="option in optionsToShow track by option.index" ng-click="select(option)" ng-class="{'selected': option.selected }">
<li bindonce="option" ng-repeat="option in optionsToShow track by option.hash" ng-click="select(option)" ng-class="{'selected': option.selected }">
<div class="state">
<input type="checkbox" ng-model="option.selected" ng-change="onOptionStateChange()" ng-click="onOptionStateClick($event)">
</div>
Expand Down

0 comments on commit f4aa7f2

Please sign in to comment.