我在joomla 1.5组件的工具栏菜单中添加工具栏添加按钮时遇到问题。我需要以标准的方式添加一个添加自定义按钮,这样我的按钮就被添加到我的菜单中,但它不起作用。我需要一个功能,它可以帮助我从按钮中获取参数,例如我的情况下的任务(aaaa)。
/*
ToolBarHelper::custom('aaaa', 'new', 'new', 'Add Article', 'add_article', false);
*/
下面是整个工具栏类如何获取任务参数。
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
/**
* @package Joomla
* @subpackage Config
*/
class TOOLBAR_video
{
function _DEFAULT() {
/*
* DEVNOTE: This should make sense by itself now...
*/
JToolBarHelper::title( JText::_( 'Video Manager' ), 'generic.png' );
JToolBarHelper::custom('aaaa', 'new', 'new', 'Add Article', 'add_article', false);
JToolBarHelper::help( 'screen.video' );
);
}
}
它开始让你惊叹,你所要做的就是覆盖函数submitbutton函数此函数位于includes/js/joomla.javascript.js中,因此您应该覆盖此函数以将其用作自定义
submitbutton(pressbutton) {
submitform(pressbutton);
}
经过一些研究,我在这里的输入链接描述中发现了joomlausfull文章,所以我用这种方式写作。
function submitbutton(pressbutton) {
// Some conditions
document.adminForm.task.value=pressbutton;
// More conditions
submitform(pressbutton);
}
所以最后的结果是这个
<script>
/**
* Function is Overwriting native submitbutton() function.
* A Custom button relies on javascript from
* includes/js/joomla.javascript.js to execute the task indicated by the user:
*/
function submitbutton(pressbutton) {
var url = '';
if (pressbutton == 'add_article') {
url = '<?php echo JURI::root(); ?>'+'administrator/index.php?option=com_video&controller=video&action=add_article';
post_to_url(url,{'add_article': 'add_article'} );
}
if (pressbutton == 'delete_article') {
url = '<?php echo JURI::root(); ?>'+'administrator/index.php?option=com_video&controller=articlelisting&action=delete_article';
post_to_url(url,{'add_article': 'add_article'} );
}
}
/**
* Function is creating form and submitting using given url
* @var url string //Joomla admin component constructor path with action
* @var params string //it has {'var1': 'value1','var2': 'value2'} notation
*/
function post_to_url(url, params) {
var form = document.createElement('form');
form.action = url;
form.method = 'POST';
for (var i in params) {
if (params.hasOwnProperty(i)) {
var input = document.createElement('input');
input.type = 'hidden';
input.name = i;
input.value = params[i];
form.appendChild(input);
}
}
form.submit();
}
</script>