MediaWiki:Centralnotice-template-mobilebannerkaldari

From Meta, a Wikimedia project coordination wiki

<script type="text/javascript">

 mw.centralNotice.bannerData.alterImpressionData = function( impressionData ) {
   // always show if forced
   if (window.location.search.match(/\breset=1/) || window.location.search.match(/\bforce=1/)) {
     $.cookie('{{{hide-cookie-name}}}', 0, { expires: 365, path: '/' });
     mw.centralNotice.bannerData.hideResult = false;
     return true;
   }
   // hide if cookies disabled
   if ( !navigator.cookieEnabled ) {
     mw.centralNotice.bannerData.hideResult = true;
     return false;
   }
   // else check the cookie counter
   var cookieCount = parseInt($.cookie('{{{hide-cookie-name}}}')) | 0;
   mw.centralNotice.bannerData.cookieCount = cookieCount;
   if (cookieCount < {{{hide-cookie-max-count}}}) {
     $.cookie('{{{hide-cookie-name}}}', cookieCount + 1, { expires: 365, path: '/' });
     mw.centralNotice.bannerData.hideResult = false;
     return true;
   } else {
     mw.centralNotice.bannerData.hideResult = true;
     return false;
   }
 };

</script>

<style>

  1. centralNotice.collapsed #{{{banner}}}{
 display: none;

}

  1. {{{banner}}} {
 background: #cce4ff;
 width: 100%;
 z-index: 100;
 top: 0;
 left: 0;

}

  1. {{{banner}}}-collapsed {
 background: #cce4ff;
 padding: 8px 30px 8px 8px;
 cursor: pointer;
 text-align: justify;

}

.{{{banner}}}-highlight {

 background: #c7f6ff;
 padding: 1px 1px;

}

div#{{{banner}}} span.{{{banner}}}-close {

 position: absolute;
 background: url(//upload.wikimedia.org/wikipedia/donate/1/1e/Small-black-close.png) no-repeat center center;
 display: block;
 width: 30px;
 height: 30px;
 right: 0;
 top: 0;
 cursor: pointer;
 z-index: 999;

}

  1. {{{banner}}}-expanded {
 padding: 0 1em 1em 1em;

}

  1. {{{banner}}} fieldset {
 border: 0;
 margin: 0;
 padding: 0;

}

  1. {{{banner}}} #donate-amount-buttons,
  2. {{{banner}}} #donate-payment-buttons {
 text-align: center;

}

  1. {{{banner}}} .donate-button {
 display: inline-block;
 font-size: 1.4em;
 color: #fff;
 background: #7E7E7E;
 border: 4px solid #fff;
 border-radius: 8px;
 margin: 8px 2px 8px 2px;
 padding: 0.3em 0;
 cursor: pointer;

}

  1. {{{banner}}} #donate-amount-buttons .donate-button {
 width: 18%;

}

  1. {{{banner}}} #donate-payment-buttons input[type="radio"] {
 display: none;

}

  1. {{{banner}}} #donate-payment-buttons input[type="radio"]:checked + label,
  2. {{{banner}}} #donate-amount-buttons button:active {
 background-color: #bbb !important;
 border-color: #0645ad !important;

}

  1. {{{banner}}} #donate-payment-buttons .donate-button {
 width: 100%;
 text-transform: uppercase;

}

/* Landscape */ @media screen and (orientation:landscape) {

 #{{{banner}}} #donate-payment-buttons .donate-button {
   width: 48%;
 }
 #{{{banner}}} #paypal-button { float: left; }
 #{{{banner}}} #amazon-button { float: right; }

}


  1. {{{banner}}} .donate-legal-text {
 font-size: smaller;
 line-height: 1.2;

} </style>

<script> $(document).ready( function () {

 if ((parseInt($.cookie('{{{hide-cookie-name}}}')) | 0) < {{{hide-cookie-max-count}}}) {
   $('#siteNotice').prependTo('body');
   $('#{{{banner}}}').css('display', 'block');
   bannerAddSpace();
   $(window).resize(function() {
     bannerAddSpace();
   });
 }

});

