11'use strict' ;
22/*
33 * Bootstrap-fullscreen-select v1.5.1 (http://craftpip.github.io/bootstrap-fullscreen-select/)
4- *
5- * www.craftpip.com
4+ * Author: bonifacepereira
5+ * Website: www.craftpip.com
6+ 67 *
78 * Copyright 2013-2014 bootstrap-select
89 * Licensed under MIT (https://github.com/craftpip/bootstrap-fullscreen-select/blob/master/LICENSE)
910 */
10- // $e = select element
11- // $c = container element
12- // $triggerElement = trigger element
11+
1312try {
1413 jQuery ;
1514} catch ( e ) {
1615 console . error ( 'MobileSelect\'s javascript requires jQuery' ) ;
1716}
17+
1818( function ( $ ) {
19+
1920 $ . fn . mobileSelect = function ( options ) {
2021 var $this = $ ( this ) ;
21-
22+
2223 /*
2324 * backout if no elements are selected.
2425 */
2526 if ( ! $this . length )
2627 return 'no elements to process' ;
27-
28+
2829 /*
2930 * set an empty object if options === undefined
3031 */
3132 if ( ! options )
3233 options = { } ;
33-
34+
3435 if ( typeof options === 'string' ) {
3536 if ( options === 'destroy' ) {
3637 // destroy the mobile select initialization.
7172 options = $ . extend ( { } , $ . fn . mobileSelect . defaults , options ) ;
7273 // start iterating over!
7374 $this . each ( function ( i , a ) {
74- console . log ( i ) ;
7575 var $elm = $ ( a ) ;
7676 //reject non SELECT elements
7777 if ( $elm [ 0 ] . tagName !== 'SELECT' ) {
@@ -114,7 +114,9 @@ try {
114114 if ( this . $e . attr ( 'data-style' ) !== undefined ) {
115115 this . style = this . $e . attr ( 'data-style' ) ;
116116 }
117- this . $e . before ( '<button class="btn ' + this . style + ' btn-mobileSelect-gen"><span class="text"></span> <span class="caret"></span></button>' ) ;
117+
118+ var b = this . $e . attr ( 'disabled' ) || '' ;
119+ this . $e . before ( '<button class="btn ' + this . style + ' btn-mobileSelect-gen" ' + b + '><span class="text"></span> <span class="caret"></span></button>' ) ;
118120 this . $triggerElement = this . $e . prev ( ) ;
119121 this . $e . hide ( ) ;
120122 } else {
@@ -150,20 +152,33 @@ try {
150152 this . _appendOptionsList ( ) ;
151153 } ,
152154 _appendOptionsList : function ( ) {
153-
155+
154156 /*
155157 * append options list.
156158 */
157159 this . $listcontainer . html ( '' ) ;
158160 var that = this ;
161+ var prevGroup = '' ;
159162 $ . each ( this . options , function ( i , a ) {
160- that . $listcontainer . append ( '<a href="#" class="mobileSelect-control" data-value="' + a . value + '">' + a . text + '</a>' ) ;
163+
164+ if ( a . group && a . group !== prevGroup ) {
165+ if ( a . groupDisabled ) {
166+ var b = 'disabled' ;
167+ }
168+ that . $listcontainer . append ( '<span class="mobileSelect-group" ' + b + '>' + a . group + '</span>' ) ;
169+ prevGroup = a . group ;
170+ }
171+ if ( a . groupDisabled || a . disabled ) {
172+ var b = 'disabled' ;
173+ }
174+ that . $listcontainer . append ( '<a href="#" class="mobileSelect-control" ' + b + ' data-value="' + a . value + '">' + a . text + '</a>' ) ;
175+
161176 } ) ;
162177 this . sync ( ) ;
163178 this . _updateBtnCount ( ) ;
164179 } ,
165180 _updateBtnCount : function ( ) {
166-
181+
167182 /*
168183 * Update generated button count.
169184 */
@@ -211,6 +226,10 @@ try {
211226 this . $c . find ( '.mobileSelect-control' ) . on ( 'click' , function ( e ) {
212227 e . preventDefault ( ) ;
213228 var $this = $ ( this ) ;
229+
230+ if ( $this . attr ( 'disabled' ) == 'disabled' )
231+ return false ;
232+
214233 if ( that . isMultiple ) {
215234 $this . toggleClass ( 'selected' ) ;
216235 } else {
@@ -219,7 +238,7 @@ try {
219238 } ) ;
220239 } ,
221240 _unbindEvents : function ( ) {
222-
241+
223242 /*
224243 * to unbind events while destroy.
225244 */
@@ -229,7 +248,7 @@ try {
229248 this . $c . find ( '.mobileSelect-control' ) . unbind ( 'click' ) ;
230249 } ,
231250 sync : function ( ) {
232-
251+
233252 /*
234253 * sync from select element to mobile select container
235254 */
@@ -242,7 +261,7 @@ try {
242261 }
243262 } ,
244263 syncR : function ( ) {
245-
264+
246265 /*
247266 * sync from mobile select container to select element
248267 */
@@ -253,7 +272,7 @@ try {
253272 this . $e . val ( selectedOptions ) ;
254273 } ,
255274 hide : function ( ) {
256-
275+
257276 /*
258277 * hide animation with onClose callback
259278 */
@@ -267,7 +286,7 @@ try {
267286 } , this . animationSpeed ) ;
268287 } ,
269288 show : function ( ) {
270-
289+
271290 /*
272291 * show animation with onOpen callback
273292 */
@@ -277,11 +296,11 @@ try {
277296 var that = this ;
278297 setTimeout ( function ( ) {
279298 that . $c . children ( 'div' ) . removeClass ( $ . mobileSelect . animations . join ( ' ' ) ) ;
280- } , 0 ) ;
299+ } , 10 ) ;
281300 this . onOpen . apply ( this . $e ) ;
282301 } ,
283302 _setUserOptions : function ( ) {
284-
303+
285304 /*
286305 * overwrite options with data-attributes if provided.
287306 */
@@ -315,25 +334,39 @@ try {
315334 }
316335 } ,
317336 _extractOptions : function ( ) {
318-
337+
319338 /*
320339 * Get options from the select element and store them in an array.
321340 */
322341 var options = [ ] ;
323342 $ . each ( this . $e . find ( 'option' ) , function ( i , a ) {
324- if ( $ ( this ) . text ( ) ) {
325- var label = $ ( this ) . parent ( ) . is ( 'optgroup' ) ? $ ( this ) . parent ( ) . attr ( 'label' ) : false ;
343+ var $t = $ ( a ) ;
344+ if ( $t . text ( ) ) {
345+
346+ // var label = $t.parent().is('optgroup') ? $t.parent().attr('label') : false;
347+
348+ if ( $t . parent ( ) . is ( 'optgroup' ) ) {
349+ var label = $t . parent ( ) . attr ( 'label' ) ;
350+ var labelDisabled = $t . parent ( ) . prop ( 'disabled' ) ;
351+ } else {
352+ var label = false ;
353+ var labelDisabled = false ;
354+ }
355+
326356 options . push ( {
327- value : $ ( this ) . val ( ) ,
328- text : $ . trim ( $ ( this ) . text ( ) ) ,
329- grouplabel : label
357+ value : $t . val ( ) ,
358+ text : $ . trim ( $t . text ( ) ) ,
359+ disabled : $t . prop ( 'disabled' ) ,
360+ group : label ,
361+ groupDisabled : labelDisabled
330362 } ) ;
363+
331364 }
332365 } ) ;
333366 this . options = options ;
334367 } ,
335368 destroy : function ( ) {
336-
369+
337370 /*
338371 * destroy the select
339372 * unbind events
@@ -348,7 +381,7 @@ try {
348381 console . log ( 'done ' ) ;
349382 } ,
350383 refresh : function ( ) {
351-
384+
352385 /*
353386 * refresh/sync the native select with the mobileSelect.
354387 */
@@ -358,15 +391,15 @@ try {
358391 this . _bindEvents ( ) ;
359392 }
360393 } ;
361-
394+
362395 /*
363396 * for user defaults.
364397 */
365398 $ . mobileSelect = {
366399 elements : { } , //to store records
367400 animations : [ 'anim-top' , 'anim-bottom' , 'anim-left' , 'anim-right' , 'anim-opacity' , 'anim-scale' , 'anim-zoom' , 'anim-none' ] //supported animations
368401 } ;
369-
402+
370403 /*
371404 * plugin defaults
372405 */
0 commit comments