/* * paymill-paybutton * https://github.com/Paymill/paymill-paybutton */ if ( !window.jQuery ) { throw new Error( "This script requires jQuery to be loaded" ); } (function($) { // on was added in 1.7, add support for 1.5+ (delegate exists since 1.4) if (!jQuery.fn.on) { jQuery.fn.on = function(event, selector, handler) { if (arguments.length === 3) { this.delegate(selector, event, handler); } else if (arguments.length === 2) { this.bind(event, selector); } else { throw new Error("jQuery.fn.on: Bad arguments: " + arguments); } }; } $.fn.placeholderFix = function() { // return early if browser does support placeholder attribute natively if ( "placeholder" in document.createElement( "input" ) ) { return this; } return this.each(function(){ var element = $(this), msg = element.attr('placeholder'); if ( element.val() === "" ) { element.val( msg ).addClass( "placeholder" ); } element.focus(function(){ if ( element.val() === msg ) { element.val( "" ).removeClass( "placeholder" ); } }).blur(function() { if (element.val().length === 0) { element.val( msg ).addClass( "placeholder" ); } }); }); }; var paybutton = { // starts iframe creation, usually runs when this script is executed init: function() { // the script itself is used to mark where iframes should be added // and provides a container for configuration // see also http://ejohn.org/blog/degrading-script-tags/ var script = $( "script:last" ), config = paybutton.readConfig( script ); // expose paymill key to Bridge, of not already loaded if ( !window.PAYMILL_PUBLIC_KEY ) { window.PAYMILL_PUBLIC_KEY = config.publicKey; } // unlike jQuery, we can load the Paymill bridge, as its not needed until form submit if ( !window.paymill ) { document.write( "" ); } // create popup first, since button needs a reference to the popup var popup = paybutton.createPopup( config, script ).appendTo( document.body ); paybutton.createButton( config, popup, script ); }, readConfig: function( script ) { var config = { currency: "EUR", label: "Pay With Card", lang: "en-GB", elv: false, inline: false, width: 220, height: 42, submitButton: null }, // supported data attributes; jQuery maps public-key to publicKey for us configProps = "label title description submitButton amount currency publicKey lang elv width height inline logo".split( " " ); // generate URL for default logo, based on src of this script config.logo = script.attr("src") + "/paymill-logo-signet.png"; $.each( configProps, function( index, prop ) { // in jQuery 1.5, the dash-normalization didn't exist yet var value = script.data( prop.replace(/([A-Z])/, function(match, group) { return "-" + group.toLowerCase(); })); // don't overwrite defaults if no value is provided if ( value !== undefined ) { config[ prop ] = value; } }); // make a list of missing and required (no default present) properties var missing = $.map( configProps, function( prop ) { if ( config[ prop ] === undefined ) { return prop; } }); if ( missing.length ) { // fail early throw new Error( "Paymill Paybutton Error - Missing required data-attributes: " + missing.join( ", ") ); } if ( !config.submitButton ) { var amount = (config.amount / 100).toString().replace(".", ","); if (/,\d$/.test(amount)) { amount += "0"; } config.submitButton = translate( "submitButton", config.lang ) + " " + amount + " " + config.currency; } return config; }, // popup is a fixed position fullscreen overlay // loads css for styling and shows the form createPopup: function( config, script ) { var ESCAPE = 27, // start with a blank document that includes a html5 doctype to avoid IE's quirksmode popup = $( "" ) .attr({ frameBorder: "0", allowtransparency: "true" }) .hide() .css({ position: "fixed", top: 0, left: 0, width: "100%", height: "100%", "z-index": 99999 }) .load(function() { /*jshint multistr:true*/ var doc = this.contentWindow.document; var body = $( doc.body ); // workarounds for IE8 support if ( doc.createStyleSheet ) { // allow html5 elements to be styled correctly doc.createElement('header'); doc.createElement('footer'); // see http://msdn.microsoft.com/en-us/library/ms531194%28VS.85%29.aspx doc.createStyleSheet( "https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700" ); //doc.createStyleSheet( "https://button.paymill.de/button.css" ); doc.createStyleSheet( "css/paymill-button.css" ); } var popupHtml = '\ \ \
\