1 Star 0 Fork 44

戴盛/jeasyui

forked from ForEleven/jeasyui 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
jeasyui.js 26.74 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
/**
* Created by 枫 on 2014/8/15.
*/
var jeasyui = (function () {
var je = function (d, param) {
if (typeof(d) == 'object') {
return je.fn.init(d);
} else if ((typeof d == 'string') && d.constructor == String) {
return je.fn.get(d, param);
} else {
return this;
}
};
je.fn = je.prototype = {
clone: function () {
return this;
},
init: function (d) {
if (this.tags) {
for (var i in d) {
this.tags[i] = d[i];
}
} else {
this.tags = d;
}
return this;
},
get: function (id, param) {
var tagName = this.tags[id];
this.tagName = tagName;
this.id = id;
if (typeof param != 'undefined') {
this.tag = $('#' + id)[tagName](param);
}
return this;
},
val: function (v) {
if (v) {
return $('#' + this.id)[this.tagName]('setValue', v);
} else {
return $('#' + this.id)[this.tagName]('getValue');
}
},
text: function (v) {
if (v) {
return $('#' + this.id)[this.tagName]('setText', v);
} else {
return $('#' + this.id)[this.tagName]('getText');
}
},
add: function (options) {
$('#' + this.id)[this.tagName]('add', options);
},
getSelectedIndex: function () {
var select = $('#' + this.id)[this.tagName]('getSelected');
if (this.tagName == 'tabs') {
return $('#' + this.id)[this.tagName]('getTabIndex', $(select));
} else if (this.tagName == 'accordion') {
return $('#' + this.id)[this.tagName]('getPanelIndex', $(select).panel());
}
},
load: function (options) {
$('#' + this.id)[this.tagName]('load', options);
},
reload: function (options) {
$('#' + this.id)[this.tagName]('reload', options);
},
submit: function (options) {
$('#' + this.id)[this.tagName]('submit', options);
},
reset: function (options) {
$('#' + this.id)[this.tagName]('reset', options);
},
validate: function (options) {
$('#' + this.id)[this.tagName]('validate', options);
},
getData: function (options) {
return $('#' + this.id)[this.tagName]('getData', options);
},
getChecked: function (options) {
return $('#' + this.id)[this.tagName]('getChecked', options);
},
clearChecked: function (options) {
return $('#' + this.id)[this.tagName]('clearChecked', options);
},
getSelected: function (options) {
return $('#' + this.id)[this.tagName]('getSelected', options);
}
};
je.prototype = je.fn;
je.rendBtn = function () {
$('.easy-button').linkbutton({plain: true});
};
return je;
})();
jeasyui.push = (function () {
var push = function (channel, onMessage) {
var socket = $.atmosphere;
var request = { url: channel,
contentType: "application/json",
trackMessageLength: true,
transport: 'websocket'};
request.onMessage = function (response) {
var message = response.responseBody;
if (typeof onMessage == 'function')
onMessage.apply(null, [ message]);
};
var subSocket = socket.subscribe(request);
this.socket = subSocket;
return this;
};
push.fn = push.prototype = {
push: function (message) {
this.socket.push(message);
}
};
push.prototype = push.fn;
return push;
})();
jeasyui.dialog = (function () {
var dialog = function (options) {
options = $.extend(options, defaultOptions);
var dialogDiv = $('<div></div>').appendTo($('body'));
if (options.title == null)
options.title == "";
if (options.width == null) {
var _w = document.body.clientWidth;
options.width = _w * 0.9;
}
if (options.height == null) {
var _h = document.body.clientHeight;
options.height = _h * 0.9;
}
options.onClose = function () {
if (typeof options.callback == 'function') {
var backData = $(dialogDiv).data("callbackdata");
options.callback.apply(this, [backData]);
}
$(dialogDiv).dialog('destroy');
$(dialogDiv).remove();
};
var url = options.href;
options.href = null;
if (options.queryParams) {
var tempUrl = "";
for (var i in options.queryParams) {
tempUrl += "&" + i + "=" + options.queryParams[i];
}
url += (url.indexOf("?") > 0) ? tempUrl : "?"+tempUrl.substring(1, tempUrl.length);
}
options.content = '<iframe " frameborder="0" src="' + url
+ '" style="width:100%;height:100%;"></iframe>';
$(dialogDiv).dialog(options);
this.wrapper = dialogDiv;
return this;
};
var defaultOptions = {
modal: true,
maximizable: true,
cache: false
};
dialog.fn = dialog.prototype = {
close: function (data) {
$(this.wrapper).data("callbackdata", data);
$(this.wrapper).dialog('close');
}
};
dialog.prototype = dialog.fn;
return dialog;
})();
var Frame = {
dialogs: new Array()
};
Frame.dialog = (function () {
return {
open: function (options) {
if (typeof options.top == 'undefined' || options.top) {
return window.parent.Frame.dialog.openDialog(options);
} else {
return Frame.dialog.openDialog(options);
}
},
openDialog: function (options) {
var dialog = new jeasyui.dialog(options);
Frame.dialogs.unshift(dialog);
return dialog;
},
close: function (data) {
window.parent.Frame.dialogs.shift().close(data);
}
};
})();
/**
* Some component extension
*
*/
/**
* fileUpload
*/
(function () {
$.fn.fileUpload = function (options, param) {
if (typeof options == 'string') {
return $.fn.fileUpload.methods[options](this, param);
}
var dataOptions = {};
if (typeof $(this).data('options') != 'undefined') {
dataOptions = eval("({" + $(this).data('options') + "})");
}
options = $.extend({}, $.fn.fileUpload.defaults, dataOptions, options);
return init(this, options);
};
$.fn.fileUpload.methods = {
};
$.fn.fileUpload.defaults = {
chooseBtnText: '选择文件',
uploadBtnText: '上传',
chooseBtnCls: 'c-success',
uploadBtnCls: 'c-primary',
maxFileSize: '10mb',
filters: null,
basePath: '../plupload',
multiFile: true,
params: {}
};
function init(ele, options) {
var classStyle = $(ele).attr("class");
var style = $(ele).attr('style');
var id = $(ele).attr("id");
var wrapper = $('<span></span>')[0];
$(wrapper).attr("id", id).attr('style', style).addClass("jeasyui-upload").addClass(classStyle);
$(ele).after(wrapper);
$(ele).remove();
var chooseBtn = $('<a href="#" ></a>')[0];
var uploadBtn = $('<a href="#" ></a>')[0];
$(chooseBtn).text(options.chooseBtnText).addClass(options.chooseBtnCls);
$(uploadBtn).text(options.uploadBtnText).addClass(options.uploadBtnCls);
$(wrapper).append(chooseBtn);
$(wrapper).append(uploadBtn);
var files = $('<span>暂无文件</span>').addClass("jeasyui-upload-files");
$(wrapper).append(files);
var errorMsg = $('<span></span>').addClass("jeasyui-upload-msg");
$(wrapper).append(errorMsg);
$(uploadBtn).linkbutton({iconCls: "fa fa-upload"});
$(chooseBtn).linkbutton({iconCls: "fa fa-folder-open"});
var uploadOptions = {
runtimes: 'html5,flash,silverlight,html4',
browse_button: chooseBtn, // you can pass in id...
container: wrapper,
max_file_size: options.maxFileSize,
url: options.url,
flash_swf_url: options.basePath + "/Moxie.swf",
silverlight_xap_url: options.basePath + "/Moxie.xap",
multi_selection: options.multiFile,
multipart_params: options.params,
init: {
BeforeUpload: function () {
if (typeof options.BeforeUpload == 'function') {
options.BeforeUpload.apply(this, arguments);
}
},
PostInit: function () {
if (typeof options.PostInit == 'function') {
options.PostInit.apply(this, arguments);
} else {
$(files).html("暂无文件");
$(uploadBtn)[0].onclick = function () {
uploader.start();
return false;
};
}
},
FilesAdded: function (up, _files) {
if (typeof options.FilesAdded == 'function') {
options.FilesAdded.apply(this, arguments);
} else {
if (uploader.files.length > 0) {
$(files).empty()
} else {
$(files).html("暂无文件");
}
plupload.each(_files, function (_file) {
var fileDiv = $('<div id="' + _file.id + '"><a href="#" title="删除"><i class="fa fa-close"></i></a> ' + _file.name + ' (' + plupload.formatSize(_file.size) + ') <b></b></div>');
$(files).append(fileDiv);
$(fileDiv).find("a").on('click', function () {
var fileId = $(this).parent().attr("id");
var f = uploader.getFile(fileId);
uploader.removeFile(f);
$(this).parent().remove();
if (uploader.getFiles().length == 0) {
$(files).html("暂无文件");
}
});
});
}
},
UploadProgress: function (up, file) {
if (typeof options.UploadProgress == 'function') {
options.UploadProgress.apply(this, arguments);
} else {
$("#" + file.id)[0].getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
}
},
Error: function (up, err) {
if (typeof options.Error == 'function') {
options.Error.apply(this, arguments);
} else {
$(errorMsg).html(err);
}
}
}
};
if (options.filters) {
uploadOptions.filters = options.filters;
}
var uploader = new plupload.Uploader(uploadOptions);
uploader.init();
}
})(jQuery);
/**
* selectBooleanCheckbox
*/
(function () {
function init(ele, options) {
var span = $("<span></span>").addClass($(ele).attr("class")).css("display", "inline-block").css("height", "24px");
$(ele).wrap(span);
$(ele).change(function () {
$(this).val($(ele)[0].checked ? true : false);
});
}
$.fn.selectBooleanCheckbox = function (options, param) {
if (typeof options == 'string') {
return $.fn.selectManyCheckbox.methods[options](this, param);
}
var dataOptions = eval("({" + $(this).data('options') + "})");
options = $.extend({}, $.fn.selectManyCheckbox.defaults, dataOptions, options);
return init(this, options);
};
$.fn.selectBooleanCheckbox.methods = {
setValue: function (ele, param) {
$(ele)[0].checked = param ? true : false;
},
getValue: function (ele) {
return $(ele)[0].checked;
}
};
$.fn.selectBooleanCheckbox.defaults = {
};
})(jQuery);
/**
* selectManyCheckbox
*/
(function () {
var componentName = "selectManyCheckbox";
function init(target, options) {
var id = $(target).attr("id");
var style = $(target).attr("style") || '';
var classStyle = $(target).attr("class");
$(target).removeAttr("name");
var wrapper = $('<span class="' + componentName + '"></span>');
if (classStyle) {
wrapper.addClass(classStyle);
}
var data = getDataFromOption(target).concat(options.data);
if (options.url) {
getDataFromUrl(options.url, function (d) {
handleNewHtml(data.concat(d), wrapper, target, options);
});
} else {
handleNewHtml(data, wrapper, target, options);
}
return this;
}
function handleNewHtml(data, wrapper, target, options) {
var name = $(target).attr("name") || $(target).attr("id");
var table = $('<table></table>');
wrapper.append(table);
$(target).after(wrapper);
$(target).hide();
var tr = $("<tr></tr>");
$(data).each(function (i) {
var value = this[options.valueField] || this['value'];
var text = this[options.textField] || this['text'];
var checkbox = '<td><input type="checkbox" name="' + name + '" value="' + value + '" ' + (this['selected'] ? 'checked="checked"' : '') + '></td>';
tr.append($(checkbox));
tr.append('<td class="selectManyCheckbox-text">' + text + '</td>');
$(checkbox).click(function () {
var input = $(this).find('input')[0];
if (input.checked) {
input.checked = false;
} else {
input.checked = true;
}
});
i = i + 1;
if (options.columns > 0 && i % options.columns == 0) {
table.append(tr);
tr = $("<tr></tr>");
}
if (i == data.length) {
table.append(tr);
}
});
if (options.checkAllable) {
var checkAllSpan = $('<span></span>').addClass('selectManyCheckbox-checkAll');
var checkAllA = $('<a href="#">全选</a>').bind('click', function () {
$(this).parent().parent().find('input').each(function () {
$(this)[0].checked = true;
});
});
var checkNoA = $('<a href="#">全不选</a>').bind('click', function () {
$(this).parent().parent().find('input').each(function () {
$(this)[0].checked = false;
});
});
checkAllSpan.append(checkAllA).append("/").append(checkNoA);
wrapper.append(checkAllSpan);
}
}
function getDataFromOption(elem) {
var data = [];
$(elem).find("option").each(function () {
var d = {value: $(this).attr('value'), text: $(this).text(), selected: $(this).attr('selected')};
data.push(d);
});
return data;
}
function getDataFromUrl(url, callback) {
$.ajax({
url: url,
type: "GET",
dataType: "JSON",
success: function (d) {
callback.apply(this, [d]);
}
});
}
$.fn.selectManyCheckbox = function (options, param) {
if (typeof options == 'string') {
return $.fn.selectManyCheckbox.methods[options](this, param);
}
var dataOptions = eval("({" + $(this).data('options') + "})");
options = $.extend({}, $.fn.selectManyCheckbox.defaults, dataOptions, options);
return init(this, options);
};
$.fn.selectManyCheckbox.methods = {
setValues: function (elem, params) {
var jWrap = $(elem).next();
for (var i = 0; i < params.length; i++) {
jWrap.find('input').each(function () {
var value = $(this).val();
if (value == params[i]) {
$(this)[0].checked = true;
}
});
}
},
getValues: function (elem) {
var jWrap = $(elem).next();
var values = [];
jWrap.find('input').each(function () {
var value = $(this).val();
var checked = $(this)[0].checked;
if (checked) {
values.push(value);
}
});
return values;
},
checkAll: function (elem) {
var jWrap = $(elem).next();
jWrap.find('input').each(function () {
$(this)[0].checked = true;
});
}
};
$.fn.selectManyCheckbox.defaults = {
width: 'auto',
height: '24',
columns: 0,
data: [],
url: null,
valueField: "value",
textField: "text",
checkAllable: true
};
})(jQuery);
/**
*
*/
(function () {
var componentName = "selectOneRadio";
function init(target, options) {
var id = $(target).attr("id");
var style = $(target).attr("style") || '';
var classStyle = $(target).attr("class");
$(target).removeAttr("name");
var wrapper = $('<span class="' + componentName + '"></span>');
if (classStyle) {
wrapper.addClass(classStyle);
}
var data = getDataFromOption(target).concat(options.data);
if (options.url) {
getDataFromUrl(options.url, function (d) {
handleNewHtml(data.concat(d), wrapper, target, options);
});
} else {
handleNewHtml(data, wrapper, target, options);
}
$(target).selectOneRadio('setValue', $(target).attr("value"));
return $(target);
}
function handleNewHtml(data, wrapper, target, options) {
var name = $(target).attr("name") || $(target).attr("id");
var table = $('<table></table>');
wrapper.append(table);
$(target).after(wrapper);
$(target).hide();
var tr = $("<tr></tr>");
$(data).each(function (i) {
var value = this[options.valueField] || this['value'];
var text = this[options.textField] || this['text'];
var checkbox = '<td><input type="radio" name="' + name + '" value="' + value + '" ' + (this['selected'] ? 'checked="checked"' : '') + '></td>';
tr.append($(checkbox));
tr.append('<td class="selectOneRadio-text">' + text + '</td>');
$(checkbox).click(function () {
var input = $(this).find('input')[0];
if (input.checked) {
input.checked = false;
} else {
input.checked = true;
}
});
i = i + 1;
if (options.columns > 0 && i % options.columns == 0) {
table.append(tr);
tr = $("<tr></tr>");
}
if (i == data.length) {
table.append(tr);
}
});
}
function getDataFromOption(elem) {
var data = [];
$(elem).find("option").each(function () {
var d = {value: $(this).attr('value'), text: $(this).text(), selected: $(this).attr('selected')};
data.push(d);
});
return data;
}
function getDataFromUrl(url, callback) {
$.ajax({
url: url,
type: "GET",
dataType: "JSON",
success: function (d) {
callback.apply(this, [d]);
}
});
}
$.fn.selectOneRadio = function (options, param) {
if (typeof options == 'string') {
return $.fn.selectOneRadio.methods[options](this, param);
}
var dataOptions = $(this).data('options') ? eval("({" + $(this).data('options') + "})") : {};
options = $.extend({}, $.fn.selectOneRadio.defaults, dataOptions, options);
return init(this, options);
};
$.fn.selectOneRadio.methods = {
setValue: function (elem, param) {
var jWrap = $(elem).next();
jWrap.find('input').each(function () {
var value = $(this).val();
if (value == param) {
$(this)[0].checked = true;
}
});
},
getValue: function (elem) {
var jWrap = $(elem).next();
var values = [];
jWrap.find('input').each(function () {
var value = $(this).val();
var checked = $(this)[0].checked;
if (checked) {
return value;
}
});
}
};
$.fn.selectOneRadio.defaults = {
width: 'auto',
height: '24',
columns: 0,
data: [],
url: null,
valueField: "value",
textField: "text"
};
})(jQuery);
(function () {
function init(ele, options) {
var legend = $(ele).find('legend')[0];
$(legend).addClass(options.legendCls);
var content = $(ele).find('.jeasyui-fieldset-content')[0];
if (options.closed) {
$(content).hide();
$(content).addClass('jeasyui-closed');
}
if (options.toggleable) {
$(legend).click(function () {
$(content).toggle(options.toggleSpeed);
$(content).toggleClass("jeasyui-closed");
if ($(content).hasClass("jeasyui-closed")) {
$(ele).fieldset('close');
} else {
$(ele).fieldset('open');
}
});
}
return this;
}
$.fn.fieldset = function (options, param) {
if (typeof options == 'string') {
return $.fn.fieldset.methods[options](this, param, options);
}
var dataOptions = $(this).data('options') ? eval("({" + $(this).data('options') + "})") : {};
options = $.extend({}, $.fn.fieldset.defaults, dataOptions, options);
$(this).data('options', options);
return init(this, options);
};
$.fn.fieldset.defaults = {
onOpen: null,
onClose: null,
closed: false,
toggleable: false,
toggleSpeed: 500,
legendCls: 'c-info'
};
$.fn.fieldset.methods = {
open: function (ele, force) {
var options = $.data(ele).options;
$(ele).find("legend").find("i").removeClass().addClass("fa").addClass("fa-minus");
if (typeof force != 'undefined' && !force && typeof options.onClose == 'function') {
options.onOpen.apply(this);
}
},
close: function (ele, force) {
var options = $.data(ele).options;
$(ele).find("legend").find("i").removeClass().addClass("fa").addClass("fa-plus");
if (typeof force != 'undefined' && !force && typeof options.onClose == 'function') {
options.onClose.apply(this);
}
}
};
})(jQuery);
var Alert = {};
Alert.info = function (msg, title, event) {
var t = title ? title : '系统消息';
if (event == 'refresh') {
$.messager.alert(t, msg, 'info', function () {
window.location = window.location.href.replace("#", "");
});
} else if (event == 'close') {
$.messager.alert(t, msg, 'info', function () {
window.close();
});
} else if (typeof (event) == 'function') {
$.messager.alert(t, msg, 'info', event);
} else {
$.messager.alert(t, msg, 'info');
}
};
Alert.error = function (msg, title, event) {
var t = title ? title : '系统消息';
if (event == 'refresh') {
$.messager.alert(t, msg, 'error', function () {
window.location = window.location.href.replace("#", "");
});
} else if (event == 'close') {
$.messager.alert(t, msg, 'error', function () {
window.close();
});
} else if (typeof (event) == 'function') {
$.messager.alert(t, msg, 'error', event);
} else {
$.messager.alert(t, msg, 'error');
}
};
Alert.question = function (msg, title, event) {
var t = title ? title : '系统消息';
if (event == 'refresh') {
$.messager.alert(t, msg, 'question', function () {
window.location = window.location.href.replace("#", "");
});
} else if (event == 'close') {
$.messager.alert(t, msg, 'question', function () {
window.close();
});
} else if (typeof (event) == 'function') {
$.messager.alert(t, msg, 'question', event);
} else {
$.messager.alert(t, msg, 'question');
}
};
Alert.warning = function (msg, title, event) {
var t = title ? title : '系统消息';
if (event == 'refresh') {
$.messager.alert(t, msg, 'warning', function () {
window.location = window.location.href.replace("#", "");
});
} else if (event == 'close') {
$.messager.alert(t, msg, 'warning', function () {
window.close();
});
} else if (typeof (event) == 'warning') {
$.messager.alert(t, msg, 'question', event);
} else {
$.messager.alert(t, msg, 'warning');
}
};
Alert.confirm = function (msg, event) {
$.messager.confirm('系统消息', msg, event);
};
var StringUtil = {};
StringUtil.array2Str = function (rows, attr, split) {
var attrs = new Array();
for (var i = 0; i < rows.length; i++) {
var a = eval("rows[" + i + "]." + attr);
attrs[attrs.length] = a;
}
if (typeof (split) == "undefined") {
return attrs.join(",");
} else {
return attrs.join(split);
}
};
jeasyui.valid = function (d) {
if (typeof d != 'object') {
try {
d = eval('(' + d + ')');
} catch (ex) {
return false;
}
}
if (!d.success) {
if (d.error.fieldErrors.length > 0) {
for (var error in d.error.fieldErrors) {
Alert.warning(d.error.fieldErrors[error].message);
}
} else {
Alert.warning(d.error.errorMessage);
}
try {
console.error(d);
} catch (e) {
}
return false;
} else {
return true;
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/aqsc_qy/jeasyui.git
git@gitee.com:aqsc_qy/jeasyui.git
aqsc_qy
jeasyui
jeasyui
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385