📄 ajaxtags.js
字号:
parameters: options.parameters || '', eventType: options.eventType ? options.eventType : "click", parser: options.parser ? options.parser : new ResponseXmlToHtmlLinkListParser(), handler: options.handler ? options.handler : this.handler, collapsedClass: options.collapsedClass ? options.collapsedClass : "collapsedNode", expandedClass: options.expandedClass ? options.expandedClass : "expandedNode", treeClass: options.treeClass ? options.treeClass : "tree", nodeClass: options.nodeClass || '' }, options || {}); this.calloutParameter = AJAX_DEFAULT_PARAMETER; }, execute: function(e) { if (isFunction(this.options.preFunction)) {this.options.preFunction();} if (this.options.cancelExecution) { this.cancelExecution = false; return ; } //if the node is expanded, just collapse it if(this.options.target != null) { var imgElem = $("span_" + this.options.target); if(imgElem != null) { var expanded = this.toggle(imgElem); if(!expanded) { $(this.options.target).innerHTML = ""; if (! $(this.options.target).style) $(this.options.target).setAttribute("style",""); $(this.options.target).style.display ="none"; return; } } } // indicator // parse parameters and do replacements var ajaxParameters = this.options.parameters || ''; var re = new RegExp("(\\{"+this.calloutParameter+"\\})", 'g'); ajaxParameters = ajaxParameters.replace(re, this.options.target); var params = buildParameterString(ajaxParameters); var obj = this; // required because 'this' conflict with Ajax.Request var aj = new Ajax.Request(this.url, { asynchronous: true, method: 'get', evalScripts: true, parameters: params, onSuccess: function(request) { // IE 5,6 BUG objx = new Object(); objx.responseXML = request.responseXML; obj.options.parser.load(Object.extend(objx, { collapsedClass: obj.options.collapsedClass, treeClass: obj.options.treeClass, nodeClass: obj.options.nodeClass})); obj.options.handler(objx, {target: obj.options.target, parser: obj.options.parser, eventType: obj.options.eventType, url: obj.url}); }, onFailure: function(request) { if (isFunction(obj.options.errorFunction)){ obj.options.errorFunction();} }, onComplete: function(request) { if (isFunction(obj.options.postFunction)) {obj.options.postFunction();} // damit htmlcontent wieder geht reloadAjaxListeners(); } }); }, toggle: function (e) { var expanded = e.className == this.options.expandedClass; e.className = expanded ? this.options.collapsedClass : this.options.expandedClass; return !expanded; }, handler: function(request, options) { var parser = options.parser; var target = $(options.target); if (parser.content == null) { // div.setAttribute("style",""); // div.style.display ="none"; if (!target.style) target.setAttribute("style",""); target.style.display ="none"; target.innerHTML = ""; return; } target.appendChild(parser.content); if (!target.style) target.setAttribute("style",""); target.style.display ="block"; var images = target.getElementsByTagName("span"); for (var i=0; i<images.length; i++) { //get id var id = images[i].id.substring(5); var toggleFunction = "function() {toggleTreeNode('" + id + "', '" + options.url + "', null);}"; eval("images[i].on" + options.eventType + "=" + toggleFunction); } //toggle the one that must be expanded var expandedNodes = parser.expandedNodes; for (var i=0; i<expandedNodes.length; i++) { toggleTreeNode(expandedNodes[i], options.url, null); } }});/** * TABPANEL TAG */AjaxJspTag.TabPanel = Class.create();AjaxJspTag.TabPanel.prototype = Object.extend(new AjaxJspTag.Base(), { initialize: function(url, options) { this.url = url; this.setOptions(options); this.execute(); }, setOptions: function(options) { this.options = Object.extend({ parameters: options.parameters || '', eventType: options.eventType ? options.eventType : "click", parser: options.parser ? options.parser : new ResponseHtmlParser(), handler: options.handler ? options.handler : this.handler }, options || {}); }, execute: function(e) { if (isFunction(this.options.preFunction)){ this.options.preFunction();} if (this.options.cancelExecution) { this.cancelExecution = false; return ; } // parse parameters and do replacements this.resolveParameters(); var params = buildParameterString(this.options.parameters); var obj = this; // required because 'this' conflict with Ajax.Request var aj = new Ajax.Updater(this.options.target, this.url, { asynchronous: true, method: 'get', evalScripts: true, parameters: params, onSuccess: function(request) { var src; if (obj.options.source) { src = obj.options.source; } else { src = document.getElementsByClassName(obj.options.currentStyleClass, $(obj.options.panelId))[0]; } obj.options.handler(request, {source: src, panelStyleId: obj.options.panelId, currentStyleClass: obj.options.currentStyleClass}); }, onFailure: function(request) { if (isFunction(obj.options.errorFunction)){ obj.options.errorFunction();} }, onComplete: function(request) { if (isFunction(obj.options.postFunction)){ obj.options.postFunction();} } }); }, handler: function(request, options) { // find current anchor var cur = document.getElementsByClassName(options.currentStyleClass, $(options.panelStyleId)); // remove class if(cur.length > 0) cur[0].className = ''; // add class to selected tab options.source.className = options.currentStyleClass; }});/** * PORTLET TAG */AjaxJspTag.Portlet = Class.create();AjaxJspTag.Portlet.prototype = Object.extend(new AjaxJspTag.Base(), { initialize: function(url, options) { this.url = url; this.setOptions(options); this.setListeners(); if (parseBoolean(this.options.executeOnLoad )) { this.execute(); } if (this.preserveState) this.checkCookie(); if (parseBoolean(this.options.startMinimize)) { this.togglePortlet(); } addAjaxListener(this); // should i reloadAjaxListeners() after execute? }, reload: function () { this.setListeners(); }, setOptions: function(options) { this.options = Object.extend({ parameters: options.parameters || '', target: options.source+"Content", close: options.source+"Close", startMinimize: options.startMinimize || false, refresh: options.source+"Refresh", toggle: options.source+"Size", isMaximized: true, expireDays: options.expireDays || "0", expireHours: options.expireHours || "0", expireMinutes: options.expireMinutes || "0", executeOnLoad: evalBoolean(options.executeOnLoad, true), refreshPeriod: options.refreshPeriod || null, eventType: options.eventType ? options.eventType : "click", parser: options.parser ? options.parser : new ResponseHtmlParser(), handler: options.handler ? options.handler : this.handler }, options || {}); if (parseInt(this.options.expireDays) > 0 || parseInt(this.options.expireHours) > 0 || parseInt(this.options.expireMinutes) > 0) { this.preserveState = true; this.options.expireDate = getExpDate( parseInt(this.options.expireDays), parseInt(this.options.expireHours), parseInt(this.options.expireMinutes)); } this.isAutoRefreshSet = false; }, setListeners: function() { if (this.options.imageClose) { eval("$(this.options.close).on"+this.options.eventType+" = this.closePortlet.bindAsEventListener(this)"); } if (this.options.imageRefresh) { eval("$(this.options.refresh).on"+this.options.eventType+" = this.refreshPortlet.bindAsEventListener(this)"); } if (this.options.imageMaximize && this.options.imageMinimize) { eval("$(this.options.toggle).on"+this.options.eventType+" = this.togglePortlet.bindAsEventListener(this)"); } }, execute: function(e) { if (isFunction(this.options.preFunction)){ this.options.preFunction();} if (this.options.cancelExecution) { this.cancelExecution = false; return ; } // parse parameters and do replacements this.resolveParameters(); var params = buildParameterString(this.options.parameters); var obj = this; // required because 'this' conflict with Ajax.Request if (this.options.refreshPeriod && this.isAutoRefreshSet == false) { // periodic updater var freq = this.options.refreshPeriod; this.ajaxPeriodicalUpdater = new Ajax.PeriodicalUpdater(this.options.target, this.url, { asynchronous: true, method: 'get', evalScripts: true, parameters: params, frequency: freq, onFailure: function(request) { if (isFunction(obj.options.errorFunction)){ obj.options.errorFunction();} }, onComplete: function(request) {}, onSuccess: function(request) { if (isFunction(obj.options.postFunction)) {obj.options.postFunction();} } }); this.isAutoRefreshSet = true; } else { // normal updater this.ajaxUpdater = new Ajax.Updater(this.options.target, this.url, { asynchronous: true, method: 'get', parameters: params, evalScripts: true, onFailure: function(request) { if (isFunction(obj.options.errorFunction)) {obj.options.errorFunction();} }, onComplete: function(request) { if (isFunction(obj.options.postFunction)) {obj.options.postFunction();} } }); } }, checkCookie: function() { // Check cookie for save state var cVal = getCookie("AjaxJspTag.Portlet."+this.options.source); if (cVal != null) { if (cVal == AJAX_PORTLET_MIN) { this.togglePortlet(); } else if (cVal == AJAX_PORTLET_CLOSE) { this.closePortlet(); } } }, stopAutoRefresh: function() { // stop auto-update if present if (this.ajaxPeriodicalUpdater != null && this.options.refreshPeriod && this.isAutoRefreshSet == true) { this.ajaxPeriodicalUpdater.stop(); } }, startAutoRefresh: function() { // stop auto-update if present if (this.ajaxPeriodicalUpdater != null && this.options.refreshPeriod) { this.ajaxPeriodicalUpdater.start(); } }, refreshPortlet: function(e) { // clear existing updater this.stopAutoRefresh(); if (this.ajaxPeriodicalUpdater != null) { this.startAutoRefresh(); } else { this.execute(); } }, closePortlet: function(e) { this.stopAutoRefresh(); Element.remove(this.options.source); // Save state in cookie if (this.preserveState) { setCookie("AjaxJspTag.Portlet."+this.options.source, AJAX_PORTLET_CLOSE, this.options.expireDate); } }, togglePortlet: function(e) { Element.toggle(this.options.target); if (this.options.isMaximized) { if (this.options.imageMaximize){ $(this.options.toggle).src = this.options.imageMaximize; } this.stopAutoRefresh(); } else { if (this.options.imageMinimize){ $(this.options.toggle).src = this.options.imageMinimize; } this.startAutoRefresh(); } this.options.isMaximized = !this.options.isMaximized; // Save state in cookie if (this.preserveState) { setCookie("AjaxJspTag.Portlet."+this.options.source, (this.options.isMaximized === true ? AJAX_PORTLET_MAX : AJAX_PORTLET_MIN), this.options.expireDate); } }});/** * AUTOCOMPLETE TAG */Ajax.XmlToHtmlAutocompleter = Class.create();Object.extend(Object.extend(Ajax.XmlToHtmlAutocompleter.prototype, Autocompleter.Base.prototype), { initialize: function(element, update, url, options) { this.baseInitialize(element, update, options); this.options.asynchronous = true; this.options.onComplete = this.onComplete.bind(this); this.options.defaultParams = this.options.parameters || null; this.url = url; }, // onblur hack IE works with FF onBlur: function (event) { // Dont hide the div on "blur" if the user clicks scrollbar if(Element.getStyle(this.update, 'height') != ''){ var x=999999; var y=999999; var offsets = Position.positionedOffset(this.update); var top = offsets[1]; var left = offsets[0]; var data = Element.getDimensions(this.update); var width = data.width; var height = data.height; if (event) { x=event.x-left; y=event.y -top; } if (x > 0 && x < width && y > 0 && y < height ) { this.element.focus(); return; } } // needed to make click events working setTimeout(this.hide.bind(this), 250); this.hasFocus = false; this.active = false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -