All Downloads are FREE. Search and download functionalities are using the official Maven repository.

template.js.struts2.jquery.struts2.min.js Maven / Gradle / Ivy

There is a newer version: 5.0.5
Show newest version
/*!
 * jquery.struts2.js
 *
 * Integration of jquery and jquery ui with struts 2
 * for ajax, widget and interactions support in struts 2
 *
 * Requires use of jQuery.
 * Tested with jQuery 1.10 and jQuery UI 1.10
 *
 * Copyright (c) 2008 Eric Chijioke (obinna a-t g mail dot c o m)
 * Copyright (c) 2012 Johannes Geppert http://www.jgeppert.com
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 */
(function(a,b){a.struts2_jquery={debug:false,debugPrefix:"[struts2_jquery] ",ajaxhistory:false,loadAtOnce:false,local:"en",gridLocal:"en",timeLocal:"en",minSuffix:".min",historyelements:{},forms:{},scriptCache:{},styleCache:{},defaults:{indicator:"",loadingText:null,errorText:null},handler:{load:"_s2j_container_load",form:"_s2j_form_submit",effect:"_s2j_effects"},currentXhr:{},log:function(c){if(this.debug){var d=this.debugPrefix+c;if(window.console&&window.console.log){window.console.log(d)}else{if(window.opera&&window.opera.postError){window.opera.postError(d)}}}},escId:function(c){return"#"+c.replace(/(:|\.)/g,"\\$1")},addParam:function(c,d){if(c.indexOf("?")>0){return c+"&"+d}else{return c+"?"+d}},changeParam:function(d,j,h){var f=d.split("?"),g=f[1].split("&"),c=[],e;for(e=0;e10){e=false;if(k.substring(0,2)==="/*"){l=a.parseJSON(k.substring(2,k.length-2))}else{l=a.parseJSON(k)}g.validateFunction(j,l)}}else{if(StrutsUtils!==b){StrutsUtils.clearValidationErrors(d[0]);if(k.substring(0,2)==="/*"){l=StrutsUtils.getValidationErrors(k)}else{l=StrutsUtils.getValidationErrors(a.parseJSON(k))}if(l.fieldErrors||l.errors){StrutsUtils.showValidationErrors(d[0],l);e=false}}}c.log("form validation : "+e)};d.ajaxSubmit(f);return e},addForms:function(d,e){var c=this;if(d){if(!c.loadAtOnce){c.require("js/plugins/jquery.form"+c.minSuffix+".js")}a.each(d.split(","),function(g,j){var h=a(c.escId(j)).formSerialize();e=c.addParam(e,h)})}return e},pubTops:function(e,c,f){var d=this;if(f){return function(g,i){var h={};h.event=g;h.ui=i;d.publishTopic(e,f,h);d.publishTopic(e,c,h)}}else{return null}},subscribeTopics:function(d,f,c,e){if(f&&d){a.each(f.split(","),function(h,g){if(d.isSubscribed(g)){d.destroyTopic(g)}d.subscribe(g,c,e)})}},publishTopic:function(d,f,e){var c=this;if(f){a.each(f.split(","),function(g,h){c.log("publish topic : "+h);d.publish(h,d,e)})}},pubSuc:function(l,f,j,d,k,e){var q=this,m=a(l),h,p,g=null,n=0,r=false;return function(s,c,i){var o={};o.data=s;o.status=c;o.request=i;if(k==="html"&&!a.isArray(s)&&!a.isPlainObject(s)){m.html(s)}else{if(k==="value"){m.val(a.trim(s))}else{if(k==="select"||k==="radio"||k==="checkbox"){if(k==="select"){m[0].length=0}else{m.children().remove()}if(typeof(s)==="object"||a.isArray(s)){h=-1;if(k==="select"){if(e.headerkey&&e.headervalue){g=a('");if(e.value===e.headervalue){g.prop("selected",true)}g.appendTo(m)}if(e.emptyoption){a("").appendTo(m)}}if(s[e.list]!==null){if(!a.isArray(s[e.list])){r=true}a.each(s[e.list],function(t,v){var u={};if(k==="radio"||k==="checkbox"){u.name=e.name}if(r){u.text=v;u.value=t}else{if(e.listkey!==b&&e.listvalue!==b){u.text=v[e.listvalue];u.value=v[e.listkey]}else{u.text=s[e.list][n];u.value=s[e.list][n]}}if(e.value!==b&&e.value==u.value){u.selected=true}if(k==="select"){g=a('");if(u.selected){g.prop("selected",true)}g.appendTo(m)}else{p=++h;if(k==="radio"){g=a('')}else{if(k==="checkbox"){g=a('')}}if(u.selected){g.prop("checked",true)}m.append(g);m.append(a('"))}n++})}}}}}if(j){q.publishTopic(m,j,o);q.publishTopic(m,f,o)}}},pubCom:function(h,f,k,g,d,e){var l=this,j=a.struts2_jquery_ui,i=a(h);return function(m,c){var n={};n.request=m;n.status=c;l.hideIndicator(d);l.publishTopic(i,k,n);l.publishTopic(i,f,n);if(!g){g=e.id}if(g){a.each(g.split(","),function(o,q){var p=a(l.escId(q));p.publish("_sj_div_effect_"+q+e.id,e)})}if(j&&e.resizable){j.resizable(i,e)}}},pubErr:function(j,d,i,h,f){var e=this,g=a(j);if(i||h){return function(l,c,k){var m={};m.request=l;m.status=c;m.error=k;if(f==="html"||f==="value"){if(h&&h!=="false"){g.html(h)}else{if(e.defaults.errorText!==null){g.html(e.defaults.errorText)}}}e.publishTopic(g,i,m);e.publishTopic(g,d,m)}}else{return null}},preBind:null,postBind:null,bind:function(f,g){var d=this,e,c;if(f){e=a(f);f=e[0];c=f.tagName.toLowerCase();g.tagname=c;if(typeof(d.preBind)!=="function"||d.preBind(e)){if(!g.jqueryaction){g.jqueryaction=c}d.log("bind "+g.jqueryaction+" on "+g.id);d[g.jqueryaction](e,g);if(d.postBind&&(typeof(d.postBind)==="function")){return d.postBind(f)}}}},jqueryaction:function(e,c){var d=this;if(e&&c){d[e]=c}},history:function(d,e,f){var c=this,g={};g.target=f;g.topic=e;d.bind("click",g,function(h){c.historyelements[h.data.target]=h.data.topic;c.lasttopic=e;a.bbq.pushState(c.historyelements);return false});a(window).bind("hashchange",g,function(i){var h=i.getState(i.data.target)||"";a.each(i.fragment.split("&"),function(k,l){var j=l.split("=");if(c.historyelements[j[0]]!==j[1]&&j[1]!==c.lasttopic){c.lasttopic=h;a.publish(j[1],i.data.options)}})})},action:function(e,j,i,h){var d=this,f="_sj_action_"+j.id,c=j.href,g={};j.actionTopic=f;if(c===null||c===""){c="#";j.href=c}g.effect=j.effect;g.effectoptions=j.effectoptions;g.effectmode=j.effectmode;g.oneffect=j.oneffect;g.effectduration=j.effectduration;if(j.datatype&&!j.targets){if(j.datatype==="json"){j.targets="false"}}if(j.targets){a.each(j.targets.split(","),function(k,l){g.targets=l;var m=a(d.escId(l));if(m.length===0){m=e}d.subscribeTopics(m,f+l,i,j);d.subscribeTopics(m,"_sj_div_effect_"+l+j.id,d.handler.effect,g);if(d.ajaxhistory){d.history(e,f+l,l)}})}else{g.targets=j.id;d.subscribeTopics(a(d.escId(j.id)),"_sj_div_effect_"+j.id+j.id,d.handler.effect,g);if(j.onbef||j.oncom||j.onsuc||j.onerr){d.subscribeTopics(e,f,i,j)}}if(h==="a"){e.click(function(){if(j.targets){a.each(j.targets.split(","),function(k,l){e.publish(f+l)})}if(j.preventAction){return false}})}},container:function(c,d){var j=this,g="_s2j_div_load_"+d.id,f="_s2j_div_effect_"+d.id,h=a.struts2_jquery_ui,k={},e=c,i="click";j.log("container : "+d.id);j.action(c,d,j.handler.load,"div");if((d.formids&&!d.type)||(d.href&&d.href!=="#")){if(d.href!=="#"){j.subscribeTopics(c,d.reloadtopics,j.handler.load,d);j.subscribeTopics(c,d.listentopics,j.handler.load,d);j.subscribeTopics(c,g,j.handler.load,d);if(d.bindon){if(d.events){a.each(d.events.split(","),function(l,m){a("#"+d.bindon).publishOnEvent(m,g,d)})}else{a("#"+d.bindon).publishOnEvent("click",g,d)}}}else{if(d.formids){if(!j.loadAtOnce){j.require("js/plugins/jquery.form"+j.minSuffix+".js")}d.targets=d.id;j.formsubmit(c,d,g)}}if(!d.deferredloading){if(d.delay){setTimeout(function(){c.publish(g,d)},d.delay)}else{c.publish(g,d)}}if(d.updatefreq){if(d.delay){setTimeout(function(){setInterval(function(){c.publish(g,d)},d.updatefreq)},d.delay)}else{setInterval(function(){c.publish(g,d)},d.updatefreq)}}}else{if(d.id&&d.effect){k.targets=d.id;k.effect=d.effect;k.effectoptions=d.effectoptions;k.effectduration=d.effectduration;j.subscribeTopics(c,f+d.id+d.id,j.handler.effect,k)}if(d.events||d.bindon){if(d.bindon){e=a(j.escId(d.bindon))}if(d.events){i=d.events}a.each(i.split(","),function(l,m){if(d.onbef){a.each(d.onbef.split(","),function(n,o){e.publishOnEvent(m,o)})}e.publishOnEvent(m,f+d.id+d.id,d);if(d.oncom){a.each(d.oncom.split(","),function(n,o){e.publishOnEvent(m,o)})}})}else{if(d.onbef){a.each(d.onbef.split(","),function(l,m){c.publish(m,d)})}c.publish(f+d.id+d.id,d);if(d.oncom){a.each(d.oncom.split(","),function(l,m){c.publish(m,d)})}}if(h&&d.resizable){h.resizable(c,d)}}if(h&&d.draggable){h.draggable(c,d)}if(h&&d.droppable){h.droppable(c,d)}if(h&&d.selectable){h.selectable(c,d)}if(h&&d.sortable){h.sortable(c,d)}if(d.onblurtopics){a.each(d.onblurtopics.split(","),function(m,l){c.blur(function(){j.publishTopic(c,l,{})})})}if(d.onfocustopics){a.each(d.onfocustopics.split(","),function(m,l){c.focus(function(){j.publishTopic(c,l,{})})})}if(d.oncha){if(d.type){if(d.type==="text"){c.keyup(function(){j.publishTopic(c,d.oncha,{})})}else{if(d.type==="select"){c.change(function(){j.publishTopic(c,d.oncha,{})});c.select(function(){j.publishTopic(c,d.onselecttopics,{})})}}}}},anchor:function(e,f){var d=this,c="_s2j_form_topic_"+f.id;d.log("anchor : "+f.id);if(f.onclick){a.each(f.onclick.split(","),function(h,g){e.publishOnEvent("click",g,f)})}if(f.opendialog){a.struts2_jquery_ui.opendialog(e,f)}if(f.button){a.struts2_jquery_ui.jquerybutton(e,f)}if((!f.href||f.href==="#")&&f.formids){d.formsubmit(e,f,c)}else{d.action(e,f,d.handler.load,"a");if(f.targets&&(f.reloadtopic||f.listentopics)){a.each(f.targets.split(","),function(h,g){var j=a(d.escId(g));d.subscribeTopics(j,f.reloadtopics,d.handler.load,f);d.subscribeTopics(j,f.listentopics,d.handler.load,f)})}}},select:function(e,f){var d=this,c="_s2j_topic_load_"+f.id;d.log("select : "+f.id);if(!d.loadAtOnce){d.require("js/plugins/jquery.form"+d.minSuffix+".js")}if(f.href&&f.href!=="#"){d.subscribeTopics(e,f.reloadtopics,d.handler.load,f);d.subscribeTopics(e,f.listentopics,d.handler.load,f);d.subscribeTopics(e,c,d.handler.load,f);if(!f.deferredloading){e.publish(c,f)}}if(f.oncha){a.each(f.oncha.split(","),function(g,h){e.publishOnEvent("change",h)})}if(f.autocomplete){if(!d.loadAtOnce){d.require(["js/base/jquery.ui.widget"+d.minSuffix+".js","js/base/jquery.ui.position"+d.minSuffix+".js","js/base/jquery.ui.menu"+d.minSuffix+".js","js/base/jquery.ui.button"+d.minSuffix+".js","js/base/jquery.ui.autocomplete"+d.minSuffix+".js"])}d.requireCss("themes/s2j-combobox.css");d.require(["js/plugins/jquery.combobox"+d.minSuffix+".js"]);e.combobox(f)}},button:function(e,j){var d=this,c="_s2j_form_topic_"+j.id,f,h,g,i;j.preventAction=true;if(j.opendialog){a.struts2_jquery_ui.opendialog(e,j)}if(j.button){a.struts2_jquery_ui.jquerybutton(e,j)}if((!j.href||j.href==="#")||j.formids!==b){d.formsubmit(e,j,c)}else{if(j.href&&j.href!=="#"){d.action(e,j,d.handler.load,"a");if(j.targets){a.each(j.targets.split(","),function(l,k){d.subscribeTopics(a(d.escId(k)),j.reloadtopics,d.handler.load,j);d.subscribeTopics(a(d.escId(k)),j.listentopics,d.handler.load,j)})}}else{f=e.parents("form:first")[0];if(f!==b){h=a(f);g=h.attr("id");if(g!==b){j.formids=g}else{i="s2jqform"+Math.floor(Math.random()*10000);h.attr("id",i);j.formids=i}d.formsubmit(e,j,c)}else{d.action(e,j,d.handler.load,"a");if(j.targets){a.each(j.targets.split(","),function(l,k){d.subscribeTopics(a(d.escId(k)),j.reloadtopics,d.handler.load,j);d.subscribeTopics(a(d.escId(k)),j.listentopics,d.handler.load,j)})}}}}if(j.onclick){a.each(j.onclick.split(","),function(l,k){e.publishOnEvent("click",k)})}e.removeAttr("name")},formsubmit:function(d,g,e){var c=this,f={};g.actionTopic=e;c.log("formsubmit : "+g.id);if(!c.loadAtOnce){c.require("js/plugins/jquery.form"+c.minSuffix+".js")}if(g.targets){c.subscribeTopics(d,g.reloadtopics,c.handler.form,g);c.subscribeTopics(d,g.listentopics,c.handler.form,g);c.subscribeTopics(d,e,c.handler.form,g);a.each(g.targets.split(","),function(h,j){c.subscribeTopics(a(c.escId(j)),"_sj_div_effect_"+j+g.id,c.handler.effect,g);if(c.ajaxhistory){c.history(d,e,j)}});a.each(g.formids.split(","),function(h,j){a(c.escId(j)).bind("submit",function(i){i.preventDefault()})});d.click(function(){d.publish(e);return false})}else{d.click(function(j){var h=a(c.escId(g.formids)),i={};i.formvalidate=true;j.preventDefault();if(g.validate){i.formvalidate=c.validateForm(h,g);if(g.onaftervalidation){a.each(g.onaftervalidation.split(","),function(l,k){d.publish(k,d,i)})}}if(i.formvalidate){h.submit()}return false});if(g.listentopics){f.formids=g.formids;f.validate=g.validate;d.subscribe(g.listentopics,function(i){var h=a(c.escId(i.data.formids)),j={formvalidate:true};if(i.data.validate){j.formvalidate=c.validateForm(h,g);if(g.onaftervalidation){a.each(g.onaftervalidation.split(","),function(l,k){d.publish(k,d,j)})}}if(j.formvalidate){h.submit()}},f)}}}};a.subscribeHandler(a.struts2_jquery.handler.load,function(c,i){var m=a.struts2_jquery,d=a(c.target),k,f={},l=false,e,h,j="html",g={};if(i){a.extend(f,i)}if(c.data){a.extend(f,c.data)}m.lasttopic=f.actionTopic;e=f.indicatorid;h=f.onalw;l=f.disabled===null?l:f.disabled;l=d.prop("disabled");if(c.originalEvent){l=a(c.originalEvent.currentTarget).prop("disabled")}if(l!==true){if(f){m.showIndicator(e);if(f.type){if(f.type==="text"){j="value"}else{if(f.type==="select"){j="select"}else{if(f.type==="checkbox"){j="checkbox"}else{if(f.type==="radio"){j="radio"}}}}}if(j==="html"||j==="value"){if(!f.datatype||f.datatype!=="json"){if(f.loadingtext&&f.loadingtext!=="false"){if(j==="html"){d.html(f.loadingtext)}else{d.val(f.loadingtext)}}else{if(m.defaults.loadingText!==null){if(j==="html"){d.html(m.defaults.loadingText)}else{d.val(m.defaults.loadingText)}}}}}g.success=m.pubSuc(c.target,h,f.onsuc,e,j,f);g.complete=m.pubCom(c.target,h,f.oncom,f.targets,e,f);g.error=m.pubErr(c.target,h,f.onerr,f.errortext,j);if(f.href){g.url=f.href;g.data="";if(f.hrefparameter){g.data=f.hrefparameter}if(f.requesttype){g.type=f.requesttype}else{g.type="POST"}if(f.formids){if(!m.loadAtOnce){m.require("js/plugins/jquery.form"+m.minSuffix+".js")}a.each(f.formids.split(","),function(n,p){var o=a(m.escId(p)).formSerialize();if(g.data!==""){g.data=g.data+"&"+o}else{g.data=o}})}if(f.datatype){g.dataType=f.datatype}else{g.dataType="html"}if(!g.data){g.data={}}f.options=g;f.options.submit=true;m.publishTopic(d,h,f);m.publishTopic(d,f.onbef,f);if(f.options.submit){k=d.attr("id");m.abortReq(d.attr("id"));m.currentXhr[k]=a.ajax(g)}}}}});a.subscribeHandler(a.struts2_jquery.handler.form,function(f,g){var e=a.struts2_jquery,d=a(f.target),i={},h={},j,c;if(g){a.extend(i,g)}if(f.data){a.extend(i,f.data)}e.lasttopic=i.actionTopic;j=i.indicatorid;c=i.onalw;if(i.href&&i.href!=="#"){h.url=i.href;if(i.hrefparameter){h.url=h.url+"?"+i.hrefparameter}}if(i.clearform){h.clearForm=true}if(i.iframe){h.iframe=true}if(i.resetform){h.resetForm=true}if(i.replaceTarget){h.replaceTarget=true}if(i.timeout){h.timeout=parseInt(i.timeout,10)}if(i.datatype){h.dataType=i.datatype}else{h.dataType=null}h.target="";if(i.targets){a.each(i.targets.split(","),function(k,l){d=a(e.escId(l));if(h.target===""){h.target=e.escId(l)}else{h.target=h.target+",#"+e.escId(l)}})}h.beforeSubmit=function(n,l,k){var m={};m.formData=n;m.form=l;m.options=k;m.options.submit=true;e.publishTopic(d,c,m);if(i.onbef){a.each(i.onbef.split(","),function(p,o){d.publish(o,d,m)})}if(i.validate){m.options.submit=e.validateForm(l,i);m.formvalidate=m.options.submit;if(i.onaftervalidation){a.each(i.onaftervalidation.split(","),function(p,o){d.publish(o,d,m)})}}if(m.options.submit){e.showIndicator(j);if(!i.datatype||i.datatype!=="json"){if(i.loadingtext&&i.loadingtext!=="false"){a.each(i.targets.split(","),function(o,p){a(e.escId(p)).html(i.loadingtext)})}else{if(e.defaults.loadingText!==null){a.each(i.targets.split(","),function(o,p){a(e.escId(p)).html(e.defaults.loadingText)})}}}}return m.options.submit};h.success=e.pubSuc(d,c,i.onsuc,j,"form",i);h.complete=e.pubCom(d,c,i.oncom,i.targets,j,i);h.error=e.pubErr(d,c,i.onerr,i.errortext,"html");a.each(i.formids.split(","),function(k,l){e.log("submit form : "+l);a(e.escId(l)).ajaxSubmit(h)});return false});a.subscribeHandler(a.struts2_jquery.handler.effect,function(f,g){var e=a.struts2_jquery,i={},d={},h=2000,j=null,c=null;a.extend(i,f.data);if(i.targets&&i.effect){if(i.effectoptions){d=i.effectoptions}if(i.effectduration){h=i.effectduration}if(i.oneffect){a.each(i.targets.split(","),function(k,l){a.subscribe(a(e.escId(l)),i.oneffect,i)});j=function(){a.each(i.targets.split(","),function(k,l){e.publishTopic(a(e.escId(l)),i.oneffect,i)})}}if(!e.loadAtOnce){e.require(["js/base/jquery.ui.effect"+e.minSuffix+".js","js/base/jquery.ui.effect-"+i.effect+e.minSuffix+".js"])}e.log("effect "+i.effect+" for "+i.targets);a.each(i.targets.split(","),function(k,l){c=a(e.escId(l));if(!i.effectmode||i.effectmode==="none"){c.effect(i.effect,d,h,j)}else{if(i.effectmode==="show"){c.show(i.effect,d,h,j)}else{if(i.effectmode==="hide"){c.hide(i.effect,d,h,j)}else{if(i.effectmode==="toggle"){c.toggle(i.effect,d,h,j)}}}}})}})})(jQuery);




© 2015 - 2024 Weber Informatics LLC | Privacy Policy