loader.js
3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// loads the frontend ui for ticket selection
( function( $, q, qt ) {
var S = $.extend( { messages:{} }, _qsot_seating_loader );
function __( name ) {
var args = [].slice.call( arguments, 1 ), str = qt.is( S.messages[ name ] ) ? S.messages[ name ] : name, i;
for ( i = 0; i < args.length; i++ ) str = str.replace( '%s', args[ i ] );
return str;
}
$( function() {
// the UI container
var sel = $( '[rel="ticket-selection"]' );
// test features, and load the necessary version based on what is available
q.Features.load( [
{
// we require cookies to work, since woocommerce requires cookies to track the cart. if cookies are on, then proceed
name: 'cookies',
run: function() {
q.Loader.js( S.assets.res, 'qsot-seating-reservations', 'head', 'append', function() {
$( qt.is( S.templates['loading'] ) ? S.templates['loading'] : '' ).appendTo( '.event-area-image' ).show();
/*
$.ajax( {
url: S.ajaxurl,
data: { action:'qsots-ajax', sa:'chart-data', n:S.nonce, ei:S.event_id },
dataType: 'json',
error: function() { console.log( 'ERROR: Unexpected Error loading chart' ); },
method: 'POST',
success: function( r ) {
if ( r.s && qt.isO( r.r ) ) {
S = $.extend( true, {}, S, r.r );
console.log( 'final settings', S );
*/
S.resui = new QS.Reservations( $( '[rel="ticket-selection"]' ), S );
var modes = [];
if ( qt.is( S.event_id ) && qt.toInt( S.event_id ) > 0 ) {
modes.push( {
// svg is the preferred method of interface. if it is available, then load the SVG interface
name: 'svg',
run: function() {
if ( qt.isO( S.assets ) && qt.is( S.assets.svg ) )
q.Loader.js( S.assets.snap, 'qsot-seating-snap', 'head', 'append', function() {
q.Loader.js( S.assets.svg, 'qsot-seating-svgui', 'head', 'append', function() {
$( '.event-area-image' ).empty();
var ticket_selection = $( '[rel="ticket-selection"]' ).empty();
if ( ticket_selection.length )
QS.svgui( ticket_selection, S );
} );
} );
else
$( '<div class="error">' + __( 'Could not load the required components.' ) + '</div>' ).appendTo( sel.empty() );
}
} );
}
modes.push( {
// if svg is not available, then we can fallback to the basic 'dropdown' style, crappy interface that everyone else has
name: 'fallback',
run: function() {
if ( qt.isO( S.assets ) && qt.is( S.assets.svg ) )
q.Loader.js( S.assets.nosvg, 'qsot-seating-nosvgui', 'head', 'append', function() {
var ticket_selection = $( '[rel="ticket-selection"]' ).empty();
if ( ticket_selection.length )
QS.nosvgui( ticket_selection, S );
} );
else
$( '<div class="error">' + __( 'Could not load a required component.' ) + '</div>' ).appendTo( sel.empty() );
}
} );
q.Features.load( modes );
/*
} else if ( r.e && r.e.length ) {
console.log( 'ERROR: ', r.e );
} else {
console.log( 'ERROR: Unexpected Error loading chart' );
}
},
xhrFields: { withCredentials: true }
} );
*/
} )
}
},
{
// if cookies are off, then error out
name: 'fallback',
run: function() {
$( '<div class="error">' + __( 'You do not have cookies enabled, and they are required.' ) + '</div>' ).appendTo( sel.empty() );
alert( __( 'You must have cookies enabled to purchase tickets.' ) );
}
}
] );
} );
} )( jQuery, QS, QS.Tools );