11
11
var SelectParser ;
12
12
13
13
SelectParser = ( function ( ) {
14
-
15
14
function SelectParser ( ) {
16
15
this . options_index = 0 ;
17
16
this . parsed = [ ] ;
27
26
28
27
SelectParser . prototype . add_group = function ( group ) {
29
28
var group_position , option , _i , _len , _ref , _results ;
29
+
30
30
group_position = this . parsed . length ;
31
31
this . parsed . push ( {
32
32
array_index : group_position ,
79
79
80
80
SelectParser . select_to_array = function ( select ) {
81
81
var child , parser , _i , _len , _ref ;
82
+
82
83
parser = new SelectParser ( ) ;
83
84
_ref = select . childNodes ;
84
85
for ( _i = 0 , _len = _ref . length ; _i < _len ; _i ++ ) {
91
92
this . SelectParser = SelectParser ;
92
93
93
94
} ) . call ( this ) ;
94
-
95
95
/*
96
96
Chosen source: generate output using 'cake build'
97
97
Copyright (c) 2011 by Harvest
@@ -104,7 +104,6 @@ Copyright (c) 2011 by Harvest
104
104
root = this ;
105
105
106
106
AbstractChosen = ( function ( ) {
107
-
108
107
function AbstractChosen ( form_field , options ) {
109
108
this . form_field = form_field ;
110
109
this . options = options != null ? options : { } ;
@@ -122,6 +121,7 @@ Copyright (c) 2011 by Harvest
122
121
123
122
AbstractChosen . prototype . set_default_values = function ( ) {
124
123
var _this = this ;
124
+
125
125
this . click_test_action = function ( evt ) {
126
126
return _this . test_active_click ( evt ) ;
127
127
} ;
@@ -165,6 +165,7 @@ Copyright (c) 2011 by Harvest
165
165
166
166
AbstractChosen . prototype . input_focus = function ( evt ) {
167
167
var _this = this ;
168
+
168
169
if ( this . is_multiple ) {
169
170
if ( ! this . active_field ) {
170
171
return setTimeout ( ( function ( ) {
@@ -180,6 +181,7 @@ Copyright (c) 2011 by Harvest
180
181
181
182
AbstractChosen . prototype . input_blur = function ( evt ) {
182
183
var _this = this ;
184
+
183
185
if ( ! this . mouse_on_container ) {
184
186
this . active_field = false ;
185
187
return setTimeout ( ( function ( ) {
@@ -190,6 +192,7 @@ Copyright (c) 2011 by Harvest
190
192
191
193
AbstractChosen . prototype . result_add_option = function ( option ) {
192
194
var classes , style ;
195
+
193
196
if ( ! option . disabled ) {
194
197
option . dom_id = this . container_id + "_o_" + option . array_index ;
195
198
classes = option . selected && this . is_multiple ? [ ] : [ "active-result" ] ;
@@ -237,6 +240,7 @@ Copyright (c) 2011 by Harvest
237
240
238
241
AbstractChosen . prototype . keyup_checker = function ( evt ) {
239
242
var stroke , _ref ;
243
+
240
244
stroke = ( _ref = evt . which ) != null ? _ref : evt . keyCode ;
241
245
this . search_field_scale ( ) ;
242
246
switch ( stroke ) {
@@ -273,20 +277,23 @@ Copyright (c) 2011 by Harvest
273
277
274
278
AbstractChosen . prototype . generate_field_id = function ( ) {
275
279
var new_id ;
280
+
276
281
new_id = this . generate_random_id ( ) ;
277
282
this . form_field . id = new_id ;
278
283
return new_id ;
279
284
} ;
280
285
281
286
AbstractChosen . prototype . generate_random_char = function ( ) {
282
287
var chars , newchar , rand ;
288
+
283
289
chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
284
290
rand = Math . floor ( Math . random ( ) * chars . length ) ;
285
291
return newchar = chars . substring ( rand , rand + 1 ) ;
286
292
} ;
287
293
288
294
AbstractChosen . prototype . container_width = function ( ) {
289
295
var width ;
296
+
290
297
if ( this . options . width != null ) {
291
298
return this . options . width ;
292
299
}
@@ -296,6 +303,7 @@ Copyright (c) 2011 by Harvest
296
303
297
304
AbstractChosen . browser_is_supported = function ( ) {
298
305
var _ref ;
306
+
299
307
if ( window . navigator . appName === "Microsoft Internet Explorer" ) {
300
308
return ( null !== ( _ref = document . documentMode ) && _ref >= 8 ) ;
301
309
}
@@ -315,15 +323,14 @@ Copyright (c) 2011 by Harvest
315
323
root . AbstractChosen = AbstractChosen ;
316
324
317
325
} ) . call ( this ) ;
318
-
319
326
/*
320
327
Chosen source: generate output using 'cake build'
321
328
Copyright (c) 2011 by Harvest
322
329
*/
323
330
324
331
325
332
( function ( ) {
326
- var $ , Chosen , get_side_border_padding , root ,
333
+ var $ , Chosen , get_side_border_padding , root , _ref ,
327
334
__hasProp = { } . hasOwnProperty ,
328
335
__extends = function ( child , parent ) { for ( var key in parent ) { if ( __hasProp . call ( parent , key ) ) child [ key ] = parent [ key ] ; } function ctor ( ) { this . constructor = child ; } ctor . prototype = parent . prototype ; child . prototype = new ctor ( ) ; child . __super__ = parent . prototype ; return child ; } ;
329
336
@@ -338,6 +345,7 @@ Copyright (c) 2011 by Harvest
338
345
}
339
346
return this . each ( function ( input_field ) {
340
347
var $this ;
348
+
341
349
$this = $ ( this ) ;
342
350
if ( ! $this . hasClass ( "chzn-done" ) ) {
343
351
return $this . data ( 'chosen' , new Chosen ( this , options ) ) ;
@@ -347,11 +355,11 @@ Copyright (c) 2011 by Harvest
347
355
} ) ;
348
356
349
357
Chosen = ( function ( _super ) {
350
-
351
358
__extends ( Chosen , _super ) ;
352
359
353
360
function Chosen ( ) {
354
- return Chosen . __super__ . constructor . apply ( this , arguments ) ;
361
+ _ref = Chosen . __super__ . constructor . apply ( this , arguments ) ;
362
+ return _ref ;
355
363
}
356
364
357
365
Chosen . prototype . setup = function ( ) {
@@ -366,6 +374,7 @@ Copyright (c) 2011 by Harvest
366
374
367
375
Chosen . prototype . set_up_html = function ( ) {
368
376
var container_classes , container_props ;
377
+
369
378
this . container_id = this . form_field . id . length ? this . form_field . id . replace ( / [ ^ \w ] / g, '_' ) : this . generate_field_id ( ) ;
370
379
this . container_id += "_chzn" ;
371
380
container_classes = [ "chzn-container" ] ;
@@ -411,6 +420,7 @@ Copyright (c) 2011 by Harvest
411
420
412
421
Chosen . prototype . register_observers = function ( ) {
413
422
var _this = this ;
423
+
414
424
this . container . mousedown ( function ( evt ) {
415
425
_this . container_mousedown ( evt ) ;
416
426
} ) ;
@@ -432,6 +442,12 @@ Copyright (c) 2011 by Harvest
432
442
this . search_results . mouseout ( function ( evt ) {
433
443
_this . search_results_mouseout ( evt ) ;
434
444
} ) ;
445
+ this . search_results . bind ( 'mousewheel' , function ( evt ) {
446
+ _this . search_results_mousewheel ( evt ) ;
447
+ } ) ;
448
+ this . search_results . bind ( 'DOMMouseScroll' , function ( evt ) {
449
+ _this . search_results_mousewheel_ff ( evt ) ;
450
+ } ) ;
435
451
this . form_field_jq . bind ( "liszt:updated" , function ( evt ) {
436
452
_this . results_update_field ( evt ) ;
437
453
} ) ;
@@ -509,6 +525,23 @@ Copyright (c) 2011 by Harvest
509
525
}
510
526
} ;
511
527
528
+ Chosen . prototype . search_results_mousewheel = function ( evt ) {
529
+ this . search_results [ 0 ] . scrollTop -= evt . wheelDelta ;
530
+ return evt . preventDefault ( ) ;
531
+ } ;
532
+
533
+ Chosen . prototype . search_results_mousewheel_ff = function ( evt ) {
534
+ var bottom_overflow , delta , target , top_overflow , _ref1 ;
535
+
536
+ target = evt . currentTarget ;
537
+ delta = ( ( _ref1 = evt . originalEvent ) != null ? _ref1 . wheelDelta : void 0 ) || - evt . detail ;
538
+ bottom_overflow = target . scrollTop + $ ( target ) . outerHeight ( ) - target . scrollHeight >= 0 ;
539
+ top_overflow = target . scrollTop <= 0 ;
540
+ if ( target . scrollHeight > $ ( target ) . outerHeight ( ) && ( ( delta < 0 && bottom_overflow ) || ( delta > 0 && top_overflow ) ) ) {
541
+ return evt . preventDefault ( ) ;
542
+ }
543
+ } ;
544
+
512
545
Chosen . prototype . blur_test = function ( evt ) {
513
546
if ( ! this . active_field && this . container . hasClass ( "chzn-container-active" ) ) {
514
547
return this . close_field ( ) ;
@@ -542,7 +575,8 @@ Copyright (c) 2011 by Harvest
542
575
} ;
543
576
544
577
Chosen . prototype . results_build = function ( ) {
545
- var content , data , _i , _len , _ref ;
578
+ var content , data , _i , _len , _ref1 ;
579
+
546
580
this . parsing = true ;
547
581
this . results_data = root . SelectParser . select_to_array ( this . form_field ) ;
548
582
if ( this . is_multiple && this . choices > 0 ) {
@@ -557,9 +591,9 @@ Copyright (c) 2011 by Harvest
557
591
}
558
592
}
559
593
content = '' ;
560
- _ref = this . results_data ;
561
- for ( _i = 0 , _len = _ref . length ; _i < _len ; _i ++ ) {
562
- data = _ref [ _i ] ;
594
+ _ref1 = this . results_data ;
595
+ for ( _i = 0 , _len = _ref1 . length ; _i < _len ; _i ++ ) {
596
+ data = _ref1 [ _i ] ;
563
597
if ( data . group ) {
564
598
content += this . result_add_group ( data ) ;
565
599
} else if ( ! data . empty ) {
@@ -592,6 +626,7 @@ Copyright (c) 2011 by Harvest
592
626
593
627
Chosen . prototype . result_do_highlight = function ( el ) {
594
628
var high_bottom , high_top , maxHeight , visible_bottom , visible_top ;
629
+
595
630
if ( el . length ) {
596
631
this . result_clear_highlight ( ) ;
597
632
this . result_highlight = el ;
@@ -646,6 +681,7 @@ Copyright (c) 2011 by Harvest
646
681
647
682
Chosen . prototype . set_tab_index = function ( el ) {
648
683
var ti ;
684
+
649
685
if ( this . form_field_jq . attr ( "tabindex" ) ) {
650
686
ti = this . form_field_jq . attr ( "tabindex" ) ;
651
687
this . form_field_jq . attr ( "tabindex" , - 1 ) ;
@@ -655,6 +691,7 @@ Copyright (c) 2011 by Harvest
655
691
656
692
Chosen . prototype . set_label_behavior = function ( ) {
657
693
var _this = this ;
694
+
658
695
this . form_field_label = this . form_field_jq . parents ( "label" ) ;
659
696
if ( ! this . form_field_label . length && this . form_field . id . length ) {
660
697
this . form_field_label = $ ( "label[for=" + this . form_field . id + "]" ) ;
@@ -682,6 +719,7 @@ Copyright (c) 2011 by Harvest
682
719
683
720
Chosen . prototype . search_results_mouseup = function ( evt ) {
684
721
var target ;
722
+
685
723
target = $ ( evt . target ) . hasClass ( "active-result" ) ? $ ( evt . target ) : $ ( evt . target ) . parents ( ".active-result" ) . first ( ) ;
686
724
if ( target . length ) {
687
725
this . result_highlight = target ;
@@ -692,6 +730,7 @@ Copyright (c) 2011 by Harvest
692
730
693
731
Chosen . prototype . search_results_mouseover = function ( evt ) {
694
732
var target ;
733
+
695
734
target = $ ( evt . target ) . hasClass ( "active-result" ) ? $ ( evt . target ) : $ ( evt . target ) . parents ( ".active-result" ) . first ( ) ;
696
735
if ( target ) {
697
736
return this . result_do_highlight ( target ) ;
@@ -714,6 +753,7 @@ Copyright (c) 2011 by Harvest
714
753
Chosen . prototype . choice_build = function ( item ) {
715
754
var choice_id , html , link ,
716
755
_this = this ;
756
+
717
757
if ( this . is_multiple && this . max_selected_options <= this . choices ) {
718
758
this . form_field_jq . trigger ( "liszt:maxselected" , {
719
759
chosen : this
@@ -775,6 +815,7 @@ Copyright (c) 2011 by Harvest
775
815
776
816
Chosen . prototype . result_select = function ( evt ) {
777
817
var high , high_id , item , position ;
818
+
778
819
if ( this . result_highlight ) {
779
820
high = this . result_highlight ;
780
821
high_id = high . attr ( "id" ) ;
@@ -823,6 +864,7 @@ Copyright (c) 2011 by Harvest
823
864
824
865
Chosen . prototype . result_deselect = function ( pos ) {
825
866
var result , result_data ;
867
+
826
868
result_data = this . results_data [ pos ] ;
827
869
if ( ! this . form_field . options [ result_data . options_index ] . disabled ) {
828
870
result_data . selected = false ;
@@ -848,16 +890,17 @@ Copyright (c) 2011 by Harvest
848
890
} ;
849
891
850
892
Chosen . prototype . winnow_results = function ( ) {
851
- var found , option , part , parts , regex , regexAnchor , result , result_id , results , searchText , startpos , text , zregex , _i , _j , _len , _len1 , _ref ;
893
+ var found , option , part , parts , regex , regexAnchor , result , result_id , results , searchText , startpos , text , zregex , _i , _j , _len , _len1 , _ref1 ;
894
+
852
895
this . no_results_clear ( ) ;
853
896
results = 0 ;
854
897
searchText = this . search_field . val ( ) === this . default_text ? "" : $ ( '<div/>' ) . text ( $ . trim ( this . search_field . val ( ) ) ) . html ( ) ;
855
898
regexAnchor = this . search_contains ? "" : "^" ;
856
899
regex = new RegExp ( regexAnchor + searchText . replace ( / [ - [ \] { } ( ) * + ? . , \\ ^ $ | # \s ] / g, "\\$&" ) , 'i' ) ;
857
900
zregex = new RegExp ( searchText . replace ( / [ - [ \] { } ( ) * + ? . , \\ ^ $ | # \s ] / g, "\\$&" ) , 'i' ) ;
858
- _ref = this . results_data ;
859
- for ( _i = 0 , _len = _ref . length ; _i < _len ; _i ++ ) {
860
- option = _ref [ _i ] ;
901
+ _ref1 = this . results_data ;
902
+ for ( _i = 0 , _len = _ref1 . length ; _i < _len ; _i ++ ) {
903
+ option = _ref1 [ _i ] ;
861
904
if ( ! option . disabled && ! option . empty ) {
862
905
if ( option . group ) {
863
906
$ ( '#' + option . dom_id ) . css ( 'display' , 'none' ) ;
@@ -911,6 +954,7 @@ Copyright (c) 2011 by Harvest
911
954
912
955
Chosen . prototype . winnow_results_clear = function ( ) {
913
956
var li , lis , _i , _len , _results ;
957
+
914
958
this . search_field . val ( "" ) ;
915
959
lis = this . search_results . find ( "li" ) ;
916
960
_results = [ ] ;
@@ -930,6 +974,7 @@ Copyright (c) 2011 by Harvest
930
974
931
975
Chosen . prototype . winnow_results_set_highlight = function ( ) {
932
976
var do_high , selected_results ;
977
+
933
978
if ( ! this . result_highlight ) {
934
979
selected_results = ! this . is_multiple ? this . search_results . find ( ".result-selected.active-result" ) : [ ] ;
935
980
do_high = selected_results . length ? selected_results . first ( ) : this . search_results . find ( ".active-result" ) . first ( ) ;
@@ -941,6 +986,7 @@ Copyright (c) 2011 by Harvest
941
986
942
987
Chosen . prototype . no_results = function ( terms ) {
943
988
var no_results_html ;
989
+
944
990
no_results_html = $ ( '<li class="no-results">' + this . results_none_found + ' "<span></span>"</li>' ) ;
945
991
no_results_html . find ( "span" ) . first ( ) . html ( terms ) ;
946
992
return this . search_results . append ( no_results_html ) ;
@@ -952,6 +998,7 @@ Copyright (c) 2011 by Harvest
952
998
953
999
Chosen . prototype . keydown_arrow = function ( ) {
954
1000
var first_active , next_sib ;
1001
+
955
1002
if ( ! this . result_highlight ) {
956
1003
first_active = this . search_results . find ( "li.active-result" ) . first ( ) ;
957
1004
if ( first_active ) {
@@ -970,6 +1017,7 @@ Copyright (c) 2011 by Harvest
970
1017
971
1018
Chosen . prototype . keyup_arrow = function ( ) {
972
1019
var prev_sibs ;
1020
+
973
1021
if ( ! this . results_showing && ! this . is_multiple ) {
974
1022
return this . results_show ( ) ;
975
1023
} else if ( this . result_highlight ) {
@@ -987,6 +1035,7 @@ Copyright (c) 2011 by Harvest
987
1035
988
1036
Chosen . prototype . keydown_backstroke = function ( ) {
989
1037
var next_available_destroy ;
1038
+
990
1039
if ( this . pending_backstroke ) {
991
1040
this . choice_destroy ( this . pending_backstroke . find ( "a" ) . first ( ) ) ;
992
1041
return this . clear_backstroke ( ) ;
@@ -1011,8 +1060,9 @@ Copyright (c) 2011 by Harvest
1011
1060
} ;
1012
1061
1013
1062
Chosen . prototype . keydown_checker = function ( evt ) {
1014
- var stroke , _ref ;
1015
- stroke = ( _ref = evt . which ) != null ? _ref : evt . keyCode ;
1063
+ var stroke , _ref1 ;
1064
+
1065
+ stroke = ( _ref1 = evt . which ) != null ? _ref1 : evt . keyCode ;
1016
1066
this . search_field_scale ( ) ;
1017
1067
if ( stroke !== 8 && this . pending_backstroke ) {
1018
1068
this . clear_backstroke ( ) ;
@@ -1042,6 +1092,7 @@ Copyright (c) 2011 by Harvest
1042
1092
1043
1093
Chosen . prototype . search_field_scale = function ( ) {
1044
1094
var div , h , style , style_block , styles , w , _i , _len ;
1095
+
1045
1096
if ( this . is_multiple ) {
1046
1097
h = 0 ;
1047
1098
w = 0 ;
@@ -1072,6 +1123,7 @@ Copyright (c) 2011 by Harvest
1072
1123
1073
1124
Chosen . prototype . generate_random_id = function ( ) {
1074
1125
var string ;
1126
+
1075
1127
string = "sel" + this . generate_random_char ( ) + this . generate_random_char ( ) + this . generate_random_char ( ) ;
1076
1128
while ( $ ( "#" + string ) . length > 0 ) {
1077
1129
string += this . generate_random_char ( ) ;
@@ -1087,6 +1139,7 @@ Copyright (c) 2011 by Harvest
1087
1139
1088
1140
get_side_border_padding = function ( elmt ) {
1089
1141
var side_border_padding ;
1142
+
1090
1143
return side_border_padding = elmt . outerWidth ( ) - elmt . width ( ) ;
1091
1144
} ;
1092
1145
0 commit comments