Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the jQuery interface #2776

Open
validide opened this issue Feb 18, 2017 · 0 comments
Open

Improve the jQuery interface #2776

validide opened this issue Feb 18, 2017 · 0 comments

Comments

@validide
Copy link

validide commented Feb 18, 2017

Hi,

Would it be possible to improve the jQuery interface by making it similar to the one most of the jQuery plugins are using?
This would require adding the following 2 properties:

  • Constructor
  • noConflict method

My suggestion for the changes is:

JQUERY_INTERFACE = (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'
        if chosen instanceof Chosen
          chosen.destroy()
        return
      unless chosen instanceof Chosen
        $this.data('chosen', new Chosen(this, options))

      return

JQUERY_NO_CONFLICT = $.fn["chosen"];
$.fn["chosen"] = JQUERY_INTERFACE;
$.fn["chosen"].Constructor = Chosen;
$.fn["chosen"].AbstractConstructor = AbstractChosen;
$.fn["chosen"].noConflict  = () ->
    $.fn["chosen"] = JQUERY_NO_CONFLICT;
    return jQueryInterface;

I am not a Coffee Script programmer so if you see any issues with the code let me know.

The reason for exposing the Chosen and AbstractChosen is to allow the user to change some of the default settings(like the default strings).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant