palmpay.io-website/public/js/react-language-selector.min.js

1 line
9.5 KiB
JavaScript
Raw Normal View History

2018-08-05 00:49:40 +00:00
React.LS=function(){var Lang=function(defaultLangfile,defaultLang){var self=this;if(defaultLangfile){if(defaultLang){self.dLang=defaultLang;self.dLangFile=defaultLangfile}else{self.dLang=defaultLangfile;self.dLangFile=null}if(self.get_setting("lang",self.dLang)!=self.dLang){self.set_load_lang(self.get_setting("lang",defaultLang),self.get_setting("langfile",defaultLangfile))}}};Lang.prototype.dLangFile="";Lang.prototype.dLang="";Lang.prototype.pack=[];Lang.prototype.loadedfiles=[];Array.prototype.contains=function(obj){var i=this.length;while(i--){if(this[i]===obj){return true}}return false};Lang.prototype.ready=function(fn){if(document.readyState!="loading"){fn()}else{document.addEventListener("DOMContentLoaded",fn)}};Lang.prototype.currentLang=function(){var self=this;return self.get_setting("lang",self.dLang)};Lang.prototype.loadLangPack=function(callback,myLangFile){var self=this;if(!self.loadedfiles.contains(myLangFile)){self.loadJSON(function(response){var result=JSON.parse(response);if(self.pack){for(var i=0;i<result.length;i++){self.pack.push(result[i])}}else{self.pack=result}self.set_setting("langfile",myLangFile);callback()},myLangFile)}else{self.set_setting("langfile",myLangFile);callback()}};Lang.prototype.set_lang=function(myLang){var self=this;var num=0;var oldelem;for(var i=0;i<self.pack.length;i++){if(self.pack[i].lang==myLang){var noderesult=document.evaluate(self.pack[i].elem,document,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);var thisNode=noderesult.iterateNext();if(i!=0){if(self.pack[i].elem==oldelem){num++}if(num!=0){for(var x=0;x<num;x++){thisNode=noderesult.iterateNext()}}else{}React.SHP.render(thisNode.outerHTML,self.pack[i].text,self.pack[i].attr,true,thisNode.parentNode)}else{React.SHP.render(thisNode.outerHTML,self.pack[i].text,self.pack[i].attr,true,thisNode.parentNode)}oldelem=self.pack[i].elem}}self.set_setting("lang",myLang)};Lang.prototype.set_load_lang=function(myLang,myLangFile,isfirst){var self=this;self.loadLangPack(function(){if(isfirst==true){self.ready(function(){self.set_lang(myLang)})}else{self.set_lang(myLang)}},myLangFile,isfirst)};Lang.prototype.get_setting=function(setKey,defaultval){var temp=null;if(typeof Storage!=="undefined"){temp=localStorage[setKey]||defaultval}else{temp=defaultval}return temp};Lang.prototype.set_setting=function(setKey,setVal){if(typeof Storage!=="undefined"){localStorage.setItem(setKey,setVal)}};Lang.prototype.loadJSON=function(callback,myfile){var self=this;var xmlhttp=new XMLHttpRequest;try{xmlhttp.open("GET",myfile,true);xmlhttp.overrideMimeType("application/json");xmlhttp.setRequestHeader("Content-Type","application/json");xmlhttp.setRequestHeader("Accept-Encoding","gzip");xmlhttp.send(null);xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4&&xmlhttp.status==200){self.loadedfiles.push(myfile);callback(xmlhttp.responseText)}}}catch(e){localStorage.clear()}};Lang.prototype.UI=React.createClass({displayName:"ReactLanguageSelectorUI",propTypes:{items:React.PropTypes.array.isRequired,openMode:React.PropTypes.string,hoverTimeout:React.PropTypes.number,gridColumns:React.PropTypes.oneOfType([React.PropTypes.number,React.PropTypes.func]),showFlag:React.PropTypes.bool,selectedLang:React.PropTypes.oneOfType([React.PropTypes.string,React.PropTypes.func]),onPopupOpening:React.PropTypes.func,onPopupOpened:React.PropTypes.func,onPopupClosing:React.PropTypes.func,onPopupClosed:React.PropTypes.func,onLanguageChanged:React.PropTypes.func},getDefaultProps:function(){return{gridColumns:1,showFlag:true,openMode:"click",hoverTimeout:200,selectedLang:null,onPopupOpening:null,onPopupOpened:null,onPopupClosing:null,onPopupClosed:null,onLanguageChanged:null}},getInitialState:function(){var itemsProp=this.props.items;var selectedLangProp=this.props.selectedLang;var selectedLang=null;for(var i=0;i<itemsProp.length;i++){var item=itemsProp[i];if(selectedLangProp===item.id){selectedLang=item}}return{popupOpened:false,selectedLang:selectedLang?selectedLang:itemsProp[0],closePopupTimeout:-1}},_documentClickHandler:function(evt){this._processEvent({id:"onPopupClo