Skip to content
Browse files

Added pubsub events for Kalendae.Input showing and hiding when the in…

…put gains and loses focus

Closes Issue #59
  • Loading branch information...
1 parent da4b857 commit 2100daa111481468d94643618a7baed5f291cb9e @ChiperSoft committed Aug 29, 2012
Showing with 20 additions and 10 deletions.
  1. +3 −1 build/kalendae.js
  2. +8 −8 build/kalendae.min.js
  3. +6 −0 readme.md
  4. +3 −1 src/input.js
View
4 build/kalendae.js
@@ -879,11 +879,13 @@ Kalendae.Input.prototype = util.merge(Kalendae.prototype, {
}
style.position = util.isFixed($input) ? 'fixed' : 'absolute';
-
+
+ this.publish('show', this);
},
hide : function () {
this.container.style.display = 'none';
+ this.publish('hide', this);
}
});
View
16 build/kalendae.min.js
@@ -31,14 +31,14 @@ b){var c=a.offsetLeft,e=a.offsetTop,d={};if(!b)for(;a=a.offsetParent;)c+=a.offse
b){if("function"===typeof document.addEventListener){var c=this.input=f.$(a),e;if(!c||"INPUT"!==c.tagName)throw"First argument for Kalendae.Input must be an <input> element or a valid element id.";var d=this,g=d.classes;opts=d.settings=f.merge(d.defaults,b);opts.attachTo=window.document.body;opts.selected?e=!0:opts.selected=c.value;q.call(d,opts);if(opts.closeButton){var l=f.make("a",{"class":g.closeButton},d.container);f.addEvent(l,"click",function(){c.blur()})}e&&(c.value=d.getSelected());e=d.container;
var h=!1;e.style.display="none";f.addClassName(e,g.positioned);f.addEvent(e,"mousedown",function(){h=true});f.addEvent(window.document,"mousedown",function(){h=false});f.addEvent(c,"focus",function(){d.setSelected(this.value);d.show()});f.addEvent(c,"blur",function(){if(h){h=false;c.focus()}else d.hide()});f.addEvent(c,"keyup",function(){d.setSelected(this.value)});(g=f.scrollContainer(c))&&f.addEvent(g,"scroll",function(){c.blur()});d.subscribe("change",function(){c.value=d.getSelected()})}};q.Input.prototype=
f.merge(q.prototype,{defaults:f.merge(q.prototype.defaults,{format:"MM/DD/YYYY",side:"bottom",closeButton:!0,offsetLeft:0,offsetTop:0}),classes:f.merge(q.prototype.classes,{positioned:"k-floating",closeButton:"k-btn-close"}),show:function(){var a=this.container,b=a.style,c=this.input,e=f.getPosition(c),d=f.scrollContainer(c),d=d?d.scrollTop:0;b.display="";switch(opts.side){case "left":b.left=e.left-f.getWidth(a)+this.settings.offsetLeft+"px";b.top=e.top+this.settings.offsetTop-d+"px";break;case "right":b.left=
-e.left+f.getWidth(c)+"px";b.top=e.top+this.settings.offsetTop-d+"px";break;case "top":b.left=e.left+this.settings.offsetLeft+"px";b.top=e.top-f.getHeight(a)+this.settings.offsetTop-d+"px";break;default:b.left=e.left+this.settings.offsetLeft+"px",b.top=e.top+f.getHeight(c)+this.settings.offsetTop-d+"px"}b.position=f.isFixed(c)?"fixed":"absolute"},hide:function(){this.container.style.display="none"}});var K=function(a){a||(a=this);var b=a.c_||{};a.publish=function(a,e,d){for(var g=(a=b[a])?a.length:
-0,f;g--;)if(f=a[g].apply(e,d||[]),"boolean"===typeof f)return f};a.subscribe=function(a,e,d){b[a]||(b[a]=[]);d?b[a].push(e):b[a].unshift(e);return[a,e]};a.unsubscribe=function(a){for(var e=b[a[0]],a=a[1],d=e?e.length:0;d--;)e[d]===a&&e.splice(d,1)}},p=Date,u=function(a,b){this._d=a;this._isUTC=!!b},r=function(a,b){for(var c=a+"";c.length<b;)c="0"+c;return c},F=function(a,b,c,e){var d="string"===typeof b,g=d?{}:b;d&&e&&(g[b]=+e);b=(g.ms||g.milliseconds||0)+1E3*(g.s||g.seconds||0)+6E4*(g.m||g.minutes||
-0)+36E5*(g.h||g.hours||0);e=(g.d||g.days||0)+7*(g.w||g.weeks||0);g=(g.M||g.months||0)+12*(g.y||g.years||0);b&&a.setTime(+a+b*c);e&&a.setDate(a.getDate()+e*c);g&&(b=a.getDate(),a.setDate(1),a.setMonth(a.getMonth()+g*c),a.setDate(Math.min((new p(a.getFullYear(),a.getMonth()+1,0)).getDate(),b)));return a},y=function(a){return"[object Array]"===Object.prototype.toString.call(a)},G=function(a){return new p(a[0],a[1]||0,a[2]||1,a[3]||0,a[4]||0,a[5]||0,a[6]||0)},z=function(a,b){function c(b){var s;switch(b){case "M":return e+
-1;case "Mo":return e+1+m(e+1);case "MM":return r(e+1,2);case "MMM":return h.monthsShort[e];case "MMMM":return h.months[e];case "D":return d;case "Do":return d+m(d);case "DD":return r(d,2);case "DDD":return b=new p(g,e,d),s=new p(g,0,1),~~((b-s)/864E5+1.5);case "DDDo":return b=c("DDD"),b+m(b);case "DDDD":return r(c("DDD"),3);case "d":return f;case "do":return f+m(f);case "ddd":return h.weekdaysShort[f];case "dddd":return h.weekdays[f];case "w":return b=new p(g,e,d-f+5),s=new p(b.getFullYear(),0,4),
-~~((b-s)/864E5/7+1.5);case "wo":return b=c("w"),b+m(b);case "ww":return r(c("w"),2);case "YY":return r(g%100,2);case "YYYY":return g;case "a":return 11<j?k.pm:k.am;case "A":return 11<j?k.PM:k.AM;case "H":return j;case "HH":return r(j,2);case "h":return j%12||12;case "hh":return r(j%12||12,2);case "m":return q;case "mm":return r(q,2);case "s":return n;case "ss":return r(n,2);case "zz":case "z":return(a._d.toString().match(L)||[""])[0].replace(M,"");case "Z":return(0>o?"-":"+")+r(~~(Math.abs(o)/60),
-2)+":"+r(~~(Math.abs(o)%60),2);case "ZZ":return(0>o?"-":"+")+r(~~(10*Math.abs(o)/6),4);case "L":case "LL":case "LLL":case "LLLL":case "LT":return z(a,h.longDateFormat[b]);default:return b.replace(/(^\[)|(\\)|\]$/g,"")}}var e=a.month(),d=a.date(),g=a.year(),f=a.day(),j=a.hours(),q=a.minutes(),n=a.seconds(),o=-a.zone(),m=h.ordinal,k=h.meridiem;return b.replace(N,c)},B=function(a,b){var c=[0,0,1,0,0,0,0],e=0,d=0,g=!1,f=a.match(A),j=b.match(O),q=Math.min(f.length,j.length),n,o;for(n=0;n<q;n++){var m=
-f[n],k=void 0;switch(j[n]){case "M":case "MM":c[1]=~~m-1;break;case "MMM":case "MMMM":for(k=0;12>k;k++)if(h.monthsParse[k].test(m)){c[1]=k;break}break;case "D":case "DD":case "DDD":case "DDDD":c[2]=~~m;break;case "YY":m=~~m;c[0]=m+(70<m?1900:2E3);break;case "YYYY":c[0]=~~Math.abs(m);break;case "a":case "A":o="pm"===m.toLowerCase();break;case "H":case "HH":case "h":case "hh":c[3]=~~m;break;case "m":case "mm":c[4]=~~m;break;case "s":case "ss":c[5]=~~m;break;case "Z":case "ZZ":g=!0,(k=(m||"").match(P))&&
-k[1]&&(e=~~k[1]),k&&k[2]&&(d=~~k[2]),k&&"+"===k[0]&&(e=-e,d=-d)}}o&&12>c[3]&&(c[3]+=12);!1===o&&12===c[3]&&(c[3]=0);c[3]+=e;c[4]+=d;return g?new p(p.UTC.apply({},c)):G(c)},Q=function(a,b,c){var e=h.relativeTime[a];return"function"===typeof e?e(b||1,!!c,a):e.replace(/%d/i,b||1)},H=function(a,b){h.fn[a]=function(a){var e=this._isUTC?"UTC":"";return"undefined"!==typeof a?(this._d["set"+e+b](a),this):this._d["get"+e+b]()}},h,s=Math.round,C={},R="undefined"!==typeof module,I="months monthsShort monthsParse weekdays weekdaysShort longDateFormat calendar relativeTime ordinal meridiem".split(" "),
+e.left+f.getWidth(c)+"px";b.top=e.top+this.settings.offsetTop-d+"px";break;case "top":b.left=e.left+this.settings.offsetLeft+"px";b.top=e.top-f.getHeight(a)+this.settings.offsetTop-d+"px";break;default:b.left=e.left+this.settings.offsetLeft+"px",b.top=e.top+f.getHeight(c)+this.settings.offsetTop-d+"px"}b.position=f.isFixed(c)?"fixed":"absolute";this.publish("show",this)},hide:function(){this.container.style.display="none";this.publish("hide",this)}});var K=function(a){a||(a=this);var b=a.c_||{};a.publish=
+function(a,e,d){for(var g=(a=b[a])?a.length:0,f;g--;)if(f=a[g].apply(e,d||[]),"boolean"===typeof f)return f};a.subscribe=function(a,e,d){b[a]||(b[a]=[]);d?b[a].push(e):b[a].unshift(e);return[a,e]};a.unsubscribe=function(a){for(var e=b[a[0]],a=a[1],d=e?e.length:0;d--;)e[d]===a&&e.splice(d,1)}},p=Date,u=function(a,b){this._d=a;this._isUTC=!!b},r=function(a,b){for(var c=a+"";c.length<b;)c="0"+c;return c},F=function(a,b,c,e){var d="string"===typeof b,g=d?{}:b;d&&e&&(g[b]=+e);b=(g.ms||g.milliseconds||
+0)+1E3*(g.s||g.seconds||0)+6E4*(g.m||g.minutes||0)+36E5*(g.h||g.hours||0);e=(g.d||g.days||0)+7*(g.w||g.weeks||0);g=(g.M||g.months||0)+12*(g.y||g.years||0);b&&a.setTime(+a+b*c);e&&a.setDate(a.getDate()+e*c);g&&(b=a.getDate(),a.setDate(1),a.setMonth(a.getMonth()+g*c),a.setDate(Math.min((new p(a.getFullYear(),a.getMonth()+1,0)).getDate(),b)));return a},y=function(a){return"[object Array]"===Object.prototype.toString.call(a)},G=function(a){return new p(a[0],a[1]||0,a[2]||1,a[3]||0,a[4]||0,a[5]||0,a[6]||
+0)},z=function(a,b){function c(b){var s;switch(b){case "M":return e+1;case "Mo":return e+1+m(e+1);case "MM":return r(e+1,2);case "MMM":return h.monthsShort[e];case "MMMM":return h.months[e];case "D":return d;case "Do":return d+m(d);case "DD":return r(d,2);case "DDD":return b=new p(g,e,d),s=new p(g,0,1),~~((b-s)/864E5+1.5);case "DDDo":return b=c("DDD"),b+m(b);case "DDDD":return r(c("DDD"),3);case "d":return f;case "do":return f+m(f);case "ddd":return h.weekdaysShort[f];case "dddd":return h.weekdays[f];
+case "w":return b=new p(g,e,d-f+5),s=new p(b.getFullYear(),0,4),~~((b-s)/864E5/7+1.5);case "wo":return b=c("w"),b+m(b);case "ww":return r(c("w"),2);case "YY":return r(g%100,2);case "YYYY":return g;case "a":return 11<j?k.pm:k.am;case "A":return 11<j?k.PM:k.AM;case "H":return j;case "HH":return r(j,2);case "h":return j%12||12;case "hh":return r(j%12||12,2);case "m":return q;case "mm":return r(q,2);case "s":return n;case "ss":return r(n,2);case "zz":case "z":return(a._d.toString().match(L)||[""])[0].replace(M,
+"");case "Z":return(0>o?"-":"+")+r(~~(Math.abs(o)/60),2)+":"+r(~~(Math.abs(o)%60),2);case "ZZ":return(0>o?"-":"+")+r(~~(10*Math.abs(o)/6),4);case "L":case "LL":case "LLL":case "LLLL":case "LT":return z(a,h.longDateFormat[b]);default:return b.replace(/(^\[)|(\\)|\]$/g,"")}}var e=a.month(),d=a.date(),g=a.year(),f=a.day(),j=a.hours(),q=a.minutes(),n=a.seconds(),o=-a.zone(),m=h.ordinal,k=h.meridiem;return b.replace(N,c)},B=function(a,b){var c=[0,0,1,0,0,0,0],e=0,d=0,g=!1,f=a.match(A),j=b.match(O),q=Math.min(f.length,
+j.length),n,o;for(n=0;n<q;n++){var m=f[n],k=void 0;switch(j[n]){case "M":case "MM":c[1]=~~m-1;break;case "MMM":case "MMMM":for(k=0;12>k;k++)if(h.monthsParse[k].test(m)){c[1]=k;break}break;case "D":case "DD":case "DDD":case "DDDD":c[2]=~~m;break;case "YY":m=~~m;c[0]=m+(70<m?1900:2E3);break;case "YYYY":c[0]=~~Math.abs(m);break;case "a":case "A":o="pm"===m.toLowerCase();break;case "H":case "HH":case "h":case "hh":c[3]=~~m;break;case "m":case "mm":c[4]=~~m;break;case "s":case "ss":c[5]=~~m;break;case "Z":case "ZZ":g=
+!0,(k=(m||"").match(P))&&k[1]&&(e=~~k[1]),k&&k[2]&&(d=~~k[2]),k&&"+"===k[0]&&(e=-e,d=-d)}}o&&12>c[3]&&(c[3]+=12);!1===o&&12===c[3]&&(c[3]=0);c[3]+=e;c[4]+=d;return g?new p(p.UTC.apply({},c)):G(c)},Q=function(a,b,c){var e=h.relativeTime[a];return"function"===typeof e?e(b||1,!!c,a):e.replace(/%d/i,b||1)},H=function(a,b){h.fn[a]=function(a){var e=this._isUTC?"UTC":"";return"undefined"!==typeof a?(this._d["set"+e+b](a),this):this._d["get"+e+b]()}},h,s=Math.round,C={},R="undefined"!==typeof module,I="months monthsShort monthsParse weekdays weekdaysShort longDateFormat calendar relativeTime ordinal meridiem".split(" "),
v,S=/^\/?Date\((\-?\d+)/i,N=/(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|zz?|ZZ?|LT|LL?L?L?)/g,M=/[^A-Z]/g,L=/\([A-Za-z ]+\)|:[0-9]{2} [A-Z]{3} /g,O=/(\\)?(MM?M?M?|dd?d?d|DD?D?D?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|ZZ?|T)/g,A=/(\\)?([0-9]+|([a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+|([\+\-]\d\d:?\d\d))/gi,T=/\d{4}.\d\d.\d\d(T(\d\d(.\d\d(.\d\d)?)?)?([\+\-]\d\d:?\d\d)?)?/,J=[["HH:mm:ss",/T\d\d:\d\d:\d\d/],["HH:mm",/T\d\d:\d\d/],["HH",/T\d\d/]],P=/([\+\-]|\d\d)/gi,
D="Month Date Hours Minutes Seconds Milliseconds".split(" ");h=function(a,b){if(null===a||""===a)return null;var c;if(a&&a._d instanceof p)c=new p(+a._d);else if(b)if(y(b)){var e=a.match(A),d=99,g,f,h;for(g=0;g<b.length;g++){f=B(a,b[g]);h=e;for(var j=z(new u(f),b[g]).match(A),n=Math.min(h.length,j.length),o=Math.abs(h.length-j.length),m=0,k=void 0,k=0;k<n;k++)~~h[k]!==~~j[k]&&m++;h=m+o;h<d&&(d=h,c=f)}}else c=B(a,b);else if(c=S.exec(a),void 0===a)c=new p;else if(c)c=new p(+c[1]);else if(a instanceof
p)c=a;else if(y(a))c=G(a);else if("string"===typeof a)if(c="YYYY-MM-DDT",T.exec(a)){for(e=0;3>e;e++)if(J[e][1].exec(a)){c+=J[e][0];break}c=B(a,c+"Z")}else c=new p(a);else c=new p(a);return new u(c)};h.utc=function(a,b){return y(a)?new u(new p(p.UTC.apply({},a)),!0):b&&a?h(a+" 0",b+" Z").utc():h(a).utc()};h.humanizeDuration=function(a,b,c){var a=+a,e=h.relativeTime;switch(b){case "seconds":a*=1E3;break;case "minutes":a*=6E4;break;case "hours":a*=36E5;break;case "days":a*=864E5;break;case "weeks":a*=
View
6 readme.md
@@ -214,6 +214,12 @@ Kalendae offers the following events:
- `view-changed` - Fires when the user has clicked the next or previous month button, but before the calendar is redrawn. Returning false will prevent the change.
+Additionally, Kalendae.Input provides the following events:
+
+- `show` - Fires when the calendar appears due to the input gaining focus
+
+- `hide` - Fires when the calendar hides due to the input blurring
+
##Skinning Kalendae
View
4 src/input.js
@@ -120,11 +120,13 @@ Kalendae.Input.prototype = util.merge(Kalendae.prototype, {
}
style.position = util.isFixed($input) ? 'fixed' : 'absolute';
-
+
+ this.publish('show', this);
},
hide : function () {
this.container.style.display = 'none';
+ this.publish('hide', this);
}
});

0 comments on commit 2100daa

Please sign in to comment.
Something went wrong with that request. Please try again.