-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsegment.js
28 lines (28 loc) · 831 Bytes
/
segment.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(function( $ ){
$.fn.extend({
Segment: function ( ) {
var is_disabled = $(this).prop("disabled");
$(this).each(function (){
var self = $(this);
var onchange = self.attr('onchange');
var wrapper = $("<div>",{class: "ui-segment"});
$(this).find("option").each(function (){
var option = $("<span>",{class: 'option',onclick:onchange,text: $(this).text(),value: $(this).val()});
if ($(this).is(":selected")){
option.addClass("active");
}
wrapper.append(option);
});
wrapper.find("span.option").click(function (){
if (!is_disabled) {
wrapper.find("span.option").removeClass("active");
$(this).addClass("active");
self.val($(this).attr('value'));
}
});
$(this).after(wrapper);
$(this).hide();
});
}
});
})(jQuery);