Welcome! Select Box Factory 2.0 is a tool written using jQuery 1.2.6 for jQuery users, and was ported over from version 1.1 for mooTools. All you need to do is drop in this js file, and you can call up a select box with much more intelligence, usability, and customization that any current select box allows. This tool is an object that you instantiate with the new keyword, it is not a wrapper or a plug-in for jQuery, it simply runs on that framework, using as much of the internal logic as possible. Thanks to the folks who wrote Visual jQuery 1.2, one of the best resources I found. There is a lot to cover here, but I plan on starting simple, for those who want to just try it out and get running. When you create your first SBF, you'll get a select box that is skinnable, siftable, polymorphous, fast, browser-compatible, sortable, and resizable. They have the ability to show you counts, selections, images, numbers, urls, states in the form of a heatmap with filter buttons. They have an eraser function, a keystroke find function, spreadsheet style selection capability. They can find divs in the DOM and "absorb them" into the select box, use choices right from the JSON definition, and can easily take and allow removal of choices after the object has been returned. Using this for a "swap selection" box is a piece of cake. It is flexible enough to go beyond the average select box and the limits are your imagination. What else can you use it for? |
Lynx Cheetah Bobcat |
For those of you who want to jump right in, the snippet at the bottom shows the least amount of code you need to create a select box. Except for the div that contains your div choices which is also shown in the formatted section below, that's all there is to it. The little thing on the left with three choices is one of the simplest possible ways to show your select box. But there are several basic decisions you need to make in terms of its configuration, regardless of how you want to use it.
|
var dropdown = new sFac({ id : "fromMemory", container : "dropdownContainer" }); <div id="dropdownContainer"> <div id="lynx" title="lynx" defaultSelection="false" state="0" data="claws,stripes"> Lynx </div> <div id="cheetah" title="cheetah" defaultSelection="false" state="0" data="eyes,claws">Cheetah</div> <div id="bobcat" title="bobcat" defaultSelection="false" state="0" data="eyes,nose">Bobcat</div> </div>
When loading from the server side or even if you just want to hard code the choices without using the DOM, you can iterate by putting your server logic around the choices.
|
var dropdown = new sFac({ id : "fromTheServerSide", container : "dropdownContainer", choices : [ // iterate here for server side grab. ['leopard','leopard','Leopard',false,0,["spots"," ears"]], ['tiger','tiger','Tiger',false,0,[" tail","nose"]], ['serval','serval','Serval',true,0,["tail","nose"]], ] });
Style 1: A Dropdown | Style 2: A Select-one Box | Style 3: A Select-multiple Box |
By the time you are done, you'll see that there is a tremendous amount of flexibility and configuration for such a small widget. That can be good, but it can also be bad, for people who feel overwhelmed. That is why I'm moving into this slowly. I'll give you what I feel would be the most popular and requested, yet still very basic settings first. Although I have described two fundamental ways to load choices into your SBF's, from here on in, I will always be showing you snippets where choices are part of the definition, not found in the DOM. If you click to open the dropdowns anywhere in this tutorial, you will notice it pushes everything out of its way. That is because it is relatively positioned. Later on in this tutorial, I'll show you how to make these absolutely positioned, and yes it takes a very small bit of work. |
var dropdownType1 = new sFac({ id : "dropdownType1", container : "dropdownContainerType1", coreImages : ["clear.gif","eraser.gif"], width: 140, toggleStyle : 'closed', eraser: true, type : 'dropdown', maxSize: 6, choices : [ ['leopard','leopard','Leopard',false,0,["spots"," ears"]], ['tiger','tiger','Tiger',false,0,[" tail","nose"]], ['serval','serval','Serval',false,0,["tail","nose"]], ['lion','lion','Lion',true,0,["mane","claws"]], ['jaguar','jaguar','Jaguar',false,0,["mane","claws"]], ['cougar','cougar','Cougar',false,0,["tail","nose"]] ] });
var dropdownType2 = new sFac({ id : "dropdownType2", container : "dropdownContainerType2", width: 150, eraser: true, info: true, type : 'selectone', count : true, maxSize: 3, choices : [ ['leopard','leopard','Leopard',false,0,["spots"," ears"]], ['tiger','tiger','Tiger',false,0,[" tail","nose"]], ['serval','serval','Serval',false,0,["tail","nose"]], ['lion','lion','Lion',true,0,["mane","claws"]], ['jaguar','jaguar','Jaguar',false,0,["mane","claws"]], ['cougar','cougar','Cougar',false,0,["tail","nose"]] ] });
var dropdownType3 = new sFac({ id : "dropdownType3", container : "dropdownContainerType3", coreImages : ["clear.gif","eraser.gif","sortasc.gif","sortdesc.gif"], width: 150, eraser: true, info: true, resizable: true, type : 'selectmultiple', count : true, sortDirection : 'descending', sort:true, maxSize: 6, choices : [ ['leopard','leopard','Leopard',false,0,["spots"," ears"]], ['tiger','tiger','Tiger',false,0,[" tail","nose"]], ['serval','serval','Serval',false,0,["tail","nose"]], ['lion','lion','Lion',true,0,["mane","claws"]], ['jaguar','jaguar','Jaguar',false,0,["mane","claws"]], ['cougar','cougar','Cougar',false,0,["tail","nose"]] ] });
If you specify sift: true in your definition, you will get this feature, and it is only available for selectone or selectmultiple. To me, its the peanut butter to the select box chocolate. Essentially its a filter that reduces your list based what you type into the box. You don't even have to specify the optional "details" parameters I mentioned earlier, which show as an array at the end of the choices array (if your not using DOM), or as a comma separated attribute if you are using DOM. If you don't specify the details, you still automatically get to sift on the id, the displayname, and the state.
|
var dropdownType4 = new sFac({ id : "dropdownType4", container : "dropdownContainerType4", coreImages : ["clear.gif","eraser.gif","sortasc.gif","sortdesc.gif"], width: 150, eraser: true, info: true, type : 'selectmultiple', count : true, sort:true, sift: true, maxSize: 6, choices : [ ['leopard','leopard','Leopard',false,0,["spots"," ears"]], ['tiger','tiger','Tiger',false,0,[" tail","nose"]], ['serval','serval','Serval',false,0,["tail","nose"]], ['lion','lion','Lion',true,0,["mane","claws"]], ['jaguar','jaguar','Jaguar',false,0,["mane","claws"]], ['cougar','cougar','Cougar',false,0,["tail","nose"]] ] });
If you specify useStates : true and stateColors : [an array of colors, hex or by name] in your definition, you will get the ability to show states.
If you specify showStateButtons : true in your definition, you will get the ability to show states as buttons in the top "toggle" bar.
|
var dropdownType5 = new sFac({ id : "dropdownType5", container : "dropdownContainerType5", coreImages : ["clear.gif","eraser.gif","sortasc.gif","sortdesc.gif"], width: 150, eraser: true, info: true, type : 'selectmultiple', count : true, sort:true, sift: true, maxSize: 6, useStates : true, stateColors : ["red","orange","yellow","lightblue","darkblue"], showStateButtons : true, choices : [ ['leopard','leopard','Leopard',false,3,["spots"," ears"]], ['tiger','tiger','Tiger',false,1,[" tail","nose"]], ['serval','serval','Serval',false,2,["tail","nose"]], ['lion','lion','Lion',true,2,["mane","claws"]], ['jaguar','jaguar','Jaguar',false,4,["mane","claws"]], ['cougar','cougar','Cougar',false,2,["tail","nose"]] ] });
|
The buttons on the left are various ways you may want to update the select boxes. This is where you probably need to do the most custom work depending on what you want to achieve, although I have provided some decent samples that I created on my own.
|
function addChoices(){ dropdownType7._addChoices( [ ['lynx','lynx','Lynx',false,0,["eyes","spots"]], ['cheetah','cheetah','Cheetah',false,0,["spots"," ears"]], ['bobcat','bobcat','Bobcat',false,0,["spots"," ears"]] ] ) } function addChoicesLoad(){ var num = document.getElementById("testNum").value; if(num > 350){ document.getElementById("testNum").value = 350; return; } var arr = []; document.getElementById("testNum").disabled = true; for(i=0;i < num;i++) arr.push(['test_choice'+i,'test_choice'+i,'test_choice sample',false,0,["data1","data2"]]) dropdownType7._addChoices(arr); document.getElementById("testNum").disabled = false; } dropdownType7._addChoices([['liger','liger','Liger',true,2,['claws','stripes']]]) dropdownType7._removeChoices(['liger']) dropdownType7._addChoices([['includeLowerRange','img1','img-insideincludelower.gif',true,2,[]]]) dropdownType7._addChoices([[1132,1132,1132,false,2,[]]])
var dropdown_abs3 = new sFac({ id : "dropdown_abs3", container : "dropdownContainerAbs", coreImages : ["clear.gif","eraser.gif","sortasc.gif","sortdesc.gif"], selectionImagePath : "/",// leave / for root width: 160, resizable: true,// best for non-dropdowns. Tell uiSelectBox class to be padding:4px; to look nicer. toggleStyle : 'closed', type : 'dropdown', eraser : true, count : true, isAbsolute : true, absolutePosition : { top: 60, left : 70, z:10 }, maxSize: 6, sortDirection : 'descending', sort: true, choices : [ ['cat','cat','Cat',true,0,["eyes","teeth"]], ['leopard','leopard','Leopard',false,0,["spots"," ears"]], ['tiger','tiger','Tiger',false,0,[" tail","nose"]], ['serval','serval','Serval',false,0,["tail","nose"]], ['lion','lion','Lion',true,0,["mane","claws"]], ['kodkod','kodkod','Kodkod',true,0,["mane","claws"]], ['puma','puma','Puma',false,0,["paws","stripes"]], ['ocelot','ocelot','Ocelot',false,0,["eyes","teeth"]], ['oncilla','oncilla','Oncilla',false,0,["eyes","teeth"]], ['jaguar','jaguar','Jaguar',false,0,["mane","claws"]], ['cougar','cougar','Cougar',false,0,["tail","nose"]] ] });
Adding urls is easy, and urls get sorted just as strings do. There are a couple of issues to note, but first, the settings:
|
var dropdownUrl = new sFac({ id : "dropdownUrl", container : "dropdownContainerUrl", coreImages : ["clear.gif","eraser.gif","sortasc.gif","sortdesc.gif"], width: 160, toggleStyle : 'open', type : 'dropdown', eraser : true, count : true, maxSize: 6, sortDirection : 'descending', sort: true, choices : [ ['google','google','url-www.google.com',false,0,[]], ['dzone','dzone','url-www.dzone.com',false,0,[]], ['jQUery','jQUery','url-www.jQUery.com',false,0,[]], ['theuiguy','the ui guy','url-theuiguy.blogspot.com',false,0,[]] ] });
Adding images is also fairly easy, and images get sorted just as if they were strings. The settings:
|
var dropdown_img10 = new sFac({ id : "dropdown_img10", container : "dropdownContainer10", coreImages : ["clear.gif","eraser.gif","sortasc.gif","sortdesc.gif"], selectionImagePath : "/",// leave / for root width: 160, resizable: true,// best for non-dropdowns. Tell uiSelectBox class to be padding:4px; to look nicer. type : 'selectone', sift:true, eraser : true, count : true, maxSize: 3, sortDirection : 'descending', sort: true, choices : [ ['lion','lion','img-lion.gif',true,0,["eyes","teeth"]], ['leopard','leopard','img-leopard.gif',false,0,["spots"," ears"]], ['tiger','tiger','img-tiger.gif',false,0,[" tail","nose"]] ] });
Here are some variations in skinning that I included. In these examples, I am using a variation not seen before, which is a select box that has its toggle open by default. You can click the title to see that it does toggle.
|
for the box and choices: .uiSelectBox .uiSelectBoxToggle .uiSelectBoxToggleSift .uiSelectBoxToggleDisabled .uiSelectBoxDisabled .uiSelectBoxStack .uiSelectBoxStackDisabled .uiSelectBoxChoice .uiSelectBoxChoiceDisabled .uiSelectBoxChoice.uiSelectBoxChoiceNormal .uiSelectBoxChoice.uiSelectBoxChoiceActive .uiSelectBoxChoice.uiSelectBoxChoiceGraze .uiSelectBoxChoice.uiSelectBoxChoiceSelected .uiSelectBoxChoice.uiSelectBoxChoiceSelected a .uiSelectBoxChoice.uiSelectBoxChoiceDisabled for the states: .statesHeader .statesHeaderItem .statesHeaderItem.pushedHeaderItem .statesHeaderItem.unPushedHeaderItem for the other parts: .sortFlip .toggleText .selectUpdate .infoBar .siftBox .focusBox .link
The following features, not previously discussed come automatically with the SBF.
|
The following features, not previously discussed must be configured. For the comprehensive list of settings, see the next section.
|
The following variations are also available:
|
Setting | Type | Default if not set (or example) | Description | Notes |
---|---|---|---|---|
id | string | required | N/A | N/A |
container | string | required | this is the id of a container somewhere on the screen. | document.body will be used if no id is specified, but its not something you want. |
type | string | selectone | the dropdown type | selectone | selectmultiple | dropdown (are the choices) |
choices | array (with arrays) | if none specified, will look in DOM for choices, or will show empty otherwise. | as described above, the choices for the dropdown | |
toggleStyle | string | none | used to determined if a toggle should be shown, and if so: open or closed by default. | none | open | closed (are the choices) |
coreImages | array | ["clear.gif", "eraser3.gif", "sortasc3.gif", "sortdesc3.gif"] | list the images you required, in the directory of the js file. | |
classes | array | ["uiSelectBox", "uiSelectBoxToggle", "uiSelectBoxChoice", "uiSelectBoxStack"] | the default classes used by the select box | |
isAbsolute | boolean | false | sets the specified container to be absolute as well. | |
absolutePosition | JSON object | { top: 0, left : 0, z : 0 } | sets the top, left, and zIndex of your select box inside the container, goes with "absolutePosition". | |
urlTarget | string | "new" | where to open the url, if addding urls. | options are your standard window open options, like "self", "new", "top". |
width | number | the default is from the class first, container second. | ||
eraser | Boolean | false | whether or not to allow the clear selections feature. | |
sift | Boolean | false | whether to allow the sift feature. | sift can only be used with selectone or selectmultiple and when a toggle is present. |
info | Boolean | false | whether or not to show how many items are selected. | |
count | Boolean | false | whether or not to show how many items are in the dropdown. | |
sort | Boolean | false | whether or not to sort the list by default, and show a sort icon to allow sort flipping. | |
disabled | Boolean | false | whether or not to show the select box as disabled by default. | select box can be "enabled" later with your own function. |
typeSearch | Boolean | true | whether or not allow a user to find items by pressing a key | if your using opera 9.5, you may want this turned off, so i added this setting. Its turly horrific because of the way Opera decided to do selections. |
sortDirection | string | ascending | the direction to sort the options by default. | descending or ascending (are the choices) |
useStates | Boolean | false | whether or not to show states (0-n) in the choices. | |
showStateButtons | Boolean | false | whether or not to show state filter buttons on the toggle. | Useful if you include this with sift. The erase clears the selection. |
stateColors | array | ["red" ,"orange" ,"yellow" ,"lightblue" ,"darkblue"] | the colors, if needed, to specify for the states. | should match the unique count of states. |
maxSize | number | choices.length | how many items to show before scrolling occurs. | |
selectionImagePath | string | "/" | used to specify the path of images, if you are loading images into the dropdown instead of strings or numbers. | |
resizable | Boolean | false | whether or not to allow resizing the select box. | requires a jQuery plugin, and (works in IE only when the dropdown is absolutely positioned). |
toggleLabel | string | Select One: | what to show in the toggle when nothing is selected. | |
toggleLabelChosen | string | "" (empty) | what to prepend selections with. | example: "item selected: x". |
siftTitle | string | Use AND (+) plus, or OR (|) pipe to extend search. Use (!) not to flip the search. | what to show as the title (alt) popup. |
The following are features or enhancements I expect to be in the next release (2.1)
|
The following are issues I've noticed:
|
The following functions are stubs in the code or can be turned on or extended
|
The following are a few things to check, they come up time and time again.
|
Available under MIT style license, which in layman terms says, "go ahead and take it, mang, just at least tell people I wrote the software. But if it blows up your house or makes your dog run away, you can't sue me." That's it.
Copyright (c) 2008 Ari N. Karp |