Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 31 additions & 17 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,28 @@ This file is generated by `grunt build`, do not edit it by hand.
coffee:
options:
join: true
compile:
jquery:
files:
'public/chosen.jquery.js': ['coffee/lib/select-parser.coffee', 'coffee/lib/abstract-chosen.coffee', 'coffee/chosen.jquery.coffee']
proto:
files:
'public/chosen.proto.js': ['coffee/lib/select-parser.coffee', 'coffee/lib/abstract-chosen.coffee', 'coffee/chosen.proto.coffee']
test:
files:
'spec/public/jquery_specs.js': 'spec/jquery/*.spec.coffee'
'spec/public/proto_specs.js': 'spec/proto/*.spec.coffee'

uglify:
options:
mangle:
except: ['jQuery', 'AbstractChosen', 'Chosen', 'SelectParser']
banner: '<%= minified_comments %>'
minified_chosen_js:
jquery:
options:
mangle:
except: ['jQuery']
files:
'public/chosen.jquery.min.js': ['public/chosen.jquery.js']
proto:
files:
'public/chosen.proto.min.js': ['public/chosen.proto.js']

sass:
Expand All @@ -65,41 +72,48 @@ This file is generated by `grunt build`, do not edit it by hand.
processors: [
require('autoprefixer')(browsers: 'last 2 versions, IE 8')
]
dist:
main:
src: 'public/chosen.css'

cssmin:
minified_chosen_css:
options:
banner: '<%= minified_comments %>'
keepSpecialComments: 0
options:
banner: '<%= minified_comments %>'
keepSpecialComments: 0
main:
src: 'public/chosen.css'
dest: 'public/chosen.min.css'

watch:
scripts:
default:
files: ['coffee/**/*.coffee', 'sass/*.scss']
tasks: ['build']
tasks: ['build', 'jasmine']
test:
files: ['spec/**/*.coffee']
tasks: ['jasmine']

jasmine:
jquery:
src: [ 'public/chosen.jquery.js' ]
options:
vendor: [ 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js' ]
vendor: [
'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js'
]
specs: 'spec/public/jquery_specs.js'
src: [ 'public/chosen.jquery.js' ]
proto:
src: [ 'public/chosen.proto.js' ]
options:
vendor: [
'https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js',
'public/docsupport/event.simulate.js'
'https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js'
'node_modules/simulant/dist/simulant.umd.js'
]
specs: 'spec/public/proto_specs.js'
src: [ 'public/chosen.proto.js' ]

grunt.loadTasks 'tasks'

grunt.registerTask 'default', ['build']
grunt.registerTask 'build', ['coffee', 'sass', 'concat', 'uglify', 'postcss', 'cssmin', 'package-bower']
grunt.registerTask 'build', ['coffee:jquery', 'coffee:proto', 'sass', 'concat', 'uglify', 'postcss', 'cssmin', 'package-bower']
grunt.registerTask 'test', ['coffee', 'jasmine']
grunt.registerTask 'test:jquery', ['coffee:test', 'coffee:jquery', 'jasmine:jquery']
grunt.registerTask 'test:proto', ['coffee:test', 'coffee:proto', 'jasmine:proto']


3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"grunt-postcss": "^0.7.1",
"grunt-sass": "^1.1.0",
"grunt-zip": "~0.9.2",
"load-grunt-tasks": "^3.0.0"
"load-grunt-tasks": "^3.0.0",
"simulant": "^0.2.2"
},
"contributors": [
{
Expand Down
64 changes: 0 additions & 64 deletions public/docsupport/event.simulate.js

This file was deleted.

5 changes: 3 additions & 2 deletions spec/proto/basic.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ describe "Basic setup", ->
expect($F(select)).toBe ""

container = div.down(".chosen-container")
container.simulate("mousedown") # open the drop
simulant.fire(container, "mousedown") # open the drop
expect(container.hasClassName("chosen-container-active")).toBe true

#select an item
container.select(".active-result").last().simulate("mouseup")
result = container.select(".active-result").last()
simulant.fire(result, "mouseup")

expect($F(select)).toBe "Afghanistan"
div.remove()
Expand Down
5 changes: 3 additions & 2 deletions spec/proto/events.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ describe "Events", ->
document.addEventListener 'change', -> event_sequence.push 'change'

container = div.down(".chosen-container")
container.simulate("mousedown") # open the drop
simulant.fire(container, "mousedown") # open the drop
expect(container.hasClassName("chosen-container-active")).toBe true

#select an item
container.select(".active-result").last().simulate("mouseup")
result = container.select(".active-result").last()
simulant.fire(result, "mouseup")

expect(event_sequence).toEqual ['input', 'change']
div.remove()
68 changes: 68 additions & 0 deletions spec/proto/max_shown_results.spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
describe 'search', ->
it 'should display only matching items when entering a search term', ->
tmpl = '''
<select data-placeholder="Choose a Country...">
<option value=""></option>
<option value="United States">United States</option>
<option value="United Kingdom">United Kingdom</option>
<option value="Afghanistan">Afghanistan</option>
</select>
'''
div = new Element('div')
document.body.insert(div)
div.update(tmpl)
select = div.down('select')
new Chosen(select)

container = div.down('.chosen-container')
simulant.fire(container, 'mousedown') # open the drop
# Expect all results to be shown
results = div.select('.active-result')
expect(results.length).toBe(3)

# Enter some text in the search field.
search_field = div.down('.chosen-search input')
search_field.value = 'Afgh'
simulant.fire(search_field, 'keyup')

# Expect to only have one result: 'Afghanistan'.
results = div.select('.active-result')
expect(results.length).toBe(1)
expect(results[0].innerText).toBe 'Afghanistan'

it 'should only show max_shown_results items in results', ->
tmpl = '''
<select data-placeholder="Choose a Country...">
<option value=""></option>
<option value="United States">United States</option>
<option value="United Kingdom">United Kingdom</option>
<option value="Afghanistan">Afghanistan</option>
</select>
'''
div = new Element('div')
document.body.insert(div)
div.update(tmpl)
select = div.down('select')
new Chosen(select, { max_shown_results: 1 })

container = div.down('.chosen-container')
simulant.fire(container, 'mousedown') # open the drop
results = div.select('.active-result')
expect(results.length).toBe(1)

# Enter some text in the search field.
search_field = div.down('.chosen-search input')
search_field.value = 'United'
simulant.fire(search_field, 'keyup')

# Showing only one result: the one that occurs first.
results = div.select('.active-result')
expect(results.length).toBe(1)
expect(results[0].innerText).toBe 'United States'

# Showing still only one result, but not the first one.
search_field.value = 'United Ki'
simulant.fire(search_field, 'keyup')
results = div.select('.active-result')
expect(results.length).toBe(1)
expect(results[0].innerText).toBe 'United Kingdom'