File: classWt_1_1JSlot.html

package info (click to toggle)
witty 3.1.2-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 45,512 kB
  • ctags: 35,832
  • sloc: cpp: 69,469; ansic: 66,945; xml: 4,383; sh: 594; perl: 108; makefile: 106
file content (237 lines) | stat: -rw-r--r-- 15,314 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Wt: Wt::JSlot Class Reference</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="annotated.html"><span>Class&nbsp;List</span></a></li>
      <li><a href="hierarchy.html"><span>Class&nbsp;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&nbsp;Members</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="namespaceWt.html">Wt</a>::<a class="el" href="classWt_1_1JSlot.html">JSlot</a>
  </div>
</div>
<div class="contents">
<h1>Wt::JSlot Class Reference<br>
<small>
[<a class="el" href="group__signalslot.html">Signal/slot system</a>]</small>
</h1><!-- doxytag: class="Wt::JSlot" -->A slot that is only implemented in client side JavaScript code.  
<a href="#_details">More...</a>
<p>
<code>#include &lt;Wt/WJavaScript&gt;</code>
<p>

<p>
<a href="classWt_1_1JSlot-members.html">List of all members.</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1JSlot.html#0d7d51d1bfe2c1fe86fd0da1aa6100a2">JSlot</a> (<a class="el" href="classWt_1_1WWidget.html">WWidget</a> *parent=0)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Constructs a JavaScript-only slot within the parent scope.  <a href="#0d7d51d1bfe2c1fe86fd0da1aa6100a2"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1JSlot.html#5a029953497443c38ba50514194a7925">JSlot</a> (const std::string &amp;javaScript, <a class="el" href="classWt_1_1WWidget.html">WWidget</a> *parent=0)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Constructs a JavaScript-only and sets the JavaScript code.  <a href="#5a029953497443c38ba50514194a7925"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="de213c06a4ee987a4ec39446e6954e21"></a><!-- doxytag: member="Wt::JSlot::~JSlot" ref="de213c06a4ee987a4ec39446e6954e21" args="()" -->
&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1JSlot.html#de213c06a4ee987a4ec39446e6954e21">~JSlot</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Destructor. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1JSlot.html#4e28a8ef6d2965aeaac0c5dcf587bbbb">setJavaScript</a> (const std::string &amp;javaScript)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Sets or modify the JavaScript code associated with the slot.  <a href="#4e28a8ef6d2965aeaac0c5dcf587bbbb"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1JSlot.html#3d65b00a8015e556580527b52750ef87">exec</a> (const std::string &amp;object=&quot;null&quot;, const std::string &amp;event=&quot;null&quot;)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Executes the JavaScript code.  <a href="#3d65b00a8015e556580527b52750ef87"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">std::string&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1JSlot.html#520731f1245cb9a757675a93372c761c">execJs</a> (const std::string &amp;object=&quot;null&quot;, const std::string &amp;event=&quot;null&quot;)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Returns a JavaScript statement that executes the slot.  <a href="#520731f1245cb9a757675a93372c761c"></a><br></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
A slot that is only implemented in client side JavaScript code. 
<p>
This class provides a hook for adding your own JavaScript to respond to events.<p>
Carefully consider the use of this. Not only is writing cross-browser JavaScript hard and tedious, but one must also be aware of possible security problems (see further), and ofcourse, the event handling will not be available when JavaScript is disabled or not present at all.<p>
If you wish to add client side event handling, with automatic fall-back to server-side event handling and without writing JavaScript code with the associated risks and problems, consider using stateless slot implementations instead (see <a class="el" href="classWt_1_1WObject.html#c00d775170f47e715894b24de6b869da" title="Declares a slot to be stateless and learn client-side behaviour on first invocation...">WObject::implementStateless()</a>)<p>
For some purposes, stateless slot implementations are not sufficient, since they do not allow state inspection. At the same time, the non-availability in case of disabled JavaScript may also be fine for some non-essential functionality (see for example the <a class="el" href="classWt_1_1WSuggestionPopup.html" title="A widget which popups to assist in editing a textarea or lineedit.">WSuggestionPopup</a> widget), or when you simply do not care. For these situations a JSlot can be used to add client-side event handling.<p>
The JavaScript code may be set (or changed) using the <a class="el" href="classWt_1_1JSlot.html#4e28a8ef6d2965aeaac0c5dcf587bbbb" title="Sets or modify the JavaScript code associated with the slot.">setJavaScript()</a> method which takes a string that implements a JavaScript function with the following signature:<p>
<div class="fragment"><pre class="fragment"> function(sender, event) {
   <span class="comment">// handle the event, and sender is a reference to the DOM element</span>
   <span class="comment">// which captured the event (and holds the signal). Therefore it</span>
   <span class="comment">// equivalent to the sender for a normal %Wt slot.</span>

   <span class="comment">// You can prevent the default action using:</span>
   ${WT_CLASS}.cancelEvent(event);
   <span class="comment">// (where ${WT_CLASS} should be the value of the WT_CLASS define</span>
 }
