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

String parameter not working as expected for: jQuery.fn.control / jQuery.fn.controls #448

Merged
merged 1 commit into from
Oct 11, 2013

Conversation

daffl
Copy link
Contributor

@daffl daffl commented Oct 11, 2013

Using CanJS v1.1.6

String parameter not working as expected for: jQuery.fn.control / jQuery.fn.controls

Reference: http://canjs.com/docs/jQuery.fn.control.html

//
//  Define Plugin
//
var MyPlugin = can.Control.extend('MyPlugin', {
  pluginName: 'MyPlugin'
}, {});

// init plugin
$('body').MyPlugin();


//
//  Attempt to get defined plugin
//
$('body').control(); // returns MyPlugin (works as expected)
$('body').control(); // returns MyPlugin (works as expected)
$('body').control(MyPlugin); // returns MyPlugin (works as expected)

$('body').control('MyPlugin');  // returns undefined
$('body').control('myplugin'); // return undefined

@tilleps
Copy link
Author

tilleps commented Jul 11, 2013

Turns out that the string parameter will need to be converted with can.underscore()

$('body').control('MyPlugin');  // returns undefined
$('body').control( can.underscore('MyPlugin') ); // returns MyPlugin
$('body').control('my_plugin'); // returns MyPlugin

This does not seem intuitive as initializing the plugin is done with the string defined in pluginName

$('body').MyPlugin();  // initializes
$('body').my_plugin(); // Error: has no method 'my_plugin'

Notes/examples of this behavior would be helpful on the documentation page
http://canjs.com/docs/jQuery.fn.control.html

@tilleps
Copy link
Author

tilleps commented Jul 11, 2013

Another note, the fullName parameter can.Control() must also be provided in order for control() and controls() to match a control.

Would there be any issues assigning pluginName as fullName if fullName is not provided?

//
// Instead of having to manually assign fullName and pluginName
//
var MyPlugin = can.Control.extend('MyPlugin', {
  pluginName: 'MyPlugin'
}, {});

//
// Allow this instead
//
var MyPlugin = can.Control.extend({
  pluginName: 'MyPlugin'
}, {});


MyPlugin.fullName;  // return undefined (currently)
MyPlugin.fullName;  // returns MyPlugin (proposed)

@daffl
Copy link
Contributor

daffl commented Jul 11, 2013

Thanks! These docs are definitely not up-to date. I will have a look at it today.

@ghost ghost assigned daffl Jul 17, 2013
@daffl
Copy link
Contributor

daffl commented Oct 11, 2013

This was actually a bug which is fixed now with the attached pull request. Documentation has been updated as well.

daffl added a commit that referenced this pull request Oct 11, 2013
String parameter not working as expected for: jQuery.fn.control / jQuery.fn.controls
@daffl daffl merged commit 1b4e48c into master Oct 11, 2013
@daffl daffl deleted the control-plugin-naming-448 branch October 11, 2013 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants