// 弹出层相关
var hn = {
dragging: false,
dragx: 0,
dragy: 0,
dragel: null,
dragbox: null,
dragmaxx: 0,
dragmaxy: 0,
draghasset: false,
msg: function(text, el, fn) {
var hntip = $("#hntip")
if (!hntip.length) {
hntip = $('
')
$("body").append(hntip)
}
hntip.find(".hn-msg").html(text || '')
settimeout(function() {
hntip.addclass("show")
}, 1)
el = el || {}
var time = el.time || 1500
settimeout(function() {
hntip.removeclass("show")
typeof el == 'function' && el()
typeof fn == 'function' && fn()
}, time)
},
load: function(text, el, fn) {
var hnload = $("#hnload")
if (!hnload.length) {
hnload = $('')
$("body").append(hnload)
}
hnload.find(".hn-load-title").html(text || '')
settimeout(function() {
hnload.addclass("show")
}, 1)
el = el || {}
var time = el.time || 360000
settimeout(function() {
hnload.removeclass("show")
typeof el == 'function' && el()
typeof fn == 'function' && fn()
}, time)
},
hideload: function() {
$("#hnload").removeclass("show")
},
confirm: function(el) {
var hnconfirm = $("#hnconfirm")
if (!hnconfirm.length) {
hnconfirm = $('')
$("body").append(hnconfirm)
}
hn.dragel = hnconfirm.find(".hn-confirm-title")
hn.dragbox = hnconfirm.find(".hn-confirm-dialog")
hn.setdrag()
hn.dragel.text(el.title || '')
hnconfirm.find(".hn-confirm-cont").text(el.content || '')
var btns = hnconfirm.find(".hn-confirm-btns")
btns.html('')
if (el.btn.length) {
for (var i = 0; i < el.btn.length; i++) {
if (i == 0) {
$('' + el.btn[i] + '').appendto(btns)
} else {
$('' + el.btn[i] + '').appendto(btns)
}
}
}
if (el.callback.length) {
var cbtn = btns.find(".c-btn")
for (var i = 0; i < el.callback.length; i++) {
cbtn.eq(i).on("click", el.callback[i])
}
}
hn.dragbox.css({
left: ($(window).width() - hn.dragbox.outerwidth()) / 2,
top: ($(window).height() - hn.dragbox.outerheight()) / 2
})
settimeout(function() {
hnconfirm.addclass("show")
}, 1)
},
hideconfirm: function() {
$("#hnconfirm").removeclass("show")
},
open: function(el) {
var hnhtml = $("#hnhtml")
if (!hnhtml.length) {
hnhtml = $('')
$("body").append(hnhtml)
}
hn.dragel = hnhtml.find(".hn-html-title")
hn.dragbox = hnhtml.find(".hn-html-dialog")
hn.setdrag()
hn.dragel.text(el.title || '')
var cont = hnhtml.find(".hn-html-cont")
cont.html(el.content || '')
var area = el.area || [600, 338]
cont.css({
width: area[0],
height: area[1] - hn.dragel.outerheight()
})
hn.dragbox.css({
left: ($(window).width() - hn.dragbox.outerwidth()) / 2,
top: ($(window).height() - hn.dragbox.outerheight()) / 2
})
settimeout(function() {
hnhtml.addclass("show")
}, 1)
},
hideopen: function() {
$("#hnhtml").removeclass("show")
},
//让弹窗可拖动
setdrag: function() {
hn.dragel.off("mousedown").on("mousedown", function(e) {
hn.dragx = e.offsetx
hn.dragy = e.offsety
hn.dragmaxx = $(window).width() - hn.dragbox.outerwidth()
hn.dragmaxy = $(window).height() - hn.dragbox.outerheight()
hn.dragging = true
})
if (hn.draghasset) {
return
} else {
hn.draghasset = true
}
$(document).on("mousemove", function(e) {
if (hn.dragging) {
var x = e.pagex - hn.dragx - $(window).scrollleft()
var y = e.pagey - hn.dragy - $(window).scrolltop()
x = x < 0 ? 0 : x
y = y < 0 ? 0 : y
x = x > hn.dragmaxx ? hn.dragmaxx : x
y = y > hn.dragmaxy ? hn.dragmaxy : y
hn.dragbox.css({
left: x,
top: y
})
}
})
$(document).on("mouseup", function(e) {
hn.dragging = false
})
}
}