Skip to content

Commit 076bc25

Browse files
committed
Add fomantic Slider classes
1 parent 3766ddb commit 076bc25

File tree

5 files changed

+175
-11
lines changed

5 files changed

+175
-11
lines changed

Ajax/semantic/components/Slider.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Ajax\semantic\components;
4+
5+
use Ajax\JsUtils;
6+
7+
/**
8+
* Ajax\semantic\components$Slider
9+
* This class is part of phpMv-ui
10+
* @author jcheron <[email protected]>
11+
* @version 1.0.0
12+
* @since 2.3.0
13+
* @see https://fomantic-ui.com/modules/slider.html
14+
*/
15+
class Slider extends SimpleSemExtComponent {
16+
17+
public function __construct(JsUtils $js=NULL) {
18+
parent::__construct($js);
19+
$this->uiName='slider';
20+
}
21+
22+
public function close(){
23+
return $this->addBehavior('close');
24+
}
25+
26+
public function setInterpretLabel($labels){
27+
$this->addCode('var labels='.\json_encode($labels).';');
28+
$this->params['interpretLabel']='%function(value) {return labels[value];}%';
29+
}
30+
31+
public function setMin($min){
32+
$this->params['min']=$min;
33+
}
34+
35+
public function setMax($max){
36+
$this->params['max']=$max;
37+
}
38+
39+
public function setStart($start){
40+
$this->params['start']=$start;
41+
}
42+
43+
public function setEnd($end){
44+
$this->params['end']=$end;
45+
}
46+
47+
public function setStep($step){
48+
$this->params['step']=$step;
49+
}
50+
51+
public function setSmooth($smooth) {
52+
$this->params['smooth']=$smooth;
53+
}
54+
55+
public function setOnChange($jsCode) {
56+
$this->addComponentEvent('onChange', $jsCode);
57+
}
58+
59+
public function setOnMove($jsCode) {
60+
$this->addComponentEvent('onMove', $jsCode);
61+
}
62+
63+
}