function bannerAddSpace() {

 var bannerHeight = $('#{{{banner}}}-collapsed').outerHeight();
 var cssString = '#mw-mf-viewport { top: ' + bannerHeight + 'px; }';
 mw.util.addCSS(cssString);

}

function bannerToggleExpanded() {

 $('#{{{banner}}}-expanded').slideDown(300);
 setTimeout(function(){
   // Hide the address bar!
   window.scrollTo(0, 1);
 }, 0);

}

function hideStickyBanner() {

 hideBanner();
 var cssString = '#mw-mf-viewport { top: 0; }';
 mw.util.addCSS(cssString);

} </script>

<script> /**

* NOTE: The following currency mapping is WMF-specific based on payment
* provider availability, NOT necessarily the official currency of the country
*/

function getCurrency() {

   switch(Geo.country) {
       // Big 5 at the top for speed
       case "US": return "USD";
       case "CA": return "CAD";
       case "GB": return "GBP";
       case "AU": return "AUD";
       case "NZ": return "NZD";
       // Euro countries
       case "AD":
       case "AL":
       case "AM":
       case "AT":
       case "AW":
       case "AZ":
       case "BE":
       case "BY":
       case "CI":
       case "CY":
       case "DE":
       case "EE":
       case "ES":
       case "FI":
       case "FR":
       case "GF":
       case "GR":
       case "IE":
       case "IT":
       case "LT":
       case "LU":
       case "LV":
       case "LY":
       case "MC":
       case "ME":
       case "MG":
       case "MT":
       case "NL":
       case "PT":
       case "RE":
       case "RS":
       case "SI":
       case "SK":
       case "SM":
       case "SR":
       case "VA":
           return "EUR";
       // The rest
       case "AE": return "AED";
       case "AR": return "ARS";
       case "BA": return "BAM";
       case "BB": return "BBD";
       case "BD": return "BDT";
       case "BG": return "BGN";
       case "BH": return "BHD";
       case "BM": return "BMD";
       case "BO": return "BOB";
       case "BR": return "BRL";
       case "BZ": return "BZD";
       case "CH": return "CHF";
       case "CK": return "NZD";
       case "CL": return "CLP";
       case "CN": return "CNY";
       case "CO": return "COP";
       case "CR": return "CRC";
       case "CZ": return "CZK";
       case "DK": return "DKK";
       case "DO": return "DOP";
       case "DZ": return "DZD";
       case "EG": return "EGP";
       case "FJ": return "FJD";
       case "FO": return "DKK";
       case "GL": return "DKK";
       case "GT": return "GTQ";
       case "HK": return "HKD";
       case "HN": return "HNL";
       case "HR": return "HRK";
       case "HU": return "HUF";
       case "ID": return "IDR";
       case "IL": return "ILS";
       case "IN": return "INR";
       case "IS": return "ISK";
       case "JM": return "JMD";
       case "JO": return "JOD";
       case "JP": return "JPY";
       case "KE": return "KES";
       case "KI": return "AUD";
       case "KR": return "KRW";
       case "KZ": return "KZT";
       case "LB": return "LBP";
       case "LI": return "CHF";
       case "LK": return "LKR";
       case "MA": return "MAD";
       case "MK": return "MKD";
       case "MV": return "MVR";
       case "MW": return "GBP";
       case "MX": return "MXN";
       case "MY": return "MYR";
       case "NI": return "NIO";
       case "NO": return "NOK";
       case "NP": return "INR";
       case "NR": return "AUD";
       case "OM": return "OMR";
       case "PA": return "PAB";
       case "PE": return "PEN";
       case "PG": return "AUD";
       case "PH": return "PHP";
       case "PK": return "PKR";
       case "PL": return "PLN";
       case "PY": return "PYG";
       case "QA": return "QAR";
       case "RO": return "RON";
       case "RU": return "RUB";
       case "SA": return "SAR";
       case "SD": return "GBP";
       case "SE": return "SEK";
       case "SG": return "SGD";
       case "TH": return "THB";
       case "TM": return "RUB";
       case "TN": return "TND";
       case "TR": return "TRY";
       case "TT": return "TTD";
       case "TW": return "TWD";
       case "UA": return "UAH";
       case "UY": return "UYU";
       case "UZ": return "RUB";
       case "VE": return "VEF";
       case "VN": return "VND";
       case "VU": return "AUD";
       case "ZA": return "ZAR";
       // small multi-country currencies
       case "CW":
       case "SX":
           return "ANG";
       case "AG":
       case "DM":
       case "GD":
       case "KN":
       case "LC":
           return "XCD";
       case "BJ":
       case "BF":
       case "CI":
       case "GW":
       case "ML":
       case "NE":
       case "SN":
       case "TG":
           return "XOF";
       case "PF":
       case "NC":
       case "WF":
           return "XPF";
       // fall back to USD
       default:
           return "USD";
   }

} </script> <script> /**

* Javascript for mobile banners
*
* Dependencies: MediaWiki:FR2013/Resources/Country2Currency.js
*/

