ulvis.paste.net

Paste Search Dynamic
Recent pastes
cf.common.js
  1. // CloudFlare: Common
  2. // ===================
  3.  
  4. // We use Polyglot for translations
  5. // ---------------------------------
  6. // Polyglot.js (c) 2012 Airbnb, Inc.
  7. //
  8. // polyglot.js may be freely distributed under the terms of the BSD
  9. // license. For all licensing information, details, and documention:
  10. // http://airbnb.github.com/polyglot.js
  11. !function(e){"use strict";function t(e){e=e||{},this.phrases=e.phrases||{},this.currentLocale=e.locale||"en"}function n(e){return"shared.pluralize."+e}function o(e){var t,n,r,i={};for(t in e)if(e.hasOwnProperty(t)){n=e[t];for(r in n)i[n[r]]=t}return i}function u(e){var t=/^\s+|\s+$/g;return e.replace(t,"")}function a(e,t,n){var i,s,o;return n!=null&&e?(s=e.split(r),o=s[l(t,n)]||s[0],i=u(o)):i=e,i}function f(e){var t=o(s);return t[e]||t.en}function l(e,t){return i[f(e)](t)}function c(e,t){for(var n in t)n!=="_"&&t.hasOwnProperty(n)&&(e=e.replace(new RegExp("%\\{"+n+"\\}","g"),t[n]));return e}function h(t){e.console&&e.console.warn&&e.console.warn("WARNING: "+t)}function p(e){var t={};for(var n in e)t[n]=e[n];return t}t.VERSION="0.2.0",t.prototype.locale=function(e){return e&&(this.currentLocale=e),this.currentLocale},t.prototype.extend=function(e){for(var t in e)e.hasOwnProperty(t)&&(this.phrases[t]=e[t])},t.prototype.clear=function(){this.phrases={}},t.prototype.replace=function(e){this.clear(),this.extend(e)},t.prototype.t=function(e,t){var n;t=t||{};var r=this.phrases[e]||t._||"";return r===""?(h('Missing translation for key: "'+e+'"'),n=e):(t=p(t),t.smart_count!=null&&t.smart_count.length!=null&&(t.smart_count=t.smart_count.length),n=a(r,this.currentLocale,t.smart_count),n=c(n,t)),n},t.prototype.pluralize=function(e,t){t!=null&&t.length!=null&&(t=t.length);var r=n(e);return this.t(r,{smart_count:t})};var r="||||",i={chinese:function(e){return 0},german:function(e){return e!==1?1:0},french:function(e){return e>1?1:0},russian:function(e){return e%10===1&&e%100!==11?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2},czech:function(e){return e===1?0:e>=2&&e<=4?1:2},polish:function(e){return e===1?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2},icelandic:function(e){return e%10!==1||e%100===11?1:0}},s={chinese:["id","ja","ko","ms","th","tr","zh"],german:["da","de","en","es","fi","el","he","hu","it","nl","no","pt","sv"],french:["fr","tl"],russian:["hr","ru"],czech:["cs"],polish:["pl"],icelandic:["is"]};typeof module!="undefined"&&module.exports?module.exports=t:e.Polyglot=t}(this);
  12.  
  13. (function($, Polyglot, window, navigator, undefined){
  14.         var polyglot = window.polyglot = new Polyglot();
  15.  
  16.         // Process tranlations
  17.         function translate( json ){
  18.                 if( !json ){ return false; }
  19.                 polyglot.extend( json );
  20.                 $.each( polyglot.phrases, function( key, val ){ $('[data-translate='+key+']').html( val ); });
  21.         }
  22.  
  23.         // Piece links back together if they were split apart
  24.         function unobfuscateLinks(){
  25.                 $('a[data-orig-ref]').each(function(){
  26.                         var $el = $(this),
  27.                                 proto = $el.data('orig-proto') || '',
  28.                                 url = $el.data('orig-ref') || '';
  29.  
  30.                         url = (proto.length ? proto+'://' : '') + url;
  31.                         $el.attr('href', url );
  32.                 });
  33.         }
  34.  
  35.         $('html')
  36.                 // Let everything know that JS is ready/enabled
  37.                 .toggleClass('no-js js')
  38.                 // Hide all HTML content until the DOM is ready (used to prevent translation text from flashing)
  39.                 .css({ 'visibility' : 'hidden', 'opacity': 0 });
  40.  
  41.         // Once the DOM is ready
  42.         $(function(){
  43.                 var alertContainer = $('<label/>',{'class':'alert alert-error'}),
  44.                         languageSelect = $('#lang-selector');
  45.  
  46.                 // Process translations if it exists
  47.                 if( window._cf_translation ){
  48.                         // Setup the translation object, run through all translations, and show the body again
  49.                         polyglot.locale = window._cf_translation.locale;
  50.                         translate( window._cf_translation.blobs );
  51.  
  52.                         languageSelect.val( polyglot.locale );
  53.                 }
  54.  
  55.                 // Translate obfuscated links back to clickable links.
  56.                 unobfuscateLinks();
  57.  
  58.                 // Show the page to the user
  59.                 $('html').css({ 'opacity': 1, 'visibility' : 'visible' });
  60.  
  61.                 // Go grab the requested language
  62.                 languageSelect.on('change', function( evt ){
  63.                         var lang = evt.target.value;
  64.                         if( lang ){
  65.                                 $.getJSON('/cdn-cgi/scripts/lang/waf/'+lang+'.json', function( data ){
  66.                                         polyglot.locale = lang;
  67.                                         translate( data );
  68.                                 });
  69.                         }
  70.                 });
  71.  
  72.                 // If cookies aren't enabled, let the visitor know
  73.                 if( !navigator.cookieEnabled ){
  74.                         $('#cookie-alert').show();
  75.                 }
  76.         });
  77.  
  78. })( window.$, window.Polyglot, window, navigator );
Parsed in 0.029 seconds