t('YUI button settings'), 'page callback' => 'drupal_get_form', 'page arguments' => array('yui_button_settings_form'), 'access callback' => 'user_access', 'access arguments' => array('administer site configuration'), 'description' => t("View/Modify YUI button settings"), ); return $items; } function yui_button_init() { // Thank you block.module :) $path = drupal_get_path_alias($_GET['q']); $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote(variable_get("yui_button_include", ''), '/')) .')$/'; $yui_include = variable_get("yui_button_include", ""); if(preg_match($regexp, $path) or empty($yui_include)) { ;//render_button(); } } function yui_button_form_alter(&$form, $form_state, $form_id) { array_walk($form, '_yui_button_form_alter'); } function _yui_button_form_alter($element, $id) { if (is_array($element)) { array_walk($element, '_yui_button_form_alter'); } switch ($element['#type']) { case 'button': render_button($id); break; case 'submit': render_button($id); break; case 'checkbox': render_button($id, 'checkbox'); break; case 'radio': render_button($id, 'radio'); break; case 'radios': render_button($id, 'radios'); break; case 'select': case 'weight': render_button('menu-' . $id, 'menu'); break; } } /* * implementation of hook_perm(). */ function yui_button_perm() { $array = array('Access YUI button'); return $array; } /* *The settings page. */ function yui_button_settings_form() { $form = array(); return system_settings_form($form); } /* * Add the javascript/CSS needed to render the button */ function render_button($id, $type = 'button') { if (!user_access('Access YUI button')) { return; } static $radios; yui_add_css('button', $yui_source, '/build/fonts/fonts-min.css'); yui_add_css('button', $yui_source, '/build/button/assets/skins/sam/button.css'); yui_add_css('button', $yui_source, '/build/button/assets/skins/sam/menu.css'); yui_add_js('button', $yui_source, '/build/yahoo-dom-event/yahoo-dom-event.js'); yui_add_js('button', $yui_source, '/build/container/container_core-min.js'); yui_add_js('button', $yui_source, '/build/menu/menu-min.js'); yui_add_js('button', $yui_source, '/build/element/element-beta-min.js'); yui_add_js('button', $yui_source, '/build/button/button-min.js'); if ($type == 'menu') { drupal_add_js(" YAHOO.util.Event.onContentReady('edit-$id', function() { var menu = document.createElement('input'); var menuID = YAHOO.util.Dom.generateId(menu, 'edit-${id}-menu'); YAHOO.util.Dom.insertBefore(menu, 'edit-$id'); var button = new YAHOO.widget.Button(menuID, { label : 'foobar', type : '$type'" . ($type == 'menu' ? ", menu : 'edit-$id'" : '') . " }); });", "inline", "footer"); } else if ($type == 'radios' and $radios == NULL) { $radios = TRUE; drupal_add_js(" YAHOO.util.Event.onDOMReady(function() { var radioGroups = YAHOO.util.Dom.getElementsByClassName('form-radios'); for (var radioGroup in radioGroups) { var radioGroupID = YAHOO.util.Dom.generateId(radioGroups[radioGroup], 'form-radios-'); var button = new YAHOO.widget.ButtonGroup(radioGroupID); } });", "inline", "footer"); } else { drupal_add_js(" YAHOO.util.Event.onContentReady('edit-$id', function() { var button = new YAHOO.widget.Button('edit-${id}', { type : '$type' }); });", "inline", "footer"); } }