var fundraisingBanner = fundraisingBanner || {};

fundraisingBanner.validateForm = function(form) {

   // check if form is ready to submit
   // we don't have much to do on mobile forms at the moment
   // Get payment method
   var method = null;
   for (var i = 0; i < form.payment_method.length; i++) {
       if (form.payment_method[i].checked) {
           method = form.payment_method[i].value;
       }
   }
   if (method === null) {
       alert('Please select a payment method');
       return false;
   }
   return true;

}

fundraisingBanner.redirectPayment = function(amount) {

   var form = document.paypalcontribution; // we should really change this some day
   var language = $("input[name='language']").val();
   var paymentMethod = $( "input:radio[name=payment_method]:checked" ).val();
   var paymentsURL = 'https://payments.wikimedia.org/index.php/Special:GatewayFormChooser';
   var params = {
       'uselang' : language,
       'language' : language,
       'currency' : $("input[name='currency_code']").val(),
       'country' : $("input[name='country']").val(),
       'paymentmethod' : paymentMethod,
       'amount' : amount
   };
   form.action = paymentsURL + '?' + $.param(params);
   form.utm_source.value = '{{{banner}}}.no-LP' + '.' + paymentMethod;
   form.payment_method.value = paymentMethod;
   form.amount.value = amount;
   if (fundraisingBanner.validateForm(document.paypalcontribution)) {
       form.submit();
   }

}


$(document).ready( function () {

   if ( wgCanonicalSpecialPageName != "CentralNotice" && wgCanonicalSpecialPageName != "NoticeTemplate" ){
       // allow overriding country
       if(mw.util.getParamValue('country') !== null){
           Geo.country = mw.util.getParamValue('country');
       }
       // append the banner count in utm-key
       var cookieName = 'centralnotice_bannercount_fr12';
       var count = $.cookie(cookieName);
       $('[name="paypalcontribution"]').append(
           $('<input type="hidden" name="utm_key" />').attr('value', count)
       );
       var currency = getCurrency();
       var language = mw.config.get('wgUserLanguage');
       // set the form fields
       $("input[name='country']").val(Geo.country);
       $("input[name='currency_code']").val(currency);
       $("input[name='language']").val(mw.config.get('wgUserLanguage'));
       $("input[name='return_to']").val("Thank_You/" + mw.config.get('wgUserLanguage'));
       $("a.localize").each(
           function(index){
               var url = $(this).attr("href");
               if( url.indexOf("?") == -1 ){
                   url = url + "?"
               } else {
                   url = url + "&"
               }
               $(this).attr("href", url + "country=" + Geo.country + "&language=" + mw.config.get('wgUserLanguage')
                   + "&uselang=" + mw.config.get('wgUserLanguage'));
           }
       );
       if (Geo.country === 'US') {
           $('.informationsharing-US').show();
           $('.informationsharing-nonUS').hide();
       }
   }

}); </script>