Permalink
Browse files

input-calendar-sync: leverage finally

  • Loading branch information...
1 parent fdb7b53 commit b01dcba5701c2cf71b1b09621a1f4b1760912441 John Lindal committed Jun 12, 2012
@@ -59,14 +59,15 @@ function syncFromInput()
cal.deselectDates(); // hack for http://yuilibrary.com/projects/yui3/ticket/2530928
cal.selectDates(result.date);
cal.set('date', result.date);
-
- this.ignore_selection_change = false;
}
catch (ex)
{
- this.ignore_selection_change = false;
Y.log('invalid date, falling back to selected date', 'debug', 'InputCalendarSync');
}
+ finally
+ {
+ this.ignore_selection_change = false;
+ }
}
syncFromCalendar.call(this);
@@ -1 +1 @@
-YUI.add("gallery-input-calendar-sync",function(d){function c(e){c.superclass.constructor.call(this,e);}c.NAME="InputCalendarSyncPlugin";c.NS="calendarSync";c.ATTRS={calendar:{validator:function(e){return(e instanceof d.Calendar);}}};function b(){var g=this.get("host"),i=this.get("calendar"),h=d.Lang.trim(g.get("value"));if(h){try{this.ignore_selection_change=true;var e=d.DateTimeUtils.normalize(d.DateTimeUtils.parseDate(h),{hour:0,minute:0});i.deselectDates();i.selectDates(e.date);i.set("date",e.date);this.ignore_selection_change=false;}catch(f){this.ignore_selection_change=false;}}a.call(this);}function a(){if(!this.ignore_selection_change){var e=this.get("calendar").get("selectedDates")[0];this.get("host").set("value",d.DateTimeUtils.formatDate(e));}}d.extend(c,d.Plugin.Base,{initializer:function(e){var f=this.get("host");this.change_handle=f.on("change",b,this);this.cal_handle=this.get("calendar").on("selectionChange",a,this);this.get("calendar").set("selectionMode","single");b.call(this);},destructor:function(){this.change_handle.detach();this.cal_handle.detach();}});d.namespace("Plugin");d.Plugin.InputCalendarSync=c;},"@VERSION@",{requires:["node-pluginhost","plugin","gallery-datetime-utils","calendar"]});
+YUI.add("gallery-input-calendar-sync",function(d){function c(e){c.superclass.constructor.call(this,e);}c.NAME="InputCalendarSyncPlugin";c.NS="calendarSync";c.ATTRS={calendar:{validator:function(e){return(e instanceof d.Calendar);}}};function b(){var g=this.get("host"),i=this.get("calendar"),h=d.Lang.trim(g.get("value"));if(h){try{this.ignore_selection_change=true;var e=d.DateTimeUtils.normalize(d.DateTimeUtils.parseDate(h),{hour:0,minute:0});i.deselectDates();i.selectDates(e.date);i.set("date",e.date);}catch(f){}finally{this.ignore_selection_change=false;}}a.call(this);}function a(){if(!this.ignore_selection_change){var e=this.get("calendar").get("selectedDates")[0];this.get("host").set("value",d.DateTimeUtils.formatDate(e));}}d.extend(c,d.Plugin.Base,{initializer:function(e){var f=this.get("host");this.change_handle=f.on("change",b,this);this.cal_handle=this.get("calendar").on("selectionChange",a,this);this.get("calendar").set("selectionMode","single");b.call(this);},destructor:function(){this.change_handle.detach();this.cal_handle.detach();}});d.namespace("Plugin");d.Plugin.InputCalendarSync=c;},"@VERSION@",{requires:["node-pluginhost","plugin","gallery-datetime-utils","calendar"]});
@@ -59,11 +59,12 @@ function syncFromInput()
cal.deselectDates(); // hack for http://yuilibrary.com/projects/yui3/ticket/2530928
cal.selectDates(result.date);
cal.set('date', result.date);
-
- this.ignore_selection_change = false;
}
catch (ex)
{
+ }
+ finally
+ {
this.ignore_selection_change = false;
}
}
@@ -156,30 +156,23 @@ DateTime.ATTRS =
}
}
-function installDateTimeCalendarSelection()
+function handleCalendarSelection()
{
- var self = this;
- var handler = this.calendar.handleDateSelection;
- this.calendar.handleDateSelection = function(date)
+ if (!this.ignore_date_selection)
{
- handler.call(this, date);
+ this.rb[ this.rb.length-1 ].checked = true;
+ this._updateDisplay();
- if (!self.ignore_date_selection)
+ if (this.hour_menu.selectedIndex == -1 ||
+ this.minute_menu.selectedIndex == -1)
{
- self.rb[ self.rb.length-1 ].checked = true;
- self._updateDisplay();
-
- if (self.hour_menu.selectedIndex == -1 ||
- self.minute_menu.selectedIndex == -1)
- {
- self.hour_menu.value = self.blank_time.hour;
- self.minute_menu.value = self.blank_time.minute;
- }
-
- self.ping_input = self.should_ping_input;
- enforceDateTimeLimits.call(self, 'same-day');
+ this.hour_menu.value = this.blank_time.hour;
+ this.minute_menu.value = this.blank_time.minute;
}
- };
+
+ this.ping_input = this.should_ping_input;
+ enforceDateTimeLimits.call(this, 'same-day');
+ }
}
function handleRadioSelection(e)
@@ -188,23 +181,18 @@ function handleRadioSelection(e)
if (Y.Lang.isArray(this.rb_hook))
{
- for (var i=0; i<this.rb.length; i++)
+ var i = this.rb.indexOf(e.target);
+ if (i >= 0)
{
- if (e.target != this.rb[i])
- {
- continue;
- }
-
applyRadioHook.call(this, i);
- break;
}
}
}
function applyRadioHook(
/* int */ index)
{
- if (!YAHOO.lang.isArray(this.rb_hook))
+ if (!Y.Lang.isArray(this.rb_hook))
{
return;
}
@@ -214,11 +202,11 @@ function applyRadioHook(
try
{
var hook = this.rb_hook[index];
- if (YAHOO.lang.isFunction(hook))
+ if (Y.Lang.isFunction(hook))
{
hook.call(this);
}
- else if (YAHOO.lang.isString(hook))
+ else if (Y.Lang.isString(hook))
{
this[hook].call(this);
}
@@ -242,21 +230,22 @@ function selectHook(
/* string */ name)
{
if (this.skip_select_hook ||
- !YAHOO.lang.isArray(this.rb_hook))
+ !Y.Lang.isArray(this.rb_hook))
{
return;
}
- for (var i=0; i<this.rb_hook.length; i++)
+ var i = Y.Array.findIndexOf(this.rb_hook, function(hook)
{
- var hook = this.rb_hook[i];
- if ((YAHOO.lang.isFunction(hook) && hook == this[name]) ||
- (YAHOO.lang.isString(hook) && hook == name))
- {
- this.rb[i].checked = true;
- this._updateDisplay();
- break;
- }
+ return ((Y.Lang.isFunction(hook) && hook == this[name]) ||
+ (Y.Lang.isString(hook) && hook == name));
+ },
+ this);
+
+ if (i >= 0)
+ {
+ this.rb.item(i).set('checked', true);
+ this._updateDisplay();
}
}
@@ -57,14 +57,15 @@ function syncFromInput()
cal.deselectDates(); // hack for http://yuilibrary.com/projects/yui3/ticket/2530928
cal.selectDates(result.date);
cal.set('date', result.date);
-
- this.ignore_selection_change = false;
}
catch (ex)
{
- this.ignore_selection_change = false;
Y.log('invalid date, falling back to selected date', 'debug', 'InputCalendarSync');
}
+ finally
+ {
+ this.ignore_selection_change = false;
+ }
}
syncFromCalendar.call(this);

0 comments on commit b01dcba

Please sign in to comment.