This repository has been archived by the owner on Aug 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathangular-twig-pack.js
21 lines (21 loc) · 9.41 KB
/
angular-twig-pack.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
angular.module("twig.config",[]).value("twig.config",{macroCache:null,lowercase:function(a){return isString(a)?a.toLowerCase():a},toBoolean:function(a){a&&0!==a.length?(a=angular.isString(a)?(""+a).toLowerCase():a,a=!("f"==a||"0"==a||"false"==a||"no"==a||"n"==a||"[]"==a)):a=!1;return a},random:function(a){return angular.isArray(a)||angular.isString(a)?a[Math.floor(Math.random()*a.length)]:angular.isNumber(a)?Math.floor(Math.random()*a):Math.floor(1E9*Math.random())},divisibleby:function(a,b){return angular.isNumber(a)&&
angular.isNumber(b)&&Math.floor(a/b)===a/b},even:function(a){return 0===a%2},odd:function(a){return 0!==a%2}});angular.module("twig.filters",["twig.config"]);angular.module("twig.directives",["twig.config"]).factory("twig",["twig.config",function(a){this.random=a.random;this.divisibleby=a.divisibleby;this.even=a.even;this.odd=a.odd;return this}]);angular.module("twig",["twig.filters","twig.directives","twig.config"]);
angular.isUndefined(Array.range)&&(Array.range=function(a,b,c){var e=[];if("number"===typeof a){e[0]=a;for(c=c||1;a+c<=b;)e[e.length]=a+=c}else c="abcdefghijklmnopqrstuvwxyz",a===a.toUpperCase()&&(b=b.toUpperCase(),c=c.toUpperCase()),c=c.substring(c.indexOf(a),c.indexOf(b)+1),e=c.split("");return e});String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});angular.module("twig.filters").filter("format",function(){return function(a,b){if(!a)return a;var c=a.toString(),e;if(void 0===b)return c;if(!angular.isArray(b)&&!angular.isObject(b))return c.split("$0").join(b);e=angular.isArray(b)&&"$"||":";angular.forEach(b,function(a,b){c=c.split(e+b).join(a)});return c}});angular.module("twig.filters").filter("url_encode",function(){return function(a){return!a?a:encodeURIComponent(a.toString())}});
angular.module("twig.filters").filter("json_decode",function(){return function(a){return!a?a:angular.fromJson(a.toString())}});angular.module("twig.filters").filter("title",function(){return function(a){return!a?a:a.toString().replace(/\w\S*/g,function(a){return a.charAt(0).toUpperCase()+a.substr(1).toLowerCase()})}});angular.module("twig.filters").filter("divisibleby",["twig.config",function(a){return function(b,c){return!b?b:a.divisibleby(b,c)}}]);
angular.module("twig.filters").filter("odd",["twig.config",function(a){return function(b){return!b?b:a.odd(b)}}]);angular.module("twig.filters").filter("even",["twig.config",function(a){return function(b){return!b?b:a.even(b)}}]);angular.module("twig.filters").filter("capitalize",function(){return function(a){if(!a)return a;a=a.toString().toLowerCase();return a.charAt(0).toUpperCase()+a.slice(1)}});angular.module("twig.filters").filter("upper",function(){return function(a){return!a?a:target=a.toString().toUpperCase()}});
angular.module("twig.filters").filter("lower",function(){return function(a){return!a?a:target=a.toString().toLowerCase()}});angular.module("twig.filters").filter("striptags",function(){return function(a,b){if(!a)return a;b=(((b||"")+"").toLowerCase().match(/<[a-z][a-z0-9]*>/g)||[]).join("");return a.replace(/\x3c!--[\s\S]*?--\x3e|<\?(?:php)?[\s\S]*?\?>/gi,"").replace(/<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,function(a,e){return-1<b.indexOf("<"+e.toLowerCase()+">")?a:""})}});
angular.module("twig.filters").filter("join",function(){return function(a,b){return!a||!angular.isArray(a)?a:a.join(b||"")}});angular.module("twig.filters").filter("reverse",function(){return function(a){return!a?a:angular.isString(a)?a.split("").reverse().join(""):angular.isArray(a)?angular.copy(a).reverse():a}});angular.module("twig.filters").filter("length",function(){return function(a){return!a?0:angular.isString(a)?a.split("").length:angular.isArray(a)?a.length:0}});
angular.module("twig.filters").filter("sort",function(){return function(a){return!a||!angular.isArray(a)?a:angular.copy(a).sort()}});angular.module("twig.filters").filter("merge",function(){return function(a,b){if(!a||!b)return a;var c=angular.copy(a),e=angular.copy(b);return angular.isArray(a)&&angular.isArray(b)?c.concat(e):angular.isObject(a)&&angular.isObject(b)?angular.extend({},c,e):a}});
angular.module("twig.filters").filter("default",function(){return function(a,b){return!b?a:!a||""===a||null===a?b:a}});angular.module("twig.filters").filter("keys",function(){return function(a){if(!a||!angular.isArray(a)&&!angular.isObject(a))return[];a=angular.copy(a);var b=[],c;for(c in a)b.push(c);return b}});
angular.module("twig.filters").filter("escape",function(){return function(a,b){if(!a||!angular.isString(a))return a;angular.isUndefined(b)&&(b="html");switch(b){case "html":return a.replace(/[&<>"'`]/g,function(a){return"&#"+a.charCodeAt(0)+";"});case "js":return a.replace(/([\\"'])/g,"\\$1").replace(/\0/g,"\\0");case "url":return encodeURIComponent(a)}}});angular.module("twig.filters").filter("abs",function(){return function(a){return!a||!angular.isNumber(a)?a:Math.abs(a)}});
angular.module("twig.filters").filter("nl2br",function(){return function(a){return!a||!angular.isString(a)?a:a.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,"$1<br />$2")}});
angular.module("twig.filters").filter("number_format",function(){return function(a,b,c,e){if(!a)return a;a=(a+"").replace(/[^0-9+\-Ee.]/g,"");a=!isFinite(+a)?0:+a;b=!isFinite(+b)?0:Math.abs(b);e=angular.isUndefined(e)?",":e;c=angular.isUndefined(c)?".":c;var d="",d=function(a,b){var c=Math.pow(10,b);return""+Math.round(a*c)/c},d=(b?d(a,b):""+Math.round(a)).split(".");3<d[0].length&&(d[0]=d[0].replace(/\B(?=(?:\d{3})+(?!\d))/g,e));if((d[1]||"").length<b)d[1]=d[1]||"",d[1]+=Array(b-d[1].length+1).join("0");
return d.join(c)}});angular.module("twig.filters").filter("slice",function(){return function(a,b,c){if(!angular.isString(a)&&!angular.isArray(a)||!angular.isNumber(b))return a;angular.isNumber(c)||(c=0);return a.slice(b,b+c)}});angular.module("twig.filters").filter("trim",function(){return function(a,b){if(!a)return a;var c=a.trim();return angular.isDefined(b)&&angular.isString(b)?c.replace(b,""):c}});angular.module("twig.directives").directive("for",["$compile","twig.config",function(a,b){return{scope:!0,restrict:"A",link:function(c,e,d){var g=/([\w-'|]*)\.\.([\w-'|]*)/,f="",h=angular.isDefined(d.forElse)?d.forElse:"No data",k=e.clone().removeAttr("for").removeAttr("for-else"),f=/(.*)\s*in\s*(.*)/.exec(d["for"]);if(null===f)throw Error("For attr no valid "+d["for"]);var l=f[1].trim(),j=/(.*) if (.*)/.exec(f[2]);d=null;j?(d=g.exec(j[1]),f[2]=j[2]):d=g.exec(f[2]);var m=function(d){c.items=[];angular.forEach(d,
function(a){c[l]=a;var d=j?angular.isUndefined(c.$eval(j[2]))?eval(j[2]):c.$eval(j[2]):"";j&&!1===b.toBoolean(d)||c.items.push(a)});angular.isUndefined(c.items)||angular.isArray(c.items)&&0===c.items.length?e.replaceWith(a(k.html(h))(c)):(k.attr("ng-repeat",l+" in items"),e.replaceWith(a(k)(c)))};if(d){g=angular.isUndefined(c.$eval(d[1]))?d[1]:c.$eval(d[1]);f=angular.isUndefined(c.$eval(d[2]))?d[2]:c.$eval(d[2]);if(angular.isNumber(g)&&angular.isNumber(f)){if(g>f)throw Error("First number have to be lower than second number ("+
g+" <= "+f);}else if(angular.isString(g)&&angular.isString(f)){if(1!==g.length||1!==f.length)throw Error("First and second parameters have to be char and not string ("+g+", "+f);}else throw Error("Undefined values ("+g+", "+f);m(angular.copy(Array.range(g,f)))}else{var n=j?j[1]:f[2];c.$watch(n,function(a){m(angular.copy(a))});c.$watch(n+".length",function(a){0!==a&&m(angular.copy(c.$eval(n)))})}}}}]);
angular.module("twig.directives").directive("if",["twig.config",function(a){return{scope:!0,restrict:"A",link:function(b,c,e){e=angular.isDefined(e["if"])?e["if"]:null;var d=c.clone().removeAttr("if"),g=d.find("else").first(),f=d.find("elseif"),h=[],k=function(a,b){return{cdt:a,html:b}};d.find("elseif, else").remove();h.push(k(e,d.html()));f.each(function(){var a=$(this),b=a.attr("on");h.push(k(b,a.html()))});h.push(k("_else_",g.html()));var l=function(){var d=!1;angular.forEach(h,function(c){if(!1===
d&&("_else_"===c.cdt||a.toBoolean(b.$eval(c.cdt))))d=c.html});!1!==d&&c.html(d)};angular.forEach(h,function(a){b.$watch(a.cdt,l)})}}}]);
angular.module("twig.directives").directive("macroGet",["twig.config","$compile",function(a,b){return{scope:!0,restrict:"E",link:function(c,e,d){var g=angular.isDefined(d.name)?d.name:null,f=angular.isDefined(d.param)?d.param.split(","):null;if(!angular.isString(g)||!angular.isArray(f)||0===f.length)throw Error('The given expression is not valid "'+g+'" - "'+f+'". SYNTAX: macro name="nameMacro" param="\'param1\',\'param2\',paramFromScope".');angular.forEach(f,function(a,b){-1<a.indexOf("'")?f[b]=
a.replace("'",""):angular.isDefined(c[a])&&(f[b]=c.$eval(a))});d=a.macroCache.get(g);var h=c.$new();if(angular.isUndefined(d))return e.html(""),!1;angular.forEach(d.param,function(a,b){angular.isDefined(f[b])&&(h[a]=f[b])});e.replaceWith(b(d.html)(h))}}}]);
angular.module("twig.directives").directive("macroSet",["twig.config","$cacheFactory",function(a,b){return{scope:!0,restrict:"E",terminal:!0,compile:function(){return{pre:function(c,e,d){c=angular.isDefined(d.name)?d.name:null;d=angular.isDefined(d.param)?d.param.split(","):null;if(!angular.isString(c)||!angular.isArray(d)||0===d.length)throw Error('The given expression is not valid "'+c+'" - "'+d+'". SYNTAX: macro-set name="MacroName" param="paramName1,paramName2". ');if(angular.isUndefined(a.macroCache)||
null===a.macroCache)a.macroCache=b("twigMacros");var g=e.clone().removeAttr("macro-set");angular.isDefined(a.macroCache.get(c))&&console.error('The given macro name already exist! "'+c+'"');a.macroCache.put(c,{param:d,html:g.html()});e.css("display","none")}}}}}]);