Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
init/destroy/enable/disable methods. 2x arrow graphic. cleanup.
- Loading branch information
1 parent
aea56cb
commit 651baab
Showing
5 changed files
with
95 additions
and
113 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
body { | ||
background: white; | ||
text-align: center; | ||
font-family: "proxima nova", "helvetica neue", helvetica, arial, sans-serif; | ||
font-size: 13px; | ||
color: #333; | ||
padding: 20px; | ||
} | ||
#wrapper { | ||
margin: 0 auto; | ||
width: 400px; | ||
} | ||
h1 { | ||
text-align: center; | ||
font-size: 22px; | ||
font-weight: 600; | ||
} | ||
.fancyselect { | ||
margin: 0 auto 20px auto; | ||
vertical-align: middle; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,52 @@ | ||
(function($){ | ||
|
||
$.fn.fancyselect = function() { | ||
|
||
this.each(function(i,select) { | ||
$(select) | ||
.wrap('<span class="fancyselect" />') | ||
.before('<span class="arrows" />') | ||
.before('<span class="selecttext" />') | ||
.fadeTo(0,0) | ||
.focus(function() { $(this).parent('span').addClass('focus') }) | ||
.blur(function() { $(this).parent('span').removeClass('focus') }) | ||
.on("change keyup", function() { $(this).prev(".selecttext").text($(select).val()) }) | ||
.siblings(".selecttext").text($(select).val()); | ||
|
||
select.disable = function() { | ||
$(this).attr("disabled", "disabled").parent().addClass('disabled'); | ||
}; | ||
select.enable = function() { | ||
$(this).removeAttr('disabled').parent().removeClass('disabled'); | ||
}; | ||
|
||
if ($(select).attr("disabled")) select.disable(); | ||
|
||
}); | ||
|
||
var methods = { | ||
init: function() { | ||
return this.each(function(i,el) { | ||
$(el).wrap('<span class="fancyselect" />') | ||
.before('<span class="arrows" />') | ||
.before('<span class="selecttext" />') | ||
.fadeTo(0,0) | ||
.focus(function() { $(el).parent('span').addClass('focus'); }) | ||
.blur(function() { $(el).parent('span').removeClass('focus'); }) | ||
.on("change keydown keyup", function() { $(el).fancyselect('update'); }) | ||
.fancyselect('update'); | ||
if ($(el).attr("disabled")) $(el).fancyselect('disable'); | ||
}); | ||
}, | ||
destroy: function() { | ||
return this.each(function(i,el) { | ||
$(el).siblings('span').remove(); | ||
$(el).unwrap().fadeTo(0,1).unbind('focus blur change keydown keyup'); | ||
}); | ||
}, | ||
enable: function() { | ||
return this.each(function(i,el) { | ||
$(el).removeAttr('disabled').parent().removeClass('disabled'); | ||
}); | ||
}, | ||
disable: function() { | ||
return this.each(function(i,el) { | ||
$(el).attr("disabled", "disabled").parent().addClass('disabled'); | ||
}); | ||
}, | ||
update: function() { | ||
return this.each(function(i,el) { | ||
$(el).prev(".selecttext").text($(el).children('option:selected').text()); | ||
}); | ||
} | ||
}; | ||
|
||
$.fn.fancyselect = function(method) { | ||
if (methods[method]) { | ||
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); | ||
} | ||
else if (typeof method === 'object' || ! method) { | ||
return methods.init.apply(this, arguments); | ||
} | ||
else { | ||
$.error('Method ' + method + ' does not exist for .fancyselect()'); | ||
} | ||
}; | ||
|
||
})( jQuery ); |