diff --git a/on_the_web.admin.inc b/on_the_web.admin.inc index 9179142..765efa3 100644 --- a/on_the_web.admin.inc +++ b/on_the_web.admin.inc @@ -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. FontAwesome account 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'] . ' — ' . $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 register your email address 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'), diff --git a/on_the_web.install b/on_the_web.install index 0d1ceab..5a6ad03 100755 --- a/on_the_web.install +++ b/on_the_web.install @@ -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'); +} diff --git a/on_the_web.module b/on_the_web.module index c28d2ad..a6e1ac7 100755 --- a/on_the_web.module +++ b/on_the_web.module @@ -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/fork-awesome@1.2.0/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'); } } }