diff --git a/js/jquery.addressfield/jquery.addressfield.js b/js/jquery.addressfield/jquery.addressfield.js index 99c96ad..fdcdfb5 100644 --- a/js/jquery.addressfield/jquery.addressfield.js +++ b/js/jquery.addressfield/jquery.addressfield.js @@ -1,6 +1,6 @@ -/*! Address Field - v1.0.1 - 2014-12-01 +/*! Address Field - v1.0.2 - 2015-06-18 * https://github.com/tableau-mkt/jquery.addressfield -* Copyright (c) 2014 Eric Peterson; Licensed MIT */ +* Copyright (c) 2015 Eric Peterson; Licensed MIT */ (function ($) { /** @@ -191,7 +191,7 @@ $.fn.addressfield.binder = function(fieldMap, countryConfigMap) { var $container = this; - $(fieldMap.country).bind('change', function() { + $container.find(fieldMap.country).bind('change', function() { // Trigger the apply method with the country's data. $.fn.addressfield.apply.call($container, countryConfigMap[this.value], fieldMap); }); diff --git a/js/jquery.addressfield/jquery.addressfield.min.js b/js/jquery.addressfield/jquery.addressfield.min.js index 380c189..43debd4 100644 --- a/js/jquery.addressfield/jquery.addressfield.min.js +++ b/js/jquery.addressfield/jquery.addressfield.min.js @@ -1,4 +1,4 @@ -/*! Address Field - v1.0.1 - 2014-12-01 +/*! Address Field - v1.0.2 - 2015-06-18 * https://github.com/tableau-mkt/jquery.addressfield -* Copyright (c) 2014 Eric Peterson; Licensed MIT */ -!function(a){a.fn.addressfield=function(b){var c=this,d=a.extend({fields:{},json:null,async:!0,defs:{fields:{}}},b);return"string"==typeof d.json?(a.ajax({dataType:"json",url:d.json,async:d.async,success:function(b){a.fn.addressfield.binder.call(c,d.fields,a.fn.addressfield.transform(b)),a(d.fields.country).change()}}),c):"object"==typeof d.json&&null!==d.json?(a.fn.addressfield.binder.call(c,d.fields,a.fn.addressfield.transform(d.json)),a(d.fields.country).change(),c):a.fn.addressfield.apply.call(c,d.defs,d.fields)},a.fn.addressfield.apply=function(b,c){var d,e,f,g,h,i=a(this),j=[];for(g in b.fields){if(h=a.fn.addressfield.onlyKey(b.fields[g]),e=c.hasOwnProperty(h)?c[h]:"."+h,d=i.find(e),b.fields[g][h]instanceof Array)return a.fn.addressfield.apply.call(d,{fields:b.fields[g][h]},c);d.length&&c.hasOwnProperty(h)&&(j.push(e),"undefined"!=typeof b.fields[g][h].options?(d.is("select")||(d=a.fn.addressfield.convertToSelect.call(d)),a.fn.addressfield.updateOptions.call(d,b.fields[g][h].options)):(d.is("select")&&(d=a.fn.addressfield.convertToText.call(d)),f=b.fields[g][h].hasOwnProperty("eg")?b.fields[g][h].eg:"",a.fn.addressfield.updateEg.call(d,f)),a.fn.addressfield.updateLabel.call(d,b.fields[g][h].label)),!a.fn.addressfield.isVisible.call(d)&&c.hasOwnProperty(h)&&a.fn.addressfield.showField.call(d),a.fn.addressfield.validate.call(d,h,b.fields[g][h])}return a.each(c,function(c,d){var e=i.find(d);e.length&&!a.fn.addressfield.hasField(b,c)&&a.fn.addressfield.hideField.call(e)}),a.fn.addressfield.orderFields.call(i,j),i.trigger("addressfield:after",{config:b,fieldMap:c}),this},a.fn.addressfield.binder=function(b,c){var d=this;return a(b.country).bind("change",function(){a.fn.addressfield.apply.call(d,c[this.value],b)}),d},a.fn.addressfield.transform=function(a){var b,c={};for(b in a.options)c[a.options[b].iso]=a.options[b];return c},a.fn.addressfield.onlyKey=function(a){for(var b in a)return b},a.fn.addressfield.hasField=function(b,c){var d,e;for(d in b.fields){if(e=a.fn.addressfield.onlyKey(b.fields[d]),b.fields[d][e]instanceof Array)return a.fn.addressfield.hasField({fields:b.fields[d][e]},c);if(e===c)return!0}return!1},a.fn.addressfield.updateLabel=function(b){var c=a(this),d=c.attr("id"),e=a('label[for="'+d+'"]')||c.prev("label");e.text(b)},a.fn.addressfield.updateEg=function(b){var c=b?"e.g. "+b:"";a(this).attr("placeholder",c)},a.fn.addressfield.updateOptions=function(b){var c=a(this),d=c.data("_saved")||c.val();c.children("option").remove(),a.each(b,function(d){var e=a.fn.addressfield.onlyKey(b[d]);c.append(a("").attr("value",e).text(b[d][e]))}),c.val(d).change(),c.removeData("_saved")},a.fn.addressfield.convertToText=function(){var b=a(this),c=a("").attr("type","text");return a.fn.addressfield.copyAttrsTo.call(b,c),c.val(b.val()),b.replaceWith(c),c},a.fn.addressfield.convertToSelect=function(){var b=a(this),c=a("");return a.fn.addressfield.copyAttrsTo.call(b,c),c.data("_saved",b.val()),b.replaceWith(c),c},a.fn.addressfield.validate=function(b,c){var d=a(this),e="isValid_"+b,f={},g="Please check your formatting.";"undefined"!=typeof a.validator&&(g=a.validator.messages.hasOwnProperty(e)?a.validator.messages[e]:g,c.hasOwnProperty("format")?(a.validator.addMethod(e,function(b){return new RegExp(c.format).test(a.trim(b.toString()))},g),f[e]=!0,d.rules("add",f)):a.validator.addMethod(e,function(){return!0},g))},a.fn.addressfield.hideField=function(){a(this).val("").hide(),a.fn.addressfield.container.call(this).hide()},a.fn.addressfield.showField=function(){this.show(),a.fn.addressfield.container.call(this).show()},a.fn.addressfield.isVisible=function(){return a(this).is(":visible")},a.fn.addressfield.container=function(){var b=a(this),c=b.attr("id"),d=a('label[for="'+c+'"]')||b.prev("label");return"function"==typeof a.fn.has?b.parents().has(d).first():b.parents().find(":has(label):has(#"+c+"):last")},a.fn.addressfield.copyAttrsTo=function(b){var c=["class","id","name","propdescname"],d=a(this);a.each(d[0].attributes,function(){-1!==a.inArray(this.name,c)&&("propdescname"===this.name?b.attr("name",this.value):b.attr(this.name,this.value))})},a.fn.addressfield.orderFields=function(b){var c,d,e=b.length;for(c=0;e>c;++c)c in b&&(d=a.fn.addressfield.container.call(this.find(b[c])),b[c]={element:d.clone(),selector:b[c],value:a(this).find(b[c]).val()},d.remove());for(c=0;e>c;++c)c in b&&(d=a(this).append(b[c].element),d.find(b[c].selector).val(b[c].value).change())}}(jQuery); \ No newline at end of file +* Copyright (c) 2015 Eric Peterson; Licensed MIT */ +!function(a){a.fn.addressfield=function(b){var c=this,d=a.extend({fields:{},json:null,async:!0,defs:{fields:{}}},b);return"string"==typeof d.json?(a.ajax({dataType:"json",url:d.json,async:d.async,success:function(b){a.fn.addressfield.binder.call(c,d.fields,a.fn.addressfield.transform(b)),a(d.fields.country).change()}}),c):"object"==typeof d.json&&null!==d.json?(a.fn.addressfield.binder.call(c,d.fields,a.fn.addressfield.transform(d.json)),a(d.fields.country).change(),c):a.fn.addressfield.apply.call(c,d.defs,d.fields)},a.fn.addressfield.apply=function(b,c){var d,e,f,g,h,i=a(this),j=[];for(g in b.fields){if(h=a.fn.addressfield.onlyKey(b.fields[g]),e=c.hasOwnProperty(h)?c[h]:"."+h,d=i.find(e),b.fields[g][h]instanceof Array)return a.fn.addressfield.apply.call(d,{fields:b.fields[g][h]},c);d.length&&c.hasOwnProperty(h)&&(j.push(e),"undefined"!=typeof b.fields[g][h].options?(d.is("select")||(d=a.fn.addressfield.convertToSelect.call(d)),a.fn.addressfield.updateOptions.call(d,b.fields[g][h].options)):(d.is("select")&&(d=a.fn.addressfield.convertToText.call(d)),f=b.fields[g][h].hasOwnProperty("eg")?b.fields[g][h].eg:"",a.fn.addressfield.updateEg.call(d,f)),a.fn.addressfield.updateLabel.call(d,b.fields[g][h].label)),!a.fn.addressfield.isVisible.call(d)&&c.hasOwnProperty(h)&&a.fn.addressfield.showField.call(d),a.fn.addressfield.validate.call(d,h,b.fields[g][h])}return a.each(c,function(c,d){var e=i.find(d);e.length&&!a.fn.addressfield.hasField(b,c)&&a.fn.addressfield.hideField.call(e)}),a.fn.addressfield.orderFields.call(i,j),i.trigger("addressfield:after",{config:b,fieldMap:c}),this},a.fn.addressfield.binder=function(b,c){var d=this;return d.find(b.country).bind("change",function(){a.fn.addressfield.apply.call(d,c[this.value],b)}),d},a.fn.addressfield.transform=function(a){var b,c={};for(b in a.options)c[a.options[b].iso]=a.options[b];return c},a.fn.addressfield.onlyKey=function(a){for(var b in a)return b},a.fn.addressfield.hasField=function(b,c){var d,e;for(d in b.fields){if(e=a.fn.addressfield.onlyKey(b.fields[d]),b.fields[d][e]instanceof Array)return a.fn.addressfield.hasField({fields:b.fields[d][e]},c);if(e===c)return!0}return!1},a.fn.addressfield.updateLabel=function(b){var c=a(this),d=c.attr("id"),e=a('label[for="'+d+'"]')||c.prev("label");e.text(b)},a.fn.addressfield.updateEg=function(b){var c=b?"e.g. "+b:"";a(this).attr("placeholder",c)},a.fn.addressfield.updateOptions=function(b){var c=a(this),d=c.data("_saved")||c.val();c.children("option").remove(),a.each(b,function(d){var e=a.fn.addressfield.onlyKey(b[d]);c.append(a("").attr("value",e).text(b[d][e]))}),c.val(d).change(),c.removeData("_saved")},a.fn.addressfield.convertToText=function(){var b=a(this),c=a("").attr("type","text");return a.fn.addressfield.copyAttrsTo.call(b,c),c.val(b.val()),b.replaceWith(c),c},a.fn.addressfield.convertToSelect=function(){var b=a(this),c=a("");return a.fn.addressfield.copyAttrsTo.call(b,c),c.data("_saved",b.val()),b.replaceWith(c),c},a.fn.addressfield.validate=function(b,c){var d=a(this),e="isValid_"+b,f={},g="Please check your formatting.";"undefined"!=typeof a.validator&&(g=a.validator.messages.hasOwnProperty(e)?a.validator.messages[e]:g,c.hasOwnProperty("format")?(a.validator.addMethod(e,function(b){return new RegExp(c.format).test(a.trim(b.toString()))},g),f[e]=!0,d.rules("add",f)):a.validator.addMethod(e,function(){return!0},g))},a.fn.addressfield.hideField=function(){a(this).val("").hide(),a.fn.addressfield.container.call(this).hide()},a.fn.addressfield.showField=function(){this.show(),a.fn.addressfield.container.call(this).show()},a.fn.addressfield.isVisible=function(){return a(this).is(":visible")},a.fn.addressfield.container=function(){var b=a(this),c=b.attr("id"),d=a('label[for="'+c+'"]')||b.prev("label");return"function"==typeof a.fn.has?b.parents().has(d).first():b.parents().find(":has(label):has(#"+c+"):last")},a.fn.addressfield.copyAttrsTo=function(b){var c=["class","id","name","propdescname"],d=a(this);a.each(d[0].attributes,function(){-1!==a.inArray(this.name,c)&&("propdescname"===this.name?b.attr("name",this.value):b.attr(this.name,this.value))})},a.fn.addressfield.orderFields=function(b){var c,d,e=b.length;for(c=0;e>c;++c)c in b&&(d=a.fn.addressfield.container.call(this.find(b[c])),b[c]={element:d.clone(),selector:b[c],value:a(this).find(b[c]).val()},d.remove());for(c=0;e>c;++c)c in b&&(d=a(this).append(b[c].element),d.find(b[c].selector).val(b[c].value).change())}}(jQuery); \ No newline at end of file diff --git a/scale_addressfield.module b/scale_addressfield.module index b115bc3..551e701 100644 --- a/scale_addressfield.module +++ b/scale_addressfield.module @@ -108,7 +108,7 @@ function scale_addressfield_library() { $path = drupal_get_path('module', 'scale_addressfield'); $items['jquery.addressfield'] = array( 'title' => 'jquery.addressfield', - 'version' => '1.0.1', + 'version' => '1.0.2', 'js' => array( $path . '/js/jquery.addressfield/jquery.addressfield.min.js' => array( 'group' => JS_LIBRARY,