From e131e5bb05d2a1c41afda3a4dd78f598659966b8 Mon Sep 17 00:00:00 2001 From: rumd3x Date: Sat, 2 Feb 2019 20:36:55 -0200 Subject: [PATCH] updated minified version Signed-off-by: rumd3x --- beth.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beth.min.js b/beth.min.js index 404c0af..8d88a19 100644 --- a/beth.min.js +++ b/beth.min.js @@ -1 +1 @@ -$(document,window,void 0).ready(function(){Beth._refreshInterval=70,Beth._init()});class Beth{constructor(){this._init()}static _init(){Beth._initialized=!1,Beth.loops={},Beth._initDynamicHtml(),Beth._bindDirectives(),Beth._initInputValues(),Beth._bindVariables(),Beth._initialized=!0}static _initDynamicHtml(){Beth.binds=[];var e=document.documentElement.innerHTML,t=e,a=e.match(/\{\{.*\}\}/g);null==a&&(a=[]);for(var i=0,r=a.length;i'+Beth._unescapeReal(n)+"")):$('[beth-bind="'+s+'"][beth-default]').length>0?(Beth._declareVar(s,$('[beth-bind="'+s+'"][beth-default]').first().attr("beth-default")),Beth.binds.push(s),t=e.replace(h,''+Beth._unescapeReal($('[beth-bind="'+s+'"][beth-default]').first().attr("beth-default"))+"")):t=e.replace(h,""),e=t}document.documentElement.innerHTML=t}static _bindVariables(){$("textarea[beth-bind], input[beth-bind][type!='radio'][type!='checkbox'], select[beth-bind]").each(function(){var bethvar_name=$(this).attr("beth-bind");if(Beth._isVarDefined(bethvar_name))try{var bethvar_value=eval(bethvar_name);bethvar_value!=$(this).val()&&(eval(bethvar_name+" = $(this).val()"),Beth._triggerEvent($(this),"change"))}catch(e){console.warn("Beth: Variable not defined",e)}}),$("input[beth-bind][type='radio']").each(function(){var bethvar_name=$(this).attr("beth-bind");if($(this).is(":checked")&&Beth._isVarDefined(bethvar_name))try{var bethvar_value=eval(bethvar_name);bethvar_value!=$(this).val()&&(eval(bethvar_name+" = $(this).val()"),Beth._triggerEvent($(this),"change"))}catch(e){console.warn("Beth: Variable not defined",e)}}),$("input[beth-bind][type='checkbox']").each(function(){var bethvar_name=$(this).attr("beth-bind");if(Beth._isVarDefined(bethvar_name))try{var bethvar_value=eval(bethvar_name);bethvar_value!=$(this).is(":checked")&&(eval(bethvar_name+" = $(this).is(':checked')"),Beth._triggerEvent($(this),"change"))}catch(e){console.warn("Beth: Variable not defined",e)}}),$("beth").each(function(){try{var newHtml=eval(Beth.binds[parseInt($(this).data("bind"))])}catch(e){var newHtml=""}$(this).html()!=newHtml&&$(this).html(Beth._unescapeReal(newHtml))}),setTimeout(function(){Beth._bindVariables()},Beth._refreshInterval)}static _initInputValues(){$("textarea[beth-default]:not([beth-bind]), input[beth-default]:not([beth-bind]), select[beth-default]:not([beth-bind])").each(function(){try{var bethvar_name=$(this).val(eval($(this).attr("beth-default")))}catch(e){var bethvar_name=$(this).val($(this).attr("beth-default"))}}),$("textarea[beth-bind], input[beth-bind][type!='radio'][type!='checkbox'], select[beth-bind]").each(function(){try{var bethvar_name=$(this).attr("beth-bind");Beth._declareVar(bethvar_name,$(this).attr("beth-default")),$(this).val(Beth._unescapeReal(eval($(this).attr("beth-bind"))))}catch(e){$(this).removeAttr("beth-bind"),console.warn("Beth: Variable not defined",e)}}),$("input[beth-bind][type='radio']").each(function(){try{var bethvar_name=$(this).attr("beth-bind");Beth._declareVar(bethvar_name,$(this).attr("beth-default")),$(this).prop("checked",Beth._unescapeReal(eval($(this).attr("beth-bind")))==$(this).val())}catch(e){$(this).removeAttr("beth-bind"),console.warn("Beth: Variable not defined",e)}}),$("input[beth-bind][type='checkbox']").each(function(){try{var bethvar_name=$(this).attr("beth-bind");Beth._declareVar(bethvar_name,$(this).attr("beth-default")),$(this).prop("checked",!!eval($(this).attr("beth-bind")))}catch(e){$(this).removeAttr("beth-bind"),console.warn("Beth: Variable not defined",e)}}),$("beth-include, beth-include-async").each(function(){try{var e=$(this),t=e.attr("url"),a="beth-include-async"===e.prop("tagName");$.get({async:a,url:t,error:function(e,t,a){console.warn("Beth: Error downloading include data: Server responded with status code ["+e.status+"] "+e.statusText)},success:function(t,a,i){e.replaceWith(i.responseText)}})}catch(e){$(this).removeAttr("beth-bind"),console.warn("Beth: Error downloading include data",e)}})}static _bindDirectives(){$("[beth-hide]").each(function(){try{var hide=eval($(this).attr("beth-hide"));1==hide?$(this).hide():$(this).show()}catch(e){$(this).removeAttr("beth-hide"),console.warn("Beth: Invalid expression inside 'Hide' directive",e)}}),$("[beth-disable]").each(function(){try{var disable=eval($(this).attr("beth-disable"));1==disable?$(this).prop("disabled",!0):$(this).prop("disabled",!1)}catch(e){$(this).removeAttr("beth-disable"),console.warn("Beth: Invalid expression inside 'Disable' directive",e)}}),$("[beth-if]").each(function(){try{var result=eval($(this).attr("beth-if"));1!=result&&$(this).remove()}catch(e){console.warn("Beth: Invalid expression inside 'If' directive",e)}$(this).removeAttr("beth-if")}),$("[beth-click]").each(function(){$(this).off("click"),$(this).on("click",function(){Beth._triggerEvent($(this),"click")})}),$("[beth-inside]").each(function(){let e="";try{e=Beth._parseValue($(this).attr("beth-inside"))}catch(e){console.warn("Beth: Invalid expression inside 'Inside' directive",e)}$(this).text()!==e&&$(this).text(e)}),$("[beth-html-inside]").each(function(){let e="";try{e=Beth._parseValue($(this).attr("beth-html-inside"))}catch(e){console.warn("Beth: Invalid expression inside 'Html-inside' directive",e)}$(this).html()!==e&&$(this).html(e)}),$("[beth-class]").each(function(){try{var added_classes=$(this).attr("beth-added-classes"),new_classes=eval($(this).attr("beth-class"));added_classes!==new_classes&&($(this).removeClass(added_classes),$(this).addClass(new_classes),$(this).attr("beth-added-classes",new_classes))}catch(e){console.warn("Beth: Invalid expression inside 'Class' directive",e)}}),$("[beth-each]").each(function(){var newLoop=!1;if(void 0===$(this).attr("beth-id")){do{var uniqueId=Beth._makeId()}while($("[beth-id="+uniqueId+"]").length>0);$(this).attr("beth-id",uniqueId);var newLoop=!0}try{var uniqueId=$(this).attr("beth-id"),expression=$(this).attr("beth-each"),exploded=expression.split("=>"),loopVarName=exploded[1].trim(),source=eval(exploded[0].trim()),match=!1;if(newLoop?Beth.loops[uniqueId]=jQuery.extend(!0,[],source):JSON.stringify(Beth.loops[uniqueId])===JSON.stringify(source)?match=!0:Beth.loops[uniqueId]=jQuery.extend(!0,[],source),!match){"BETH-IT"!=$(this).parent().prop("tagName")&&$(this).wrap(""),$("[beth-loop-id='"+uniqueId+"']").remove();for(let index=0;index-1)var varname_arr=varname.split("."),prop=varname_arr.pop(),obj=varname_arr.join("."),realObj=eval(obj);else var prop=varname,realObj=window;realObj.watch(prop,function(e,t,a){realObj.unwatch(e),$("[beth-bind='"+varname+"']").each(function(){"radio"==$(this).prop("type")?$(this).prop("checked",a==$(this).val()):"checkbox"==$(this).prop("type")?$(this).prop("checked",a):$(this).val(Beth._unescapeReal(a)).change()}),realObj[prop]!=a&&(realObj[prop]=a),setTimeout(function(){Beth._watchVar(varname)},Beth._refreshInterval)})}static _triggerEvent(selector,event){var callback=selector.attr("beth-"+event);if(void 0!==callback&&Beth._initialized)try{eval(callback)}catch(e){console.error("Beth: Invalid Statement",e)}}static _unescapeReal(e){for(var t=e;t!==unescape(t);)t=unescape(t);return t}static _declareVar(varname,varvalue=null){if(Beth._watchVar(varname),Beth._isVarDefined(varname))return!1;varvalue=Beth._parseValue(varvalue);try{return eval("window."+varname+'="'+escape(varvalue)+'";'),"null"!=eval("window."+varname)&&"undefined"!=eval("window."+varname)||eval("window."+varname+'="";'),!0}catch(e){return!1}}static _isVarDefined(varname){var valid=!0;try{if(valid=eval("typeof "+varname+" !== 'undefined'"),valid){var varvalue=eval(varname);valid=void 0!==varvalue||-1==Beth.binds.indexOf(varname)}}catch(e){valid=!1}return valid}static _parseValue(varvalue){if(void 0!==varvalue)try{varvalue=eval(varvalue)}catch(e){varvalue=String(varvalue)}else varvalue="";return varvalue}static _extractTextBetween(e,t,a){var i=e;try{return e.split(t)[1].split(a)[0]}catch(e){return i}}}Object.prototype.watch||Object.defineProperty(Object.prototype,"watch",{enumerable:!1,configurable:!0,writable:!1,value:function(e,t){var a=this[e],i=a;delete this[e]&&Object.defineProperty(this,e,{get:function(){return i},set:function(r){return a=i,i=t.call(this,e,a,r)},enumerable:!0,configurable:!0})}}),Object.prototype.unwatch||Object.defineProperty(Object.prototype,"unwatch",{enumerable:!1,configurable:!0,writable:!1,value:function(e){var t=this[e];delete this[e],this[e]=t}}); \ No newline at end of file +$(document,window,void 0).ready(function(){Beth._refreshInterval=70,Beth._init()});class Beth{constructor(){this._init()}static _init(){Beth._initialized=!1,Beth.loops={},Beth._initDynamicHtml(),Beth._bindDirectives(),Beth._initInputValues(),Beth._bindVariables(),Beth._initialized=!0}static _initDynamicHtml(){Beth.binds=[];var e=document.documentElement.innerHTML,t=e,a=e.match(/\{\{.*\}\}/g);null==a&&(a=[]);for(var i=0,r=a.length;i'+Beth._unescapeReal(n)+"")):$('[beth-bind="'+s+'"][beth-default]').length>0?(Beth._declareVar(s,$('[beth-bind="'+s+'"][beth-default]').first().attr("beth-default")),Beth.binds.push(s),t=e.replace(h,''+Beth._unescapeReal($('[beth-bind="'+s+'"][beth-default]').first().attr("beth-default"))+"")):t=e.replace(h,""),e=t}document.documentElement.innerHTML=t}static _bindVariables(){$("textarea[beth-bind], input[beth-bind][type!='radio'][type!='checkbox'], select[beth-bind]").each(function(){var bethvar_name=$(this).attr("beth-bind");if(Beth._isVarDefined(bethvar_name))try{var bethvar_value=eval(bethvar_name);bethvar_value!=$(this).val()&&(eval(bethvar_name+" = $(this).val()"),Beth._triggerEvent($(this),"change"))}catch(e){console.warn("Beth: Variable not defined",e)}}),$("input[beth-bind][type='radio']").each(function(){var bethvar_name=$(this).attr("beth-bind");if($(this).is(":checked")&&Beth._isVarDefined(bethvar_name))try{var bethvar_value=eval(bethvar_name);bethvar_value!=$(this).val()&&(eval(bethvar_name+" = $(this).val()"),Beth._triggerEvent($(this),"change"))}catch(e){console.warn("Beth: Variable not defined",e)}}),$("input[beth-bind][type='checkbox']").each(function(){var bethvar_name=$(this).attr("beth-bind");if(Beth._isVarDefined(bethvar_name))try{var bethvar_value=eval(bethvar_name);bethvar_value!=$(this).is(":checked")&&(eval(bethvar_name+" = $(this).is(':checked')"),Beth._triggerEvent($(this),"change"))}catch(e){console.warn("Beth: Variable not defined",e)}}),$("beth").each(function(){try{var newHtml=eval(Beth.binds[parseInt($(this).data("bind"))])}catch(e){var newHtml=""}$(this).html()!=newHtml&&$(this).html(Beth._unescapeReal(newHtml))}),setTimeout(function(){Beth._bindVariables()},Beth._refreshInterval)}static _initInputValues(){$("textarea[beth-default]:not([beth-bind]), input[beth-default]:not([beth-bind]), select[beth-default]:not([beth-bind])").each(function(){try{var bethvar_name=$(this).val(eval($(this).attr("beth-default")))}catch(e){var bethvar_name=$(this).val($(this).attr("beth-default"))}}),$("textarea[beth-bind], input[beth-bind][type!='radio'][type!='checkbox'], select[beth-bind]").each(function(){try{var bethvar_name=$(this).attr("beth-bind");Beth._declareVar(bethvar_name,$(this).attr("beth-default")),$(this).val(Beth._unescapeReal(eval($(this).attr("beth-bind"))))}catch(e){$(this).removeAttr("beth-bind"),console.warn("Beth: Variable not defined",e)}}),$("input[beth-bind][type='radio']").each(function(){try{var bethvar_name=$(this).attr("beth-bind");Beth._declareVar(bethvar_name,$(this).attr("beth-default")),$(this).prop("checked",Beth._unescapeReal(eval($(this).attr("beth-bind")))==$(this).val())}catch(e){$(this).removeAttr("beth-bind"),console.warn("Beth: Variable not defined",e)}}),$("input[beth-bind][type='checkbox']").each(function(){try{var bethvar_name=$(this).attr("beth-bind");Beth._declareVar(bethvar_name,$(this).attr("beth-default")),$(this).prop("checked",!!eval($(this).attr("beth-bind")))}catch(e){$(this).removeAttr("beth-bind"),console.warn("Beth: Variable not defined",e)}}),$("beth-include, beth-include-async").each(function(){try{var e=$(this),t=e.attr("url"),a="beth-include-async"===e.prop("tagName");$.get({async:a,url:t,error:function(e,t,a){console.warn("Beth: Error downloading include data: Server responded with status code ["+e.status+"] "+e.statusText)},success:function(t,a,i){e.replaceWith(i.responseText)}})}catch(e){$(this).removeAttr("beth-bind"),console.warn("Beth: Error downloading include data",e)}})}static _bindDirectives(){$("[beth-hide]").each(function(){try{var hide=eval($(this).attr("beth-hide"));1==hide?$(this).hide():$(this).show()}catch(e){$(this).removeAttr("beth-hide"),console.warn("Beth: Invalid expression inside 'Hide' directive",e)}}),$("[beth-show]").each(function(){try{var show=eval($(this).attr("beth-show"));1==show?$(this).show():$(this).hide()}catch(e){$(this).removeAttr("beth-show"),console.warn("Beth: Invalid expression inside 'Show' directive",e)}}),$("[beth-disable]").each(function(){try{var disable=eval($(this).attr("beth-disable"));1==disable?$(this).prop("disabled",!0):$(this).prop("disabled",!1)}catch(e){$(this).removeAttr("beth-disable"),console.warn("Beth: Invalid expression inside 'Disable' directive",e)}}),$("[beth-if]").each(function(){try{var result=eval($(this).attr("beth-if"));1!=result&&$(this).remove()}catch(e){console.warn("Beth: Invalid expression inside 'If' directive",e)}$(this).removeAttr("beth-if")}),$("[beth-click]").each(function(){$(this).off("click"),$(this).on("click",function(){Beth._triggerEvent($(this),"click")})}),$("[beth-inside]").each(function(){let e="";try{e=Beth._parseValue($(this).attr("beth-inside"))}catch(e){console.warn("Beth: Invalid expression inside 'Inside' directive",e)}$(this).text()!==e&&$(this).text(e)}),$("[beth-html-inside]").each(function(){let e="";try{e=Beth._parseValue($(this).attr("beth-html-inside"))}catch(e){console.warn("Beth: Invalid expression inside 'Html-inside' directive",e)}$(this).html()!==e&&$(this).html(e)}),$("[beth-class]").each(function(){try{var added_classes=$(this).attr("beth-added-classes"),new_classes=eval($(this).attr("beth-class"));added_classes!==new_classes&&($(this).removeClass(added_classes),$(this).addClass(new_classes),$(this).attr("beth-added-classes",new_classes))}catch(e){console.warn("Beth: Invalid expression inside 'Class' directive",e)}}),$("[beth-each]").each(function(){var newLoop=!1;if(void 0===$(this).attr("beth-id")){do{var uniqueId=Beth._makeId()}while($("[beth-id="+uniqueId+"]").length>0);$(this).attr("beth-id",uniqueId);var newLoop=!0}try{var uniqueId=$(this).attr("beth-id"),expression=$(this).attr("beth-each"),exploded=expression.split("=>"),loopVarName=exploded[1].trim(),source=eval(exploded[0].trim()),match=!1;if(newLoop?Beth.loops[uniqueId]=jQuery.extend(!0,[],source):JSON.stringify(Beth.loops[uniqueId])===JSON.stringify(source)?match=!0:Beth.loops[uniqueId]=jQuery.extend(!0,[],source),!match){"BETH-IT"!=$(this).parent().prop("tagName")&&$(this).wrap(""),$("[beth-loop-id='"+uniqueId+"']").remove(),void 0===source&&(source=[]),0===source.length&&($(this).parent().hide(),console.log("hey"));for(let index=0;index-1)var varname_arr=varname.split("."),prop=varname_arr.pop(),obj=varname_arr.join("."),realObj=eval(obj);else var prop=varname,realObj=window;realObj.watch(prop,function(e,t,a){realObj.unwatch(e),$("[beth-bind='"+varname+"']").each(function(){"radio"==$(this).prop("type")?$(this).prop("checked",a==$(this).val()):"checkbox"==$(this).prop("type")?$(this).prop("checked",a):$(this).val(Beth._unescapeReal(a)).change()}),realObj[prop]!=a&&(realObj[prop]=a),setTimeout(function(){Beth._watchVar(varname)},Beth._refreshInterval)})}static _triggerEvent(selector,event){var callback=selector.attr("beth-"+event);if(void 0!==callback&&Beth._initialized)try{eval(callback)}catch(e){console.error("Beth: Invalid Statement",e)}}static _unescapeReal(e){for(var t=e;t!==unescape(t);)t=unescape(t);return t}static _declareVar(varname,varvalue=null){if(Beth._watchVar(varname),Beth._isVarDefined(varname))return!1;varvalue=Beth._parseValue(varvalue);try{return eval("window."+varname+'="'+escape(varvalue)+'";'),"null"!=eval("window."+varname)&&"undefined"!=eval("window."+varname)||eval("window."+varname+'="";'),!0}catch(e){return!1}}static _isVarDefined(varname){var valid=!0;try{if(valid=eval("typeof "+varname+" !== 'undefined'"),valid){var varvalue=eval(varname);valid=void 0!==varvalue||-1==Beth.binds.indexOf(varname)}}catch(e){valid=!1}return valid}static _parseValue(varvalue){if(void 0!==varvalue)try{varvalue=eval(varvalue)}catch(e){varvalue=String(varvalue)}else varvalue="";return varvalue}static _extractTextBetween(e,t,a){var i=e;try{return e.split(t)[1].split(a)[0]}catch(e){return i}}}Object.prototype.watch||Object.defineProperty(Object.prototype,"watch",{enumerable:!1,configurable:!0,writable:!1,value:function(e,t){var a=this[e],i=a;delete this[e]&&Object.defineProperty(this,e,{get:function(){return i},set:function(r){return a=i,i=t.call(this,e,a,r)},enumerable:!0,configurable:!0})}}),Object.prototype.unwatch||Object.defineProperty(Object.prototype,"unwatch",{enumerable:!1,configurable:!0,writable:!1,value:function(e){var t=this[e];delete this[e],this[e]=t}});