// thinksns ui.box
jquery.extend(ui, {
box:function(element, options){
}
});
jquery.extend(ui.box, {
wrapper: '
',
inited: false,
ie6: (jquery.browser.msie && jquery.browser.version < 7),
init:function(title,callback){
//edit by yangjs 避免意外情况重载
if( !this.inited ){
$('body').prepend( this.wrapper );
this.inited = true;
}else{
return false;
}
if("undefined" != typeof(title)){
$("").insertbefore($('#tsbox .layer-content'));
}
$('#tsbox').show();
jquery('')
.css(jquery.extend(ui.box._cssforoverlay(), {
zindex: 999, opacity: 0.6
})).appendto(document.body);
$('#tsbox').stop().css({width: '', height: ''});
jquery(document.body).bind('keypress.tsbox', function(event) {
var key = event.keycode?event.keycode:event.which?event.which:event.charcode;
if (key == 27) {
jquery(document.body).unbind('keypress.tsbox');
ui.box.close(callback);
return false;
}
});
$('#tsbox').find('.ico-close').click(function() {
ui.box.close(callback);
return false;
});
},
setcontent:function(content){
$('#layer-content').html(content);
},
close:function(fn){
this.inited = false;
$('#ui-fs .ui-fs-all .ui-fs-allinner div.list').find("a").die("click");
$('.talkpop').remove();
$('#tsbox').remove();
jquery('.boxy-modal-blackout').remove();
if("undefined" != typeof(fn)){
eval(fn); //edit by yangjs
}
},
alert:function(data,title,callback){
this.init(title,callback);
this.setcontent(''+data+'
');
this.center();
},
show:function(content,title,callback){
this.init(title,callback);
this.setcontent(content);
this.center();
},
//requreurl 请求地址
//title 弹窗标题
//callback 窗口关闭后的回调事件
//requestdata 请求附带的参数
//type ajax请求协议 默认为get
//edit by yangjs
load:function(requesturl,title,callback,requestdata,type){
// if("undefined" != typeof(_uid_)){ //需要才判断
// //增加判断未登录时的登录操作,可能有些地方需要排除.允许弹窗.
// if(_uid_<=0 && option.title!='快速登录'){
// option.title = '快速登录';
// data = u('home/public/quick_login');
// }
// }
this.init(title,callback);
if( "undefined" != typeof(type) ){
var ajaxtype = type;
}else{
var ajaxtype = "get";
}
this.setcontent('');
this.center();
var obj = this;
if("undefined" == requestdata){
var requestdata = {};
}
jquery.ajax({url:requesturl,
type:ajaxtype,
data:requestdata,
cache:false,
datatype:'html',
success:function(html){
obj.setcontent(html);
obj.center();
}
});
},
_viewport: function() {
var d = document.documentelement, b = document.body, w = window;
return jquery.extend(
jquery.browser.msie ?
{ left: b.scrollleft || d.scrollleft, top: b.scrolltop || d.scrolltop } :
{ left: w.pagexoffset, top: w.pageyoffset },
!ui.box._u(w.innerwidth) ?
{ width: w.innerwidth, height: w.innerheight } :
(!ui.box._u(d) && !ui.box._u(d.clientwidth) && d.clientwidth != 0 ?
{ width: d.clientwidth, height: d.clientheight } :
{ width: b.clientwidth, height: b.clientheight }) );
},
_u: function() {
for (var i = 0; i < arguments.length; i++)
if (typeof arguments[i] != 'undefined') return false;
return true;
},
_cssforoverlay: function() {
if (ui.box.ie6) {
return ui.box._viewport();
} else {
return {width: '100%', height: jquery(document).height()};
}
},
center: function(axis) {
var v = ui.box._viewport();
var o = [v.left, v.top];
if (!axis || axis == 'x') this.centerat(o[0] + v.width / 2 , null);
if (!axis || axis == 'y') this.centerat(null, o[1] + v.height / 2);
return this;
},
movetox: function(x) {
if (typeof x == 'number') $('#tsbox').css({left: x});
else this.centerx();
return this;
},
// move this dialog (y-coord only)
movetoy: function(y) {
if (typeof y == 'number') $('#tsbox').css({top: y});
else this.centery();
return this;
},
centerat: function(x, y) {
var s = this.getsize();
//alert(s);
if (typeof x == 'number') this.movetox(x - s[0]/2 );
if (typeof y == 'number') this.movetoy(y - s[1]/2 );
return this;
},
centeratx: function(x) {
return this.centerat(x, null);
},
centeraty: function(y) {
return this.centerat(null, y);
},
getsize: function() {
return [$('#tsbox').width(), $('#tsbox').height()];
},
getcontent: function() {
return $('#tsbox').find('.boxy-content');
},
getposition: function() {
var b = $('#tsbox');
return [b.offsetleft, b.offsettop];
},
getcontentsize: function() {
var c = this.getcontent();
return [c.width(), c.height()];
},
_getboundsforresize: function(width, height) {
var csize = this.getcontentsize();
var delta = [width - csize[0], height - csize[1]];
var p = this.getposition();
return [math.max(p[0] - delta[0] / 2, 0),
math.max(p[1] - delta[1] / 2, 0), width, height];
}
});