Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8006317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:28:25+00:00 2026-06-04T17:28:25+00:00

I am making my first file uploader jquery plugin (in coffeescript): $.fn.uploadable = (opts={})

  • 0

I am making my first file uploader jquery plugin (in coffeescript):

    $.fn.uploadable = (opts={}) ->
      console.log $(@).attr('type') # undefined
      event = if $(@).attr('type') is 'file' then 'change' else 'drop'
      @
      .on event, (evt) ->
        # do something
        off
      .on 'dragover', (evt) -> off


    $('#files_input, #drop_zone').uploadable

So you can see, in the first .on(), I am determining whether the element of the event is a browse file button or not ;if YES, then this element will be listened for “change” event when the user selects the file, if NO, then I assume it’s some plain old div or something for an HTML5 drag and drop action.

So I am using the plugin on one INPUT element and one DIV element. As you can see from my console.log logged ‘undefined’

So far I only know that calling method like attr(), you will only get the result from one of the listed selectors’ elements. But I need to set the .on(event)’s event variable individually for each of the matched element. How can I do this?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:28:29+00:00Added an answer on June 4, 2026 at 5:28 pm

    The usual plugin pattern looks something like this:

    $.fn.plugin = function(options) {
        options = $.extend({ }, $.fn.plugin.defaults, options || { });
        return this.each(function() {
            // Do things to $(this) to set up your plugin.
        });
    };
    $.fn.plugin.defaults = { ... };
    

    The CoffeeScript version would be:

    $.fn.plugin = (options = { }) ->
        options = $.extend({ }, $.fn.plugin.defaults, options)
        @.each ->
            # Do things to $(@) to set up your plugin
    $.fn.plugin.defaults = { ... }
    

    The return part of return this.each is what gives you the usual chaining, the this.each part is what allows the plugin to bind to several things at once.

    Applying this your case would give you:

    $.fn.uploadable = (opts = { }) ->
      @.each ->
        event = if $(@).attr('type') is 'file' then 'change' else 'drop'
        $(@)
          .on event, (evt) ->
            # do something
            off
          .on 'dragover', (evt) -> off
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making my first program with beautifulsoup and my html file has code
I'm making a first attempt at embedding an mp3 file on a webpage. I've
i am making an application which first compresses a file and then transfer it.
Making my first steps in RIA Services (VS2010Beta2) and i encountered this problem: created
I am making my first program using Java3D. I have setup some transformGroups that
I'm making my first iOS app, and am in need of some help. Here
I am making my first ever C# GUI. It is using a BackgroundWorker to
I'm making my first application in Windows Azure and I have some problem. This
I've been making a first attempt to use fluent nHibernate on an ASP.NET MVC
I'm making my first steps with unit testing and am unsure about two paradigms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.