(function ($) { function S4() { return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1); } function CreateIndentityWindowId() { return "UUID-" + (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4()); } function destroy(target) { $(target).dialog("destroy"); } function getWindow(target) { if (typeof target == "string") { return document.getElementById(target); } else { return $(target).closest(".window-body"); } } if(window.top != self){ if(window.top.jQuery && window.top.jQuery.window){ $.window = window.top.jQuery.window; return; } throw "鐖剁獥鍙f病鏈夊鍏Query鎴栧畾涔墂indow鎻掍欢锛�"; } $.window = function (options) { if (!options.url && !options.contents) { $.messager.alert("鎻愮ず", "缂哄皯蹇呰鍙傛暟!(url or contents)"); return false; } var windowId = CreateIndentityWindowId(); if (options.winId) { windowId = options.winId; } else { options.winId = windowId; } var defaultBtn = [{ text : '鍏抽棴', iconCls:'icon-delete', handler : function () { $("#" + windowId).dialog("close"); } } ]; if(options.buttons){ options.buttons = $.merge(options.buttons || [], defaultBtn); } options = $.extend({}, $.window.defaults, options || {}); if (options.isMax) { options.draggable = false; options.closed = true; } var dialog = $('
'); if (options.target != 'body') { options.inline = true; } dialog.appendTo($(options.target)); dialog.dialog($.extend({}, options, { onClose : function () { //鏈�绠�鍗曠殑瑙i噴灏辨槸锛氭妸闅愯棌鐨勭涓�涓弬鏁版樉绀哄寲銆傚洜涓洪�氬父涓�涓嚱鏁�(Function)鐨勮皟鐢紝浼氭湁涓�涓澶栫殑闅愯棌鍙傛暟锛� //灏辨槸鍑芥暟(Function)鎵�灞炵殑瀵硅薄(濡傛灉娌℃湁鎵�鐗规寚锛屽垯涓篻lobal锛堝window锛夊璞�)锛屽湪鍑芥暟鍐呬綘鍙敤this鍏抽敭瀛楄闂箣 if (typeof options.onClose == "function") { options.onClose.call(dialog,$); } destroy(this); }, onMove : function (left, top) { if (typeof options.onMove == "function") { options.onMove.call(dialog,$); } var o = $.data(this, 'panel').options; if (top < 0) { $(this).dialog("move", { "left" : left, "top" : 0 }); } else if (o.maximized) { $(this).dialog("restore"); $(this).dialog("move", { "left" : left + 100, "top" : top }); } if (top > ($(o.target).height() - 20)) { $(this).dialog("move", { "left" : left, "top" : ($(o.target).height() - 25) }); } } })); if (options.align) { var w = dialog.closest(".window"); switch (options.align) { case "right": dialog.dialog("move", { left : w.parent().width() - w.width() - 10 }); break; case "tright": dialog.dialog("move", { left : w.parent().width() - w.width() - 10, top : 0 }); break; case "bright": dialog.dialog("move", { left : w.parent().width() - w.width() - 10, top : w.parent().height() - w.height() - 10 }); break; case "left": dialog.dialog("move", { left : 0 }); break; case "tleft": dialog.dialog("move", { left : 0, top : 0 }); break; case "bleft": dialog.dialog("move", { left : 0, top : w.parent().height() - w.height() - 10 }); break; case "top": dialog.dialog("move", { top : 0 }); break; case "bottom": dialog.dialog("move", { top : w.parent().height() - w.height() - 10 }); break; } } if (options.isMax) { dialog.dialog("maximize"); dialog.dialog("open"); } if (options.contents) { ajaxSuccess(options.contents); } else { if (!options.isIframe) { $.ajax({ url : options.url, type : options.ajaxType || "POST", data : options.data == null ? "" : options.data, success : function (date) { ajaxSuccess(date); } }); } else { ajaxSuccess(); } } dialog.attr("id",windowId); dialog.destroy = function(){ destroy(this); }; return dialog; function ajaxSuccess(date) { if (options.isIframe && !date) { dialog.find("div.dialog-content").html(''); } else { dialog.find("div.dialog-content").html(date); } $.parser.parse(dialog); options.onComplete.call(dialog,$); } }; $.window.defaults = $.extend({}, $.fn.dialog.defaults, { url : '', data : '', contents:'', ajaxType:"POST", target : 'body', height : 200, width : 400, collapsible : false, minimizable : false, maximizable : false, closable : true, modal : true, shadow : false, onComplete : function (topjQuery) {} }); })(jQuery);