Passed
Push — master ( 8a5275...187fb8 )
by Jean-Christophe
03:33
created

Toast::setPreserveHTML()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Ajax\semantic\components;
4
5
use Ajax\JsUtils;
6
7
/**
8
 * Ajax\semantic\components$Toast
9
 * This class is part of phpMv-ui
10
 * @author jcheron <[email protected]>
11
 * @version 1.0.1
12
 * @since 2.3.0
13
 * @see https://fomantic-ui.com/modules/toast.html
14
 */
15
class Toast extends SimpleSemExtComponent {
16
17
	public function __construct(JsUtils $js=NULL) {
18
		parent::__construct($js);
19
		$this->uiName='toast';
20
	}
21
22
	public function close(){
23
		return $this->addBehavior('close');
24
	}
25
26
	public function setClass($value){
27
		$this->params['class']=$value;
28
		return $this;
29
	}
30
	
31
	public function setCloseIcon(){
32
		$this->params['closeIcon']=true;
33
		return $this;
34
	}
35
	
36
	public function setShowIcon($value=false){
37
		$this->params['showIcon']=$value;
38
		return $this;
39
	}
40
41
	public function setPreserveHTML($value=false){
42
		$this->params['preserveHTML']=$value;
43
		return $this;
44
	}
45
	
46
	public function setCloseOnClick($value){
47
		$this->params['closeOnClick']=$value;
48
		return $this;
49
	}
50
	
51
	public function setTitle($title){
52
		$this->params['title']=$title;
53
		return $this;
54
	}
55
56
	public function setActions(array $actions){
57
		foreach ($actions as &$action){
58
			if(isset($action['click'])){
59
				$js=\str_ireplace("\"","%quote%", $action['click']);
60
				$action['click']="%function(){".$js."}%";
0 ignored issues
show
Bug introduced by
Are you sure $js of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

60
				$action['click']="%function(){"./** @scrutinizer ignore-type */ $js."}%";
Loading history...
61
			}
62
		}
63
		$this->params['actions']=$actions;
64
		if(count($actions)>0) {
65
			$this->params['displayTime'] = 0;
66
		}
67
		return $this;
68
	}
69
	
70
	public function setMessage($message){
71
		$this->params['message']=$message;
72
		return $this;
73
	}
74
	
75
	public function setPosition($position){
76
		$this->params['position']=$position;
77
		return $this;
78
	}
79
	
80
	public function setDisplayTime($time){
81
		$this->params['displayTime']=$time;
82
		return $this;
83
	}
84
	
85
	public function setShowProgress($value='top'){
86
		$this->params['showProgress']=$value;
87
		return $this;
88
	}
89
	
90
	public function setClassProgress($value){
91
		$this->params['classProgress']=$value;
92
		return $this;
93
	}
94
95
	public function setOnShow($jsCode) {
96
		$this->addComponentEvent('onShow', $jsCode);
97
	}
98
	
99
	public function setOnHide($jsCode) {
100
		$this->addComponentEvent('onHide', $jsCode);
101
		return $this;
102
	}
103
	
104
	public function setOnApprove($jsCode) {
105
		$this->addComponentEvent('onApprove', $jsCode);
106
		return $this;
107
	}
108
	
109
	public function setOnDeny($jsCode) {
110
		$this->addComponentEvent('onDeny', $jsCode);
111
		return $this;
112
	}
113
}
114