Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
first commit
  • Loading branch information
airportyh authored and airportyh committed Jul 20, 2009
0 parents commit f5dfd26
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
19 changes: 19 additions & 0 deletions jquery.js

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions jradio.js
@@ -0,0 +1,30 @@
(function(){
function jRadio(name){
this.elements = $('input[type=radio][name=' + name + ']');
this.lastVal = jRadio.prototype.val.apply(this);
}
jRadio.prototype.change = function(callback){
var self = this;
this.elements.click(function(){
var val = self.val();
if (val != self.lastVal){
self.lastVal = val;
callback(self);
}
})
}
jRadio.prototype.val = function(val){
if (val === undefined){
return this.elements.filter(function(){ return this.checked; }).val();
}else{
if (this.lastVal == val) return;
this.lastVal = val;
this.elements.filter(function(){ return $(this).val() == val; }).attr('checked', true);
return this;
}
}

$.radio = function(name){
return new jRadio(name);
}
})();
26 changes: 26 additions & 0 deletions test.html
@@ -0,0 +1,26 @@
<!DOCTYPE PUBLIC "-//W3c//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jradio.js"></script>
<script type="text/javascript">
<!--



$(function(){
$.radio('radio').change(function(ui){
console.log('Radio button changed to ' + ui.val());
})
})
-->
</script>
<title>Test jRadio</title>

</head>
<body>
<label>One: </label><input type="radio" name="radio" value="one"><br>
<label>Two: </label><input type="radio" name="radio" value="two">
</body>
</html>

0 comments on commit f5dfd26

Please sign in to comment.