Download version 2.2.1 (uncompressed*) | See below for Acknowledgements.
|
Welcome! Select Box Factory 2.2.1j 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 than any current select box allows.
Whats new in 2.1? Aside from a few bugs fixes, check it out on the left. See the little bar graph icon? Click it! Then mouseover the bar graph and labels. Whats new in 2.2.x? The ability to call your own code when someone touches a dropdown, the ability to grab all selections, and the ability to show images and text together in one dropdown, and images in the toggle. 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 and now a graph. 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. |
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 may 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 hard-coded and not by searching for DOM elements. If you click to open the closed dropdown, you may notice that 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, then you will get this feature, and it is only available for selectone or selectmultiple. To me, it's the peanut butter to the select box chocolate. Essentially it's 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 you're 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"]] ] });
Colored States: If you specify useStates : true and stateColors : [an array of colors, hex or by name] in your definition, then you will get the ability to show states.
If you specify showStateButtons : true in your definition, then you will get the ability to show states as buttons in the top "toggle" bar.
In 2.1, you can now turn your states into a 5-state css graph. Click the little graph icon and watch it appear. The bars show you all the items that belong to that particular state, and the labels, if they happen to be truncated, do have title text popups as well and this shows you the entire state.
|
var dropdownType5 = new sFac({ id : "dropdownType5", container : "dropdownContainerType5", coreImages : ["clear.gif","eraser.gif","sortasc.gif","sortdesc.gif","graphicon.gif"], width: 150, type : 'selectmultiple', count : true, sort: true, eraser: true, info: true, maxSize: 6, useStates : true, states : ["red","orange","yellow","blue","green"], stateColors : ["#BB4446","#E6B42F","#E0DE0D","#577CCD","#77A05C"], showStateButtons : true, showStateGraph : true, boxScale : 32.0, choices : [ ['leopard','leopard','Leopard',false,1,["spots"," ears"]], ['tiger','tiger','Tiger',false,1,[" tail","nose"]], ['serval','serval','Serval',false,2,["tail","nose"]], ['lion','lion','Lion',true,3,["mane","claws"]], ['jaguar','jaguar','Jaguar',false,4,["mane","claws"]], ['cougar','cougar','Cougar',false,5,["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 : "images/", 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", imageSelections : { show: true, height: 35, padding: { top:2, left:0, bottom: 2, right: 0 } }, container : "dropdownContainer10", coreImages : ["clear.gif","eraser.gif","sortasc.gif","sortdesc.gif"], selectionImagePath : "images/", coreImagePath : "images/", width: 180, 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: 4, sortDirection : 'descending', sort: true, choices : [ ['lion','lion','img-lion.gif',true,0,[]], ['leopard','leopard','img-leopard.gif',false,0,[]], ['tiger','tiger','img-tiger.gif',false,0,[]] ['tiger','tiger','img-tiger.gif|Any Text I want...',false,0,[]], ['tiger.com','tiger.com','url-www.tigers.com',false,0,[]] ] });
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
|
function gatherAllChoices(){ var monthsSelected = monthSelect._gatherChoices(";"); // using semicolon separated list as example var yearsSelected = yearSelect._gatherChoices(";"); //alert("Months:" + monthsSelected + " Years:" + yearsSelected); }
function gatherAllChoices(){ < button onclick="$(monthSelect.dropdownStack.childNodes[0]).trigger('externalClick')"> reset month < /button > < button onclick="$(yearSelect.dropdownStack.childNodes[0]).trigger('externalClick')" > reset year < /button > }
function selectBoxItemHook(box){ //this happens when you press a select box item, now part of the tookit. defaults to nothing (as in this demo). // example of what you may want to write. switch(box.id){ case "example1": // user clicked anything in the month sFac log.out("general note: i clicked something either manually or programmatically in example1") break; case "example2": // user clicked anything in the year sFace log.out("general note: i clicked something either manually or programmatically in example2") break; } }
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 it's 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", "graphIcon.gif"] | list the images you required, in the directory of the js file. | graphIcon is new in 2.1 |
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 you're using opera 9.5, you may want this turned off, so i added this setting. It's truly 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) |
states (2.1) | string | ,["red","orange","yellow","blue","green"] | the names of your states to show on the chart. | in 2.1, you call a state using 1-n, not 0-n. |
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. | |
coreImagePath (2.2.1) | string | same as selectionImagePath is not defined | used to specify the path of the images core to the select box and not the selections. (like the eraser, graph, dropdown bg) | |
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. | |
showStateGraph (2.1) | boolean | false | whether to show the graph or not. | |
graphPosition (2.1) | string | relative | what position to place the graph. | absolute or relative |
boxScale (2.1) | decimal | 3.0 | The scaling factor for your graph. | the higher the scale, the taller each segment in a bar will be. |
imageSelections (2.2.1) | JSON definition | false | When you want an image to appear in the toggle of a dropdown. | { show: true, height: 35, padding: { top:2, left:0, bottom:2, right: 0}} |
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 - the parts the I myself wrote. But if it blows up your house or makes your dog run away, you can't sue me." That's it.
SelectboxFactory.js Copyright (c) 2008 Headcircus |