');
g.selectBox.table = $("table:first", g.selectBox);
//外层
g.wrapper = g.inputText.wrap('').parent();
g.wrapper.append('');
g.wrapper.append(g.link);
//添加个包裹,
g.textwrapper = g.wrapper.wrap('').parent();
if (p.absolute)
g.selectBox.appendTo('body').addClass("l-box-select-absolute");
else
g.textwrapper.append(g.selectBox);
g.textwrapper.append(g.valueField);
g.inputText.addClass("l-text-field");
if (p.isShowCheckBox && !g.select)
{
$("table", g.selectBox).addClass("l-table-checkbox");
} else
{
p.isShowCheckBox = false;
$("table", g.selectBox).addClass("l-table-nocheckbox");
}
//开关 事件
g.link.hover(function ()
{
if (p.disabled) return;
this.className = "l-trigger-hover";
}, function ()
{
if (p.disabled) return;
this.className = "l-trigger";
}).mousedown(function ()
{
if (p.disabled) return;
this.className = "l-trigger-pressed";
}).mouseup(function ()
{
if (p.disabled) return;
this.className = "l-trigger-hover";
}).click(function ()
{
if (p.disabled) return;
if (g.trigger('beforeOpen') == false) return false;
g._toggleSelectBox(g.selectBox.is(":visible"));
});
g.inputText.click(function ()
{
if (p.disabled) return;
if (g.trigger('beforeOpen') == false) return false;
g._toggleSelectBox(g.selectBox.is(":visible"));
}).blur(function ()
{
if (p.disabled) return;
g.wrapper.removeClass("l-text-focus");
}).focus(function ()
{
if (p.disabled) return;
g.wrapper.addClass("l-text-focus");
});
g.wrapper.hover(function ()
{
if (p.disabled) return;
g.wrapper.addClass("l-text-over");
}, function ()
{
if (p.disabled) return;
g.wrapper.removeClass("l-text-over");
});
g.resizing = false;
g.selectBox.hover(null, function (e)
{
if (p.hideOnLoseFocus && g.selectBox.is(":visible") && !g.boxToggling && !g.resizing)
{
g._toggleSelectBox(true);
}
});
var itemsleng = $("tr", g.selectBox.table).length;
if (!p.selectBoxHeight && itemsleng < 8) p.selectBoxHeight = itemsleng * 30;
if (p.selectBoxHeight)
{
g.selectBox.height(p.selectBoxHeight);
}
//下拉框内容初始化
g.bulidContent();
g.set(p);
//下拉框宽度、高度初始化
if (p.selectBoxWidth)
{
g.selectBox.width(p.selectBoxWidth);
}
else
{
g.selectBox.css('width', g.wrapper.css('width'));
}
},
destroy: function ()
{
if (this.wrapper) this.wrapper.remove();
if (this.selectBox) this.selectBox.remove();
this.options = null;
$.ligerui.remove(this);
},
_setDisabled: function (value)
{
//禁用样式
if (value)
{
this.wrapper.addClass('l-text-disabled');
} else
{
this.wrapper.removeClass('l-text-disabled');
}
},
_setLable: function (label)
{
var g = this, p = this.options;
if (label)
{
if (g.labelwrapper)
{
g.labelwrapper.find(".l-text-label:first").html(label + ': ');
}
else
{
g.labelwrapper = g.textwrapper.wrap('').parent();
g.labelwrapper.prepend('
' + label + ': 
');
g.textwrapper.css('float', 'left');
}
if (!p.labelWidth)
{
p.labelWidth = $('.l-text-label', g.labelwrapper).outerWidth();
}
else
{
$('.l-text-label', g.labelwrapper).outerWidth(p.labelWidth);
}
$('.l-text-label', g.labelwrapper).width(p.labelWidth);
$('.l-text-label', g.labelwrapper).height(g.wrapper.height());
g.labelwrapper.append(' ');
if (p.labelAlign)
{
$('.l-text-label', g.labelwrapper).css('text-align', p.labelAlign);
}
g.textwrapper.css({ display: 'inline' });
g.labelwrapper.width(g.wrapper.outerWidth() + p.labelWidth + 2);
}
},
_setWidth: function (value)
{
var g = this;
if (value > 20)
{
g.wrapper.css({ width: value });
g.inputText.css({ width: value - 20 });
g.textwrapper.css({ width: value });
}
},
_setHeight: function (value)
{
var g = this;
if (value > 10)
{
g.wrapper.height(value);
g.inputText.height(value - 2);
g.link.height(value - 4);
g.textwrapper.css({ width: value });
}
},
_setResize: function (resize)
{
//调整大小支持
if (resize && $.fn.ligerResizable)
{
var g = this;
g.selectBox.ligerResizable({ handles: 'se,s,e', onStartResize: function ()
{
g.resizing = true;
g.trigger('startResize');
}
, onEndResize: function ()
{
g.resizing = false;
if (g.trigger('endResize') == false)
return false;
}
});
g.selectBox.append("");
}
},
//查找Text,适用多选和单选
findTextByValue: function (value)
{
var g = this, p = this.options;
if (value == undefined) return "";
var texts = "";
var contain = function (checkvalue)
{
var targetdata = value.toString().split(p.split);
for (var i = 0; i < targetdata.length; i++)
{
if (targetdata[i] == checkvalue) return true;
}
return false;
};
$(g.data).each(function (i, item)
{
var val = item[p.valueField];
var txt = item[p.textField];
if (contain(val))
{
texts += txt + p.split;
}
});
if (texts.length > 0) texts = texts.substr(0, texts.length - 1);
return texts;
},
//查找Value,适用多选和单选
findValueByText: function (text)
{
var g = this, p = this.options;
if (!text && text == "") return "";
var contain = function (checkvalue)
{
var targetdata = text.toString().split(p.split);
for (var i = 0; i < targetdata.length; i++)
{
if (targetdata[i] == checkvalue) return true;
}
return false;
};
var values = "";
$(g.data).each(function (i, item)
{
var val = item[p.valueField];
var txt = item[p.textField];
if (contain(txt))
{
values += val + p.split;
}
});
if (values.length > 0) values = values.substr(0, values.length - 1);
return values;
},
removeItem: function ()
{
},
insertItem: function ()
{
},
addItem: function ()
{
},
_setValue: function (value)
{
var g = this, p = this.options;
var text = g.findTextByValue(value);
if (p.tree)
{
g.selectValueByTree(value);
}
else if (!p.isMultiSelect)
{
g._changeValue(value, text);
$("tr[value=" + value + "] td", g.selectBox).addClass("l-selected");
$("tr[value!=" + value + "] td", g.selectBox).removeClass("l-selected");
}
else
{
g._changeValue(value, text);
var targetdata = value.toString().split(p.split);
$("table.l-table-checkbox :checkbox", g.selectBox).each(function () { this.checked = false; });
for (var i = 0; i < targetdata.length; i++)
{
$("table.l-table-checkbox tr[value=" + targetdata[i] + "] :checkbox", g.selectBox).each(function () { this.checked = true; });
}
}
},
selectValue: function (value)
{
this._setValue(value);
},
bulidContent: function ()
{
var g = this, p = this.options;
this.clearContent();
if (g.select)
{
g.setSelect();
}
else if (g.data)
{
g.setData(g.data);
}
else if (p.tree)
{
g.setTree(p.tree);
}
else if (p.grid)
{
g.setGrid(p.grid);
}
else if (p.url)
{
$.ajax({
type: 'post',
url: p.url,
cache: false,
dataType: 'json',
success: function (data)
{
g.data = data;
g.setData(g.data);
g.trigger('success', [g.data]);
},
error: function (XMLHttpRequest, textStatus)
{
g.trigger('error', [XMLHttpRequest, textStatus]);
}
});
}
},
clearContent: function ()
{
var g = this, p = this.options;
$("table", g.selectBox).html("");
//g.inputText.val("");
//g.valueField.val("");
},
setSelect: function ()
{
var g = this, p = this.options;
this.clearContent();
$('option', g.select).each(function (i)
{
var val = $(this).val();
var txt = $(this).html();
var tr = $("
" + txt + "
");
$("table.l-table-nocheckbox", g.selectBox).append(tr);
$("td", tr).hover(function ()
{
$(this).addClass("l-over");
}, function ()
{
$(this).removeClass("l-over");
});
});
$('td:eq(' + g.select[0].selectedIndex + ')', g.selectBox).each(function ()
{
if ($(this).hasClass("l-selected"))
{
g.selectBox.hide();
return;
}
$(".l-selected", g.selectBox).removeClass("l-selected");
$(this).addClass("l-selected");
if (g.select[0].selectedIndex != $(this).attr('index') && g.select[0].onchange)
{
g.select[0].selectedIndex = $(this).attr('index'); g.select[0].onchange();
}
var newIndex = parseInt($(this).attr('index'));
g.select[0].selectedIndex = newIndex;
g.select.trigger("change");
g.selectBox.hide();
var value = $(this).attr("value");
var text = $(this).html();
if (p.render)
{
g.inputText.val(p.render(value, text));
}
else
{
g.inputText.val(text);
}
});
g._addClickEven();
},
setData: function (data)
{
var g = this, p = this.options;
this.clearContent();
if (!data || !data.length) return;
if (g.data != data) g.data = data;
if (p.columns)
{
g.selectBox.table.headrow = $("
");
g.selectBox.table.append(g.selectBox.table.headrow);
g.selectBox.table.addClass("l-box-select-grid");
for (var j = 0; j < p.columns.length; j++)
{
var headrow = $("
" + p.columns[j].header + "
");
if (p.columns[j].width)
{
headrow.width(p.columns[j].width);
}
g.selectBox.table.headrow.append(headrow);
}
}
for (var i = 0; i < data.length; i++)
{
var val = data[i][p.valueField];
var txt = data[i][p.textField];
if (!p.columns)
{
$("table.l-table-checkbox", g.selectBox).append("