📄 window.js
字号:
}, updateZindex: function(zindex, win) { if (zindex > this.maxZIndex) this.maxZIndex = zindex; this.focusedWindow = win; }};var Dialog = { dialogId: null, onCompleteFunc: null, callFunc: null, parameters: null, confirm: function(content, parameters) { // Get Ajax return before if (content && typeof content != "string") { Dialog._runAjaxRequest(content, parameters, Dialog.confirm); return } content = content || ""; parameters = parameters || {}; var okLabel = parameters.okLabel ? parameters.okLabel : "Ok"; var cancelLabel = parameters.cancelLabel ? parameters.cancelLabel : "Cancel"; // Backward compatibility parameters = Object.extend(parameters, parameters.windowParameters || {}); parameters.windowParameters = parameters.windowParameters || {}; parameters.className = parameters.className || "alert"; var okButtonClass = "class ='" + (parameters.buttonClass ? parameters.buttonClass + " " : "") + " ok_button'" var cancelButtonClass = "class ='" + (parameters.buttonClass ? parameters.buttonClass + " " : "") + " cancel_button'" var content = "\ <div class='" + parameters.className + "_message'>" + content + "</div>\ <div class='" + parameters.className + "_buttons'>\ <input type='button' value='" + okLabel + "' onclick='Dialog.okCallback()' " + okButtonClass + "/>\ <input type='button' value='" + cancelLabel + "' onclick='Dialog.cancelCallback()' " + cancelButtonClass + "/>\ </div>\ "; return this._openDialog(content, parameters) }, alert: function(content, parameters) { // Get Ajax return before if (content && typeof content != "string") { Dialog._runAjaxRequest(content, parameters, Dialog.alert); return } content = content || ""; parameters = parameters || {}; var okLabel = parameters.okLabel ? parameters.okLabel : "Ok"; // Backward compatibility parameters = Object.extend(parameters, parameters.windowParameters || {}); parameters.windowParameters = parameters.windowParameters || {}; parameters.className = parameters.className || "alert"; var okButtonClass = "class ='" + (parameters.buttonClass ? parameters.buttonClass + " " : "") + " ok_button'" var content = "\ <div class='" + parameters.className + "_message'>" + content + "</div>\ <div class='" + parameters.className + "_buttons'>\ <input type='button' value='" + okLabel + "' onclick='Dialog.okCallback()' " + okButtonClass + "/>\ </div>"; return this._openDialog(content, parameters) }, info: function(content, parameters) { // Get Ajax return before if (content && typeof content != "string") { Dialog._runAjaxRequest(content, parameters, Dialog.info); return } content = content || ""; // Backward compatibility parameters = parameters || {}; parameters = Object.extend(parameters, parameters.windowParameters || {}); parameters.windowParameters = parameters.windowParameters || {}; parameters.className = parameters.className || "alert"; var content = "<div id='modal_dialog_message' class='" + parameters.className + "_message'>" + content + "</div>"; if (parameters.showProgress) content += "<div id='modal_dialog_progress' class='" + parameters.className + "_progress'> </div>"; parameters.ok = null; parameters.cancel = null; return this._openDialog(content, parameters) }, setInfoMessage: function(message) { $('modal_dialog_message').update(message); }, closeInfo: function() { Windows.close(this.dialogId); }, _openDialog: function(content, parameters) { var className = parameters.className; if (! parameters.height && ! parameters.width) { parameters.width = WindowUtilities.getPageSize().pageWidth / 2; } if (parameters.id) this.dialogId = parameters.id; else { var t = new Date(); this.dialogId = 'modal_dialog_' + t.getTime(); parameters.id = this.dialogId; } // compute height or width if need be if (! parameters.height || ! parameters.width) { var size = WindowUtilities._computeSize(content, this.dialogId, parameters.width, parameters.height, 5, className) if (parameters.height) parameters.width = size + 5 else parameters.height = size + 5 } //parameters.resizable = parameters.resizable || false; parameters.effectOptions = parameters.effectOptions || {duration: 1}; parameters.minimizable = false; parameters.maximizable = false; //parameters.draggable = false; parameters.closable = false; var win = new Window(parameters); win.getContent().innerHTML = content; win.showCenter(true, parameters.top, parameters.left); win.setDestroyOnClose(); win.cancelCallback = parameters.onCancel || parameters.cancel; win.okCallback = parameters.onOk || parameters.ok; return win; }, _getAjaxContent: function(originalRequest) { Dialog.callFunc(originalRequest.responseText, Dialog.parameters) }, _runAjaxRequest: function(message, parameters, callFunc) { if (message.options == null) message.options = {} Dialog.onCompleteFunc = message.options.onComplete; Dialog.parameters = parameters; Dialog.callFunc = callFunc; message.options.onComplete = Dialog._getAjaxContent; new Ajax.Request(message.url, message.options); }, okCallback: function() { var win = Windows.focusedWindow; if (!win.okCallback || win.okCallback(win)) { // Remove onclick on button $$("#" + win.getId()+" input").each(function(element) {element.onclick=null;}) win.close(); } }, cancelCallback: function() { var win = Windows.focusedWindow; // Remove onclick on button $$("#" + win.getId()+" input").each(function(element) {element.onclick=null}) win.close(); if (win.cancelCallback) win.cancelCallback(win); }}/* Based on Lightbox JS: Fullsize Image Overlays by Lokesh Dhakar - http://www.huddletogether.com For more information on this script, visit: http://huddletogether.com/projects/lightbox/ Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/ (basically, do anything you want, just leave my name and link)*/var isIE = navigator.appVersion.match(/MSIE/) == "MSIE";var WindowUtilities = { // From script.aculo.us getWindowScroll: function() { var w = window; var T, L, W, H; with (w.document) { if (w.document.documentElement && typeof documentElement.scrollTop != "undefined") { T = documentElement.scrollTop; L = documentElement.scrollLeft; } else if (w.document.body) { T = body.scrollTop; L = body.scrollLeft; } if (w.innerWidth) { W = w.innerWidth; H = w.innerHeight; } else if (w.document.documentElement && typeof documentElement.clientWidth != "undefined") { W = documentElement.clientWidth; H = documentElement.clientHeight; } else { W = body.offsetWidth; H = body.offsetHeight } } return { top: T, left: L, width: W, height: H }; }, // // getPageSize() // Returns array with page width, height and window width, height // Core code from - quirksmode.org // Edit for Firefox by pHaez // getPageSize: function(){ var xScroll, yScroll; if (window.innerHeight && window.scrollMaxY) { xScroll = document.body.scrollWidth; yScroll = window.innerHeight + window.scrollMaxY; } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac xScroll = document.body.scrollWidth; yScroll = document.body.scrollHeight; } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari xScroll = document.body.offsetWidth; yScroll = document.body.offsetHeight; } var windowWidth, windowHeight; if (self.innerHeight) { // all except Explorer windowWidth = self.innerWidth; windowHeight = self.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode windowWidth = document.documentElement.clientWidth; windowHeight = document.documentElement.clientHeight; } else if (document.body) { // other Explorers windowWidth = document.body.clientWidth; windowHeight = document.body.clientHeight; } var pageHeight, pageWidth; // for small pages with total height less then height of the viewport if(yScroll < windowHeight){ pageHeight = windowHeight; } else { pageHeight = yScroll; } // for small pages with total width less then width of the viewport if(xScroll < windowWidth){ pageWidth = windowWidth; } else { pageWidth = xScroll; } return {pageWidth: pageWidth ,pageHeight: pageHeight , windowWidth: windowWidth, windowHeight: windowHeight}; }, disableScreen: function(className, overlayId, contentId) { WindowUtilities.initLightbox(overlayId, className); var objBody = document.body; // prep objects var objOverlay = $(overlayId); var pageSize = WindowUtilities.getPageSize(); // Hide select boxes as they will 'peek' through the image in IE, store old value if (contentId && isIE) { WindowUtilities._hideSelect(); WindowUtilities._showSelect(contentId); } // set height of Overlay to take up whole page and show objOverlay.style.height = (pageSize.pageHeight + 'px'); objOverlay.style.width = (pageSize.windowWidth + 'px'); objOverlay.style.display = 'block'; }, enableScreen: function(id) { id = id || 'overlay_modal'; var objOverlay = $(id); if (objOverlay) { // hide lightbox and overlay objOverlay.style.display = 'none'; // make select boxes visible using old value if (id != "__invisible__") WindowUtilities._showSelect(); objOverlay.parentNode.removeChild(objOverlay); } }, _hideSelect: function(id) { if (isIE) { id = id == null ? "" : "#" + id + " "; $$(id + 'select').each(function(element) { if (! WindowUtilities.isDefined(element.oldVisibility)) { element.oldVisibility = element.style.visibility ? element.style.visibility : "visible"; element.style.visibility = "hidden"; } }); } }, _showSelect: function(id) { if (isIE) { id = id == null ? "" : "#" + id + " "; $$(id + 'select').each(function(element) { if (WindowUtilities.isDefined(element.oldVisibility)) { // Why?? Ask IE try { element.style.visibility = element.oldVisibility; } catch(e) { element.style.visibility = "visible"; } element.oldVisibility = null; } else { if (element.style.visibility) element.style.visibility = "visible"; } }); } }, isDefined: function(object) { return typeof(object) != "undefined" && object != null; }, // initLightbox() // Function runs on window load, going through link tags looking for rel="lightbox". // These links receive onclick events that enable the lightbox display for their targets. // The function also inserts html markup at the top of the page which will be used as a // container for the overlay pattern and the inline image. initLightbox: function(id, className) { // Already done, just update zIndex if ($(id)) { Element.setStyle(id, {zIndex: Windows.maxZIndex + 10}); } // create overlay div and hardcode some functional styles (aesthetic styles are in CSS file) else { var objBody = document.body; var objOverlay = document.createElement("div"); objOverlay.setAttribute('id', id); objOverlay.className = "overlay_" + className objOverlay.style.display = 'none'; objOverlay.style.position = 'absolute'; objOverlay.style.top = '0'; objOverlay.style.left = '0'; objOverlay.style.zIndex = Windows.maxZIndex + 10; objOverlay.style.width = '100%'; objBody.insertBefore(objOverlay, objBody.firstChild); } }, setCookie: function(value, parameters) { document.cookie= parameters[0] + "=" + escape(value) + ((parameters[1]) ? "; expires=" + parameters[1].toGMTString() : "") + ((parameters[2]) ? "; path=" + parameters[2] : "") + ((parameters[3]) ? "; domain=" + parameters[3] : "") + ((parameters[4]) ? "; secure" : ""); }, getCookie: function(name) { var dc = document.cookie; var prefix = name + "="; var begin = dc.indexOf("; " + prefix); if (begin == -1) { begin = dc.indexOf(prefix); if (begin != 0) return null; } else { begin += 2; } var end = document.cookie.indexOf(";", begin); if (end == -1) { end = dc.length; } return unescape(dc.substring(begin + prefix.length, end)); }, _computeSize: function(content, id, width, height, margin, className) { var objBody = document.body; var tmpObj = document.createElement("div"); tmpObj.setAttribute('id', id); tmpObj.className = className + "_content"; if (height) tmpObj.style.height = height + "px" else tmpObj.style.width = width + "px" tmpObj.style.position = 'absolute'; tmpObj.style.top = '0'; tmpObj.style.left = '0'; tmpObj.style.display = 'none'; tmpObj.innerHTML = content; objBody.insertBefore(tmpObj, objBody.firstChild); var size; if (height) size = $(id).getDimensions().width + margin; else size = $(id).getDimensions().height + margin; objBody.removeChild(tmpObj); return size; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -