Before you begin download the newest jQuery library and the plainList (jquery.plainlist.js) plugin. Save both to "js/" folder on your webserver.
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery.plainlist.js"></script>
.plainList_normal {
padding:5px 5px 5px 5px;
margin:3px 3px 3px 3px;
border:2px solid #EDE5DF;
display:inline-block;
cursor:pointer;
background-color:#CEC7B8;
}
.plainList_hover {
background-color:#eeeeee;
}
.plainList_selected {
color:white;
background-color:#65482C;
}
<div id="myElement"></div>
Insert pre defined elements. Each element schould have a pattern like this: {"element-id":{"attribute1":"attribute value", ...}, ...}
$("#eElements1").plainList({
elements: {"aaa":{title:"AAA"}, "bbb": {title:"BBB"}, "ccc": {title:"CCC"}}
});
Style classes for normal, mouse over and selected elements.
$("#eClasses1").plainList({
classes: {
normal : "myNormal",
hover : "myHover",
selected : "mySelected"
},
elements: {"aaa":{title:"AAA"}, "bbb": {title:"BBB"}, "ccc": {title:"CCC"}}
});
Allow selection of multiple elements.
$("#elementMultiselect2").plainList({
multiselect : false,
elements: {"aaa":{title:"AAA"}, "bbb": {title:"BBB"}, "ccc": {title:"CCC"}}
});
The element title (text of the element) will be redered by using this function.
(String) id - ID of the element.
(Object) attr object with attributes of the current element.
$("#eTitleRenderer1").plainList({
elements: {"aaaa":{title:"AAAA"}, "bb": {title:"BB"}, "ccc": {title:"CCC"}},
titleRenderer : function(attr){
var number = randomNumber(10,3000);
return attr["title"]+" ("+attr["title"].length+" chars)";
}
});
This function will be called every time selection changes.
$("#eOnChange1").plainList({
elements: {"aaa":{title:"AAA"}, "bbb": {title:"BBB"}, "ccc": {title:"CCC"}},
onChange: function(selected){
alert("Selected elements: "+selected);
},
});
You can directly assign the created plainList object to a variable. For accessing its methods later simply use the variable.
var access1 = $("#eAccess1").plainList({});
for(var i=0; i<10; i++) {
access1.append(Math.round(Math.random()*1000));
}
It's not necessary to store each plainList object in a separate variable. Once you created it you can access it's methods by initialising it without any options.
(look at the previous plainList object after a click)
<button onclick='$("#eAccess1").plainList().append(Math.round(Math.random()*1000))'>Append</button>
(String) id - the unique ID of the element. It is not possible to insert two or more elements with identical ID in a plainList element.
(Object) attr - (Optional) an object with key-value pairs which will be saved in the object. If attr is empty, the attr.title will be automatical created and set to id.
$("#eAppend1").plainList().append(Math.round(Math.random()*1000), {title: "WWW"});
If attributes is undefined: the method returns all attributes of an element.
If attributes are defined: the attributes of particulat object will be set to attributes.
(String) id - id of an element.
alert($("#eAttr1").plainList().attr("aaa").title)
Removes all elements from the plainList container and returns the cleared plainList object.
$("#eClear1").plainList().clear();
Clone all elements and their attributes (only first level of attributes).
$("#eClone2").plainList({elements:$("#eClone1").plainList().clone()});
Clone all selected elements and their attributes (only first level of attributes).
$("#eCloneSelected2").plainList({elements:$("#eCloneSelected1").plainList().cloneSelected()});
Returns a DOM object reference of element.
(String) id - ID of an element.
$("#eGetElement1").plainList().getElement("aaa").css("font-size","22pt");
Returns array if IDs of all elements of the list.
alert($("#eGetElementIds1").plainList().getElementIds());
Returns all DOM objects of all elements (buttons). In the example below we use this method to add a qTip tooltip to every element.
$("#eGetElements1").plainList({
elements: {"aaa":{title:"AAA"}, "bbb": {title:"BBB"}, "ccc": {title:"CCC"}}
});
$.each($("#eGetElements1").plainList().getElements(), function(index, item){
$(item).qtip({ content: 'Hello!', style: { name: 'cream', tip: true } });
});
Returns an array of IDs of selected elements.
$("#eGetSelected1").plainList().getSelected()
Repaints an element with particular id. This method can be used if the content depends on attributes of the element.
(String) id - ID of an element.
$("#eRepaint1").plainList().attr("aaa").color = "blue";
$("#eRepaint1").plainList().repaint("aaa");
This method selects an element with particular ID.(String) id - element's ID.
(boolean) state - (Optional) the end state of the element. true - selected, false - unselected.
/ /
$('#eSelect1').plainList().select('aaa');
$('#eSelect1').plainList().select('aaa', true);
$('#eSelect1').plainList().select('aaa', false);
(boolean) select - true - all elements will be selected, false - all already selected elements will be unselected.
/
$('#eSelectall1').plainList().selectAll(true);
$('#eSelectall1').plainList().selectAll(false);
Enable or disable multiselect.
(boolean) multiselect - true - enable multiselect, false - disable multiselect (selected items except one will be unselected).
/
$('#eSetMultiselect1').plainList().setMultiselect(true);
$('#eSetMultiselect1').plainList().setMultiselect(false);