1
1
<?php
2
-
3
2
namespace Ajax \common \html ;
4
3
5
-
6
4
use Ajax \JsUtils ;
7
5
use Ajax \semantic \html \collections \form \HtmlFormField ;
8
6
use Ajax \semantic \html \collections \form \HtmlForm ;
7
+
9
8
class HtmlDoubleElement extends HtmlSingleElement {
9
+
10
10
/**
11
11
*
12
12
* @var mixed
13
13
*/
14
14
protected $ content ;
15
- protected $ wrapContentBefore ="" ;
16
- protected $ wrapContentAfter ="" ;
15
+
16
+ protected $ wrapContentBefore = "" ;
17
+
18
+ protected $ wrapContentAfter = "" ;
19
+
17
20
protected $ _editableContent ;
18
21
19
- public function __construct ($ identifier , $ tagName= "p " ) {
22
+ public function __construct ($ identifier , $ tagName = "p " ) {
20
23
parent ::__construct ($ identifier , $ tagName );
21
- $ this ->_template = '<%tagName% id="%identifier%" %properties%>%wrapContentBefore%%content%%wrapContentAfter%</%tagName%> ' ;
24
+ $ this ->_template = '<%tagName% id="%identifier%" %properties%>%wrapContentBefore%%content%%wrapContentAfter%</%tagName%> ' ;
22
25
}
23
26
24
27
public function setContent ($ content ) {
25
- $ this ->content = $ content ;
28
+ $ this ->content = $ content ;
26
29
return $ this ;
27
30
}
28
31
29
32
public function getContent () {
30
33
return $ this ->content ;
31
34
}
32
35
33
- public function addContent ($ content ,$ before =false ) {
34
- if (!\is_array ($ this ->content )) {
35
- if (isset ($ this ->content ))
36
- $ this ->content =array ($ this ->content );
36
+ public function addContent ($ content , $ before = false ) {
37
+ if (! \is_array ($ this ->content )) {
38
+ if (isset ($ this ->content ))
39
+ $ this ->content = array (
40
+ $ this ->content
41
+ );
37
42
else
38
- $ this ->content = array ();
43
+ $ this ->content = array ();
39
44
}
40
- if ($ before )
41
- array_unshift ($ this ->content ,$ content );
45
+ if ($ before )
46
+ array_unshift ($ this ->content , $ content );
42
47
else
43
- $ this ->content []= $ content ;
48
+ $ this ->content [] = $ content ;
44
49
return $ this ;
45
50
}
46
51
@@ -53,93 +58,103 @@ public function run(JsUtils $js) {
53
58
if ($ this ->content instanceof HtmlDoubleElement) {
54
59
$ this ->content ->run ($ js );
55
60
} else if (\is_array ($ this ->content )) {
56
- foreach ( $ this ->content as $ itemContent ) {
61
+ foreach ($ this ->content as $ itemContent ) {
57
62
if ($ itemContent instanceof HtmlDoubleElement) {
58
63
$ itemContent ->run ($ js );
59
64
}
60
65
}
61
66
}
62
67
}
63
68
64
- public function setValue ($ value ) {
65
- }
69
+ public function setValue ($ value ) {}
66
70
67
- public function wrapContent ($ before , $ after= "" ) {
68
- $ this ->wrapContentBefore .= $ before ;
69
- $ this ->wrapContentAfter = $ after. $ this ->wrapContentAfter ;
71
+ public function wrapContent ($ before , $ after = "" ) {
72
+ $ this ->wrapContentBefore .= $ before ;
73
+ $ this ->wrapContentAfter = $ after . $ this ->wrapContentAfter ;
70
74
return $ this ;
71
75
}
72
76
73
- public function getContentInstances ($ class ){
74
- return $ this ->_getContentInstances ($ class ,$ this ->content );
77
+ /**
78
+ * Wraps the element with a container.
79
+ *
80
+ * @param HtmlDoubleElement $container
81
+ * @return \Ajax\common\html\HtmlDoubleElement
82
+ */
83
+ public function wrapWith (HtmlDoubleElement $ container ) {
84
+ return $ container ->setContent ($ this );
85
+ }
86
+
87
+ public function getContentInstances ($ class ) {
88
+ return $ this ->_getContentInstances ($ class , $ this ->content );
75
89
}
76
90
77
- protected function _getContentInstances ($ class ,$ content ){
78
- $ instances= [];
79
- if ($ content instanceof $ class ){
80
- $ instances []= $ content ;
81
- }elseif ($ content instanceof HtmlDoubleElement){
82
- $ instances= \array_merge ($ instances ,$ content ->getContentInstances ($ class ));
83
- }elseif (\is_array ($ content )){
84
- foreach ($ content as $ element ){
85
- $ instances= \array_merge ($ instances ,$ this ->_getContentInstances ($ class , $ element ));
91
+ protected function _getContentInstances ($ class , $ content ) {
92
+ $ instances = [];
93
+ if ($ content instanceof $ class ) {
94
+ $ instances [] = $ content ;
95
+ } elseif ($ content instanceof HtmlDoubleElement) {
96
+ $ instances = \array_merge ($ instances , $ content ->getContentInstances ($ class ));
97
+ } elseif (\is_array ($ content )) {
98
+ foreach ($ content as $ element ) {
99
+ $ instances = \array_merge ($ instances , $ this ->_getContentInstances ($ class , $ element ));
86
100
}
87
101
}
88
102
return $ instances ;
89
103
}
90
104
91
105
/**
92
106
* Transforms the element into a link
107
+ *
93
108
* @return HtmlDoubleElement
94
109
*/
95
- public function asLink ($ href= NULL ,$ target= NULL ) {
110
+ public function asLink ($ href = NULL , $ target = NULL ) {
96
111
if (isset ($ href ))
97
112
$ this ->setProperty ("href " , $ href );
98
- if (isset ($ target ))
113
+ if (isset ($ target ))
99
114
$ this ->setProperty ("target " , $ target );
100
115
return $ this ->setTagName ("a " );
101
116
}
102
-
103
- public function getTextContent (){
104
- if (is_array ($ this ->content )){
117
+
118
+ public function getTextContent () {
119
+ if (is_array ($ this ->content )) {
105
120
return strip_tags (implode ("" , $ this ->content ));
106
121
}
107
122
return strip_tags ($ this ->content );
108
123
}
109
-
110
- public function asEditable (HtmlFormField $ field ,$ asForm= false ,$ setValueProperty= "val() " ){
111
- $ idF= $ field ->getIdentifier ();
112
- $ idE= $ idF ;
113
- if ($ asForm ){
114
- $ frm= new HtmlForm ("frm- " . $ field ->getIdentifier ());
124
+
125
+ public function asEditable (HtmlFormField $ field , $ asForm = false , $ setValueProperty = "val() " ) {
126
+ $ idF = $ field ->getIdentifier ();
127
+ $ idE = $ idF ;
128
+ if ($ asForm ) {
129
+ $ frm = new HtmlForm ("frm- " . $ field ->getIdentifier ());
115
130
$ frm ->setProperty ("onsubmit " , "return false; " );
116
- $ fields= $ frm ->addFields ();
117
- $ idE= $ frm ->getIdentifier ();
131
+ $ fields = $ frm ->addFields ();
132
+ $ idE = $ frm ->getIdentifier ();
118
133
$ fields ->addItem ($ field );
119
- $ fields ->addButtonIcon ("bt-okay " , "check " ,"green mini " ,"\$('# " . $ idE. "').trigger('validate',{value: $('#'+idF+' input').val()}); " );
120
- $ fields ->addButtonIcon ("bt-cancel " , "close " ,"mini " ,"\$('# " . $ idE. "').trigger('endEdit'); " );
121
- $ this ->_editableContent = $ frm ;
122
- $ keypress= "" ;
123
- $ focusOut= "" ;
124
- }else {
125
- $ focusOut= "if(e.relatedTarget==null)elm.trigger('endEdit'); " ;
126
- $ this ->_editableContent = $ field ;
127
- $ keypress= "$('# " . $ idF. "').keyup(function(e){if(e.which == 13) { \$('# " . $ idE. "').trigger('validate',{value: $('#'+idF+' input').val()});}if(e.keyCode===27) { \$('# " . $ idE. "').trigger('endEdit');}}); " ;
134
+ $ fields ->addButtonIcon ("bt-okay " , "check " , "green mini " , "\$('# " . $ idE . "').trigger('validate',{value: $('#'+idF+' input').val()}); " );
135
+ $ fields ->addButtonIcon ("bt-cancel " , "close " , "mini " , "\$('# " . $ idE . "').trigger('endEdit'); " );
136
+ $ this ->_editableContent = $ frm ;
137
+ $ keypress = "" ;
138
+ $ focusOut = "" ;
139
+ } else {
140
+ $ focusOut = "if(e.relatedTarget==null)elm.trigger('endEdit'); " ;
141
+ $ this ->_editableContent = $ field ;
142
+ $ keypress = "$('# " . $ idF . "').keyup(function(e){if(e.which == 13) { \$('# " . $ idE . "').trigger('validate',{value: $('#'+idF+' input').val()});}if(e.keyCode===27) { \$('# " . $ idE . "').trigger('endEdit');}}); " ;
128
143
}
129
144
$ this ->_editableContent ->setProperty ("style " , "display:none; " );
130
- $ this ->onCreate ("let idF=' " . $ idF. "';let idE=' " . $ idE. "';let elm=$('#'+idE);let self=$('# " . $ this ->getIdentifier (). "'); " . $ keypress. "elm.on('validate',function(){self.html($('#'+idE+' input'). " . $ setValueProperty. ");elm.trigger('endEdit');});elm.on('endEdit',function(){self.show();$(this).hide();});elm.focusout(function(e){ " . $ focusOut. "}); " );
131
- $ this ->onClick ("let self=$(this);self.hide(); " . $ field ->setJsContent ("self.html() " ). ";$('# " . $ idF. " input').trigger('change');elm.show();$('#'+idE+' input').focus(); " );
145
+ $ this ->onCreate ("let idF=' " . $ idF . "';let idE=' " . $ idE . "';let elm=$('#'+idE);let self=$('# " . $ this ->getIdentifier () . "'); " . $ keypress . "elm.on('validate',function(){self.html($('#'+idE+' input'). " . $ setValueProperty . ");elm.trigger('endEdit');});elm.on('endEdit',function(){self.show();$(this).hide();});elm.focusout(function(e){ " . $ focusOut . "}); " );
146
+ $ this ->onClick ("let self=$(this);self.hide(); " . $ field ->setJsContent ("self.html() " ) . ";$('# " . $ idF . " input').trigger('change');elm.show();$('#'+idE+' input').focus(); " );
132
147
}
148
+
133
149
/**
134
- * {@inheritDoc}
150
+ *
151
+ * {@inheritdoc}
135
152
* @see \Ajax\common\html\BaseHtml::compile_once()
136
153
*/
137
154
protected function compile_once (\Ajax \JsUtils $ js = NULL , &$ view = NULL ) {
138
- if (! $ this ->_compiled && isset ($ this ->_editableContent )){
139
- $ this ->wrap ("" ,$ this ->_editableContent );
155
+ if (! $ this ->_compiled && isset ($ this ->_editableContent )) {
156
+ $ this ->wrap ("" , $ this ->_editableContent );
140
157
}
141
- parent ::compile_once ($ js ,$ view );
142
-
158
+ parent ::compile_once ($ js , $ view );
143
159
}
144
-
145
160
}
0 commit comments