Import source for “1.7.1” from upstream tarball.
[debian_jquery-textcomplete.git] / src / main.js
blob81f80d3f56c3009a6ca61cf5a11cda2d164e2453
1 /*!
2 * jQuery.textcomplete
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
7 */
9 if (typeof jQuery === 'undefined') {
10 throw new Error('jQuery.textcomplete requires jQuery');
13 +function ($) {
14 'use strict';
16 var warn = function (message) {
17 if (console.warn) { console.warn(message); }
20 var id = 1;
22 $.fn.textcomplete = function (strategies, option) {
23 var args = Array.prototype.slice.call(arguments);
24 return this.each(function () {
25 var self = this;
26 var $this = $(this);
27 var completer = $this.data('textComplete');
28 if (!completer) {
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;
36 args.shift()
37 completer[strategies].apply(completer, args);
38 if (strategies === 'destroy') {
39 $this.removeData('textComplete');
41 } else {
42 // For backward compatibility.
43 // TODO: Remove at v0.4
44 $.each(strategies, function (obj) {
45 $.each(['header', 'footer', 'placement', 'maxCount'], function (name) {
46 if (obj[name]) {
47 completer.option[name] = obj[name];
48 warn(name + 'as a strategy param is deprecated. Use option.');
49 delete obj[name];
51 });
52 });
53 completer.register($.fn.textcomplete.Strategy.parse(strategies, {
54 el: self,
55 $el: $this
56 }));
58 });
61 }(jQuery);