Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
integration:foxycart:multiship_javascript_070 [2010/11/24 05:08] – Removing console.info statements as they are throwing js errors. 98.193.202.154integration:foxycart:multiship_javascript_070 [2017/04/26 07:02] (current) – external edit 127.0.0.1
Line 1: Line 1:
----- dataentry ---- +---- dataentry  ---- 
-type          : integration # do not change this line +type          : integration #do not change this line 
-systems       : FoxyCart # the system(s) that the integration is for, separated with commas if more than one +systems       : FoxyCart #the system(s) that the integration is for, separated with commas if more than one 
-name          : multiship_jquery_070 # the name of the integration +name          : multiship_jquery_070#the name of the integration 
-description   : jQuery to automatically create a select box ("drop down") with previously entered ship-to addresses, with showing/hiding of the "New recipient" field. +description   : (FC 0.7.0+) jQuery to automatically create a select box ("drop down") with previously entered ship-to addresses, with showing/hiding of the "New recipient" field. 
-tags_tags     : multiship # tags, separated by commas. don't include the "system" here. +tags          : multiship #tags, separated by commas. don't include the "system" here. 
-date_dt       : 2010-11-16 # the date in YYYY-MM-DD format +date_dt       : 2011-06-20 #the date in YYYY-MM-DD format 
-version       : 2.1 # if you have a version for your code, enter it here+version       : 2.#if you have a version for your code, enter it here
 FC version    : 070+ FC version    : 070+
