Permalink
Browse files

added new options and supporting documentation

  • Loading branch information...
1 parent ad114d6 commit 8de027101cc7af9241491168cdf8727b28f9ef18 @skorecky committed Jun 30, 2010
Showing with 21 additions and 5 deletions.
  1. +10 −0 README.markdown
  2. +11 −5 addclear.js
View
@@ -45,6 +45,16 @@ Add Clear is a jQuery plugin that adds a input clearing button on any input you
<td>4</td>
<td>number</td>
</tr>
+ <tr>
+ <td>returnFocus</td>
+ <td>true</td>
+ <td>boolean</td>
+ </tr>
+ <tr>
+ <td>showOnLoad</td>
+ <td>false</td>
+ <td>boolean</td>
+ </tr>
</table>
#### Using Options
View
@@ -8,7 +8,9 @@
var options = $.extend({
closeImage: "clear.png",
top: 0,
- right: 4
+ right: 4,
+ returnFocus: true,
+ showOnLoad: false
}, options);
$(this).wrap("<span style='position:relative;' class='add-clear-span'>");
@@ -24,19 +26,23 @@
'top' : options.top+'px',
'width' : '16px'
}, this);
-
+
+ if($(this).val().length >= 1 && options.showOnLoad === true) {
+ $(this).siblings("a[href='#clear']").show();
+ }
+
$(this).keyup(function() {
if($(this).val().length >= 1) {
$(this).siblings("a[href='#clear']").show();
- } else {
- $(this).siblings("a[href='#clear']").hide();
}
});
$("a[href='#clear']").click(function(){
$(this).siblings("input").val("");
$(this).hide();
- $(this).siblings("input").focus();
+ if(options.returnFocus === true){
+ $(this).siblings("input").focus();
+ }
return false;
});
return this;

0 comments on commit 8de0271

Please sign in to comment.