|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AntonyThorpe\Knockout; |
|
4
|
|
|
|
|
5
|
|
|
trait Common |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* $observable |
|
9
|
|
|
* |
|
10
|
|
|
* @var string A Knockout observable |
|
11
|
|
|
*/ |
|
12
|
|
|
protected $observable; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* $otherBindings |
|
16
|
|
|
* |
|
17
|
|
|
* @var string For additional items in the data-bind attribute |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $otherBindings; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* $hasFocus |
|
23
|
|
|
* |
|
24
|
|
|
* @var boolean For applying focus to a field |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $hasFocus = false; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* setObservable |
|
30
|
|
|
* |
|
31
|
|
|
* @param string $name The name of the knockout observable |
|
32
|
|
|
* @return $this |
|
33
|
|
|
*/ |
|
34
|
|
|
public function setObservable($name) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->observable = trim($name); |
|
37
|
|
|
return $this; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* getObservable |
|
42
|
|
|
* |
|
43
|
|
|
* @return string The observable used with the binding handler |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getObservable() |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->observable; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* setbindingType |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $key As per http://knockoutjs.com/documentation/introduction.htmlentities |
|
54
|
|
|
* (e.g 'value', 'textInput', 'checked', 'options', 'selectedOptions') |
|
55
|
|
|
* @return $this |
|
56
|
|
|
*/ |
|
57
|
|
|
public function setBindingType($key) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->bindingType = $key; |
|
|
|
|
|
|
60
|
|
|
return $this; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* getBindingType |
|
65
|
|
|
* |
|
66
|
|
|
* @return string Provide the Knockoutjs binding type used on the element |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getBindingType() |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->bindingType; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* getOtherBindings |
|
76
|
|
|
* |
|
77
|
|
|
* @return string The other bindings used on the element |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getOtherBindings() |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->otherBindings; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* setOtherBindings |
|
86
|
|
|
* |
|
87
|
|
|
* @param string $otherbindings Additional value for the data-bind attribute |
|
88
|
|
|
* @return $this |
|
89
|
|
|
*/ |
|
90
|
|
|
public function setOtherBindings($otherbindings) |
|
91
|
|
|
{ |
|
92
|
|
|
$this->otherBindings = trim($otherbindings); |
|
93
|
|
|
return $this; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* setHasFocus |
|
98
|
|
|
* |
|
99
|
|
|
* @param boolean $input set the element to a focus state upon page load |
|
100
|
|
|
* @return $this |
|
101
|
|
|
*/ |
|
102
|
|
|
public function setHasFocus($input) |
|
103
|
|
|
{ |
|
104
|
|
|
$this->hasFocus = (boolean)$input; |
|
105
|
|
|
return $this; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* getHasFocus |
|
110
|
|
|
* |
|
111
|
|
|
* @return boolean |
|
112
|
|
|
*/ |
|
113
|
|
|
public function getHasFocus() |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->hasFocus; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|