/** * jmpopups * Copyright (c) 2009 Otavio Avila (http://otavioavila.com) * Licensed under GNU Lesser General Public License * * @docs http://jmpopups.googlecode.com/ * @version 0.5.1 * */ function closeWindow(title){ //alert("!~~~~~~~~~~~~~~~ closeWindow"); $.closePopupLayer(title); } function openWindow(windowUrl,windowName,windowSize) { $.openPopupLayer({ name: windowName, width: $(document).width()/4, url: windowUrl }); } (function($) { var openedPopups = []; var popupLayerScreenLocker = false; var focusableElement = []; var setupJqueryMPopups = { screenLockerBackground: "#000", screenLockerOpacity: "0.5" }; $.setupJMPopups = function(settings) { setupJqueryMPopups = jQuery.extend(setupJqueryMPopups, settings); return this; } $.openPopupLayer = function(settings) { if (typeof(settings.name) != "undefined" && !checkIfItExists(settings.name)) { settings = jQuery.extend({ width: "auto", height: "auto", parameters: {}, target: "", success: function() {}, error: function() {}, beforeClose: function() {}, afterClose: function() {}, reloadSuccess: null, cache: false }, settings); loadPopupLayerContent(settings, true); //alert("openedPopups.length:"+openedPopups.length); return this; } } $.closePopupLayer = function(name) { if (name) { //alert("name:"+name+"; openedPopups.length:"+openedPopups.length); for (var i = 0; i < openedPopups.length; i++) { //alert("openedPopups[i].name:"+openedPopups[i].name); if (openedPopups[i].name == name) { var thisPopup = openedPopups[i]; openedPopups.splice(i,1) thisPopup.beforeClose(); $("#popupLayer_" + name).fadeOut(function(){ $("#popupLayer_" + name).remove(); focusableElement.pop(); if (focusableElement.length > 0) { $(focusableElement[focusableElement.length-1]).focus(); } thisPopup.afterClose(); hideScreenLocker(name); }); break; } } } else { if (openedPopups.length > 0) { $.closePopupLayer(openedPopups[openedPopups.length-1].name); } } return this; } $.reloadPopupLayer = function(name, callback) { if (name) { for (var i = 0; i < openedPopups.length; i++) { if (openedPopups[i].name == name) { if (callback) { openedPopups[i].reloadSuccess = callback; } loadPopupLayerContent(openedPopups[i], false); break; } } } else { if (openedPopups.length > 0) { $.reloadPopupLayer(openedPopups[openedPopups.length-1].name); } } return this; } function setScreenLockerSize() { if (popupLayerScreenLocker) { $('#popupLayerScreenLocker').height($(document).height() + "px"); $('#popupLayerScreenLocker').width($(document.body).outerWidth(true) + "px"); } } function checkIfItExists(name) { if (name) { for (var i = 0; i < openedPopups.length; i++) { if (openedPopups[i].name == name) { return true; } } } return false; } function showScreenLocker() { if ($("#popupLayerScreenLocker").length) { if (openedPopups.length == 1) { popupLayerScreenLocker = true; setScreenLockerSize(); $('#popupLayerScreenLocker').fadeIn(); } if ($.browser.msie && $.browser.version < 7) { $("select:not(.hidden-by-jmp)").addClass("hidden-by-jmp hidden-by-" + openedPopups[openedPopups.length-1].name).css("visibility","hidden"); } $('#popupLayerScreenLocker').css("z-index",parseInt(openedPopups.length == 1 ? 999 : $("#popupLayer_" + openedPopups[openedPopups.length - 2].name).css("z-index")) + 1); } else { $("body").append("<div id='popupLayerScreenLocker'><!-- --></div>"); $("#popupLayerScreenLocker").css({ position: "absolute", background: setupJqueryMPopups.screenLockerBackground, left: "0", top: "0", opacity: setupJqueryMPopups.screenLockerOpacity, display: "none" }); showScreenLocker(); $("#popupLayerScreenLocker").click(function() { // $.closePopupLayer(); }); } } function hideScreenLocker(popupName) { if (openedPopups.length == 0) { screenlocker = false; $('#popupLayerScreenLocker').fadeOut(); } else { $('#popupLayerScreenLocker').css("z-index",parseInt($("#popupLayer_" + openedPopups[openedPopups.length - 1].name).css("z-index")) - 1); } if ($.browser.msie && $.browser.version < 7) { $("select.hidden-by-" + popupName).removeClass("hidden-by-jmp hidden-by-" + popupName).css("visibility","visible"); } } function setPopupLayersPosition(popupElement, animate) { if (popupElement) { if (popupElement.width() < $(window).width()) { var leftPosition = (document.documentElement.offsetWidth - popupElement.width()) / 2; } else { var leftPosition = document.documentElement.scrollLeft + 5; } if (popupElement.height() < $(window).height()) { var topPosition = document.documentElement.scrollTop + ($(window).height() - popupElement.height()) / 2; } else { var topPosition = document.documentElement.scrollTop + 5; } var positions = { left: leftPosition-200 + "px", top: topPosition + "px" }; if (!animate) { popupElement.css(positions); } else { popupElement.animate(positions, "slow"); } setScreenLockerSize(); } else { for (var i = 0; i < openedPopups.length; i++) { setPopupLayersPosition($("#popupLayer_" + openedPopups[i].name), true); } } } function showPopupLayerContent(popupObject, newElement, data) { var idElement = "popupLayer_" + popupObject.name; if (newElement) { showScreenLocker(); $("body").append("<div id='" + idElement + "'><!-- --></div>"); var zIndex = parseInt(openedPopups.length == 1 ? 1000 : $("#popupLayer_" + openedPopups[openedPopups.length - 2].name).css("z-index")) + 2; } else { var zIndex = $("#" + idElement).css("z-index"); } var popupElement = $("#" + idElement); popupElement.css({ visibility: "hidden", width: popupObject.width == "auto" ? "" : popupObject.width + "px", height: popupObject.height == "auto" ? "" : popupObject.height + "px", position: "absolute", "z-index": zIndex }); var linkAtTop = "<a href='#' class='jmp-link-at-top' style='position:absolute; left:-9999px; top:-1px;'> </a><input class='jmp-link-at-top' style='position:absolute; left:-9999px; top:-1px;' />"; var linkAtBottom = "<a href='#' class='jmp-link-at-bottom' style='position:absolute; left:-9999px; bottom:-1px;'> </a><input class='jmp-link-at-bottom' style='position:absolute; left:-9999px; top:-1px;' />"; popupElement.html(linkAtTop + data + linkAtBottom); setPopupLayersPosition(popupElement); popupElement.css("display","none"); popupElement.css("visibility","visible"); if (newElement) { popupElement.fadeIn(); } else { popupElement.show(); } $("#" + idElement + " .jmp-link-at-top, " + "#" + idElement + " .jmp-link-at-bottom").focus(function(){ $(focusableElement[focusableElement.length-1]).focus(); }); var jFocusableElements = $("#" + idElement + " a:visible:not(.jmp-link-at-top, .jmp-link-at-bottom), " + "#" + idElement + " *:input:visible:not(.jmp-link-at-top, .jmp-link-at-bottom)"); if (jFocusableElements.length == 0) { var linkInsidePopup = "<a href='#' class='jmp-link-inside-popup' style='position:absolute; left:-9999px;'> </a>"; popupElement.find(".jmp-link-at-top").after(linkInsidePopup); focusableElement.push($(popupElement).find(".jmp-link-inside-popup")[0]); } else { jFocusableElements.each(function(){ if (!$(this).hasClass("jmp-link-at-top") && !$(this).hasClass("jmp-link-at-bottom")) { focusableElement.push(this); return false; } }); } $(focusableElement[focusableElement.length-1]).focus(); popupObject.success(); if (popupObject.reloadSuccess) { popupObject.reloadSuccess(); popupObject.reloadSuccess = null; } } function loadPopupLayerContent(popupObject, newElement) { if (newElement) { openedPopups.push(popupObject); } if (popupObject.target != "") { showPopupLayerContent(popupObject, newElement, $("#" + popupObject.target).html()); } else { //源码,经过本人实验method设置成post也不行,故此改造成如下代码 // $.ajax({ // url: popupObject.url, // data: popupObject.parameters, //cache: popupObject.cache, // dataType: "html", // method: "GET", // success: function(data) { // showPopupLayerContent(popupObject, newElement, data); // }, //error: popupObject.error // }); //改造后的 $.post ( popupObject.url, popupObject.parameters, function(result) //回调函数 { showPopupLayerContent(popupObject, newElement, result); }, "html" //返回类型 ); } } $(window).resize(function(){ setScreenLockerSize(); setPopupLayersPosition(); }); $(document).keydown(function(e){ if (e.keyCode == 27) { $.closePopupLayer(); } }); })(jQuery);
相关推荐
NULL 博文链接:https://dpn525.iteye.com/blog/1258482
弹出框jquery.弹出框jquery.弹出框jquery.弹出框jquery.弹出框jquery.弹出框jquery.弹出框jquery.弹出框jquery.弹出框jquery.弹出框jquery.弹出框jquery.弹出框jquery.弹出框jquery.弹出框jquery.弹出框jquery.弹出...
jquery.purebox弹出层插件支持窗口对话框弹出层代码 jquery.purebox弹出层插件支持窗口对话框弹出层代码
jquery.popup 弹出层选择 提示
JQuery.BlockUI是众多JQuery插件弹出层中的一个,它小巧(原版16k,压缩后10左右),容易使用, 功能齐全,支持Iframe,支持Modal,可定制性高也意味他默认谦虚的外表。
jquery.DOMWindow弹出层与TAB切换实例汇总,jquery.DOMWindow.js是浮动弹出框的核心部件,本插件的弹出框有多种形式,比如它可以弹出不带边框的、带有淡入淡出特效的、各种颜色的背景浮动框、弹出后背景会变暗的浮动...
jquery.alerts 弹出框,可以自己自定义样式,通过jAlert、jConfirm、jPrompt就能实现原先js的弹出框,简单方便
jquery.cookie.js,jquery-1.11.0.min.js,respond.min.js, bootstrap.min.js,html5shiv.js
在官网上一直下载不下来 然后共享在这 jquery.json-2.3.min.js和jquery.json-2.3.js
jquery.pagination.js 下载,优秀的jquery分页插件,使用IP代理国外网站下载而来
jquery.json2xml.js&&jquery.xml2json.js在jQuery的基础上实现json与xml的相互转换
jquery.cvbox 弹出对话框插件.zip
jquery.form.js jquery.form.js
jquery.cookie.js下载 jquery.cookie.js下载
jquery.qrcode.min.js 二维码的jquery插件
jquery.qtip-1.0.0-rc3.js 弹出层
jquery.min.map is a good
jquery.validate.js jquery.validate.js
jquery.marquee.js demo及源文件
jquery.easing.1.3.min.js 动画效果js