Completed
Push — master ( b9a8b8...3e8704 )
by Jean-Christophe
03:43
created

HtmlButton::setAnimated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 10
nc 1
nop 2
1
<?php
2
3
namespace Ajax\semantic\html;
4
5
use Ajax\common\html\HtmlDoubleElement;
6
7
/**
8
 * Semantic Button component
9
 * @see http://semantic-ui.com/elements/button.html
10
 * @author jc
11
 * @version 1.001
12
 */
13
class HtmlButton extends HtmlDoubleElement {
14
15
	/**
16
	 * Constructs an HTML Semantic button
17
	 * @param string $identifier HTML id
18
	 * @param string $value value of the Button
19
	 * @param string $cssStyle btn-default, btn-primary...
20
	 * @param string $onClick JS Code for click event
21
	 */
22 View Code Duplication
	public function __construct($identifier, $value="", $cssStyle=null, $onClick=null) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
		parent::__construct($identifier, "button");
24
		$this->setProperty("class", "ui button");
25
		$this->content=$value;
26
		if (isset($cssStyle)) {
27
			$this->setStyle($cssStyle);
28
		}
29
		if (isset($onClick)) {
30
			$this->onClick($onClick);
31
		}
32
	}
33
34
	/**
35
	 * Set the button value
36
	 * @param string $value
37
	 * @return \Ajax\semantic\html\HtmlButton
38
	 */
39
	public function setValue($value) {
40
		$this->content=$value;
41
		return $this;
42
	}
43
44
	/**
45
	 * define the button style
46
	 * @param string|int $cssStyle
47
	 * @return \Ajax\semantic\html\HtmlButton default : ""
48
	 */
49
	public function setStyle($cssStyle) {
50
		return $this->addToProperty("class",$cssStyle);
51
	}
52
53
	public function setFocusable(){
54
		$this->setProperty("tabindex", "0");
55
	}
56
57
	public function setAnimated($content,$animation=""){
58
		$this->setTagName("div");
59
		$this->addToProperty("class", "animated ".$animation);
60
		$visible=new HtmlDoubleElement("visible-".$this->identifier,"div");
61
		$visible->setClass("visible content");
62
		$visible->setContent($this->content);
63
		$hidden=new HtmlDoubleElement("hidden-".$this->identifier,"div");
64
		$hidden->setClass("hidden content");
65
		$hidden->setContent($content);
66
		$this->content=$visible.$hidden;
67
	}
68
69 View Code Duplication
	public function addIcon($icon,$before=true){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
		$iconO=$icon;
71
		if(\is_string($icon)){
72
			$iconO=new HtmlIcon("icon-".$this->identifier, $icon);
73
		}
74
		$this->addContent($iconO,$before);
75
	}
76
77
	/*
78
	 * (non-PHPdoc)
79
	 * @see \Ajax\common\html\BaseHtml::fromArray()
80
	 */
81
	public function fromArray($array) {
82
		$array=parent::fromArray($array);
83
		foreach ( $array as $key => $value ) {
84
			$this->setProperty($key, $value);
85
		}
86
		return $array;
87
	}
88
}