Skip to content

Commit

Permalink
Merge remote-tracking branch 'harvesthq/master' into option_adding
Browse files Browse the repository at this point in the history
  • Loading branch information
koenpunt committed Feb 5, 2018
2 parents 33dabcf + 87d4ecd commit 1aa7e9a
Show file tree
Hide file tree
Showing 27 changed files with 9,037 additions and 2,370 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Tell us how to reproduce this issue.

3. Further steps, etc.

Additionally, please link to a working demo that shows the issue so we can attempt to reproduce. You can use [this template](https://jsfiddle.net/5v3v353z/) as a base. Alternatively, confirm that the [Chosen demo page](http://harvesthq.github.io/chosen/) shows the issue.
Additionally, please link to a working demo that shows the issue so we can attempt to reproduce. You can use [this template](https://jsfiddle.net/j7k727cp/) as a base. Alternatively, confirm that the [Chosen demo page](http://harvesthq.github.io/chosen/) shows the issue.


### Expected behavior
Expand Down
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ sudo: false
language: node_js

node_js:
- "node"
- 6
- node

addons:
apt:
Expand All @@ -12,11 +13,16 @@ addons:
packages:
- git

matrix:
fast_finish: true
allow_failures:
- node_js: node

before_install: npm install -g grunt-cli
before_script: grunt build package-npm package-bower

after_success: ./publish-package.sh

env:
global:
secure: FHc3fAbJDydJywQ3HcFrTxqyAmmKbiAwP5Bi3qIzvXXCKNYbZb45iSjrMPFq7sHQR/evxDKl3zzBd8k6lvx0Sr77GDkmbN7HjI22fb3wu1Pi3WhmIM90/70ATs6hSZunsNEHCtQa4fDFM3NYeOeiwHFX8HQ9tVlqtjeAZngONL8=
secure: "SOYNh0YO4eLAM38FQxrg7iqytXgdjJHRkmj/1lFzGrGeuuXP6Owe/2TaMyTJXWb9nHAAtRRwQyhAUE07eKhxI6b3YNyozeRulMK4B0K8P3P1B2MslpROyvQYtZupno3dWc0tyvsQ3ucnZE25mtetH6KYcwiI+vHv6hT8HnzBnp0="
19 changes: 14 additions & 5 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = (grunt) ->
require('load-grunt-tasks')(grunt)
grunt.loadNpmTasks('grunt1.0-dom-munger') # the naming convention of the package does not allow auto-discovery.

grunt.initConfig
pkg: grunt.file.readJSON('package.json')
Expand Down Expand Up @@ -52,8 +53,9 @@ This file is generated by `grunt build`, do not edit it by hand.
banner: '<%= minified_comments %>'
jquery:
options:
ie8: true
mangle:
except: ['jQuery']
reserved: ['jQuery']
files:
'public/chosen.jquery.min.js': ['public/chosen.jquery.js']
proto:
Expand Down Expand Up @@ -95,14 +97,21 @@ This file is generated by `grunt build`, do not edit it by hand.
jquery:
options:
vendor: [
'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js'
'public/docsupport/jquery-3.2.1.min.js'
]
specs: 'spec/public/jquery_specs.js'
src: [ 'public/chosen.jquery.js' ]
jquery_old:
options:
vendor: [
'public/docsupport/jquery-1.12.4.min.js'
]
specs: 'spec/public/jquery_specs.js'
src: [ 'public/chosen.jquery.js' ]
proto:
options:
vendor: [
'https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js'
'public/docsupport/prototype-1.7.0.0.js'
'node_modules/simulant/dist/simulant.umd.js'
]
specs: 'spec/public/proto_specs.js'
Expand All @@ -111,9 +120,9 @@ This file is generated by `grunt build`, do not edit it by hand.
grunt.loadTasks 'tasks'

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


2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Chosen is a library for making long, unwieldy select boxes more user friendly.

- jQuery support: 1.4+
- jQuery support: 1.7+
- Prototype support: 1.7+

For **documentation**, usage, and examples, see:
Expand Down
99 changes: 54 additions & 45 deletions coffee/chosen.jquery.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -71,43 +71,43 @@ class Chosen extends AbstractChosen
@form_field_jq.trigger("chosen:ready", {chosen: this})

register_observers: ->
@container.bind 'touchstart.chosen', (evt) => this.container_mousedown(evt); return
@container.bind 'touchend.chosen', (evt) => this.container_mouseup(evt); return

@container.bind 'mousedown.chosen', (evt) => this.container_mousedown(evt); return
@container.bind 'mouseup.chosen', (evt) => this.container_mouseup(evt); return
@container.bind 'mouseenter.chosen', (evt) => this.mouse_enter(evt); return
@container.bind 'mouseleave.chosen', (evt) => this.mouse_leave(evt); return

@search_results.bind 'mouseup.chosen', (evt) => this.search_results_mouseup(evt); return
@search_results.bind 'mouseover.chosen', (evt) => this.search_results_mouseover(evt); return
@search_results.bind 'mouseout.chosen', (evt) => this.search_results_mouseout(evt); return
@search_results.bind 'mousewheel.chosen DOMMouseScroll.chosen', (evt) => this.search_results_mousewheel(evt); return

@search_results.bind 'touchstart.chosen', (evt) => this.search_results_touchstart(evt); return
@search_results.bind 'touchmove.chosen', (evt) => this.search_results_touchmove(evt); return
@search_results.bind 'touchend.chosen', (evt) => this.search_results_touchend(evt); return

@form_field_jq.bind "chosen:updated.chosen", (evt) => this.results_update_field(evt); return
@form_field_jq.bind "chosen:activate.chosen", (evt) => this.activate_field(evt); return
@form_field_jq.bind "chosen:open.chosen", (evt) => this.container_mousedown(evt); return
@form_field_jq.bind "chosen:close.chosen", (evt) => this.close_field(evt); return

@search_field.bind 'blur.chosen', (evt) => this.input_blur(evt); return
@search_field.bind 'keyup.chosen', (evt) => this.keyup_checker(evt); return
@search_field.bind 'keydown.chosen', (evt) => this.keydown_checker(evt); return
@search_field.bind 'focus.chosen', (evt) => this.input_focus(evt); return
@search_field.bind 'cut.chosen', (evt) => this.clipboard_event_checker(evt); return
@search_field.bind 'paste.chosen', (evt) => this.clipboard_event_checker(evt); return
@container.on 'touchstart.chosen', (evt) => this.container_mousedown(evt); return
@container.on 'touchend.chosen', (evt) => this.container_mouseup(evt); return

@container.on 'mousedown.chosen', (evt) => this.container_mousedown(evt); return
@container.on 'mouseup.chosen', (evt) => this.container_mouseup(evt); return
@container.on 'mouseenter.chosen', (evt) => this.mouse_enter(evt); return
@container.on 'mouseleave.chosen', (evt) => this.mouse_leave(evt); return

@search_results.on 'mouseup.chosen', (evt) => this.search_results_mouseup(evt); return
@search_results.on 'mouseover.chosen', (evt) => this.search_results_mouseover(evt); return
@search_results.on 'mouseout.chosen', (evt) => this.search_results_mouseout(evt); return
@search_results.on 'mousewheel.chosen DOMMouseScroll.chosen', (evt) => this.search_results_mousewheel(evt); return

@search_results.on 'touchstart.chosen', (evt) => this.search_results_touchstart(evt); return
@search_results.on 'touchmove.chosen', (evt) => this.search_results_touchmove(evt); return
@search_results.on 'touchend.chosen', (evt) => this.search_results_touchend(evt); return

@form_field_jq.on "chosen:updated.chosen", (evt) => this.results_update_field(evt); return
@form_field_jq.on "chosen:activate.chosen", (evt) => this.activate_field(evt); return
@form_field_jq.on "chosen:open.chosen", (evt) => this.container_mousedown(evt); return
@form_field_jq.on "chosen:close.chosen", (evt) => this.close_field(evt); return

@search_field.on 'blur.chosen', (evt) => this.input_blur(evt); return
@search_field.on 'keyup.chosen', (evt) => this.keyup_checker(evt); return
@search_field.on 'keydown.chosen', (evt) => this.keydown_checker(evt); return
@search_field.on 'focus.chosen', (evt) => this.input_focus(evt); return
@search_field.on 'cut.chosen', (evt) => this.clipboard_event_checker(evt); return
@search_field.on 'paste.chosen', (evt) => this.clipboard_event_checker(evt); return

if @is_multiple
@search_choices.bind 'click.chosen', (evt) => this.choices_click(evt); return
@search_choices.on 'click.chosen', (evt) => this.choices_click(evt); return
else
@container.bind 'click.chosen', (evt) -> evt.preventDefault(); return # gobble click of anchor
@container.on 'click.chosen', (evt) -> evt.preventDefault(); return # gobble click of anchor

destroy: ->
$(@container[0].ownerDocument).unbind 'click.chosen', @click_test_action
@form_field_label.unbind 'click.chosen' if @form_field_label.length > 0
$(@container[0].ownerDocument).off 'click.chosen', @click_test_action
@form_field_label.off 'click.chosen' if @form_field_label.length > 0

if @search_field[0].tabIndex
@form_field_jq[0].tabIndex = @search_field[0].tabIndex
Expand All @@ -123,12 +123,12 @@ class Chosen extends AbstractChosen
@search_field[0].disabled = @is_disabled

unless @is_multiple
@selected_item.unbind 'focus.chosen', this.activate_field
@selected_item.off 'focus.chosen', this.activate_field

if @is_disabled
this.close_field()
else unless @is_multiple
@selected_item.bind 'focus.chosen', this.activate_field
@selected_item.on 'focus.chosen', this.activate_field

container_mousedown: (evt) ->
return if @is_disabled
Expand All @@ -139,7 +139,7 @@ class Chosen extends AbstractChosen
if not (evt? and ($ evt.target).hasClass "search-choice-close")
if not @active_field
@search_field.val "" if @is_multiple
$(@container[0].ownerDocument).bind 'click.chosen', @click_test_action
$(@container[0].ownerDocument).on 'click.chosen', @click_test_action
this.results_show()
else if not @is_multiple and evt and (($(evt.target)[0] == @selected_item[0]) || $(evt.target).parents("a.chosen-single").length)
evt.preventDefault()
Expand All @@ -161,7 +161,7 @@ class Chosen extends AbstractChosen
this.close_field() if not @active_field and @container.hasClass "chosen-container-active"

close_field: ->
$(@container[0].ownerDocument).unbind "click.chosen", @click_test_action
$(@container[0].ownerDocument).off "click.chosen", @click_test_action

@active_field = false
this.results_hide()
Expand Down Expand Up @@ -198,7 +198,7 @@ class Chosen extends AbstractChosen

if @is_multiple
@search_choices.find("li.search-choice").remove()
else if not @is_multiple
else
this.single_set_selected_text()
if @disable_search or @form_field.options.length <= @disable_search_threshold and not @create_option
@search_field[0].readOnly = true
Expand Down Expand Up @@ -243,6 +243,9 @@ class Chosen extends AbstractChosen
@form_field_jq.trigger("chosen:maxselected", {chosen: this})
return false

unless @is_multiple
@search_container.append @search_field

@container.addClass "chosen-with-drop"
@results_showing = true

Expand All @@ -259,6 +262,10 @@ class Chosen extends AbstractChosen
if @results_showing
this.result_clear_highlight()

unless @is_multiple
@selected_item.prepend @search_field
@search_field.focus()

@container.removeClass "chosen-with-drop"
@form_field_jq.trigger("chosen:hiding_dropdown", {chosen: this})

Expand All @@ -277,7 +284,7 @@ class Chosen extends AbstractChosen
@form_field_label = $("label[for='#{@form_field.id}']") #next check for a for=#{id}

if @form_field_label.length > 0
@form_field_label.bind 'click.chosen', this.label_click_handler
@form_field_label.on 'click.chosen', this.label_click_handler

show_search_field_default: ->
if @is_multiple and this.choices_count() < 1 and not @active_field
Expand All @@ -299,7 +306,7 @@ class Chosen extends AbstractChosen
this.result_do_highlight( target ) if target

search_results_mouseout: (evt) ->
this.result_clear_highlight() if $(evt.target).hasClass "active-result" or $(evt.target).parents('.active-result').first()
this.result_clear_highlight() if $(evt.target).hasClass("active-result") or $(evt.target).parents('.active-result').first()

choice_build: (item) ->
choice = $('<li />', { class: "search-choice" }).html("<span>#{this.choice_label(item)}</span>")
Expand All @@ -308,7 +315,7 @@ class Chosen extends AbstractChosen
choice.addClass 'search-choice-disabled'
else
close_link = $('<a />', { class: 'search-choice-close', 'data-option-array-index': item.array_index })
close_link.bind 'click.chosen', (evt) => this.choice_destroy_link_click(evt)
close_link.on 'click.chosen', (evt) => this.choice_destroy_link_click(evt)
choice.append close_link

@search_container.before choice
Expand Down Expand Up @@ -370,13 +377,16 @@ class Chosen extends AbstractChosen

@form_field.options[item.options_index].selected = true
@selected_option_count = null
@search_field.val("")

if @is_multiple
this.choice_build item
else
this.single_set_selected_text(this.choice_label(item))

unless @is_multiple && (!@hide_results_on_select || (evt.metaKey or evt.ctrlKey))
if @is_multiple && (!@hide_results_on_select || (evt.metaKey or evt.ctrlKey))
this.winnow_results()
else
this.results_hide()
this.show_search_field_default()

Expand Down Expand Up @@ -424,7 +434,7 @@ class Chosen extends AbstractChosen
@search_field.val()

get_search_text: ->
this.escape_html $.trim(this.get_search_field_value())
$.trim this.get_search_field_value()

escape_html: (text) ->
$('<div/>').text(text).html()
Expand Down Expand Up @@ -524,9 +534,8 @@ class Chosen extends AbstractChosen
width = div.width() + 25
div.remove()

container_width = @container.outerWidth()

width = Math.min(container_width - 10, width)
if @container.is(':visible')
width = Math.min(@container.outerWidth() - 10, width)

@search_field.width(width)

Expand Down
24 changes: 16 additions & 8 deletions coffee/chosen.proto.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class @Chosen extends AbstractChosen
super()

# HTML Templates
@no_results_temp = new Template(this.get_no_results_html('#{terms}'))
@new_option_temp = new Template('<option value="#{value}">#{text}</option>')
@create_option_temp = new Template('<li class="create-option active-result"><a>#{text}</a>: "#{terms}"</li>')

Expand Down Expand Up @@ -199,7 +198,7 @@ class @Chosen extends AbstractChosen

if @is_multiple
@search_choices.select("li.search-choice").invoke("remove")
else if not @is_multiple
else
this.single_set_selected_text()
if @disable_search or @form_field.options.length <= @disable_search_threshold and not @create_option
@search_field.readOnly = true
Expand Down Expand Up @@ -243,6 +242,9 @@ class @Chosen extends AbstractChosen
@form_field.fire("chosen:maxselected", {chosen: this})
return false

unless @is_multiple
@search_container.insert @search_field

@container.addClassName "chosen-with-drop"
@results_showing = true

Expand All @@ -259,6 +261,10 @@ class @Chosen extends AbstractChosen
if @results_showing
this.result_clear_highlight()

unless @is_multiple
@selected_item.insert top: @search_field
@search_field.focus()

@container.removeClassName "chosen-with-drop"
@form_field.fire("chosen:hiding_dropdown", {chosen: this})

Expand Down Expand Up @@ -371,13 +377,16 @@ class @Chosen extends AbstractChosen

@form_field.options[item.options_index].selected = true
@selected_option_count = null
@search_field.value = ""

if @is_multiple
this.choice_build item
else
this.single_set_selected_text(this.choice_label(item))

unless @is_multiple && (!@hide_results_on_select || (evt.metaKey or evt.ctrlKey))
if @is_multiple && (!@hide_results_on_select || (evt.metaKey or evt.ctrlKey))
this.winnow_results()
else
this.results_hide()
this.show_search_field_default()

Expand Down Expand Up @@ -424,7 +433,7 @@ class @Chosen extends AbstractChosen
@search_field.value

get_search_text: ->
this.escape_html this.get_search_field_value().strip()
this.get_search_field_value().strip()

escape_html: (text) ->
text.escapeHTML()
Expand All @@ -439,7 +448,7 @@ class @Chosen extends AbstractChosen
this.result_do_highlight do_high if do_high?

no_results: (terms) ->
@search_results.insert @no_results_temp.evaluate( terms: terms )
@search_results.insert this.get_no_results_html(terms)
@form_field.fire("chosen:no_results", {chosen: this})

show_create_option: (terms) ->
Expand Down Expand Up @@ -533,9 +542,8 @@ class @Chosen extends AbstractChosen
width = div.measure('width') + 25
div.remove()

container_width = @container.getWidth()

width = Math.min(container_width - 10, width)
if container_width = @container.getWidth()
width = Math.min(container_width - 10, width)

@search_field.setStyle(width: width + 'px')

Expand Down
Loading

0 comments on commit 1aa7e9a

Please sign in to comment.