1
|
|
|
<?php |
2
|
|
|
namespace Ajax\bootstrap\html\base; |
3
|
|
|
|
4
|
|
|
use Ajax\bootstrap\html\base\HtmlDoubleElement; |
5
|
|
|
use Ajax\JsUtils; |
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Bse class for navigation elements : Breadcrumbs and Pagination |
8
|
|
|
* @author jc |
9
|
|
|
* @version 1.001 |
10
|
|
|
*/ |
11
|
|
|
abstract class HtmlNavElement extends HtmlDoubleElement { |
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var string the root site |
14
|
|
|
*/ |
15
|
|
|
protected $root; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var String the html attribute which contains the elements url. default : data-ajax |
19
|
|
|
*/ |
20
|
|
|
protected $attr; |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
public function __construct($identifier,$tagName){ |
24
|
|
|
parent::__construct($identifier,$tagName); |
25
|
|
|
$this->root=""; |
26
|
|
|
$this->attr="data-ajax"; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Associate an ajax get to the elements, displayed in $targetSelector |
31
|
|
|
* $attr member is used to build each element url |
32
|
|
|
* @param string $targetSelector the target of the get |
33
|
|
|
* @param string $attr the html attribute used to build the elements url |
|
|
|
|
34
|
|
|
* @return HtmlNavElement |
35
|
|
|
*/ |
36
|
|
|
public function autoGetOnClick($targetSelector){ |
37
|
|
|
return $this->getOnClick($this->root, $targetSelector,array("attr"=>$this->attr)); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function contentAsString(){ |
41
|
|
|
return implode("", $this->content); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Generate the jquery script to set the elements to the HtmlNavElement |
46
|
|
|
* @param JsUtils $jsUtils |
47
|
|
|
*/ |
48
|
|
|
public function jsSetContent(JsUtils $jsUtils){ |
49
|
|
|
$jsUtils->html("#".$this->identifier,str_replace("\"","'", $this->contentAsString()),true); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getRoot() { |
53
|
|
|
return $this->root; |
54
|
|
|
} |
55
|
|
|
public function setRoot($root) { |
56
|
|
|
$this->root = $root; |
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
public function getAttr() { |
60
|
|
|
return $this->attr; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Define the html attribute for each element url in ajax |
65
|
|
|
* @param string $attr html attribute |
66
|
|
|
* @return HtmlNavElement |
67
|
|
|
*/ |
68
|
|
|
public function setAttr($attr) { |
69
|
|
|
$this->attr = $attr; |
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function __call($method, $args) { |
74
|
|
|
if(isset($this->$method) && is_callable($this->$method)) { |
75
|
|
|
return call_user_func_array( |
76
|
|
|
$this->$method, |
77
|
|
|
$args |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public abstract function fromDispatcher($dispatcher); |
|
|
|
|
83
|
|
|
|
84
|
|
|
} |
|
|
|
|