/**
* Window for Youth - (1.2 base jQuery), also need jquery.myext.js
*
* please reserving all of the comment, otherwise you should not use those code
*
* @Author muqiao
* @Version 1.2
* @Copyright 2008 (c) muqiao (http://hi.baidu.com/emkiao)
* @Revision $Id: window_src.js 3 2008-07-10 15:47:40Z emkiao@qq.com $
*/
Array.prototype.concat || (Array.prototype.concat = function(){
// specially for opera
var arr = [];
for(var i = 0, l = this.length; i < l; i++) arr.push(this[i]);
for(var i = 0, l = arguments.length; i < l; i++){
if(typeof arguments[i] == 'undefined') continue;
if(arguments[i].constructor == Array){
for(var j = 0, ll = arguments[i].length; j < ll; j++){
arr.push(arguments[i][j]);
}
}else{
arr.push(arguments[i]);
}
}
return arr;
});
(function($){
$.fn.extend({
getDimensions: function(){
var el = this[0];
var display = this.css('display');
if (display != 'none' && display != null) // Safari bug
return {width: el.offsetWidth, height: el.offsetHeight};
var els = el.style, oV = els.visibility, oP = els.position, oD = els.display;
els.visibility = 'hidden';
els.position = 'absolute';
els.display = 'block';
var oW = el.clientWidth, oH = el.clientHeight;
els.display = oD;
els.position = oP;
els.visibility = oV;
return {width: oW, height: oH};
}
});
$.extend({
toFloat:function(obj){
obj = parseFloat(obj);
isNaN(obj) && (obj = arguments[1]||0);
return obj;
},
/**
* parseInt失败时返回 0
*/
toInt:function(obj){
obj = parseInt(obj);
isNaN(obj) && (obj = arguments[1]||0);
return obj;
},
/**
* 克隆一个对象
* @param {Object} object
*/
clone: function(obj){
var newobj = {};
for(var key in obj){
typeof obj[key] != 'undefined' && (newobj[key] = obj[key]);
}
return newobj;
},
/**
* convert any object to array
* @param {Object} iterable
*/
array:function(iterable){
if(!iterable){
return typeof iterable == 'undefined' ? [] : [iterable];
}
if(iterable.constructor == Array){
return iterable;
}
var i = iterable.length, s = [], t;
if(typeof i != 'number' || (t = typeof iterable) && t == 'string' || t == 'function' || iterable.setInterval){
s[0] = iterable;
}else{
while(i){
s[--i] = iterable[i];
}
}
return s;
},
getWindowScroll:function(){
var T, L, W, H,win = window, dom = document.documentElement, doc = document.body;
T = dom && dom.scrollTop || doc && doc.scrollTop || 0;
L = dom && dom.scrollLeft || doc && doc.scrollLeft || 0;
if(win.innerWidth){
W = win.innerWidth;
H = win.innerHeight;
}else{
W = dom && dom.clientWidth || doc && doc.clientWidth;
H = dom && dom.clientHeight || doc && doc.clientHeight;
}
return { top: T, left: L, width: W, height: H };
},
getPageSize:function(){
var windowWidth, windowHeight,
xScroll, yScroll,
win = window, dom = document.documentElement, doc = document.body;
if (win.innerHeight && win.scrollMaxY) {
xScroll = doc.scrollWidth;
yScroll = win.innerHeight + win.scrollMaxY;
}else{
xScroll = Math.max(dom ? dom.scrollWidth : 0,doc.scrollWidth,doc.offsetWidth);
yScroll = Math.max(dom ? dom.scrollHeight : 0,doc.scrollHeight,doc.offsetHeight);
}
if(win.innerHeight){
windowWidth = win.innerWidth;
windowHeight = win.innerHeight;
}else{
windowWidth = dom && dom.clientWidth || doc && doc.clientWidth;
windowHeight = dom && dom.clientHeight || doc && doc.clientHeight;
}
yScroll < windowHeight && (yScroll = windowHeight);
xScroll < windowWidth && (xScroll = windowWidth);
return {pageWidth: xScroll ,pageHeight: yScroll , windowWidth: windowWidth, windowHeight: windowHeight};
},
/**
* 闭包一个函数
* @param {Object} bind 作用域
* @param {Array} args 附加参数
* @example
* function test(param1,param1){
* alert(this.tagName);// this == document.body
* alert('I have arguments:'+param1+', '+param1);
* }
* test.bind(document.body,['param1','param2']);
* test();// result 'BODY'
*/
fbind:function(fn,bind,args){
return function(){
return fn.apply(bind||null,$.array(args).concat(arguments));
}
},
/**
* 闭包一个函数作为事件监听程式
* @param {Object} bind 作用域
* @param {Array} args 附加参数
* @example 于上一个函数差不多 只是参数列表里面多一个event对象
* function test(evt,param){
* alert(evt.pageX);
* alert(this);// this == document
* }
* test.bindE(document,['param']);
* $(document).click(test);
* // 单击则 弹出提示
*/
fbindE:function(fn,bind,args){
return function(e){
e = $.event.fix(window.event || e || {});
var ret = fn.apply(bind||null,[e].concat(args));
if(typeof ret == 'undefined'){
e.preventDefault();
e.stopPropagation();
}
return ret;
};
}
});
})(jQuery);
(function($){
var namespace = arguments[1];
var IE6 = $.browser.msie && parseInt($.browser.version) <= 7;
var Dialog = window[namespace] = function(){
var optionIndex = 0;
if(arguments.length > 0){
if(typeof arguments[0] == "string" ){
this.id = arguments[0];
optionIndex = 1;
}else{
this.id = arguments[0] ? arguments[0].id : null;
}
}
if(!this.id){
this.id = "window_" + new Date().getTime();
}
if(Dialogs.dialogs[this.id]){
return Dialogs.dialogs[this.id].show();
}
this.options = $.extend($.clone(Dialogs.settings),arguments[optionIndex] || {});
if(document.getElementById(this.id)){
this.options.content = document.getElementById(this.id).innerHTML;
}
this.relchilds = [];
this.parnetwin = null;
Dialogs.relation(this.options.parentId,this);
this.parent = $(document.body);
this.below = null;
this.above = null;
this.dialog = null;
Dialogs.dialogs[this.id] = this;
return this;
};
Dialog.prototype = {
toggle:function(){
return this[this.visible ? 'hide' : 'show'];
},
show:function(show){
if(this.visible) return this.toFront();
this.visible = true;
this.dialog == null && _createWin(this);
var o = this.options,
after = $.fbind(function(){
this.lightbox && this.lightbox.show();
this.toFront();
},this),
gon = true;
typeof o.onShow == 'function' && (gon = o.onShow.call(this)!==false);
if(!gon) return this;
typeof show == 'function' && (show.call(this.dialog,this,after)||true) ||
typeof o.show == 'function' && (o.show.call(this.dialog,this,after)||true) ||
this.dialog.show(1,after);
return this;
},
hide:function(hide){
if(!this.visible) return this;
this.visible = false;
var o = this.options,
after = $.fbind(function(){
this.lightbox && this.lightbox.hide();
},this),
gon = true;
typeof o.onHide == 'function' && (gon = o.onHide.call(this)!==false);
typeof hide == 'function' && (hide.call(this.dialog,this,after)||true) ||
typeof o.hide == 'function' && (o.hide.call(this.dialog,this,after)||true) ||
this.dialog.hide(1,after);
return this;
},
close:function(){
if($.datepicker)
$.datepicker._checkExternalClick('');
var clean = true;
if(!this.options) return;
if(typeof this.options.onClose == 'function'){
clean = this.options.onClose.call(this);
}
if(clean === false) return;
this.dowhat && this.endDrag && this.endDrag();
this.dialog.remove();
if(this.lightbox){
this.lightbox.remove();
}
if(typeof this.options.afterClose=='function'){
this.options.afterClose();
}
if(this.autoposition){
$(window).unbind('scroll',this.autoposition).unbind('resize',this.autoposition);
}
delete Dialogs.dialogs[this.id];
Dialogs.dialogs[this.id] != undefined && (Dialogs.dialogs[this.id] = null);
if(Dialogs.calls[this.id]){
var l = Dialogs.calls[this.id].length;
while(l){
delete Dialogs.calls[this.id][--l];
Dialogs.calls[this.id][l] != undefined && (Dialogs.calls[this.id][l] = null);
}
delete Dialogs.calls[this.id];
Dialogs.calls[this.id] != undefined && (Dialogs.calls[this.id] = null);
}
if(Dialogs.focusedWindow == this){
delete Dialogs.focusedWindow;
Dialogs.focusedWindow = this.below;
}
Dialogs.shift(this);
for(var k in this){
this[k] = null;
}
},
html:function(content){
var o = this.options;
if(content==undefined){
return o.content||'';
}
content==''&& (content = " ");
if(this.dialog != null){
if(o.url){
this.content.src = null;
o.url = null;
this.content = $('
');
$('#'+this.id+'_table_content',this.dialog).empty().append(this.content);
}
this.content.empty().append(content);
o.autosize && this.autoAdaptSize();
o.autocenter && this.center();
try{$('input:visible, textarea',this.content)[0].focus()}catch(e){}
}
o.content = content;
return this;
},
center:function(){
var wsize = $.getWindowScroll();
var top = (wsize.height - (this.height + this.heightN + this.heightS))/2;
var left = (wsize.width - (this.width + this.widthW + this.widthE))/2;
if(!this.posfixed){
top += wsize.top;
left += wsize.left;
}
this.dialog.css({top:top,left:left});
},
load:function(url){
var dialog = this;
$.ajax({// Request the remote document
url: url,
cache:false,
type: 'GET',
dataType: "html",
success: function(data){
dialog.html(data);
},
error:function(){
dialog.html('请求异常');
}
});
return this;
},
status:function(status){
if(status==undefined){
return this.options.status||'';
}
if(status==''){
status = " ";
}
if(this.dialog!=null){
$('#'+this.id+'_bottom',this.dialog).empty().append(status);
}
this.options.status = status;
return this;
},
title:function(title){
if(title==undefined){
return this.options.title||'';
}
if(title==''){
title = " ";
}
if(this.dialog!=null){
$('#'+this.id+'_top',this.dialog).empty().append(title);
}
this.options.title = title;
return this;
},
href:function(url){
if(url == undefined){
return this.options.url || '';
}
if(url==''){
url = "";
}
if (this.dialog != null) {
if(this.options.url){
this.content.attr('src',url);
}
// Not an url content, change div to iframe
else{
this.content = $("");
$('#' + this.id + "_table_content").empty().append(this.content);
}
}
this.options.url = url;
return this;
},
setSize:function(width,height){
// Check min size
(!width || (!this.minimized && width < this.options.minWidth)) && (width = this.options.minWidth);
(!height || (!this.minimized && height < this.options.minHeight)) && (height = this.options.minHeight);
this.width = width;
this.height = height;
this.dialog.css({width:width+ this.widthW + this.widthE,height:this.height+ this.heightN + this.heightS});
this.content.css({height:height,width:width});
this.masker && this.masker.css('display') !='none' && this.masker.css({width:width ,height:height});
return this;
},
autoAdaptSize:function(){
var w = this.content[0].scrollWidth;
var h = this.content[0].scrollHeight;
if(w==this.width && h==this.hright) return;
this.setSize(w,h);
//{{{ hack get real scrollWidth and scrollHeight
var i = 1;
do{
this.content[0].scrollLeft += 20;
if(this.content[0].scrollLeft < 20*i){
break;
}
}while(i++);
i = 1;
do{
this.content[0].scrollTop += 20
if(this.content[0].scrollTop < 20*i){
break;
}
}while(i++);
w += this.content[0].scrollLeft;
h += this.content[0].scrollTop;
this.content[0].scrollLeft = 0;
this.content[0].scrollTop = 0;
//}}} hack end
var wsize = $.getWindowScroll();
var maxH = wsize.height - this.heightN - this.heightS - 10;
var maxW = wsize.width - this.widthW - this.widthE - 10;
h > maxH && (h = maxH);
w > maxW && (w = maxW);
this.setSize(w,h);
},
setLocation:function(top,left){
top = $.toFloat(top,this.top);
left = $.toFloat(left,this.left);
this.dialog.css({top:top,left:left});
return this;
},
minimize:function(){
var r2 = $('#'+this.id + "_row2");
if(!this.minimized){
this.minimized = true;
var dh = r2.height();
this.r2Height = dh;
var h = this.dialog.height() - dh;
this.height -= dh;
r2.hide();
this.dialog.css('height',h);
}else{
this.minimized = false;
var dh = this.r2Height;
this.r2Height = null;
var h = this.dialog.height() + dh;
this.height += dh;
this.dialog.css('height',h);
r2.show();
this.toFront();
}
return this;
},
maximize:function(){
if(this.minimized) return this;
if(this.storedLocation != null){
_restoreLocation(this);
this.maximized = false;
}else{
_storeLocation(this);
this.maximized = true;
var win = $(window),doc = $(document);
var width = win.width() - this.widthW - this.widthE;
var height= win.height() - this.heightN - this.heightS;
this.setSize(width, height);
this.posfixed ?
this.dialog.css({top:0,left:0}) :
this.dialog.css({top:(doc.scrollTop() || 0), left:(doc.scrollLeft() || 0)});
}
return this.toFront();
},
toFront:function(){
Dialogs.toFront(this);
return this;
},
ZIndex: function(zindex){
if(zindex == undefined)
return $.toInt(this.dialog.css('zIndex'));
this.dialog.css('zIndex',zindex);
return this;
},
blur:function(){
var can = true;
typeof this.options.onBlur == 'function' && (can = this.options.onBlur.call(this) !== false);
return can;
},
focus:function(){
typeof this.options.onFocus == 'function' && this.options.onFocus.call(this);
return this;
}
};
var Dialogs = window[namespace+'s'] = {
maxZIndex:99,
focusedWindow:null,
dialogs:{},
calls:{},
settings:{
minWidth: 80,
minHeight: 50,
closable: true,
resizable: false,
minimizable: false,
maximizable: false,
draggable: false,
autosize: false,
lightbox: false,
autocenter: false,
autopos: null, // 'center' / 'fixed'
left: 'auto',
top: 'auto',
title: ' ',
status: ' ',
width: 0,
height: 0
},
prevsets:function(settings){
$.extend(Dialogs.settings,settings||{});
},
toFront:function(win){
if(!Dialogs.focusedWindow){
Dialogs.focusedWindow = win;
win.ZIndex(++Dialogs.maxZIndex);
win.focus();
return;
}
if(win == Dialogs.focusedWindow){
return;
}
if($.inArray(Dialogs.focusedWindow,win.relchilds)!=-1){
return;
}
if(win.parentwin){
Dialogs.toFront(win.parentwin);
}
if(Dialogs.focusedWindow.blur() != false){
Dialogs.shift(win);
win.below = Dialogs.focusedWindow;
win.above = null;
Dialogs.focusedWindow.above = win;
Dialogs.focusedWindow = win;
var origI = win.ZIndex();
win.ZIndex(++Dialogs.maxZIndex);
var dI = Dialogs.maxZIndex - origI;
var l = win.relchilds.length;
while(l){
var w = win.relchilds[--l];
if(!w.options) continue;
var I = w.ZIndex()+dI;
w.ZIndex(I);
Dialogs.maxZIndex < I && (Dialogs.maxZIndex = I);
}
win.focus();
}
try{$('input:visible, textarea',Dialogs.focusedWindow.content)[0].focus()}catch(e){}
},
relation:function(Id,win){
if(Id == undefined) return;
var pwin = Id == 'auto' ? Dialogs.focusedWindow : Dialogs.dialogs[Id];
if(pwin instanceof Dialog){
pwin.relchilds.push(win);
win.parentwin = pwin;
}
},
shift:function(win){
(win.below instanceof Dialog) && (win.below.above = win.above);
(win.above instanceof Dialog) && (win.above.below = win.below);
},
close: function(id){
var win = id==undefined ? Dialogs.focusedWindow : Dialogs.dialogs[id];
if(win instanceof Dialog){
win.close();
}
},
show: function(id){
if(Dialogs.dialogs[id] instanceof Dialog){
Dialogs.dialogs[id].show();
}
},
alert:function(message,options){
options || (options = {});
options.button = options.button || {};
options.button.ok = options.button.ok || ['确定',function(){this.close();}];
return Dialogs.opendialog(message,options);
},
confirm:function(message,options){
options || (options = {});
options.button = options.button || {};
options.button.ok = options.button.ok || ['确定',function(){this.close();}];
options.button.cancel = options.button.cancel||['取消',function(){this.close();}];
return Dialogs.opendialog(message,options);
},
info:function(message,timeout,options){
options || (options = {});
if(timeout){
options.onShow = function(){
setTimeout($.fbind(this.close,this),$.toInt(timeout,5000));
};
}
return Dialogs.opendialog(message,options);
},
redirect:function(message,timeout,url,options){
options || (options = {});
options.afterClose = function(){
window.location = url||location.href;
};
if(timeout){
timeout = $.toInt(timeout,5000);
}else{
timeout = 5000;
}
options.onShow = function(){
this.timeout = timeout;
this.timer = setInterval($.fbind(function(){
if((this.timeout -= 1000) < 0 ){
clearInterval(this.timer);
this.close();
return;
}
this.status('leave : '+(this.timeout/1000)+ ' second');
},this),1000);
};
return Dialogs.opendialog(message,options);
},
load:function(url,params,options){
options || (options = {});
var dialog = (new Dialog(options)).html('
').show();
$.ajax({// Request the remote document
url: url,
type: 'GET',
cache:false,
data:params,
dataType: "html",
success: function(data,status){
dialog.html(data);// data.replace(/