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_form_alter(&$form, $form_state, $form_id) { array_walk($form, '_yui_button_form_alter'); } function _yui_button_form_alter($element, $id, $parentId = null) { $id = ($parentId != null ? $parentId . '-' : '') . $id; if (is_array($element)) { if (isset($element['#tree'])) { array_walk($element, '_yui_button_form_alter', $id); } else { array_walk($element, '_yui_button_form_alter'); } switch ($element['#type']) { case 'button': render_button($id); break; case 'submit': render_button($id, 'submit'); break; case 'checkbox': render_button($id, 'checkbox'); break; case 'radio': render_button($id, 'radio'); break; case 'radios': render_button($id, 'radios', $element); break; case 'select': case 'weight': render_button($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', $element = NULL) { if (!user_access('Access YUI button')) { return; } static $radios; $yui_source = variable_get('yui_source','http://yui.yahooapis.com/2.5.2'); 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 options = YAHOO.util.Dom.get('edit-$id').options; for (option in options) { var string = options[option].text + ''; options[option].text = string.replace(/>/, '-').replace(/ $label) { $labels .= "buttons['form-radios-' + $radios].getButton(" . $count++ . ").set('label', '$label');\n"; } $radios++; drupal_add_js(" YAHOO.util.Event.onDOMReady(function() { $labels; });", "inline", "footer"); } else if ($type == 'checkbox') { drupal_add_js(" YAHOO.util.Event.onContentReady('edit-$id', function() { var button = new YAHOO.widget.Button('edit-${id}', { label : YAHOO.util.Dom.get('edit-${id}').nextSibling.nodeValue, type : '$type' }); YAHOO.util.Dom.get('edit-${id}').nextSibling.nodeValue = null; });", "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"); } }