PageSourceSearch

https://www.lyceum.lk/wp-content/plugins/tickera/js/cart.js

js lyceum.lk collected 2026-10-02 23:40:53 UTC 21,620 bytes, 550 lines download raw bytes

1( function( $ ) {
2
3    /**
4     * Hook to $( window ).load() to correctly capture the rendered attribute values.
5     * @since 3.5.1.2
6     */
7    $( window ).ready( function() {
8
9        /**
10         * Payment Method selection.
11         * Expand the first Payment Method in Payment Page.
12         */
13        setTimeout( function() {
14            let selected_method = $( 'input.tc_choose_gateway:checked' ).val(),
15                max_height = $( 'div#' + selected_method + ' > .inner-wrapper' ).outerHeight();
16            $( 'div#' + selected_method ).css( { 'max-height': max_height + 'px' } );
17        }, 500 );
18    });
19
20    $( document ).ready( function() {
21
22        const tc_cart = {
23
24            quantity: function() {
25
26                var quantity = 0;
27                $( 'input[name="ticket_quantity[]"]' ).each( function() {
28                    quantity = quantity + parseInt( $( this ).val() );
29                } );
30
31                return quantity;
32            },
33
34            /**
35             * Initialize Listeners
36             */
37            init: function() {
38                tc_cart.tc_empty_cart();
39                tc_cart.tc_cart_listeners();
40            },
41
42            /**
43             * Listeners for add item to cart
44             *
45             * @returns {undefined}
46             */
47            tc_cart_listeners: function() {
48
49                $( 'body' ).on( 'click', 'input.tc_button_addcart', function() {
50
51                    var input = $( this ),
52                        formElm = $( input ).parents( 'form.tc_buy_form' ),
53                        tempHtml = formElm.html(),
54                        serializedForm = formElm.serialize();
55
56                    formElm.html( '<img src="' + tc_ajax.imgUrl + '" alt="' + tc_ajax.addingMsg + '" />' );
57
58                    $.post( tc_ajax.ajaxUrl, serializedForm, function( data ) {
59
60                        var result = data.split( '||', 2 );
61
62                        if ( 'error' == result[ 0 ] ) {
63
64                            alert( result[ 1 ] );
65                            formElm.html( tempHtml );
66                            tc_cart.tc_cart_listeners();
67
68                        } else {
69
70                            formElm.html( '<span class="tc_adding_to_cart">' + tc_ajax.successMsg + '</span>' );
71                            $( 'div.tc_cart_widget_content' ).html( result[ 1 ] );
72
73                            if ( result[ 0 ] > 0 ) {
74
75                                formElm.fadeOut( 2000, function() {
76                                    formElm.html( tempHtml ).fadeIn( 'fast' );
77                                    tc_cart.tc_cart_listeners();
78                                } );
79
80                            } else {
81                                formElm.fadeOut( 2000, function() {
82                                    formElm.html( '<span class="tc_no_stock">' + tc_ajax.outMsg + '</span>' ).fadeIn( 'fast' );
83                                    tc_cart.tc_cart_listeners();
84                                } );
85                            }
86
87                            tc_cart.tc_empty_cart(); // Re-init empty script as the widget was reloaded
88                        }
89                    } );
90                    return false;
91                } );
92            },
93
94            /**
95             * Empty Cart
96             *
97             * @returns {undefined}
98             */
99            tc_empty_cart: function() {
100
101                if ( $( 'a.tc_empty_cart' ).attr( 'onClick' ) != undefined ) {
102                    return;
103                }
104
105                $( 'body' ).on( 'click', 'a.tc_empty_cart', function() {
106
107                    var answer = confirm( tc_ajax.empty_cart_message );
108
109                    if ( answer ) {
110
111                        $( this ).html( '<img src="' + tc_ajax.imgUrl + '" />' );
112
113                        $.post( tc_ajax.ajaxUrl, { action: 'mp-update-cart', empty_cart: 1 }, function( data ) {
114                            $( 'div.tc_cart_widget_content' ).html( data );
115                        } );
116                    }
117
118                    return false;
119                } );
120            }
121        };
122
123        /**
124         * Check age restriction.
125         * Woocommerce + Bridge for Woocommerce
126         */
127        $( 'form.checkout' ).on( 'checkout_place_order', function( event ) {
128            if ( $( '#tc_age_check' ).length !== 0 ) {
129                if ( false == $( '#tc_age_check' ).is( ':checked' ) ) {
130                    $( '.tc-age-check-error' ).remove();
131                    $( '.tc-age-check-label' ).append( '<span class="tc-age-check-error">' + tc_ajax.tc_error_message + '</span>' );
132                    $( 'html, body' ).stop().animate( { 'scrollTop': ( $( '#tc_age_check' ).offset().top ) - 100 }, 350, 'swing', function() { window.location.hash = target; });
133                    return false;
134                }
135            }
136        } );
137
138
139        if ( $( '.tc_cart_widget' ).length > 0 ) {
140
141            function tc_update_cart_ajax() {
142
143                $( '.tc_cart_ul' ).css( 'opacity', '0.5' );
144
145                // Since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
146                $.post( tc_ajax.ajaxUrl, {
147                    action: 'tickera_update_widget_cart',
148                    nonce: tc_ajax.ajaxNonce
149                }, function( response ) {
150                    $( '.tc_cart_ul' ).css( 'opacity', '1' );
151                    $( '.tc_cart_ul' ).html( '' );
152                    $( '.tc_cart_ul' ).html( response );
153                } );
154            }
155
156            // Listen DOM changes
157            $( '.event_tickets, .cart_form' ).bind( 'DOMSubtreeModified', tc_update_cart_ajax );
158        }
159
160        $( document ).on( 'submit', '#tc_payment_form', function() {
161            $( '#tc_payment_confirm' ).attr( 'disabled', 'disabled' );
162        } );
163
164        /**
165         * Increase the quantity
166         */
167        $( 'body' ).on( 'click', 'input.tickera_button.plus', function() {
168            let parentContainer = $( this ).closest( 'td' ),
169                quantity = parentContainer.find( '.quantity' ).val();
170            parentContainer.find( '.quantity' ).val( parseInt( quantity ) + 1 );
171        } );
172
173        /**
174         * Decrease the quantity
175         */
176        $( 'body' ).on( 'click', 'input.tickera_button.minus', function() {
177            let parentContainer = $( this ).closest( 'td' ),
178                quantity = parentContainer.find( '.quantity' ).val();
179            if ( quantity >= 1 ) {
180                parentContainer.find( '.quantity' ).val( parseInt( quantity ) - 1 );
181            }
182        } );
183
184        /**
185         * When user clicks on the empty cart button
186         */
187        $( 'body' ).on( 'click', '#empty_cart', function( event ) {
188
189            let proceed = confirm( tc_ajax.empty_cart_confirmation );
190
191            if ( proceed ) {
192                $( 'input[name="cart_action"]' ).val( 'empty_cart' );
193
194            } else {
195                event.preventDefault();
196            }
197        } );
198
199        /**
200         * When user clicks on the update button
201         */
202        $( 'body' ).on( 'click', '#update_cart', function() {
203            $( 'input[name="cart_action"]' ).val( 'update_cart' );
204        } );
205
206        /**
207         * Toggle Customer Age Checkbox
208         */
209        $( document ).on( 'change', '#tc_age_check', function() {
210
211            if ( $( this ).is( ':checked' ) ) {
212                $( this ).removeClass( 'has-error' );
213                $( '.tc-age-check-error' ).remove();
214
215            } else {
216                $( this ).addClass( 'has-error' );
217                $( '.tc-age-check-error' ).remove();
218                $( this ).parent().append( '<span class="tc-age-check-error">' + tc_ajax.tc_error_message + '</span>' );
219            }
220        } );
221
222        /**
223         * Tickera Standalone
224         * When user click on the proceed to checkout button,
225         */
226        var current_quantity = tc_cart.quantity();
227        $( document ).on( 'click', '#proceed_to_checkout', function( event ) {
228
229            // Make sure to update the cart if there's some changes before moving to checkout page.
230            let input_quantity = tc_cart.quantity();
231            if ( typeof tc_cart.quantity() === 'undefined' || 0 == tc_cart.quantity() || current_quantity != input_quantity ) {
232                event.preventDefault();
233
234                let target = $( '.tc_cart_errors' );
235                if ( target.find( 'ul' ).length ) {
236                    target.find( 'ul' ).append( '<li>' + tc_ajax.update_cart_message + '</li>' );
237
238                } else {
239                    target.html( '<ul><li>' + tc_ajax.update_cart_message + '</li></ul>' );
240                }
241
242                $( 'html, body' ).stop().animate( { 'scrollTop': ( target.offset().top ) - 40 }, 350, 'swing', function() {
243                    window.location.hash = target;
244                } );
245            }
246
247            // Make sure confirm age before proceeding to checkout
248            if ( $( '#tc_age_check' ).length ) {
249                let age_confirmation_field = $( '#tc_age_check' );
250                if ( age_confirmation_field.is( ':checked' ) ) {
251                    age_confirmation_field.removeClass( 'has-error' );
252                    $( '.tc-age-check-error' ).remove();
253
254                } else {
255                    event.preventDefault();
256                    $( '.tc-age-check-error' ).remove();
257                    age_confirmation_field.addClass( 'has-error' );
258                    age_confirmation_field.closest( 'label' ).append( '<span class="tc-age-check-error">' + tc_ajax.tc_error_message + '</span>' );
259                }
260            }
261        } );
262
263        /**
264         * When user click on the proceed to checkout button
265         */
266        $( 'body' ).on( 'click', '#apply_coupon', function() {
267            $( 'input[name="cart_action"]' ).val( 'apply_coupon' );
268        } );
269
270        /**
271         * Add to cart button
272         */
273        $( 'body' ).on( 'click', 'a.add_to_cart', function( event ) {
274
275            event.preventDefault();
276
277            $( this ).fadeOut( 'fast' ).fadeIn( 'fast' );
278
279            var button_type = $( this ).attr( 'data-button-type' ),
280                open_method = $( this ).attr( 'data-open-method' ),
281                current_form = $( this ).parents( 'form.cart_form' ),
282                parent_container = current_form.parent(),
283                ticket_id = current_form.find( '.ticket_id' ).val(),
284                qty = $( this ).closest( 'tr' ).find( '.tc_quantity_selector' ).val(),
285                nonce = $( this ).closest( 'form.cart_form' ).find( '[name="nonce"]' ).val();
286
287            qty = ( typeof qty === 'undefined' ) ? $( this ).closest( '.cart_form' ).find( '.tc_quantity_selector' ).val() : qty;
288
289            $.post( tc_ajax.ajaxUrl, { action: 'add_to_cart', ticket_id: ticket_id, tc_qty: qty, nonce: nonce }, function( data ) {
290
291                if ( 'error' != data ) {
292
293                    parent_container.html( data );
294
295                    if ( $( '.tc_cart_contents' ).length > 0 ) {
296                        $.post( tc_ajax.ajaxUrl, { action: 'update_cart_widget', nonce: nonce }, function( widget_data ) {
297                            $( '.tc_cart_contents' ).html( widget_data );
298                        } );
299                    }
300
301                    if ( 'new' == open_method && 'buynow' == button_type ) {
302                        window.open( tc_ajax.cart_url, '_blank' );
303                    }
304
305                    if ( 'buynow' == button_type && 'new' !== open_method ) {
306                        window.location = tc_ajax.cart_url;
307                    }
308
309                } else {
310                    parent_container.html( data );
311                }
312            } );
313        } );
314
315        /**
316         * Cart Widget
317         */
318        $( 'body' ).on( 'click', '.tc_widget_cart_button', function() {
319            window.location.href = $( this ).data( 'url' );
320        } );
321
322        /**
323         * Proceed to checkout button
324         */
325        $( 'body' ).on( 'click', '#proceed_to_checkout', function() {
326            $( 'input[name="cart_action"]' ).val( 'proceed_to_checkout' );
327        } );
328
329        /**
330         * Check email-verification for owner field with Woocommerce
331         */
332        $( 'form.checkout' ).on( 'click', 'button[type="submit"][name="woocommerce_checkout_place_order"]', function() {
333
334            // Disable "Place Order" button
335            var owner_email = $( '.tc_owner_email' ).val(),
336                owner_confirm_email = $( '.tc_owner_confirm_email' ).val();
337
338            if ( ( owner_email && owner_confirm_email ) ) {
339
340                if ( ( owner_email !== owner_confirm_email ) || owner_email === "" || owner_confirm_email === "" ) {
341                    $( '.tc_owner_email,.tc_owner_confirm_email' ).css( 'border-left', '2px solid #ff0000' );
342
343                } else {
344                    $( '.tc_owner_email,.tc_owner_confirm_email' ).css( 'border-left', '2px solid #09a10f' );
345                }
346            }
347        } );
348
349        /**
350         * Payment Method selection.
351         * Accordion effect in Payment Page.
352         */
353        $( document ).on( 'change', '.tickera-payment-gateways input.tc_choose_gateway', function() {
354
355            let selected_method = $( 'input.tc_choose_gateway:checked' ).val(),
356                parent_container = $( this ).closest( '.tickera-payment-gateways' ),
357                max_height = parent_container.find( 'div#' + selected_method + ' > .inner-wrapper' ).outerHeight();
358
359            $( '.tickera-payment-gateways' ).removeClass( 'active' );
360            parent_container.addClass( 'active' );
361
362            parent_container.siblings().find( '.tc_gateway_form' ).removeAttr( 'style' );
363            $( 'div#' + selected_method ).css( { 'max-height': max_height + 'px' } );
364        });
365
366        /**
367         * Tickera Cart: Preventing Default button to trigger on Enter Key
368         */
369        $( document ).on( 'keypress', '#tickera_cart input', function( e ) {
370            if ( 13 === e.keyCode ) {
371                e.preventDefault();
372                $( '#proceed_to_checkout' ).trigger( 'click' );
373            }
374        } );
375
376        /**
377         * Payment Gateway Page - Frontend
378         */
379        $( document ).on( 'keypress', '.tc-numbers-only', function( e ) {
380            if ( e.which != 8 && e.which != 0 && ( e.which < 48 || e.which > 57 ) ) {
381                return false;
382            }
383        } );
384
385        /**
386         * Update add to cart link value/ticket type id
387         * Event Tickets - Shortcode
388         * Display Type: Dropdown
389         */
390        $( document ).on( 'change', '.tc-event-dropdown-wrap select.ticket-type-id', function() {
391
392            let wrapper = $( this ).closest( '.tc-event-dropdown-wrap' ),
393                ticketId = $( this ).val(),
394                actionsContainer = wrapper.find( '.actions' ),
395                addToCartContainer = actionsContainer.find( '[id="ticket-type-' + ticketId + '"]' );
396
397            addToCartContainer.prependTo( actionsContainer );
398        });
399    } );
400
401    /**
402     * Tickera Standalone, Woocommerce + Bridge for Woocommerce
403     * Check custom form error notification
404     */
405    $( document ).ready( function() {
406
407        /**
408         * Cart/Checkout Form validation
409         */
410        if ( $( 'form#tickera_cart' ).length || $( 'form.checkout' ).length ) {
411
412            $.validator.addMethod( 'alphanumericOnly', function( value, element ) {
413                if ( ! value ) return true; // Valid if empty value
414                let regex = new RegExp( "^[^<?=^>]+$" );
415                return ( !regex.test( value ) ) ? false : true;
416            }, tc_ajax.alphanumeric_characters_only );
417
418            $( 'form#tickera_cart, form.checkout' ).validate( {
419                debug: false,
420                errorClass: 'has-error',
421                validClass: 'valid',
422                highlight: function( element, errorClass, validClass ) {
423                    $( element ).addClass( errorClass ).removeClass( validClass );
424                },
425                unhighlight: function( element, errorClass, validClass ) {
426                    $( element ).removeClass( errorClass ).addClass( validClass );
427                }
428            } );
429
430            $( '.tickera-input-field' ).each( function() {
431
432                let field = $( this ),
433                    field_type = field.attr( 'type' ),
434                    field_name = field.attr( 'name' );
435
436                if ( ( ( 'text' == field_type && ! field.hasClass( 'checkbox_values' ) ) // Include Text but not checkbox_values
437                    || field.is( 'textarea' ) ) // Include Textarea
438                    && 'coupon_code' != field_name ) { // Don't include discount field
439                    // $( this ).rules( 'add', {
440                    //     alphanumericOnly: true
441                    // } );
442                }
443            } );
444
445            $( 'input[name="tc_cart_required[]"]' ).each( function() {
446                let field = $( this ).closest( 'div' ).find( '.tickera-input-field:not( input[type="checkbox"] ):not( input[type="radio"] )' );
447                field.rules( 'add', {
448                    required: {
449                        depends: function() {
450
451                            let trimmedValue = $( this ).val().trim();
452
453                            if ( ! trimmedValue ) {
454                                $( this ).val( $.trim( $( this ).val() ) );
455                                return true;
456
457                            } else {
458                                return false;
459                            }
460                        }
461                    },
462                    messages: {
463                        required: tc_jquery_validate_library_translation.required
464                    }
465                } );
466            } );
467
468            $( '.tc_validate_field_type_email' ).each( function() {
469                $( this ).rules( 'add', {
470                    email: true,
471                    messages: {
472                        email: tc_jquery_validate_library_translation.email
473                    }
474                } );
475            } );
476
477            $( '.tc_validate_field_type_confirm_email' ).each( function() {
478                $( this ).rules( 'add', {
479                    email: true,
480                    equalTo: '.tc_validate_field_type_email',
481                    messages: {
482                        email: tc_jquery_validate_library_translation.email,
483                        equalTo: tc_jquery_validate_library_translation.equalTo
484                    }
485                } );
486            } );
487
488            $( '.tc_owner_email' ).each( function() {
489                $( this ).rules( 'add', {
490                    email: true,
491                    messages: {
492                        email: tc_jquery_validate_library_translation.email
493                    }
494                } );
495            } );
496
497            $( '.tc_owner_confirm_email' ).each( function() {
498
499                let owner_email_name = $( this ).attr( 'name' );
500                owner_email_name = owner_email_name.replace( '_confirm', '' );
501
502                $( this ).rules( 'add', {
503                    email: true,
504                    equalTo: 'input[name="' + owner_email_name + '"]',
505                    messages: {
506                        email: tc_jquery_validate_library_translation.email,
507                        equalTo: tc_jquery_validate_library_translation.equalTo
508                    }
509                } );
510            } );
511
512            /**
513             * Update checkbox values on field change.
514             */
515            $( document ).on( 'change', '.buyer-field-checkbox, .owner-field-checkbox', function( e ) {
516
517                var field_values = $( this ).closest( 'div' ).find( '.checkbox_values' ),
518                    values = field_values.val().split( ',' );
519
520                if ( $( this ).is( ':checked' ) ) {
521                    values[ values.length ] = $( this ).val();
522                    field_values.removeClass( 'has-error' ).addClass( 'valid' );
523
524                } else {
525                    var toRemove = $( this ).val();
526                    values = $.grep( values, function( value ) {
527                        return value != toRemove;
528                    } )
529                }
530
531                field_values.val( values.filter( e => e ).join() ).focus().blur();
532            } );
533
534            /**
535             * Update radio validation field
536             */
537            $( document ).on( 'change', '.buyer-field-radio, .owner-field-radio', function( e ) {
538
539                var fieldWrapper = $( this ).closest( 'div' ),
540                    validationField = fieldWrapper.find( '.validation' );
541
542                if ( fieldWrapper.find( 'input[type="radio"]:checked' ).length > 0 ) {
543                    validationField.val( true );
544                    validationField.removeClass( 'has-error' ).addClass( 'valid' );
545                    validationField.next( '.has-error' ).remove();
546                }
547            } );
548        }
549    } );
550} )( jQuery );

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.