Ajax/semantic/components/Toast.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
/**
88
* Ajax\semantic\components$Toast
9-
* This class is part of Ubiquity
9+
* This class is part of phpMv-ui
1010
* @author jcheron <[email protected]>
1111
* @version 1.0.0
1212
* @since 2.3.0
13+
* @see https://fomantic-ui.com/modules/toast.html
1314
*/
1415
class Toast extends SimpleSemExtComponent {
1516

@@ -49,7 +50,7 @@ public function setDisplayTime($time){
4950
$this->params['displayTime']=$time;
5051
}
5152

52-
public function showProgress($value='top'){
53+
public function setShowProgress($value='top'){
5354
$this->params['showProgress']=$value;
5455
}
5556

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
namespace Ajax\semantic\html\modules;
3+
4+
use Ajax\semantic\html\base\HtmlSemDoubleElement;
5+
use Ajax\JsUtils;
6+
7+
/**
8+
* Ajax\semantic\html\modules$HtmlSlider
9+
* This class is part of phpMv-ui
10+
* @author jcheron <[email protected]>
11+
* @version 1.0.0
12+
* @since 2.3.0
13+
* @see https://fomantic-ui.com/modules/slider.html
14+
*
15+
*/
16+
class HtmlSlider extends HtmlSemDoubleElement {
17+
18+
protected $_paramParts=array();
19+
public function __construct($identifier, $content='') {
20+
parent::__construct($identifier, 'div','ui slider');
21+
}
22+
23+
public function setLabeled(){
24+
$this->addClass('labeled');
25+
}
26+
27+
public function setTicked(){
28+
if(!$this->propertyContains('class', 'labeled')){
29+
$this->addClass('labeled');
30+
}
31+
$this->addClass('ticked');
32+
}
33+
34+
/**
35+
* $values is an associative array with keys (min,max,start,end,step,smooth)
36+
* @param array $values
37+
*/
38+
public function asRange($values=NULL){
39+
$this->addClass('range');
40+
if(\is_array($values)){
41+
$this->_params=\array_merge($this->_params,$values);
42+
}
43+
}
44+
45+
/**
46+
* $values is an associative array with keys (min,max,start,step,smooth)
47+
* @param array $values
48+
*/
49+
public function setValues($values=NULL){
50+
if(\is_array($values)){
51+
$this->_params=\array_merge($this->_params,$values);
52+
}
53+
}
54+
55+
public function setReversed($value=true){
56+
if($value){
57+
$this->addClass('reversed');
58+
}
59+
}
60+
61+
public function setVertical($value=true){
62+
if($value){
63+
$this->addClass('vertical');
64+
}
65+
}
66+
67+
/*
68+
* (non-PHPdoc)
69+
* @see BaseHtml::run()
70+
*/
71+
public function run(JsUtils $js) {
72+
if(isset($this->_bsComponent)===false){
73+
$this->_bsComponent=$js->semantic()->slider('#'.$this->identifier,$this->_params,$this->_paramParts);
74+
}
75+
$this->addEventsOnRun($js);
76+
return $this->_bsComponent;
77+
}
78+
}
79+

Ajax/semantic/html/modules/HtmlToast.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,27 @@
55
use Ajax\JsUtils;
66
use Ajax\service\JArray;
77

8+
/**
9+
* Ajax\semantic\html\modules$HtmlToast
10+
* This class is part of phpMv-ui
11+
* @author jcheron <[email protected]>
12+
* @version 1.0.0
13+
* @since 2.3.0
14+
* @see https://fomantic-ui.com/modules/toast.html
15+
*/
816
class HtmlToast extends HtmlSemDoubleElement {
917

10-
protected $_params=array();
1118
protected $_paramParts=array();
12-
public function __construct($identifier, $content="") {
13-
parent::__construct($identifier, "div","ui toast");
19+
20+
public function __construct($identifier, $content='') {
21+
parent::__construct($identifier, 'div','ui toast');
1422
if(isset($content)){
1523
$this->setContent($content);
1624
}
1725
}
1826

1927
public function setContent($value) {
20-
$this->content["content"]=new HtmlSemDoubleElement("content-" . $this->identifier, "div", "content", $value);
28+
$this->content['content']=new HtmlSemDoubleElement('content-' . $this->identifier, 'div', 'content', $value);
2129
return $this;
2230
}
2331

@@ -28,18 +36,20 @@ public function setContent($value) {
2836
* @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile()
2937
*/
3038
public function compile(JsUtils $js=NULL, &$view=NULL) {
31-
$this->content=JArray::sortAssociative($this->content, ["content","actions" ]);
39+
$this->content=JArray::sortAssociative($this->content, ['content','actions' ]);
3240
return parent::compile($js, $view);
3341
}
42+
3443
/*
3544
* (non-PHPdoc)
3645
* @see BaseHtml::run()
3746
*/
3847
public function run(JsUtils $js) {
39-
if(isset($this->_bsComponent)===false)
40-
$this->_bsComponent=$js->semantic()->toast("#".$this->identifier,$this->_params,$this->_paramParts);
41-
$this->addEventsOnRun($js);
42-
return $this->_bsComponent;
48+
if(isset($this->_bsComponent)===false){
49+
$this->_bsComponent=$js->semantic()->toast('#'.$this->identifier,$this->_params,$this->_paramParts);
50+
}
51+
$this->addEventsOnRun($js);
52+
return $this->_bsComponent;
4353
}
4454
}
4555

Ajax/semantic/traits/SemanticComponentsTrait.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Ajax\semantic\components\Form;
2020
use Ajax\semantic\components\SimpleSemExtComponent;
2121
use Ajax\semantic\components\Toast;
22+
use Ajax\semantic\components\Slider;
2223

2324
/**
2425
* @author jc
@@ -178,5 +179,15 @@ public function toast($attachTo=NULL, $params=NULL) {
178179
$result= $this->addComponent(new Toast($this->js), $attachTo, $params);
179180
return $result;
180181
}
182+
183+
/**
184+
* @param string $attachTo
185+
* @param string|array $params
186+
* @return Slider
187+
*/
188+
public function slider($attachTo=NULL, $params=NULL) {
189+
$result= $this->addComponent(new Slider($this->js), $attachTo, $params);
190+
return $result;
191+
}
181192

182193
}

0 commit comments

Comments
 (0)