simple_auto_complete 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simple_auto_complete.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # SimpleAutoComplete
2
+
3
+ The most simple gem for text field auto complete. You only have to specify what collection you want to use for autocompletion.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'simple_auto_complete'
10
+
11
+ And then execute:
12
+
13
+ $ bundle install
14
+
15
+ Add this line to application.js:
16
+
17
+ //= require simple_auto_complete
18
+
19
+
20
+
21
+ Add this line to application.css:
22
+
23
+ *= require simple_auto_complete
24
+
25
+ ## Usage
26
+
27
+ Example 1:
28
+
29
+ #in controller:
30
+ @days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Satturday", "Sunday"]
31
+
32
+ #in view:
33
+ <%= text_field_tag_with_auto_complete :day, "", @days, id: "day_name" %>
34
+
35
+ Parameters are the same like text_field_tag has, but collection parameter (@days) that is put on third position
36
+
37
+ Example 2:
38
+
39
+ <%= f.text_field_with_auto_complete :country, @countries, {} %>
40
+
41
+
42
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,30 @@
1
+ require "simple_auto_complete/version"
2
+
3
+ module SimpleAutoComplete
4
+
5
+ class Engine < Rails::Engine
6
+ end
7
+
8
+ class ActionView::Helpers::FormBuilder
9
+ def text_field_with_auto_complete(method, collection = [], options = {})
10
+ helpers.content_tag :div,
11
+ @template.text_field(@object_name, method, options) +
12
+ helpers.content_tag(:div, helpers.content_tag(:ul, "", :class => "select-ul"), :class => "select-list"),
13
+ :class => "auto-complete", "data-list" => collection.to_s
14
+ end
15
+
16
+ def helpers
17
+ ActionController::Base.helpers
18
+ end
19
+ end
20
+
21
+ module ActionView::Helpers::FormTagHelper
22
+ def text_field_tag_with_auto_complete(name, value = nil, collection = [], options = {})
23
+ content_tag :div,
24
+ text_field_tag(name, value, options) +
25
+ content_tag(:div, content_tag(:ul, "", :class => "select-ul"), :class => "select-list"),
26
+ :class => "auto-complete", "data-list" => collection.to_s
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleAutoComplete
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simple_auto_complete/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "simple_auto_complete"
8
+ gem.version = SimpleAutoComplete::VERSION
9
+ gem.authors = ["Anton Chumakov"]
10
+ gem.email = ["anton@chumakoff.com"]
11
+ gem.description = %q{The most simple gem for text field auto complete}
12
+ gem.summary = %q{Text field auto complete}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_dependency('sass-rails', '~> 3.2.3')
20
+ gem.add_dependency('coffee-rails', '~> 3.2.1')
21
+ end
@@ -0,0 +1,53 @@
1
+
2
+ $ ->
3
+
4
+ input = null
5
+
6
+ $('.auto-complete input').blur ->
7
+ unless input != null and input[0] == $(this)[0]
8
+ parent = $(this).parent('.auto-complete')
9
+ parent.children('.select-list').hide()
10
+
11
+ $('.auto-complete input').focus ->
12
+ generate_list(this)
13
+
14
+ $('.auto-complete').on('click', 'li.select-li', ->
15
+ $(this).parents('.auto-complete').children('input').val($(this).html())
16
+ $(this).parents('.select-list').hide()
17
+ )
18
+
19
+ $('.select-list').hover(
20
+ ->
21
+ input = $(this).parents('.auto-complete').children('input')
22
+ ->
23
+ input = null
24
+ )
25
+
26
+ $('.auto-complete input').keyup ->
27
+ generate_list(this)
28
+
29
+
30
+ generate_list = (obj) ->
31
+ val = $(obj).val()
32
+ parent = $(obj).parent('.auto-complete')
33
+ list = parent.children('.select-list')
34
+ ul = list.find("ul")
35
+ if ( val.length != 0 )
36
+ ar = parent.data("list")
37
+ if ( ar.length > 0 )
38
+ ul.html("")
39
+ n = 0
40
+ $.each(ar, ->
41
+ if (this.toLowerCase().indexOf(val.toLowerCase()) >= 0)
42
+ n++
43
+ ul.append("<li class='select-li'>"+this+"</li>")
44
+ )
45
+ if n > 0
46
+ list.show()
47
+ else
48
+ list.hide()
49
+ else
50
+ list.hide()
51
+ else
52
+ list.hide()
53
+
@@ -0,0 +1,26 @@
1
+ .auto-complete
2
+ position: relative
3
+
4
+ .select-list
5
+ display: none
6
+ position: absolute
7
+ top: 100%
8
+ left: 0
9
+ padding: 0
10
+ border: 1px solid black
11
+ z-index: 100
12
+
13
+ ul.select-ul
14
+ margin: 0
15
+ padding: 0
16
+ background: white
17
+
18
+ li.select-li
19
+ margin: 0
20
+ padding: 2px 5px
21
+ cursor: pointer
22
+ list-style: none
23
+ text-align: left
24
+
25
+ &:hover
26
+ background: gold
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_auto_complete
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Anton Chumakov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sass-rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.3
30
+ - !ruby/object:Gem::Dependency
31
+ name: coffee-rails
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 3.2.1
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 3.2.1
46
+ description: The most simple gem for text field auto complete
47
+ email:
48
+ - anton@chumakoff.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - lib/simple_auto_complete.rb
59
+ - lib/simple_auto_complete/version.rb
60
+ - simple_auto_complete.gemspec
61
+ - vendor/assets/javascripts/simple_auto_complete/index.js.coffee
62
+ - vendor/assets/stylesheets/simple_auto_complete/index.css.sass
63
+ homepage: ''
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.24
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Text field auto complete
87
+ test_files: []