Return "undefined" for any "false" value
authorThierry Florac <tflorac@ulthar.net>
Fri, 29 Jan 2021 13:26:38 +0100
changeset 42 97e0aed85883
parent 41 708805889fe2
child 43 84a34175f37c
Return "undefined" for any "false" value
src/myams/resources/js/myams-core.js
src/myams/resources/js/myams-core.min.js
--- a/src/myams/resources/js/myams-core.js	Wed Jan 27 16:10:36 2021 +0100
+++ b/src/myams/resources/js/myams-core.js	Fri Jan 29 13:26:38 2021 +0100
@@ -319,12 +319,12 @@
 	 * Get an object given by name
 	 */
 	MyAMS.getObject = function (objectName, context) {
+		if (typeof(objectName) !== 'string') {
+			return objectName;
+		}
 		if (!objectName) {
 			return undefined;
 		}
-		if (typeof(objectName) !== 'string') {
-			return objectName;
-		}
 		var namespaces = objectName.split(".");
 		context = (context === undefined || context === null) ? window : context;
 		for (var i = 0; i < namespaces.length; i++) {
@@ -342,10 +342,11 @@
 	 * Small piece of code by Jason Bunting
 	 */
 	MyAMS.getFunctionByName = function (functionName, context) {
-		if (functionName === undefined) {
+		if (typeof(functionName) === 'function') {
+			return functionName;
+		}
+		if (!functionName) {
 			return undefined;
-		} else if (typeof(functionName) === 'function') {
-			return functionName;
 		}
 		var namespaces = functionName.split(".");
 		var func = namespaces.pop();
--- a/src/myams/resources/js/myams-core.min.js	Wed Jan 27 16:10:36 2021 +0100
+++ b/src/myams/resources/js/myams-core.min.js	Fri Jan 29 13:26:38 2021 +0100
@@ -1,1 +1,1 @@
-"use strict";!function(t,e){var n=e.console;String.prototype.startsWith=function(t){var e=this.length,n=t.length;return!(e<n)&&this.substr(0,n)===t},String.prototype.endsWith=function(t){var e=this.length,n=t.length;return!(e<n)&&this.substr(e-n)===t},String.prototype.unserialize=function(t){for(var e=decodeURIComponent(this).split("&"),n={},r=0;r<e.length;r++){var a=e[r].split("=",2);n[a[0]]=a[1]}return n},Array.prototype.indexOf||(Array.prototype.indexOf=function(t,e){var n=this.length;for((e=(e=Number(e)||0)<0?Math.ceil(e):Math.floor(e))<0&&(e+=n);e<n;e++)if(e in this&&this[e]===t)return e;return-1}),t.expr[":"].hasvalue=function(e,n,r){return""!==t(e).val()},t.expr[":"].econtains=function(e,n,r){return(e.textContent||e.innerText||t(e).text()||"").toLowerCase()===r[3].toLowerCase()},t.expr[":"].withtext=function(e,n,r){return(e.textContent||e.innerText||t(e).text()||"")===r[3]},t.expr[":"].parents=function(e,n,r){return t(e).parents(r[3]).length>0},void 0===t.scrollbarWidth&&(t.scrollbarWidth=function(){var e=t('<div style="width: 50px; height: 50px; overflow: auto"><div/></div>').appendTo("body"),n=e.children(),r=n.innerWidth()-n.height(99).innerWidth();return e.remove(),r}),t.fn.extend({exists:function(){return t(this).length>0},objectOrParentWithClass:function(t){return this.hasClass(t)?this:this.parents("."+t)},listattr:function(e){var n=[];return this.each((function(){n.push(t(this).attr(e))})),n},style:function(t,e,n){if(void 0!==this.get(0)){var r=this.get(0).style;return void 0!==t?void 0!==e?(n=void 0!==n?n:"",r.setProperty(t,e,n),this):r.getPropertyValue(t):r}},removeClassPrefix:function(e){return this.each((function(n,r){var a=r.className.split(" ").map((function(t){return t.startsWith(e)?"":t}));r.className=t.trim(a.join(" "))})),this}}),void 0===e.MyAMS&&(e.MyAMS={devmode:!0,devext:"",lang:"en",throttleDelay:350,menuSpeed:235,navbarHeight:49,ajaxNav:!0,safeMethods:["GET","HEAD","OPTIONS","TRACE"],csrfCookieName:"csrf_token",csrfHeaderName:"X-CSRF-Token",enableWidgets:!0,enableMobile:!1,enableFastclick:!1,warnOnFormChange:!1,formChangedCallback:null,ismobile:/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase())});var r,a=e.MyAMS,i=a;a.baseURL=(r=t('script[src*="/myams.js"], script[src*="/myams.min.js"], script[src*="/myams-core.js"], script[src*="/myams-core.min.js"], script[src*="/myams-require.js"], script[src*="/myams-require.min.js"]').attr("src"),i.devmode=r.indexOf(".min.js")<0,i.devext=i.devmode?"":".min",r.substring(0,r.lastIndexOf("/")+1)),a.log=function(){n&&n.debug&&n.debug(this,arguments)},a.getQueryVar=function(t,e){if(t.indexOf("?")<0)return!1;t.endsWith("&")||(t+="&");var n=new RegExp(".*?[&\\?]"+e+"=(.*?)&.*"),r=t.replace(n,"$1");return r!==t&&r},a.rgb2hex=function(e){return"#"+t.map(e.match(/\b(\d+)\b/g),(function(t){return("0"+parseInt(t).toString(16)).slice(-2)})).join("")},a.generateId=function(){function t(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return t()+t()+t()+t()},a.generateUUID=function(){var t=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var n=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"===e?n:3&n|8).toString(16)}))},a.getObject=function(t,e){if(t){if("string"!=typeof t)return t;var n=t.split(".");e=null==e?window:e;for(var r=0;r<n.length;r++)try{e=e[n[r]]}catch(t){return}return e}},a.getFunctionByName=function(t,e){if(void 0!==t){if("function"==typeof t)return t;var n=t.split("."),r=n.pop();e=null==e?window:e;for(var a=0;a<n.length;a++)try{e=e[n[a]]}catch(t){return}try{return e[r]}catch(t){return}}},a.executeFunctionByName=function(t,e){var n=i.getFunctionByName(t,window);if("function"==typeof n){var r=Array.prototype.slice.call(arguments,2);return n.apply(e,r)}},a.isInDOM=function(n){return!!(n=t(n)).exists()&&e.document.body.contains(n[0])},a.getSource=function(t){return t.replace(/{[^{}]*}/g,(function(t){return i.getFunctionByName(t.substr(1,t.length-2))}))},a.getScript=function(e,n,r,a){"object"==typeof n&&(a=r,r=n,n=null),void 0===r&&(r={});var s={dataType:"script",url:i.getSource(e),success:n,error:a||i.error.show,cache:!i.devmode,async:void 0===r.async?"function"==typeof n:r.async},o=t.extend({},s,r);return t.ajax(o)},a.getCSS=function(e,n,r,a){r&&(r=i.getFunctionByName(r));var s=t("HEAD"),o=t('style[data-ams-id="'+n+'"]',s);if(0===o.length){if(o=t("<style>").attr("data-ams-id",n).text('@import "'+i.getSource(e)+'";'),r)var c=setInterval((function(){try{o[0].sheet.cssRules;clearInterval(c),r.call(window,!0,a)}catch(t){}}),10);o.appendTo(s)}else r&&r.call(window,!1,a)},a.initHandlers=function(e){t(e).on("click","[data-ams-click-handler]",(function(e){var n=t(this),r=n.data("ams-disabled-handlers");if(!0!==r&&"click"!==r&&"all"!==r){var a=n.data();if(a.amsClickHandler){!0!==a.amsStopPropagation&&!0!==a.amsClickStopPropagation||e.stopPropagation(),!0!==a.amsClickKeepDefault&&e.preventDefault();for(var s=a.amsClickHandler.split(/\s+/),o=0;o<s.length;o++){var c=i.getFunctionByName(s[o]);void 0!==c&&c.call(n,e,a.amsClickHandlerOptions)}}}})),t(e).on("change","[data-ams-change-handler]",(function(e){var n=t(this);if(!n.prop("readonly")){var r=n.data("ams-disabled-handlers");if(!0!==r&&"change"!==r&&"all"!==r){var a=n.data();if(a.amsChangeHandler){!0!==a.amsStopPropagation&&!0!==a.amsChangeStopPropagation||e.stopPropagation(),!0!==a.amsChangeKeepDefault&&e.preventDefault();for(var s=a.amsChangeHandler.split(/\s+/),o=0;o<s.length;o++){var c=i.getFunctionByName(s[o]);void 0!==c&&c.call(n,e,a.amsChangeHandlerOptions)}}}}})),t(e).on("reset","form",(function(e){var n=t(this);setTimeout((function(){t(".alert-danger, SPAN.state-error",n).not(".persistent").remove(),t("LABEL.state-error",n).removeClass("state-error"),t('INPUT.select2[type="hidden"]',n).each((function(){var e=t(this),n=e.data("select2"),r=e.data("ams-select2-input-value");r&&e.select2("val",r.split(n.opts.separator))})),n.find(".select2").trigger("change"),t("[data-ams-reset-callback]",n).each((function(){var e=t(this),r=e.data(),a=i.getFunctionByName(r.amsResetCallback);void 0!==a&&a.call(n,e,r.amsResetCallbackOptions)}))}),10),i.form&&i.form.setFocus(n)})),t(e).on("reset","[data-ams-reset-handler]",(function(e){var n=t(this),r=n.data();if(r.amsResetHandler){!0!==r.amsResetKeepDefault&&e.preventDefault();var a=i.getFunctionByName(r.amsResetHandler);void 0!==a&&a.call(n,r.amsResetHandlerOptions)}})),t(e).on("click","[data-ams-click-event]",(function(e){var n=t(this);t(e.target).trigger(n.data("ams-click-event"),n.data("ams-click-event-options"))})),t(e).on("click",'input[type="checkbox"][readonly]',(function(){return!1}))}}(jQuery,this);
+"use strict";!function(t,e){var n=e.console;String.prototype.startsWith=function(t){var e=this.length,n=t.length;return!(e<n)&&this.substr(0,n)===t},String.prototype.endsWith=function(t){var e=this.length,n=t.length;return!(e<n)&&this.substr(e-n)===t},String.prototype.unserialize=function(t){for(var e=decodeURIComponent(this).split("&"),n={},r=0;r<e.length;r++){var a=e[r].split("=",2);n[a[0]]=a[1]}return n},Array.prototype.indexOf||(Array.prototype.indexOf=function(t,e){var n=this.length;for((e=(e=Number(e)||0)<0?Math.ceil(e):Math.floor(e))<0&&(e+=n);e<n;e++)if(e in this&&this[e]===t)return e;return-1}),t.expr[":"].hasvalue=function(e,n,r){return""!==t(e).val()},t.expr[":"].econtains=function(e,n,r){return(e.textContent||e.innerText||t(e).text()||"").toLowerCase()===r[3].toLowerCase()},t.expr[":"].withtext=function(e,n,r){return(e.textContent||e.innerText||t(e).text()||"")===r[3]},t.expr[":"].parents=function(e,n,r){return t(e).parents(r[3]).length>0},void 0===t.scrollbarWidth&&(t.scrollbarWidth=function(){var e=t('<div style="width: 50px; height: 50px; overflow: auto"><div/></div>').appendTo("body"),n=e.children(),r=n.innerWidth()-n.height(99).innerWidth();return e.remove(),r}),t.fn.extend({exists:function(){return t(this).length>0},objectOrParentWithClass:function(t){return this.hasClass(t)?this:this.parents("."+t)},listattr:function(e){var n=[];return this.each((function(){n.push(t(this).attr(e))})),n},style:function(t,e,n){if(void 0!==this.get(0)){var r=this.get(0).style;return void 0!==t?void 0!==e?(n=void 0!==n?n:"",r.setProperty(t,e,n),this):r.getPropertyValue(t):r}},removeClassPrefix:function(e){return this.each((function(n,r){var a=r.className.split(" ").map((function(t){return t.startsWith(e)?"":t}));r.className=t.trim(a.join(" "))})),this}}),void 0===e.MyAMS&&(e.MyAMS={devmode:!0,devext:"",lang:"en",throttleDelay:350,menuSpeed:235,navbarHeight:49,ajaxNav:!0,safeMethods:["GET","HEAD","OPTIONS","TRACE"],csrfCookieName:"csrf_token",csrfHeaderName:"X-CSRF-Token",enableWidgets:!0,enableMobile:!1,enableFastclick:!1,warnOnFormChange:!1,formChangedCallback:null,ismobile:/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase())});var r,a=e.MyAMS,i=a;a.baseURL=(r=t('script[src*="/myams.js"], script[src*="/myams.min.js"], script[src*="/myams-core.js"], script[src*="/myams-core.min.js"], script[src*="/myams-require.js"], script[src*="/myams-require.min.js"]').attr("src"),i.devmode=r.indexOf(".min.js")<0,i.devext=i.devmode?"":".min",r.substring(0,r.lastIndexOf("/")+1)),a.log=function(){n&&n.debug&&n.debug(this,arguments)},a.getQueryVar=function(t,e){if(t.indexOf("?")<0)return!1;t.endsWith("&")||(t+="&");var n=new RegExp(".*?[&\\?]"+e+"=(.*?)&.*"),r=t.replace(n,"$1");return r!==t&&r},a.rgb2hex=function(e){return"#"+t.map(e.match(/\b(\d+)\b/g),(function(t){return("0"+parseInt(t).toString(16)).slice(-2)})).join("")},a.generateId=function(){function t(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return t()+t()+t()+t()},a.generateUUID=function(){var t=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var n=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"===e?n:3&n|8).toString(16)}))},a.getObject=function(t,e){if("string"!=typeof t)return t;if(t){var n=t.split(".");e=null==e?window:e;for(var r=0;r<n.length;r++)try{e=e[n[r]]}catch(t){return}return e}},a.getFunctionByName=function(t,e){if("function"==typeof t)return t;if(t){var n=t.split("."),r=n.pop();e=null==e?window:e;for(var a=0;a<n.length;a++)try{e=e[n[a]]}catch(t){return}try{return e[r]}catch(t){return}}},a.executeFunctionByName=function(t,e){var n=i.getFunctionByName(t,window);if("function"==typeof n){var r=Array.prototype.slice.call(arguments,2);return n.apply(e,r)}},a.isInDOM=function(n){return!!(n=t(n)).exists()&&e.document.body.contains(n[0])},a.getSource=function(t){return t.replace(/{[^{}]*}/g,(function(t){return i.getFunctionByName(t.substr(1,t.length-2))}))},a.getScript=function(e,n,r,a){"object"==typeof n&&(a=r,r=n,n=null),void 0===r&&(r={});var s={dataType:"script",url:i.getSource(e),success:n,error:a||i.error.show,cache:!i.devmode,async:void 0===r.async?"function"==typeof n:r.async},o=t.extend({},s,r);return t.ajax(o)},a.getCSS=function(e,n,r,a){r&&(r=i.getFunctionByName(r));var s=t("HEAD"),o=t('style[data-ams-id="'+n+'"]',s);if(0===o.length){if(o=t("<style>").attr("data-ams-id",n).text('@import "'+i.getSource(e)+'";'),r)var c=setInterval((function(){try{o[0].sheet.cssRules;clearInterval(c),r.call(window,!0,a)}catch(t){}}),10);o.appendTo(s)}else r&&r.call(window,!1,a)},a.initHandlers=function(e){t(e).on("click","[data-ams-click-handler]",(function(e){var n=t(this),r=n.data("ams-disabled-handlers");if(!0!==r&&"click"!==r&&"all"!==r){var a=n.data();if(a.amsClickHandler){!0!==a.amsStopPropagation&&!0!==a.amsClickStopPropagation||e.stopPropagation(),!0!==a.amsClickKeepDefault&&e.preventDefault();for(var s=a.amsClickHandler.split(/\s+/),o=0;o<s.length;o++){var c=i.getFunctionByName(s[o]);void 0!==c&&c.call(n,e,a.amsClickHandlerOptions)}}}})),t(e).on("change","[data-ams-change-handler]",(function(e){var n=t(this);if(!n.prop("readonly")){var r=n.data("ams-disabled-handlers");if(!0!==r&&"change"!==r&&"all"!==r){var a=n.data();if(a.amsChangeHandler){!0!==a.amsStopPropagation&&!0!==a.amsChangeStopPropagation||e.stopPropagation(),!0!==a.amsChangeKeepDefault&&e.preventDefault();for(var s=a.amsChangeHandler.split(/\s+/),o=0;o<s.length;o++){var c=i.getFunctionByName(s[o]);void 0!==c&&c.call(n,e,a.amsChangeHandlerOptions)}}}}})),t(e).on("reset","form",(function(e){var n=t(this);setTimeout((function(){t(".alert-danger, SPAN.state-error",n).not(".persistent").remove(),t("LABEL.state-error",n).removeClass("state-error"),t('INPUT.select2[type="hidden"]',n).each((function(){var e=t(this),n=e.data("select2"),r=e.data("ams-select2-input-value");r&&e.select2("val",r.split(n.opts.separator))})),n.find(".select2").trigger("change"),t("[data-ams-reset-callback]",n).each((function(){var e=t(this),r=e.data(),a=i.getFunctionByName(r.amsResetCallback);void 0!==a&&a.call(n,e,r.amsResetCallbackOptions)}))}),10),i.form&&i.form.setFocus(n)})),t(e).on("reset","[data-ams-reset-handler]",(function(e){var n=t(this),r=n.data();if(r.amsResetHandler){!0!==r.amsResetKeepDefault&&e.preventDefault();var a=i.getFunctionByName(r.amsResetHandler);void 0!==a&&a.call(n,r.amsResetHandlerOptions)}})),t(e).on("click","[data-ams-click-event]",(function(e){var n=t(this);t(e.target).trigger(n.data("ams-click-event"),n.data("ams-click-event-options"))})),t(e).on("click",'input[type="checkbox"][readonly]',(function(){return!1}))}}(jQuery,this);