$.fn.extend({
ShowTheFloatDiv:
function
(obj) {
$(
this
).click(
function
() {
$(
"body"
).find(
"*"
).not(
"div.float-outer"
).attr(
"disabled"
,
"disabled"
);
var
$float = jQuery.CreateTheFloatDiv();
$img_outer_obj = obj;
});
}
});
$.extend({
CreateTheFloatDiv:
function
() {
if
($(
".float-outer"
).size() == 1) {
return
$(
".float-outer"
);
}
var
left_offset = ($(window).width() - 600) / 2;
var
top_offset = ($(window).height() - 278) / 3;
var
theFloatDivHtml =
"<div class='float-outer' style='left:"
+ left_offset +
"px;top:"
+ top_offset +
"px;'>"
;
theFloatDivHtml +=
"<div class='float-header float-border'>上传头像</div>"
;
theFloatDivHtml +=
"<div class='float-content'>"
;
theFloatDivHtml +=
"<div class='content-first-row'>文件名:"
;
theFloatDivHtml +=
"<input type='text' id='tb_filename' style=';' readonly /> "
;
theFloatDivHtml +=
"<input type='button' id='btn_selectfile' value='选择图片' style='margin-left:-10px;' />"
;
theFloatDivHtml +=
"<input type='file' id='btn_upload' name='btn_upload' style='display:none;' accept='.jpg,.bmp,.gif' />"
;
theFloatDivHtml +=
"</div>"
;
theFloatDivHtml +=
"<div class='content-second-row'>"
;
theFloatDivHtml +=
"<span class='img-portrait' style=';'>图片预览:"
;
theFloatDivHtml +=
"<div class='img-portrait' style='padding-top:30px;'>"
;
theFloatDivHtml +=
"<img src='' class='preview60' alt=''/>"
;
theFloatDivHtml +=
"<span>60*60"
;
theFloatDivHtml +=
"</div>"
;
theFloatDivHtml +=
"<div style='float:left;'>"
;
theFloatDivHtml +=
"<img src='' class='preview120' alt=''/>"
;
theFloatDivHtml +=
"<span>120*120"
;
theFloatDivHtml +=
"</div>"
;
theFloatDivHtml +=
"</div>"
;
theFloatDivHtml +=
"</div>"
;
theFloatDivHtml +=
"<div class='float-footer float-border'>"
;
theFloatDivHtml +=
"<input type='submit' value='确定' id='btn_ok' />"
;
theFloatDivHtml +=
"<input type='button' value='取消' id='btn_cancel' />"
;
theFloatDivHtml +=
"</div>"
;
theFloatDivHtml +=
"</div>"
;
$(
"body"
).append(theFloatDivHtml);
return
$(
".float-outer"
);
}
});
var
$img_outer_obj;
$(
function
() {
$(
"body"
).delegate(
"#btn_cancel"
,
"click"
,
function
() {
$(
".float-outer"
).remove();
$(
"body"
).find(
"*"
).removeAttr(
"disabled"
);
});
$(
"body"
).delegate(
"#btn_selectfile"
,
"click"
,
function
() {
$(
"#btn_upload"
).trigger(e);
});
var
e = jQuery.Event(
"click"
);
$(
"body"
).delegate(
"#btn_upload"
,
"click"
,
function
() {
}).delegate(
"#btn_upload"
,
"change"
,
function
() {
var
curPATH = getFilePath($(
this
).get(0));
var
fileName = curPATH.substring(curPATH.lastIndexOf(
"\\"
) + 1);
var
type = curPATH.substring(curPATH.lastIndexOf(
'.'
) + 1).toLowerCase();
if
(type ==
"jpg"
|| type ==
"gif"
|| type ==
"bmp"
) {
$(
"input#tb_filename"
).val(fileName);
if
($(
"input#tb_filename"
).val() ==
""
) {
alert(
"请先上传文件!"
);
return
;
}
$.ajaxFileUpload
(
{
url:
'/UploadPortrait.aspx'
,
secureuri:
false
,
fileElementId: $(
"input#btn_upload"
).attr(
"id"
),
dataType:
'json'
,
complete:
function
() {
},
success:
function
(data, status)
{
if
(
typeof
(data.error) !=
'undefined'
) {
if
(data.error !=
''
) {
if
(data.error ==
"1001"
) {
}
else
if
(data.error ==
"1002"
) {
$(
"input#tb_filename"
).val(
""
);
$(
".preview60"
).attr(
"src"
,
""
);
$(
".preview120"
).attr(
"src"
,
""
);
}
alert(data.msg);
return
;
}
else
{
alert(data.msg);
}
}
$(
".preview60"
).attr(
"src"
, data.imgurl);
$(
".preview120"
).attr(
"src"
, data.imgurl);
},
error:
function
(data, status, e)
{
alert(e);
}
}
)
return
false
;
}
else
{
alert(
"请选择正确的图片格式(.jpg|.gif|.bmp)"
);
}
});
$(
"body"
).delegate(
"#btn_ok"
,
"click"
,
function
() {
$img_outer_obj.attr(
"src"
, $(
".preview120"
).attr(
"src"
));
$(
".float-outer"
).remove();
$(
"body"
).find(
"*"
).removeAttr(
"disabled"
);
});
var
offset_left, offset_top, moveFlag;
$(
"body"
).delegate(
".float-header"
,
"mousedown"
,
function
(e) {
moveFlag =
true
;
offset_left = e.pageX - $(
this
).offset().left;
offset_top = e.pageY - $(
this
).offset().top;
$(
"body"
).delegate(
".float-header"
,
"mousemove"
,
function
(e) {
if
(moveFlag) {
$(
".float-outer"
).css(
"left"
, e.pageX - offset_left +
"px"
).css(
"top"
, e.pageY - offset_top +
"px"
);
}
}).delegate(
".float-header"
,
"mouseup"
,
function
() {
moveFlag =
false
;
})
})
});