</pre></div><p>
In the JavaScript code, you may use <a class="el" href="classWt_1_1WWidget.html#a2b7078b3b43d53a85e5244b45d504f7" title="Returns a JavaScript expression to the corresponding DOM node.">WWidget::jsRef()</a> to obtain the DOM element corresponding to any <a class="el" href="classWt_1_1WWidget.html" title="The abstract base class for a user-interface component.">WWidget</a>, or <a class="el" href="classWt_1_1WObject.html#5c5cc1d7aada99baf97d0dc203e42154" title="Returns the (unique) identifier for this object.">WWidget::id()</a> to obtain the DOM id. In addition you may trigger server-side events using the JavaScript WtSignalEmit function (see <a class="el" href="classWt_1_1JSignal.html" title="A signal to relay JavaScript to C++ calls.">JSignal</a> documentation). That's how far we can help you. For the rest you are left to yourself, buggy browsers and quirky JavaScript (<a href="http://www.quirksmode.org/">http://www.quirksmode.org/</a> was a reliable companion to me) -- good luck. <hr><h2>Constructor &amp; Destructor Documentation</h2>
<a class="anchor" name="0d7d51d1bfe2c1fe86fd0da1aa6100a2"></a><!-- doxytag: member="Wt::JSlot::JSlot" ref="0d7d51d1bfe2c1fe86fd0da1aa6100a2" args="(WWidget *parent=0)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">Wt::JSlot::JSlot           </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classWt_1_1WWidget.html">WWidget</a> *&nbsp;</td>
          <td class="paramname"> <em>parent</em> = <code>0</code>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Constructs a JavaScript-only slot within the parent scope. 
<p>
The JavaScript code block will reside within the scope of the given widget. By picking a long-lived parent, one may reuse a single block of JavasCript code for multiple widgets.<p>
When <code>parent</code> = <code>0</code>, then the JavaScript will be inlined in each caller (possibly replicating the same JavaScript). 
</div>
</div><p>
<a class="anchor" name="5a029953497443c38ba50514194a7925"></a><!-- doxytag: member="Wt::JSlot::JSlot" ref="5a029953497443c38ba50514194a7925" args="(const std::string &amp;javaScript, WWidget *parent=0)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">Wt::JSlot::JSlot           </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&nbsp;</td>
          <td class="paramname"> <em>javaScript</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="classWt_1_1WWidget.html">WWidget</a> *&nbsp;</td>
          <td class="paramname"> <em>parent</em> = <code>0</code></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Constructs a JavaScript-only and sets the JavaScript code. 
<p>
<dl class="see" compact><dt><b>See also:</b></dt><dd><a class="el" href="classWt_1_1JSlot.html#0d7d51d1bfe2c1fe86fd0da1aa6100a2" title="Constructs a JavaScript-only slot within the parent scope.">JSlot(WWidget *)</a>, <a class="el" href="classWt_1_1JSlot.html#4e28a8ef6d2965aeaac0c5dcf587bbbb" title="Sets or modify the JavaScript code associated with the slot.">setJavaScript()</a> </dd></dl>

