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

Make .placeholder classname configurable #39

Closed
wants to merge 6 commits into from

Conversation

cheeaun
Copy link

@cheeaun cheeaun commented Sep 20, 2011

Fix for issue #38 . I left out the minified version in the commit just because.

@mathiasbynens
Copy link
Owner

The easiest solution would be to just use an argument for this, e.g. $('input').placeholder(className), but that looks ugly and confusing.

I was thinking of using $.fn.placeholder.className for this, so it can easily be overridden without modifying the plugin source.

Would you mind tweaking your pull request so it works that way?

@@ -14,7 +14,10 @@

} else {

$.fn.placeholder = function() {
var placeholderClassName = 'placeholder';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not a fan of variable declarations inside an if { … } else { … } — better to keep them at the top of the scope IMHO. #ocd

@cheeaun
Copy link
Author

cheeaun commented Sep 21, 2011

Ping. I guess there's no notification for commit additions to a pull request? :/

@@ -2,7 +2,8 @@
;(function(window, document, $) {

var isInputSupported = 'placeholder' in document.createElement('input'),
isTextareaSupported = 'placeholder' in document.createElement('textarea');
isTextareaSupported = 'placeholder' in document.createElement('textarea'),
placeholderClassName = 'placeholder';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line isn’t needed, is it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used in clearPlaceholder and setPlaceholder functions, plus the domready and unload event handlers.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I was thinking is that this should be added to the code after $.fn.placeholder is declared:

$.fn.placeholder.className = 'placeholder';

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, so I should only get the className via $.fn.placeholder.className instead of a variable (outside of the function scopes)?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, and cache/re-use the $.fn.placeholder.className wherever possible (per scope).

We should probably move the$(…) and the $(window).bind(…) code inside of the $.fn.placeholder = fn block, while still making sure these only get called/bound once (even when $().placeholder() is used multiple times). We could use .one() instead of .bind(), but what about the $(…)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use .one() for the ready event.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested this and does it work?

This doesn’t seem to work: http://jsfiddle.net/mathias/tMDrZ/ Any ideas? Perhaps we could use something like this: http://jsfiddle.net/tMDrZ/1/

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it doesn't work. I thought about it, and ultimately we can assume that by the time .placeholder is called, domready is already fired.

@mathiasbynens
Copy link
Owner

@cheeaun No, no notifications for that :( Thanks for the ping; I’ve left some comments.

// Clear placeholder values upon page reload
$(window).one('unload.placeholder', function() {
$('.' + $.fn.placeholder.className).val('');
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could chain these together: $(window).ready(…).one(…);

Add `initialized` variable to prevent the events binded more than once.
@@ -14,32 +14,37 @@

} else {

var initialized = false;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this line to the top of the scope please?

@cheeaun
Copy link
Author

cheeaun commented Sep 22, 2011

Changes have been committed.

@mathiasbynens
Copy link
Owner

Looks good to me. Did you test this?

@carpeliam
Copy link

Hey all, I came here by way of #175. I'm sure there are plenty of bootstrap users out there in addition to me, is there anything I can do to move this forward?

@amerikan
Copy link
Collaborator

I can take a look at this. The idea to have custom class name is great. This PR has fallen behind, can you bring it back to date?

@amerikan
Copy link
Collaborator

This feature is already supported. Closing this.

@amerikan amerikan closed this Dec 23, 2014
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

Successfully merging this pull request may close these issues.

4 participants