game/js/jquery.smarty.js
2022-06-07 00:30:34 +03:00

1 line
16 KiB
JavaScript

(function($){if(typeof $.log==="undefined"){if(typeof window.console!=="undefined"&&typeof window.console.log==="function"){$.console={};$.console.log=$.log=function(){var arr=[];for(var i=0;i<arguments.length;i++){arr.push(arguments[i])}window.console.log.apply(window.console,arr)};if(typeof window.console.debug!=="undefined"){$.console.debug=function(){var arr=[];for(var i=0;i<arguments.length;i++){arr.push(arguments[i])}window.console.debug.apply(window.console,arr)}}else{$.console.debug=function(){var arr=[];for(var i=0;i<arguments.length;i++){arr.push(arguments[i])}window.console.log.apply(window.console,arr)}}if(typeof window.console.warn!=="undefined"){$.console.warn=function(){var arr=[];for(var i=0;i<arguments.length;i++){arr.push(arguments[i])}window.console.warn.apply(window.console,arr)}}else{$.console.warn=function(){var arr=[];for(var i=0;i<arguments.length;i++){arr.push(arguments[i])}window.console.log.apply(window.console,arr)}}if(typeof window.console.error!=="undefined"){$.console.error=function(){var arr=["An error has occured:"];for(var i=0;i<arguments.length;i++){arr.push(arguments[i])}window.console.error.apply(window.console,arr);$.console.trace()}}else{$.console.error=function(){var args=arguments;var arr=["An error has occured:"];for(var i=0;i<arguments.length;i++){arr.push(arguments[i])}window.console.log.apply(window.console,arr);$.console.trace()}}if(typeof window.console.trace!=="undefined"){$.console.trace=function(){window.console.trace()}}else{$.console.trace=function(){window.console.log.apply(window.console,["Attempted trace... but window.console.trace does not exist."])}}}else{$.console={};$.log=$.console.log=$.console.debug=$.console.warn=$.console.trace=function(){};$.console.error=function(){alert("An error has occured. Please use another browser to obtain more detailed information.")}}}$.SmartyClass=function(){this.construct()};String.prototype.populate=$.fn.populate=function(options){$.Smarty=$.Smarty||new $.SmartyClass();options=$.extend({data:null},options);var result;if(typeof this.substring!=="undefined"){result=$.Smarty.populate(this)}else{$.each($(this),function(){var $this=$(this);return $this.html($.Smarty.populate($(this).html()))});result=this}return result};$.extend($.SmartyClass.prototype,{data:{build:"0.5.0-dev (June 29, 2010)"},config:{},templates:{},onchange_funcs:{},auto_updates:{_length:0},modifier_helper:{},section:{},foreach:{},cycle:{},template_url:"templates/",search:{tags:/\{((?:"[^"\\]*(?:\\.[^"\\]*)*"|'[^'\\]*(?:\\.[^'\\]*)*'|[^\s'"}]+)*)\s*((?:(?:"[^"\\]*(?:\\.[^"\\]*)*"|'[^'\\]*(?:\\.[^'\\]*)*'|[^\s'"}]+)\s*)*)\}(?:(.+?)\{\/\1\})?/,tags_g:/\{((?:"[^"\\]*(?:\\.[^"\\]*)*"|'[^'\\]*(?:\\.[^'\\]*)*'|[^\s'"}]+)*)\s*((?:(?:"[^"\\]*(?:\\.[^"\\]*)*"|'[^'\\]*(?:\\.[^'\\]*)*'|[^\s'"}]+)\s*)*)\}(?:(.+?)\{\/\1\})?/g,attributes:/(?:[\s]*(?:([^=\s]+?)=)?((?:"[^"\\]*(?:\\.[^"\\]*)*"|'[^'\\]*(?:\\.[^'\\]*)*'|[^\s'"]+)+))+?/,attributes_g:/(?:[\s]*(?:([^=\s]+?)=)?((?:"[^"\\]*(?:\\.[^"\\]*)*"|'[^'\\]*(?:\\.[^'\\]*)*'|[^\s'"]+)+))+?/g,modifiers:/(?:([|:])("[^"\\]*(?:\\.[^"\\]*)*"|'[^'\\]*(?:\\.[^'\\]*)*'|[^|:]+)?)+?/,modifiers_g:/(?:([|:])("[^"\\]*(?:\\.[^"\\]*)*"|'[^'\\]*(?:\\.[^'\\]*)*'|[^|:]+)?)+?/g},operators:{eq:"==",ne:"!=",neq:"!=",gt:">",lt:"<",ge:">=",gte:">=",le:"<=",lte:"<=",and:"&&",or:"||",mod:"%","==":"==","===":"===","!=":"!=",">":">","<":"<",">=":">=","<=":"<=","!":"!","%":"%","(":"(",")":")","0":0,"false":false,"null":null,"undefined":null},modifiers:{auto_update:function(value,id,el,css_class){++$.Smarty.auto_updates._length;el=(typeof el==="undefined")?"span":el;css_class=css_class?' class="'+css_class+'"':"";var j;if(!el||(id&&id.match(/[^a-zA-Z0-9_]/g))){j=html_entity_decode(id);id=el=css_class=null}else{id=id||"jqsmarty__auto_update__"+$.Smarty.auto_updates._length;j="#"+id}var helper=$.extend({},$.Smarty.modifier_helper);if(helper["var"].charAt(0)!=="$"){$.Smarty.debug("jqsmarty: ERROR: auto_update does not apply for: ",helper);return value}var v=helper["var"];var s=helper.source;for(var i=1,n=helper.modifiers.length;i<n;i++){var c=helper.modifiers[i];if(c.value==="auto_update"){s=s.replace(c.source,"");break}}$.Smarty.onchange(v,function(){$.Smarty.debug("jquery: auto_update:",[v,j]);var new_value=$.Smarty.value(s);$(j).html(new_value)});var result=el?"<"+el+' id="'+id+'" '+css_class+">"+value+"</"+el+">":"";return result},capitalize:function(value){var result=ucwords(value);return result},cat:function(value,cat){return value+""+cat},count_characters:function(value,include_spaces){if(include_spaces){return value.length}return value.match(/[^\s]/g).length},count_paragraphs:function(value){return value.match(/[\r\n]+/g).length},count_sentences:function(value){return value.match(/[^\s]\.(?!\w)/g).length},count_words:function(value){return value.match(/[a-zA-Z0-9\\x80-\\xff]+/g).length},date_format:function(value,format,default_date){if(!value&&!default_date){return"!CHECK THE SYNTAX FOR [date_format]!"}var t=(value||default_date);if(typeof t!=="number"){t=strtotime(t,time())}var result=strftime((format||"%b %e %Y"),t);return result},"default":function(value,default_value){return value||default_value},fsize_format:function(size,format,precision){format=format||"";precision=precision||2;var sizes={TB:1099511627776,GB:1073741824,MB:1048576,KB:1024,B:1};var result="";$.each(sizes,function(unit,bytes){if(size>bytes||unit==strtoupper(format)){result=number_format(size/bytes,precision)+" "+unit;return false}});return result}},functions:{"*":function(content,attribute){return content.populate()},assign:function(content,attributes){if(typeof attributes["var"]==="undefined"||typeof attributes.value==="undefined"){return"!CHECK THE SYNTAX FOR [assign]!"}var value=attributes.value;if(value==="[]"){value={}}else{}var key=attributes["var"];$.Smarty.assign(key,value);return content.populate()},capture:function(content,attributes){return content.populate()},cycle:function(content,attributes){var name=attributes.name||"default";var values=attributes.values;var print=attributes.print||true;var advance=attributes.advance||true;var delimiter=attributes.delimiter||",";var assign=attributes.assign||null;var reset=attributes.reset||false;if(assign&&typeof attributes.print==="undefined"){print=false}if(typeof values==="string"){try{values=values.split(eval("/"+delimiter+"/g"))}catch(e){$.console.error(493,e)}}var data;if(typeof $.Smarty.cycle[name]==="undefined"||$.Smarty.cycle[name].values.toString()!==values.toString()){data={values:values,index:-1,length:values.length}}else{data=$.Smarty.cycle[name];if(reset){data.index=-1}}if(advance){++data.index;if(data.index>=data.length){data.index=0}}var current=data.values[data.index];if(assign){$.Smarty.assign(assign,current)}$.Smarty.cycle[name]=data;var result=print?current:"";return result},debug:function(content,attributes){var output=attributes.output;$.Smarty.debug("Smarty Debug: ",output);return""},"if":function(content,attributes){var statements="";var values=[];var attribute,statement,is,left,middle,right;var reset=function(){statement="";is=false;left="";middle="";right="== 0"};var add=function(){statement=is?"("+statement+left+") "+middle+right:statement;statements+=statement};reset();for(i in attributes){if($.Smarty.skip(i)){continue}attribute=attributes[i];if($.Smarty.skip(attribute)){continue}switch(attribute){case"is":is=true;break;case"not":right=right==="== 0"?"!= 0":"== 0";break;case"div":break;case"even":middle="% 2 ";break;case"odd":right=right==="== 0"?"!= 0":"== 0";middle="% 2 ";break;case"by":left=left+" / ";break;case"||":case"&&":add();statements+=attribute+" ";reset();break;default:if(typeof $.Smarty.operators[attribute]!=="undefined"){statement+=attribute+" "}else{values.push(attribute);if(is){left+="values["+(values.length-1)+"] "}else{statement+="values["+(values.length-1)+"] "}}break}}add();try{var result=eval(statements)}catch(e){$.console.error(652,e)}var regex;var matches;if(result){regex=/^(.*)\{(?:elseif|else)([^}]*)\}/;matches=content.match(regex);if(matches!==null){content=matches[1]}}else{regex=/\{(elseif|else)([^}]*)\}(.*)$/;matches=content.match(regex);if(matches!==null){content=matches[3];if(matches[1]==="else"){content=content.populate()}else{if(matches[1]==="elseif"){attributes=$.Smarty.attributes(matches[2]);content=$.Smarty.functions["if"](content,attributes)}else{content=""}}}else{content=""}return content}return content.populate()},include:function(content,attributes){var template=attributes.file;var template_id="smarty_incl_dataude__"+template.replace(/[^\w_]/g,"_");$.Smarty.fetch(template,template_id);return'<span id="'+template_id+'"></span><script type="text/javascript">$.Smarty.include("'+template+'","'+template_id+'");<\/script>'},literal:function(content,attributes){return content},js:function(content,attributes){return'<script type="text/javascript">'+$content+"<\/script>"},foreach:function(content,attributes){var from=attributes.from;if(typeof from!=="object"){return""}var item=attributes.item;var key=attributes.key||null;var name=attributes.name||Math.round(Math.random()*10000);if(typeof from!=="object"){return""}var length=0;for(var i in from){if($.Smarty.skip(i)){continue}++length}var data_proto={index:-1,iteration:0,first:true,last:false,show:true,total:length,item:null,key:null};var replace={item:item,key:key};var result="";$.each(from,function(key,value){var data=data_proto;++data.index;++data.iteration;data.first=data.index===0;data.last=data.iteration===data.total;data.item=value;data.key=key;$.Smarty.foreach[name]=data;var part=content;try{$.each(replace,function(replace,find){part=part.replace(eval("/\\{.*?\\$"+find+".*?\\}/g"),function(match){match=match.match(eval("/(\\{.*?)(\\$"+find+")(.*?\\})/"));match=match[1]+"$smarty.foreach."+name+"."+replace+match[3];return match})})}catch(e){$.console.error(770,e)}result+=part.populate()});return result},section:function(content,attributes){var name=attributes.name;var loop=attributes.loop;if(typeof loop!=="object"){return""}var start=attributes.start||0;var step=attributes.step||1;var max=attributes.max||loop.length;var show=attributes.show||true;try{var regex_g=eval("/{.*?\\["+name+"\\].*?}/g");var regex=eval("/({.*?\\[)("+name+")(\\].*?})/")}catch(e){$.console.error(794,e)}var result="";for(var section,i=start;i<max;i+=step){section=content.replace(regex_g,function(match){match=match.match(regex);match=match[1]+i+match[3];return match});result+=section.populate()}return result},strip:function(content,attributes){return content}},skip:function(attr){var result=false;switch(attr){case"":case"index":case"input":case"__proto__":result=true;break}return result},fetch:function(template,template_id){if(typeof $.Smarty.templates[template]!=="undefined"){if($.Smarty.templates[template]==="fetching"){return false}return $.Smarty.templates[template]}var template_url=$.Smarty.template_url+template;$.get(template_url,function(data){$.Smarty.templates[template]=data;if(typeof template_id!=="undefined"){$.Smarty.include(template,template_id)}});$.Smarty.templates[template]="fetching";return false},include:function(template,template_id){var $template=$("#"+template_id);var data=$.Smarty.fetch(template,template_id);if($template.length!==0){data=$.Smarty.fetch(template,template_id);if(data){data=data.populate();$template.next("script").remove();$template.after(data);$template.remove()}}return true},clearCache:function(){$.Smarty.templates={}},populate:function(template){template=new String(template);template=template.replace(/[\r\n\t]*/g,"");return template.replace($.Smarty.search.tags_g,$.Smarty.tag_handler)},tag_handler:function(tag){tag=tag.match($.Smarty.search.tags);if(!tag){return""}var func=tag[1];var result;if(func){var attributes=$.Smarty.attributes(tag[2]);var content=tag[3]||"";result=$.Smarty.call(func,attributes,content)}else{result=$.Smarty.value(tag[2])}return result},attributes:function(attributes){if(!attributes){return[]}attributes=(" "+attributes).match($.Smarty.search.attributes_g);var attributes_new={};for(index in attributes){if($.Smarty.skip(index)){continue}var attribute=new String(attributes[index]).match($.Smarty.search.attributes);if(attribute===null){continue}var key;var value;if(typeof attribute[1]==="undefined"){key=index;value=attribute[0].replace(/^\s+|\s+$/g,"")}else{key=attribute[1];value=attribute[2]}value=$.Smarty.value(value);attributes_new[key]=value}attributes=attributes_new;return attributes},value:function(source_raw){if(!source_raw||source_raw==="||"){return source_raw||""}var source_parts=("|"+source_raw).match($.Smarty.search.modifiers_g);var modifiers=[];for(source_part in source_parts){if($.Smarty.skip(source_part)){continue}var source=String(source_parts[source_part]);var parts=source.match($.Smarty.search.modifiers);if(parts===null){continue}var raw=parts[2];var value=raw||null;var what=parts[1]==="|"?"modifier":"attribute";if(value!==null&&value!==""){var a=value.charAt(0);var z=value.charAt(value.length-1);switch(true){case !isNaN(value)||value==="0":value=parseInt(value,10);break;case (a==='"'&&z==='"'):case (a==="'"&&z==="'"):try{value=eval(value)}catch(e){$.console.error(1002,e)}break;case (a==="$"):var loc=$.Smarty.varloc(value);if(loc.substring(0,10)==="['smarty']"){loc="$.Smarty"+loc.substring(10)}else{loc="$.Smarty.data"+loc}try{value=eval(loc)}catch(e){$.console.error(1021,e)}break;case (a==="#"&&z==="#"):value=value.substring(1,value.length-1);try{value=eval("$.Smarty.config"+$.Smarty.varloc(value))}catch(e){$.console.error(1031,e)}break;case (typeof $.Smarty.operators[value]!=="undefined"):value=$.Smarty.operators[value];break;default:break}}if(what==="modifier"){modifiers.push({source:source,raw:raw,value:value,attributes:[]})}else{modifiers[modifiers.length-1].attributes.push(value);modifiers[modifiers.length-1].source+=source}}var result;if(typeof modifiers[0].value==="undefined"){result=""}else{result=modifiers[0].value}for(var i=1,n=modifiers.length;i<n;++i){var modifier=modifiers[i];$.Smarty.modifier_helper["var"]=modifiers[0].raw;$.Smarty.modifier_helper.raw=modifier.raw;$.Smarty.modifier_helper.source=source_raw;$.Smarty.modifier_helper.modifiers=modifiers;result=$.Smarty.call(modifier.value,modifier.attributes,result)}return result},call:function(func,attributes,content){if(!func){return""}content=content||"";content=String(content);try{var call="$.Smarty.functions[func]";var ref=eval(call);if(typeof ref!=="undefined"){content=ref(content,attributes)}else{call="$.Smarty.modifiers[func]";ref=eval(call);if(typeof ref!=="undefined"){call+='("'+content.replace(/"/g,'\\"')+'",';for(index in attributes){if($.Smarty.skip(index)){continue}call+="attributes["+index+"],"}call=call.substring(0,call.length-1);call+=")";content=eval(call)}else{content=$.Smarty.value(func)}}}catch(e){$.console.error(1136,e)}return content},varloc:function(value,prefix){value=new String(value);value=value.replace(/\-\>/g,".");var parts=value.match(/([^.$\['"\]]+)/g);value="";for(var i=0,n=parts.length;i<n;++i){value+="['"+new String(parts[i])+"']"}if(prefix){prefix=$.Smarty.varloc(prefix);value=prefix+value}return value},assign:function(key,value,preloc){preloc=preloc||"";if(typeof value==="undefined"&&typeof key==="object"){$.each(key,function(i,val){$.Smarty.assign(i,val,preloc)})}else{var loc=$.Smarty.varloc(key,preloc);var loc2="$.Smarty.data"+loc;try{var old_value;old_value=eval(loc2);var call=loc2+" = value";eval(call)}catch(e){$.console.error(1201,e)}$.Smarty.changed(loc,old_value,value)}},onchange:function(key,func){try{var loc=$.Smarty.varloc(key);var loc2="$.Smarty.onchange_funcs"+loc;eval(loc2+" = "+loc2+" || []");eval(loc2+".push(func)")}catch(e){return}},changed:function(key,old_value,new_value){var loc=$.Smarty.varloc(key);try{var funcs=eval("$.Smarty.onchange_funcs"+loc)}catch(e){return}if(!funcs){return}$.each(funcs,function(i,func){func(old_value,new_value)});var merged;if(typeof old_value==="object"&&typeof new_value==="object"){merged=$.extend({},old_value,new_value)}else{if(typeof old_value==="object"){merged=old_value}else{if(typeof new_value==="object"){merged=new_value}}}if(!merged){return}$.each(merged,function(i,val){var old_value2=old_value[i];var new_value2=new_value[i];var loc2=$.Smarty.varloc(i,loc);$.Smarty.changed(loc2,old_value2,new_value2)})},escape:function(value,quote){if(typeof quote==="undefined"){quote='"'}var result;try{result=new String(value).replace(eval("/"+quote+"/g"),"\\"+quote)}catch(e){$.console.error(1283,e)}return result},debug:function(){var arr=[];for(var i=0;i<arguments.length;i++){arr.push(arguments[i])}$.console.debug.apply($.console,arr)},construct:function(){$(function(){$.Smarty.domReady()});return true},domReady:function(){}});if(typeof $.Smarty==="undefined"){$.Smarty=new $.SmartyClass()}})(jQuery);