fancy_select-rails 0.0.1

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MGE1ZTQ2Y2ZhOWQ4NzgxMTQ4OWUyNjFlOGNkNTE0NmQ2ZmU4N2JhMQ==
5
+ data.tar.gz: !binary |-
6
+ YzA2NTU1ZWQwNzU2YmRhNTkzZTQxZmMzNDhiMDA5ODc3OWY0YmNkNQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MjQyYzRhN2Q1NzFhZDRhODNiN2M0MzRmYTBjNzg1MzBiZWExZjY3MTNmMTkz
10
+ M2VhYTAwNDg1MjE0ZWFjN2IwNjc2NTIzZWI2MGY5YmRmMGI3OTg5YmVjY2Qy
11
+ ODVhOTFiMWUzNWFjNTBiZDUwMjc4MGI1MmQwYzdiNDg4NmUxNmI=
12
+ data.tar.gz: !binary |-
13
+ YzgwZWE4OWI1OTA2MjFmMmYyMWI5MzM2MWExM2U5YWNjYWU0MmI1MDEyZWIy
14
+ OTFlMjJhOTg1MGRiMjNjNWRlN2MwMWNjMGNhMjlmY2VkNWZlZmVhNTkxOTA1
15
+ ZmMwYTAyNjE1ODcxYzE3ZTdmNGM5Y2VlMDg5MzZlZDc4MDJiZjI=
@@ -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,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Stepan Parunashvili
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.
@@ -0,0 +1,5 @@
1
+ # FancySelect::Rails
2
+
3
+ Fancy Select Javascript Plugin for Rails. Big props to Octopus Creative
4
+
5
+ http://code.octopuscreative.com/fancyselect/
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fancy_select/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fancy_select-rails"
8
+ spec.version = FancySelect::Rails::VERSION
9
+ spec.authors = ["Stepan Parunashvili"]
10
+ spec.email = ["stepan.p@gmail.com"]
11
+ spec.description = %q{fancy_select.js for rails.}
12
+ spec.summary = %q{Using fancy_select.js from the folks at Octopus Creative.}
13
+ spec.homepage = "http://stepanp.com"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,8 @@
1
+ require "fancy_select/rails/version"
2
+
3
+ module FancySelect
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module FancySelect
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,193 @@
1
+ $ = window.jQuery || window.Zepto || window.$
2
+
3
+ $.fn.fancySelect = (opts = {}) ->
4
+ settings = $.extend({
5
+ forceiOS: false
6
+ includeBlank: false
7
+ optionTemplate: (optionEl) ->
8
+ return optionEl.text()
9
+ triggerTemplate: (optionEl) ->
10
+ return optionEl.text()
11
+ }, opts)
12
+
13
+ isiOS = !!navigator.userAgent.match /iP(hone|od|ad)/i
14
+
15
+ return this.each ->
16
+ sel = $(this)
17
+ return if sel.hasClass('fancified') || sel[0].tagName != 'SELECT'
18
+ sel.addClass('fancified')
19
+
20
+ # hide the native select
21
+ sel.css
22
+ width: 1
23
+ height: 1
24
+ display: 'block'
25
+ position: 'absolute'
26
+ top: 0
27
+ left: 0
28
+ opacity: 0
29
+
30
+ # some global setup stuff
31
+ sel.wrap '<div class="fancy-select">'
32
+ wrapper = sel.parent()
33
+
34
+ wrapper.addClass(sel.data('class')) if sel.data('class')
35
+
36
+ wrapper.append '<div class="trigger">'
37
+ wrapper.append '<ul class="options">' unless isiOS && !settings.forceiOS
38
+
39
+ trigger = wrapper.find '.trigger'
40
+ options = wrapper.find '.options'
41
+
42
+ # disabled in markup?
43
+ disabled = sel.prop('disabled')
44
+ if disabled
45
+ wrapper.addClass 'disabled'
46
+
47
+ updateTriggerText = ->
48
+ triggerHtml = settings.triggerTemplate(sel.find(':selected'))
49
+ trigger.html(triggerHtml)
50
+
51
+ sel.on 'blur.fs', ->
52
+ if trigger.hasClass 'open'
53
+ setTimeout ->
54
+ trigger.trigger 'close.fs'
55
+ , 120
56
+
57
+ trigger.on 'close.fs', ->
58
+ trigger.removeClass 'open'
59
+ options.removeClass 'open'
60
+
61
+ trigger.on 'click.fs', ->
62
+ unless disabled
63
+ trigger.toggleClass 'open'
64
+
65
+ # fancySelect defaults to using native selects with a styled trigger on mobile
66
+ # don't show the options if we're on mobile and haven't set `forceiOS`
67
+ if isiOS && !settings.forceiOS
68
+ if trigger.hasClass 'open'
69
+ sel.focus()
70
+ else
71
+ if trigger.hasClass 'open'
72
+ parent = trigger.parent()
73
+ offParent = parent.offsetParent()
74
+
75
+ # TODO 20 is very static
76
+ if (parent.offset().top + parent.outerHeight() + options.outerHeight() + 20) > $(window).height() + $(window).scrollTop()
77
+ options.addClass 'overflowing'
78
+ else
79
+ options.removeClass 'overflowing'
80
+
81
+ options.toggleClass 'open'
82
+
83
+ sel.focus() unless isiOS
84
+
85
+ sel.on 'enable', ->
86
+ sel.prop 'disabled', false
87
+ wrapper.removeClass 'disabled'
88
+ disabled = false
89
+ copyOptionsToList()
90
+
91
+ sel.on 'disable', ->
92
+ sel.prop 'disabled', true
93
+ wrapper.addClass 'disabled'
94
+ disabled = true
95
+
96
+ sel.on 'change.fs', (e) ->
97
+ if e.originalEvent && e.originalEvent.isTrusted
98
+ # discard firefox-only automatic event when hitting enter, we want to trigger our own
99
+ e.stopPropagation()
100
+ else
101
+ updateTriggerText()
102
+
103
+ # keyboard control
104
+ sel.on 'keydown', (e) ->
105
+ w = e.which
106
+ hovered = options.find('.hover')
107
+ hovered.removeClass('hover')
108
+
109
+ if !options.hasClass('open')
110
+ if w in [13, 32, 38, 40] # enter, space, up, down
111
+ e.preventDefault()
112
+ trigger.trigger 'click.fs'
113
+ else
114
+ if w == 38 # up
115
+ e.preventDefault()
116
+ if hovered.length && hovered.index() > 0 # move up
117
+ hovered.prev().addClass('hover')
118
+ else # move to bottom
119
+ options.find('li:last-child').addClass('hover')
120
+ else if w == 40 # down
121
+ e.preventDefault()
122
+ if hovered.length && hovered.index() < options.find('li').length - 1 # move down
123
+ hovered.next().addClass('hover')
124
+ else # move to top
125
+ options.find('li:first-child').addClass('hover')
126
+ else if w == 27 # escape
127
+ e.preventDefault()
128
+ trigger.trigger 'click.fs'
129
+ else if w in [13, 32] # enter, space
130
+ e.preventDefault()
131
+ hovered.trigger 'click.fs'
132
+ else if w == 9 # tab
133
+ if trigger.hasClass 'open' then trigger.trigger 'close.fs'
134
+
135
+ newHovered = options.find('.hover')
136
+ if newHovered.length
137
+ options.scrollTop 0
138
+ options.scrollTop newHovered.position().top - 12
139
+
140
+ # Handle item selection, and
141
+ # Add class selected to selected item
142
+ options.on 'click.fs', 'li', (e) ->
143
+ clicked = $(this)
144
+
145
+ sel.val(clicked.data('raw-value'))
146
+
147
+ sel.trigger('blur.fs').trigger('focus.fs') unless isiOS
148
+
149
+ options.find('.selected').removeClass('selected')
150
+ clicked.addClass 'selected'
151
+ return sel.val(clicked.data('raw-value')).trigger('change.fs').trigger('blur.fs').trigger('focus.fs')
152
+
153
+ # handle mouse selection
154
+ options.on 'mouseenter.fs', 'li', ->
155
+ nowHovered = $(this)
156
+ hovered = options.find('.hover')
157
+ hovered.removeClass 'hover'
158
+
159
+ nowHovered.addClass 'hover'
160
+
161
+ options.on 'mouseleave.fs', 'li', ->
162
+ options.find('.hover').removeClass('hover')
163
+
164
+ copyOptionsToList = ->
165
+ # update our trigger to reflect the select (it really already should, this is just a safety)
166
+ updateTriggerText()
167
+
168
+ return if isiOS && !settings.forceiOS
169
+
170
+ # snag current options before we add a default one
171
+ selOpts = sel.find 'option'
172
+
173
+ # generate list of options for the fancySelect
174
+
175
+ sel.find('option').each (i, opt) ->
176
+ opt = $(opt)
177
+
178
+ if !opt.prop('disabled') && (opt.val() || settings.includeBlank)
179
+ # Generate the inner HTML for the option from our template
180
+ optHtml = settings.optionTemplate(opt)
181
+
182
+ # Is there a select option on page load?
183
+ if opt.prop('selected')
184
+ options.append "<li data-raw-value=\"#{opt.val()}\" class=\"selected\">#{optHtml}</li>"
185
+ else
186
+ options.append "<li data-raw-value=\"#{opt.val()}\">#{optHtml}</li>"
187
+
188
+ # for updating the list of options after initialization
189
+ sel.on 'update.fs', ->
190
+ wrapper.find('.options').empty()
191
+ copyOptionsToList()
192
+
193
+ copyOptionsToList()
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fancy_select-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Stepan Parunashvili
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-10 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: fancy_select.js for rails.
42
+ email:
43
+ - stepan.p@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - fancy_select-rails.gemspec
54
+ - lib/fancy_select/rails.rb
55
+ - lib/fancy_select/rails/version.rb
56
+ - vendor/assets/javascripts/fancy_select.js.coffee
57
+ homepage: http://stepanp.com
58
+ licenses:
59
+ - MIT
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.2.1
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Using fancy_select.js from the folks at Octopus Creative.
81
+ test_files: []