/** * link_to_prototype_window creates a window using prototype. * * Example: * <code> * <?php use_helper('Window'); ?> * <?php if(sfConfig::get('sf_debug')) { echo link_to_function('open debug window', 'showDebug()'); } ?> * <?php echo link_to_prototype_window('Google', 'google', array('title' => 'Google', 'url' => 'http://google.com', 'width' => '520', 'height' => '350', 'center' => 'true', 'className' => 'alphacube'), array('absolute' => true)); ?> * <?php echo link_to_prototype_window('DW', 'dw', array('title' => 'DW', 'url' => '@homepage', 'width' => '520', 'height' => '350', 'center' => 'true', 'className' => 'alphacube')); ?> * </code> * * @link http://prototype-window.xilinus.com/documentation.html#initialize * * @param string $name * @param string $window_id must be unique and it's destroyed on window close. * @param array $options options for this helper: http://prototype-window.xilinus.com/documentation.html#initialize * @param array $options_html * @return string */ function link_to_prototype_window($name, $window_id, $options, $options_html = array()) { $request = sfContext::getInstance()->getResponse(); $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/prototype'); $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/scriptaculous'); $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/effects'); $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/window'); $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/window_ext'); $request->addStylesheet(sfConfig::get('sf_prototype_web_dir').'/themes/default.css'); if(isset($options['className']) && ($options['className'] != 'default')) { $request->addStylesheet(sfConfig::get('sf_prototype_web_dir').'/themes/'.$options['className'].'.css'); } if(sfConfig::get('sf_debug')) { $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/debug'); $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/extended_debug'); } $options = array_merge(array('title' => 'New Window', 'className' => 'dialog', 'width' => '600', 'height' => '450', 'zIndex' => '100', 'draggable' => 'true', 'resizable' => 'true', 'opacity' => 1, 'showEffect' => 'Effect.BlindDown', 'hideEffect' => 'Effect.SwitchOff'), _parse_attributes($options)); if (isset($options['title'])) { $options['title'] = _method_option_to_s($options['title']); } if (isset($options['className'])) { $options['className'] = _method_option_to_s($options['className']); } $absolute = isset($options_html['absolute']) ? true : false; unset($options_html['absolute']); if (isset($options['url'])) { $options['url'] = _method_option_to_s(url_for($options['url'], $absolute)); } $front = isset($options['front']) ? $window_id.'.toFront();' : ''; unset($options['front']); $status = isset($options['status']) ? $window_id.'.setStatusBar('.$options['status'].');' : ''; unset($options['status']); $show = isset($options['center']) ? $window_id.'.showCenter();' : $window_id.'.show();'; unset($options['center']); $options = _options_for_javascript($options); $options_html = _parse_attributes($options_html); $js_code = 'var ' . $window_id . ' = new Window('.$window_id.', '.$options.');'.$front.$status.$show.$window_id.'.setDestroyOnClose();'; $options_html['href'] = isset($options_html['href']) ? $options_html['href'] : '#'; $options_html['onclick'] = isset($options_html['onclick']) ? $options_html['onclick'] . $js_code : $js_code; return content_tag('a', $name, $options_html); }
function _options_for_ajax($options) { $js_options = _build_callbacks($options); $js_options['asynchronous'] = isset($options['type']) && $options['type'] == 'synchronous' ? 'false' : 'true'; if (isset($options['method'])) { $js_options['method'] = _method_option_to_s($options['method']); } if (isset($options['position'])) { $js_options['insertion'] = "Insertion." . sfInflector::camelize($options['position']); } $js_options['evalScripts'] = !isset($options['script']) || $options['script'] == '0' || $options['script'] == false ? 'false' : 'true'; if (isset($options['form'])) { $js_options['parameters'] = 'Form.serialize(this)'; } else { if (isset($options['submit'])) { $js_options['parameters'] = "Form.serialize(document.getElementById('{$options['submit']}'))"; } else { if (isset($options['with'])) { $js_options['parameters'] = $options['with']; } } } return _options_for_javascript($js_options); }
function _build_functions($type, $effects = array(), $options = array()) { $code = ''; if($effects) { $code .= ' Tooltip.'.$type.'Method = function (tooltip, options)'."\n"; $code .= ' {'."\n"; foreach($effects as $key => $value) { $code .= 'Effect.'.ucfirst($key).'(tooltip, options)'."\n"; } if($options) { foreach($options as $key => $value) { $value = _method_option_to_s($value); $value = (is_bool($value)) ? ($value === false) ? 'false' : 'true' : $value; $code .= ' tooltip.'.$key.' = '.$value."\n"; } } $code .= ' }'."\n"; return $code; } }