Created
November 5, 2013 08:40
-
-
Save vlado/7315718 to your computer and use it in GitHub Desktop.
How to extend Chosen jQuery library example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Extend Chosen with custom method or owerwrite existing methods | |
class CustomChosen extends Chosen | |
show_search_field_default: -> | |
# ... | |
# original method updated | |
# ... | |
some_new_method: -> | |
# ... | |
# 2. Extend jQuery with custom chosen (Optional, we can do custom init on app level) | |
$ = jQuery | |
$.fn.extend({ | |
customChosen: (options) -> | |
# Do no harm and return as soon as possible for unsupported browsers, namely IE6 and IE7 | |
# Continue on if running IE document type but in compatibility mode | |
return this unless AbstractChosen.browser_is_supported() | |
this.each (input_field) -> | |
$this = $ this | |
chosen = $this.data('chosen') | |
if options is 'destroy' && chosen | |
chosen.destroy() | |
else unless chosen | |
$this.data('chosen', new CustomChosen(this, options)) | |
return | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
does this code works with the latest version of Chosen?
Also can you provide plain javascript as an example, I have no clue about coffee script...
Thanks