1if (jQuery) 2 (function($) { 3 $.extend($.fn, { 4 selectBox : function(o, data) { 5 var _show = function(event) { 6 var select = event.data.select; 7 var control = event.data.control; 8 9 if ($(control).hasClass('ui-selectBox-disabled')) 10 return false; 11 if ($(control).hasClass('ui-selectBox-focus') 12 && $("#ui-selectBox-dropdown").size() === 1) { 13 _hide(event, true); 14 return false 15 } 16 $('.ui-selectBox').not(control).trigger('blur'); 17 _focus(event); 18 event.stopPropagation(); 19 $("#ui-selectBox-dropdown").remove(); 20 var dropdown = $('<div id="ui-selectBox-dropdown" class="ui-corner-bottom ' + locale + ' ' + select[0].id +'" />'); 21 var options = $('<ul />'); 22 23 if ($(select).children('optgroup').size() === 0) { 24 $(select).children('option').each(function() { 25 var text = $(this).text() !== '' 26 ? $(this).text() 27 : '\u00A0'; 28 var extraClasses = ''; 29 if ($(this).attr('disabled')) 30 extraClasses += ' ui-selectBox-disabled'; 31 $(options).append('<li class="ui-selectBox-option' 32 + extraClasses + '">
32' + text + '</li>') 33 }) 34 } else { 35 $(dropdown).addClass('ui-selectBox-hasOptgroups'); 36 $(select).children('optgroup').each(function() { 37 $(options) 38 .append('<li class="ui-selectBox-optgroup">' 39 + $(this).attr('label') + '</li>'); 40 $(this).children('option').each(function() { 41 var text = $(this).text() !== '' ? $(this) 42 .text() : '\u00A0'; 43 var extraClasses = ''; 44 if ($(this).attr('disabled')) 45 extraClasses += ' ui-selectBox-disabled'; 46 $(options) 47 .append('<li class="ui-selectBox-option' 48 + extraClasses 49 + '">' 50 + text 51 + '</li>') 52 }) 53 }) 54 } 55 $(dropdown).append(options); 56 var selectedIndex = $(select)[0].selectedIndex; 57 $(dropdown) 58 .find('LI.ui-selectBox-option') 59 .eq(selectedIndex) 60 .addClass('ui-selectBox-initial ui-selectBox-current'); 61 $(dropdown).find('LI.ui-selectBox-option').hover( 62 function() { 63 $(dropdown).find('.ui-selectBox-current') 64 .removeClass('ui-selectBox-current'); 65 $(this).addClass('ui-selectBox-current') 66 }, function() { 67 $(this).removeClass('ui-selectBox-current') 68 }).click({ 69 select : select, 70 control : control 71 }, function(event) { 72 _select(event) 73 }).mouseup({ 74 select : select, 75 control : control 76 }, function(event) { 77 $(event.target).trigger('click') 78 }); 79 $('BODY').append(dropdown); 80 var cPos = $(control).offset(); 81 var cHeight = $(control).outerHeight(); 82 var cWidth = $(control).outerWidth(); 83 var borderAdjustment = parseInt($(dropdown) 84 .css('borderLeftWidth')) 85 + parseInt($(dropdown).css('borderRightWidth')); 86 $(dropdown).css({ 87 position : 'absolute', 88 zIndex : '999999', 89 top : cPos.top + cHeight, 90 left : cPos.left, 91 width : cWidth - borderAdjustment 92 }).show(); 93 $(control).removeClass('ui-corner-all2') 94 .addClass('ui-corner-top2'); 95 _disableSelection(dropdown); 96 _dropdownScrollFix(true) 97 }; 98 var _hide = function(event, preventBlur) { 99 var select = event.data.select; 100 var control = event.data.control; 101 $("#ui-selectBox-dropdown").remove(); 102 $(control).removeClass('ui-corner-top2') 103 .addClass('ui-corner-all2'); 104 if (!preventBlur) { 105 _blur(event) 106 } else { 107 $(control).focus() 108 } 109 }; 110 var _select = function(event, option) { 111 var select = event.data.select; 112 var control = event.data.control; 113 option = option ? option : event.target; 114 if ($(option).hasClass('ui-selectBox-disabled')) 115 return false; 116 var oldSelectedIndex = $(select)[0].selectedIndex; 117 $('#ui-selectBox-dropdown .ui-selectBox-optgroup').remove(); 118 var newSelectedIndex = $('#ui-selectBox-dropdown') 119 .find('LI.ui-selectBox-current').index(); 120 if (oldSelectedIndex !== newSelectedIndex) { 121 $(select)[0].selectedIndex = newSelectedIndex; 122 $(control).find('.ui-selectBox-label').text($(option) 123 .text()); 124 $(select).trigger('change') 125 } 126 _hide(event, true) 127 }; 128 var _focus = function(event) { 129 var select = event.data.select; 130 var control = event.data.control; 131 if ($(control).hasClass('ui-selectBox-disabled')) 132 return true; 133 if ($(control).hasClass('ui-selectBox-focus')) 134 return false; 135 $(".ui-selectBox.ui-selectBox-focus") 136 .removeClass("ui-selectBox-focus"); 137 $("#ui-selectBox-dropdown").remove(); 138 $(control).addClass('ui-selectBox-focus'); 139 $(document).bind('mousedown', { 140 select : select, 141 control : control 142 }, _blur); 143 $(document).bind('keydown', { 144 select : select, 145 control : control 146 }, _key); 147 $(select).trigger('focus'); 148 $(control).focus() 149 }; 150 var _blur = function(event) { 151 var select = event.data.select; 152 var control = event.data.control; 153 if($(event.target).hasClass('ui-corner-top2')) { 154 return false; 155 } 156 if (event.target.id === 'ui-selectBox-dropdown' 157 || $(event.target) 158 .parents('#ui-selectBox-dropdown').size() === 1) { 159 $(control).trigger('focus'); 160 return false 161 } 162 if ($(control).hasClass('ui-selectBox-focus')) { 163 $(control).removeClass('ui-selectBox-focus'); 164 $(document).unbind('mousedown', _blur); 165 $(document).unbind('keydown', _key); 166 $(select).trigger('blur'); 167 _hide(event) 168 } 169 }; 170 var _key = function(event) { 171 var select = event.data.select; 172 var control = event.data.control; 173 var dropdown = $("#ui-selectBox-dropdown"); 174 if ($(control).hasClass('ui-selectBox-disabled')) 175 return false; 176 switch (event.keyCode) { 177 case 9 : 178 _blur(event); 179 break; 180 case 13 : 181 if ($(dropdown).size() === 0) 182 return false; 183 var siblings = $(dropdown) 184 .find('.ui-selectBox-option'); 185 var currentIndex = -1; 186 $.each(siblings, function(index, option) { 187 if ($(option).hasClass('ui-selectBox-current')) { 188 currentIndex = index; 189 return 190 } 191 });
192 if (currentIndex >= 0) { 193 _select(event, $(siblings).eq(currentIndex)) 194 } 195 return false; 196 break; 197 case 27 : 198 _hide(event, true); 199 break; 200 case 38 : 201 case 37 : 202 case 33 : 203 var interval = event.keyCode === 33 ? 20 : 1; 204 if ($(dropdown).size() === 0) { 205 if (event.altKey) { 206 _show(event); 207 return false 208 } 209 var totalIndexes = $(select).find('OPTION') 210 .size(), oldSelectedIndex = $(select)[0].selectedIndex, newSelectedIndex = $(select)[0].selectedIndex 211 - interval; 212 while ($(select).find('OPTION') 213 .eq(newSelectedIndex).attr('disabled') === true 214 && newSelectedIndex >= 0) { 215 newSelectedIndex-- 216 } 217 if (newSelectedIndex < 0) { 218 newSelectedIndex = $(select) 219 .find('OPTION:not([disabled]):first') 220 .index() 221 } 222 $(select)[0].selectedIndex = newSelectedIndex; 223 if ($(select)[0].selectedIndex === -1) { 224 newSelectedIndex = 0; 225 $(select)[0].selectedIndex = newSelectedIndex 226 } 227 var label = $(select).find('OPTION:selected') 228 .text(); 229 if (label === '') 230 label = '\u00A0'; 231 $(control).find('.ui-selectBox-label') 232 .text(label); 233 if (newSelectedIndex !== oldSelectedIndex) 234 $(select).trigger('change'); 235 return false 236 } 237 var siblings = $(dropdown) 238 .find('.ui-selectBox-option'); 239 var currentIndex = -1; 240 $.each(siblings, function(index, option) { 241 if ($(option).hasClass('ui-selectBox-current')) { 242 currentIndex = index; 243 return 244 } 245 }); 246 currentIndex = currentIndex - interval; 247 if (currentIndex < 0) 248 currentIndex = 0; 249 $(siblings).removeClass('ui-selectBox-current'); 250 $(siblings).eq(currentIndex) 251 .addClass('ui-selectBox-current'); 252 _dropdownScrollFix(); 253 return false; 254 break; 255 case 40 : 256 case 39 : 257 case 34 : 258 var interval = event.keyCode === 34 ? 20 : 1; 259 if ($(dropdown).size() === 0) { 260 if (event.altKey) { 261 _show(event); 262 return false 263 } 264 var totalIndexes = $(select).find('OPTION') 265 .size(), oldSelectedIndex = $(select)[0].selectedIndex, newSelectedIndex = $(select)[0].selectedIndex 266 + interval; 267 while ($(select).find('OPTION') 268 .eq(newSelectedIndex).attr('disabled') === true 269 && newSelectedIndex <= $(select) 270 .find('OPTION').size()) { 271 newSelectedIndex++ 272 } 273 if (newSelectedIndex > totalIndexes - 1) { 274 newSelectedIndex = $(select) 275 .find('OPTION:not([disabled]):last') 276 .index() 277 } 278 $(select)[0].selectedIndex = newSelectedIndex; 279 if ($(select)[0].selectedIndex === -1) { 280 newSelectedIndex = $(select).find('OPTION') 281 .size() 282 - 1; 283 $(select)[0].selectedIndex = newSelectedIndex 284 } 285 var label = $(select).find('OPTION:selected') 286 .text(); 287 if (label === '') 288 label = '\u00A0'; 289 $(control).find('.ui-selectBox-label') 290 .text(label); 291 if (newSelectedIndex != oldSelectedIndex) 292 $(select).trigger('change'); 293 return false 294 } 295 var siblings = $(dropdown) 296 .find('.ui-selectBox-option'); 297 var currentIndex = -1; 298 $.each(siblings, function(index, option) { 299 if ($(option).hasClass('ui-selectBox-current')) { 300 currentIndex = index; 301 return 302 } 303 }); 304 currentIndex = currentIndex + interval; 305 if (currentIndex > $(siblings).size() - 1) 306 currentIndex = $(siblings).size() - 1; 307 $(siblings).removeClass('ui-selectBox-current'); 308 $(siblings).eq(currentIndex) 309 .addClass('ui-selectBox-current'); 310 _dropdownScrollFix(); 311 return false; 312 break; 313 case 36 : 314 case 35 : 315 if ($(dropdown).size() === 0) { 316 if (event.altKey) { 317 _show(event); 318 return false 319 } 320 var oldSelectedIndex = $(select)[0].selectedIndex, newSelectedIndex; 321 if (event.keyCode === 36) { 322 newSelectedIndex = 0 323 } else { 324 newSelectedIndex = $(select).find('OPTION') 325 .size() 326 - 1 327 } 328 if ($(select).find('OPTION') 329 .eq(newSelectedIndex).attr('disabled') === true) { 330 if (event.keyCode === 36) { 331 newSelectedIndex = $(select) 332 .find('OPTION:not([disabled]):first') 333 .index() 334 } else { 335 newSelectedIndex = $(select) 336 .find('OPTION:not([disabled]):last') 337 .index() 338 } 339 } 340 $(select)[0].selectedIndex = newSelectedIndex; 341 var label = $(select).find('OPTION:selected') 342 .text(); 343 if (label === '') 344 label = '\u00A0'; 345 $(control).find('.ui-selectBox-label') 346 .text(label); 347 if (newSelectedIndex != oldSelectedIndex) 348 $(select).trigger('change'); 349 return false 350 } 351 $(dropdown).find('.ui-selectBox-current') 352 .removeClass('ui-selectBox-current'); 353 if (event.keyCode === 36) { 354 $(dropdown).find('.ui-selectBox-option:first') 355 .addClass('ui-selectBox-current') 356 } else { 357 $(dropdown).find('.ui-selectBox-option:last') 358 .addClass('ui-selectBox-current') 359 } 360 _dropdownScrollFix(); 361 return false; 362 break 363 } 364 }; 365 var _dropdownScrollFix = function(centerSelection) { 366 var dropdown = $("#ui-selectBox-dropdown"); 367 if ($(dropdown).size() === 0) 368 return false; 369 var target = $(dropdown).find('.ui-selectBox-current'); 370 if ($(target).size() === 0) 371 return false; 372 var targetTop = parseInt($(target).offset().top 373 - $(dropdown).position().top); 374 var targetBottom = parseInt(targetTop 375 + $(target).outerHeight()); 376 if (centerSelection) { 377 $(dropdown).scrollTop($(target).offset().top 378 - $(dropdown).offset().top 379 + $(dropdown).scrollTop() 380 - ($(dropdown).height() / 2)) 381 } else { 382 if (targetTop < 0) { 383 $(dropdown).scrollTop($(target).offset().top 384 - $(dropdown).offset().top 385 + $(dropdown).scrollTop()) 386 } 387 if (targetBottom > $(dropdown).height()) { 388 $(dropdown) 389 .scrollTop(($(target).offset().top + $(target) 390 .outerHeight()) 391 - $(dropdown).offset().top 392 + $(dropdown).scrollTop() 393 - $(dropdown).height()) 394 } 395 } 396 }; 397 var _disableSelection = function(selector) { 398 $(selector).css('MozUserSelect', 'none').bind( 399 'selectstart', function() { 400 return false 401 }).bind('mousedown', function() { 402 return false 403 });
404 return true 405 }; 406 switch (o) { 407 case 'destroy' : 408 $(this).each(function() { 409 var select = $(this); 410 var control = $(this).next('.ui-selectBox'); 411 if ($(select)[0].tagName.toLowerCase() === 'select') { 412 $(control).remove(); 413 $(select).show() 414 } 415 }); 416 return $(this); 417 break; 418 case 'disable' : 419 $(this).each(function() { 420 var select = $(this); 421 var control = $(this).next('.ui-selectBox'); 422 $(select).attr('disabled', true); 423 $(control) 424 .addClass('ui-selectBox-disabled') 425 }); 426 return $(this); 427 break; 428 case 'enable' : 429 $(this).each(function() { 430 var select = $(this); 431 var control = $(this).next('.ui-selectBox'); 432 $(select).attr('disabled', false); 433 $(control) 434 .removeClass('ui-selectBox-disabled') 435 }); 436 return $(this); 437 break; 438 default : 439 $(this).each(function() { 440 var select = $(this); 441 if ($(this).next('.ui-selectBox').size() === 0) { 442 var control = $('<a href="#" class="ui-selectBox" tabindex="' 443 + parseInt($(select).attr('tabindex')) 444 + '" />'); 445 if ($(select)[0].tagName.toLowerCase() !== 'select' 446 || $(select).attr('multiple') === true) 447 return; 448 if ($(select).attr('disabled') === true) 449 $(control) 450 .addClass('ui-selectBox-disabled'); 451 var label = $(select).find('OPTION:selected') 452 .text(); 453 if (label === '') 454 label = '\u00A0'; 455 $(control) 456 .append('<span class="ui-selectBox-label">' 457 + label + '</span>'); 458 $(control) 459 .append('<span class="ui-selectBox-arrow"></span>'); 460 $(select).hide().after(control); 461 _disableSelection(control); 462 $(control).bind('click', function() { 463 return false 464 }).bind('mousedown', { 465 select : select, 466 control : control 467 }, _show).bind('focus', { 468 select : select, 469 control : control 470 }, _focus).bind('blur', { 471 select : select, 472 control : control 473 }, _blur) 474 } 475 }); 476 return $(this); 477 break 478 } 479 } 480 }) 481 })(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.