- 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
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
$(function(){
// *****************************************************
// ON-PAGE OFFER CONTROLS
// *****************************************************
function run_offer(offer_type){
init_on_page_offers();
// add best value tab to preferred subscription
add_best_value('24');
// add offer to preferred subscription(s) - options include tutoring, bonus_months_low, bonus_months_high
add_offer('12', offer_type);
add_offer('24', offer_type);
}
run_offer('tutoring');
// *****************************************************
// ON-PAGE OFFER
// *****************************************************
function add_offer(lvl, offer_type){
var offers = {
'tutoring': {
'12': {
promo_code: 'tutor_1special',
message: 'Includes 1 free live tutoring session'
},
'24': {
promo_code: 'tutor_2special',
message: 'Includes 2 free live tutoring sessions'
}
},
'bonus_months_low': {
'12': {
sku: '91213', // 12 + 1 month
message: 'Includes 1 bonus months'
},
'24': {
sku: '91211', // 24 + 3 month
message: 'Includes 3 bonus months'
}
},
'bonus_months_high': {
'12': {
sku: '90496', // 12 + 3 month
message: 'Includes 3 bonus months'
},
'24': {
sku: '90497', // 24 + 6 month
message: 'Includes 6 bonus months'
}
}
}
var promo_code = offers[offer_type][lvl].promo_code;
var sku = offers[offer_type][lvl].sku;
var offer_message = offers[offer_type][lvl].message;
// desktop elements
var $product_content = $('.js_oct_2016_price[data-lvl='+lvl+']').closest('.oct_2016_product_square_content');
var $product_header = $product_content.find('.oct_2016_product_square_header');
// mobile elements
var $mobile_product = $('.js_radio_lvl_mobile[data-lvl='+lvl+']').closest('.mobile_product_label');
// update product header style on desktop
var product_header_style = ''
+'padding-bottom: 0px;'
+'margin-bottom: 20px;'
+'position: relative;'
+'background-color: #3E3E40;'
+'color: #fff;'
;
$product_header.attr('style', product_header_style);
// show offer on desktop
var offer_style = ''
+'background-color: gold;'
+'background-image: linear-gradient(45deg, #F2C534, #FEDE3B);'
+'box-shadow: 0px 0px 3px 0px rgba(33,33,33,0.5);'
+'font-family: gothammedium, gothambook, sans-serif;'
+'color: #333;'
+'line-height: 1;'
+'padding: 10px;'
+'position: relative;'
+'top: 20px;'
+'margin-bottom: -5px;'
;
$product_header.append('<div class="on_page_offer" style="'+offer_style+'">'+offer_message+'</div>');
// show offer on mobile
var offer_style_mobile = ''
+'background-color: #01A13A;'
+'font-family: gothammedium, gothambook, sans-serif;'
+'color: #fff;'
+'line-height: 1;'
+'padding: 10px;'
+'font-size: 14px;'
+'text-transform: uppercase;'
+'max-width: 370px;'
+'margin: auto;'
+'box-sizing: border-box;'
+'border-bottom-left-radius: 5px;'
+'border-bottom-right-radius: 5px;'
+'box-shadow: 0px 5px 8px -3px rgba(33,33,33,0.5);'
;
var offer_html_mobile = '<div class="on_page_offer_mobile" style="'+offer_style_mobile+'">'+offer_message+'</div>';
var $mobile_target_elem = _isPricingMonthly ? $mobile_product.next('.monthly_mobilebottom') : $mobile_product;
$(offer_html_mobile).insertAfter($mobile_target_elem);
$mobile_product.css({
'border-radius': 'unset',
'border-top-right-radius': '5px'
});
if(_isPricingMonthly){
$mobile_product.next('.monthly_mobilebottom').css({
'border-radius': 'unset',
'box-shadow': '0px 0px 5px 0px rgba(33,33,33,0.4)'
});
}
// fix mobile product style if best value tab is absent
var is_best_value_absent = !$mobile_product.prev('.best_value_mobile_container').length;
if(is_best_value_absent){
$mobile_product.css({
'border-top-left-radius': '5px'
});
}
// add offer data to cart url
$('.js_oct_2016_addtocart[data-lvl='+lvl+']').attr('href', function(){
var url = this.href;
return add_offer_to_url(url, promo_code, sku);
});
// make sure offer data stays in cart url whenever cart buttons update
$(document).on('cart_update', function(){
setTimeout(function(){
$('.js_oct_2016_addtocart[data-lvl='+lvl+']').attr('href', function(){
var url = this.href;
return add_offer_to_url(url, promo_code, sku);
});
},0);
});
}
// *****************************************************
// UTILITIES
// *****************************************************
function add_offer_to_url(url, promo_code, sku){
if(sku){
url = url.replace(/\/sku\/\d+/i,'/sku/'+sku);
}
if(promo_code){
var url_contains_promo = (new RegExp(promo_code, 'i')).test(url);
if(!url_contains_promo){
url = url.replace(/(pc=[^&]+)/i, '$1,'+promo_code);
}
}
return url;
}
function init_on_page_offers(){
window._isPricingMonthly = !!$('.monthly_mobilebottom').length;
// remove previous best value callout on desktop and mobile
$('.js_oct_2016_product .oct_2016_best_value, .labelcontain.topper').remove();
// if monthly pricing layout is on, style mobile accordingly
if(_isPricingMonthly){
$('.mobile_product_label').css({
'border-top-left-radius': '5px',
'border-top-right-radius': '5px',
'border-bottom-right-radius': 'unset',
'border-bottom-left-radius': 'unset'
});
}
}
// *****************************************************
// BEST VALUE
// *****************************************************
function add_best_value(lvl){
// desktop elements
var $product_box = $('.js_oct_2016_price[data-lvl='+lvl+']').closest('.js_oct_2016_product');
var $product_content = $('.js_oct_2016_price[data-lvl='+lvl+']').closest('.oct_2016_product_square_content');
// mobile elements
var $mobile_product = $('.js_radio_lvl_mobile[data-lvl='+lvl+']').closest('.mobile_product_label');
// show best value on desktop
var best_value_style_desktop = ''
+'background-color: #00A139;'
+'color: #fff;';
var desktop_best_value_html = '<div class="oct_2016_best_value" style="'+best_value_style_desktop+'">Best Value</div>';
$product_content.prepend(desktop_best_value_html);
// show best value on mobile
var best_value_style_mobile = ''
+'line-height: 1;'
+'display: inline-block;'
+'padding: 7px 14px;'
+'border-top-right-radius: 6px;'
+'border-top-left-radius: 6px;'
+'background-color: gold;'
+'background-image: linear-gradient(45deg, #F2C534, #FEDE3B);'
+'box-shadow: 0px 0px 3px 0px rgba(33,33,33,0.5);'
+'font-size: 14px;'
+'color: #333;'
+'text-transform: uppercase;'
+'font-family: gothambold, gothammedium, gothambook, sans-serif;'
;
var product_style_mobile = ''
+'position: relative;'
+'margin-top: 0px;'
+'border-top-left-radius: 0px;'
+'box-shadow: 0px 0px 5px 0px rgba(33,33,33,0.4);'
;
if(_isPricingMonthly){
product_style_mobile += ''
+'border-radius: unset;'
+'border-top-right-radius: 5px;'
;
}
var mobile_best_value_html = ''
+'<div class="best_value_mobile_container" style="margin:10px auto 0px; max-width:370px; text-align:left;">'
+'<div class="best_value_mobile" style="'+best_value_style_mobile+'">Best Value</div>'
+'</div>';
$(mobile_best_value_html).insertBefore($mobile_product);
$mobile_product.attr('style', product_style_mobile);
}
});