; (function ($, window, document, undefined) {
|
//定义Beautifier的构造函数
|
var createzeone = function (ele, opt) {
|
this.$element = ele,
|
this.defaults = {
|
upLoaderEnd: undefined,
|
clearEnd: undefined,
|
};
|
var options = $.extend(this.defaults, opt);
|
|
var id = "";
|
var html = '';
|
html += ' <input type="text" name="uploadtext" style="background-color:transparent;" txtobj=' + encodeURI(JSON.stringify(options)) + ' readonly="true" class="form-control" placeholder="请点击上传按钮上传内容" />';
|
html += ' <span class="input-group-btn">';
|
|
html += ' <button type="button" name="datafileload" class="btn btn-successs btn-outline" style=" border-color:#e5e6e7"><i class="fa fa-cloud-upload "></i></button>';
|
|
html += ' <button type="button" class="btn btn-successs btn-outline " name="datafileview" style="border-color:#e5e6e7"><i class="fa fa-chevron-down "></i></button>';
|
|
|
html += ' </span>';
|
|
//showdiv;
|
|
html += '<div name="datafileshow" style="display:none;z-index:3; position:absolute; background-color:#FFFFFF;border:1px solid #e5e6e7; "></div>';
|
|
$(this.$element).html(html);
|
|
$(this.$element).find("button[name='datafileload']").bind("click", function () {
|
ToShowFileUpLoader(ele, options);
|
});
|
//$(this.$element).find("button[name='datafileview']").bind("hover", function () {
|
|
// ShowView(ele);
|
//});
|
|
//$().bind("mouseleave", function () {
|
// var showview = $(ele).find("[name='datafileshow']");
|
// $(showview).hide();
|
|
//});
|
|
|
$(this.$element).on("click", "[name='clearfile']", function () {
|
|
|
|
var v = $(this).attr("vals");
|
Remove(ele, v);
|
msg.info("移除成功:" + GetName(v)+"。保存后生效。");
|
});
|
|
|
|
|
$(this.$element).find("button[name='datafileview']").hover(
|
function () { ShowView(ele, true); },
|
function () {
|
|
setTimeout(function(){ShowView(ele, false)} , 300);
|
|
}
|
);
|
|
$(this.$element).find("[name='datafileshow']").hover(
|
function () {
|
|
},
|
function () { ShowView(ele, false, 1); }
|
);
|
|
|
$(this.$element).find("button[name='dataclearbtn']").bind("click", function () {
|
ToClear(ele, options);
|
|
});
|
}
|
function GetName(url)
|
{
|
var rturl = url;
|
var index = url.indexOf('_');
|
if (index > -1)
|
{
|
rturl= url.substr(index+1);
|
}
|
return rturl;
|
}
|
function Remove(obj,url)
|
{
|
var urlall = ToGetVal(obj);
|
ToSetVal(obj,urlall.replace(url, ""), true);
|
|
}
|
function ShowView(obj, isshow, type) {
|
|
var showview = $(obj).find("[name='datafileshow']");
|
if (!isshow) {
|
if (type == undefined) {
|
var isFocus = $(showview).is(":hover");
|
|
if (true == isFocus) {
|
return;
|
} else {
|
|
}
|
}
|
|
$(showview).hide();
|
return;
|
}
|
var wd = $(obj).width();
|
|
var X = $(obj).position().top;
|
var Y = $(obj).position().left;
|
$(showview).css({ 'left': '0px', 'top': '34px', 'width': wd });
|
$(showview).show();
|
$(showview).focus();
|
|
}
|
function ToShowFileUpLoader(obj, options) {
|
|
|
var cars = ["确认完成", "取消"];
|
var u = "/Content/upload.html";
|
dlog.open("文件上传", cars, "lg", u,
|
function (res) {
|
if (res == undefined || res == "") {
|
alert("无数据");
|
return false;
|
}
|
//var isarea = jQuery.isArray(res);
|
//if (false == isarea) {
|
// alert("基础配置不正确:" + jQuery.isArray(res));
|
// return false;
|
//}
|
ToSetVal(obj, jQuery.parseJSON(res), false);
|
if (typeof (options.upLoaderEnd) === "function") {
|
options.upLoaderEnd(obj);
|
|
}
|
else {
|
if (options.upLoaderEnd != undefined && options.upLoaderEnd != "") {
|
var objbtns = eval(options.upLoaderEnd);
|
if (typeof (objbtns) === "function") {
|
objbtns(obj);
|
}
|
}
|
}
|
});
|
}
|
function ToClear(obj, options) {
|
var txtonbj = obj.find("input[name='uploadtext']");
|
var nval = txtonbj.attr("valcode");
|
txtonbj.val("");
|
txtonbj.attr("valcode", "");
|
txtonbj.focus();
|
if (nval != undefined && nval != "") {
|
if (typeof (options.clearEnd) === "function") {
|
options.clearEnd(obj);
|
} else {
|
if (options.clearEnd != undefined && options.clearEnd != "") {
|
var objbtns = eval(options.clearEnd);
|
if (typeof (objbtns) === "function") {
|
objbtns(obj);
|
}
|
}
|
}
|
}
|
|
}
|
|
function ToGetVal(obj) {
|
var txtobj = $(obj).find("input[name='uploadtext']");
|
//获取值
|
var va = txtobj.attr("valcode");
|
if (va == undefined || va == "") {
|
return "";
|
} else {
|
var JsonData = jQuery.parseJSON(va);
|
var str = "";
|
$.each(JsonData, function (index, item) {
|
str += ";" + item.code;
|
});
|
if (str == "") {
|
|
return "";
|
}
|
return str.substring(1);
|
}
|
|
}
|
function ToGetValJson(obj) {
|
var txtobj = $(obj).find("input[name='uploadtext']");
|
//获取值
|
var va = txtobj.attr("valcode");
|
if (va == undefined || va == "") {
|
return undefined;
|
} else {
|
return jQuery.parseJSON(va);
|
|
}
|
|
}
|
|
|
//设置及获取值 _code//可能是jsong数组 必须是[{}] 格式复制
|
function ToSetVal(obj, _code, isclearadd) {
|
//isclearadd T 清楚数据新增
|
var txtobj = $(obj).find("input[name='uploadtext']");
|
|
var Json = [];
|
if (isclearadd == false) {
|
var va = txtobj.attr("valcode");
|
if (!(va == undefined || va == "")) {
|
var JsonData = jQuery.parseJSON(va);
|
|
Json = JsonData;
|
}
|
}
|
|
|
if (jQuery.isArray(_code)) {
|
if (Json.length == 0)
|
{
|
Json = _code;
|
}
|
else
|
{
|
$.each(_code, function (i, item) {
|
Json.push(item);
|
});
|
|
}
|
|
}
|
else {
|
var codesz = _code.split(";");
|
for (var i = 0; i < codesz.length; i++) {
|
var cdstr = codesz[i];
|
if (cdstr.length > 0) {
|
|
Json.push({ code: cdstr, lable: GetName(cdstr) })
|
}
|
}
|
}
|
|
var _lable = "";
|
if (Json.length == 1) {
|
_lable = Json[0].lable
|
}
|
if (Json.length > 1) {
|
|
_lable = "附件数量:" + Json.length;
|
}
|
|
txtobj.attr("valcode", JSON.stringify(Json));
|
txtobj.val(_lable);
|
ShowHtml(obj);
|
|
|
|
|
|
}
|
function ShowHtml(obj) {
|
var updata = ToGetValJson(obj);
|
var htmls = "";
|
if (updata != undefined && updata.length > 0) {
|
|
$.each(updata, function (i, item) {
|
|
htmls += '<div class="row" style="padding:3px 14px" ><div class="col-xs-10"><a target="_blank" href="' + item.code + '">' + (i + 1) + "、" + item.lable + ' </a></div> <div class="col-xs-2" > <i name="clearfile" title="移除附件" vals="' + item.code + '" style="cursor:pointer;color:Red; border-color:#e5e6e7" class="fa fa-times"></i></div></div>';
|
|
});
|
}
|
|
|
$(obj.find("[name='datafileshow']")).html(htmls);
|
}
|
$.fn.iuploade111r = {
|
|
init: function (options) {
|
alert("初始");
|
var beautifier = new createzeone(this, options);
|
},
|
ival: function (code) {
|
//code 支持 ;间隔 或者Json格式
|
|
alert("多选项" + code);
|
if (code == undefined) {
|
return ToGetVal(this);
|
}
|
else {
|
return ToSetVal(this, code, true);
|
}
|
}
|
|
}
|
|
|
var methods = {
|
init: function (options) {
|
var beautifier = new createzeone(this, options);
|
return this.each(function () {
|
$(window).bind('resize.iuploader', methods.reposition);
|
});
|
|
},
|
destroy: function () {
|
|
return this.each(function () {
|
$(window).unbind('.iuploader');
|
})
|
|
},
|
reposition: function () {
|
//...
|
},
|
show: function () {
|
var op = this.find("input[name='uploadtext']").attr("txtobj");
|
ToShowFileUpLoader(this, jQuery.parseJSON(decodeURI(op)));
|
},
|
disabled: function (isdisabled) {
|
if (!isdisabled) {
|
this.find("button[name='datafileload']").attr("disabled", true);
|
this.find("[name='datafileshow']").find("[name='clearfile']").hide();
|
|
|
}
|
else {
|
this.find("button[name='datafileload']").removeAttr("disabled")
|
this.find("[name='datafileshow']").find("[name='clearfile']").show();
|
}
|
},
|
val: function (code) {
|
if (code == undefined) {
|
return ToGetVal(this);
|
}
|
else {
|
|
return ToSetVal(this, code, true);
|
}
|
}
|
};
|
|
|
|
$.fn.iuploader = function (method) {
|
|
if (methods[method]) {
|
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
} else if (typeof method === 'object' || !method) {
|
return methods.init.apply(this, arguments);
|
} else {
|
$.error('Method ' + method + ' does not exist on jQuery.tooltip');
|
}
|
};
|
|
|
|
|
|
|
})(jQuery, window, document);
|