View difference between Paste ID: Jk06LbfF and uBP1MPat
SHOW: | | - or go back to the newest paste.
1-
(function() 
1+
(function()
2
{
3-
    var paypalButtonData = {};
3+
    var paypalButtonData;
4
5-
    var returnDropdownPaypalButton = function( buttonData )
5+
    var returnPaypalButton = function( buttonData )
6
    {
7-
        var costLength = Object.keys(buttonData.cost).length;
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-
        var priceOptions = '<select name="amount" value="0">';
9+
10
                    '<input type="hidden" name="item_name" value="'+ buttonData.itemName +'">' +
11-
        for (var i = 0; i < costLength; i++) 
11+
12-
        {
12+
                    '<input type="hidden" name="amount" value="'+ buttonData.cost +'">' +
13-
            priceOptions += '<option value="' + buttonData.cost[i].cost + '">' + buttonData.cost[i].description + '</option>';
13+
14
                    '<input type="hidden" name="no_shipping" value="' + buttonData.shipping + '">' +
15
                    '<input type="hidden" name="shipping" value="'+ buttonData.shippingRate +'">' +
16-
        priceOptions += '</select>';
16+
17
                    '<input type="hidden" name="return" value="http://' + window.location.hostname + '/paypal/checkout' + '">' +
18-
        return '<form method="post" action="https://www.paypal.com/cgi-bin/webscr" class="paypal-button" target="_top" style="opacity: 1;">' +
18+
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-
                    priceOptions + 
23+
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-
                    '<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.">' + 
33+
34
            minHeight : 250,
35
            contents  : [
36
            
37
                {
38-
    var returnPaymentInputs = function( numberOfInputs )
38+
39
                    label: '',
40-
        var returnString = '';
40+
41
                    expand: false,
42-
        for (var i = 0; i < numberOfInputs; i++)
42+
43-
        {
43+
44-
            returnString += '<input data-key="'+i+'" data-property="description" class="cke_dialog_ui_input_text" type="text" placeholder="Item '+ (i + 1) +' Description" style="margin-right:10px;width:60% !important;"><input data-key="'+i+'" data-property="cost" class="cke_dialog_ui_input_text input-xsmall" type="text" placeholder="Item' + (i + 1) +' Price" style="margin-right:10px;width:30% !important;"><br>';
44+
45
                            type: 'text',
46
                            id: 'CKpaypal-merchantEmail',
47-
        return returnString;
47+
48
                            validate: function()
49
                            {
50-
    CKEDITOR.dialog.add( 'paypalCreateMultiButton', function( editor ) 
50+
51
                                {
52
                                    document.getElementById( 'CKpaypal-validationMessages' ).innerHTML = lang.validateMerchantEmail;
53
                                    return false;
54
                                };
55
                            },
56
                            commit: function()
57
                            {
58-
            contents: [
58+
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-
                            id: 'CKpaypal-priceOptions',
112+
113-
                            label: lang.labelpriceoptions + ' *',
113+
114-
                            labelStyle: 'margin-top:10px;float:left;',
114+
115-
                            inputStyle: 'margin-top:5px;float:left;width:100%;',
115+
116-
                            items: [ ['Please select the number of price options'], ['1'], ['2'], ['3'], ['4'], ['5'] ],
116+
117-
                            onChange: function( api )
117+
118
                        {
119-
                                var value = this.getValue(),
119+
120-
                                    priceOptions = '';
120+
121
                            label: lang.labelshippingRate + ' *',
122-
                                if( value === '' || value === 'Please select the number of price options this item has' )
122+
123
                            inputStyle: 'float:left',
124
                            commit: function()
125
                            {
126
                                paypalButtonData.shippingRate = ( this.getValue() ? this.getValue() : 0 );
127-
                                value = parseInt( value );
127+
128
                        },
129-
                                priceOptions = returnPaymentInputs( value );
129+
130
                            type: 'html',
131-
                                document.getElementById( 'CKpaypal-priceOptionsContainer' ).innerHTML = priceOptions;
131+
132-
                                return;
132+
133
                    ]
134
                }
135
            ],
136-
                                paypalButtonData.cost = {};
136+
137
            {
138-
                                var div    = document.getElementById( 'CKpaypal-priceOptionsContainer' );
138+
139-
                                var inputs = div.getElementsByTagName( 'input' );                           
139+
                
140
                var paypalButton = returnPaypalButton( paypalButtonData );
141-
                                for (var i = 0; i < inputs.length; i++) 
141+
142
                editor.insertHtml(paypalButton);
143-
                                    var key      = inputs[i].getAttribute( 'data-key' ),
143+
144-
                                        property = inputs[i].getAttribute( 'data-property' ),
144+
            },
145-
                                        value    = inputs[i].value ? inputs[i].value : '0';
145+
            onShow: function()
146
            {
147-
                                    if( !paypalButtonData.cost.hasOwnProperty(key)  )
147+
                paypalButtonData = {};
148-
                                    {
148+
                document.getElementById( 'CKpaypal-validationMessages' ).innerHTML = '';
149-
                                        paypalButtonData.cost[key] = {}; 
149+
150-
                                    };
150+
151
        };
152-
                                    paypalButtonData.cost[key][property] = value;
152+
153
    });
154
155
})();