ajax-autocomplete-rails 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/README.md +23 -0
- data/Rakefile +2 -0
- data/ajax-autocomplete-rails.gemspec +31 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/ajax/autocomplete/rails.rb +9 -0
- data/lib/ajax/autocomplete/rails/version.rb +7 -0
- data/vendor/assets/javascripts/ajax.autocomplete.js +147 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8ab6a28c74c259650b7cf0aeade1f6115e6b6ba4
|
4
|
+
data.tar.gz: e664d537de45a62cb1eaf7ac58fe508dd63cb1ff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 65d80c3d93993e3b91f64a8fdc2e1dcdce9f974f23357f7a345f573bef02e926d81f98eb218b06f91cd83a44b099af3eb7409e837f319a0785d3e822473e6360
|
7
|
+
data.tar.gz: 3cb01fded3859787419002c61b34d7f2f39940aa21070d6433f5e4da1581afbdf0323958bc2f7375f6e23cad8e1766f4ed08c3d11b1e97b69a31f1f9369d07f8
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Ajax-Autocomplete-Rails
|
2
|
+
|
3
|
+
## Usage
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'ajax-autocomplete-rails'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ajax-autocomplete-rails
|
18
|
+
|
19
|
+
Add the following directive to your Javascript manifest file (application.js):
|
20
|
+
|
21
|
+
//= require ajax-autocomplete
|
22
|
+
|
23
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ajax/autocomplete/rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ajax-autocomplete-rails"
|
8
|
+
spec.version = Ajax::Autocomplete::Rails::VERSION
|
9
|
+
spec.authors = ["mtuck063"]
|
10
|
+
spec.email = ["meneliktucker@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Ajax autocompleter"
|
13
|
+
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
14
|
+
spec.homepage = "https://github.com/mtuck063/ajax-autocomplete-rails"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
# if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
# else
|
21
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
# end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ajax/autocomplete/rails"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
(function($) {
|
2
|
+
"use strict";
|
3
|
+
|
4
|
+
function Autocomplete(options){
|
5
|
+
options = $.extend({
|
6
|
+
data : null
|
7
|
+
}, options);
|
8
|
+
|
9
|
+
$(this).each(function(){
|
10
|
+
|
11
|
+
var $autocomplete = $(this);
|
12
|
+
|
13
|
+
if($autocomplete.hasClass('initialized')){
|
14
|
+
return false;
|
15
|
+
}
|
16
|
+
|
17
|
+
//deep copy the options object for every element
|
18
|
+
$autocomplete.options = $.extend(true, {}, options);
|
19
|
+
|
20
|
+
var onKeyDown = function(e){
|
21
|
+
$autocomplete.highlighted = $autocomplete.highlighted || $autocomplete.dropdown.find('.highlighted');
|
22
|
+
|
23
|
+
// TAB
|
24
|
+
if(e.which === 9){
|
25
|
+
$autocomplete.trigger('close');
|
26
|
+
$autocomplete.set();
|
27
|
+
}
|
28
|
+
|
29
|
+
// ENTER
|
30
|
+
if(e.which === 13){
|
31
|
+
e.preventDefault();
|
32
|
+
$autocomplete.trigger('close');
|
33
|
+
if($autocomplete.highlighted.length !== 0) $autocomplete.set($autocomplete.highlighted.text());
|
34
|
+
}
|
35
|
+
|
36
|
+
// ESC
|
37
|
+
if(e.which === 27){
|
38
|
+
$autocomplete.trigger('close');
|
39
|
+
}
|
40
|
+
|
41
|
+
// ARROW DOWN
|
42
|
+
if(e.which === 40){
|
43
|
+
if($autocomplete.highlighted.length === 0){
|
44
|
+
$autocomplete.highlighted = $autocomplete.dropdown.children().first();
|
45
|
+
$autocomplete.highlighted.toggleClass("highlighted");
|
46
|
+
return;
|
47
|
+
}
|
48
|
+
|
49
|
+
$autocomplete.highlighted.toggleClass("highlighted");
|
50
|
+
$autocomplete.highlighted = $autocomplete.highlighted.next().toggleClass("highlighted");
|
51
|
+
}
|
52
|
+
|
53
|
+
// ARROW UP
|
54
|
+
if(e.which === 38){
|
55
|
+
if($autocomplete.highlighted.length === 0){
|
56
|
+
$autocomplete.highlighted = $autocomplete.dropdown.children().last();
|
57
|
+
$autocomplete.highlighted.toggleClass("highlighted");
|
58
|
+
return;
|
59
|
+
}
|
60
|
+
|
61
|
+
$autocomplete.highlighted.toggleClass("highlighted");
|
62
|
+
$autocomplete.highlighted = $autocomplete.highlighted.prev().toggleClass("highlighted");
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
$autocomplete.on({
|
67
|
+
'keyup focus click' : function(e){
|
68
|
+
if([9,13,27,38,40].indexOf(e.which) !== -1 || $autocomplete.val() === "") return;
|
69
|
+
var autocompleteValue = $autocomplete.val();
|
70
|
+
|
71
|
+
if(typeof $autocomplete.options.data === "function"){
|
72
|
+
$autocomplete.options.data.call($autocomplete, autocompleteValue);
|
73
|
+
}
|
74
|
+
},
|
75
|
+
'open' : function(){
|
76
|
+
$autocomplete.wrapper.toggleClass('active');
|
77
|
+
$autocomplete.active = true;
|
78
|
+
$(document).on('click.close-autocomplete', function(e){
|
79
|
+
if(e.target !== $autocomplete[0] && e.target !== $autocomplete.dropdown[0]) $autocomplete.trigger('close');
|
80
|
+
});
|
81
|
+
},
|
82
|
+
'close' : function(){
|
83
|
+
$autocomplete.wrapper.toggleClass('active');
|
84
|
+
$autocomplete.active = false;
|
85
|
+
$autocomplete.dropdown.empty();
|
86
|
+
$(document).off('click.close-autocomplete');
|
87
|
+
},
|
88
|
+
'init' : function(){
|
89
|
+
// Disable default browser autocomplete
|
90
|
+
$autocomplete.attr('autocomplete', 'off');
|
91
|
+
$autocomplete.addClass('initialized');
|
92
|
+
|
93
|
+
$autocomplete.wrap('<div class="autocomplete-wrapper">');
|
94
|
+
$autocomplete.wrapper = $autocomplete.parent();
|
95
|
+
$autocomplete.addClass('autocomplete-textfield');
|
96
|
+
$autocomplete.wrapper.append('<ul class="autocomplete-dropdown">');
|
97
|
+
$autocomplete.dropdown = $autocomplete.wrapper.find('.autocomplete-dropdown');
|
98
|
+
},
|
99
|
+
'populate:dropdown' : function(){
|
100
|
+
var dropdownOptions = "";
|
101
|
+
$.each($autocomplete.options.results, function(){
|
102
|
+
dropdownOptions += '<li>'+ this +'</li>';
|
103
|
+
});
|
104
|
+
$autocomplete.dropdown
|
105
|
+
.html(dropdownOptions)
|
106
|
+
.find('li').click(function(){
|
107
|
+
$autocomplete.trigger('close');
|
108
|
+
$autocomplete.set(this.innerText);
|
109
|
+
});
|
110
|
+
},
|
111
|
+
'keydown' : onKeyDown
|
112
|
+
});
|
113
|
+
|
114
|
+
$autocomplete.set = function(value){
|
115
|
+
value = typeof value == 'undefined' ? $autocomplete.input.val() : value
|
116
|
+
$autocomplete.val(value);
|
117
|
+
|
118
|
+
// Trigger change event for React input autocomplete fields
|
119
|
+
var event = new Event('input', { bubbles: true });
|
120
|
+
$autocomplete[0].dispatchEvent(event);
|
121
|
+
}
|
122
|
+
|
123
|
+
$autocomplete.parseData = function(){
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
$autocomplete.setData = function(data){
|
128
|
+
$autocomplete.options.results = data;
|
129
|
+
$autocomplete.trigger('populate:dropdown');
|
130
|
+
if(!$autocomplete.active) $autocomplete.trigger('open');
|
131
|
+
}
|
132
|
+
|
133
|
+
$autocomplete.trigger('init');
|
134
|
+
|
135
|
+
});
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
$.fn.autocomplete = function(method){
|
140
|
+
if ( typeof method === 'object' ) {
|
141
|
+
return Autocomplete.apply(this, arguments );
|
142
|
+
} else {
|
143
|
+
$.error('An object for instantiation is needed.');
|
144
|
+
}
|
145
|
+
};
|
146
|
+
|
147
|
+
})(jQuery);
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ajax-autocomplete-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mtuck063
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- meneliktucker@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- ajax-autocomplete-rails.gemspec
|
53
|
+
- bin/console
|
54
|
+
- bin/setup
|
55
|
+
- lib/ajax/autocomplete/rails.rb
|
56
|
+
- lib/ajax/autocomplete/rails/version.rb
|
57
|
+
- vendor/assets/javascripts/ajax.autocomplete.js
|
58
|
+
homepage: https://github.com/mtuck063/ajax-autocomplete-rails
|
59
|
+
licenses: []
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.4.6
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Ajax autocompleter
|
81
|
+
test_files: []
|