Skip to content

Instantly share code, notes, and snippets.

View acatl's full-sized avatar

Acatl Pacheco acatl

  • ViacomCBS
  • New York, NY
View GitHub Profile
@acatl
acatl / gist:1098705
Created July 22, 2011 01:47
ir.itemrenderer's options
$.widget("ir.itemrenderer", {
options: {
/** type string, name of widget to use as renderer */
itemRenderer:null,
/** type function, function that will be executed on each iteration*/
rendererFunction:null,
/** type function, function to process the label that will be used */
labelFunction:null,
/** type string, name of the field to use as the label */
labelField:null,
@acatl
acatl / gist:1098774
Created July 22, 2011 02:39
itemrenderer example 1
$(function () {
var itemrendererOptions = {
dataProvider: ["lorem", "lipsum", "dolor", "sit"]
};
$("#itemrenderer").itemrenderer(itemrendererOptions);
});
@acatl
acatl / gist:1098808
Created July 22, 2011 03:06
itemrenderer example 2: using objects as elements of the dataProvider
$(function () {
var itemrendererOptions = {
dataProvider: [
{
label: "lorem"
},
{
label: "lipsum"
},
{
@acatl
acatl / gist:1098839
Created July 22, 2011 03:38
itemrenderer example 3: using labelField option
$(function () {
var itemrendererOptions = {
labelField: "name",
dataProvider: [
{
name: "lorem"
},
{
name: "lipsum"
},
@acatl
acatl / gist:1098878
Created July 22, 2011 04:18
itemrenderer example 4.1: using labelFunction option
var itemrendererOptions = {
labelFunction: function (data, options) {
return "$ " + data.price;
},
dataProvider: [
{
name: "lorem",
price: 123.34
},
{
@acatl
acatl / gist:1098891
Created July 22, 2011 04:31
itemrenderer example 4.2: using labelFunction option using the options argument
var itemrendererOptions = {
labelField: "name",
labelFunction: function (data, options) {
return data[options.labelField] + " is $ " + data.price;
},
dataProvider: [
{
name: "lorem",
price: 123.34
},
@acatl
acatl / gist:1098903
Created July 22, 2011 04:38
itemrenderer example 5: using rendererFunction option
var itemrendererOptions = {
labelField: "name",
rendererFunction: function (container, listData) {
if(listData.data.price > 100) {
container.css("color","red");
}
container.html(listData.label);
},
dataProvider: [
{
@acatl
acatl / gist:1098931
Created July 22, 2011 05:13
itemrenderer example 6: using the itemRenderer option
// create a custom widget to be attached to each of the items created.
$.widget("ui.customwidget", {
options: {
listData:null
},
_create: function (){
this.element.addClass("ui-customwidget");
$("<span></span>")
.text(this.options.listData.data.name + " is $" + this.options.listData.data.price)
@acatl
acatl / gist:1099971
Created July 22, 2011 17:52
requiredfield example
var requeiredFieldOptions = {
watermarkText: "Enter age here...",
functionValidate: function(value) {
if (parseInt(value) < 18) {
return false;
}
return true;
},
dataType: "number",
liveCheck: true
@acatl
acatl / gist:4196153
Created December 3, 2012 16:38
Parse JS object path that uses dot and bracket notation
parse = (obj, path) ->
path = path.split(/[\[\]\.]+/)
path.pop() if path[path.length - 1] is ""
while path.length and (obj = obj[path.shift()])
;
obj