PageSourceSearch

https://po4ivka.net/data/js/jquery.selectbox-0.6.1.js

js po4ivka.net collected 2026-10-03 01:57:01 UTC 5,429 bytes, 147 lines download raw bytes

1/**
2 * jQuery custom selectboxes
3 * 
4 * Copyright (c) 2008 Krzysztof Suszyński (suszynski.org)
5 * Licensed under the MIT License:
6 * http://www.opensource.org/licenses/mit-license.php
7 *
8 * @version 0.6.1
9 * @category visual
10 * @package jquery
11 * @subpakage ui.selectbox
12 * @author Krzysztof Suszyński <[email protected]>
13**/
14jQuery.fn.selectbox = function(options){
15	/* Default settings */
16	var settings = {
17		className: 'jquery-selectbox',
18		animationSpeed: "normal",
19		listboxMaxSize: 10,
20		replaceInvisible: false
21	};
22	var commonClass = 'jquery-custom-selectboxes-replaced';
23	var listOpen = false;
24	var showList = function(listObj) {
25		var selectbox = listObj.parents('.' + settings.className + '');
26		listObj.slideDown(settings.animationSpeed, function(){
27			listOpen = true;
28		});
29		selectbox.addClass('selecthover');
30		jQuery(document).bind('click', onBlurList);
31		return listObj;
32	}
33	var hideList = function(listObj) {
34		var selectbox = listObj.parents('.' + settings.className + '');
35		listObj.slideUp(settings.animationSpeed, function(){
36			listOpen = false;
37			jQuery(this).parents('.' + settings.className + '').removeClass('selecthover');
38		});
39		jQuery(document).unbind('click', onBlurList);
40		return listObj;
41	}
42	var onBlurList = function(e) {
43		var trgt = e.target;
44		var currentListElements = jQuery('.' + settings.className + '-list:visible').parent().find('*').andSelf();
45		if(jQuery.inArray(trgt, currentListElements)<0 && listOpen) {
46			hideList( jQuery('.' + commonClass + '-list') );
47		}
48		return false;
49	}
50	
51	/* Processing settings */
52	settings = jQuery.extend(settings, options || {});
53	/* Wrapping all passed elements */
54	return this.each(function() {
55		var _this = jQuery(this);
56		if(_this.filter(':visible').length == 0 && !settings.replaceInvisible)
57			return;
58		var replacement = jQuery(
59			'<div class="' + settings.className + ' ' + commonClass + '">' +
60				'<div class="' + settings.className + '-moreButton" />' +
61				'<div class="' + settings.className + '-list ' + commonClass + '-list" />' +
62				'<span class="' + settings.className + '-currentItem" />' +
63			'</div>'
64		);
65		jQuery('option', _this).each(function(k,v){
66			var v = jQuery(v);
67			var listElement =  jQuery('<span class="' + settings.className + '-item value-'+v.val()+' item-'+k+'">' + v.text() + '</span>');	
68			listElement.click(function(){
69				var thisListElement = jQuery(this);
70				var thisReplacment = thisListElement.parents('.'+settings.className);
71				var thisIndex = thisListElement[0].className.split(' ');
72				for( k1 in thisIndex ) {
73					if(/^item-[0-9]+$/.test(thisIndex[k1])) {
74						thisIndex = parseInt(thisIndex[k1].replace('item-',''), 10);
75						break;
76					}
77				};
78				var thisValue = thisListElement[0].className.split(' ');
79				for( k1 in thisValue ) {
80					if(/^value-.+$/.test(thisValue[k1])) {
81						thisValue = thisValue[k1].replace('value-','');
82						break;
83					}
84				};
85				thisReplacment
86					.find('.' + settings.className + '-currentItem')
87					.text(thisListElement.text());
88				thisReplacment
89					.find('select')
90					.val(thisValue)
91					.triggerHandler('change');
92				var thisSublist = thisReplacment.find('.' + settings.className + '-list');
93				if(thisSublist.filter(":visible").length > 0) {
94					hideList( thisSublist );
95				}else{
96					showList( thisSublist );
97				}
98			}).bind('mouseenter',function(){
99				jQuery(this).addClass('listelementhover');
100			}).bind('mouseleave',function(){
101				jQuery(this).removeClass('listelementhover');
102			});
103			jQuery('.' + settings.className + '-list', replacement).append(listElement);
104			if(v.filter(':selected').length > 0) {
105				jQuery('.'+settings.className + '-currentItem', replacement).text(v.text());
106			}
107		});
108		replacement.find('.' + settings.className + '-moreButton').click(function(){
109			var thisMoreButton = jQuery(this);
110			var otherLists = jQuery('.' + settings.className + '-list')
111				.not(thisMoreButton.siblings('.' + settings.className + '-list'));
112			hideList( otherLists );
113			var thisList = thisMoreButton.siblings('.' + settings.className + '-list');
114			if(thisList.filter(":visible").length > 0) {
115				hideList( thisList );
116			}else{
117				showList( thisList );
118			}
119		}).bind('mouseenter',function(){
120			jQuery(this).addClass('morebuttonhover');
121		}).bind('mouseleave',function(){
122			jQuery(this).removeClass('morebuttonhover');
123		});
124		_this.hide().replaceWith(replacement).appendTo(replacement);
125		var thisListBox = replacement.find('.' + settings.className + '-list');
126		var thisListBoxSize = thisListBox.find('.' + settings.className + '-item').length;
127		if(thisListBoxSize > settings.listboxMaxSize)
128			thisListBoxSize = settings.listboxMaxSize;
129		if(thisListBoxSize == 0)
130			thisListBoxSize = 1;	
131		var thisListBoxWidth = Math.round(_this.width() + 5);
132		if(jQuery.browser.safari)
133			thisListBoxWidth = thisListBoxWidth * 0.94;
134		replacement.css('width', thisListBoxWidth + 'px');
135		thisListBox.css({
136			width: Math.round(thisListBoxWidth-5) + 'px',
137			height: thisListBoxSize + 'em'
138		});
139	});
140}
141jQuery.fn.unselectbox = function(){
142	var commonClass = 'jquery-custom-selectboxes-replaced';
143	return this.each(function() {
144		var selectToRemove = jQuery(this).filter('.' + commonClass);
145		selectToRemove.replaceWith(selectToRemove.find('select').show());		
146	});
147}

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.