1/* This is common javascript functions needed by various commerce components. Widgets are wired to call these functions for commerce. */ 2 3/* Because safari is a shit browser, and Apple can't follow a standard, you cannot hide select options to prevent users from seeing them, ony disable. 4Because this creates a trash UX, we ahve to do a workaround here to allow for options to be removed and then re-added instead of just hiding them.*/ 5 6var cTypeOpts = new Array(); //will hold the custom type options for saturation. 7var formatOpts = new Array(); //will hold all format opts, we will add them all then remove them on change. 8 9///When someone selects a purchase for option, we can then scaffold out other cascading drop downs on the screen. 10function Commerce_PurchaseForSelect(select, customerType, format) 11{ 12 13 if (cTypeOpts.length == 0) 14 { 15 $('.commerce_ctype_option').each(function () { 16 cTypeOpts.push($(this)); 17 }); 18 } 19 20 if (formatOpts.length == 0) 21 { 22 $('.commerce_format_option').each(function () { 23 formatOpts.push($(this)); 24 }); 25 } 26 27 console.log(formatOpts); 28 29 //First, what option did they select? 30 var selectedOption = $(select).find('option:selected'); 31 $('#commerece_add_to_cart_button').removeClass('hidden'); 32 $('#commerce_purchase_for_no_selection').addClass('hidden'); 33 //hide all options in customer type. 34 $('.commerce_ctype_option').remove(); //remove all optiosn and prepare for resaturation. 35 for (var i = 0; i < cTypeOpts.length; i ++) 36 { 37 $('.commerce_customertype_select').append(cTypeOpts[i]); 38 } 39 40 if ($(selectedOption).data("type") == "personal") 41 { 42 var first = null; 43 $('.ptype_personal').each(function () { if (first == null) { first = this; } }); 44 $('.ptype_institutional').remove(); 45 //select first avialable option. 46 customerType.val($(first).prop("value")); 47 } 48 else 49 { 50 var first; 51 $('.ptype_institutional').each(function () { if (first == null) { first = this; } }); 52 $('.ptype_personal').remove(); 53 customerType.val($(first).prop("value")); 54 } 55 56 57 //Go ahead and trigger on first selected option. 58 Commerce_CustomerTypeSelect(customerType, format); 59 60} 61 62function Commerce_CustomerTypeSelect(customerType, format) 63{ 64 var selectedOption = $(customerType).find('option:selected'); 65 66 //Remove and reapply. 67 $('.commerce_format_option').remove(); 68 for (var i = 0; i < formatOpts.length; i ++) 69 { 70 $('.commerce_format_select').append(formatOpts[i]); 71 } 72 73 var first = null; 74 $('.commerce_format_option').each(function () { 75 if ($(this).hasClass('format_' + selectedOption.data("cssclean"))) 76 { 77 if (first == null) { first = $(this); } 78 } 79 else 80 { 81 $(this).remove(); 82 } 83 }); 84 85 $(first).prop("selected", true); 86 Commerce_FormatSelect(customerType, format); 87} 88 89function Commerce_FormatSelect(customerType, format) 90{ 91 var selectedType = $(customerType).find('option:selected'); 92 var selectedFormat = $(format).find('option:selected'); 93 94 $('.commerce_cost_option').each(function () { $(this).hide(); }); 95 96 $('.cost_' + selectedType.data("cssclean") + '_' + selectedFormat.data("cssclean")).show(); 97 98 99} 100
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.