Guest User

CKEDITOR 4 Paypal Insert Plugin singleButton.js

a guest
Aug 5th, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function()
  2. {
  3.     var paypalButtonData;
  4.  
  5.     var returnPaypalButton = function( buttonData )
  6.     {
  7.         return  '<form method="post" action="https://www.paypal.com/cgi-bin/webscr" class="paypal-button" target="_top" style="opacity: 1;">' +
  8.                     '<input type="hidden" name="button" value="buynow">' +
  9.                     '<input type="hidden" name="business" value="'+ buttonData.account +'">' +
  10.                     '<input type="hidden" name="item_name" value="'+ buttonData.itemName +'">' +
  11.                     '<input type="hidden" name="quantity" value="1">' +
  12.                     '<input type="hidden" name="amount" value="'+ buttonData.cost +'">' +
  13.                     '<input type="hidden" name="currency_code" value="'+ buttonData.currency +'">' +
  14.                     '<input type="hidden" name="no_shipping" value="' + buttonData.shipping + '">' +
  15.                     '<input type="hidden" name="shipping" value="'+ buttonData.shippingRate +'">' +
  16.                     '<input type="hidden" name="tax" value="">' +
  17.                     '<input type="hidden" name="return" value="http://' + window.location.hostname + '/paypal/checkout' + '">' +
  18.                     '<input type="hidden" name="cancel_return" value="http://' + window.location.hostname + '/paypal/checkout' + '">' +
  19.                     '<input type="hidden" name="notify_url" value="http://' + window.location.hostname + '/paypal/ipn' + '">' +
  20.                     '<input type="hidden" name="cmd" value="_xclick">' +
  21.                     '<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">' +
  22.                     '<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online.">' +
  23.                     '<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">' +
  24.                 '</form>';
  25.     };
  26.  
  27.     CKEDITOR.dialog.add( 'paypalCreateSingleButton', function( editor )
  28.     {
  29.         var lang = editor.lang.paypal;
  30.  
  31.         return {
  32.             title     : CKEDITOR.env.ie ? lang.dlgTitle : lang.title,
  33.             minWidth  : 300,
  34.             minHeight : 250,
  35.             contents  : [
  36.            
  37.                 {
  38.                     id: 'paypal1',
  39.                     label: '',
  40.                     title: '',
  41.                     expand: false,
  42.                     padding: 0,
  43.                     elements: [
  44.                         {
  45.                             type: 'text',
  46.                             id: 'CKpaypal-merchantEmail',
  47.                             label: lang.labelMerchantEmail + ' *',
  48.                             validate: function()
  49.                             {
  50.                                 if( !this.getValue() )
  51.                                 {
  52.                                     document.getElementById( 'CKpaypal-validationMessages' ).innerHTML = lang.validateMerchantEmail;
  53.                                     return false;
  54.                                 };
  55.                             },
  56.                             commit: function()
  57.                             {
  58.                                 paypalButtonData.account = this.getValue();
  59.                             }
  60.                         },
  61.                         {
  62.                             type: 'text',
  63.                             id: 'CKpaypal-itemName',
  64.                             label: lang.labelitemName + ' *',
  65.                             commit: function()
  66.                             {
  67.                                 paypalButtonData.itemName = this.getValue();
  68.                             }
  69.                         },
  70.                         {
  71.                             type: 'select',
  72.                             id: 'CKpaypal-currency',
  73.                             label: lang.labelcurrency + ' *',
  74.                             items: [ ['Please select one:'],['CAD'],['EUR'],['GBP'],['NZD'],['USD'] ],
  75.                             validate: function()
  76.                             {
  77.                                 if( this.getValue() === 'Please select one:' )
  78.                                 {
  79.                                     document.getElementById( 'CKpaypal-validationMessages' ).innerHTML = lang.validatecurrency;
  80.                                     return false;
  81.                                 };
  82.                             },
  83.                             commit: function()
  84.                             {
  85.                                 paypalButtonData.currency = this.getValue();
  86.                             }
  87.                         },
  88.                         {
  89.                             type: 'text',
  90.                             id: 'CKpaypal-price',
  91.                             label: lang.labelprice + ' *',
  92.                             labelStyle: 'margin-top:10px;float:left',
  93.                             inputStyle: 'float:left',
  94.                             commit: function()
  95.                             {
  96.                                 paypalButtonData.cost = this.getValue();
  97.                             }
  98.                         },
  99.                         {
  100.                             type: 'select',
  101.                             id: 'CKpaypal-shipping',
  102.                             label: lang.labelshipping + '*',
  103.                             items: [ ['Please select one:'],['yes'],['no'] ],
  104.                             validate: function()
  105.                             {
  106.                                 if( this.getValue() === 'Please select one:' )
  107.                                 {
  108.                                     document.getElementById( 'CKpaypal-validationMessages' ).innerHTML = lang.validateshipping;
  109.                                     return false;
  110.                                 };
  111.                             },
  112.                             commit: function()
  113.                             {
  114.                                 var shippingValue = this.getValue();
  115.                                 paypalButtonData.shipping = ( this.getValue() === 'yes' ? 2 : 1 );
  116.                             }
  117.                         },
  118.                         {
  119.                             type: 'text',
  120.                             id: 'CKpaypal-shippingRate',
  121.                             label: lang.labelshippingRate + ' *',
  122.                             labelStyle: 'margin-top:10px;float:left',
  123.                             inputStyle: 'float:left',
  124.                             commit: function()
  125.                             {
  126.                                 paypalButtonData.shippingRate = ( this.getValue() ? this.getValue() : 0 );
  127.                             }
  128.                         },
  129.                         {
  130.                             type: 'html',
  131.                             html: '<div id="CKpaypal-validationMessages" style="color:red;font-weight:bold;margin-top:20px;"></div>'
  132.                         }
  133.                     ]
  134.                 }
  135.             ],
  136.             onOk: function()
  137.             {
  138.                 this.commitContent();
  139.                
  140.                 var paypalButton = returnPaypalButton( paypalButtonData );
  141.  
  142.                 editor.insertHtml(paypalButton);
  143.                 return;
  144.             },
  145.             onShow: function()
  146.             {
  147.                 paypalButtonData = {};
  148.                 document.getElementById( 'CKpaypal-validationMessages' ).innerHTML = '';
  149.                 return;
  150.             }
  151.         };
  152.  
  153.     });
  154.  
  155. })();
Add Comment
Please, Sign In to add comment