Permalink
Browse files

fixes #20 {cacheType: false} disables the cache

  • Loading branch information...
fabiomcosta committed Dec 16, 2012
1 parent 35b7f95 commit 40e71d09301df8d4edfe87f6d70fdd7b35ab90bb
Showing with 34 additions and 13 deletions.
  1. +13 −5 README.md
  2. +13 −1 Source/Meio.Autocomplete.Cache.js
  3. +4 −2 Source/Meio.Autocomplete.js
  4. +4 −5 Specs/user/index.html
View
@@ -96,18 +96,19 @@ Options, Events.
* **delay** - (number: defaults to 200) The delay before rendering the list of options. Usefull when you are using the autocomplete with ajax
* **minChars** - (number: defaults to 0) The minimum number of characters the user has to input before the list of options to select is shown.
+* **cacheType** - (mixed: defaults to 'shared') Can be 'shared' or 'own'.
+ * **'shared'** - The cache instance will be shared with other Meio.Autocomplete instances in the same page.
+ * **'own'** - The Meio.Autocomplete instance will have its own cache.
+ * **false** - Disables cache.
* **cacheLength** - (number: defaults to 20) The cache length. Cache will decrease the number of ajax calls. Each time you make a different query it will be cached locally.
-* **cacheType** - (string: defaults to 'shared') Can be 'shared' or 'own'.
- * **shared** - The cache instance will be shared with other Meio.Autocomplete instances in the same page.
- * **own** - The Meio.Autocomplete instance will have its own cache.
* **selectOnTab** - (boolean: defaults to true) If the user press the 'tab' key, the current focused option will be selected.
-* **autoFocus** - (boolean: defaults to true) Auto focus if there is only one option. Also selects this one option if element is not active (user moved to other field while request running).
+* **autoFocus** - (boolean: defaults to false) Auto focus first option if there is only one option. Also selects this one option if element is not active (user moved to other field while request running).
* **maxVisibleItems** - (number: defaults to 10) Defines the height of the list. If its 10, for example, the list will have its height adjusted to show 10 options, but you can still scroll to the others.
* **filter** - (object) The filter options. Its posible to pass the filter functions directly or by passing a type and optionaly a path.
* **type** - (string: defaults to 'contains') If 'contains' is used, the items that contains the inputted text will be listed. If 'startswith' is used, only the items that starts with the inputted text will be listed. You can still define your own filter using the Meio.Autocomplete.Filter.define method, see the code to understand how it works.
* **path** - (string: default to '') Should define the path to the text key into the objects that are in the data array. Ex: 'a.b.c' will get the 'c' key from the object {a: {b: {c: 'some-text'}}}.
* or
- * **filter** - (function(text, data)) Filters the data array. It should return true if the 'data' should be listed while the passed 'text' is inputted in the field.
+ * **filter** - (function(text, data)) Filters the data array. It should return true if the 'data' should be listed while the passed 'text' is inputted in the field.
* **formatMatch** - (function(text, data, i)) This function should return the text that will be matched with the current inputted text into the field.
* **formatItem** - (function(text, data)) The return of this function will be applied to the 'html' of the li's into the list.
* **fieldOptions** - (object) The options that are gonna be applied to the field element.
@@ -195,6 +196,13 @@ Inspiration and some ideas came from:
Changelog
---------
+##### 2.0.1
+
+* Moved full Documentation to Github.
+* NEW: **cacheType** option now can be false, which completely disables cache.
+* NEW: **autoFocus** option (boolean: defaults to true) Auto focus first option if there is only one.
+Also selects this one option if element is not active (user moved to other field while request running).
+
##### 2.0
* This is basically the same as 1.0 but with full support for Mootools 1.3 and greater.
@@ -21,7 +21,7 @@ provides: [Meio.Autocomplete.Cache]
global.Meio.Autocomplete = global.Meio.Autocomplete || {};
- global.Meio.Autocomplete.Cache = new Class({
+ var Cache = global.Meio.Autocomplete.Cache = new Class({
initialize: function(maxLength) {
this.refresh();
@@ -64,6 +64,18 @@ provides: [Meio.Autocomplete.Cache]
});
+ global.Meio.Autocomplete.FakeCache = new Class({
+ Extends: Cache,
+
+ get: function() {
+ return null;
+ },
+
+ set: function() {
+ return this;
+ }
+ });
+
global.Meio.Autocomplete.Cache.instance = new Meio.Autocomplete.Cache();
}(this));
@@ -185,7 +185,7 @@ provides: [Meio.Autocomplete]
data = data.get();
var itemsHtml = [], itemsData = [], classes = list.options.classes, text = this.inputedText;
var filter = this.filters.filter, formatMatch = this.filters.formatMatch, formatItem = this.filters.formatItem;
- for (var row, i = 0, n = 0; row = data[i++];) if (filter.call(this, text, row)) {
+ for (var row, i = 0, n = 0; (row = data[i++]);) if (filter.call(this, text, row)) {
itemsHtml.push(
'<li title="', encode(formatMatch.call(this, text, row)),
'" data-index="', n,
@@ -287,8 +287,10 @@ provides: [Meio.Autocomplete]
if (this.options.cacheType == 'shared') {
this.cache = Meio.Autocomplete.Cache.instance;
this.cache.setMaxLength(cacheLength);
- } else { // 'own'
+ } else if (this.options.cacheType == 'own') { // 'own'
this.cache = new Meio.Autocomplete.Cache(cacheLength);
+ } else { // deactivates cache
+ this.cache = new Meio.Autocomplete.FakeCache();
}
},
View
@@ -149,7 +149,6 @@
<br />
<br />
<br />
-
<form>
<div>
New Jersey:
@@ -169,7 +168,6 @@
<a title="Test refreshAll" href="#" onclick="instance.refreshAll(); return false;">Test refreshAll</a>
</form>
-
<script>
var data = '../fixtures/data.txt';
@@ -203,6 +201,7 @@
syncName: 'id',
valueField: $('some1'),
selectOnTab: false,
+ cacheType: false,
onNoItemToList: function(elements) {
elements.field.node.highlight('#ff0000');
},
@@ -211,13 +210,13 @@
path: 'text'
},
onSelect: function(elements, data) {
- console.log('hell yeah');
-
+ console.log('onSelect');
[$('some4')].each(function(el){
el.set('value', data.text);
});
},
onDeselect: function(elements) {
+ console.log('onDeselect');
[$('some4')].each(function(el){
el.set('value', '');
});
@@ -227,7 +226,7 @@
{
name: $('some2').get('name'),
value: function() {
- return $('some2').get('value')
+ return $('some2').get('value');
}
},
$('some3')

0 comments on commit 40e71d0

Please sign in to comment.