-developer_url : www.foxycart.com # if you'd like a link back to your site, stick it here+developer_url : http://www.foxycart.com #if you'd like a link back to your site, stick it here
 ---- ----
  
  
 ====== multiship javascript ====== ====== multiship javascript ======
 +
 +<WRAP important round>
 +//**Please note:**//
 +The code on this page is submitted by members of the FoxyCart community, and may not verified by FoxyCart.com LLC in any way, shape, or form. Please double check the code before installing. If you need help with it please [[http://forum.foxycart.com/|post in our forum]], but if we cannot offer assistance (due to unfamiliarity with this particular system or language) we apologize in advance.
 +</WRAP>
 +
 ===== Description ===== ===== Description =====
 Quickly and easily add multiple ship-to addresses to your FoxyCart site by including a single javascript file and adding a few classes to your "add to cart" forms. It looks something like this: Quickly and easily add multiple ship-to addresses to your FoxyCart site by including a single javascript file and adding a few classes to your "add to cart" forms. It looks something like this:
Line 58: Line 64:
 /* /*
  FoxyCart Multiship Javascript  FoxyCart Multiship Javascript
- v2.1 + v2.4 
- 2010-11-16+ 2013-03-02
    
  INSTRUCTIONS:  INSTRUCTIONS:
Line 74: Line 80:
  jQuery('div.shipto_select').show();  jQuery('div.shipto_select').show();
  jQuery('div.shipto_name').hide();  jQuery('div.shipto_name').hide();
 + jQuery('div.shipto_name input').val("");
 } }
    
Line 100: Line 107:
  jQuery.each(shipto, function(i, val){  jQuery.each(shipto, function(i, val){
  // alert('starting the .each loop with: ' + i + ' = ' + val);  // alert('starting the .each loop with: ' + i + ' = ' + val);
- if (val != 'null' && val != '' && val != 'me') {+ if (val != 'undefined' && val != 'null' && val != '' && val != 'Me') {
  shipto_options += '<option value="' + val + '">' + val + '<\/option>';  shipto_options += '<option value="' + val + '">' + val + '<\/option>';
  // alert('and it worked: ' + val);  // alert('and it worked: ' + val);
  }  }
  });  });
- shipto_options += '<option value="">- - - - - - - - -<\/option>';+ if (shipto_options != ''shipto_options += '<option value="">- - - - - - - - -<\/option>';
  }  }
    
Line 112: Line 119:
  shipto_options += '<option value="add_new">Add a new recipient...<\/option>';  shipto_options += '<option value="add_new">Add a new recipient...<\/option>';
  shipto_options += '<option value="">- - - - - - - - -<\/option>';  shipto_options += '<option value="">- - - - - - - - -<\/option>';
- shipto_options += '<option selected="selected" value="me">Yourself<\/option>';+ shipto_options += '<option selected="selected" value="Me">Yourself<\/option>';
    
  // Set the select boxes with the proper values  // Set the select boxes with the proper values
Line 122: Line 129:
  jQuery(this).parents('form').find('div.shipto_name').show();  jQuery(this).parents('form').find('div.shipto_name').show();
  // Set any shipto values. Done this way in case you're adding more than one product at a time.  // Set any shipto values. Done this way in case you're adding more than one product at a time.
- jQuery(this).parents('form').find('input[name$="shipto"]').val(''); + jQuery(this).parents('form').find('input[name*="shipto"]').val(''); 
- // alert(jQuery('input[name="shipto"]').attr('name') + jQuery('input[name="shipto"]').val())+ // alert(jQuery('input[name^="shipto"]').attr('name') + jQuery('input[name^="shipto"]').val())
  } else {  } else {
  jQuery(this).parents('form').find('div.shipto_name').hide();  jQuery(this).parents('form').find('div.shipto_name').hide();
  // Set any shipto values. Done this way in case you're adding more than one product at a time.  // Set any shipto values. Done this way in case you're adding more than one product at a time.
- jQuery(this).parents('form').find('input[name$="shipto"]').val(jQuery(this).val());+ jQuery(this).parents('form').find('input[name*="shipto"]').val(jQuery(this).val());
  }  }
- // console.info(jQuery('input[name="shipto"]').val()); + // console.info(jQuery('input[name^="shipto"]').val()); 
- // console.info(jQuery('input[name="2:shipto"]').val());+ // console.info(jQuery('input[name^="2:shipto"]').val());
  });  });
    
  // Finally, select the last used shipto  // Finally, select the last used shipto
  if (jQuery.cookie('shipto_name_recent') != '') {  if (jQuery.cookie('shipto_name_recent') != '') {
- jQuery('div.shipto_select select').selectOptions(jQuery.cookie('shipto_name_recent'));+ jQuery('div.shipto_select select').val(jQuery.cookie('shipto_name_recent')).change();
  } else {  } else {
- jQuery('div.shipto_select select').selectOptions('me');+ jQuery('div.shipto_select select').val('Me').change();
  }  }
-  +  
- // console.info(jQuery('input[name$="shipto"]').val())+ // console.info(jQuery('input[name*="shipto"]').val())
 } }
    
 // Tie any additional product shipto's to the primary shipto // Tie any additional product shipto's to the primary shipto
 function shipto_multiples() { function shipto_multiples() {
- jQuery('input[name$="shipto"]').change(function(){ + jQuery('input[name*="shipto"]').change(function(){ 
- jQuery(this).parents('form').find('input[name$="shipto"]').val(jQuery(this).val());+ jQuery(this).parents('form').find('input[name*="shipto"]').val(jQuery(this).val());
  });  });
 } }
Line 159: Line 166:
    
 // Set the cookie on cart add // Set the cookie on cart add
-// NOTE: This does not yet work with multiple forms on the same page. +setCookie = function(e, arr) {
-// If you need that, chime in on the FoxyCart forums: http://forum.foxycart.com +
-setCookie = function() {+
  // Run any custom scripts you may have before dealing with,  // Run any custom scripts you may have before dealing with,
  // or just insert your code here  // or just insert your code here
Line 170: Line 175:
  var error = false;  var error = false;
  var shipto_cookie = jQuery.cookie('shipto_names');  var shipto_cookie = jQuery.cookie('shipto_names');
- var shipto_new = jQuery('input[name="shipto"]').eq(0).val();+ var shipto_new = jQuery(e).find('input[name^="shipto"]').eq(0).val();
    
  jQuery.cookie('shipto_name_recent', '', {expires: -1, path: '/', domain: location.host.match('[^.]+.[^.]+$')});  jQuery.cookie('shipto_name_recent', '', {expires: -1, path: '/', domain: location.host.match('[^.]+.[^.]+$')});
  jQuery.cookie('shipto_name_recent', shipto_new, {expires: 300, path: '/', domain: location.host.match('[^.]+.[^.]+$')});  jQuery.cookie('shipto_name_recent', shipto_new, {expires: 300, path: '/', domain: location.host.match('[^.]+.[^.]+$')});
    
- if ((shipto_new != 'undefined') && (shipto_new != 'null') && (shipto_new != 'me')) {+ if ((shipto_new != 'undefined') && (shipto_new != 'null') && (shipto_new != 'Me')) {
  jQuery.cookie('shipto_names', '', {expires: -1, path: '/', domain: location.host.match('[^.]+.[^.]+$')});  jQuery.cookie('shipto_names', '', {expires: -1, path: '/', domain: location.host.match('[^.]+.[^.]+$')});
  jQuery.cookie('shipto_names', shipto_cookie + '||' + shipto_new, {expires: 300, path: '/', domain: location.host.match('[^.]+.[^.]+$')});  jQuery.cookie('shipto_names', shipto_cookie + '||' + shipto_new, {expires: 300, path: '/', domain: location.host.match('[^.]+.[^.]+$')});
Line 182: Line 187:
 } }
    
-constructShipTo = function() {+constructShipTo = function(e, arr) {
  shipto_initialize();  shipto_initialize();
  shipto_select();  shipto_select();
Line 216: Line 221:
 } }
 // ============================================================================ // ============================================================================
-  
-  
-  
    
    
    
 // ============================================================================ // ============================================================================
-/** +/*! 
- * Cookie plugin + jQuery Cookie Plugin v1.3.1 
- * + https://github.com/carhartl/jquery-cookie
- * Copyright (c) 2006 Klaus Hartl (stilbuero.de) +
- Dual licensed under the MIT and GPL licenses: +
- * http://www.opensource.org/licenses/mit-license.php +
- * http://www.gnu.org/licenses/gpl.html+
  *  *
 + * Copyright 2013 Klaus Hartl
 + * Released under the MIT license
  */  */
-  +(function(d){"function"===typeof define&&define.amd?define(["jquery"],d):d(jQuery)})(function(d){function m(a){return a}function n(a){return decodeURIComponent(a.replace(j," "))}function k(a){0===a.indexOf('"')&&(a=a.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\"));try{return e.json?JSON.parse(a):a}catch(c){}}var j=/\+/g,e=d.cookie=function(a,c,b){if(void 0!==c){b=d.extend({},e.defaults,b);if("number"===typeof b.expires){var g=b.expires,f=b.expires=new Date;f.setDate(f.getDate()+g)}c=e.json? 
-/** +JSON.stringify(c):String(c);return document.cookie=[e.raw?a:encodeURIComponent(a),"=",e.raw?c:encodeURIComponent(c),b.expires?"; expires="+b.expires.toUTCString():"",b.path?"; path="+b.path:"",b.domain?"; domain="+b.domain:"",b.secure?"; secure":""].join("")}c=e.raw?m:n;b=document.cookie.split("");for(var g=a?void 0:{},f=0,j=b.length;f<j;f++){var h=b[f].split("="),l=c(h.shift()),h=c(h.join("="));if(a&&a===l){g=k(h);break}a||(g[l]=k(h))}return g};e.defaults={};d.removeCookie=function(a,c){return void 0!== 
- * Create a cookie with the given name and value and other optional parameters. +d.cookie(a)?(d.cookie(a,"",d.extend({},c,{expires:-1})),!0):!1}});
- * +
- * @example $.cookie('the_cookie', 'the_value')+
- * @desc Set the value of a cookie. +
- * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com'securetrue })+
- * @desc Create cookie with all available options. +
- * @example $.cookie('the_cookie', 'the_value')+
- * @desc Create session cookie. +
- * @example $.cookie('the_cookie'null)+
- * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain +
-       used when the cookie was set. +
- * +
- * @param String name The name of the cookie. +
- * @param String value The value of the cookie. +
- * @param Object options An object literal containing key/value pairs to provide optional cookie attributes. +
- * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object. +
-                             If a negative value is specified (e.g. date in the past), the cookie will be deleted. +
-                             If set to null or omitted, the cookie will be session cookie and will not be retained +
-                             when the the browser exits. +
- * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie). +
- * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie). +
- * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will +
-                        require a secure protocol (like HTTPS). +
- * @type undefined +
- * +
- * @name $.cookie +
- * @cat Plugins/Cookie +
- * @author Klaus Hartl/klaus.hartl@stilbuero.de +
- */ +
-  +
-/** +
- * Get the value of a cookie with the given name. +
- * +
- * @example $.cookie('the_cookie')+
- * @desc Get the value of cookie. +
- * +
- * @param String name The name of the cookie. +
- * @return The value of the cookie. +
- * @type String +
- * +
- * @name $.cookie +
- * @cat Plugins/Cookie +
- * @author Klaus Hartl/klaus.hartl@stilbuero.de +
- */ +
-jQuery.cookie = function(namevalueoptions) { +
-    if (typeof value != 'undefined') { // name and value given, set cookie +
-        options options || {}; +
-        if (value === null) { +
-            value ''; +
-            options.expires = -1; +
-        } +
-        var expires = ''; +
-        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { +
-            var date; +
-            if (typeof options.expires == 'number'+
-                date = new Date(); +
-                date.setTime(date.getTime() (options.expires * 24 * 60 * 60 * 1000)); +
-            } else { +
-                date = options.expires; +
-            } +
-            expires = '; expires=' date.toUTCString(); // use expires attribute, max-age is not supported by IE +
-        } +
-        // CAUTIONNeeded to parenthesize options.path and options.domain +
-        // in the following expressionsotherwise they evaluate to undefined +
-        // in the packed version for some reason... +
-        var path = options.path ? '; path=(options.path''; +
-        var domain = options.domain ? '; domain=(options.domain''; +
-        var secure = options.secure ? '; secure''; +
-        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('')+
-    else { // only name given, get cookie +
-        var cookieValue null; +
-        if (document.cookie && document.cookie != '') { +
-            var cookies = document.cookie.split(';'); +
-            for (var = 0; i < cookies.length; i++) { +
-                var cookie jQuery.trim(cookies[i]); +
-                // Does this cookie string begin with the name we want? +
-                if (cookie.substring(0name.length + 1) == (name + '=')) +
-                    cookieValue decodeURIComponent(cookie.substring(name.length + 1)); +
-                    break; +
-                } +
-            } +
-        } +
-        return cookieValue; +
-    } +
-}; +
-// ============================================================================ +
-  +
-  +
-  +
-// ============================================================================ +
-// http://www.mathias-bank.de/2006/11/01/jquery-plugin-select-box-manipulation/ +
-/* +
- * +
- * Copyright (c2006 Sam Collett (http://www.texotela.co.uk) +
- * Licensed under the MIT License: +
- * http://www.opensource.org/licenses/mit-license.php +
- * +
- * Addepted to select an option by Mathias Bank (http://www.mathias-bank.de) +
- */ +
-  +
-/* +
- * Selects an option by value +
- * +
- * @name     selectOptions +
- * @author   Mathias Bank (http://www.mathias-bank.de) +
- * @param    value specifies, which options should be selected +
- * @example  jQuery("#myselect").selectOptions("val1"); +
- * +
- */ +
-jQuery.fn.selectOptions = function(value) { +
- this.each( +
- function() +
- if(this.nodeName.toLowerCase() != "select") return; +
-  +
- // get number of options +
- var optionsLength = this.options.length; +
-  +
-  +
- for(var i = 0; i<optionsLength; i++) { +
- if (this.options[i].value == value) { +
- this.options[i].selected = true; +
- }+
- } +
- } +
- ) +
- return this; +
-}+
 </file> </file>
- 
- 

Site Tools