17
17
< meta property ="og:site_name " content ="jQuery Selectric ">
18
18
< meta property ="og:image " content ="http://lcdsantos.github.io/jQuery-Selectric/share.jpg ">
19
19
20
- < link rel ="stylesheet " id ="theme " href ="themes/default/ selectric.css ">
20
+ < link rel ="stylesheet " id ="theme " href ="selectric.css ">
21
21
< style id ="template " style ="display: none; "> </ style >
22
22
</ head >
23
23
< body >
@@ -58,8 +58,72 @@ <h3>Basic usage</h3>
58
58
</ div >
59
59
60
60
< div class ="code ">
61
- < pre > < code class ="language-javascript "> $(function(){
62
- $('select').selectric();
61
+ < pre > < code class ="language-javascript "> $('select').selectric();</ code > </ pre >
62
+ </ div >
63
+ </ div >
64
+
65
+ < div class ="demo ">
66
+ < h3 > Get selected option value</ h3 >
67
+
68
+ < div class ="view ">
69
+ < select id ="get_value ">
70
+ < option value ="strawberries "> Strawberries</ option >
71
+ < option value ="mango "> Mango</ option >
72
+ < option value ="bananas "> Bananas</ option >
73
+ < option value ="watermelon "> Watermelon</ option >
74
+ < option value ="apples "> Apples</ option >
75
+ < option value ="grapes "> Grapes</ option >
76
+ < option value ="oranges "> Oranges</ option >
77
+ < option value ="pineapple "> Pineapple</ option >
78
+ < option value ="peaches "> Peaches</ option >
79
+ < option value ="cherries "> Cherries</ option >
80
+ </ select >
81
+
82
+ < p id ="select_value "> Current value: < strong > </ strong > </ p >
83
+ </ div >
84
+
85
+ < div class ="code ">
86
+ < pre > < code class ="language-javascript "> // Cache the target element
87
+ var $selectValue = $('#select_value').find('strong');
88
+
89
+ // Get initial value
90
+ $selectValue.text($('#get_value').val());
91
+
92
+ // Initialize Selectric and bind to 'change' event
93
+ $('#get_value').selectric().on('change', function() {
94
+ $selectValue.text($(this).val());
95
+ });</ code > </ pre >
96
+ </ div >
97
+ </ div >
98
+
99
+ < div class ="demo ">
100
+ < h3 > Set value</ h3 >
101
+
102
+ < div class ="view ">
103
+ < select id ="set_value ">
104
+ < option value ="0 "> First option</ option >
105
+ < option value ="1 "> Second option</ option >
106
+ < option value ="2 "> Third option</ option >
107
+ </ select >
108
+
109
+ < p > < button id ="set_first_option "> Select 1st option</ button > </ p >
110
+ < p > < button id ="set_second_option "> Select 2nd option</ button > </ p >
111
+ < p > < button id ="set_third_option "> Select 3rd option</ button > </ p >
112
+ </ div >
113
+
114
+ < div class ="code ">
115
+ < pre > < code class ="language-javascript "> $('#set_value').selectric();
116
+
117
+ $('#set_first_option').on('click', function() {
118
+ $('#set_value').prop('selectedIndex', 0).selectric('refresh');
119
+ });
120
+
121
+ $('#set_second_option').on('click', function() {
122
+ $('#set_value').prop('selectedIndex', 1).selectric('refresh');
123
+ });
124
+
125
+ $('#set_third_option').on('click', function() {
126
+ $('#set_value').prop('selectedIndex', 2).selectric('refresh');
63
127
});</ code > </ pre >
64
128
</ div >
65
129
</ div >
@@ -81,26 +145,24 @@ <h3>Change options on the fly</h3>
81
145
< option value ="cherries "> Cherries</ option >
82
146
</ select >
83
147
84
- < input type ="text " id ="add_val " name ="add_val ">
85
- < button id ="bt_add_val "> Add value</ button >
148
+ < p >
149
+ < input type ="text " id ="add_val " name ="add_val ">
150
+ < button id ="bt_add_val "> Add value</ button >
151
+ </ p >
86
152
</ div >
87
153
88
154
< div class ="code ">
89
- < pre > < code class ="language-javascript "> $(function(){
90
- $('#dynamic').selectric();
91
-
92
- $('#bt_add_val').click(function(e){
93
- e.preventDefault();
155
+ < pre > < code class ="language-javascript "> $('#dynamic').selectric();
94
156
95
- // Store the value in a variable
96
- var value = $('#add_val').val();
157
+ $('#bt_add_val').click(function() {
158
+ // Store the value in a variable
159
+ var value = $('#add_val').val();
97
160
98
- // Append to original select
99
- $('#dynamic').append('<option>' + (value ? value : 'Empty') + '</option>');
161
+ // Append to original select
162
+ $('#dynamic').append('<option>' + (value ? value : 'Empty') + '</option>');
100
163
101
- // Refresh Selectric
102
- $('#dynamic').selectric('refresh');
103
- });
164
+ // Refresh Selectric
165
+ $('#dynamic').selectric('refresh');
104
166
});</ code > </ pre >
105
167
</ div >
106
168
</ div >
@@ -126,10 +188,10 @@ <h3>Callbacks</h3>
126
188
< div class ="code ">
127
189
< pre > < code class ="language-javascript "> // With events
128
190
$('#callbacks')
129
- .on('selectric-before-open', function(){
191
+ .on('selectric-before-open', function() {
130
192
alert('Before open');
131
193
})
132
- .on('selectric-before-close', function(){
194
+ .on('selectric-before-close', function() {
133
195
alert('Before close');
134
196
})
135
197
// You can bind to change event on original element
@@ -160,7 +222,7 @@ <h3>Populate via ajax request</h3>
160
222
</ div >
161
223
162
224
< div class ="code ">
163
- < pre > < code class ="language-javascript "> $.get('ajax.html', function(data){
225
+ < pre > < code class ="language-javascript "> $.get('ajax.html', function(data) {
164
226
$('#ajax').append(data).selectric();
165
227
});</ code > </ pre >
166
228
< br >
@@ -172,7 +234,7 @@ <h3>Populate via ajax request</h3>
172
234
< h3 > Custom markup for items box</ h3 >
173
235
174
236
< div class ="view ">
175
- < select class ="customOptions ">
237
+ < select class ="custom-options ">
176
238
< option value =""> Select with icons</ option >
177
239
< option value ="firefox "> Firefox</ option >
178
240
< option value ="chrome "> Chrome</ option >
@@ -183,12 +245,10 @@ <h3>Custom markup for items box</h3>
183
245
</ div >
184
246
185
247
< div class ="code ">
186
- < pre > < code class ="language-javascript "> $(function(){
187
- $('.customOptions').selectric({
188
- optionsItemBuilder: function(itemData, element, index){
189
- return element.val().length ? '<span class="ico ico-' + element.val() + '"></span>' + itemData.text : itemData.text;
190
- }
191
- });
248
+ < pre > < code class ="language-javascript "> $('.custom-options').selectric({
249
+ optionsItemBuilder: function(itemData, element, index) {
250
+ return element.val().length ? '<span class="ico ico-' + element.val() + '"></span>' + itemData.text : itemData.text;
251
+ }
192
252
});</ code > </ pre >
193
253
< br >
194
254
< pre data-src ="customoptions.css "> </ pre >
0 commit comments