Skip to content

Commit

Permalink
Merge pull request #7255 from mrclay/initDatePicker_logic
Browse files Browse the repository at this point in the history
chore(js): simplifies elgg.ui.initDatePicker logic
  • Loading branch information
Juho Jaakkola committed Oct 2, 2014
2 parents b7eca3e + b5c0fdf commit e23bbe9
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions js/lib/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ elgg.ui.loginHandler = function(hook, type, params, options) {
* @requires jqueryui.datepicker
*/
elgg.ui.initDatePicker = function() {
var loadDatePicker = function() {
function loadDatePicker() {
$('.elgg-input-date').datepicker({
// ISO-8601
dateFormat: 'yy-mm-dd',
Expand All @@ -283,11 +283,16 @@ elgg.ui.initDatePicker = function() {
}
}
});
};

if ($('.elgg-input-date').length && elgg.get_language() == 'en') {
}

if (!$('.elgg-input-date').length) {
return;
}

if (elgg.get_language() == 'en') {
loadDatePicker();
} else if ($('.elgg-input-date').length) {
} else {
// load language first
elgg.get({
url: elgg.config.wwwroot + 'vendors/jquery/i18n/jquery.ui.datepicker-'+ elgg.get_language() +'.js',
dataType: "script",
Expand All @@ -301,18 +306,18 @@ elgg.ui.initDatePicker = function() {
/**
* This function registers two menu items that are actions that are the opposite
* of each other and ajaxifies them. E.g. like/unlike, friend/unfriend, ban/unban, etc.
*
*
* Note the menu item names must be given in their normalized form. So if the
* name is remove_friend, you should call this function with "remove-friend" instead.
*/
elgg.ui.registerTogglableMenuItems = function(menuItemNameA, menuItemNameB) {
// Handles clicking the first button.
$('.elgg-menu-item-' + menuItemNameA + ' a').live('click', function() {
var $menu = $(this).closest('.elgg-menu');

// Be optimistic about success
elgg.ui.toggleMenuItems($menu, menuItemNameB, menuItemNameA);

// Send the ajax request
elgg.action($(this).attr('href'), {
success: function(json) {
Expand All @@ -325,19 +330,19 @@ elgg.ui.registerTogglableMenuItems = function(menuItemNameA, menuItemNameB) {
// Something went wrong, so undo the optimistic changes
elgg.ui.toggleMenuItems($menu, menuItemNameA, menuItemNameB);
}
});
});

// Don't want to actually click the link
return false;
});

// Handles clicking the second button
$('.elgg-menu-item-' + menuItemNameB + ' a').live('click', function() {
var $menu = $(this).closest('.elgg-menu');

// Be optimistic about success
elgg.ui.toggleMenuItems($menu, menuItemNameA, menuItemNameB);

// Send the ajax request
elgg.action($(this).attr('href'), {
success: function(json) {
Expand All @@ -350,8 +355,8 @@ elgg.ui.registerTogglableMenuItems = function(menuItemNameA, menuItemNameB) {
// Something went wrong, so undo the optimistic changes
elgg.ui.toggleMenuItems($menu, menuItemNameB, menuItemNameA);
}
});
});

// Don't want to actually click the link
return false;
});
Expand Down

0 comments on commit e23bbe9

Please sign in to comment.