</div>
</div><p>
<hr><h2>Member Function Documentation</h2>
<a class="anchor" name="4e28a8ef6d2965aeaac0c5dcf587bbbb"></a><!-- doxytag: member="Wt::JSlot::setJavaScript" ref="4e28a8ef6d2965aeaac0c5dcf587bbbb" args="(const std::string &amp;javaScript)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Wt::JSlot::setJavaScript           </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&nbsp;</td>
          <td class="paramname"> <em>javaScript</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Sets or modify the JavaScript code associated with the slot. 
<p>
When the slot is triggered, the corresponding function defined by <code>javaScript</code> is executed.<p>
The JavaScript function takes two parameters and thus should look like: <div class="fragment"><pre class="fragment">     function(obj, event) {
       <span class="comment">// ...</span>
     }
</pre></div><p>
The first parameter <code>obj</code> is a reference to the DOM element that generates the event. The <code>event</code> refers to the JavaScript event object.<p>
<dl class="see" compact><dt><b>See also:</b></dt><dd><a class="el" href="classWt_1_1WWidget.html#a2b7078b3b43d53a85e5244b45d504f7" title="Returns a JavaScript expression to the corresponding DOM node.">WWidget::jsRef()</a> </dd></dl>

</div>
</div><p>
<a class="anchor" name="3d65b00a8015e556580527b52750ef87"></a><!-- doxytag: member="Wt::JSlot::exec" ref="3d65b00a8015e556580527b52750ef87" args="(const std::string &amp;object=&quot;null&quot;, const std::string &amp;event=&quot;null&quot;)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Wt::JSlot::exec           </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&nbsp;</td>
          <td class="paramname"> <em>object</em> = <code>&quot;null&quot;</code>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const std::string &amp;&nbsp;</td>
          <td class="paramname"> <em>event</em> = <code>&quot;null&quot;</code></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Executes the JavaScript code. 
<p>
This executes the JavaScript code in the same way as when triggered by a <a class="el" href="classWt_1_1EventSignal.html" title="A signal that conveys user-interface events.">EventSignal</a>. This function returns immediately, and execution of the JavaScript code is deferred until after the event handling.<p>
The arguments are the <code>"object, event"</code> arguments of the JavaScript event callback function.<p>
<dl class="see" compact><dt><b>See also:</b></dt><dd><a class="el" href="classWt_1_1JSlot.html#4e28a8ef6d2965aeaac0c5dcf587bbbb" title="Sets or modify the JavaScript code associated with the slot.">setJavaScript()</a> </dd></dl>

</div>
</div><p>
<a class="anchor" name="520731f1245cb9a757675a93372c761c"></a><!-- doxytag: member="Wt::JSlot::execJs" ref="520731f1245cb9a757675a93372c761c" args="(const std::string &amp;object=&quot;null&quot;, const std::string &amp;event=&quot;null&quot;)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">std::string Wt::JSlot::execJs           </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&nbsp;</td>
          <td class="paramname"> <em>object</em> = <code>&quot;null&quot;</code>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const std::string &amp;&nbsp;</td>
          <td class="paramname"> <em>event</em> = <code>&quot;null&quot;</code></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Returns a JavaScript statement that executes the slot. 
<p>
This returns the JavaScript code to execute the slot.<p>
The arguments are the <code>"object, event"</code> arguments of the JavaScript event callback function.<p>
<dl class="see" compact><dt><b>See also:</b></dt><dd><a class="el" href="classWt_1_1JSlot.html#3d65b00a8015e556580527b52750ef87" title="Executes the JavaScript code.">exec()</a> </dd></dl>

</div>
</div><p>
</div>
<hr size="1"><address style="align: right;"><small>
Generated on Fri Mar 26 17:12:07 2010 for <a href="http://www.webtoolkit.eu/wt/">Wt</a> by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6</small></address>
</body>
</html>