From 7d8e1f237475ea0c68b9064297061772a081aab6 Mon Sep 17 00:00:00 2001 From: Daniel Castillo Date: Wed, 8 Jun 2016 21:14:19 -0430 Subject: [PATCH 1/7] add ability for change language --- src/jquery.date-dropdowns.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/jquery.date-dropdowns.js b/src/jquery.date-dropdowns.js index c5d8423..7cf4680 100644 --- a/src/jquery.date-dropdowns.js +++ b/src/jquery.date-dropdowns.js @@ -19,7 +19,9 @@ daySuffixes: true, monthSuffixes: true, monthFormat: 'long', - required: false + required: false, + monthShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'], + monthLong: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Augosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'] }; // The actual plugin constructor @@ -80,8 +82,8 @@ this.internals.currentDay = date.getDate(); this.internals.currentMonth = date.getMonth() + 1; this.internals.currentYear = date.getFullYear(); - this.internals.monthShort = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; - this.internals.monthLong = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; + this.internals.monthShort = this.config.monthShort, + this.internals.monthLong = this.config.monthLong }, /** From bec7caaf0898c8c4bc2510e8d056389bb78751a0 Mon Sep 17 00:00:00 2001 From: Daniel Castillo Date: Wed, 8 Jun 2016 21:32:25 -0430 Subject: [PATCH 2/7] update diet files --- dist/jquery.date-dropdowns.js | 15 +++++---------- dist/jquery.date-dropdowns.min.js | 2 +- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/dist/jquery.date-dropdowns.js b/dist/jquery.date-dropdowns.js index f330431..7cf4680 100644 --- a/dist/jquery.date-dropdowns.js +++ b/dist/jquery.date-dropdowns.js @@ -1,10 +1,3 @@ -/* - * jQuery Date Dropdowns - v1.0.0 - * A simple, customisable date select plugin - * - * Made by Chris Brown - * Under MIT License - */ ;(function ($, window, document, undefined) { 'use strict'; @@ -26,7 +19,9 @@ daySuffixes: true, monthSuffixes: true, monthFormat: 'long', - required: false + required: false, + monthShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'], + monthLong: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Augosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'] }; // The actual plugin constructor @@ -87,8 +82,8 @@ this.internals.currentDay = date.getDate(); this.internals.currentMonth = date.getMonth() + 1; this.internals.currentYear = date.getFullYear(); - this.internals.monthShort = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; - this.internals.monthLong = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; + this.internals.monthShort = this.config.monthShort, + this.internals.monthLong = this.config.monthLong }, /** diff --git a/dist/jquery.date-dropdowns.min.js b/dist/jquery.date-dropdowns.min.js index 0162ef5..0f26977 100644 --- a/dist/jquery.date-dropdowns.min.js +++ b/dist/jquery.date-dropdowns.min.js @@ -5,4 +5,4 @@ * Made by Chris Brown * Under MIT License */ -!function(a,b,c){"use strict";function d(b,c){return this.element=b,this.$element=a(b),this.config=a.extend({},f,c),this.internals={objectRefs:{}},this.init(),this}var e="dateDropdowns",f={defaultDate:null,defaultDateFormat:"yyyy-mm-dd",displayFormat:"dmy",submitFormat:"yyyy-mm-dd",minAge:0,maxAge:120,minYear:null,maxYear:null,submitFieldName:"date",wrapperClass:"date-dropdowns",dropdownClass:null,daySuffixes:!0,monthSuffixes:!0,monthFormat:"long",required:!1};d.message={day:"Day",month:"Month",year:"Year"},a.extend(d.prototype,{init:function(){this.checkForDuplicateElement(),this.setInternalVariables(),this.setupMarkup(),this.buildDropdowns(),this.attachDropdowns(),this.bindChangeEvent(),this.config.defaultDate&&this.populateDefaultDate()},checkForDuplicateElement:function(){return a('input[name="'+this.config.submitFieldName+'"]').length?(a.error("Duplicate element found"),!1):!0},setInternalVariables:function(){var a=new Date;this.internals.currentDay=a.getDate(),this.internals.currentMonth=a.getMonth()+1,this.internals.currentYear=a.getFullYear(),this.internals.monthShort=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],this.internals.monthLong=["January","February","March","April","May","June","July","August","September","October","November","December"]},setupMarkup:function(){var b,c;if("input"===this.element.tagName.toLowerCase()){this.config.defaultDate||(this.config.defaultDate=this.element.value),c=this.$element.attr("type","hidden").wrap('
');var d=this.config.submitFieldName!==f.submitFieldName,e=this.element.hasAttribute("name");e||d?d&&this.$element.attr("name",this.config.submitFieldName):this.$element.attr("name",f.submitFieldName),b=this.$element.parent()}else c=a("",{type:"hidden",name:this.config.submitFieldName}),this.$element.append(c).addClass(this.config.wrapperClass),b=this.$element;return this.internals.objectRefs.pluginWrapper=b,this.internals.objectRefs.hiddenField=c,!0},buildDropdowns:function(){var a,b,c;return a=this.buildDayDropdown(),this.internals.objectRefs.dayDropdown=a,b=this.buildMonthDropdown(),this.internals.objectRefs.monthDropdown=b,c=this.buildYearDropdown(),this.internals.objectRefs.yearDropdown=c,!0},attachDropdowns:function(){var a=this.internals.objectRefs.pluginWrapper,b=this.internals.objectRefs.dayDropdown,c=this.internals.objectRefs.monthDropdown,d=this.internals.objectRefs.yearDropdown;switch(this.config.displayFormat){case"mdy":a.append(c,b,d);break;case"ymd":a.append(d,c,b);break;case"dmy":default:a.append(b,c,d)}return!0},bindChangeEvent:function(){var a=this.internals.objectRefs.dayDropdown,b=this.internals.objectRefs.monthDropdown,c=this.internals.objectRefs.yearDropdown,d=this,e=this.internals.objectRefs;e.pluginWrapper.on("change","select",function(){var f,g,h=a.val(),i=b.val(),j=c.val();return(f=d.checkDate(h,i,j))?(e.dayDropdown.addClass("invalid"),!1):("00"!==e.dayDropdown.val()&&e.dayDropdown.removeClass("invalid"),e.hiddenField.val(""),f||h*i*j===0||(g=d.formatSubmitDate(h,i,j),e.hiddenField.val(g)),void e.hiddenField.change())})},populateDefaultDate:function(){var a=this.config.defaultDate,b=[],c="",d="",e="";switch(this.config.defaultDateFormat){case"yyyy-mm-dd":default:b=a.split("-"),c=b[2],d=b[1],e=b[0];break;case"dd/mm/yyyy":b=a.split("/"),c=b[0],d=b[1],e=b[2];break;case"mm/dd/yyyy":b=a.split("/"),c=b[1],d=b[0],e=b[2];break;case"unix":b=new Date,b.setTime(1e3*a),c=b.getDate()+"",d=b.getMonth()+1+"",e=b.getFullYear(),c.length<2&&(c="0"+c),d.length<2&&(d="0"+d)}return this.internals.objectRefs.dayDropdown.val(c),this.internals.objectRefs.monthDropdown.val(d),this.internals.objectRefs.yearDropdown.val(e),this.internals.objectRefs.hiddenField.val(a),!0===this.checkDate(c,d,e)&&this.internals.objectRefs.dayDropdown.addClass("invalid"),!0},buildBaseDropdown:function(b){var c=b;return this.config.dropdownClass&&(c+=" "+this.config.dropdownClass),a("",{"class":c,name:this.config.submitFieldName+"_["+b+"]",required:this.config.required})},buildDayDropdown:function(){var a,b=this.buildBaseDropdown("day"),e=c.createElement("option");e.setAttribute("value",""),e.appendChild(c.createTextNode(d.message.day)),b.append(e);for(var f=1;10>f;f++)a=this.config.daySuffixes?f+this.getSuffix(f):"0"+f,e=c.createElement("option"),e.setAttribute("value","0"+f),e.appendChild(c.createTextNode(a)),b.append(e);for(var g=10;31>=g;g++)a=g,this.config.daySuffixes&&(a=g+this.getSuffix(g)),e=c.createElement("option"),e.setAttribute("value",g),e.appendChild(c.createTextNode(a)),b.append(e);return b},buildMonthDropdown:function(){var a=this.buildBaseDropdown("month"),b=c.createElement("option");b.setAttribute("value",""),b.appendChild(c.createTextNode(d.message.month)),a.append(b);for(var e=1;12>=e;e++){var f;switch(this.config.monthFormat){case"short":f=this.internals.monthShort[e-1];break;case"long":f=this.internals.monthLong[e-1];break;case"numeric":f=e,this.config.monthSuffixes&&(f+=this.getSuffix(e))}10>e&&(e="0"+e),b=c.createElement("option"),b.setAttribute("value",e),b.appendChild(c.createTextNode(f)),a.append(b)}return a},buildYearDropdown:function(){var a=this.config.minYear,b=this.config.maxYear,e=this.buildBaseDropdown("year"),f=c.createElement("option");f.setAttribute("value",""),f.appendChild(c.createTextNode(d.message.year)),e.append(f),a||(a=this.internals.currentYear-(this.config.maxAge+1)),b||(b=this.internals.currentYear-this.config.minAge);for(var g=b;g>=a;g--)f=c.createElement("option"),f.setAttribute("value",g),f.appendChild(c.createTextNode(g)),e.append(f);return e},getSuffix:function(a){var b="";switch(a%10){case 1:b=a%100===11?"th":"st";break;case 2:b=a%100===12?"th":"nd";break;case 3:b=a%100===13?"th":"rd";break;default:b="th"}return b},checkDate:function(a,b,c){var d;if("00"!==b){var e=new Date(c,b,0).getDate(),f=parseInt(a,10);d=this.updateDayOptions(e,f),d&&this.internals.objectRefs.hiddenField.val("")}return d},updateDayOptions:function(a,b){var d=parseInt(this.internals.objectRefs.dayDropdown.children(":last").val(),10),e="",f="",g=!1;if(d>a){for(;d>a;)this.internals.objectRefs.dayDropdown.children(":last").remove(),d--;b>a&&(g=!0)}else if(a>d)for(;a>d;){e=++d,f=e,this.config.daySuffixes&&(f+=this.getSuffix(d));var h=c.createElement("option");h.setAttribute("value",e),h.appendChild(c.createTextNode(f)),this.internals.objectRefs.dayDropdown.append(h)}return g},formatSubmitDate:function(a,b,c){var d,e;switch(this.config.submitFormat){case"unix":e=new Date,e.setDate(a),e.setMonth(b-1),e.setYear(c),d=Math.round(e.getTime()/1e3);break;default:d=this.config.submitFormat.replace("dd",a).replace("mm",b).replace("yyyy",c)}return d},destroy:function(){var a=this.config.wrapperClass;if(this.$element.hasClass(a))this.$element.empty();else{var b=this.$element.parent(),c=b.find("select");this.$element.unwrap(),c.remove()}}}),a.fn[e]=function(b){return this.each(function(){if("string"==typeof b){var c=Array.prototype.slice.call(arguments,1),f=a.data(this,"plugin_"+e);if("undefined"==typeof f)return a.error("Please initialize the plugin before calling this method."),!1;f[b].apply(f,c)}else a.data(this,"plugin_"+e)||a.data(this,"plugin_"+e,new d(this,b))}),this}}(jQuery,window,document); \ No newline at end of file +!function(e,t,n,i){"use strict";function a(t,n){return this.element=t,this.$element=e(t),this.config=e.extend({},s,n),this.internals={objectRefs:{}},this.init(),this}var r="dateDropdowns",s={defaultDate:null,defaultDateFormat:"yyyy-mm-dd",displayFormat:"dmy",submitFormat:"yyyy-mm-dd",minAge:0,maxAge:120,minYear:null,maxYear:null,submitFieldName:"date",wrapperClass:"date-dropdowns",dropdownClass:null,daySuffixes:!0,monthSuffixes:!0,monthFormat:"long",required:!1,monthShort:["Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic"],monthLong:["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Augosto","Septiembre","Octubre","Noviembre","Diciembre"]};a.message={day:"Day",month:"Month",year:"Year"},e.extend(a.prototype,{init:function(){this.checkForDuplicateElement(),this.setInternalVariables(),this.setupMarkup(),this.buildDropdowns(),this.attachDropdowns(),this.bindChangeEvent(),this.config.defaultDate&&this.populateDefaultDate()},checkForDuplicateElement:function(){return e('input[name="'+this.config.submitFieldName+'"]').length?(e.error("Duplicate element found"),!1):!0},setInternalVariables:function(){var e=new Date;this.internals.currentDay=e.getDate(),this.internals.currentMonth=e.getMonth()+1,this.internals.currentYear=e.getFullYear(),this.internals.monthShort=this.config.monthShort,this.internals.monthLong=this.config.monthLong},setupMarkup:function(){var t,n;if("input"===this.element.tagName.toLowerCase()){this.config.defaultDate||(this.config.defaultDate=this.element.value),n=this.$element.attr("type","hidden").wrap('
');var i=this.config.submitFieldName!==s.submitFieldName,a=this.element.hasAttribute("name");a||i?i&&this.$element.attr("name",this.config.submitFieldName):this.$element.attr("name",s.submitFieldName),t=this.$element.parent()}else n=e("",{type:"hidden",name:this.config.submitFieldName}),this.$element.append(n).addClass(this.config.wrapperClass),t=this.$element;return this.internals.objectRefs.pluginWrapper=t,this.internals.objectRefs.hiddenField=n,!0},buildDropdowns:function(){var e,t,n;return e=this.buildDayDropdown(),this.internals.objectRefs.dayDropdown=e,t=this.buildMonthDropdown(),this.internals.objectRefs.monthDropdown=t,n=this.buildYearDropdown(),this.internals.objectRefs.yearDropdown=n,!0},attachDropdowns:function(){var e=this.internals.objectRefs.pluginWrapper,t=this.internals.objectRefs.dayDropdown,n=this.internals.objectRefs.monthDropdown,i=this.internals.objectRefs.yearDropdown;switch(this.config.displayFormat){case"mdy":e.append(n,t,i);break;case"ymd":e.append(i,n,t);break;case"dmy":default:e.append(t,n,i)}return!0},bindChangeEvent:function(){var e=this.internals.objectRefs.dayDropdown,t=this.internals.objectRefs.monthDropdown,n=this.internals.objectRefs.yearDropdown,i=this,a=this.internals.objectRefs;a.pluginWrapper.on("change","select",function(){var r,s,o=e.val(),d=t.val(),l=n.val();return(r=i.checkDate(o,d,l))?(a.dayDropdown.addClass("invalid"),!1):("00"!==a.dayDropdown.val()&&a.dayDropdown.removeClass("invalid"),a.hiddenField.val(""),r||o*d*l===0||(s=i.formatSubmitDate(o,d,l),a.hiddenField.val(s)),void a.hiddenField.change())})},populateDefaultDate:function(){var e=this.config.defaultDate,t=[],n="",i="",a="";switch(this.config.defaultDateFormat){case"yyyy-mm-dd":default:t=e.split("-"),n=t[2],i=t[1],a=t[0];break;case"dd/mm/yyyy":t=e.split("/"),n=t[0],i=t[1],a=t[2];break;case"mm/dd/yyyy":t=e.split("/"),n=t[1],i=t[0],a=t[2];break;case"unix":t=new Date,t.setTime(1e3*e),n=t.getDate()+"",i=t.getMonth()+1+"",a=t.getFullYear(),n.length<2&&(n="0"+n),i.length<2&&(i="0"+i)}return this.internals.objectRefs.dayDropdown.val(n),this.internals.objectRefs.monthDropdown.val(i),this.internals.objectRefs.yearDropdown.val(a),this.internals.objectRefs.hiddenField.val(e),!0===this.checkDate(n,i,a)&&this.internals.objectRefs.dayDropdown.addClass("invalid"),!0},buildBaseDropdown:function(t){var n=t;return this.config.dropdownClass&&(n+=" "+this.config.dropdownClass),e("",{"class":n,name:this.config.submitFieldName+"_["+t+"]",required:this.config.required})},buildDayDropdown:function(){var e,t=this.buildBaseDropdown("day"),i=n.createElement("option");i.setAttribute("value",""),i.appendChild(n.createTextNode(a.message.day)),t.append(i);for(var r=1;10>r;r++)e=this.config.daySuffixes?r+this.getSuffix(r):"0"+r,i=n.createElement("option"),i.setAttribute("value","0"+r),i.appendChild(n.createTextNode(e)),t.append(i);for(var s=10;31>=s;s++)e=s,this.config.daySuffixes&&(e=s+this.getSuffix(s)),i=n.createElement("option"),i.setAttribute("value",s),i.appendChild(n.createTextNode(e)),t.append(i);return t},buildMonthDropdown:function(){var e=this.buildBaseDropdown("month"),t=n.createElement("option");t.setAttribute("value",""),t.appendChild(n.createTextNode(a.message.month)),e.append(t);for(var i=1;12>=i;i++){var r;switch(this.config.monthFormat){case"short":r=this.internals.monthShort[i-1];break;case"long":r=this.internals.monthLong[i-1];break;case"numeric":r=i,this.config.monthSuffixes&&(r+=this.getSuffix(i))}10>i&&(i="0"+i),t=n.createElement("option"),t.setAttribute("value",i),t.appendChild(n.createTextNode(r)),e.append(t)}return e},buildYearDropdown:function(){var e=this.config.minYear,t=this.config.maxYear,i=this.buildBaseDropdown("year"),r=n.createElement("option");r.setAttribute("value",""),r.appendChild(n.createTextNode(a.message.year)),i.append(r),e||(e=this.internals.currentYear-(this.config.maxAge+1)),t||(t=this.internals.currentYear-this.config.minAge);for(var s=t;s>=e;s--)r=n.createElement("option"),r.setAttribute("value",s),r.appendChild(n.createTextNode(s)),i.append(r);return i},getSuffix:function(e){var t="";switch(e%10){case 1:t=e%100===11?"th":"st";break;case 2:t=e%100===12?"th":"nd";break;case 3:t=e%100===13?"th":"rd";break;default:t="th"}return t},checkDate:function(e,t,n){var i;if("00"!==t){var a=new Date(n,t,0).getDate(),r=parseInt(e,10);i=this.updateDayOptions(a,r),i&&this.internals.objectRefs.hiddenField.val("")}return i},updateDayOptions:function(e,t){var i=parseInt(this.internals.objectRefs.dayDropdown.children(":last").val(),10),a="",r="",s=!1;if(i>e){for(;i>e;)this.internals.objectRefs.dayDropdown.children(":last").remove(),i--;t>e&&(s=!0)}else if(e>i)for(;e>i;){a=++i,r=a,this.config.daySuffixes&&(r+=this.getSuffix(i));var o=n.createElement("option");o.setAttribute("value",a),o.appendChild(n.createTextNode(r)),this.internals.objectRefs.dayDropdown.append(o)}return s},formatSubmitDate:function(e,t,n){var i,a;switch(this.config.submitFormat){case"unix":a=new Date,a.setDate(e),a.setMonth(t-1),a.setYear(n),i=Math.round(a.getTime()/1e3);break;default:i=this.config.submitFormat.replace("dd",e).replace("mm",t).replace("yyyy",n)}return i},destroy:function(){var e=this.config.wrapperClass;if(this.$element.hasClass(e))this.$element.empty();else{var t=this.$element.parent(),n=t.find("select");this.$element.unwrap(),n.remove()}}}),e.fn[r]=function(t){return this.each(function(){if("string"==typeof t){var n=Array.prototype.slice.call(arguments,1),i=e.data(this,"plugin_"+r);if("undefined"==typeof i)return e.error("Please initialize the plugin before calling this method."),!1;i[t].apply(i,n)}else e.data(this,"plugin_"+r)||e.data(this,"plugin_"+r,new a(this,t))}),this}}(jQuery,window,document); \ No newline at end of file From 0ccf6f60f609817cacb15f022cbafdf38a35fb8c Mon Sep 17 00:00:00 2001 From: Daniel Castillo Date: Wed, 8 Jun 2016 21:45:52 -0430 Subject: [PATCH 3/7] change messages --- dist/jquery.date-dropdowns.js | 6 +++--- dist/jquery.date-dropdowns.min.js | 2 +- src/jquery.date-dropdowns.js | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dist/jquery.date-dropdowns.js b/dist/jquery.date-dropdowns.js index 7cf4680..7bdb755 100644 --- a/dist/jquery.date-dropdowns.js +++ b/dist/jquery.date-dropdowns.js @@ -38,9 +38,9 @@ } Plugin.message = { - day: 'Day', - month: 'Month', - year: 'Year' + day: 'Día', + month: 'Mes', + year: 'Año' }; // Avoid Plugin.prototype conflicts diff --git a/dist/jquery.date-dropdowns.min.js b/dist/jquery.date-dropdowns.min.js index 0f26977..c4814be 100644 --- a/dist/jquery.date-dropdowns.min.js +++ b/dist/jquery.date-dropdowns.min.js @@ -5,4 +5,4 @@ * Made by Chris Brown * Under MIT License */ -!function(e,t,n,i){"use strict";function a(t,n){return this.element=t,this.$element=e(t),this.config=e.extend({},s,n),this.internals={objectRefs:{}},this.init(),this}var r="dateDropdowns",s={defaultDate:null,defaultDateFormat:"yyyy-mm-dd",displayFormat:"dmy",submitFormat:"yyyy-mm-dd",minAge:0,maxAge:120,minYear:null,maxYear:null,submitFieldName:"date",wrapperClass:"date-dropdowns",dropdownClass:null,daySuffixes:!0,monthSuffixes:!0,monthFormat:"long",required:!1,monthShort:["Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic"],monthLong:["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Augosto","Septiembre","Octubre","Noviembre","Diciembre"]};a.message={day:"Day",month:"Month",year:"Year"},e.extend(a.prototype,{init:function(){this.checkForDuplicateElement(),this.setInternalVariables(),this.setupMarkup(),this.buildDropdowns(),this.attachDropdowns(),this.bindChangeEvent(),this.config.defaultDate&&this.populateDefaultDate()},checkForDuplicateElement:function(){return e('input[name="'+this.config.submitFieldName+'"]').length?(e.error("Duplicate element found"),!1):!0},setInternalVariables:function(){var e=new Date;this.internals.currentDay=e.getDate(),this.internals.currentMonth=e.getMonth()+1,this.internals.currentYear=e.getFullYear(),this.internals.monthShort=this.config.monthShort,this.internals.monthLong=this.config.monthLong},setupMarkup:function(){var t,n;if("input"===this.element.tagName.toLowerCase()){this.config.defaultDate||(this.config.defaultDate=this.element.value),n=this.$element.attr("type","hidden").wrap('
');var i=this.config.submitFieldName!==s.submitFieldName,a=this.element.hasAttribute("name");a||i?i&&this.$element.attr("name",this.config.submitFieldName):this.$element.attr("name",s.submitFieldName),t=this.$element.parent()}else n=e("",{type:"hidden",name:this.config.submitFieldName}),this.$element.append(n).addClass(this.config.wrapperClass),t=this.$element;return this.internals.objectRefs.pluginWrapper=t,this.internals.objectRefs.hiddenField=n,!0},buildDropdowns:function(){var e,t,n;return e=this.buildDayDropdown(),this.internals.objectRefs.dayDropdown=e,t=this.buildMonthDropdown(),this.internals.objectRefs.monthDropdown=t,n=this.buildYearDropdown(),this.internals.objectRefs.yearDropdown=n,!0},attachDropdowns:function(){var e=this.internals.objectRefs.pluginWrapper,t=this.internals.objectRefs.dayDropdown,n=this.internals.objectRefs.monthDropdown,i=this.internals.objectRefs.yearDropdown;switch(this.config.displayFormat){case"mdy":e.append(n,t,i);break;case"ymd":e.append(i,n,t);break;case"dmy":default:e.append(t,n,i)}return!0},bindChangeEvent:function(){var e=this.internals.objectRefs.dayDropdown,t=this.internals.objectRefs.monthDropdown,n=this.internals.objectRefs.yearDropdown,i=this,a=this.internals.objectRefs;a.pluginWrapper.on("change","select",function(){var r,s,o=e.val(),d=t.val(),l=n.val();return(r=i.checkDate(o,d,l))?(a.dayDropdown.addClass("invalid"),!1):("00"!==a.dayDropdown.val()&&a.dayDropdown.removeClass("invalid"),a.hiddenField.val(""),r||o*d*l===0||(s=i.formatSubmitDate(o,d,l),a.hiddenField.val(s)),void a.hiddenField.change())})},populateDefaultDate:function(){var e=this.config.defaultDate,t=[],n="",i="",a="";switch(this.config.defaultDateFormat){case"yyyy-mm-dd":default:t=e.split("-"),n=t[2],i=t[1],a=t[0];break;case"dd/mm/yyyy":t=e.split("/"),n=t[0],i=t[1],a=t[2];break;case"mm/dd/yyyy":t=e.split("/"),n=t[1],i=t[0],a=t[2];break;case"unix":t=new Date,t.setTime(1e3*e),n=t.getDate()+"",i=t.getMonth()+1+"",a=t.getFullYear(),n.length<2&&(n="0"+n),i.length<2&&(i="0"+i)}return this.internals.objectRefs.dayDropdown.val(n),this.internals.objectRefs.monthDropdown.val(i),this.internals.objectRefs.yearDropdown.val(a),this.internals.objectRefs.hiddenField.val(e),!0===this.checkDate(n,i,a)&&this.internals.objectRefs.dayDropdown.addClass("invalid"),!0},buildBaseDropdown:function(t){var n=t;return this.config.dropdownClass&&(n+=" "+this.config.dropdownClass),e("",{"class":n,name:this.config.submitFieldName+"_["+t+"]",required:this.config.required})},buildDayDropdown:function(){var e,t=this.buildBaseDropdown("day"),i=n.createElement("option");i.setAttribute("value",""),i.appendChild(n.createTextNode(a.message.day)),t.append(i);for(var r=1;10>r;r++)e=this.config.daySuffixes?r+this.getSuffix(r):"0"+r,i=n.createElement("option"),i.setAttribute("value","0"+r),i.appendChild(n.createTextNode(e)),t.append(i);for(var s=10;31>=s;s++)e=s,this.config.daySuffixes&&(e=s+this.getSuffix(s)),i=n.createElement("option"),i.setAttribute("value",s),i.appendChild(n.createTextNode(e)),t.append(i);return t},buildMonthDropdown:function(){var e=this.buildBaseDropdown("month"),t=n.createElement("option");t.setAttribute("value",""),t.appendChild(n.createTextNode(a.message.month)),e.append(t);for(var i=1;12>=i;i++){var r;switch(this.config.monthFormat){case"short":r=this.internals.monthShort[i-1];break;case"long":r=this.internals.monthLong[i-1];break;case"numeric":r=i,this.config.monthSuffixes&&(r+=this.getSuffix(i))}10>i&&(i="0"+i),t=n.createElement("option"),t.setAttribute("value",i),t.appendChild(n.createTextNode(r)),e.append(t)}return e},buildYearDropdown:function(){var e=this.config.minYear,t=this.config.maxYear,i=this.buildBaseDropdown("year"),r=n.createElement("option");r.setAttribute("value",""),r.appendChild(n.createTextNode(a.message.year)),i.append(r),e||(e=this.internals.currentYear-(this.config.maxAge+1)),t||(t=this.internals.currentYear-this.config.minAge);for(var s=t;s>=e;s--)r=n.createElement("option"),r.setAttribute("value",s),r.appendChild(n.createTextNode(s)),i.append(r);return i},getSuffix:function(e){var t="";switch(e%10){case 1:t=e%100===11?"th":"st";break;case 2:t=e%100===12?"th":"nd";break;case 3:t=e%100===13?"th":"rd";break;default:t="th"}return t},checkDate:function(e,t,n){var i;if("00"!==t){var a=new Date(n,t,0).getDate(),r=parseInt(e,10);i=this.updateDayOptions(a,r),i&&this.internals.objectRefs.hiddenField.val("")}return i},updateDayOptions:function(e,t){var i=parseInt(this.internals.objectRefs.dayDropdown.children(":last").val(),10),a="",r="",s=!1;if(i>e){for(;i>e;)this.internals.objectRefs.dayDropdown.children(":last").remove(),i--;t>e&&(s=!0)}else if(e>i)for(;e>i;){a=++i,r=a,this.config.daySuffixes&&(r+=this.getSuffix(i));var o=n.createElement("option");o.setAttribute("value",a),o.appendChild(n.createTextNode(r)),this.internals.objectRefs.dayDropdown.append(o)}return s},formatSubmitDate:function(e,t,n){var i,a;switch(this.config.submitFormat){case"unix":a=new Date,a.setDate(e),a.setMonth(t-1),a.setYear(n),i=Math.round(a.getTime()/1e3);break;default:i=this.config.submitFormat.replace("dd",e).replace("mm",t).replace("yyyy",n)}return i},destroy:function(){var e=this.config.wrapperClass;if(this.$element.hasClass(e))this.$element.empty();else{var t=this.$element.parent(),n=t.find("select");this.$element.unwrap(),n.remove()}}}),e.fn[r]=function(t){return this.each(function(){if("string"==typeof t){var n=Array.prototype.slice.call(arguments,1),i=e.data(this,"plugin_"+r);if("undefined"==typeof i)return e.error("Please initialize the plugin before calling this method."),!1;i[t].apply(i,n)}else e.data(this,"plugin_"+r)||e.data(this,"plugin_"+r,new a(this,t))}),this}}(jQuery,window,document); \ No newline at end of file +!function(e,t,n,i){"use strict";function a(t,n){return this.element=t,this.$element=e(t),this.config=e.extend({},r,n),this.internals={objectRefs:{}},this.init(),this}var s="dateDropdowns",r={defaultDate:null,defaultDateFormat:"yyyy-mm-dd",displayFormat:"dmy",submitFormat:"yyyy-mm-dd",minAge:0,maxAge:120,minYear:null,maxYear:null,submitFieldName:"date",wrapperClass:"date-dropdowns",dropdownClass:null,daySuffixes:!0,monthSuffixes:!0,monthFormat:"long",required:!1,monthShort:["Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic"],monthLong:["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Augosto","Septiembre","Octubre","Noviembre","Diciembre"]};a.message={day:"Día",month:"Mes",year:"Año"},e.extend(a.prototype,{init:function(){this.checkForDuplicateElement(),this.setInternalVariables(),this.setupMarkup(),this.buildDropdowns(),this.attachDropdowns(),this.bindChangeEvent(),this.config.defaultDate&&this.populateDefaultDate()},checkForDuplicateElement:function(){return e('input[name="'+this.config.submitFieldName+'"]').length?(e.error("Duplicate element found"),!1):!0},setInternalVariables:function(){var e=new Date;this.internals.currentDay=e.getDate(),this.internals.currentMonth=e.getMonth()+1,this.internals.currentYear=e.getFullYear(),this.internals.monthShort=this.config.monthShort,this.internals.monthLong=this.config.monthLong},setupMarkup:function(){var t,n;if("input"===this.element.tagName.toLowerCase()){this.config.defaultDate||(this.config.defaultDate=this.element.value),n=this.$element.attr("type","hidden").wrap('
');var i=this.config.submitFieldName!==r.submitFieldName,a=this.element.hasAttribute("name");a||i?i&&this.$element.attr("name",this.config.submitFieldName):this.$element.attr("name",r.submitFieldName),t=this.$element.parent()}else n=e("",{type:"hidden",name:this.config.submitFieldName}),this.$element.append(n).addClass(this.config.wrapperClass),t=this.$element;return this.internals.objectRefs.pluginWrapper=t,this.internals.objectRefs.hiddenField=n,!0},buildDropdowns:function(){var e,t,n;return e=this.buildDayDropdown(),this.internals.objectRefs.dayDropdown=e,t=this.buildMonthDropdown(),this.internals.objectRefs.monthDropdown=t,n=this.buildYearDropdown(),this.internals.objectRefs.yearDropdown=n,!0},attachDropdowns:function(){var e=this.internals.objectRefs.pluginWrapper,t=this.internals.objectRefs.dayDropdown,n=this.internals.objectRefs.monthDropdown,i=this.internals.objectRefs.yearDropdown;switch(this.config.displayFormat){case"mdy":e.append(n,t,i);break;case"ymd":e.append(i,n,t);break;case"dmy":default:e.append(t,n,i)}return!0},bindChangeEvent:function(){var e=this.internals.objectRefs.dayDropdown,t=this.internals.objectRefs.monthDropdown,n=this.internals.objectRefs.yearDropdown,i=this,a=this.internals.objectRefs;a.pluginWrapper.on("change","select",function(){var s,r,o=e.val(),d=t.val(),l=n.val();return(s=i.checkDate(o,d,l))?(a.dayDropdown.addClass("invalid"),!1):("00"!==a.dayDropdown.val()&&a.dayDropdown.removeClass("invalid"),a.hiddenField.val(""),s||o*d*l===0||(r=i.formatSubmitDate(o,d,l),a.hiddenField.val(r)),void a.hiddenField.change())})},populateDefaultDate:function(){var e=this.config.defaultDate,t=[],n="",i="",a="";switch(this.config.defaultDateFormat){case"yyyy-mm-dd":default:t=e.split("-"),n=t[2],i=t[1],a=t[0];break;case"dd/mm/yyyy":t=e.split("/"),n=t[0],i=t[1],a=t[2];break;case"mm/dd/yyyy":t=e.split("/"),n=t[1],i=t[0],a=t[2];break;case"unix":t=new Date,t.setTime(1e3*e),n=t.getDate()+"",i=t.getMonth()+1+"",a=t.getFullYear(),n.length<2&&(n="0"+n),i.length<2&&(i="0"+i)}return this.internals.objectRefs.dayDropdown.val(n),this.internals.objectRefs.monthDropdown.val(i),this.internals.objectRefs.yearDropdown.val(a),this.internals.objectRefs.hiddenField.val(e),!0===this.checkDate(n,i,a)&&this.internals.objectRefs.dayDropdown.addClass("invalid"),!0},buildBaseDropdown:function(t){var n=t;return this.config.dropdownClass&&(n+=" "+this.config.dropdownClass),e("",{"class":n,name:this.config.submitFieldName+"_["+t+"]",required:this.config.required})},buildDayDropdown:function(){var e,t=this.buildBaseDropdown("day"),i=n.createElement("option");i.setAttribute("value",""),i.appendChild(n.createTextNode(a.message.day)),t.append(i);for(var s=1;10>s;s++)e=this.config.daySuffixes?s+this.getSuffix(s):"0"+s,i=n.createElement("option"),i.setAttribute("value","0"+s),i.appendChild(n.createTextNode(e)),t.append(i);for(var r=10;31>=r;r++)e=r,this.config.daySuffixes&&(e=r+this.getSuffix(r)),i=n.createElement("option"),i.setAttribute("value",r),i.appendChild(n.createTextNode(e)),t.append(i);return t},buildMonthDropdown:function(){var e=this.buildBaseDropdown("month"),t=n.createElement("option");t.setAttribute("value",""),t.appendChild(n.createTextNode(a.message.month)),e.append(t);for(var i=1;12>=i;i++){var s;switch(this.config.monthFormat){case"short":s=this.internals.monthShort[i-1];break;case"long":s=this.internals.monthLong[i-1];break;case"numeric":s=i,this.config.monthSuffixes&&(s+=this.getSuffix(i))}10>i&&(i="0"+i),t=n.createElement("option"),t.setAttribute("value",i),t.appendChild(n.createTextNode(s)),e.append(t)}return e},buildYearDropdown:function(){var e=this.config.minYear,t=this.config.maxYear,i=this.buildBaseDropdown("year"),s=n.createElement("option");s.setAttribute("value",""),s.appendChild(n.createTextNode(a.message.year)),i.append(s),e||(e=this.internals.currentYear-(this.config.maxAge+1)),t||(t=this.internals.currentYear-this.config.minAge);for(var r=t;r>=e;r--)s=n.createElement("option"),s.setAttribute("value",r),s.appendChild(n.createTextNode(r)),i.append(s);return i},getSuffix:function(e){var t="";switch(e%10){case 1:t=e%100===11?"th":"st";break;case 2:t=e%100===12?"th":"nd";break;case 3:t=e%100===13?"th":"rd";break;default:t="th"}return t},checkDate:function(e,t,n){var i;if("00"!==t){var a=new Date(n,t,0).getDate(),s=parseInt(e,10);i=this.updateDayOptions(a,s),i&&this.internals.objectRefs.hiddenField.val("")}return i},updateDayOptions:function(e,t){var i=parseInt(this.internals.objectRefs.dayDropdown.children(":last").val(),10),a="",s="",r=!1;if(i>e){for(;i>e;)this.internals.objectRefs.dayDropdown.children(":last").remove(),i--;t>e&&(r=!0)}else if(e>i)for(;e>i;){a=++i,s=a,this.config.daySuffixes&&(s+=this.getSuffix(i));var o=n.createElement("option");o.setAttribute("value",a),o.appendChild(n.createTextNode(s)),this.internals.objectRefs.dayDropdown.append(o)}return r},formatSubmitDate:function(e,t,n){var i,a;switch(this.config.submitFormat){case"unix":a=new Date,a.setDate(e),a.setMonth(t-1),a.setYear(n),i=Math.round(a.getTime()/1e3);break;default:i=this.config.submitFormat.replace("dd",e).replace("mm",t).replace("yyyy",n)}return i},destroy:function(){var e=this.config.wrapperClass;if(this.$element.hasClass(e))this.$element.empty();else{var t=this.$element.parent(),n=t.find("select");this.$element.unwrap(),n.remove()}}}),e.fn[s]=function(t){return this.each(function(){if("string"==typeof t){var n=Array.prototype.slice.call(arguments,1),i=e.data(this,"plugin_"+s);if("undefined"==typeof i)return e.error("Please initialize the plugin before calling this method."),!1;i[t].apply(i,n)}else e.data(this,"plugin_"+s)||e.data(this,"plugin_"+s,new a(this,t))}),this}}(jQuery,window,document); \ No newline at end of file diff --git a/src/jquery.date-dropdowns.js b/src/jquery.date-dropdowns.js index 7cf4680..7bdb755 100644 --- a/src/jquery.date-dropdowns.js +++ b/src/jquery.date-dropdowns.js @@ -38,9 +38,9 @@ } Plugin.message = { - day: 'Day', - month: 'Month', - year: 'Year' + day: 'Día', + month: 'Mes', + year: 'Año' }; // Avoid Plugin.prototype conflicts From f1c095cb384f02ece5e44caf427d8529b0ed96b9 Mon Sep 17 00:00:00 2001 From: Mikk Tendermann Date: Thu, 7 Jul 2016 15:06:41 +0300 Subject: [PATCH 4/7] translate things back to English add ability to translate messages --- src/jquery.date-dropdowns.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/jquery.date-dropdowns.js b/src/jquery.date-dropdowns.js index 7bdb755..4cebbf6 100644 --- a/src/jquery.date-dropdowns.js +++ b/src/jquery.date-dropdowns.js @@ -20,8 +20,13 @@ monthSuffixes: true, monthFormat: 'long', required: false, - monthShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'], - monthLong: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Augosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'] + message: { + day: 'Day', + month: 'Month', + year: 'Year' + }, + monthShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], + monthLong: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] }; // The actual plugin constructor @@ -37,12 +42,6 @@ return this; } - Plugin.message = { - day: 'Día', - month: 'Mes', - year: 'Año' - }; - // Avoid Plugin.prototype conflicts $.extend(Plugin.prototype, { @@ -322,7 +321,7 @@ option = document.createElement('option'); option.setAttribute('value', ''); - option.appendChild(document.createTextNode(Plugin.message.day)); + option.appendChild(document.createTextNode(this.config.message.day)); dropdown.append(option); // Days 1-9 @@ -364,7 +363,7 @@ option = document.createElement('option'); option.setAttribute('value', ''); - option.appendChild(document.createTextNode(Plugin.message.month)); + option.appendChild(document.createTextNode(this.config.message.month)); dropdown.append(option); // Populate the month values @@ -416,7 +415,7 @@ option = document.createElement('option'); option.setAttribute('value', ''); - option.appendChild(document.createTextNode(Plugin.message.year)); + option.appendChild(document.createTextNode(this.config.message.year)); dropdown.append(option); if (!minYear) { From dba18ad651a596c81ecc736c26f640546d1aa726 Mon Sep 17 00:00:00 2001 From: Mikk Tendermann Date: Thu, 7 Jul 2016 15:21:16 +0300 Subject: [PATCH 5/7] add support for localized ordinalisation --- src/jquery.date-dropdowns.js | 55 +++++++++++++++--------------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/src/jquery.date-dropdowns.js b/src/jquery.date-dropdowns.js index 4cebbf6..755deee 100644 --- a/src/jquery.date-dropdowns.js +++ b/src/jquery.date-dropdowns.js @@ -26,7 +26,25 @@ year: 'Year' }, monthShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], - monthLong: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] + monthLong: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], + ordinalize: function (number) { + switch (number % 10) { + case 1: + suffix = (number % 100 === 11) ? 'th' : 'st'; + break; + case 2: + suffix = (number % 100 === 12) ? 'th' : 'nd'; + break; + case 3: + suffix = (number % 100 === 13) ? 'th' : 'rd'; + break; + default: + suffix = 'th'; + break; + } + + return number+suffix; + } }; // The actual plugin constructor @@ -327,7 +345,7 @@ // Days 1-9 for (var i = 1; i < 10; i++) { if (this.config.daySuffixes) { - day = i + this.getSuffix(i); + day = this.options.ordinalize(i); } else { day = '0' + i; } @@ -342,7 +360,7 @@ day = j; if (this.config.daySuffixes) { - day = j + this.getSuffix(j); + day = this.options.ordinalize(j); } option = document.createElement('option'); option.setAttribute('value', j); @@ -382,7 +400,7 @@ month = monthNo; if (this.config.monthSuffixes) { - month += this.getSuffix(monthNo); + month = this.options.ordinalize(monthNo); } break; } @@ -436,33 +454,6 @@ return dropdown; }, - /** - * Get the relevant suffix for a day/month number - * - * @param number - * @returns {string} - */ - getSuffix: function (number) { - var suffix = ''; - - switch (number % 10) { - case 1: - suffix = (number % 100 === 11) ? 'th' : 'st'; - break; - case 2: - suffix = (number % 100 === 12) ? 'th' : 'nd'; - break; - case 3: - suffix = (number % 100 === 13) ? 'th' : 'rd'; - break; - default: - suffix = 'th'; - break; - } - - return suffix; - }, - /** * Check whether the date entered is invalid, e.g. 31st Feb * @@ -525,7 +516,7 @@ // Add the suffix if required if (this.config.daySuffixes) { - newDayText += this.getSuffix(lastDayOption); + newDayText = this.options.ordinalize(lastDayOption); } // Build the option and append to the dropdown From 3a339a0324c3529cb0ef8f6c75978c3a2f60c20b Mon Sep 17 00:00:00 2001 From: Mikk Tendermann Date: Thu, 7 Jul 2016 15:24:55 +0300 Subject: [PATCH 6/7] fix --- src/jquery.date-dropdowns.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/jquery.date-dropdowns.js b/src/jquery.date-dropdowns.js index 755deee..e071770 100644 --- a/src/jquery.date-dropdowns.js +++ b/src/jquery.date-dropdowns.js @@ -345,7 +345,7 @@ // Days 1-9 for (var i = 1; i < 10; i++) { if (this.config.daySuffixes) { - day = this.options.ordinalize(i); + day = this.config.ordinalize(i); } else { day = '0' + i; } @@ -360,7 +360,7 @@ day = j; if (this.config.daySuffixes) { - day = this.options.ordinalize(j); + day = this.config.ordinalize(j); } option = document.createElement('option'); option.setAttribute('value', j); @@ -400,7 +400,7 @@ month = monthNo; if (this.config.monthSuffixes) { - month = this.options.ordinalize(monthNo); + month = this.config.ordinalize(monthNo); } break; } @@ -516,7 +516,7 @@ // Add the suffix if required if (this.config.daySuffixes) { - newDayText = this.options.ordinalize(lastDayOption); + newDayText = this.config.ordinalize(lastDayOption); } // Build the option and append to the dropdown From 5931d2fb8a0948b92d4c373b7f59fb348fd28fcf Mon Sep 17 00:00:00 2001 From: Mikk Tendermann Date: Thu, 7 Jul 2016 15:29:37 +0300 Subject: [PATCH 7/7] add suffix --- src/jquery.date-dropdowns.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/jquery.date-dropdowns.js b/src/jquery.date-dropdowns.js index e071770..b8dac0c 100644 --- a/src/jquery.date-dropdowns.js +++ b/src/jquery.date-dropdowns.js @@ -28,6 +28,7 @@ monthShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], monthLong: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], ordinalize: function (number) { + var suffix = ''; switch (number % 10) { case 1: suffix = (number % 100 === 11) ? 'th' : 'st';