mootools_PHP / MooTools 1.2手风琴助手

mootools

The MooTools Accordion plugin seems to be the plugin that people seem to have the most problems with. It's an awesome plugin, so I can see why so many people want to use it, but I think that may be part of the problem. I think people see and want it without sufficient knowledge of MooTools or JavaScript in general. That's why I've created a PHP Accordion class to help make the development of accordions easier and faster.

MooTools Accordion插件似乎是人们似乎遇到最多问题的插件。 这是一个很棒的插件,所以我可以看到为什么这么多人想要使用它,但是我认为这可能是问题的一部分。 我认为人们通常在没有足够的MooTools或JavaScript知识的情况下看到并想要它。 这就是为什么我创建一个PHP手风琴类来帮助使手风琴的开发变得更加轻松和快捷的原因。

PHP类 (The PHP Class)


class accordion
{
	var $toggler_class;
	var $item_class;
	var $items;
	var $open;
	
	function accordion($toggler_class = 'toggler',$item_class = 'item')
	{
		$this->items = array();
		$this->toggler_class = $toggler_class;
		$this->item_class = $item_class;
		$this->open = 0;
	}
	
	function add_item($toggler_content = '',$item_content = '',$open = 0)
	{
		$this->items[] = array('toggler'=>$toggler_content,'item'=>$item_content,'open'=>(int)$open);
	}
	
	function build()
	{
		foreach($this->items as $index=>$item)
		{
			$return.= '
   
   
'.$item['toggler'].'
'.$item['item'].'
'; if($item['open']) { $this->open = $index; } } return $return; } function output() { echo $this->build(); } function output_js($options = '') { return 'window.addEvent(\'domready\', function () { var accordion = new Accordion($$(\'.'.$this->toggler_class.'\'),$$(\'.'.$this->item_class.'\'), { display:'.$this->open.' '.($options ? ', '.$options : '').' }); });'; } }

Check out the usage for comments about the class.

查看用法以获取有关该类的注释。

PHP用法 (The PHP Usage)


$acc = new accordion('toggler','item');

$acc->add_item('The Beatles','<img src="https://davidwalsh.name/demo/accordion/let-it-be.jpg" class="image" />
<p>The Beatles were a pop and rock group from Liverpool, England. They are one of the most commercially successful and critically acclaimed bands in the history of popular music. The band\'s principal members were John Lennon, Paul McCartney, George Harrison, and Ringo Starr.</p>
<p>The Beatles led the mid-1960s musical "British Invasion" into the United States. Although their initial musical style was rooted in 1950s rock and roll and homegrown skiffle, the group explored genres ranging from Tin Pan Alley to psychedelic rock. Their clothes, styles, and statements made them trend-setters, while their growing social awareness saw their influence extend into the social and cultural revolutions of the 1960s.</p>
<p><a href="http://en.wikipedia.org/wiki/The_beatles">Click here</a> to learn more about The Beatles.</p>');

$acc->add_item('Rod Stewart','<img src="https://davidwalsh.name/demo/accordion/every-picture.jpg" class="image" />
<p>Roderick "Rod" David Stewart, CBE (born January 10, 1945), is a singer and songwriter born and raised in London, England, with Scottish and English parentage. He currently resides in Epping. With a distinctive, raspy voice, Stewart came to prominence in the late 1960s and early \'70s with The Jeff Beck Group and then The Faces and began a solo career in 1969, with his debut album An Old Raincoat Won\'t Ever Let You Down.</p>
<p>With his career in its fifth decade, Stewart has achieved numerous hit singles worldwide, most notably in the UK, where he has garnered six consecutive number one albums and his tally of 62 hit singles include 24 that reached the top 10, six of which gained the number one position. It has been estimated that Stewart\'s album and single sales total more than 250 million, easily earning him a place on the list of best-selling music artists.</p>
<p><a href="http://en.wikipedia.org/wiki/Rod_Stewart">Click here</a> to learn more about Rod Stewart.</p>', 1);

$acc->add_item('Oasis','<img src="https://davidwalsh.name/demo/accordion/oasis.jpg" class="image" />
<p>Oasis are an English rock band that formed in Manchester in 1991. The group was formed by Liam Gallagher (lead vocals), Paul Arthurs (guitar), Paul McGuigan (bass) and Tony McCarroll (drums), who were soon joined by Liam\'s older brother Noel Gallagher (lead guitar, vocals). Oasis have sold more than 50 million albums worldwide, and have had eight UK number one singles. The Gallagher brothers are the band\'s leading songwriters and the only continual members. The present lineup is completed by rhythm/lead guitarist and songwriter Gem Archer, guitarist and songwriter Andy Bell and as-yet unofficial drummer Zak Starkey.</p>
<p><a href="http://en.wikipedia.org/wiki/Oasis_band">Click here</a> to learn more about Oasis.</p>');

echo $acc->output(),'<script type="text/javascript">',$acc->output_js(),'</script>';


When creating the accordion, pass in the CSS class given to each toggler element and the CSS class given to each content element. Then it's time to add accordion items. For each item you want to create, pass in the toggler's content, the item's content, and whether you'd like the given item to start open. Once all of the items are in, you can call output() to output the XHTML and output_js() to output the MooTools JavaScript. You can pass extra options to output_js() if you'd like to get fancy.

创建手风琴时,传递给每个切换器元素CSS类和给每个内容元素CSS类。 然后是时候添加手风琴了。 对于要创建的每个项目,请传递切换器的内容,该项目的内容以及是否要打开给定的项目。 输入所有项目后,您可以调用output()输出XHTML,并调用output_js()输出MooTools JavaScript。 如果您愿意,可以将其他选项传递给output_js() 。

If you already know how to create a MooTools accordion, I'm not sure that this class would be of any value to you. If, however, you've been struggling with creating one, this may be that little helper that gets you there.

如果您已经知道如何创建MooTools手风琴,那么我不确定该类对您是否有任何价值。 但是,如果您一直在努力创建一个,那可能就是那个帮助您的小助手。

翻译自: https://davidwalsh.name/php-mootools-12-accordion-helper

mootools

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值