Skip to content

Commit

Permalink
Issue #34: Add support for ForkAwesome.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jen Lampton committed Aug 28, 2021
1 parent 72b65f4 commit fe3994a
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 3 deletions.
62 changes: 62 additions & 0 deletions on_the_web.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,68 @@ function on_the_web_settings_form($form, &$form_state) {
),
),
);

$sources = array(
'fontawesome' => array(
'key' => '4.7.0',
'label' => 'FontAwesome 4.7.0',
'icons_url' => 'https://fontawesome.com/v4.7/icons',
'description' => t('The last Open Source version of FontAwesome'),
),
'forkawesome' => array(
'key' => '1.2.0',
'label' => 'ForkAwesome 1.2.0',
'icons_url' => 'http://forkaweso.me/Fork-Awesome/icons',
'description' => t('The FontAwesome Fork'),
),
/* @todo Support FA5?
'fontawesome_5' => array(
'key' => '5.x.x',
'label' => 'FontAwesome 5.x',
'icons_url' => 'https://fontawesome.com/v5.15/icons',
'description' => t('The latest version of FontAwesome. <a href=":faurl">FontAwesome account</a> Required.', array(':faurl' => 'https://fontawesome.com/start')),
),
*/
);

$form['version'] = array(
'#type' => 'radios',
'#title' => t('FontAwesome Version'),
'#default_value' => $config->get('version'),
'#states' => array(
'visible' => array(
':input[name="type"]' => array('value' => 'font'),
),
),
);

$source_options = array();
foreach ($sources as $source) {
$icons_link = l('see icons', $source['icons_url']);
$source_options[$source['key']] = $source['label'] . ' &mdash; ' . $icons_link;
$form['version']['key']['#description'] = $source['description'];
}

$form['version']['#options'] = $source_options;

/* @todo Support FA5?
$form['kit_hash'] = array(
'#type' => 'textfield',
'#title' => t('FontAwesome Kit Hash'),
'#default_value' => $config->get('kit_hash'),
'#attributes' => array(
'placeholder' => 'abcdefghij',
),
'#description' => t('In order to use FontAwesome 5 you must <a href=":faurl">register your email address</a> to recieve a kit.'),
'#states' => array(
'visible' => array(
':input[name="type"]' => array('value' => 'font'),
':input[name="version"]' => array('value' => '5.0.0'),
),
),
);
*/

$form['size'] = array(
'#type' => 'radios',
'#title' => t('Icon size'),
Expand Down
7 changes: 7 additions & 0 deletions on_the_web.install
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ function on_the_web_update_1000() {
update_variable_del('on_the_web_display');
update_variable_del('on_the_web_enabled');
}

/**
* Add FontAwesome version.
*/
function on_the_web_update_1001() {
config_set('on_the_web.settings', 'version', '4.7.0');
}
21 changes: 18 additions & 3 deletions on_the_web.module
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,24 @@ function on_the_web_display_block($delta, $settings = array(), $contexts = array
}
elseif ($type == 'font') {
if (!module_exists('font_awesome')) {
$links['#attached']['css']['https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css'] = array(
'type' => 'external',
);

$version = $config->get('version');
switch ($version) {
case '4.7.0':
$font_url = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css';
break;
case '1.2.0':
$font_url = 'https://cdn.jsdelivr.net/npm/[email protected]/css/fork-awesome.min.css';
break;
/* @todo Support FA5
case '5.x.x':
$hash = $config->get('kit_hash');
$font_url = 'https://kit.fontawesome.com/' . $hash . '.js';
break;
*/
}

$links['#attached']['css'][$font_url] = array('type' => 'external');
}
}
}
Expand Down

0 comments on commit fe3994a

Please sign in to comment.