Passed
Push — master ( e33ab3...35deb2 )
by Jean-Christophe
02:27
created

HtmlShape::flipBackOn()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Ajax\semantic\html\modules;
3
4
use Ajax\semantic\html\base\HtmlSemCollection;
5
use Ajax\semantic\html\content\HtmlShapeItem;
6
use Ajax\JsUtils;
7
use Ajax\semantic\html\base\HtmlSemDoubleElement;
8
use Ajax\common\html\BaseHtml;
9
10
11
class HtmlShape extends HtmlSemCollection{
12
13
	protected $_params=array();
14
	protected $_autoActive=true;
15
16
	public function __construct( $identifier, $sides){
17
		parent::__construct( $identifier, "div", "ui shape");
18
		$this->_template='<%tagName% id="%identifier%" %properties%><div class="sides">%wrapContentBefore%%content%%wrapContentAfter%</div></%tagName%>';
19
		$this->addItems($sides);
20
	}
21
22
	/**
23
	 * {@inheritDoc}
24
	 * @see \Ajax\common\html\HtmlCollection::createItem()
25
	 */
26
	protected function createItem($value){
27
		if(\is_object($value)===false){
28
			$value=new HtmlSemDoubleElement("","div","content",$value);
29
		}
30
		return new HtmlShapeItem("side-".$this->identifier."-".$this->count(), $value);
31
	}
32
33
	/**
34
	 * {@inheritDoc}
35
	 * @see \Ajax\common\html\HtmlCollection::createCondition()
36
	 */
37
	protected function createCondition($value){
38
		return ($value instanceof HtmlShapeItem)===false;
39
	}
40
41
	/**
42
	 * @param int $index
43
	 * @return \Ajax\semantic\html\content\HtmlShapeItem
44
	 */
45
	public function getSide($index){
46
		return $this->getItem($index);
47
	}
48
49
	/**
50
	 * @param int $index
51
	 * @return mixed|NULL
52
	 */
53
	public function getSideContent($index){
54
		$item= $this->getItem($index);
55
		if(isset($item))
56
			return $item->getContent();
57
		return null;
58
	}
59
60
	public function jsDo($action){
61
		return "$('#".$this->identifier."').shape('".$action."');";
62
	}
63
64
	public function jsFlipLeft(){
65
		return $this->jsDo("flip left");
66
	}
67
68
	public function jsFlipRight(){
69
		return $this->jsDo("flip right");
70
	}
71
72
	public function jsFlipUp(){
73
		return $this->jsDo("flip up");
74
	}
75
76
	public function jsFlipDown(){
77
		return $this->jsDo("flip down");
78
	}
79
80
	public function jsFlipOver(){
81
		return $this->jsDo("flip over");
82
	}
83
84
	public function jsFlipBack(){
85
		return $this->jsDo("flip back");
86
	}
87
88
	private function doActionOn($element,$event,$what){
89
		if($element instanceof BaseHtml){
90
			return $element->on($event, $what,true,true);
91
		}
92
	}
93
94
	public function flipLeftOn($element,$event){
95
		return $this->doActionOn($element, $event, $this->jsFlipLeft());
96
	}
97
98
	public function flipRightOn($element,$event){
99
		return $this->doActionOn($element, $event, $this->jsFlipRight());
100
	}
101
102
	public function flipUpOn($element,$event){
103
		return $this->doActionOn($element, $event, $this->jsFlipUp());
104
	}
105
106
	public function flipDownOn($element,$event){
107
		return $this->doActionOn($element, $event, $this->jsFlipDown());
108
	}
109
110
	public function flipBackOn($element,$event){
111
		return $this->doActionOn($element, $event, $this->jsFlipBack());
112
	}
113
114
	public function flipOverOn($element,$event){
115
		return $this->doActionOn($element, $event, $this->jsFlipOver());
116
	}
117
118
	public function setActiveSide($index){
119
		$side=$this->getSide($index);
120
		if(isset($side)){
121
			$side->setActive(true);
122
		}
123
		return $this;
124
	}
125
126
	public function asCube(){
127
		return $this->addToPropertyCtrl("class", "cube", ["cube"]);
128
	}
129
130
	public function asText(){
131
		return $this->addToPropertyCtrl("class", "text", ["text"]);
132
	}
133
134
	public function setWidth($width="initial"){
135
		$this->_params["width"]=$width;
136
	}
137
	public function onChange($jsCode){
138
		return $this->_params["onChange"]="%function(){" . $jsCode . "}%";
139
	}
140
141
	public function beforeChange($jsCode){
142
		return $this->_params["beforeChange"]="%function(){" . $jsCode . "}%";
143
	}
144
145
	/*
146
	 * (non-PHPdoc)
147
	 * @see BaseHtml::run()
148
	 */
149
	public function run(JsUtils $js) {
150
		if (isset($this->_bsComponent) === false)
151
			$this->_bsComponent=$js->semantic()->shape("#" . $this->identifier, $this->_params);
152
		$this->addEventsOnRun($js);
153
		return $this->_bsComponent;
154
	}
155
156
	public function compile(JsUtils $js=NULL, &$view=NULL) {
157
		if($this->_autoActive)
158
			$this->setActiveSide(0);
159
		return parent::compile($js,$view);
160
	}
161
}
162