Skip to content

Instantly share code, notes, and snippets.

@lagden
Created October 15, 2012 18:08
Show Gist options
  • Save lagden/3894070 to your computer and use it in GitHub Desktop.
Save lagden/3894070 to your computer and use it in GitHub Desktop.
<div class="pr">
<select title="sample" class="Styled" name="sample">
<option value="">Selecione</option>
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
</select>
</div>
// Styled JQuery Plugin
;(function($){
var opts;
var methods = {
init: function(options) {
opts = $.extend({
'hiddenStyle': 'hiddenStyle'
}, options);
return this.each(function(){
var $this = $(this);
if ($this.is('select'))
methods.styledSelect($this);
});
},
styledSelect: function(self){
var span = $('<span></span>');
var options = self.find('option');
var title = (options.filter(":selected").val() != '') ? options.filter(":selected").text() : options.eq(0).text();
self
.after(
span
.attr("class", self.attr("class"))
.css('width', self.width() + 'px')
.html(title)
)
.addClass(opts.hiddenStyle)
.bind('change',methods.change);
},
change: function(e){
var span = $(this).next('span:eq(0)').text($('option:selected', this).text());
},
destroy: function(){
return this.each(function(){
var $this = $(this);
$this
.removeClass(opts.hiddenStyle)
.unbind('change')
.next('span:eq(0)').remove();
});
}
};
$.fn.customized = 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' );
};
})( jQuery );
// jQuery document ready
jQuery.fn.ready(function(){
// Custom Form
jQuery('select.Styled').customized();
});
@import "compass";
// Vars
$red: #cc001b;
$white : #FFF;
// Font
$fontBase: 16;
// Form
$paddingForm: 5;
$heightForm: 30;
$lineHeightForm: 30;
select{
width: 200px;
}
// Customized
.Styled{
height: #{($heightForm - $paddingForm)}px;
line-height: #{($lineHeightForm - $paddingForm)}px;
vertical-align: middle;
}
select.Styled{
position: relative;
z-index: 10;
cursor: pointer;
&.hiddenStyle{
@include opacity(0);
}
}
span.Styled{
@include box-sizing(border-box);
padding: #{$paddingForm}px;
background:{
color: gray;
image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAYAAAGXljaGAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAINJREFUeNpiPMIgdoABCFiA2AHEAAggBqDIfyYgox4ggBiBLJDAfyBmBAggEOc/TOE+IGYGMZxBIgABhKwOBhiZYAxkGiCA4IbAABPUMBg4yAQzFAocWKAMsJUw+xmQVQEEGMhQJyC9lwE3cIZZ5IxLAUieCckuZ2wKYE5mwKLQGdkrAGDxF+9hnUNVAAAAAElFTkSuQmCC');
position: 95% center;
repeat: no-repeat;
};
color: $red;
position: absolute;
top: 0;
left: 0;
z-index: 9;
display: block;
height: inherit;
text-transform: uppercase;
}
// Others
.pr{
position: relative;
margin: 50px auto;
width: 500px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment