4 * Repository: https://github.com/yuku-t/jquery-textcomplete
5 * License: MIT (https://github.com/yuku-t/jquery-textcomplete/blob/master/LICENSE)
6 * Author: Yuku Takahashi
9 if (typeof jQuery
=== 'undefined') {
10 throw new Error('jQuery.textcomplete requires jQuery');
16 var warn = function (message
) {
17 if (console
.warn
) { console
.warn(message
); }
22 $.fn
.textcomplete = function (strategies
, option
) {
23 var args
= Array
.prototype.slice
.call(arguments
);
24 return this.each(function () {
27 var completer
= $this.data('textComplete');
29 option
|| (option
= {});
30 option
._oid
= id
++; // unique object id
31 completer
= new $.fn
.textcomplete
.Completer(this, option
);
32 $this.data('textComplete', completer
);
34 if (typeof strategies
=== 'string') {
35 if (!completer
) return;
37 completer
[strategies
].apply(completer
, args
);
38 if (strategies
=== 'destroy') {
39 $this.removeData('textComplete');
42 // For backward compatibility.
43 // TODO: Remove at v0.4
44 $.each(strategies
, function (obj
) {
45 $.each(['header', 'footer', 'placement', 'maxCount'], function (name
) {
47 completer
.option
[name
] = obj
[name
];
48 warn(name
+ 'as a strategy param is deprecated. Use option.');
53 completer
.register($.fn
.textcomplete
.Strategy
.parse(strategies
, {