diff --git a/editors/js/markitup.js b/editors/js/markitup.js index 4211415..6989557 100644 --- a/editors/js/markitup.js +++ b/editors/js/markitup.js @@ -33,16 +33,19 @@ Drupal.wysiwyg.editor.attach.markitup = function(context, params, settings) { $('#' + params.field, context).markItUp(settings); - // Adjust CSS for editor buttons. - $.each(settings.markupSet, function (index, button) { - // Get button from class name, for example: markitup-h1 - var name = button.className.substr(9); - if (name != 'separator') { - $('.' + settings.nameSpace + ' .' + this.className + ' a') - .css({ backgroundImage: 'url(' + settings.root + 'sets/' + settings.markupSetName + '/images/' + name + '.png' + ')' }) - .parents('li').css({ backgroundImage: 'none' }); - } - }); + // Only add the buttons if the iconset is set to the default iconset. + if (settings.iconset == 'default') { + // Adjust CSS for editor buttons. + $.each(settings.markupSet, function (index, button) { + // Get button from class name, for example: markitup-h1 + var name = button.className.substr(9); + if (name != 'separator') { + $(context).find('.' + this.className + ' a') + .css({ backgroundImage: 'url(' + settings.root + 'sets/' + settings.markupSetName + '/images/' + name + '.png' + ')' }) + .parents('li').css({ backgroundImage: 'none' }); + } + }); + } }; /** diff --git a/editors/markitup.inc b/editors/markitup.inc index 5f1191a..1e17278 100644 --- a/editors/markitup.inc +++ b/editors/markitup.inc @@ -197,6 +197,25 @@ function wysiwyg_markitup_settings_form(&$form, &$form_state) { '#default_value' => !empty($settings['set'])? $settings['set'] : NULL, '#options' => $options, ); + + // Get the available iconsets. + $iconsets = module_invoke_all('wysiwyg_markitup_iconset_info'); + + // Put the icons in an options array. The default value is the icons from the + // set. + $options = array('default' => t('Default')); + foreach ($iconsets as $iconset_machine_name => $iconset_info) { + $options[$iconset_machine_name] = $iconset_info['name']; + } + + $form['output']['iconset'] = array( + '#type' => 'select', + '#title' => t('Iconset'), + '#description' => t('Set of icons for the buttons on the editor.'), + '#required' => TRUE, + '#default_value' => !empty($settings['iconset']) ? $settings['iconset'] : 'default', + '#options' => $options, + ); } /** @@ -221,11 +240,15 @@ function wysiwyg_markitup_settings($editor, $config, $theme) { 'group' => CSS_THEME, )); + // Set iconset. + $iconset = !empty($config['iconset']) ? $config['iconset'] : 'default'; + $settings = array( 'root' => base_path() . $editor['library path'] . '/markitup/', - 'nameSpace' => $theme, + 'nameSpace' => $theme . ' markitup-' . $iconset, 'buttons' => array(), 'markupSetName' => isset($config['set']) ? $config['set'] : 'default', + 'iconset' => $iconset, ); // Get the available sets. @@ -246,6 +269,14 @@ function wysiwyg_markitup_settings($editor, $config, $theme) { } } + // Add the iconset CSS. + if ($iconset !== 'default') { + $iconsets = module_invoke_all('wysiwyg_markitup_iconset_info'); + foreach ($iconsets[$iconset]['css'] as $css) { + drupal_add_css($css); + } + } + $buttons = _wysiwyg_markitup_default_buttons(); // Only need the buttons the set supports. diff --git a/wysiwyg.api.php b/wysiwyg.api.php index 620c8af..993d1a5 100644 --- a/wysiwyg.api.php +++ b/wysiwyg.api.php @@ -329,3 +329,26 @@ function hook_wysiwyg_markitup_sets_info() { ), ); } + +/** + * Return an array of icon sets. This will add a class on the wysiwyg wrapper + * in the form of markitup-[machine name]. This class can be used to theme the + * icons in the css. + * + * @return Array + * An associative array having iconset machine names as keys and an array of + * iconset meta-information as values. + * + * - name: Display name of the iconset. + * - css: CSS to add when showing this iconset. + */ +function hook_wysiwyg_markitup_iconset_info() { + return array( + 'myiconset' => array( + 'name' => t('My Iconset'), + 'css' => array( + drupal_get_path('module', 'module_name') . '/iconset.css', + ), + ), + ); +} \ No newline at end of file