Skip to content

Commit

Permalink
input-calendar-sync: leverage finally
Browse files Browse the repository at this point in the history
  • Loading branch information
John Lindal committed Jun 12, 2012
1 parent fdb7b53 commit b01dcba
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ 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;
}
Expand Down
67 changes: 28 additions & 39 deletions src/gallery-datetime/js/DateTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand All @@ -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);
}
Expand All @@ -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();
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/gallery-input-calendar-sync/js/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b01dcba

Please sign in to comment.