Skip to content

Commit

Permalink
small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
frozeman committed Jul 30, 2012
1 parent e76668d commit cc2874f
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 38 deletions.
3 changes: 3 additions & 0 deletions Demo/index.html
Expand Up @@ -10,6 +10,9 @@
</script>
</head>
<body>
<h1>PlaceholderSupprt Demo</h1>
<p>You will only see this script in action if you use an ancient browser like IE, but don't worry it will look the same ;)</p>

<input type='text' placeholder='some text'>
<br><br>
<textarea cols=20 rows=5 placeholder='some other txt'></textarea>
Expand Down
File renamed without changes.
31 changes: 23 additions & 8 deletions README.md
@@ -1,20 +1,35 @@
PlaceholderSupport
================
Adds a fallback for browsers that do not support the placeholder property.
Probably the most simple solution for this out there.
I found many others where you need extra CSS. This is so simple you just call the class and you have placeholder support in all browsers!
Adds a fallback for browsers that do not support the placeholder attribute.<br>
Probably the most simple solution for this out there.<br>
I found many others where you need extra CSS. This is so simple that you just have to call the class and you have placeholder support for all browsers!

<b>Published under the MIT-License</b>.

![Screenshot](https://github.com/frozeman/PlaceholderSupport/raw/master/screenshot.png)

How to use
----------
Just add the PlaceholderSupport.js to your website and call:


#JS
window.addEvent('domready',function(){

new PlaceholderSupport();

});


Will add placeholder functionality to all inputs and textarea elements with a "placeholder" attribute.


#JS
new PlaceholderSupport();
window.addEvent('domready',function(){

or
new PlaceholderSupport('input.myInputWithPlaceholder');

new PlaceholderSupport(elements);
});

Leave the "elements" parameter empty, to add placeholder functionality to all inputs and textarea elements with a "placeholder" attribute.

Otherwise the "elements" parameter can be a string with CSS selectors or an array with elements.
Will add the placeholder only to inputs with the class "myInputWithPlaceholder". But this input needs also a placeholder attribute with a text!
53 changes: 25 additions & 28 deletions Source/PlaceholderSupport.js
Expand Up @@ -2,7 +2,7 @@
---
description: Adds cross browser Placeholder support to inputs and textareas, which have a placholder attribute.
license: MIT-style
license: MIT-License
authors:
- Fabian Vogelsteller [frozeman.de]
Expand All @@ -14,44 +14,41 @@ provides: [PlaceholderSupport]
...
*/
PlaceholderSupport = new Class({
var PlaceholderSupport = new Class({
initialize : function(els){
if(('placeholder' in document.createElement('input')))
return;

var self = this;

window.addEvent('domready',function(){
this.elements = (typeOf(els) === 'string') ? $$(els) : els;
if(typeOf(this.elements) === 'null' || typeOf(this.elements[0]) === 'null') {
this.elements = $$('input[placeholder],textarea[placeholder]');
}
this.elements = (typeOf(els) === 'string') ? $$(els) : els;
if(typeOf(this.elements) === 'null' || typeOf(this.elements[0]) === 'null') {
this.elements = $$('input[placeholder],textarea[placeholder]');
}

this.elements.each(function(input){
var textColor = input.getStyle('color');
var lighterTextColor = self.LightenDarkenColor(textColor,80);
this.elements.each(function(input){
var textColor = input.getStyle('color');
var lighterTextColor = self.LightenDarkenColor(textColor,80);

if(input.getProperty('value') === '') {
input.setProperty('value',input.getProperty('placeholder'));
input.setStyle('color',lighterTextColor);
}
if(input.getProperty('value') === '') {
input.setProperty('value',input.getProperty('placeholder'));
input.setStyle('color',lighterTextColor);
}

input.addEvents({
focus: function(){
if(input.getProperty('value') === input.getProperty('placeholder')) {
input.setProperty('value','');
input.setStyle('color',textColor);
}
},
blur: function(){
if(input.getProperty('value') === '') {
input.setProperty('value',input.getProperty('placeholder'));
input.setStyle('color',lighterTextColor);
}
input.addEvents({
focus: function(){
if(input.getProperty('value') === input.getProperty('placeholder')) {
input.setProperty('value','');
input.setStyle('color',textColor);
}
});
},
blur: function(){
if(input.getProperty('value') === '') {
input.setProperty('value',input.getProperty('placeholder'));
input.setStyle('color',lighterTextColor);
}
}
});

});
},

Expand Down
4 changes: 2 additions & 2 deletions package.yml
@@ -1,5 +1,5 @@
name: PlaceholderSupport
author: frozeman
current: 1.0
category: Utilities
tags: [Placeholder]
category: Forms
tags: [Placeholder,html5]
Binary file added screenshot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cc2874f

Please sign in to comment.