📄 ajaxtags_tags.js
字号:
execute : function(e) { if (Object.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("(\\{" + AJAX_DEFAULT_PARAMETER + "\\})", '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 : this.getMethod(), evalScripts :true, parameters :params, onSuccess : function(request) { // IE 5,6 BUG objx = {}; objx.responseXML = request.responseXML; obj.options.parser.load(Object.extend(objx, { collapsedClass :obj.options.collapsedClass, treeClass :obj.options.treeClass, nodeClass :obj.options.nodeClass })); obj.handler(objx, { target :obj.options.target, parser :obj.options.parser, eventType :obj.options.eventType, url :obj.url }); }, onFailure : function(request) { if (Object.isFunction(obj.options.errorFunction)) { obj.options.errorFunction(); } }, onComplete : function(request) { if (Object.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) { var parser = this.options.parser; var target = $(this.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++) { images[i]["on" + this.options.eventType ] = this.toggleTreeNode.bind(this,images[i].id.substring(5)); } // toggle the one that must be expanded var expandedNodes = parser.expandedNodes; for ( var i = 0; i < expandedNodes.length; i++) { this.toggleTreeNode(expandedNodes[i]); } }, toggleTreeNode:function (xid) { var opt = Object.clone(this.options); opt["target"] = xid; new AjaxJspTag.Tree(opt); }});/** * TABPANEL TAG */AjaxJspTag.TabPanel = Class.create(AjaxJspTag.Base, { initialize : function( options) { this.panel = $(options.id); this.panel.className = "tabPanel"; this.content = document.createElement('div'); this.content.className = "tabContent"; // clsName var ul = document.createElement("ul"); ul.innerHTML = ''; // this.tabs = tabs; // alle dabs als array ! müssen angelegt werden! var obj = this; var f = null; options.pages.each( function(tab) { var li = document.createElement('li'); var a = document.createElement('a'); a.appendChild(document.createTextNode(tab.caption)); a.baseUrl = tab.baseUrl; a.parameters = tab.parameters || ''; li.appendChild(a); a.onclick = function() { obj.url = a.baseUrl; obj.options.parameters = a.parameters; obj.source = a; obj.execute(); }; a.href = "javascript:///nop"; if (f === null && tab.defaultTab) { f = a.onclick.bind(a); } ul.appendChild(li); }); this.panel.innerHTML = ''; // clear first! var nav = document.createElement('div'); nav.className = "tabNavigation"; nav.appendChild(ul); this.panel.appendChild(nav); this.panel.appendChild(this.content); this.setOptions(options); if (f !== null) { f(); } }, setOptions : function(options) { this.options = Object.extend( { parameters :options.parameters || '', eventType :options.eventType ? options.eventType : "click", parser :options.parser ? options.parser : new DefaultResponseParser("html"), }, options || {}); }, execute : function() { if (Object.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 new Ajax.Updater(this.content, this.url, { asynchronous :true, method : this.getMethod(), evalScripts :true, parameters :params, onSuccess :obj.handler.bind(obj), onFailure :obj.options.onFailure, onComplete :obj.options.onComplete });},handler : function() { // find current anchor var cur = this.panel.select(".ajaxCurrentTab"); // remove class if (cur.length > 0) cur[0].className = ''; // add class to selected tab this.source.className = "ajaxCurrentTab";}});/** * PORTLET TAG */AjaxJspTag.Portlet = Class.create(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? }, 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 :parseBoolean(options.executeOnLoad), refreshPeriod :options.refreshPeriod || null, eventType :options.eventType ? options.eventType : "click", parser :options.parser ? options.parser : new DefaultResponseParser("html"), }, 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) { $(this.options.close)["on" + this.options.eventType] = this.closePortlet.bindAsEventListener(this); } if (this.options.imageRefresh) { $(this.options.refresh)["on" + this.options.eventType] = this.refreshPortlet.bindAsEventListener(this); } if (this.options.imageMaximize && this.options.imageMinimize) { $(this.options.toggle)["on" + this.options.eventType] = this.togglePortlet.bindAsEventListener(this); } }, execute : function(e) { if (Object.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 : this.getMethod(), evalScripts :true, parameters :params, frequency :freq, onFailure : function(request) { if (Object.isFunction(obj.options.errorFunction)) { obj.options.errorFunction(); } }, onComplete : function(request) { }, onSuccess : function(request) { if (Object.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 : this.getMethod(), parameters :params, evalScripts :true, onFailure : function(request) { if (Object.isFunction(obj.options.errorFunction)) { obj.options.errorFunction(); } }, onComplete : function(request) { if (Object.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 */AjaxJspTag.XmlToHtmlAutocompleter = Class .create( Autocompleter.Base, { // AjaxJspTag.Autocomplete 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; // just 4 don't write a copy this.getUpdatedChoices0 = Ajax.Autocompleter.prototype.getUpdatedChoices; this.onBlur0 = Autocompleter.Base.prototype.onBlur; }, // 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; } } // call base this.onBlur0(); }, getUpdatedChoices : function() { if (Object.isFunction(this.options.preFunction)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -