PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/wp-e-commerce/js/wp-e-commerce.js

https://gitlab.com/endomorphosis/reservationtelco
JavaScript | 368 lines | 283 code | 46 blank | 39 comment | 46 complexity | b663401b46ebcc1a12b924d5ed89449a MD5 | raw file
  1. // This is the wp-e-commerce front end javascript "library"
  2. // empty the cart using ajax when the form is submitted,
  3. function check_make_purchase_button(){
  4. toggle = jQuery('#noca_gateway').attr('checked');
  5. if(toggle == true){
  6. //jQuery('.make_purchase').hide();
  7. jQuery('#OCPsubmit').show();
  8. }else{
  9. jQuery('.make_purchase').show();
  10. jQuery('#OCPsubmit').hide();
  11. }
  12. }
  13. // this function is for binding actions to events and rebinding them after they are replaced by AJAX
  14. // these functions are bound to events on elements when the page is fully loaded.
  15. jQuery(document).ready(function () {
  16. //this bit of code runs on the checkout page. If the checkbox is selected it copies the valus in the billing country and puts it in the shipping country form fields. 23.07.09
  17. //jQuery('.wpsc_shipping_forms').hide();
  18. jQuery("#shippingSameBilling").click(function(){
  19. jQuery('.wpsc_shipping_forms').show();
  20. // If checked
  21. jQuery("#shippingSameBilling").livequery(function(){
  22. if(jQuery(this).is(":checked")){
  23. var fname = jQuery("input[title='billingfirstname']").val();
  24. var lname = jQuery("input[title='billinglastname']").val();
  25. var addr = jQuery("textarea[title='billingaddress']").val();
  26. var city = jQuery("input[title='billingcity']").val();
  27. var pcode = jQuery("input[title='billingpostcode']").val();
  28. var phone = jQuery("input[title='billingphone']").val();
  29. var email = jQuery("input[title='billingfirstname']").val();
  30. var state = jQuery("select[title='billingregion'] :selected").text();
  31. var stateID = jQuery("select[title='billingregion'] :selected").val();
  32. var country = jQuery("select[title='billingcountry'] :selected").text();
  33. var countryID = jQuery("select[title='billingcountry'] :selected").val();
  34. var shipID;
  35. var shipName;
  36. jQuery("input[title='shippingfirstname']").val(fname);
  37. jQuery("input[title='shippinglastname']").val(lname);
  38. jQuery("textarea[title='shippingaddress']").val(addr);
  39. jQuery("input[title='shippingcity']").val(city);
  40. jQuery("input[title='shippingpostcode']").val(pcode);
  41. jQuery("input[title='shippingphone']").val(phone);
  42. jQuery("input[title='shippingemail']").val(email);
  43. jQuery("input[title='shippingstate']").val(stateID);
  44. jQuery("input.shipping_country").val(countryID);
  45. jQuery("span.shipping_country_name").html(country);
  46. jQuery("input.shipping_region").val(countryID);
  47. //jQuery("span.shipping_region_name").html(state);
  48. jQuery("select#current_country").val(countryID);
  49. if(state == ''){
  50. state = jQuery("select.current_region :selected").text();
  51. stateID = jQuery("select.current_region :selected").val();
  52. if(state == ''){
  53. jQuery("select#region").hide();
  54. shipName = jQuery('input.shipping_region').attr('name');
  55. shipID = jQuery('input.shipping_region').attr('id');
  56. jQuery('input.shipping_region').replaceWith('<input class="shipping_region" type="text" value="'+state+'" name="'+shipName+'" id="'+shipName+'" />');
  57. jQuery('span.shipping_region_name').replaceWith('<span class="shipping_region_name"></span>');
  58. }else{
  59. jQuery("select#region").show();
  60. jQuery("select#region :selected").html(state).attr('selected','selected');
  61. shipName = jQuery('input.shipping_region').attr('name');
  62. shipID = jQuery('input.shipping_region').attr('id');
  63. jQuery('input.shipping_region').replaceWith('<input type="hidden" value="'+stateID+'" name="'+shipName+'" id="'+shipName+'" class="shipping_region" />');
  64. jQuery('input.shipping_region').append('<span class="shipping_region_name">'+state+'</span>');
  65. // jQuery('span.shipping_region_name').html(state);
  66. }
  67. }else{
  68. jQuery("select#region").show();
  69. shipName = jQuery('input.shipping_region').attr('name');
  70. shipID = jQuery('input.shipping_region').attr('id');
  71. jQuery('input.shipping_region').replaceWith('<input type="hidden" class="shipping_region" value="'+stateID+'" name="'+shipName+'" id="'+shipName+'" />');
  72. jQuery('.shipping_region_name').replaceWith('<span class="shipping_region_name">'+state+'</span>');
  73. jQuery("select#region :selected").html(state).attr('selected','selected');
  74. jQuery("select[title='shippingregion']").val(stateID);
  75. //jQuery('span.shipping_region_name').html(state);
  76. }
  77. jQuery("select[title='shipping_country']").val(countryID);
  78. var html_form_id = jQuery("select[title='shipping_country']").attr('id');
  79. var form_id = jQuery("select[title='shipping_country']").attr('name');
  80. if(form_id != null){
  81. form_id = form_id.replace("collected_data[", "");
  82. form_id = form_id.replace("]", "");
  83. form_id = form_id.replace("[0]", "");
  84. set_shipping_country(html_form_id, form_id)
  85. if(jQuery("select[title='billingcountry'] :selected").val() != jQuery("select[name='country'] :selected").val()){
  86. id = jQuery("select[name='country'] :selected").val();
  87. if(id == 'undefined'){
  88. jQuery("select[name='country']").val(countryID);
  89. // submit_change_country();
  90. }
  91. }
  92. }
  93. submit_change_country(true);
  94. }
  95. //otherwise, hide it
  96. //jQuery("#extra").hide("fast");
  97. });
  98. });
  99. // Submit the product form using AJAX
  100. jQuery("form.product_form").submit(function() {
  101. // we cannot submit a file through AJAX, so this needs to return true to submit the form normally if a file formfield is present
  102. file_upload_elements = jQuery.makeArray(jQuery('input[type=file]', jQuery(this)));
  103. if(file_upload_elements.length > 0) {
  104. return true;
  105. } else {
  106. form_values = jQuery(this).serialize();
  107. // Sometimes jQuery returns an object instead of null, using length tells us how many elements are in the object, which is more reliable than comparing the object to null
  108. if(jQuery('#fancy_notification').length == 0) {
  109. jQuery('div.wpsc_loading_animation',this).css('visibility', 'visible');
  110. }
  111. jQuery.post( 'index.php?ajax=true', form_values, function(returned_data) {
  112. eval(returned_data);
  113. jQuery('div.wpsc_loading_animation').css('visibility', 'hidden');
  114. if(jQuery('#fancy_notification') != null) {
  115. jQuery('#loading_animation').css("display", 'none');
  116. //jQuery('#fancy_notificationimage').css("display", 'none');
  117. }
  118. });
  119. wpsc_fancy_notification(this);
  120. return false;
  121. }
  122. });
  123. jQuery('a.wpsc_category_link, a.wpsc_category_image_link').click(function(){
  124. product_list_count = jQuery.makeArray(jQuery('ul.category-product-list'));
  125. if(product_list_count.length > 0) {
  126. jQuery('ul.category-product-list', jQuery(this).parent()).toggle();
  127. return false;
  128. }
  129. });
  130. // this is for storing data with the product image, like the product ID, for things like dropshop and the the ike.
  131. jQuery("form.product_form").livequery(function(){
  132. product_id = jQuery('input[name=product_id]',this).val();
  133. image_element_id = 'product_image_'+product_id;
  134. jQuery("#"+image_element_id).data("product_id", product_id);
  135. parent_container = jQuery(this).parents('div.product_view_'+product_id);
  136. jQuery("div.item_no_image", parent_container).data("product_id", product_id);
  137. });
  138. //jQuery("form.product_form").trigger('load');
  139. // Toggle the additional description content
  140. jQuery("a.additional_description_link").click(function() {
  141. parent_element = jQuery(this).parent('.additional_description_span');
  142. jQuery('.additional_description',parent_element).toggle();
  143. return false;
  144. });
  145. // update the price when the variations are altered.
  146. jQuery("div.wpsc_variation_forms .wpsc_select_variation").change(function() {
  147. parent_form = jQuery(this).parents("form.product_form");
  148. form_values =jQuery("input[name=product_id],div.wpsc_variation_forms .wpsc_select_variation",parent_form).serialize( );
  149. jQuery.post( 'index.php?update_product_price=true', form_values, function(returned_data) {
  150. eval(returned_data);
  151. if(product_id != null) {
  152. target_id = "product_price_"+product_id;
  153. second_target_id = "donation_price_"+product_id;
  154. buynow_id = "BB_BuyButtonForm"+product_id;
  155. //document.getElementById(target_id).firstChild.innerHTML = price;
  156. if(jQuery("input#"+target_id).attr('type') == 'text') {
  157. jQuery("input#"+target_id).val(numeric_price);
  158. } else {
  159. jQuery("#"+target_id+".pricedisplay").html(price);
  160. }
  161. jQuery("input#"+second_target_id).val(numeric_price);
  162. }
  163. });
  164. return false;
  165. });
  166. // Object frame destroying code.
  167. jQuery("div.shopping_cart_container").livequery(function(){
  168. object_html = jQuery(this).html();
  169. window.parent.jQuery("div.shopping-cart-wrapper").html(object_html);
  170. });
  171. // Ajax cart loading code.
  172. jQuery("div.wpsc_cart_loading").livequery(function(){
  173. form_values = "ajax=true"
  174. jQuery.post( 'index.php?wpsc_ajax_action=get_cart', form_values, function(returned_data) {
  175. eval(returned_data);
  176. });
  177. });
  178. // Object frame destroying code.
  179. jQuery("form.wpsc_product_rating").livequery(function(){
  180. jQuery(this).rating();
  181. });
  182. jQuery("form.wpsc_empty_the_cart").livequery(function(){
  183. jQuery(this).submit(function() {
  184. form_values = "ajax=true&";
  185. form_values += jQuery(this).serialize();
  186. jQuery.post( 'index.php', form_values, function(returned_data) {
  187. eval(returned_data);
  188. });
  189. return false;
  190. });
  191. });
  192. jQuery("form.wpsc_empty_the_cart span.emptycart a").livequery(function(){
  193. jQuery(this).click(function() {
  194. parent_form = jQuery(this).parents("form.wpsc_empty_the_cart");
  195. form_values = "ajax=true&";
  196. form_values += jQuery(parent_form).serialize();
  197. jQuery.post( 'index.php', form_values, function(returned_data) {
  198. eval(returned_data);
  199. });
  200. return false;
  201. });
  202. });
  203. //Shipping bug fix by James Collins
  204. var radios = jQuery(".productcart input:radio[name=shipping_method]");
  205. if (radios.length == 1) {
  206. // If there is only 1 shipping quote available during checkout, automatically select it
  207. jQuery(radios).click();
  208. } else if (radios.length > 1) {
  209. // There are multiple shipping quotes, simulate a click on the checked one
  210. jQuery(".productcart input:radio[name=shipping_method]:checked").click();
  211. }
  212. });
  213. // update the totals when shipping methods are changed.
  214. function switchmethod(key,key1){
  215. // total=document.getElementById("shopping_cart_total_price").value;
  216. form_values = "ajax=true&";
  217. form_values += "wpsc_ajax_action=update_shipping_price&";
  218. form_values += "key1="+key1+"&";
  219. form_values += "key="+key;
  220. jQuery.post( 'index.php', form_values, function(returned_data) {
  221. eval(returned_data);
  222. });
  223. }
  224. // submit the country forms.
  225. function submit_change_country(ajax){
  226. if(!ajax){
  227. document.forms.change_country.submit();
  228. }else{
  229. var country_code = jQuery('#current_country :selected').val();
  230. var params = 'ajax=true&wpsc_ajax_actions=update_location&country='+country_code;
  231. var region_code = jQuery('#region :selected').val();
  232. if(typeof(region_code) != 'undefined'){
  233. params += '&region='+region_code;
  234. }
  235. jQuery.post( 'index.php', params, function(returned_data) { });
  236. jQuery.post( 'index.php', 'wpsc_ajax_action=update_shipping_price', function(returned_data) {
  237. eval(returned_data);
  238. });
  239. }
  240. }
  241. // submit the fancy notifications forms.
  242. function wpsc_fancy_notification(parent_form){
  243. if(typeof(WPSC_SHOW_FANCY_NOTIFICATION) == 'undefined'){
  244. WPSC_SHOW_FANCY_NOTIFICATION = true;
  245. }
  246. if((WPSC_SHOW_FANCY_NOTIFICATION == true) && (jQuery('#fancy_notification') != null)){
  247. var options = {
  248. margin: 1 ,
  249. border: 1 ,
  250. padding: 1 ,
  251. scroll: 1
  252. };
  253. form_button_id = jQuery(parent_form).attr('id') + "_submit_button";
  254. //console.log(form_button_id);
  255. //return;
  256. var container_offset = {};
  257. new_container_offset = jQuery('#products_page_container').offset();
  258. if(container_offset['left'] == null) {
  259. container_offset['left'] = new_container_offset.left;
  260. container_offset['top'] = new_container_offset.top;
  261. }
  262. var button_offset = {};
  263. new_button_offset = jQuery('#'+form_button_id).offset()
  264. if(button_offset['left'] == null) {
  265. button_offset['left'] = new_button_offset.left;
  266. button_offset['top'] = new_button_offset.top;
  267. }
  268. // console.log((button_offset['left'] - container_offset['left'] + 10));
  269. jQuery('#fancy_notification').css("left", (button_offset['left'] - container_offset['left'] + 10) + 'px');
  270. jQuery('#fancy_notification').css("top", ((button_offset['top'] - container_offset['top']) -60) + 'px');
  271. jQuery('#fancy_notification').css("display", 'block');
  272. jQuery('#loading_animation').css("display", 'block');
  273. jQuery('#fancy_notification_content').css("display", 'none');
  274. }
  275. }
  276. function shopping_cart_collapser() {
  277. switch(jQuery("#sliding_cart").css("display")) {
  278. case 'none':
  279. jQuery("#sliding_cart").slideToggle("fast",function(){
  280. jQuery.post( 'index.php', "ajax=true&set_slider=true&state=1", function(returned_data) { });
  281. jQuery("#fancy_collapser").attr("src", (WPSC_URL+"/images/minus.png"));
  282. });
  283. break;
  284. default:
  285. jQuery("#sliding_cart").slideToggle("fast",function(){
  286. jQuery.post( 'index.php', "ajax=true&set_slider=true&state=0", function(returned_data) { });
  287. jQuery("#fancy_collapser").attr("src", (WPSC_URL+"/images/plus.png"));
  288. });
  289. break;
  290. }
  291. return false;
  292. }
  293. function set_billing_country(html_form_id, form_id){
  294. var billing_region = '';
  295. country = jQuery(("select[class=current_country]")).val();
  296. region = jQuery(("select[class=current_region]")).val();
  297. if(/[\d]{1,}/.test(region)) {
  298. billing_region = "&billing_region="+region;
  299. }
  300. form_values = "wpsc_ajax_action=change_tax&form_id="+form_id+"&billing_country="+country+billing_region;
  301. jQuery.post( 'index.php', form_values, function(returned_data) {
  302. eval(returned_data);
  303. });
  304. //ajax.post("index.php",changetaxntotal,("ajax=true&form_id="+form_id+"&billing_country="+country+billing_region));
  305. }
  306. function set_shipping_country(html_form_id, form_id){
  307. var shipping_region = '';
  308. country = jQuery(("div#"+html_form_id+" select[class=current_country]")).val();
  309. if(country == 'undefined'){
  310. // alert(country);
  311. country = jQuery("select[title='billingcountry']").val();
  312. }
  313. region = jQuery(("div#"+html_form_id+" select[class=current_region]")).val();
  314. if(/[\d]{1,}/.test(region)) {
  315. shipping_region = "&shipping_region="+region;
  316. }
  317. form_values = "wpsc_ajax_action=change_tax&form_id="+form_id+"&shipping_country="+country+shipping_region;
  318. jQuery.post( 'index.php', form_values, function(returned_data) {
  319. eval(returned_data);
  320. });
  321. //ajax.post("index.php",changetaxntotal,("ajax=true&form_id="+form_id+"&billing_country="+country+billing_region));
  322. }