Fix #121: Ui lost menu item icon when translate

This commit is contained in:
Michael Stenta 2018-11-08 15:33:15 -05:00
parent 513b65a377
commit 2ff910dd5c
2 changed files with 22 additions and 43 deletions

View File

@ -1,56 +1,19 @@
(function ($) {
Drupal.behaviors.farm_theme_glyphicons = {
attach: function(context, settings) {
var glyphicons_text = settings['farm_theme']['glyphicons_text'];
$('#navbar ul li a', context).each(function(index) {
Drupal.behaviors.farm_theme_glyphicons.glyphicon(this);
Drupal.behaviors.farm_theme_glyphicons.glyphicon(this, glyphicons_text);
});
$('ul.tabs--primary li a', context).each(function(index) {
Drupal.behaviors.farm_theme_glyphicons.glyphicon(this);
Drupal.behaviors.farm_theme_glyphicons.glyphicon(this, glyphicons_text);
});
},
glyphicon: function(element) {
glyphicon: function(element, glyphicons_text) {
var link_text = $(element).clone().children().remove().end().text().trim();
var icon = '';
switch (link_text) {
case 'Dashboard':
icon = 'dashboard';
break;
case 'Calendar':
icon = 'calendar';
break;
case 'Help':
icon = 'question-sign';
break;
case 'Create new account':
icon = 'user';
break;
case 'My account':
icon = 'user';
break;
case 'Log out':
icon = 'log-out';
break;
case 'Log in':
icon = 'log-in';
break;
case 'Request new password':
icon = 'lock';
break;
case 'Areas':
icon = 'globe';
break;
case 'Assets':
icon = 'grain';
break;
case 'Logs':
icon = 'list';
break;
case 'People':
icon = 'user';
break;
case 'Plans':
icon = 'book';
break;
if (glyphicons_text[link_text] !== undefined) {
icon = glyphicons_text[link_text]
}
if (icon) {
$(element).prepend('<span class="icon glyphicon glyphicon-' + icon + '"></span> ');

View File

@ -400,6 +400,22 @@ function farm_theme_page_alter(&$page) {
function farm_theme_preprocess_page(&$vars) {
// Add JS for adding Bootstrap glyphicons throughout the UI.
$glyphicons_text = array(
t('Dashboard') => 'dashboard',
t('Calendar') => 'calendar',
t('Help') => 'question-sign',
t('Create new account') =>'user',
t('My account') => 'user',
t('Log out') => 'log-out',
t('Log in') => 'log-in',
t('Request new password') => 'lock',
t('Areas') => 'globe',
t('Assets') => 'grain',
t('Logs') => 'list',
t('People') => 'user',
t('Plans') => 'book',
);
drupal_add_js(array('farm_theme' => array('glyphicons_text' => $glyphicons_text)), 'setting');
drupal_add_js(drupal_get_path('theme', 'farm_theme') . '/js/glyphicons.js');
// Add Javascript to automatically collapse the help text.