Skip to content

Instantly share code, notes, and snippets.

@pmint93
Created September 19, 2015 02:56
Show Gist options
  • Save pmint93/d7c46d528afd7e0c8012 to your computer and use it in GitHub Desktop.
Save pmint93/d7c46d528afd7e0c8012 to your computer and use it in GitHub Desktop.
Fontbox.vn Temporary Downloader fix
//Buy Form
jQuery.fn.fontbox_buy_form = function(variables){
var z_this_form = jQuery(this);
var a_check_all = jQuery('#buy_check_all');
var b_check_box_child_class = '.buy-check-box';
var c_check_box_class = '.check-box';
var d_total_price = 0;
var e_total_price_obj = jQuery('#buy_total_price');
var f_total_check_box_child = jQuery(b_check_box_child_class).size();
var g_download_iframe = jQuery('#buy_download_iframe');
var h_facebook_share = jQuery('#facebook_share_btn');
var m_methods = {
ma_update_price: function(){
d_total_price = 0;
var count_check = 0;
jQuery(b_check_box_child_class).each(function(evt){
if(this.checked){
d_total_price = d_total_price + parseInt(jQuery(this).attr('data-price'));
jQuery(this).parent().find('strong').removeClass('line-through');
count_check++;
}else{
jQuery(this).parent().find('strong').addClass('line-through');
}
});
if(count_check < f_total_check_box_child){
a_check_all.removeAttr('checked');
}else{
a_check_all.attr('checked', 'checked');
}
if(count_check == 0){
a_check_all.parent().find('strong').addClass('line-through');
}else{
a_check_all.parent().find('strong').removeClass('line-through');
}
e_total_price_obj.text(m_methods.mc_format_number(d_total_price)+'Ä‘');
},
mb_check_all: function(){
if(a_check_all.is(':checked')){
jQuery(b_check_box_child_class).attr('checked', 'checked');
}
},
mc_format_number: function(nStr){
nStr += '';
var x = nStr.split(',');
var x1 = x[0];
var x2 = x.length > 1 ? ',' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + '.' + '$2');
}
return x1 + x2;
},
md_gplus_share_callback: function(repsonse){
//alert(repsonse.state); //on | off
if(repsonse.state == 'on'){
jQuery.ajax({
url: wp_vars.ajaxurl,
dataType: "html",
async: false,
type: "POST",
cache: true,
data: z_this_form.serialize() + '&action=' + wp_vars.action_buy_download + '&do=shared',
success: function(data) {
if(data){
var rs = JSON.parse(data);
if(rs.success == 1){
g_download_iframe.attr('src', rs.url);
}
}
}
});
jQuery('#gplus_share_button').hide();
}
},
me_gplus_render_button: function(){
if(typeof(gapi) != 'undefined'){
gapi.plusone.render("gplus_share_button",{
'callback': m_methods.md_gplus_share_callback,
'width': "65",
'theme': "light",
'recommendations': false,
'count': true,
'action': "share",
'annotation': "bubble", //none, bubble, inline
'align': "left",
'expandTo': "top", //top, right, bottom, left
'size': 'medium', //small, medium, standard, tall
});
}
}
}
a_check_all.change(function(evt){
if(a_check_all.is(':checked')){
jQuery(b_check_box_child_class).attr('checked', 'checked');
}else{
jQuery(b_check_box_child_class).removeAttr('checked');
}
m_methods.ma_update_price();
});
jQuery(b_check_box_child_class).change(function(evt){
m_methods.ma_update_price();
});
h_facebook_share.click(function(evt){
var url = jQuery(this).attr("data-url");
var id = jQuery(this).attr("data-id");
var obj = {
method: 'feed',
link: url,
};
function callback(response) {
if (response !== null && response !== undefined) {
jQuery.ajax({
url: wp_vars.ajaxurl,
dataType: "html",
async: false,
type: "POST",
cache: true,
data: z_this_form.serialize() + '&action=' + wp_vars.action_buy_download + '&do=shared',
success: function(data) {
if(data){
var rs = JSON.parse(data);
if(rs.success == 1){
g_download_iframe.attr('src', rs.url);
}
}
}
});
} else {
}
}
FB.ui(obj, callback);
});
z_this_form.bind('submit', function(evt){
//var post_data = jQuery(Se);
//post_data[post_data.length] = { name: "action", value: wp_vars.action_buy_download};
jQuery.ajax({
url: wp_vars.ajaxurl,
dataType: "html",
async: false,
type: "POST",
cache: true,
data: jQuery(this).serialize() + '&action=' + wp_vars.action_buy_download,
success: function(data) {
if(data){
var rs = JSON.parse(data);
if(rs.success == 1){
g_download_iframe.attr('src', rs.url);
}
}
}
});
return false;
});
//Init
m_methods.mb_check_all();
m_methods.ma_update_price();
m_methods.me_gplus_render_button();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment